SRD Standelone programmation box: UsbManager.c File Reference

| SRD Standelone programmation box 2.0 (16/11/15 10:00:00) Documentation of the SRD standelone programmation box

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Enumerations Enumerator Macros Pages
Functions | Variables
UsbManager.c File Reference

Source file for USB Uart management (with FTDI). More...

`#include "UsbManager.h"`
Include dependency graph for UsbManager.c:

Go to the source code of this file.

## Functions

void | UsbManagerInit (void)
| Function used to initialize the USB manager. More...
void | UsbManager (void)
| USB manager. More...
void | UsbManagerCmdDealer (void)
| Function use to deal received command. More...
void | UsbManagerSendCR95Error (void)
| Function used to send the CR95 error on the USB. More...
void | UsbManagerSendCR95Result (char *result, unsigned short length)
| Function used to send the CR95 result of last RFID operation on the USB. More...

## Variables

tUsbCtrl | UsbCtrl
| Variable used to control the USB manager. More...

## Detailed Description

Source file for USB Uart management (with FTDI).

Author
  Thibaut LALUQUE 3D-Ouest

Date
  20/11/2014

Version
  1.0

All Right Reserved.

Definition in file UsbManager.c.

## Function Documentation

void UsbManager | ( | void |  | ) |

USB manager.

Definition at line 83 of file UsbManager.c.

References tUsbCtrl::all, tUsbCtrl::bits, tUsbCtrl::cmdSize, tUsbCtrl::cmdSizeRequested, tUsbCtrl::cmdType, tUsbCtrl::command, tUsbCtrl::commandId, tUsbCtrl::msRef, tUsbCtrl::rxState, TickGetMsCounter(), TickMilliSecElapsedFrom(), USB_CMD_MAX_TIME_MS_FOR_COMPLETE_CMD, USB_CMD_PROTOCOLE, USB_CMD_REMOTE, USB_CMD_RFIDECHO, USB_CMD_RW, USB_CMD_RXSTATE_CMDCOMPLETED, USB_CMD_RXSTATE_SIZERECEIVED, USB_CMD_RXSTATE_TYPERECEIVED, UsbManagerCmdDealer(), UsbUartCtrl, UsbUartDisableReceiver, UsbUartDisableTransmitter, UsbUartEnableReceiver, UsbUartInit, and UsbUartReadChar.

Referenced by taskBackground().

