comparison Small_CPU/Src/uart.c @ 721:fceae45b3a69

DigO2 added raw data request: Beside ppO2 the Digo2 also offers raw data like humidity, pressure or signal intensity. These information may be of interest for diagnostic functions and have been added to the protocol support function.
author Ideenmodellierer
date Thu, 05 Jan 2023 18:22:21 +0100
parents 045ff7800501
children 621265ec3d23
comparison
equal deleted inserted replaced
720:4f70155362d2 721:fceae45b3a69
24 #include "data_exchange.h" 24 #include "data_exchange.h"
25 #include <string.h> /* memset */ 25 #include <string.h> /* memset */
26 26
27 /* Private variables ---------------------------------------------------------*/ 27 /* Private variables ---------------------------------------------------------*/
28 28
29 #define CHUNK_SIZE (20u) /* the DMA will handle chunk size transfers */ 29 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */
30 #define CHUNKS_PER_BUFFER (3u) 30 #define CHUNKS_PER_BUFFER (5u)
31 UART_HandleTypeDef huart1; 31 UART_HandleTypeDef huart1;
32 32
33 DMA_HandleTypeDef hdma_usart1_rx; 33 DMA_HandleTypeDef hdma_usart1_rx;
34 34
35 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */ 35 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */
387 break; 387 break;
388 case UART_O2_REQ_ID: *cmdLength = snprintf((char*)cmdString, 10, "#IDNR"); 388 case UART_O2_REQ_ID: *cmdLength = snprintf((char*)cmdString, 10, "#IDNR");
389 break; 389 break;
390 case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY"); 390 case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY");
391 break; 391 break;
392 392 case UART_O2_REQ_RAW: *cmdLength = snprintf((char*)cmdString, 10, "#DRAW");
393 break;
393 default: *cmdLength = 0; 394 default: *cmdLength = 0;
394 break; 395 break;
395 } 396 }
396 if(*cmdLength != 0) 397 if(*cmdLength != 0)
397 { 398 {
470 if(time_elapsed_ms(lastO2ReqTick,tick) > 1000) /* repeat request once per second */ 471 if(time_elapsed_ms(lastO2ReqTick,tick) > 1000) /* repeat request once per second */
471 { 472 {
472 lastO2ReqTick = tick; 473 lastO2ReqTick = tick;
473 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */ 474 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */
474 { 475 {
475 Comstatus_O2 = UART_O2_REQ_O2; 476 Comstatus_O2 = UART_O2_REQ_RAW;
476 rxState = O2RX_CONFIRM; 477 rxState = O2RX_CONFIRM;
477 } 478 }
478 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); 479 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength);
479 480
480 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); 481 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10);
506 break; 507 break;
507 case UART_O2_REQ_ID: rxState = O2RX_GETNR; 508 case UART_O2_REQ_ID: rxState = O2RX_GETNR;
508 break; 509 break;
509 case UART_O2_REQ_INFO: rxState = O2RX_GETTYPE; 510 case UART_O2_REQ_INFO: rxState = O2RX_GETTYPE;
510 break; 511 break;
512 case UART_O2_REQ_RAW:
511 case UART_O2_REQ_O2: rxState = O2RX_GETO2; 513 case UART_O2_REQ_O2: rxState = O2RX_GETO2;
512 break; 514 break;
513 default: Comstatus_O2 = UART_O2_IDLE; 515 default: Comstatus_O2 = UART_O2_IDLE;
514 rxState = O2RX_IDLE; 516 rxState = O2RX_IDLE;
515 break; 517 break;
523 case O2RX_GETTYPE: 525 case O2RX_GETTYPE:
524 case O2RX_GETVERSION: 526 case O2RX_GETVERSION:
525 case O2RX_GETCHANNEL: 527 case O2RX_GETCHANNEL:
526 case O2RX_GETSUBSENSORS: 528 case O2RX_GETSUBSENSORS:
527 case O2RX_GETO2: 529 case O2RX_GETO2:
528 case O2RX_GETNR: if(rxBuffer[localRX] != 0x0D) 530 case O2RX_GETNR:
531 case O2RX_GETDPHI:
532 case O2RX_INTENSITY:
533 case O2RX_AMBIENTLIGHT:
534 case O2RX_PRESSURE:
535 case O2RX_HUMIDITY:
536 if(rxBuffer[localRX] != 0x0D)
529 { 537 {
530 if(rxBuffer[localRX] != ' ') 538 if(rxBuffer[localRX] != ' ')
531 { 539 {
532 tmpRxBuf[tmpRxIdx++] = rxBuffer[localRX]; 540 tmpRxBuf[tmpRxIdx++] = rxBuffer[localRX];
533 } 541 }
552 rxState = O2RX_GETTEMP; 560 rxState = O2RX_GETTEMP;
553 break; 561 break;
554 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.temperature); 562 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.temperature);
555 rxState = O2RX_GETSTATUS; 563 rxState = O2RX_GETSTATUS;
556 break; 564 break;
565 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&sensorDataDiveO2.status); /* raw data cycle */
566 rxState = O2RX_GETDPHI;
567 break;
568 case O2RX_GETDPHI: /* ignored to save memory and most likly irrelevant for diver */
569 rxState = O2RX_INTENSITY;
570 break;
571 case O2RX_INTENSITY: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.intensity); /* raw data cycle */
572 rxState = O2RX_AMBIENTLIGHT;
573 break;
574 case O2RX_AMBIENTLIGHT: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.ambient); /* raw data cycle */
575 rxState = O2RX_PRESSURE;
576 break;
577 case O2RX_PRESSURE: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.pressure); /* raw data cycle */
578 rxState = O2RX_HUMIDITY;
579 break;
557 default: 580 default:
558 break; 581 break;
559 } 582 }
560 memset((char*) tmpRxBuf, 0, tmpRxIdx); 583 memset((char*) tmpRxBuf, 0, tmpRxIdx);
561 tmpRxIdx = 0; 584 tmpRxIdx = 0;
573 break; 596 break;
574 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData); 597 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData);
575 Comstatus_O2 = UART_O2_IDLE; 598 Comstatus_O2 = UART_O2_IDLE;
576 rxState = O2RX_IDLE; 599 rxState = O2RX_IDLE;
577 break; 600 break;
601 case O2RX_HUMIDITY: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.humidity); /* raw data cycle */
602 externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2);
603 Comstatus_O2 = UART_O2_IDLE;
604 rxState = O2RX_IDLE;
605 break;
578 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&sensorDataDiveO2.sensorId); 606 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&sensorDataDiveO2.sensorId);
579 /* no break */ 607 /* no break */
580 default: Comstatus_O2 = UART_O2_IDLE; 608 default: Comstatus_O2 = UART_O2_IDLE;
581 rxState = O2RX_IDLE; 609 rxState = O2RX_IDLE;
582 break; 610 break;