Subversion Repositories public

Rev

Rev 230 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
230 andreas 1
/***************************************************************************
2
 *   Copyright (C) 2007 to 2009 by Andreas Theofilu                        *
3
 *   andreas@theosys.at                                                    *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation version 3 of the License.                *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
20
#ifndef _GANT_H
21
#define _GANT_H
22
 
23
#include <qstring.h>
24
#include <qfile.h>
25
 
26
#define MAXMSG 12 // SYNC,LEN,MSG,data[8],CHKSUM
27
#define hexval(c) ((c >= '0' && c <= '9') ? (c-'0') : ((c&0xdf)-'A'+10))
28
 
29
#define EVENT_RX_ACKNOWLEDGED		0x9b
30
#define EVENT_RX_BROADCAST		0x9a
31
#define EVENT_RX_BURST_PACKET		0x9c
32
#define EVENT_RX_EXT_ACKNOWLEDGED	0x9e
33
#define EVENT_RX_EXT_BROADCAST		0x9d
34
#define EVENT_RX_EXT_BURST_PACKET	0x9f
35
#define EVENT_TRANSFER_TX_COMPLETED	0x05
36
#define INVALID_MESSAGE			0x28
37
#define MESG_ACKNOWLEDGED_DATA_ID	0x4f
38
#define MESG_ASSIGN_CHANNEL_ID		0x42
39
#define MESG_BROADCAST_DATA_ID		0x4e
40
#define MESG_BURST_DATA_ID		0x50
41
#define MESG_CAPABILITIES_ID		0x54
42
#define MESG_CHANNEL_ID_ID		0x51
43
#define MESG_CHANNEL_MESG_PERIOD_ID	0x43
44
#define MESG_CHANNEL_RADIO_FREQ_ID	0x45
45
#define MESG_CHANNEL_SEARCH_TIMEOUT_ID	0x44
46
#define MESG_CHANNEL_STATUS_ID		0x52
47
#define MESG_CLOSE_CHANNEL_ID		0x4c
48
#define MESG_DATA_SIZE			13	// due to dodgy msg from suunto
49
#define MESG_EXT_ACKNOWLEDGED_DATA_ID	0x5e
50
#define MESG_EXT_BROADCAST_DATA_ID	0x5d
51
#define MESG_EXT_BURST_DATA_ID		0x5f
52
#define MESG_NETWORK_KEY_ID		0x46
53
#define MESG_OPEN_CHANNEL_ID		0x4b
54
#define MESG_OPEN_RX_SCAN_ID		0x5b
55
#define MESG_REQUEST_ID			0x4d
56
#define MESG_RESPONSE_EVENT_ID		0x40
57
#define MESG_RESPONSE_EVENT_SIZE	3
58
#define MESG_SEARCH_WAVEFORM_ID		0x49
59
#define MESG_SYSTEM_RESET_ID		0x4a
60
#define MESG_TX_SYNC			0xa4
61
#define MESG_UNASSIGN_CHANNEL_ID	0x41
62
#define RESPONSE_NO_ERROR		0x00
63
 
64
#define ACKSIZE 8		// above structure must be this size
65
#define AUTHSIZE 24		// ditto
66
#define PAIRSIZE 16
67
 
68
struct msg_queue
69
{
70
	uchar msgid;
71
	uchar len;
72
};
73
 
74
struct ack_msg
75
{
76
	uchar code;
77
	uchar atype;
78
	uchar c1;
79
	uchar c2;
80
	uint id;
81
};
82
 
83
struct auth_msg
84
{
85
	uchar code;
86
	uchar atype;
87
	uchar phase;
88
	uchar u1;
89
	uint id;
90
	ulong auth1;
91
	ulong auth2;
92
	ulong fill1;
93
	ulong fill2;
94
};
95
 
96
struct pair_msg
97
{
98
	uchar code;
99
	uchar atype;
100
	uchar phase;
101
	uchar u1;
102
	uint id;
103
	char devname[8];
104
};
105
 
106
class ant
107
{
108
	public:
109
	   ant ();
110
	   ~ant ();
111
 
112
	   bool setDevice (const QFile &fl);
113
	   bool setDevice (const QString &fl);
114
	   bool commfn ();	// Start reading data from device
115
 
116
	   // Basic functions to manage the device
117
	   bool ANT_ResetSystem ();
118
	   bool ANT_Cmd55 (uchar chan);
119
	   bool ANT_OpenRxScanMode (uchar chan);
120
	   bool ANT_Init ();
121
	   bool ANT_RequestMessage (uchar chan, uchar mesg);
122
	   bool ANT_SetNetworkKeya (uchar net, uchar *key);
123
	   bool ANT_SetNetworkKey (uchar net, uchar *key);
124
	   bool ANT_AssignChannel (uchar chan, uchar chtype, uchar net);
125
	   bool ANT_UnAssignChannel (uchar chan);
126
	   bool ANT_SetChannelId (uchar chan, ushort dev, uchar devtype, uchar manid);
127
	   bool ANT_SetChannelRFFreq (uchar chan, uchar freq);
128
	   bool ANT_SetChannelPeriod (uchar chan, ushort period);
129
	   bool ANT_SetChannelSearchTimeout (uchar chan, uchar timeout);
130
	   bool ANT_SetSearchWaveform (uchar chan, ushort waveform);
131
	   bool ANT_SendAcknowledgedDataA (uchar chan, uchar *data);
132
	   bool ANT_SendAcknowledgedData (uchar chan, uchar *data);
133
	   unsigned short ANT_SendBurstTransferA(uchar chan, uchar *data, unsigned short numpkts);
134
	   unsigned short ANT_SendBurstTransfer (uchar chan, uchar *data, unsigned short numpkts);
135
	   bool ANT_OpenChannel (uchar chan);
136
	   bool ANT_CloseChannel (uchar chan);
137
	   int ANT_fd();
138
 
139
	public:
140
	   typedef bool (ant::*RESPONSE_FUNC)(uchar chan, uchar msgid);
141
	   typedef bool (ant::*CHANNEL_EVENT_FUNC)(uchar chan, uchar event);
142
	   void ANT_AssignResponseFunction (RESPONSE_FUNC rf, uchar* rbuf);
143
	   void ANT_AssignChannelEventFunction (uchar chan, CHANNEL_EVENT_FUNC rf, uchar* rbuf);
144
 
145
	protected:
146
	   bool msg_send(uchar mesg, uchar *inbuf, uchar len);
147
	   bool msg_send(uchar mesg, uchar data1, uchar data2);
148
	   bool msg_send(uchar mesg, uchar data1, uchar data2, uchar data3);
149
	   bool get_data(int fd);
150
 
151
	private:
152
	   QFile device;
153
	   bool qFile;
154
	   int commenabled;
155
	   RESPONSE_FUNC rfn;
156
	   CHANNEL_EVENT_FUNC cfn;
157
	   uchar *rbufp;
158
	   uchar *cbufp;
159
};
160
 
161
class gant : public ant
162
{
163
	public:
164
	   gant (const QString &af);
165
	   ~gant ();
166
 
234 andreas 167
	   bool read_device ();
168
	   QString getBufferName () { return tmpOut.fileName (); };
169
	   uchar *getBuffer(int *size);
170
 
171
	protected:
230 andreas 172
	   uint randno ();
173
	   bool chevent (uchar chan, uchar event);
174
	   bool revent (uchar chan, uchar event);
234 andreas 175
 
230 andreas 176
	private:
177
	   uchar cbuf[MESG_DATA_SIZE]; // channel event data gets stored here
178
	   uchar ebuf[MESG_DATA_SIZE]; // response event data gets stored here
179
 
180
	   bool authfd;
181
	   QString authfile;
234 andreas 182
	   QFile faf, tmpOut;
230 andreas 183
 
184
	   uint mydev;
185
	   uint peerdev;
186
	   uint myid;
187
	   unsigned long myauth1;
188
	   unsigned long myauth2;
189
	   char authdata[33];
190
 
191
	   uchar clientid[3][8];
192
 
193
	   int state;		// state machine state
194
};
195
 
196
#endif