83 {
84
85 /*=== Manage overflow ===*/
86
87 if(UsbUartCtrl.flags.bits.rxOverrun) {
88 UsbUartDisableReceiver();
89 UsbUartCtrl.rx.lastIn = 0;
90 UsbUartCtrl.rx.lastOut = 0;
91 UsbUartCtrl.rx.nbrChar = 0;
92 UsbUartCtrl.flags.bits.stringReceived = 0;
93 UsbUartCtrl.flags.bits.charReceived = 0;
94 UsbUartEnableReceiver();
95
96 UsbCtrl.cmdSize = 0;
97 UsbCtrl.cmdSizeRequested = 0;
98 UsbCtrl.msRef = 0;
99 UsbCtrl.rxState.all = 0;
100 UsbCtrl.commandId = 0;
101 }
102
103 if(UsbUartCtrl.flags.bits.txOverrun) {
104 UsbUartDisableTransmitter();
105 UsbUartCtrl.tx.lastIn = 0;
106 UsbUartCtrl.tx.lastOut = 0;
107 UsbUartCtrl.tx.nbrChar = 0;
108 UsbUartCtrl.flags.bits.txOverrun = 0;
109 }
110
111 /*=== Manage module error ===*/
112
113 if(UsbUartCtrl.flags.bits.moduleError) {
114 UsbUartInit();
115 UsbUartCtrl.flags.bits.moduleError = 0;
116
117 UsbCtrl.cmdSize = 0;
118 UsbCtrl.cmdSizeRequested = 0;
119 UsbCtrl.msRef = 0;
120 UsbCtrl.rxState.all = 0;
121 UsbCtrl.commandId = 0;
122 }
123
124 /*=== Manage command receiving ===*/
125 while(UsbUartCtrl.rx.nbrChar) {
126
127 char read = UsbUartReadChar(); //Read current char
128
129 UsbCtrl.msRef = TickGetMsCounter();
130
131 //Controller is looking for cmd type
132 if(UsbCtrl.rxState.all == 0) {
133 if(read == USB_CMD_REMOTE || read == USB_CMD_PROTOCOLE || read == USB_CMD_RW || read == USB_CMD_RFIDECHO) {
134 if(read != USB_CMD_RFIDECHO) {
135 UsbCtrl.cmdType = read;
136 UsbCtrl.rxState.bits.cmdTypeReceived = 1;
137 UsbCtrl.command[UsbCtrl.commandId++] = read;
138 } else { //Porte dérobée pour le CR95 Echo
139 UsbCtrl.cmdType = read;
140 UsbCtrl.rxState.bits.cmdTypeReceived = 1;
141 UsbCtrl.rxState.bits.sizeReceived = 1;
142 UsbCtrl.rxState.bits.cmdComplete = 1;
143 UsbCtrl.command[UsbCtrl.commandId++] = read;
144 UsbManagerCmdDealer();
145 }
146 } else { //Unknow type -> reset
147 UsbCtrl.commandId = 0;
148 }
149
150 //Controller is looking for frame size
151 } else if (UsbCtrl.rxState.all == USB_CMD_RXSTATE_TYPERECEIVED) {
152 UsbCtrl.cmdSizeRequested = read;
153 UsbCtrl.cmdSize = 0;
154 UsbCtrl.rxState.bits.sizeReceived = 1;
155 UsbCtrl.command[UsbCtrl.commandId++] = read;
156
157 // Controller is waiting for complete frame
158 } else if (UsbCtrl.rxState.all == (USB_CMD_RXSTATE_SIZERECEIVED | USB_CMD_RXSTATE_TYPERECEIVED) ) {
159 UsbCtrl.command[UsbCtrl.commandId++] = read;
160 UsbCtrl.cmdSize++;
161 if(UsbCtrl.cmdSize == UsbCtrl.cmdSizeRequested) {
162 UsbCtrl.rxState.bits.cmdComplete = 1;
163 UsbManagerCmdDealer();
164 }
165
166 // Controller wait for command completion
167 } else if (UsbCtrl.rxState.all == (USB_CMD_RXSTATE_SIZERECEIVED | USB_CMD_RXSTATE_TYPERECEIVED | USB_CMD_RXSTATE_CMDCOMPLETED) ) {
168
169 //Don't care of incoming char
170
171 // Controller Error -> reset
172 } else {
173 UsbCtrl.cmdSize = 0;
174 UsbCtrl.cmdSizeRequested = 0;
175 UsbCtrl.rxState.all = 0;
176 UsbCtrl.commandId = 0;
177 }
178 }
179
180
181 /*-- Too much time for command complete receiving --*/
182 if(UsbCtrl.rxState.all & (USB_CMD_RXSTATE_TYPERECEIVED | USB_CMD_RXSTATE_SIZERECEIVED) != 0 ) {
183
184 if( TickMilliSecElapsedFrom(UsbCtrl.msRef) > USB_CMD_MAX_TIME_MS_FOR_COMPLETE_CMD) {
185 UsbCtrl.cmdSize = 0;
186 UsbCtrl.cmdSizeRequested = 0;
187 UsbCtrl.commandId = 0;
188 UsbCtrl.rxState.all = 0;
189 }
190 }
191 }
USB_CMD_PROTOCOLE
#define USB_CMD_PROTOCOLE
Define USB commands type.
Definition: UsbManager.h:49
tUsbCtrl::rxState
union tUsbCtrl::@14 rxState
tUsbCtrl::msRef
unsigned long msRef
Definition: UsbManager.h:132
USB_CMD_REMOTE
#define USB_CMD_REMOTE
Define USB commands type.
Definition: UsbManager.h:48
tUsbCtrl::bits
struct tUsbCtrl::@14::@15 bits
UsbUartDisableReceiver
#define UsbUartDisableReceiver()
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:84
UsbUartInit
#define UsbUartInit()
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:78
USB_CMD_MAX_TIME_MS_FOR_COMPLETE_CMD
#define USB_CMD_MAX_TIME_MS_FOR_COMPLETE_CMD
Define the maximum time to receive or send a complete command.
Definition: UsbManager.h:102
tUsbCtrl::command
char command[USB_CMD_MAX_LENGTH]
Definition: UsbManager.h:150
UsbUartEnableReceiver
#define UsbUartEnableReceiver()
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:83
UsbManagerCmdDealer
void UsbManagerCmdDealer(void)
Function use to deal received command.
Definition: UsbManager.c:194
tUsbCtrl::commandId
unsigned char commandId
Definition: UsbManager.h:152
USB_CMD_RFIDECHO
#define USB_CMD_RFIDECHO
Define USB commands type.
Definition: UsbManager.h:51
tUsbCtrl::cmdSize
unsigned short cmdSize
Definition: UsbManager.h:136
USB_CMD_RXSTATE_CMDCOMPLETED
#define USB_CMD_RXSTATE_CMDCOMPLETED
Define USB receiver state manager.
Definition: UsbManager.h:93
tUsbCtrl::cmdSizeRequested
unsigned short cmdSizeRequested
Definition: UsbManager.h:134
UsbCtrl
tUsbCtrl UsbCtrl
Variable used to control the USB manager.
Definition: UsbManager.c:53
TickGetMsCounter
unsigned long TickGetMsCounter(void)
Get the milliseconds counter.
Definition: tick.c:137
UsbUartReadChar
#define UsbUartReadChar()
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:88
UsbUartDisableTransmitter
#define UsbUartDisableTransmitter()
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:80
tUsbCtrl::all
unsigned short all
Definition: UsbManager.h:147
USB_CMD_RXSTATE_TYPERECEIVED
#define USB_CMD_RXSTATE_TYPERECEIVED
Define USB receiver state manager.
Definition: UsbManager.h:91
tUsbCtrl::cmdType
tUsbCmdType cmdType
Definition: UsbManager.h:138
TickMilliSecElapsedFrom
unsigned long TickMilliSecElapsedFrom(unsigned long refTimeMs)
Get the milliseconds counter.
Definition: tick.c:141
USB_CMD_RW
#define USB_CMD_RW
Define USB commands type.
Definition: UsbManager.h:50
UsbUartCtrl
#define UsbUartCtrl
Define the control structure used by the USB UART interface.
Definition: UsbUart.h:42
USB_CMD_RXSTATE_SIZERECEIVED
#define USB_CMD_RXSTATE_SIZERECEIVED
Define USB receiver state manager.
Definition: UsbManager.h:92

