KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bps_v3.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  *
4  * Copyright 2015 KM3NeT Collaboration
5  *
6  * All Rights Reserved.
7  *
8  *
9  * File : bps_v3.c
10  * Created : 23 feb 2015
11  * Author : Riccardo Travaglini
12  * Modified: Jan 2020 by Stefano Mastroianni for BPS_V3
13  */
14 
15 #include <stddef.h>
16 #include "kernel/tm.h"
17 #include "kernel/err.h"
18 #include "string.h"
19 #include "assert.h"
20 #include "util/convert.h"
21 
22 
23 #include "drv/uart/bps_v3.h"
24 
25 
26 #define BPS_TIMEOUT_MS 2000
27 
28 #define _BPS_SOF 0x01
29 #define _BPS_EOF 0x0
30 
31 //#define FULL_CMD_MAX_LENGTH 30
32 
33 // buffers for tx and rx storaging
34 #define BPS_MAX_RET_LEN 80
35 #define BPS_MAX_CMD_LEN 80
36 
37 static unsigned char _BpsCmdBuf[BPS_MAX_CMD_LEN];
38 static unsigned char _retBpsCmdBuf[BPS_MAX_RET_LEN];
39 
40 // fixed address
41 #define BPS_ADDR 0x30
42 
43 //size of uint16_t in the BPS command Data field is encoded with 4 bytes
44 
45 #define _BPS_USHORT_SIZE 4
46 #define _BPS_UCHAR_SIZE 2
47 
48 
49 //command list and relative command response - version 1.3
50 #define _BPSCMD_SwitchControl_Request 0x40
51 #define _BPSCMD_SwitchControl_Answer 0x41
52 #define _BPSCMD_AlarmEnable_Request 0x42
53 #define _BPSCMD_AlarmEnable_Answer 0x43
54 #define _BPSCMD_AlarmTimeOut_Save_Request 0x44
55 #define _BPSCMD_AlarmTimeOut_Save_Answer 0x45
56 #define _BPSCMD_AlarmTimeOut_Load_Request 0x46
57 #define _BPSCMD_AlarmTimeOut_Load_Answer 0x47
58 #define _BPSCMD_Alarm_Threshold_Save_Request 0x4C
59 #define _BPSCMD_Alarm_Threshold_Save_Answer 0x4D
60 #define _BPSCMD_Alarm_Threshold_Load_Request 0x4E
61 #define _BPSCMD_Alarm_Threshold_Load_Answer 0x4F
62 #define _BPSCMD_Alarm_Fired_Get_Request 0x50
63 #define _BPSCMD_Alarm_Fired_Get_Answer 0x51
64 #define _BPSCMD_ReadSensorsSingle_Request 0x56
65 #define _BPSCMD_ReadSensorsSingle_Answer 0x57
66 #define _BPSCMD_SensorMaxvalueReset_Request 0x58
67 #define _BPSCMD_SensorMaxvalueReset_Answer 0x59
68 #define _BPSCMD_ReadSensors_Request 0x5a
69 #define _BPSCMD_ReadSensors_Answer 0x5b
70 #define _BPSCMD_ReadSensorsAverage_Request 0x5c
71 #define _BPSCMD_ReadSensorsAverage_Answer 0x5d
72 #define _BPSCMD_ReadSensorsMax_Request 0x60
73 #define _BPSCMD_ReadSensorsMax_Answer 0x61
74 #define _BPSCMD_ReadVersion_Request 0x6a
75 #define _BPSCMD_ReadVersion_Answer 0x6b
76 #define _BPSCMD_Rescue_Enable_Request 0x6e
77 #define _BPSCMD_Rescue_Enable_Answer 0x6f
78 /*
79 #define _BPSCMD_ReleToggle_BackBone_Request 0x05
80 #define _BPSCMD_ReleToggle_BackBone_Answer 0x06
81 #define _BPSCMD_ReleToggle_12Vdc_Request 0x0B
82 #define _BPSCMD_ReleToggle_12Vdc_Answer 0x0C
83 #define _BPSCMD_PingDevice_Request 0x2F
84 #define _BPSCMD_PingDevice_Answer 0x30
85 #define _BPSCMD_Alarm_Enable_Save_Request 0x25
86 #define _BPSCMD_Alarm_Enable_Save_Answer 0x26
87 #define _BPSCMD_Alarm_Enable_Load_Request 0x27
88 #define _BPSCMD_Alarm_Enable_Load_Answer 0x28
89 #define _BPSCMD_Alarm_ClearStatus_Request 0x29
90 #define _BPSCMD_Alarm_ClearStatus_Answer 0x2A
91 */
92 
93 // COMMAND RETURN ERRORS
94 #define _BPSCMD_Error_Chk 0x02
95 #define _BPSCMD_Error_Start 0x04
96 #define _BPSCMD_Error_Timeout 0x08
97 
98 
99 // Sending Command structure and init macro
100 typedef struct {
101  uint8_t addr;
102  uint8_t cmd;
103  uint8_t *pData;
104  uint8_t nData;
105 }BpsCmd;
106 
107 typedef struct {
108  uint8_t sof;
109  uint8_t addr;
110  uint8_t cmd;
111  uint8_t chk;
112  uint8_t eof;
113 }BpsAnswFix;
114 
115 typedef struct {
116  BpsAnswFix hf;
117  uint8_t *pData;
118  uint8_t nData;
119 }BpsAnsw;
120 
121 
122 #define NTHRESHOLD 2
123 #define SIZE_THRESHOLD (NTHRESHOLD * _BPS_USHORT_SIZE)
124 
125 /*#define BSP_CMD_INIT \
126 { \
127  .addr = BPS_ADDR, \
128  .pData = 0x0, \
129  .nData = 0x0 \
130 }*/
131 static const BpsCmd BSP_CMD_INIT = {BPS_ADDR,0x0,0x0,0x0};
132 
133 static const CnvParams _hex = CNV_DEFAULT_HEX;
134 
135 
136 
137 /*info
138 
139 uint16 is uint8[0] LSB and uint8[1] MSB
140 uint8[0] is tx/rx before uint8[1]
141 
142 */
143 
144 
145 #ifdef BPSSIM
146 #include <stdio.h>
147 #endif
148 
149 
150 /*Utility Macros
151 * Byte order in BPS command is Little Endian (from Angelo)
152 */
153 /*
154 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
155 
156 #define HTOBPSS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
157 #define BPSTOHS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
158 #define HTOBPSL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
159  ((((unsigned long)(n) & 0xFF00)) << 8) | \
160  ((((unsigned long)(n) & 0xFF0000)) >> 8) | \
161  ((((unsigned long)(n) & 0xFF000000)) >> 24))
162 #define BPSTOHL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
163  ((((unsigned long)(n) & 0xFF00)) << 8) | \
164  ((((unsigned long)(n) & 0xFF0000)) >> 8) | \
165  ((((unsigned long)(n) & 0xFF000000)) >> 24))
166 
167 #else
168 
169 #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
170 
171 #define HTOBPSS(n) (n)
172 #define BPSTOHS(n) (n)
173 #define HTOBPSL(n) (n)
174 #define BPSTOHL(n) (n)
175 
176 #else
177 
178 #error "Platform endianess could not be detected"
179 
180 #endif
181 #endif
182 
183 unsigned short htobpss(unsigned short n);
184 unsigned short bpstohs(unsigned short n);
185 unsigned long htobpsl(unsigned long n);
186 unsigned long bpstohl(unsigned long n);
187 
188 #define htobpss(n) HTOBPSS(n)
189 #define bpstohs(n) BPSTOHS(n)
190 
191 #define htobpsl(n) HTOBPSL(n)
192 #define bpstohl(n) BPSTOHL(n) */
193 
194 /* private functions prototypes and Macro */
195 bool _bpsIn(char *c );
196 void _bpsOut(char c);
197 unsigned char bpschecksum(unsigned char* buff, int num);
198 unsigned char s_bpschecksum(BpsAnsw* answ);
199 void _bpsCmdTx (int nBytes);
200 bool _bpsRxCommand(BpsAnsw* answ);
201 int _bpsBufferCmd(BpsCmd* _cmd);
202 bool _bpsCmdRxCheck(uint8_t answ, BpsAnsw* s_answ);
203 bool _bpsTxAndRx(BpsCmd *pcmd,BpsAnsw* pansw, uint8_t cansw);
204 
205 
206 
207 /*
208 rx a char from the bps uart and return false if error
209 */
210 bool _bpsIn(char *c )
211 {
212 
213  if(bfEmpty(BPS_UART->rxfifo))return false;
214 
215  __irqDisable();
216  bfRead(BPS_UART->rxfifo,(uint8_t*) c);
217  __irqEnable();
218  //printf("rx -> 0x%x (%d) \n",*c,*c);
219 #ifdef BPSDEBUG
220  printf("rx -> 0x%x (%d)\n",*c,*c);
221 #endif
222  return true;
223 }
224 
225 /*
226 send a char to the edfa uart
227 */
228 void _bpsOut(char c)
229 {
230 //printf("tx -> 0x%x (%d)\n",c,c);
231 #ifndef BPSSIM
232  suartTx(BPS_UART,c);
233 #endif
234 #ifdef BPSDEBUG
235  printf("tx -> 0x%x (%d)\n",c,c);
236 #endif
237 
238 }
239 
240 //calculate BPS-like checksum for buffer of num elements
241 
242 unsigned char bpschecksum(unsigned char* buff, int num)
243 {
244 // printf("call: bpschecksum num %d \n",num);
245  unsigned char chk = 256;
246  int i=0;
247  while(i<num)
248  {
249  chk -= buff[i];
250  i++;
251  }
252 // printf("chk %x \n",chk);
253  return (chk );
254 }
255 
256 unsigned char s_bpschecksum(BpsAnsw* answ)
257 {
258  assert(answ);
259  unsigned char chk;
260 
261  chk = bpschecksum(answ->pData, answ->nData);
262 
263  chk -= answ->hf.addr ;
264  chk -= answ->hf.cmd ;
265  return (chk );
266 }
267 
268 /*
269 send nBytes bytes of the CMD buffer, calculates anbd tx checksum and append a 0xFF at the end
270 */
271 void _bpsCmdTx (int nBytes)
272 {
273  //printf("call: _bpsCmdTx nBytes %x \n",nBytes);
274  assert(nBytes < BPS_MAX_CMD_LEN);
275 //#ifndef BPSSIM
276  int i = 0;
277 
278  _bpsOut(0x0); // puts a 0 at the beginning to wakeup the rs-232 driver (FMC mezzanine issue due to MAX3227 autopowerdown)
279  _bpsOut(0x0); // tested : one more 0 is mandatory to always wake up
280  _bpsOut(_BPS_SOF);
281 
282  for(;i<nBytes;i++)
283  {
284  _bpsOut(_BpsCmdBuf[i]);
285  }
286 
287 
288  _bpsOut(bpschecksum(_BpsCmdBuf,nBytes));
289 
290 
291  _bpsOut(_BPS_EOF);
292 //#endif
293  return;
294 }
295 
296 
297 bool _bpsRxCommand(BpsAnsw* answ)
298 {
299  //printf("call: _bpsRxCommand--> byte to be read %d answ->nData %d BpsAnswFix %d \n",answ->nData + sizeof(BpsAnswFix), answ->nData, sizeof(BpsAnswFix) );
300  assert(answ);
301  assert(answ->nData + sizeof(BpsAnswFix) < BPS_MAX_RET_LEN);
302 #ifndef BPSSIM
303  uint32_t to = timeOutInit(BPS_TIMEOUT_MS);
304  int i = 0;
305  char c;
306  bool isFrame = false;
307 
308 
309  while(i< (answ->nData + sizeof(BpsAnswFix) )){
310 
311  if (timeOut(to)) {
313  printf("Error timeout \n");
314  return false;
315  }
316  if(_bpsIn(&c) ){
317  if(c == _BPS_SOF || isFrame){
318  _retBpsCmdBuf[i] = (unsigned char) c;
319  //printf("rx %x --> _retBpsCmdBuf[%d] %x \n",c,i,_retBpsCmdBuf[i]);
320  isFrame = true;
321  i++;
322  }
323  else
324  {
325  //printf("rx %x \n",c);
326  }
327 
328  }
329  }
330 
331 
332 #else
333 
334 
335  _retBpsCmdBuf[0] = _BPS_SOF;
336  _retBpsCmdBuf[1] = _BpsCmdBuf[0];
337 
338  // insert emulated response here
339  if(_BpsCmdBuf[1] == _BPSCMD_ReadSensors_Request){
340  _retBpsCmdBuf[2] = _BPSCMD_ReadSensors_Answer;
341  _retBpsCmdBuf[3] = '1';
342  _retBpsCmdBuf[4] = '2';
343  _retBpsCmdBuf[5] = '3';
344  _retBpsCmdBuf[6] = '4'; //1
345  _retBpsCmdBuf[7] = '5';
346  _retBpsCmdBuf[8] = '6';
347  _retBpsCmdBuf[9] = '7';
348  _retBpsCmdBuf[10] = '8'; // 2
349  _retBpsCmdBuf[11] = '9';
350  _retBpsCmdBuf[12] = 'a';
351  _retBpsCmdBuf[13] = 'b';
352  _retBpsCmdBuf[14] = 'c'; //3
353  _retBpsCmdBuf[15] = 'd';
354  _retBpsCmdBuf[16] = 'e';
355  _retBpsCmdBuf[17] = 'f';
356  _retBpsCmdBuf[18] = '0'; // 4
357  _retBpsCmdBuf[19] = '1';
358  _retBpsCmdBuf[20] = '2';
359  _retBpsCmdBuf[21] = '3';
360  _retBpsCmdBuf[22] = '4'; //5
361  _retBpsCmdBuf[23] = '5';
362  _retBpsCmdBuf[24] = '6';
363  _retBpsCmdBuf[25] = '7';
364  _retBpsCmdBuf[26] = '8'; // 6
365  _retBpsCmdBuf[27] = '9';
366  _retBpsCmdBuf[28] = 'a';
367  _retBpsCmdBuf[29] = 'b';
368  _retBpsCmdBuf[30] = 'c'; //7
369  _retBpsCmdBuf[31] = 'd';
370  _retBpsCmdBuf[32] = 'e';
371  _retBpsCmdBuf[33] = 'f';
372  _retBpsCmdBuf[34] = '0'; //8
373  _retBpsCmdBuf[35] = bpschecksum(_retBpsCmdBuf+1,34);
374  _retBpsCmdBuf[36] = _BPS_EOF;
375 
376  }
377  else if(_BpsCmdBuf[1] == _BPSCMD_Alarm_Enable_Load_Request){
378  _retBpsCmdBuf[2] = _BPSCMD_Alarm_Enable_Load_Answer;
379  _retBpsCmdBuf[3] = '1';
380  _retBpsCmdBuf[4] = '2';
381  _retBpsCmdBuf[5] = '3';
382  _retBpsCmdBuf[6] = '4';
383  _retBpsCmdBuf[7] = bpschecksum(_retBpsCmdBuf+1,6);
384  _retBpsCmdBuf[8] = _BPS_EOF;
385  }
386  else if(_BpsCmdBuf[1] == _BPSCMD_Alarm_Enable_Save_Request){
387  _retBpsCmdBuf[2] = _BPSCMD_Alarm_Enable_Save_Answer;
388  _retBpsCmdBuf[3] = _BpsCmdBuf[2];
389  _retBpsCmdBuf[4] = _BpsCmdBuf[3];
390  _retBpsCmdBuf[5] = _BpsCmdBuf[4];
391  _retBpsCmdBuf[6] = _BpsCmdBuf[5];
392  _retBpsCmdBuf[7] = bpschecksum(_retBpsCmdBuf+1,6);
393  _retBpsCmdBuf[8] = _BPS_EOF;
394  }
395  else if(_BpsCmdBuf[1] == _BPSCMD_Alarm_ClearStatus_Request){
396  _retBpsCmdBuf[2] = _BPSCMD_Alarm_ClearStatus_Answer;
397  _retBpsCmdBuf[3] = '1';
398  _retBpsCmdBuf[4] = '2';
399  _retBpsCmdBuf[5] = '3';
400  _retBpsCmdBuf[6] = '4';
401  _retBpsCmdBuf[7] = bpschecksum(_retBpsCmdBuf+1,6);
402  _retBpsCmdBuf[8] = _BPS_EOF;
403  }
404  else if(_BpsCmdBuf[1] == _BPSCMD_Alarm_Threshold_Load_Request){
405  _retBpsCmdBuf[2] = _BPSCMD_Alarm_Threshold_Load_Answer;
406  _retBpsCmdBuf[3] = '1';
407  _retBpsCmdBuf[4] = '2';
408  _retBpsCmdBuf[5] = '3';
409  _retBpsCmdBuf[6] = '4';
410  _retBpsCmdBuf[7] = '1';
411  _retBpsCmdBuf[8] = '2';
412  _retBpsCmdBuf[9] = '3';
413  _retBpsCmdBuf[10] = '4';
414  _retBpsCmdBuf[11] = bpschecksum(_retBpsCmdBuf+1,10);
415  _retBpsCmdBuf[12] = _BPS_EOF;
416  }
417  else if(_BpsCmdBuf[1] == _BPSCMD_Alarm_Threshold_Save_Request){
418  _retBpsCmdBuf[2] = _BPSCMD_Alarm_Threshold_Save_Answer;
419  _retBpsCmdBuf[3] = _BpsCmdBuf[2];
420  _retBpsCmdBuf[4] = _BpsCmdBuf[3];
421  _retBpsCmdBuf[5] = _BpsCmdBuf[4];
422  _retBpsCmdBuf[6] = _BpsCmdBuf[5];
423  _retBpsCmdBuf[7] = _BpsCmdBuf[6];
424  _retBpsCmdBuf[8] = _BpsCmdBuf[7];
425  _retBpsCmdBuf[9] = _BpsCmdBuf[8];
426  _retBpsCmdBuf[10] = _BpsCmdBuf[9];
427  _retBpsCmdBuf[11] = bpschecksum(_retBpsCmdBuf+1,10);
428  _retBpsCmdBuf[12] = _BPS_EOF;
429  }
430  else if(_BpsCmdBuf[1] == _BPSCMD_ReleToggle_Ixx_Request){
431  _retBpsCmdBuf[2] = _BPSCMD_ReleToggle_Ixx_Answer;
432  _retBpsCmdBuf[3] = 0x31;
433  _retBpsCmdBuf[4] = 0x30;
434  _retBpsCmdBuf[5] = 0x30;
435  _retBpsCmdBuf[6] = 0x30;
436  _retBpsCmdBuf[7] = bpschecksum(_retBpsCmdBuf+1,6);
437  _retBpsCmdBuf[8] = _BPS_EOF;
438  }
439  else if(_BpsCmdBuf[1] == _BPSCMD_PingDevice_Request){
440  _retBpsCmdBuf[2] = _BPSCMD_PingDevice_Answer;
441  _retBpsCmdBuf[3] = '1';
442  _retBpsCmdBuf[4] = '2';
443  _retBpsCmdBuf[5] = '3';
444  _retBpsCmdBuf[6] = '4';
445  _retBpsCmdBuf[7] = bpschecksum(_retBpsCmdBuf+1,6);
446  _retBpsCmdBuf[8] = _BPS_EOF;
447  }
448 
449 
450 #endif
451 
452  /* now fill Answer structure */
453 
454 
455  answ->hf.sof = _retBpsCmdBuf[0];
456  answ->hf.addr = _retBpsCmdBuf[1];
457  answ->hf.cmd = _retBpsCmdBuf[2];
458  answ->pData = &_retBpsCmdBuf[3];
459  answ->hf.chk = _retBpsCmdBuf[3+answ->nData];
460  answ->hf.eof = _retBpsCmdBuf[4+answ->nData];
461 
462 
463 
464  return true;
465 }
466 
467 /* Prepare a given command into the Tx buffer*/
468 int _bpsBufferCmd(BpsCmd* _cmd)
469 {
470  //printf("call: _bpsBufferCmd _cmd.addr %x _cmd.cmd %x _cmd.pData %x _cmd.nData %x\n",_cmd->addr,_cmd->cmd,_cmd->pData,_cmd->nData);
471  assert(_cmd->nData + 2 < BPS_MAX_CMD_LEN);
472  _BpsCmdBuf[0] = _cmd->addr;
473  _BpsCmdBuf[1] = _cmd->cmd;
474  if(_cmd->nData && _cmd->pData)memcpy ( _BpsCmdBuf+2, _cmd->pData, _cmd->nData );
475  //printf("_bpsBufferCmd: _cmd->nData %x _cmd->pData %x \n",_cmd->nData,_cmd->pData);
476  return (_cmd->nData + 2);
477 
478 }
479 
480 /* Check command response (address , command and errors)*/
481 bool _bpsCmdRxCheck(uint8_t answ, BpsAnsw* s_answ)
482 {
483 
484  if(s_answ->hf.sof != _BPS_SOF){
486  return false;
487  }
488 
489  if(s_bpschecksum(s_answ) != s_answ->hf.chk ){
490  //printf("c2 = %x\n",s_bpschecksum(s_answ));
492  return false;
493  }
494  if(s_answ->hf.eof != _BPS_EOF){
496  return false;
497  }
498 
499 
500  if(BPS_ADDR != s_answ->hf.addr){
501  errSet(ERROR(E_BPS_RETADDR));
502  return false;
503  }
504  if(s_answ->hf.cmd == answ) return true;
505 
506  switch(s_answ->hf.cmd){
507  case _BPSCMD_Error_Chk:
508  errSet(ERROR(E_BPS_RETCHK));
509  break;
510  case _BPSCMD_Error_Start:
511  errSet(ERROR(E_BPS_RETSTA));
512  break;
513  case _BPSCMD_Error_Timeout:
514  errSet(ERROR(E_BPS_RETTIM));
515  break;
516  default:
517  errSet(ERROR(E_BPS_RETUNK));
518  break;
519  }
520 
521  return false;
522 }
523 
524 bool _bpsTxAndRx(BpsCmd *pcmd,BpsAnsw* pansw, uint8_t cansw)
525 {
526  //printf("call: _bpsTxAndRx cmd.adr %x cmd.cmd %x cmd.pdata %x cmd.ndata %x \n",pcmd->addr,pcmd->cmd,pcmd->pData,pcmd->nData);
527  _bpsCmdTx (_bpsBufferCmd(pcmd));
528  if(_bpsRxCommand(pansw)) return _bpsCmdRxCheck(cansw,pansw);
529  return false;
530 }
531 
532 
533 uint16_t _bpsHexAscii2Short(uint8_t* input)
534 {
535  int j;
536  char crev[_BPS_USHORT_SIZE];
537  uint32_t lb;
538 
539  for(j=0;j<_BPS_USHORT_SIZE;j++){
540  //crev[j]=input[_BPS_USHORT_SIZE-1-j]; // order is reversed : BPS send from LSB to MSB
541  crev[j]=input[j];
542  // printf("_bpsHexAscii2Short j = %d - %c\n",j,input[_BPS_USHORT_SIZE-1-j]);
543 #ifdef BPSSIM
544 // printf("j = %d - %c\n",j,input[_BPS_USHORT_SIZE-1-j]);
545 #endif
546  }
547 
548  if (cnvParseU(crev, &lb, _hex) == 0)return 0x0;
549 
550  return (uint16_t) (lb & 0xFFFF);
551 }
552 
553 uint8_t _bpsHexAscii2Char(uint8_t* input)
554 {
555  int j;
556  char crev[_BPS_UCHAR_SIZE];
557  uint32_t lb;
558 
559  for(j=0;j<_BPS_UCHAR_SIZE;j++){
560  //crev[j]=input[_BPS_UCHAR_SIZE-1-j]; // order is reversed : BPS send from LSB to MSB
561  crev[j]=input[j];
562  // printf("_bpsHexAscii2Char j = %d - %c\n",j,input[_BPS_USHORT_SIZE-1-j]);
563 #ifdef BPSSIM
564 // printf("j = %d - %c\n",j,input[_BPS_USHORT_SIZE-1-j]);
565 #endif
566  }
567 
568  if (cnvParseU(crev, &lb, _hex) == 0)return 0x0;
569 
570  return (uint8_t) (lb & 0xFFFF);
571 }
572 
573 void _bpsShort2HexAscii(uint16_t sdata, uint8_t* input)
574 {
575  assert(input);
576  char outstring[2*_BPS_USHORT_SIZE]; // safe
577  int j=0;
578  int k;
579 
580 
581  if( cnvFormatU( (int32_t) sdata, outstring,_hex) == 0)return;
582 
583  j=0;
584 
585  //find '\0'
586  while(outstring[j] != '\0' && j<2*_BPS_USHORT_SIZE)
587  {j++;
588 #ifdef BPSSIM
589 
590 #endif
591  }
592 
593  if (j < _BPS_USHORT_SIZE)
594  {
595  for(k=0;k<j;k++){
596  input[k]='0';
597  }
598  for(k=_BPS_USHORT_SIZE-j;k<_BPS_USHORT_SIZE;k++){
599  input[k]=outstring[k+j-_BPS_USHORT_SIZE];
600  }
601 
602  }
603  else
604  {
605 
606  for(k=0;k<_BPS_USHORT_SIZE;k++){
607  input[k]=outstring[k];
608  }
609 
610 
611 #ifdef BPSSIM
612 // printf("k = %d - %d - %c\n",k,j-1-k,input[k]);
613 #endif
614 
615  }
616 
617 }
618 
619 
620 void _bpsChar2HexAscii(uint8_t sdata, uint8_t* input)
621 {
622  assert(input);
623  char outstring[2*_BPS_UCHAR_SIZE]; // safe
624  int j=0;
625  int k;
626 
627 
628  if( cnvFormatU( (int32_t) sdata, outstring,_hex) == 0)return;
629 
630  j=0;
631  //find '\0'
632  while(outstring[j] != '\0' && j<2*_BPS_UCHAR_SIZE)
633  {j++;
634 #ifdef BPSSIM
635 // printf("j = %d - %c\n",j,outstring[j]);
636 #endif
637  }
638 
639  if (j < _BPS_UCHAR_SIZE)
640  {
641  for(k=0;k<j;k++){
642  input[k]='0';
643  }
644 
645  for(k=_BPS_UCHAR_SIZE-j;k<_BPS_UCHAR_SIZE;k++){
646  input[k]=outstring[k+j-_BPS_UCHAR_SIZE];
647  }
648  }
649  else
650  {
651 
652  for(k=0;k<_BPS_UCHAR_SIZE;k++){
653  input[k]=outstring[k];
654  }
655 
656 #ifdef BPSSIM
657 // printf("k = %d - %d - %c\n",k,j-1-k,input[k]);
658 #endif
659  }
660 
661 
662 }
663 
664 
665 bool bpsAlarmTimeOutSaveV3(uint8_t time_out_ch, uint16_t time_out_val){
666 
667  //assert(rdtime_out);
668 
669  uint8_t sData[_BPS_USHORT_SIZE + _BPS_UCHAR_SIZE];
670  //uint16_t rawth[NTHRESHOLD];
671 
672  BpsCmd cmd = BSP_CMD_INIT;
673  cmd.cmd = _BPSCMD_AlarmTimeOut_Save_Request;
674  cmd.nData = _BPS_USHORT_SIZE + _BPS_UCHAR_SIZE;
675  cmd.pData = sData;
676  BpsAnsw ans;
677  //ans.nData = _BPS_USHORT_SIZE + _BPS_UCHAR_SIZE;
678  ans.nData = 0;
679 
680  //printf(" th_alarm_ch %d (%x) hex th_alarm_val %d (%x) hex \n",time_out_ch, time_out_ch, time_out_val, time_out_val);
681 
682  _bpsChar2HexAscii(time_out_ch,sData);
683  // printf(" SData_1 %x SData_2 %x \n",sData[0], sData[1]);
684  _bpsShort2HexAscii(time_out_val,sData+_BPS_UCHAR_SIZE);
685  //printf(" SData_3 %x SData_4 %x ",sData[2], sData[3]);
686  //printf(" SData_5 %x SData_6 %x ",sData[4], sData[5]);
687  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_AlarmTimeOut_Save_Answer))return false;
688 
689  return true;
690 }
691 
692 
693 /*
694 // OK BUT DOESN'T FIT THE ROM
695 bool bpsAlarmTimeOutLoadV3(uint8_t time_out_ch, BpsAlarmTimeOutV3 *rdtout)
696 {
697 
698  assert(rdtout);
699  uint8_t sData[_BPS_UCHAR_SIZE];
700  BpsCmd cmd = BSP_CMD_INIT;
701  cmd.cmd = _BPSCMD_AlarmTimeOut_Load_Request;
702  cmd.nData = _BPS_UCHAR_SIZE;
703  cmd.pData = sData;
704  BpsAnsw ans;
705  //int i;
706  //uint16_t rawth[NTHRESHOLD];
707 
708 
709  //ans.nData = SIZE_THRESHOLD;
710  ans.nData = 6;
711 
712  //printf(" Call: bpsAlarmTimeOutLoadV3 read channel: %d (%x) hex \n",time_out_ch,time_out_ch);
713  _bpsChar2HexAscii(time_out_ch,sData);
714 
715 
716  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_AlarmTimeOut_Load_Answer))return false;
717 
718  // tout_ch = _bpsHexAscii2Char(ans.pData);
719  // tout_val= _bpsHexAscii2Short(ans.pData+_BPS_UCHAR_SIZE);
720 
721  rdtout->timeout_ch = _bpsHexAscii2Char(ans.pData);
722  rdtout->timeout_val = _bpsHexAscii2Short(ans.pData+_BPS_UCHAR_SIZE);
723 
724  //printf("time_out ch = %d\n",rdtout->timeout_ch);
725  //printf("time_out Val = %d\n",rdtout->timeout_val);
726 
727  return true;
728 }
729 
730 */
731 
732 
733 bool bpsReadSensorSingleV3(uint8_t single_var, BpsRdSingleAnswV3* stat){
734 
735  assert(stat);
736  uint8_t sData[_BPS_UCHAR_SIZE];
737  BpsCmd cmd = BSP_CMD_INIT;
738  cmd.cmd = _BPSCMD_ReadSensorsSingle_Request;
739  cmd.nData = _BPS_UCHAR_SIZE;
740  cmd.pData = sData;
741  BpsAnsw ans;
742  uint8_t pvar;
743  uint16_t pRet[4];
744  int i;
745 
746  ans.nData = 18;
747 
748  // printf(" Call: bpsReadSensorSingleV3 Variable: %d (%x) hex \n",single_var, single_var);
749  _bpsChar2HexAscii(single_var,sData);
750 
751  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_ReadSensorsSingle_Answer))return false;
752 
753  pvar = _bpsHexAscii2Char(ans.pData);
754 
755  for(i=0;i<4;i++){ // i loop are over any status word (4 bytes)
756  pRet[i] = _bpsHexAscii2Short(ans.pData+_BPS_UCHAR_SIZE+i*_BPS_USHORT_SIZE);
757  // printf("i %d pRet %x \n",i,pRet[i]); //--Stefano
758  }
759 
760  stat->single_var_num = pvar;
761  stat->single_value = pRet[0];
762  stat->single_offset = pRet[1];
763  stat->single_maxval = pRet[2];
764  stat->single_meanval = pRet[3];
765 
766  //printf(" bpsReadSensorSingle done\n");
767 
768  return true;
769 
770 
771 }
772 
774 
775  assert(stat);
776  BpsCmd cmd = BSP_CMD_INIT;
777  cmd.cmd = _BPSCMD_ReadSensorsAverage_Request;
778  BpsAnsw ans;
779  uint16_t pRet[8];
780  int i;
781 
782  ans.nData = 32;
783 
784  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_ReadSensorsAverage_Answer))return false;
785 
786  for(i=0;i<8;i++){ // i loop are over any status word (4 bytes)
787 
788  pRet[i] = _bpsHexAscii2Short(ans.pData+i*_BPS_USHORT_SIZE);
789  //printf("i %d pRet %x \n",i,pRet[i]); //--Stefano
790  }
791 
792  stat->mon_5V_i_M = pRet[0];
793  stat->mon_LBL_i_M = pRet[1];
794  stat->mon_DU_i_M = pRet[2];
795  stat->mon_DU_irtn_M = pRet[3];
796  stat->mon_BPS_v_M = pRet[4];
797  stat->mon_HYDRO_i_M = pRet[5];
798  stat->mon_MON_THEATSINK_M = pRet[6];
799  stat->mon_TBOARD_M = pRet[7];
800 
801 
802  //printf(" bpsReadSensorAverage done\n");
803 
804  return true;
805 
806 
807 }
808 
809 
811 
812  assert(stat);
813  BpsCmd cmd = BSP_CMD_INIT;
814  cmd.cmd = _BPSCMD_ReadSensors_Request;
815  BpsAnsw ans;
816  uint16_t pRet[8];
817  uint8_t pRet2[4];
818  int i;
819 
820  ans.nData = 40;
821 
822  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_ReadSensors_Answer))return false;
823 
824  for(i=0;i<8;i++){ // i loop are over any status word (4 bytes)
825 
826  pRet[i] = _bpsHexAscii2Short(ans.pData+i*_BPS_USHORT_SIZE);
827  // printf("i %d pRet %x \n",i,pRet[i]); //--Stefano
828  }
829 
830  for(i=0;i<4;i++){ // i loop are over any status word (4 bytes)
831 
832  pRet2[i] = _bpsHexAscii2Char(ans.pData+8*_BPS_USHORT_SIZE+i*_BPS_UCHAR_SIZE);
833  // printf("i %d pRet2 %x \n",i,pRet2[i]); //--Stefano
834  }
835 
836  stat->mon_5V_i = pRet[0];
837  stat->mon_LBL_i = pRet[1];
838  stat->mon_DU_i = pRet[2];
839  stat->mon_DU_irtn = pRet[3];
840  stat->mon_BPS_v = pRet[4];
841  stat->mon_HYDRO_i = pRet[5];
842  stat->mon_MON_THEATSINK = pRet[6];
843  stat->mon_TBOARD = pRet[7];
844  stat->mon_ALRMPOS1 = pRet2[0];
845  stat->mon_ALRMPOS2 = pRet2[1];
846  stat->mon_ALRMNEG1 = pRet2[2];
847  stat->mon_ALRMNEG2 = pRet2[3];
848 
849  //printf(" bpsReadSensor done\n");
850 
851  return true;
852 
853 
854 }
855 
856 
858 
859  assert(stat);
860  BpsCmd cmd = BSP_CMD_INIT;
861  cmd.cmd = _BPSCMD_ReadSensorsMax_Request;
862  BpsAnsw ans;
863  uint16_t pRet[8];
864  uint8_t pRet2[4];
865  int i;
866 
867  ans.nData = 40;
868 
869  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_ReadSensorsMax_Answer))return false;
870 
871  for(i=0;i<8;i++){ // i loop are over any status word (4 bytes)
872 
873  pRet[i] = _bpsHexAscii2Short(ans.pData+i*_BPS_USHORT_SIZE);
874  // printf("i %d pRet %x \n",i,pRet[i]);
875  }
876 
877  for(i=0;i<4;i++){ // i loop are over any status word (4 bytes)
878 
879  pRet2[i] = _bpsHexAscii2Char(ans.pData+8*_BPS_USHORT_SIZE+i*_BPS_UCHAR_SIZE);
880  // printf("i %d pRet2 %x \n",i,pRet2[i]);
881  }
882 
883  stat->mon_5V_i = pRet[0];
884  stat->mon_LBL_i = pRet[1];
885  stat->mon_DU_i = pRet[2];
886  stat->mon_DU_irtn = pRet[3];
887  stat->mon_BPS_v = pRet[4];
888  stat->mon_HYDRO_i = pRet[5];
889  stat->mon_MON_THEATSINK = pRet[6];
890  stat->mon_TBOARD = pRet[7];
891  stat->mon_ALRMPOS1 = pRet2[0];
892  stat->mon_ALRMPOS2 = pRet2[1];
893  stat->mon_ALRMNEG1 = pRet2[2];
894  stat->mon_ALRMNEG2 = pRet2[3];
895 
896  //printf(" bpsReadSensorMaxV3 done\n");
897 
898  return true;
899 
900 
901 }
902 
903 /*
904 // OK BUT DOESN'T FIT THE ROM
905 bool bpsReadVersion(BpsRdVersionV3* stat){
906 
907  assert(stat);
908  BpsCmd cmd = BSP_CMD_INIT;
909  cmd.cmd = _BPSCMD_ReadVersion_Request;
910  BpsAnsw ans;
911  uint16_t pRet[2];
912  uint8_t pRet2[5];
913  int i;
914 
915  ans.nData = 18;
916 
917  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_ReadVersion_Answer))return false;
918 
919  for(i=0;i<2;i++){ // i loop are over any status word (4 bytes)
920 
921  pRet[i] = _bpsHexAscii2Short(ans.pData+i*_BPS_USHORT_SIZE);
922  //printf("i %d pRet %d (%x) \n",i,pRet[i],pRet[i]);
923  }
924 
925  for(i=0;i<5;i++){ //
926 
927  pRet2[i] = _bpsHexAscii2Char(ans.pData+2*_BPS_USHORT_SIZE+i*_BPS_UCHAR_SIZE);
928  //printf("i %d pRet %d (%x) \n",i,pRet2[i],pRet2[i]);
929  }
930 
931  stat->ver = pRet[0];
932  stat->year = pRet[1];
933  stat->month = pRet2[0];
934  stat->day = pRet2[1];
935  stat->hour = pRet2[2];
936  stat->minute = pRet2[3];
937  stat->second = pRet2[4];
938 
939  //printf(" bpsReadVersion done\n");//--Stefano
940 
941  return true;
942 
943 
944 }
945 */
946 
947 
948 // OK BUT DOESN'T FIT THE ROM
949 
950 bool bpsAlarmThLoadV3(uint8_t th_channel, BspThV3 *th)
951 {
952  assert(th);
953  uint8_t sData[_BPS_UCHAR_SIZE];
954  BpsCmd cmd = BSP_CMD_INIT;
955  cmd.cmd = _BPSCMD_Alarm_Threshold_Load_Request;
956  cmd.nData = _BPS_UCHAR_SIZE;
957  cmd.pData = sData;
958  BpsAnsw ans;
959  int i;
960  uint16_t rawth[NTHRESHOLD];
961  uint8_t th_alarm_ch;
962  uint16_t th_alarm_val;
963 
964 
965  //ans.nData = SIZE_THRESHOLD;
966  ans.nData = 6;
967 
968  //printf(" Call: bpsAlarmThLoadV3 read channel: %d (%x) hex \n",th_channel,th_alarm_ch);
969  _bpsChar2HexAscii(th_channel,sData);
970 
971 
972  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_Alarm_Threshold_Load_Answer))return false;
973 
974  th_alarm_ch = _bpsHexAscii2Char(ans.pData);
975  th_alarm_val= _bpsHexAscii2Short(ans.pData+_BPS_UCHAR_SIZE);
976 
977  //printf("Th_Alarm ch = %d\n",th_alarm_ch);
978  //printf("TH Alarm Val = %d\n",th_alarm_val);
979 
980  th->thr_alarm_ch = th_alarm_ch ;
981  th->thr_alarm_val = th_alarm_val;
982 
983 
984 
985  return true;
986 }
987 
988 
989 // OK BUT DOESN'T FIT THE ROM
990 
991 bool bpsAlarmThSaveV3(uint8_t al_th_ch, uint16_t al_th_val){
992  //assert(th);
993 
994  uint8_t sData[_BPS_USHORT_SIZE + _BPS_UCHAR_SIZE];
995  int i;
996  //uint8_t th_alarm_ch;
997  //uint16_t th_alarm_val;
998 
999  BpsCmd cmd = BSP_CMD_INIT;
1000  cmd.cmd = _BPSCMD_Alarm_Threshold_Save_Request;
1001  cmd.nData = _BPS_USHORT_SIZE + _BPS_UCHAR_SIZE;
1002  cmd.pData = sData;
1003  BpsAnsw ans;
1004  ans.nData = 0;
1005 
1006  _bpsChar2HexAscii(al_th_ch,sData);
1007  _bpsShort2HexAscii(al_th_val,sData+_BPS_UCHAR_SIZE);
1008  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_Alarm_Threshold_Save_Answer))return false;
1009 
1010  return true;
1011 }
1012 
1013 
1014 bool bpsSwitchControlV3(uint8_t ch, uint8_t val, SwCtrlV3* sw_rd){
1015 
1016  assert(sw_rd);
1017 
1018  uint8_t sData[2*_BPS_UCHAR_SIZE];
1019  int i;
1020 
1021  BpsCmd cmd = BSP_CMD_INIT;
1022  cmd.cmd = _BPSCMD_SwitchControl_Request;
1023  cmd.nData = 2*_BPS_UCHAR_SIZE;
1024  cmd.pData = sData;
1025  BpsAnsw ans;
1026  ans.nData = 2*_BPS_UCHAR_SIZE;
1027 
1028  //printf(" sw_ch %d (%x) hex sw_val %d (%x) hex \n",ch, ch, val, val);
1029 
1030  _bpsChar2HexAscii(ch,sData);
1031  //printf(" SData_1 %x SData_2 %x \n",sData[0], sData[1]);
1032  _bpsChar2HexAscii(val,sData+_BPS_UCHAR_SIZE);
1033  //printf(" SData_3 %x SData_4 %x ",sData[2], sData[3]);
1034  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_SwitchControl_Answer))return false;
1035 
1036  sw_rd->sw_control_ch = _bpsHexAscii2Char(ans.pData);
1037  sw_rd->sw_control_val = _bpsHexAscii2Char(ans.pData+_BPS_UCHAR_SIZE);
1038 
1039  //printf("Sw_control ch = %x\n", sw_rd->sw_control_ch);
1040  //printf("Sw_control = %x\n", sw_rd->sw_control_val);
1041 
1042 
1043  return true;
1044 }
1045 
1046 
1047 bool bpsAlarmFiredGetV3(uint8_t ch, BpsAlarmV3* AlarmFiredGet){
1048 
1049  assert(AlarmFiredGet);
1050 
1051  uint8_t sData[_BPS_UCHAR_SIZE];
1052  BpsCmd cmd = BSP_CMD_INIT;
1053  cmd.cmd = _BPSCMD_Alarm_Fired_Get_Request;
1054  cmd.nData = _BPS_UCHAR_SIZE;
1055  cmd.pData = sData;
1056  BpsAnsw ans;
1057  ans.nData = 2*_BPS_UCHAR_SIZE;
1058 
1059  _bpsChar2HexAscii(ch,sData);
1060 
1061  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_Alarm_Fired_Get_Answer))return false;
1062 
1063  AlarmFiredGet->alarm_ch = _bpsHexAscii2Char(ans.pData) ;
1064  AlarmFiredGet->alarm_val = _bpsHexAscii2Char(ans.pData+_BPS_UCHAR_SIZE);
1065  /*
1066  printf("alarm_fired_get ch = %x\n",AlarmFiredGet->alarm_ch);
1067  printf("alarm_fired_get val = %x\n",AlarmFiredGet->alarm_val);
1068  */
1069 
1070  return true;
1071 }
1072 
1073 
1074 bool bpsAlarmEnV3(uint8_t ch, uint8_t val, BpsAlarmV3* AlarmEn_rd){
1075 
1076  assert(AlarmEn_rd);
1077 
1078  uint8_t sData[2*_BPS_UCHAR_SIZE];
1079  int i;
1080 
1081  BpsCmd cmd = BSP_CMD_INIT;
1082  cmd.cmd = _BPSCMD_AlarmEnable_Request;
1083  cmd.nData = 2*_BPS_UCHAR_SIZE;
1084  cmd.pData = sData;
1085  BpsAnsw ans;
1086  ans.nData = 2*_BPS_UCHAR_SIZE;
1087 
1088  //printf(" alarm_en_ch %d (%x) hex alarm_en_val %d (%x) hex \n",ch, ch, val, val);
1089 
1090  _bpsChar2HexAscii(ch,sData);
1091  //printf(" SData_1 %x SData_2 %x \n",sData[0], sData[1]);
1092  _bpsChar2HexAscii(val,sData+_BPS_UCHAR_SIZE);
1093  //printf(" SData_3 %x SData_4 %x ",sData[2], sData[3]);
1094  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_AlarmEnable_Answer))return false;
1095 
1096  AlarmEn_rd->alarm_ch = _bpsHexAscii2Char(ans.pData) ;
1097  AlarmEn_rd->alarm_val = _bpsHexAscii2Char(ans.pData+_BPS_UCHAR_SIZE);
1098 
1099  // printf("alarm_en ch = %x\n",AlarmEn_rd->alarm_ch);
1100  // printf("alarm_en_val = %x\n",AlarmEn_rd->alarm_val );
1101 
1102 
1103  return true;
1104 }
1105 
1106 bool bpsRescueEnable(uint8_t set_val, uint8_t* rd_val){
1107  assert(rd_val);
1108  uint8_t sData[_BPS_UCHAR_SIZE];
1109  BpsCmd cmd = BSP_CMD_INIT;
1110  cmd.cmd = _BPSCMD_Rescue_Enable_Request;
1111  cmd.nData = _BPS_UCHAR_SIZE;
1112  cmd.pData = sData;
1113  BpsAnsw ans;
1114  ans.nData = _BPS_UCHAR_SIZE;
1115 
1116  //printf(" RescueEnable %d (%x) hex \n",set_val, set_val);
1117 
1118  _bpsChar2HexAscii(set_val,sData);
1119  //printf(" SData %x \n",sData[0]);
1120 
1121  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_Rescue_Enable_Answer))return false;
1122 
1123  *rd_val = _bpsHexAscii2Char(ans.pData) ;
1124  //printf("RescueEnable read_val = %x\n",*rd_val);
1125 
1126  return true;
1127 }
1128 
1129 
1130 bool bpsSensorMaxvalueReset(uint8_t set_val){
1131  uint8_t sData[_BPS_UCHAR_SIZE];
1132  BpsCmd cmd = BSP_CMD_INIT;
1133  cmd.cmd = _BPSCMD_SensorMaxvalueReset_Request;
1134  cmd.nData = _BPS_UCHAR_SIZE;
1135  cmd.pData = sData;
1136  BpsAnsw ans;
1137  ans.nData = 0;
1138 
1139  //printf(" SensorMaxvalueReset %d (%x) hex \n",set_val, set_val);
1140 
1141  _bpsChar2HexAscii(set_val,sData);
1142  //printf(" SData %x \n",sData[0]);
1143 
1144  if(!_bpsTxAndRx(&cmd, &ans, _BPSCMD_SensorMaxvalueReset_Answer))return false;
1145  //printf("SensorMaxvalueReset _done \n");
1146 
1147  return true;
1148 }
1149 
1150 
1151 
1152 /*
1153 bool bpsPingDevice(uint16_t *fw){
1154 
1155  assert(fw);
1156 
1157  BpsCmd cmd = BSP_CMD_INIT;
1158  cmd.cmd = _BPSCMD_PingDevice_Request;
1159  BpsAnsw ans;
1160  ans.nData = sizeof(uint8_t);
1161 
1162  if(!_bpsTxAndRx(&cmd,&ans, _BPSCMD_PingDevice_Answer))return false;
1163 
1164 
1165  *fw = (uint16_t) (ans.pData[0] & 0xFF);
1166 
1167 
1168  return true;
1169 }
1170 */
1171 
1172 bool bpsDbgCmdReply(uint8_t cmdCode, uint8_t * cmdPData, uint8_t cmdNData,
1173  uint8_t rplCode, uint8_t ** rplPData, uint8_t rplNData)
1174 {
1175  BpsCmd cmd = BSP_CMD_INIT ;
1176  BpsAnsw ans;
1177  cmd.cmd = cmdCode;
1178  cmd.pData = cmdPData;
1179  cmd.nData = cmdNData;
1180  ans.nData = rplNData;
1181 
1182  if (!_bpsTxAndRx(&cmd, &ans, rplCode)) return false;
1183 
1184  *rplPData = ans.pData;
1185 
1186  return true;
1187 }
1188 
1189 
1190 
int cnvFormatU(int32_t input, char *output, CnvParams params)
Formats an unsigned integer into a character buffer.
Definition: convert.c:137
bool bpsSwitchControlV3(uint8_t ch, uint8_t val, SwCtrlV3 *sw_rd)
switch control
Definition: bps_v3.c:1014
bool bpsReadSensorMaxV3(BpsRdSensAnswV3 *stat)
return all sensors&#39; max values
Definition: bps_v3.c:857
bool bpsRescueEnable(uint8_t set_val, uint8_t *rd_val)
Version.
Definition: bps_v3.c:1106
bool bpsAlarmFiredGetV3(uint8_t ch, BpsAlarmV3 *AlarmFiredGet)
Return flag of one alarm.
Definition: bps_v3.c:1047
static bool bfEmpty(ByteFifo *const bf)
Returns whether or not the byte-fifo is empty.
Definition: bytefifo.h:72
bool bpsDbgCmdReply(uint8_t cmdCode, uint8_t *cmdPData, uint8_t cmdNData, uint8_t rplCode, uint8_t **rplPData, uint8_t rplNData)
Exposes the low-level interface to the BPS.
Definition: bps.c:788
static void __irqEnable()
Enabled IRQ&#39;s on a global level.
Definition: lm32.h:75
int cnvParseU(const char *input, uint32_t *output, CnvParams params)
Parse an unsigned integer.
Definition: convert.c:61
static void __irqDisable()
Disables IRQ&#39;s on a global level.
Definition: lm32.h:62
bool bpsSensorMaxvalueReset(uint8_t set_val)
SENSOR_MAXVALUE_RESET set_val : Variable number.
Definition: bps_v3.c:1130
Definition: bps.c:90
bool bpsAlarmTimeOutSaveV3(uint8_t time_out_ch, uint16_t time_out_val)
Set the threshold value of one analog alarm.
Definition: bps_v3.c:665
#define E_BPS_TIMEOUT
Receive timeout.
Definition: bps.h:31
static uint32_t timeOutInit(uint32_t msec)
Initializes a timeout with the specified no of msecs.
Definition: tm.h:53
static bool timeOut(uint32_t to)
Checks whether or not the timeout has expired.
Definition: tm.h:77
Manages the global system error.
Definition: bps.c:82
This structure provides information about formatting and parsing.
Definition: convert.h:37
bool bpsReadSensorAverageV3(BpsRdSensAverageAnswV3 *stat)
return all sensors&#39; mean values
Definition: bps_v3.c:773
Simple timer functions.
Definition: bps.c:75
#define E_BPS_NOSOF
no EOF received when expected
Definition: bps.h:55
#define E_BPS_CHKERR
bad checksum received
Definition: bps.h:34
BPS Uart driver (.
bool bfRead(ByteFifo *const bf, uint8_t *const b)
Reads a byte from the byte-fifo.
Definition: bytefifo.c:28
#define E_BPS_NOEOF
no EOF received when expected
Definition: bps.h:37
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).
bool suartTx(SUART_Descriptor *desc, char c)
Transmits a character.
Definition: suart.c:58
bool bpsReadSensorV3(BpsRdSensAnswV3 *stat)
return all sensors&#39; values
Definition: bps_v3.c:810
bool bpsAlarmEnV3(uint8_t ch, uint8_t val, BpsAlarmV3 *AlarmEn_rd)
Return current enable status.
Definition: bps_v3.c:1074
This module implements parsing and formating of strings and integers.
bool bpsReadSensorSingleV3(uint8_t single_var, BpsRdSingleAnswV3 *stat)
return one sensor&#39;s current value, offset, max, mean value
Definition: bps_v3.c:733