comparison Small_CPU/Src/uart.c @ 714:045ff7800501

Added customizable data area for specific sensor data: In future smart sensors will be connected via UART interface. These sensor provide additional data like diagnostics or id numbers which may vary from sensor to sensor. That's why a byte array has been added which stores up to 32 bytes. The layout of this array may be specific to sensor needs. As first example temperature and id number of the DiveO2 sensor are provided.
author Ideenmodellierer
date Sun, 20 Nov 2022 20:42:08 +0100
parents f1b40364b0af
children fceae45b3a69
comparison
equal deleted inserted replaced
713:1fbcca5bdf5d 714:045ff7800501
36 static uint8_t rxWriteIndex; /* Index of the data item which is analysed */ 36 static uint8_t rxWriteIndex; /* Index of the data item which is analysed */
37 static uint8_t rxReadIndex; /* Index at which new data is stared */ 37 static uint8_t rxReadIndex; /* Index at which new data is stared */
38 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */ 38 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */
39 static uint8_t dmaActive; /* Indicator if DMA receiption needs to be started */ 39 static uint8_t dmaActive; /* Indicator if DMA receiption needs to be started */
40 40
41 static SSensorDataDiveO2 sensorDataDiveO2; /* intermediate storage for additional sensor data */
42
41 char tmpRxBuf[30]; 43 char tmpRxBuf[30];
42 uint8_t tmpRxIdx = 0; 44 uint8_t tmpRxIdx = 0;
43 45
44 static uartO2Status_t Comstatus_O2 = UART_O2_INIT; 46 static uartO2Status_t Comstatus_O2 = UART_O2_INIT;
45
46 static uint32_t DigitalO2ID = 0;
47 47
48 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */ 48 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */
49 float LED_ZeroOffset = 0.0; 49 float LED_ZeroOffset = 0.0;
50 float pCO2 = 0.0; 50 float pCO2 = 0.0;
51 /* Exported functions --------------------------------------------------------*/ 51 /* Exported functions --------------------------------------------------------*/
398 cmdString[*cmdLength] = 0x0D; 398 cmdString[*cmdLength] = 0x0D;
399 *cmdLength = *cmdLength + 1; 399 *cmdLength = *cmdLength + 1;
400 } 400 }
401 } 401 }
402 402
403 void StringToInt(char *pstr, uint32_t *pInt) 403 void StringToInt(char *pstr, uint32_t *puInt32)
404 { 404 {
405 uint8_t index = 0; 405 uint8_t index = 0;
406 uint32_t result = 0; 406 uint32_t result = 0;
407 while((pstr[index] >= '0') && (pstr[index] <= '9')) 407 while((pstr[index] >= '0') && (pstr[index] <= '9'))
408 { 408 {
409 result *=10; 409 result *=10;
410 result += pstr[index] - '0'; 410 result += pstr[index] - '0';
411 index++; 411 index++;
412 } 412 }
413 *pInt = result; 413 *puInt32 = result;
414 }
415
416 void StringToUInt64(char *pstr, uint64_t *puint64)
417 {
418 uint8_t index = 0;
419 uint64_t result = 0;
420 while((pstr[index] >= '0') && (pstr[index] <= '9'))
421 {
422 result *=10;
423 result += pstr[index] - '0';
424 index++;
425 }
426 *puint64 = result;
414 } 427 }
415 428
416 void HandleUARTDigitalO2(void) 429 void HandleUARTDigitalO2(void)
417 { 430 {
418 static uint32_t lastO2ReqTick = 0; 431 static uint32_t lastO2ReqTick = 0;
433 446
434 447
435 if(Comstatus_O2 == UART_O2_INIT) 448 if(Comstatus_O2 == UART_O2_INIT)
436 { 449 {
437 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); 450 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE);
451 memset((char*) &sensorDataDiveO2, 0, sizeof(sensorDataDiveO2));
452 externalInterface_SetSensorData(0,(uint8_t*)&sensorDataDiveO2);
453
438 lastAlive = 0; 454 lastAlive = 0;
439 curAlive = 0; 455 curAlive = 0;
440 456
441 Comstatus_O2 = UART_O2_CHECK; 457 Comstatus_O2 = UART_O2_CHECK;
442 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); 458 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength);
481 { 497 {
482 tmpRxIdx = 0; 498 tmpRxIdx = 0;
483 memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf)); 499 memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf));
484 switch (Comstatus_O2) 500 switch (Comstatus_O2)
485 { 501 {
486 case UART_O2_CHECK: Comstatus_O2 = UART_O2_REQ_INFO; 502 case UART_O2_CHECK: Comstatus_O2 = UART_O2_REQ_ID;
503 rxState = O2RX_CONFIRM;
487 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); 504 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength);
488 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); 505 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10);
489 break; 506 break;
490 case UART_O2_REQ_ID: rxState = O2RX_GETNR; 507 case UART_O2_REQ_ID: rxState = O2RX_GETNR;
491 break; 508 break;
532 549
533 case O2RX_GETO2: StringToInt(tmpRxBuf,&tmpO2); 550 case O2RX_GETO2: StringToInt(tmpRxBuf,&tmpO2);
534 setExternalInterfaceChannel(0,(float)(tmpO2 / 10000.0)); 551 setExternalInterfaceChannel(0,(float)(tmpO2 / 10000.0));
535 rxState = O2RX_GETTEMP; 552 rxState = O2RX_GETTEMP;
536 break; 553 break;
537 case O2RX_GETTEMP: rxState = O2RX_GETSTATUS; 554 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.temperature);
555 rxState = O2RX_GETSTATUS;
538 break; 556 break;
539 default: 557 default:
540 break; 558 break;
541 } 559 }
542 memset((char*) tmpRxBuf, 0, tmpRxIdx); 560 memset((char*) tmpRxBuf, 0, tmpRxIdx);
546 } 564 }
547 else 565 else
548 { 566 {
549 switch (rxState) 567 switch (rxState)
550 { 568 {
551 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&tmpData); 569 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&sensorDataDiveO2.status);
570 externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2);
552 Comstatus_O2 = UART_O2_IDLE; 571 Comstatus_O2 = UART_O2_IDLE;
553 rxState = O2RX_IDLE; 572 rxState = O2RX_IDLE;
554 break; 573 break;
555 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData); 574 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData);
556 Comstatus_O2 = UART_O2_IDLE; 575 Comstatus_O2 = UART_O2_IDLE;
557 rxState = O2RX_IDLE; 576 rxState = O2RX_IDLE;
558 break; 577 break;
559 case O2RX_GETNR: StringToInt((char*)rxBuffer,&DigitalO2ID); 578 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&sensorDataDiveO2.sensorId);
560 /* no break */ 579 /* no break */
561 default: Comstatus_O2 = UART_O2_IDLE; 580 default: Comstatus_O2 = UART_O2_IDLE;
562 rxState = O2RX_IDLE; 581 rxState = O2RX_IDLE;
563 break; 582 break;
564 } 583 }