Here is the call graph for this function:

Here is the caller graph for this function:

void UsbManagerCmdDealer | ( | void |  | ) |

Function use to deal received command.

Definition at line 194 of file UsbManager.c.

References tUsbCtrl::all, tMemoryManagerCtrl::bits, BQBatteryStatus, tBQBatteryStatus::cellVoltage, tUsbCtrl::cmdSize, tUsbCtrl::cmdSizeRequested, tUsbCtrl::cmdType, tUsbCtrl::command, tUsbCtrl::commandId, tMemoryManagerLog::date, tMemoryManagerDiving::depth, DivingParameters, tMemoryManagerDiving::filterLSB, tMemoryManagerDiving::filterMSB, tBQBatteryStatus::fullCapacity, GLOBAL_FIRMWARE_RAMIFICATION, GLOBAL_FIRMWARE_REVISION, tMemoryManagerCtrl::isValid, tMemoryManagerLog::logOp, MEMORYMANAGER_LOG_SIZE, MEMORYMANAGER_SERIAL_BLOCK_SIZE, MemoryManagerCheckDiving(), MemoryManagerClearLog(), MemoryManagerCtrl, MemoryManagerReadLog(), MemoryManagerWriteDiving(), MemoryManagerWriteSerial(), tMemoryManagerCtrl::nbrLog, RFIDManagerSendBridgeCommand(), RtcGetTime(), RtcSetTime(), tUsbCtrl::rxState, tMemoryManagerSerial::serial, SerialParameters, SRD_MEMORY_NBR_BYTE, tMemoryManagerLog::srdData, tBQBatteryStatus::stateOfCharge, tBQBatteryStatus::timeToEmpty, tBQBatteryStatus::timeToFull, USB_CMD_PROTOCOLE, USB_CMD_REMOTE, USB_CMD_REMOTE_CLEAR_MEM, USB_CMD_REMOTE_ECHO, USB_CMD_REMOTE_echo, USB_CMD_REMOTE_ERROR, USB_CMD_REMOTE_GET_BATTERY, USB_CMD_REMOTE_GET_DIVING, USB_CMD_REMOTE_GET_FIRMWARE, USB_CMD_REMOTE_GET_LOG, USB_CMD_REMOTE_GET_NBRLOG, USB_CMD_REMOTE_GET_SERIAL, USB_CMD_REMOTE_GET_TIME, USB_CMD_REMOTE_SET_DIVING, USB_CMD_REMOTE_SET_SERIAL, USB_CMD_REMOTE_SET_TIME, USB_CMD_RFIDECHO, USB_CMD_RW, UsbUartSendData, and UsbUartSendString.

Referenced by UsbManager().

194 {
195
196 /*=== Remote command ===*/
197 if(UsbCtrl.cmdType == USB_CMD_REMOTE) {
198
199 /*-- echo request --*/
200 if(UsbCtrl.command[2] == USB_CMD_REMOTE_ECHO) {
201
202 char answer[] = {USB_CMD_REMOTE, 0x01, USB_CMD_REMOTE_echo, 0x00};
203
204 UsbUartSendString(answer);
205
206 //Acknowledge command
207 UsbCtrl.commandId = 0;
208 UsbCtrl.rxState.all = 0;
209 UsbCtrl.cmdSize = 0;
210 UsbCtrl.cmdSizeRequested = 0;
211 }
212
213 /*-- current date requested --*/
214 if(UsbCtrl.command[2] == USB_CMD_REMOTE_GET_TIME) {
215
216 char answer[7];
217 unsigned long rtcTime = RtcGetTime();
218
219 answer[0] = USB_CMD_REMOTE;
220 answer[1] = 5;
221 answer[2] = USB_CMD_REMOTE_GET_TIME;
222 answer[3] = (unsigned char)(rtcTime >> 24) & 0xFF;
223 answer[4] = (unsigned char)(rtcTime >> 16) & 0xFF;
224 answer[5] = (unsigned char)(rtcTime >> 8) & 0xFF;
225 answer[6] = (unsigned char)(rtcTime) & 0xFF;
226
227 UsbUartSendData(answer,7);
228
229 //Acknowledge command
230 UsbCtrl.commandId = 0;
231 UsbCtrl.rxState.all = 0;
232 UsbCtrl.cmdSize = 0;
233 UsbCtrl.cmdSizeRequested = 0;
234 }
235
236 /*-- set current date --*/
237 if(UsbCtrl.command[2] == USB_CMD_REMOTE_SET_TIME) {
238
239 char answer[3];
240 unsigned long rtcTime;
241
242 rtcTime = ( ( (unsigned long)(UsbCtrl.command[3]) & 0xFF ) << 24 ) |
243 ( ( (unsigned long)(UsbCtrl.command[4]) & 0xFF ) << 16 ) |
244 ( ( (unsigned long)(UsbCtrl.command[5]) & 0xFF ) << 8 ) |
245 ( ( (unsigned long)(UsbCtrl.command[6]) & 0xFF ) );
246
247 RtcSetTime(rtcTime);
248
249 answer[0] = USB_CMD_REMOTE;
250 answer[1] = 1;
251 answer[2] = USB_CMD_REMOTE_SET_TIME;
252 UsbUartSendData(answer,3);
253
254 //Acknowledge command
255 UsbCtrl.commandId = 0;
256 UsbCtrl.rxState.all = 0;
257 UsbCtrl.cmdSize = 0;
258 UsbCtrl.cmdSizeRequested = 0;
259 }
260
261 /*-- get battery status --*/
262 if(UsbCtrl.command[2] == USB_CMD_REMOTE_GET_BATTERY) {
263
264 char answer[12];
265
266 answer[0] = USB_CMD_REMOTE;
267 answer[1] = 10;
268 answer[2] = USB_CMD_REMOTE_GET_BATTERY;
269 answer[3] = (unsigned char)((BQBatteryStatus.cellVoltage >> 8) & 0xFF);
270 answer[4] = (unsigned char)((BQBatteryStatus.cellVoltage) & 0xFF);
271 answer[5] = (BQBatteryStatus.stateOfCharge);
272 answer[6] = (unsigned char)((BQBatteryStatus.fullCapacity >> 8) & 0xFF);
273 answer[7] = (unsigned char)((BQBatteryStatus.fullCapacity) & 0xFF);
274 answer[8] = (unsigned char)((BQBatteryStatus.timeToEmpty >> 8) & 0xFF);
275 answer[9] = (unsigned char)((BQBatteryStatus.timeToEmpty) & 0xFF);
276 answer[10] = (unsigned char)((BQBatteryStatus.timeToFull >> 8) & 0xFF);
277 answer[11] = (unsigned char)((BQBatteryStatus.timeToFull) & 0xFF);
278
279 UsbUartSendData(answer,12);
280
281 //Acknowledge command
282 UsbCtrl.commandId = 0;
283 UsbCtrl.rxState.all = 0;
284 UsbCtrl.cmdSize = 0;
285 UsbCtrl.cmdSizeRequested = 0;
286 }
287
288 /*-- set diving parameters --*/
289 if(UsbCtrl.command[2] == USB_CMD_REMOTE_SET_DIVING) {
290
291 DivingParameters.depth = UsbCtrl.command[3];
292 DivingParameters.filterMSB = UsbCtrl.command[4];
293 DivingParameters.filterLSB = UsbCtrl.command[5];
294
295 unsigned short result = MemoryManagerWriteDiving(&DivingParameters);
296
297 char answer[3];
298
299 answer[0] = USB_CMD_REMOTE;
300 answer[1] = 1;
301
302 if(result == 0) {
303 answer[2] = USB_CMD_REMOTE_SET_DIVING;
304 } else {
305 answer[2] = USB_CMD_REMOTE_ERROR;
306 }
307
308 UsbUartSendData(answer,3);
309
310 //Acknowledge command
311 UsbCtrl.commandId = 0;
312 UsbCtrl.rxState.all = 0;
313 UsbCtrl.cmdSize = 0;
314 UsbCtrl.cmdSizeRequested = 0;
315 }
316
317 /*-- get diving parameters --*/
318 if(UsbCtrl.command[2] == USB_CMD_REMOTE_GET_DIVING) {
319
320 char answer[3];
321
322 answer[0] = USB_CMD_REMOTE;
323
324 /*-- checksum --*/
325 MemoryManagerCheckDiving(&DivingParameters);
326 if(MemoryManagerCtrl.isValid.bits.diving) {
327 answer[1] = 4;
328 answer[2] = USB_CMD_REMOTE_GET_DIVING;
329 answer[3] = DivingParameters.depth;
330 answer[4] = DivingParameters.filterMSB;
331 answer[5] = DivingParameters.filterLSB;
332 UsbUartSendData(answer,6);
333 } else {
334 answer[1] = 1;
335 answer[2] = USB_CMD_REMOTE_ERROR;
336 UsbUartSendData(answer,3);
337 }
338
339 //Acknowledge command
340 UsbCtrl.commandId = 0;
341 UsbCtrl.rxState.all = 0;
342 UsbCtrl.cmdSize = 0;
343 UsbCtrl.cmdSizeRequested = 0;
344 }
345
346 /*-- get firmware revision --*/
347 if(UsbCtrl.command[2] == USB_CMD_REMOTE_GET_FIRMWARE) {
348
349 char answer[7];
350
351 answer[0] = USB_CMD_REMOTE;
352 answer[1] = 3;
353 answer[2] = USB_CMD_REMOTE_GET_FIRMWARE;
354 answer[3] = GLOBAL_FIRMWARE_REVISION;
355 answer[4] = GLOBAL_FIRMWARE_RAMIFICATION;
356
357 UsbUartSendData(answer,5);
358
359 //Acknowledge command
360 UsbCtrl.commandId = 0;
361 UsbCtrl.rxState.all = 0;
362 UsbCtrl.cmdSize = 0;
363 UsbCtrl.cmdSizeRequested = 0;
364 }
365
366
367 /*-- get serial --*/
368 if(UsbCtrl.command[2] == USB_CMD_REMOTE_GET_SERIAL) {
369
370 char answer[11];
371
372 answer[0] = USB_CMD_REMOTE;
373
374 MemoryManagerCheckDiving(&DivingParameters);
375 if(MemoryManagerCtrl.isValid.bits.serial) {
376 answer[1] = 9;
377 answer[2] = USB_CMD_REMOTE_GET_SERIAL;
378
379 unsigned char i;
380 for(i=0 ; i<MEMORYMANAGER_SERIAL_BLOCK_SIZE-1 ; i++) {
381 answer[3+i] = *(((unsigned char*)&SerialParameters.serial) + i);
382 }
383
384 UsbUartSendData(answer,11);
385 } else {
386 answer[1] = 1;
387 answer[2] = USB_CMD_REMOTE_ERROR;
388 UsbUartSendData(answer,3);
389 }
390
391 //Acknowledge command
392 UsbCtrl.commandId = 0;
393 UsbCtrl.rxState.all = 0;
394 UsbCtrl.cmdSize = 0;
395 UsbCtrl.cmdSizeRequested = 0;
396 }
397
398 /*-- Set serial --*/
399 if(UsbCtrl.command[2] == USB_CMD_REMOTE_SET_SERIAL) {
400
401 unsigned char i;
402
403 for(i=0 ; i<MEMORYMANAGER_SERIAL_BLOCK_SIZE-1 ; i++) {
404 *(((unsigned char*)&SerialParameters.serial) + i) = UsbCtrl.command[3+i];
405 }
406
407 unsigned short result = MemoryManagerWriteSerial(&SerialParameters);
408
409 char answer[3];
410
411 answer[0] = USB_CMD_REMOTE;
412 answer[1] = 1;
413
414 if(result == 0) {
415 answer[2] = USB_CMD_REMOTE_SET_SERIAL;
416 } else {
417 answer[2] = USB_CMD_REMOTE_ERROR;
418 }
419
420 UsbUartSendData(answer,3);
421
422 //Acknowledge command
423 UsbCtrl.commandId = 0;
424 UsbCtrl.rxState.all = 0;
425 UsbCtrl.cmdSize = 0;
426 UsbCtrl.cmdSizeRequested = 0;
427 }
428
429 if(UsbCtrl.command[2] == USB_CMD_REMOTE_CLEAR_MEM) {
430
431 unsigned short result = MemoryManagerClearLog();
432
433 char answer[3];
434
435 answer[0] = USB_CMD_REMOTE;
436 answer[1] = 1;
437
438 if(result == 0) {
439 answer[2] = USB_CMD_REMOTE_CLEAR_MEM;
440 } else {
441 answer[2] = USB_CMD_REMOTE_ERROR;
442 }
443
444 UsbUartSendData(answer,3);
445
446 //Acknowledge command
447 UsbCtrl.commandId = 0;
448 UsbCtrl.rxState.all = 0;
449 UsbCtrl.cmdSize = 0;
450 UsbCtrl.cmdSizeRequested = 0;
451 }
452
453 if(UsbCtrl.command[2] == USB_CMD_REMOTE_GET_NBRLOG) {
454
455 char answer[5];
456
457 answer[0] = USB_CMD_REMOTE;
458 answer[1] = 3;
459 answer[2] = USB_CMD_REMOTE_GET_NBRLOG;
460 answer[3] = (unsigned char)((MemoryManagerCtrl.nbrLog >> 8) & 0x000000FF);
461 answer[4] = (unsigned char)((MemoryManagerCtrl.nbrLog >> 0) & 0x000000FF);
462
463 UsbUartSendData(answer,5);
464
465 //Acknowledge command
466 UsbCtrl.commandId = 0;
467 UsbCtrl.rxState.all = 0;
468 UsbCtrl.cmdSize = 0;
469 UsbCtrl.cmdSizeRequested = 0;
470 }
471
472 if(UsbCtrl.command[2] == USB_CMD_REMOTE_GET_LOG) {
473
474 unsigned short logId = ((unsigned short)UsbCtrl.command[3] << 8) | (unsigned short)UsbCtrl.command[4];
475
476 /*-- Send log --*/
477 if(logId < MemoryManagerCtrl.nbrLog) {
478
479 tMemoryManagerLog log;
480 signed short result;
481
482 result = MemoryManagerReadLog(logId,&log);
483
484 if(result == -1) {
485 char answer[11];
486 answer[0] = USB_CMD_REMOTE;
487 answer[1] = 1;
488 answer[2] = USB_CMD_REMOTE_ERROR;
489 UsbUartSendData(answer,3);
490 } else {
491 char answer[11];
492 answer[0] = USB_CMD_REMOTE;
493 answer[1] = MEMORYMANAGER_LOG_SIZE + 1;
494 answer[2] = USB_CMD_REMOTE_GET_LOG;
495
496 answer[3] = (char)((log.date>>24) & 0xFF);
497 answer[4] = (char)((log.date>>16) & 0xFF);
498 answer[5] = (char)((log.date>>8) & 0xFF);
499 answer[6] = (char)((log.date>>0) & 0xFF);
500
501 answer[7] = (char)((log.logOp>>24) & 0xFF);
502 answer[8] = (char)((log.logOp>>16) & 0xFF);
503 answer[9] = (char)((log.logOp>>8) & 0xFF);
504 answer[10] = (char)((log.logOp>>0) & 0xFF);
505
506 UsbUartSendData(answer,11);
507 UsbUartSendData((char*)&(log.srdData),SRD_MEMORY_NBR_BYTE);
508 }
509
510 /*-- Error --*/
511 } else {
512 char answer[3];
513 answer[0] = USB_CMD_REMOTE;
514 answer[1] = 1;
515 answer[2] = USB_CMD_REMOTE_ERROR;
516 UsbUartSendData(answer,3);
517 }
518
519 //Acknowledge command
520 UsbCtrl.commandId = 0;
521 UsbCtrl.rxState.all = 0;
522 UsbCtrl.cmdSize = 0;
523 UsbCtrl.cmdSizeRequested = 0;
524 }
525
526
527 /*=== Protocole command ===*/
528 } else if (UsbCtrl.cmdType == USB_CMD_PROTOCOLE) {
529
530 char answer[2];
531
532 answer[0] = 0;
533 answer[1] = 0;
534 UsbUartSendData(answer,2);
535
536 //Acknowledge command
537 UsbCtrl.commandId = 0;
538 UsbCtrl.rxState.all = 0;
539 UsbCtrl.cmdSize = 0;
540 UsbCtrl.cmdSizeRequested = 0;
541
542 /*=== Read / Write operation ====*/
543 } else if (UsbCtrl.cmdType == USB_CMD_RW) {
544
545 unsigned short result = RFIDManagerSendBridgeCommand(UsbCtrl.command, UsbCtrl.cmdSize + 2);
546
547 if(result == -1) { //Error
548
549 char answer[2];
550
551 answer[0] = 0x87;
552 answer[1] = 0x00;
553 UsbUartSendData(answer,2);
554
555 //Acknowledge command
556 UsbCtrl.commandId = 0;
557 UsbCtrl.rxState.all = 0;
558 UsbCtrl.cmdSize = 0;
559 UsbCtrl.cmdSizeRequested = 0;
560
561 } else {
562 //Wait for completion -> This is RFIDManager which trig the end of this job
563 }
564
565 /*=== RFID ECHO command ===*/
566 } else if (UsbCtrl.cmdType == USB_CMD_RFIDECHO) {
567
568 char answer[1];
569
570 answer[0] = 0x55;
571 UsbUartSendData(answer,1);
572
573 //Acknowledge command
574 UsbCtrl.commandId = 0;
575 UsbCtrl.rxState.all = 0;
576 UsbCtrl.cmdSize = 0;
577 UsbCtrl.cmdSizeRequested = 0;
578
579 } else {
580 //This is an error
581 //Acknowledge command
582 UsbCtrl.commandId = 0;
583 UsbCtrl.rxState.all = 0;
584 UsbCtrl.cmdSize = 0;
585 UsbCtrl.cmdSizeRequested = 0;
586 }
587
588 }
tMemoryManagerLog::srdData
tSRDEeprom srdData
Definition: MemoryManager.h:143
USB_CMD_PROTOCOLE
#define USB_CMD_PROTOCOLE
Define USB commands type.
Definition: UsbManager.h:49
MemoryManagerReadLog
signed short MemoryManagerReadLog(unsigned short addr, tMemoryManagerLog *data)
Definition: MemoryManager.c:350
tUsbCtrl::rxState
union tUsbCtrl::@14 rxState
USB_CMD_REMOTE_GET_DIVING
#define USB_CMD_REMOTE_GET_DIVING
Define remote commands.
Definition: UsbManager.h:69
USB_CMD_REMOTE
#define USB_CMD_REMOTE
Define USB commands type.
Definition: UsbManager.h:48
SRD_MEMORY_NBR_BYTE
#define SRD_MEMORY_NBR_BYTE
Define the number of byte used in the SRD RFID memory.
Definition: SRDMemoryMapping.h:106
tMemoryManagerDiving::filterLSB
unsigned char filterLSB
Definition: MemoryManager.h:90
GLOBAL_FIRMWARE_REVISION
#define GLOBAL_FIRMWARE_REVISION
Define the firmware revision.
Definition: globalParameters.h:34
USB_CMD_REMOTE_SET_SERIAL
#define USB_CMD_REMOTE_SET_SERIAL
Define remote commands.
Definition: UsbManager.h:74
RtcGetTime
unsigned long RtcGetTime(void)
return the current time in the RTC.
Definition: rtc.c:98
UsbUartSendString
#define UsbUartSendString(string)
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:87
tUsbCtrl::command
char command[USB_CMD_MAX_LENGTH]
Definition: UsbManager.h:150
USB_CMD_REMOTE_ECHO
#define USB_CMD_REMOTE_ECHO
Define remote commands.
Definition: UsbManager.h:60
MemoryManagerCtrl
tMemoryManagerCtrl MemoryManagerCtrl
Variable used to control the memory manager.
Definition: MemoryManager.c:53
tUsbCtrl::commandId
unsigned char commandId
Definition: UsbManager.h:152
USB_CMD_RFIDECHO
#define USB_CMD_RFIDECHO
Define USB commands type.
Definition: UsbManager.h:51
tBQBatteryStatus::timeToFull
unsigned short timeToFull
Definition: BQ27510DRZRG2.h:98
USB_CMD_REMOTE_GET_SERIAL
#define USB_CMD_REMOTE_GET_SERIAL
Define remote commands.
Definition: UsbManager.h:73
tUsbCtrl::cmdSize
unsigned short cmdSize
Definition: UsbManager.h:136
tBQBatteryStatus::fullCapacity
unsigned short fullCapacity
Definition: BQ27510DRZRG2.h:95
MemoryManagerWriteDiving
signed short MemoryManagerWriteDiving(tMemoryManagerDiving *divingParameters)
Definition: MemoryManager.c:139
DivingParameters
tMemoryManagerDiving DivingParameters
Variable used to control the diving parameters.
Definition: MemoryManager.c:54
tMemoryManagerLog
Define a structure used to store a log in memory.
Definition: MemoryManager.h:140
MemoryManagerCheckDiving
void MemoryManagerCheckDiving(tMemoryManagerDiving *divingParameters)
Definition: MemoryManager.c:128
tUsbCtrl::cmdSizeRequested
unsigned short cmdSizeRequested
Definition: UsbManager.h:134
UsbCtrl
tUsbCtrl UsbCtrl
Variable used to control the USB manager.
Definition: UsbManager.c:53
MemoryManagerWriteSerial
signed short MemoryManagerWriteSerial(tMemoryManagerSerial *serialParameters)
Definition: MemoryManager.c:204
USB_CMD_REMOTE_GET_FIRMWARE
#define USB_CMD_REMOTE_GET_FIRMWARE
Define remote commands.
Definition: UsbManager.h:71
tMemoryManagerLog::logOp
unsigned long logOp
Definition: MemoryManager.h:142
SerialParameters
tMemoryManagerSerial SerialParameters
Variable used to control the serial parameters.
Definition: MemoryManager.c:55
tMemoryManagerDiving::depth
unsigned char depth
Definition: MemoryManager.h:88
USB_CMD_REMOTE_SET_DIVING
#define USB_CMD_REMOTE_SET_DIVING
Define remote commands.
Definition: UsbManager.h:68
BQBatteryStatus
tBQBatteryStatus BQBatteryStatus
Variable used to store informations about the cell monitoring.
Definition: BQ27510DRZRG2.c:61
tMemoryManagerCtrl::nbrLog
unsigned long nbrLog
Definition: MemoryManager.h:131
MEMORYMANAGER_LOG_SIZE
#define MEMORYMANAGER_LOG_SIZE
Define memory mapping of the log and control structure.
Definition: MemoryManager.h:61
USB_CMD_REMOTE_GET_TIME
#define USB_CMD_REMOTE_GET_TIME
Define remote commands.
Definition: UsbManager.h:63
RFIDManagerSendBridgeCommand
signed short RFIDManagerSendBridgeCommand(char *command, unsigned short commandSize)
function used to send a bridge command.
Definition: RFIDManager.c:763
tMemoryManagerDiving::filterMSB
unsigned char filterMSB
Definition: MemoryManager.h:89
tBQBatteryStatus::stateOfCharge
unsigned short stateOfCharge
Definition: BQ27510DRZRG2.h:107
MEMORYMANAGER_SERIAL_BLOCK_SIZE
#define MEMORYMANAGER_SERIAL_BLOCK_SIZE
Define memory mapping of the log and control structure.
Definition: MemoryManager.h:58
tMemoryManagerCtrl::isValid
union tMemoryManagerCtrl::@2 isValid
tUsbCtrl::all
unsigned short all
Definition: UsbManager.h:147
USB_CMD_REMOTE_GET_BATTERY
#define USB_CMD_REMOTE_GET_BATTERY
Define remote commands.
Definition: UsbManager.h:66
USB_CMD_REMOTE_ERROR
#define USB_CMD_REMOTE_ERROR
Define remote commands.
Definition: UsbManager.h:82
tMemoryManagerLog::date
unsigned long date
Definition: MemoryManager.h:141
MemoryManagerClearLog
signed short MemoryManagerClearLog(void)
Definition: MemoryManager.c:280
USB_CMD_REMOTE_GET_NBRLOG
#define USB_CMD_REMOTE_GET_NBRLOG
Define remote commands.
Definition: UsbManager.h:78
tMemoryManagerCtrl::bits
struct tMemoryManagerCtrl::@2::@3 bits
USB_CMD_REMOTE_echo
#define USB_CMD_REMOTE_echo
Define remote commands.
Definition: UsbManager.h:61
tUsbCtrl::cmdType
tUsbCmdType cmdType
Definition: UsbManager.h:138
tBQBatteryStatus::timeToEmpty
unsigned short timeToEmpty
Definition: BQ27510DRZRG2.h:97
RtcSetTime
void RtcSetTime(unsigned long nbrSec)
set the current time.
Definition: rtc.c:110
tBQBatteryStatus::cellVoltage
unsigned short cellVoltage
Definition: BQ27510DRZRG2.h:91
USB_CMD_REMOTE_GET_LOG
#define USB_CMD_REMOTE_GET_LOG
Define remote commands.
Definition: UsbManager.h:80
USB_CMD_RW
#define USB_CMD_RW
Define USB commands type.
Definition: UsbManager.h:50
tMemoryManagerSerial::serial
unsigned long long serial
Definition: MemoryManager.h:101
UsbUartSendData
#define UsbUartSendData(pdata, dataLength)
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:86
USB_CMD_REMOTE_CLEAR_MEM
#define USB_CMD_REMOTE_CLEAR_MEM
Define remote commands.
Definition: UsbManager.h:76
GLOBAL_FIRMWARE_RAMIFICATION
#define GLOBAL_FIRMWARE_RAMIFICATION
Define the firmware revision.
Definition: globalParameters.h:35
USB_CMD_REMOTE_SET_TIME
#define USB_CMD_REMOTE_SET_TIME
Define remote commands.
Definition: UsbManager.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

void UsbManagerInit | ( | void |  | ) |

Function used to initialize the USB manager.

Definition at line 71 of file UsbManager.c.

References tUsbCtrl::all, tUsbCtrl::cmdSize, tUsbCtrl::cmdSizeRequested, tUsbCtrl::commandId, tUsbCtrl::msRef, tUsbCtrl::rxState, UsbUartEnableReceiver, and UsbUartInit.

71 {
72
73 UsbCtrl.cmdSize = 0;
74 UsbCtrl.cmdSizeRequested = 0;
75 UsbCtrl.msRef = 0;
76 UsbCtrl.rxState.all = 0;
77 UsbCtrl.commandId = 0;
78
79 UsbUartInit();
80 UsbUartEnableReceiver();
81 }
tUsbCtrl::rxState
union tUsbCtrl::@14 rxState
tUsbCtrl::msRef
unsigned long msRef
Definition: UsbManager.h:132
UsbUartInit
#define UsbUartInit()
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:78
UsbUartEnableReceiver
#define UsbUartEnableReceiver()
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:83
tUsbCtrl::commandId
unsigned char commandId
Definition: UsbManager.h:152
tUsbCtrl::cmdSize
unsigned short cmdSize
Definition: UsbManager.h:136
tUsbCtrl::cmdSizeRequested
unsigned short cmdSizeRequested
Definition: UsbManager.h:134
UsbCtrl
tUsbCtrl UsbCtrl
Variable used to control the USB manager.
Definition: UsbManager.c:53
tUsbCtrl::all
unsigned short all
Definition: UsbManager.h:147

void UsbManagerSendCR95Error | ( | void |  | ) |

Function used to send the CR95 error on the USB.

Definition at line 590 of file UsbManager.c.

References tUsbCtrl::all, tUsbCtrl::cmdSize, tUsbCtrl::cmdSizeRequested, tUsbCtrl::commandId, tUsbCtrl::rxState, and UsbUartSendData.

Referenced by RFIDBridgeStateMachine().

590 {
591 char answer[2];
592
593 answer[0] = 0x87;
594 answer[1] = 0x00;
595 UsbUartSendData(answer,2);
596
597 //Acknowledge command
598 UsbCtrl.commandId = 0;
599 UsbCtrl.rxState.all = 0;
600 UsbCtrl.cmdSize = 0;
601 UsbCtrl.cmdSizeRequested = 0;
602 }
tUsbCtrl::rxState
union tUsbCtrl::@14 rxState
tUsbCtrl::commandId
unsigned char commandId
Definition: UsbManager.h:152
tUsbCtrl::cmdSize
unsigned short cmdSize
Definition: UsbManager.h:136
tUsbCtrl::cmdSizeRequested
unsigned short cmdSizeRequested
Definition: UsbManager.h:134
UsbCtrl
tUsbCtrl UsbCtrl
Variable used to control the USB manager.
Definition: UsbManager.c:53
tUsbCtrl::all
unsigned short all
Definition: UsbManager.h:147
UsbUartSendData
#define UsbUartSendData(pdata, dataLength)
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:86

Here is the caller graph for this function:

void UsbManagerSendCR95Result | ( | char * | result,
|  | unsigned short | length
| ) |  |

Function used to send the CR95 result of last RFID operation on the USB.

Parameters

  [in] | result | (char*) : data to send.
  [in] | length | (unsigned short) : length of the data to send.

Definition at line 604 of file UsbManager.c.

References tUsbCtrl::all, tUsbCtrl::cmdSize, tUsbCtrl::cmdSizeRequested, tUsbCtrl::commandId, tUsbCtrl::rxState, and UsbUartSendData.

Referenced by RFIDBridgeStateMachine().

604 {
605
606 UsbUartSendData(result,length);
607
608 //Acknowledge command
609 UsbCtrl.commandId = 0;
610 UsbCtrl.rxState.all = 0;
611 UsbCtrl.cmdSize = 0;
612 UsbCtrl.cmdSizeRequested = 0;
613 }
tUsbCtrl::rxState
union tUsbCtrl::@14 rxState
tUsbCtrl::commandId
unsigned char commandId
Definition: UsbManager.h:152
tUsbCtrl::cmdSize
unsigned short cmdSize
Definition: UsbManager.h:136
tUsbCtrl::cmdSizeRequested
unsigned short cmdSizeRequested
Definition: UsbManager.h:134
UsbCtrl
tUsbCtrl UsbCtrl
Variable used to control the USB manager.
Definition: UsbManager.c:53
tUsbCtrl::all
unsigned short all
Definition: UsbManager.h:147
UsbUartSendData
#define UsbUartSendData(pdata, dataLength)
Map the USB/UART functions on the rigth uart module functions.
Definition: UsbUart.h:86

Here is the caller graph for this function:

## Variable Documentation

UsbCtrl

Variable used to control the USB manager.

Definition at line 53 of file UsbManager.c.