sensor_lib.c
Go to the documentation of this file.
1 
63 /*---- "module header" ----------------------------------------------------------------*/
64 #include "toposens/sensor_lib.h"
65 #include "toposens/uart_wrapper.h"
66 /*---- <system includes> --------------------------------------------------------------*/
67 #include <endian.h>
68 #include <pthread.h>
69 #include <semaphore.h>
70 #include <stdio.h>
71 #include <stdlib.h>
72 #include <string.h>
73 #include <unistd.h>
74 /*---- "library includes" -------------------------------------------------------------*/
75 
76 /*---- "project includes" -------------------------------------------------------------*/
77 
78 #ifdef __linux__
79 #ifdef CAN_AVAILABLE
81 #endif
82 #ifdef UART_AVAILABLE
84 
85 #endif
86 #endif
87 
88 /*---- local macros and constants -----------------------------------------------------*/
93 #define MULTICAST_ID 0x00
94 #define UART_DUMMY_ID 0x01
95 
98 #define PARAM_BYTE_5_IDX 6
99 
102 #define PARAM_BYTE_6_IDX 7
103 
107 #define SET_U8_LEN 4
108 
112 #define SET_U8_U8_LEN 5
113 
117 #define SET_U8_U16_LEN 6
118 
122 #define SET_U16_LEN 5
123 
127 #define SET_U32_LEN 7
128 
131 #define NUMBER_OF_ADC_DUMP_DATAPOINTS_PER_LINE 8
132 
136 #define FLOAT_CONVERSION_FACTOR 1000.0
137 
141 #define REQUEST_RESPONSE_INDEX 0
142 #define UART_CHECKSUM_TARGET 256
143 
144 /*---- local types --------------------------------------------------------------------*/
148 typedef struct Session_Data_t
149 {
157 typedef struct ADCDump_Data_t
158 {
162 
163 typedef enum UARTMessageState_t
164 {
172 
173 typedef struct UART_Msg_t
174 {
176  uint8_t PayloadLen_u8;
179  uint8_t Checksum_u8;
180 } UART_Msg_t;
181 
182 typedef struct Interface_t
183 {
186 } Interface_t;
187 
188 /*---- local functions prototypes -----------------------------------------------------*/
189 #ifdef CAN_AVAILABLE
190 
197 static void FrameReadCallback(struct can_frame* frame);
198 #endif
199 
208 static void UARTReadCallback(uint8_t* ReceivedUARTMsg_pu8, uint16_t UARTMsgLength_u16,
209  uint8_t InterfaceId_u8);
210 
217 static void AddSenderToKnownSensors(uint16_t Sender_u16, uint8_t SensorInterfaceIndex_u8);
218 
228 static bool ParseMessage_b(uint16_t SenderId_u16, uint8_t* msg, uint8_t len);
229 
239 static bool EvaluateACKStatus_b(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8);
240 
250 static bool ActionRequestSuccessful_b(const uint8_t* request, const uint8_t* response);
251 
258 static bool IsACKResponse_b(const uint8_t* ReceivedPayload_pu8);
259 
267 static void ConfigureACKStatus(uint8_t* payload);
268 
274 static int8_t GetCurrentSendersSessionIndex(uint16_t SenderId_u16);
275 
281 static int8_t GetCurrentSendersADCSessionIndex(uint16_t SenderId_u16);
282 
292 static bool IsSessionStartFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
293 
303 static bool IsSessionEndFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
304 
312 static bool IsSessionDataFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
313 
322 static bool IsNearFieldFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
323 
332 static bool IsNoiseLevelFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
333 
343 static bool Is1DFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
344 
354 static bool Is3DFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
355 
364 static bool IsLogMessage(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8);
365 
375 static bool IsADCDumpStartFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
376 
387 static bool IsADCDataFrame_b(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8, uint8_t len);
388 
389 #ifdef CAN_AVAILABLE
390 
396 static void PrintCanFrame(struct can_frame* frame);
397 #endif
398 
404 static void PrintPayload(const uint8_t* payload);
405 
411 static void PrintADCBlob(uint16_t SenderId_u16);
412 
422 static bool SetParameterSuccessful_b(const uint8_t* request, const uint8_t* response);
423 
431 static void SendCommand(uint8_t* payload, uint16_t length);
432 
441 static bool StartNewSessionRecord_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8);
442 
448 static bool CloseSessionRecord_b(uint16_t SenderId_u16);
449 
455 static bool CloseADCSessionRecord_b(uint16_t SenderId_u16);
456 
461 static bool AllSessionsActive_b();
462 
467 static bool AllSessionsClosed_b();
468 
473 static bool AllADCSessionsClosed_b();
474 
479 void SetSessionStateExpected(uint16_t TargetSensorId_u16);
480 
485 void SetADCSessionStateExpected(uint16_t TargetSensorId_u16);
486 
492 bool GetSessionRunning_b(uint16_t TargetSensorId_u16);
493 
499 bool GetSessionComplete_b(uint16_t TargetSensorId_u16);
500 
506 bool GetADCSessionRunning_b(uint16_t TargetSensorId_u16);
507 
513 bool GetADCSessionComplete_b(uint16_t TargetSensorId_u16);
514 
520 static void Init_Semaphores();
521 
529 static void ReplaceIdInListOfKnownSensors(uint16_t OldId_u16, uint16_t NewId_u16);
530 
535 static void ResetListOfKnownSensors();
536 
542 static void RemoveSenderFromList(uint16_t Sender_u16);
543 
550 uint8_t CalculateUARTChecksum(const uint8_t* Payload_pu8, uint8_t PayloadLength_u8);
551 
557 static bool ValidateUARTChecksum(UART_Msg_t* ReceivedUARTMsg_pt);
558 
564 static void AddInterfaceToInterfaceList(CommsInterfaceType_t SensorInterface_t,
565  char* InterfaceName_cp);
566 
572 static int16_t GetInterfaceIndex_i16(char* InterfaceName);
573 
579 static void SendViaCAN(uint8_t* payload, uint16_t length);
580 
587 static void SendViaUART(uint8_t* payload, uint16_t length, uint8_t InterfaceId_u8);
588 
594 static uint16_t GetUARTNodeId(uint8_t InterfaceId_u8);
595 
601 void ParseResetReasonLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8);
602 
609 void ParseBootloaderLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8);
610 
617 void ParseSelfCheckLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8);
618 
625 void ParseSignalProcessingLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8);
626 
633 void ParseSoftwareLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8);
634 
641 void ParseStringLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8);
642 
649 void ParseCalibrationLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8);
650 
656 void ACKADCDumpStart(uint16_t TargetSensor_u16);
657 
663 void ACKSessionStart(uint16_t TargetSensor_u16);
664 
669 void ACKSessionEnd();
670 
675 void* WaitForACKTimeout(void* vargp);
676 
681 void* WaitForSessionStartTimeout(void* vargp);
682 
687 void* WaitForSessionEndTimeout(void* vargp);
688 
689 /*---- local inline functions ---------------------------------------------------------*/
690 
691 /*---- local variables (static) -------------------------------------------------------*/
692 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
693 static uint16_t CurrentTarget_u16 = MULTICAST_ID;
694 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
695 static uint16_t CurrentStatusInformant_u16 = 0;
696 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
697 static bool ConnectedToCANBus_b = false;
698 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
699 static bool ConnectedToCUART_b = false;
700 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
701 static bool ConnectedToUSB_b = false;
702 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
704 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
705 static uint8_t NumberOfKnownSensors_u8 = 0;
707 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
708 static sem_t wait_ack_sem;
709 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
711 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
713 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
715 // Session Data
716 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
718 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
720 // Callback for Session-Start / End
721 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
722 static void (*SessionStartCallback)(uint16_t Sender_u16) = NULL;
723 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
724 static void (*SessionEndCallback)(uint16_t Sender_u16) = NULL;
725 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
726 static void (*ADCDUmpEndCallback)(uint16_t Sender_u16) = NULL;
727 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
728 static void (*RdyCallback)(uint16_t Sender_u16) = NULL;
729 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
730 static void (*ADCDumpStartRequestCallback)(uint16_t Sender_u16, uint32_t ADCDumpSize_u32) = NULL;
731 
732 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
733 static void (*LogMsgCallback)(uint16_t Sender_u16, uint8_t* ReceivedPayload_pu8) = NULL;
734 // Semaphores for blocking wait-for functions
735 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
737 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
738 static sem_t wait_session_end_sem;
740 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
741 static sem_t wait_ready_sem;
742 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
743 static bool SemaphoresInit_b = false;
744 static uint8_t UartPayload_pu8[UART_MAX_FRAME_LEN] = {0}; //@Fixme: Size can be optimized
748 static pthread_t timeoutID;
750 static pthread_mutex_t mutex_currentstatusinformant = PTHREAD_MUTEX_INITIALIZER;
751 static pthread_mutex_t mutex_knownsensors = PTHREAD_MUTEX_INITIALIZER;
752 static pthread_mutex_t mutex_knownsensor = PTHREAD_MUTEX_INITIALIZER;
753 static pthread_mutex_t mutex_getdatafromsensor = PTHREAD_MUTEX_INITIALIZER;
754 static pthread_mutex_t mutex_currentsessions = PTHREAD_MUTEX_INITIALIZER;
755 static pthread_mutex_t mutex_currenttarget = PTHREAD_MUTEX_INITIALIZER;
756 static pthread_mutex_t mutex_currentackstatus = PTHREAD_MUTEX_INITIALIZER;
757 static pthread_mutex_t mutex_numberofknownsensors = PTHREAD_MUTEX_INITIALIZER;
758 static pthread_mutex_t mutex_numberofsensorsackisexpectedfrom = PTHREAD_MUTEX_INITIALIZER;
759 static pthread_mutex_t mutex_waitackpayload = PTHREAD_MUTEX_INITIALIZER;
760 static pthread_mutex_t mutex_connectedtocanbus = PTHREAD_MUTEX_INITIALIZER;
761 /*---- public variables ---------------------------------------------------------------*/
762 
763 /*---- functions ----------------------------------------------------------------------*/
764 
766 {
767  Sensor_t* value = NULL;
768  pthread_mutex_lock(&mutex_knownsensors);
769  value = KnownSensors;
770  pthread_mutex_unlock(&mutex_knownsensors);
771  return value;
772 }
773 
774 static uint8_t* GetWaitACKPayload()
775 {
776  uint8_t* value = NULL;
777  pthread_mutex_lock(&mutex_waitackpayload);
778  value = wait_ack_payload_pu8;
779  pthread_mutex_unlock(&mutex_waitackpayload);
780  return value;
781 }
782 
784 {
785  uint8_t value = 0;
786  pthread_mutex_lock(&mutex_numberofsensorsackisexpectedfrom);
788  pthread_mutex_unlock(&mutex_numberofsensorsackisexpectedfrom);
789  return value;
790 }
791 
792 static void SetNumberOfSensorsACKIsExpectedFrom(uint8_t newvalue)
793 {
794  pthread_mutex_lock(&mutex_numberofsensorsackisexpectedfrom);
796  pthread_mutex_unlock(&mutex_numberofsensorsackisexpectedfrom);
797 }
798 
800 {
801  uint8_t value = 0;
802  pthread_mutex_lock(&mutex_numberofknownsensors);
803  value = NumberOfKnownSensors_u8;
804  pthread_mutex_unlock(&mutex_numberofknownsensors);
805  return value;
806 }
807 
808 static void SetNumberOfKnownSensors(uint8_t newvalue)
809 {
810  pthread_mutex_lock(&mutex_numberofknownsensors);
811  NumberOfKnownSensors_u8 = newvalue;
812  pthread_mutex_unlock(&mutex_numberofknownsensors);
813 }
814 
815 static uint16_t GetCurrentTarget_u16()
816 {
817  uint16_t value = 0;
818  pthread_mutex_lock(&mutex_currenttarget);
819  value = CurrentTarget_u16;
820  pthread_mutex_unlock(&mutex_currenttarget);
821  return value;
822 }
823 
824 static void SetCurrentTarget_u16(uint16_t newvalue)
825 {
826  pthread_mutex_lock(&mutex_currenttarget);
827  CurrentTarget_u16 = newvalue;
828  pthread_mutex_unlock(&mutex_currenttarget);
829 }
830 
832 {
833  uint8_t value = 0;
834  pthread_mutex_lock(&mutex_currentsessions);
836  pthread_mutex_unlock(&mutex_currentsessions);
837  return value;
838 }
839 
840 static void SetCurrentSessionsNumberOfActiveSessions_u8(uint8_t newvalue)
841 {
842  pthread_mutex_lock(&mutex_currentsessions);
844  pthread_mutex_unlock(&mutex_currentsessions);
845 }
846 
848 {
849  Sensor_Session_t* value = NULL;
850  pthread_mutex_lock(&mutex_currentsessions);
851  value = &CurrentSessions.ActiveSessions[index];
852  pthread_mutex_unlock(&mutex_currentsessions);
853  return value;
854 }
855 
857 {
858  uint16_t value = 0;
859  pthread_mutex_lock(&mutex_currentsessions);
860  value = session->SenderId_u16;
861  pthread_mutex_unlock(&mutex_currentsessions);
862  return value;
863 }
864 
866 {
867  SessionState_t value = {0};
868  pthread_mutex_lock(&mutex_currentsessions);
869  value = session->SessionState;
870  pthread_mutex_unlock(&mutex_currentsessions);
871  return value;
872 }
873 
874 static Sensor_t* GetKnownSensor(uint8_t index)
875 {
876  Sensor_t* value = NULL;
877  pthread_mutex_lock(&mutex_knownsensor);
878  value = &KnownSensors[index];
879  pthread_mutex_unlock(&mutex_knownsensor);
880  return value;
881 }
882 
883 static uint16_t GetInterfaceSensorIdFromSensor(Sensor_t* sensor)
884 {
885  uint16_t value = 0;
886  pthread_mutex_lock(&mutex_getdatafromsensor);
887  value = sensor->InterfaceSensorId_u16;
888  pthread_mutex_unlock(&mutex_getdatafromsensor);
889  return value;
890 }
891 
893 {
894  uint16_t value = 0;
895  pthread_mutex_lock(&mutex_currentstatusinformant);
897  pthread_mutex_unlock(&mutex_currentstatusinformant);
898  return value;
899 }
900 
901 static void SetCurrentStatusInformant_u16(uint16_t newvalue)
902 {
903  pthread_mutex_lock(&mutex_currentstatusinformant);
904  CurrentStatusInformant_u16 = newvalue;
905  pthread_mutex_unlock(&mutex_currentstatusinformant);
906 }
907 
909 {
910  ACK_Status_t* value = NULL;
911  pthread_mutex_lock(&mutex_currentackstatus);
912  value = &CurrentACKStatus[index];
913  pthread_mutex_unlock(&mutex_currentackstatus);
914  return value;
915 }
916 
917 static void SetSenderIdForACKStatus(ACK_Status_t* ackstatus, uint16_t senderId)
918 {
919  pthread_mutex_lock(&mutex_currentackstatus);
920  ackstatus->SenderId_u16 = senderId;
921  pthread_mutex_unlock(&mutex_currentackstatus);
922 }
923 
924 static uint16_t GetSenderIdFromACKStatus(ACK_Status_t* ackstatus)
925 {
926  uint16_t value = 0;
927  pthread_mutex_lock(&mutex_currentackstatus);
928  value = ackstatus->SenderId_u16;
929  pthread_mutex_unlock(&mutex_currentackstatus);
930  return value;
931 }
932 
933 static void SetWaitForACKForACKStatus(ACK_Status_t* ackstatus, bool waitforack)
934 {
935  pthread_mutex_lock(&mutex_currentackstatus);
936  ackstatus->WaitForACK_b = waitforack;
937  pthread_mutex_unlock(&mutex_currentackstatus);
938 }
939 
941 {
942  bool value = false;
943  pthread_mutex_lock(&mutex_currentackstatus);
944  value = ackstatus->WaitForACK_b;
945  pthread_mutex_unlock(&mutex_currentackstatus);
946  return value;
947 }
948 
949 static void SetACKForACKStatus(ACK_Status_t* ackstatus, bool ack)
950 {
951  pthread_mutex_lock(&mutex_currentackstatus);
952  ackstatus->ACK_b = ack;
953  pthread_mutex_unlock(&mutex_currentackstatus);
954 }
955 
956 static bool GetACKFromACKStatus(ACK_Status_t* ackstatus)
957 {
958  bool value = false;
959  pthread_mutex_lock(&mutex_currentackstatus);
960  value = ackstatus->ACK_b;
961  pthread_mutex_unlock(&mutex_currentackstatus);
962  return value;
963 }
964 
965 static void SetConnectedToCANBus(bool newvalue)
966 {
967  pthread_mutex_lock(&mutex_connectedtocanbus);
968  ConnectedToCANBus_b = newvalue;
969  pthread_mutex_unlock(&mutex_connectedtocanbus);
970 }
971 
972 static bool GetConnectedToCANBus()
973 {
974  bool value = false;
975  pthread_mutex_lock(&mutex_connectedtocanbus);
976  value = ConnectedToCANBus_b;
977  pthread_mutex_unlock(&mutex_connectedtocanbus);
978  return value;
979 }
980 
981 static void SetResponsePayloadForACKStatus(ACK_Status_t* ackstatus, uint8_t* payload, uint16_t len)
982 {
983  pthread_mutex_lock(&mutex_currentackstatus);
984  memcpy(ackstatus->ResponsePayload_pu8, payload, len);
985  pthread_mutex_unlock(&mutex_currentackstatus);
986 }
987 
989 {
990  uint8_t* value = NULL;
991  pthread_mutex_lock(&mutex_currentackstatus);
992  value = ackstatus->ResponsePayload_pu8;
993  pthread_mutex_unlock(&mutex_currentackstatus);
994  return value;
995 }
996 
997 static int16_t GetInterfaceIndex_i16(char* InterfaceName)
998 {
999  int16_t InterfaceIndex = -1;
1000  for (uint8_t Idx_u8 = 0; Idx_u8 < NumberOfKnownInterfaces_u8; Idx_u8++)
1001  {
1002  if (strncmp(KnownInterfaces_tp[Idx_u8].InterfaceName, InterfaceName, strlen(InterfaceName)) ==
1003  0)
1004  {
1005  InterfaceIndex = Idx_u8;
1006  break;
1007  }
1008  }
1009  return InterfaceIndex;
1010 }
1012  char* InterfaceName_cp)
1013 {
1015  {
1017  memcpy(KnownInterfaces_tp[NumberOfKnownInterfaces_u8].InterfaceName, InterfaceName_cp,
1018  strlen(InterfaceName_cp));
1019  MPRINTF("Added Interface: %s at Postion:%d\n",
1023  }
1024  else
1025  {
1026  MPRINTF("ERROR - CAN NOT ADD MORE SENSORS - LIMIT REACHED\n");
1027  }
1028 }
1029 
1030 uint8_t CalculateUARTChecksum(const uint8_t* Payload_pu8, uint8_t PayloadLength_u8)
1031 {
1032  uint8_t Checksum_u8 = PayloadLength_u8 + UART_OVERHEAD_LENGTH;
1033  uint16_t PayloadSum_u16 = 0;
1034  for (uint8_t Idx_u8 = 0; Idx_u8 < PayloadLength_u8; Idx_u8++)
1035  {
1036  PayloadSum_u16 += Payload_pu8[Idx_u8];
1037  }
1038  Checksum_u8 = PayloadSum_u16 + Checksum_u8;
1039  Checksum_u8 = UINT8_MAX + 1 - Checksum_u8;
1040  return Checksum_u8;
1041 }
1042 
1043 static bool ValidateUARTChecksum(UART_Msg_t* ReceivedUARTMsg_pt)
1044 {
1045  uint8_t PayloadLength_u8 = ReceivedUARTMsg_pt->PayloadLen_u8;
1046  uint8_t CalculatedChecksum_u8 =
1047  CalculateUARTChecksum(ReceivedUARTMsg_pt->Payload_pu8, PayloadLength_u8);
1048  return CalculatedChecksum_u8 == ReceivedUARTMsg_pt->Checksum_u8;
1049 }
1050 
1051 static void SendViaCAN(uint8_t* payload, uint16_t length)
1052 {
1053 #ifdef CAN_AVAILABLE
1054  struct can_frame frame;
1055  memset(&frame, 0x00, sizeof(frame));
1056  frame.can_dlc = length;
1057  frame.can_id = GetCurrentTarget_u16();
1058  memcpy(frame.data, payload, length > sizeof(frame.data) ? sizeof(frame.data) : length);
1059 
1060  PrintCanFrame(&frame);
1061  WriteFrame(&frame);
1062 #endif
1063 }
1064 static void SendViaUART(uint8_t* payload, uint16_t length, uint8_t InterfaceId_u8)
1065 {
1066  uint8_t UartPayloadLength_u8 = length + UART_OVERHEAD_LENGTH;
1068  UartPayload_pu8[UART_LENGTH_IDX] = UartPayloadLength_u8;
1069  memcpy(&UartPayload_pu8[UART_PAYLOAD_START_OFFSET], payload,
1072  : length);
1073  uint8_t Checksum_u8 = CalculateUARTChecksum(payload, length);
1076  WriteUARTPayload(UartPayload_pu8, UartPayloadLength_u8, InterfaceId_u8);
1077 }
1078 
1079 static void PrintKnownSensors()
1080 {
1081  MPRINTF("---PrintCurrentSensors---\n");
1082  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
1083  {
1084  MPRINTF("KnownSensors[%d].InterfaceSensorId_u16: %d\n", Idx_u8,
1086  MPRINTF("KnownSensors[%d].InterfaceIndex_u8: %d\n", Idx_u8,
1087  KnownSensors[Idx_u8].InterfaceIndex_u8);
1088  }
1089  MPRINTF("-------------------------\n");
1090 }
1091 
1093 {
1094  MPRINTF("---PrintKnownInterfaces---\n");
1095  for (uint8_t Idx_u8 = 0; Idx_u8 < NumberOfKnownInterfaces_u8; Idx_u8++)
1096  {
1097  MPRINTF("KnownInterfaces_tp[%d].InterfaceName: %s\n", Idx_u8,
1098  KnownInterfaces_tp[Idx_u8].InterfaceName);
1099  MPRINTF("KnownInterfaces_tp[%d].SensorInterface_t: %d\n", Idx_u8,
1100  KnownInterfaces_tp[Idx_u8].SensorInterface_t);
1101  }
1102  MPRINTF("-------------------------\n");
1103 }
1104 
1105 static void SendCommand(uint8_t* payload, uint16_t length)
1106 {
1107  CommsInterfaceType_t SensorInterface_t = IF_UART;
1108  if (GetConnectedToCANBus())
1109  {
1110  SensorInterface_t = IF_CAN;
1111  }
1112  switch (SensorInterface_t)
1113  {
1114  case IF_UART:
1115  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
1116  {
1118  GetCurrentTarget_u16() == 0)
1119  {
1120  if (payload != NULL)
1121  {
1122  MPRINTF("SendCommand to Target: Id:%d %s\n",
1124  KnownInterfaces_tp[KnownSensors[Idx_u8].InterfaceIndex_u8].InterfaceName);
1125  PrintPayload(payload);
1126  SendViaUART(payload, length, KnownSensors[Idx_u8].InterfaceIndex_u8); //@Fixme -
1127  }
1128  }
1129  }
1130  break;
1131  case IF_CAN:
1132  if (GetConnectedToCANBus())
1133  {
1134  if (payload != NULL)
1135  {
1136  SendViaCAN(payload, length);
1137  }
1138  }
1139  break;
1140  case IF_USB:
1141  break;
1142  default:
1143  MPRINTF("Interface currently unsupported\n");
1144  }
1145 }
1146 
1147 static void PrintPayload(const uint8_t* payload)
1148 {
1149  CommsInterfaceType_t SensorInterface_t = IF_UART;
1150  if (GetConnectedToCANBus())
1151  {
1152  SensorInterface_t = IF_CAN;
1153  }
1154  int loopCondition = CAN_MAX_FRAME_LEN;
1155  switch (SensorInterface_t)
1156  {
1157  case IF_CAN:
1158  loopCondition = CAN_MAX_FRAME_LEN;
1159  break;
1160  case IF_UART:
1161  loopCondition = UART_MAX_FRAME_LEN;
1162  break;
1163  default:
1164  loopCondition = CAN_MAX_FRAME_LEN;
1165  break;
1166  }
1167  for (int i = 0; i < loopCondition; i++)
1168  {
1169  MPRINTF("%02X ", payload[i]);
1170  }
1171  MPRINTF("\r\n");
1172 }
1173 #ifdef CAN_AVAILABLE
1174 
1175 static void PrintCanFrame(struct can_frame* frame)
1176 {
1177  MPRINTF("0x%03X [%d] ", frame->can_id, frame->can_dlc);
1178 
1179  for (int i = 0; i < frame->can_dlc; i++)
1180  {
1181  MPRINTF("%02X ", frame->data[i]);
1182  }
1183  MPRINTF("\r\n");
1184 }
1185 #endif
1186 
1187 static void ConfigureACKStatus(uint8_t* payload)
1188 {
1189  memcpy(GetWaitACKPayload(), payload, CAN_MAX_FRAME_LEN);
1191  {
1193  }
1194  else
1195  {
1197  }
1198  // In case this is the very first msg send, GetNumberOfKnownSensors() will be 0
1199  /* Reset Current ACK-Status */
1200  if (GetNumberOfKnownSensors() != 0)
1201  {
1203  {
1204  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfSensorsACKIsExpectedFrom(); Idx_u8++)
1205  {
1209  SetACKForACKStatus(GetCurrentACKStatus(Idx_u8), false);
1210  for (uint8_t SubIdx_u8 = 0; SubIdx_u8 < CAN_MAX_FRAME_LEN; SubIdx_u8++)
1211  {
1212  GetResponsePayloadFromACKStatus(GetCurrentACKStatus(Idx_u8))[SubIdx_u8] = 0;
1213  }
1214  }
1215  }
1216  else
1217  {
1221  for (uint8_t SubIdx_u8 = 0; SubIdx_u8 < CAN_MAX_FRAME_LEN; SubIdx_u8++)
1222  {
1224  }
1225  }
1226  }
1227  else
1228  {
1229  // Is very first msg - set SenderId_u16 to 0 so this can be evaluated later
1230  MPRINTF("Unknown Number of Sensors on Bus, but wait for ack is called\n");
1235  for (uint8_t SubIdx_u8 = 0; SubIdx_u8 < CAN_MAX_FRAME_LEN; SubIdx_u8++)
1236  {
1238  }
1239  }
1240  MPRINTF("NumberOfSensorsACKIsExpectedFrom:%d\n ", GetNumberOfSensorsACKIsExpectedFrom());
1241 }
1242 
1243 static bool EvaluateACKStatus_b(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8)
1244 {
1245  bool retval_b = false;
1246  bool can_release_sem = true;
1247  uint8_t ExpectedACK = GetWaitACKPayload()[CONTROL_BYTE_IDX] + 1;
1248  uint8_t ExpectedNACK = GetWaitACKPayload()[CONTROL_BYTE_IDX] + 2;
1249  uint8_t ExpectedSubControlByte_u8 = GetWaitACKPayload()[SUBCONTROL_BYTE_IDX];
1250  uint8_t CurrentACK_u8 = ReceivedPayload_pu8[CONTROL_BYTE_IDX];
1251  uint8_t CurrentSubControlByte_u8 = ReceivedPayload_pu8[SUBCONTROL_BYTE_IDX];
1252  MPRINTF("-----\n");
1254  PrintPayload(ReceivedPayload_pu8);
1255  MPRINTF("NumberOfSensorsACKIsExpectedFrom:%d\n", GetNumberOfSensorsACKIsExpectedFrom());
1256  MPRINTF("SenderId_u16: %d\n", SenderId_u16);
1257  MPRINTF("-----\n");
1258  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfSensorsACKIsExpectedFrom(); Idx_u8++)
1259  {
1260  MPRINTF("CurrentACKStatus[%d].SenderId_u16: %d\n", Idx_u8,
1261  CurrentACKStatus[Idx_u8].SenderId_u16);
1262  if (SenderId_u16 == GetSenderIdFromACKStatus(GetCurrentACKStatus(Idx_u8)) ||
1264  {
1265  // Got Message from Sender we are expecting an answer from
1266  // Evaluate Answer
1267  MPRINTF("Evaluate Answer\n");
1268  if (CurrentACK_u8 == ExpectedACK || CurrentACK_u8 == ExpectedNACK ||
1269  CurrentACK_u8 == CONTROL_BYTE_NACK)
1270  {
1271  MPRINTF("Is ACK Message\n");
1272  if (CurrentSubControlByte_u8 == ExpectedSubControlByte_u8)
1273  {
1274  // Is ACK msg we expect
1275  memcpy(GetResponsePayloadFromACKStatus(GetCurrentACKStatus(Idx_u8)), ReceivedPayload_pu8,
1277  CurrentACKStatus[Idx_u8].WaitForACK_b = false;
1278  bool ACK_b = false;
1279  // Determine if ack was a success
1280  if (SetParameterSuccessful_b(GetWaitACKPayload(), ReceivedPayload_pu8))
1281  {
1282  ACK_b = true;
1283  }
1284  else
1285  {
1286  if (ActionRequestSuccessful_b(GetWaitACKPayload(), ReceivedPayload_pu8))
1287  {
1288  ACK_b = true;
1289  }
1290  }
1291  CurrentACKStatus[Idx_u8].ACK_b = ACK_b;
1292  // Got an Answer
1293 
1294  retval_b = true;
1295  }
1296  }
1297  }
1298  // In last iteration / response, WaitForACK_b will always be false, so Semaphore can be released
1300  {
1301  can_release_sem = false;
1302  }
1303  }
1304  if (retval_b && can_release_sem)
1305  {
1306  int sem_count = 0;
1307  sem_getvalue(&wait_ack_sem, &sem_count);
1308  if (sem_count == 0)
1309  {
1310  sem_post(&wait_ack_sem);
1311  }
1312  }
1313  return retval_b;
1314 }
1315 
1316 void WaitForACK(uint8_t* payload, uint16_t length_u16)
1317 {
1318  MPRINTF("WaitForACK\n");
1319 
1320  ConfigureACKStatus(payload);
1321  SendCommand(payload, length_u16);
1322  pthread_create(&timeoutID, NULL, WaitForACKTimeout, &timeoutmSeconds);
1323  sem_wait(&wait_ack_sem);
1324  sem_wait(&wait_ack_sem);
1325  pthread_cancel(timeoutID);
1326  pthread_join(timeoutID, NULL);
1327  sem_post(&wait_ack_sem);
1328 }
1329 static void WaitForACKNoSend(uint8_t* payload)
1330 {
1331  ConfigureACKStatus(payload);
1332  sem_wait(&wait_ack_sem);
1333  sem_wait(&wait_ack_sem);
1334  sem_post(&wait_ack_sem);
1335 }
1336 
1337 void SetTargetSensor(uint16_t TargetSensor_u16) { SetCurrentTarget_u16(TargetSensor_u16); }
1338 
1339 static void AddSenderToKnownSensors(uint16_t Sender_u16, uint8_t SensorInterfaceIndex_u8)
1340 {
1341  MPRINTF("Try to Add %d to List of known Sensors - SensorInterfaceIndex_u8:%d\n", Sender_u16,
1342  SensorInterfaceIndex_u8);
1344  {
1345  bool SensorAlreadyKnown = false;
1346  for (int i = 0; i < GetNumberOfKnownSensors(); i++)
1347  {
1348  if (GetInterfaceSensorIdFromSensor(GetKnownSensor(i)) == Sender_u16)
1349  {
1350  MPRINTF("Sensor was known - not adding\n");
1351  SensorAlreadyKnown = true;
1352  break;
1353  }
1354  }
1355  if (!SensorAlreadyKnown)
1356  {
1357  MPRINTF("Sensor was unknown - adding now at index %d\n", GetNumberOfKnownSensors() + 1);
1359  KnownSensors[GetNumberOfKnownSensors()].InterfaceIndex_u8 = SensorInterfaceIndex_u8;
1361  }
1362  }
1363  else
1364  {
1365  MPRINTF("WARNING: To many sensors on Bus\n");
1366  }
1367 }
1368 
1369 static bool IsACKResponse_b(const uint8_t* ReceivedPayload_pu8)
1370 {
1371  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_TRIGGER_ACTION_ACK)
1372  {
1373  return true;
1374  }
1375  return false;
1376 }
1377 
1378 static bool StartNewSessionRecord_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1379 {
1380  int8_t NewIndex_i8 = GetCurrentSendersSessionIndex(SenderId_u16);
1381  if (NewIndex_i8 == -1)
1382  {
1383  // No existing session was found that can be overwritten
1384  // Before Starting a new Session, validate there is still free memory:
1386  {
1389  1);
1390  }
1391  else
1392  {
1393  MPRINTF(
1394  "No free session-memory left. Looks like there are more sensors on bus then expected\n");
1395  return false;
1396  }
1397  }
1398  else
1399  {
1400  // There is already session-data for this sender. Those have to be cleared before starting a new
1401  // session
1402  MPRINTF("Delete Old Session Data\n");
1403  memset(GetCurrentSessionsActiveSessions(NewIndex_i8), 0, sizeof(Sensor_Session_t));
1404  }
1405  // Start New Session
1406  MPRINTF("Starting new Session at index: %d\n", NewIndex_i8);
1407  CurrentSessions.ActiveSessions[NewIndex_i8].SenderId_u16 = SenderId_u16;
1409  ReceivedPayload_pu8[PARAM_BYTE_1_IDX];
1411  MPRINTF("Created Empty Session Record for sender %d with index: %d\n", SenderId_u16, NewIndex_i8);
1412  return true;
1413 }
1414 
1415 static bool IsSessionStartFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1416 {
1417  PrintPayload(ReceivedPayload_pu8);
1418  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_BEGIN_POINT_OUTPUT_SESSION)
1419  {
1420  MPRINTF("Session Start Detected!\n");
1421  // Start New Session-Record
1422  if (!StartNewSessionRecord_b(SenderId_u16, ReceivedPayload_pu8))
1423  {
1424  MPRINTF("Error while trying to start new session\n");
1425  }
1426 
1427  uint16_t keepCurrentTarget_u16 = GetCurrentTarget_u16();
1428  SetCurrentTarget_u16(SenderId_u16);
1429 
1430  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
1431  {
1433  GetCurrentTarget_u16() == 0)
1434  {
1435  if (KnownSensors[Idx_u8].SensorMode != SENSOR_MODE_CONTINUOUS_TRANSMIT_LISTEN)
1436  {
1437  ACKSessionStart(SenderId_u16);
1438  }
1439  }
1440  }
1441  SetCurrentTarget_u16(keepCurrentTarget_u16);
1442 
1443  // Free Semaphore to unblock possible wait for session start
1444  // Free only if was taken..
1445  if (AllSessionsActive_b())
1446  {
1447  int sem_count = 0;
1448  sem_getvalue(&wait_session_start_sem, &sem_count);
1449  if (sem_count == 0)
1450  {
1451  sem_post(&wait_session_start_sem);
1452  }
1453  }
1454  if (SessionStartCallback != NULL)
1455  {
1456  // Execute Callback function if one has been registered
1457  SessionStartCallback(SenderId_u16);
1458  }
1459 
1460  return true;
1461  }
1462  return false;
1463 }
1464 
1465 static int8_t GetCurrentSendersSessionIndex(uint16_t SenderId_u16)
1466 {
1467  int8_t Index_i8 = -1;
1468  for (uint8_t Index_u8 = 0; Index_u8 < MAX_NUMBER_OF_SENSORS_ON_BUS; Index_u8++)
1469  {
1470  MPRINTF("CurrentSessions.ActiveSessions[%d].SenderId_u16:%d\n", Index_u8,
1472  if (CurrentSessions.ActiveSessions[Index_u8].SenderId_u16 == SenderId_u16)
1473  {
1474  Index_i8 = (int8_t)Index_u8;
1475  break;
1476  }
1477  }
1478  if (Index_i8 == -1)
1479  {
1480  // No session for this sensor-id yet - try to create one
1481  // 1. Find free index:
1482  uint8_t Index_u8 = 0;
1483  for (Index_u8 = 0; Index_u8 < MAX_NUMBER_OF_SENSORS_ON_BUS; Index_u8++)
1484  {
1485  MPRINTF("CurrentSessions.ActiveSessions[%d].SenderId_u16:%d\n", Index_u8,
1487  if (CurrentSessions.ActiveSessions[Index_u8].SenderId_u16 == 0)
1488  {
1489  Index_i8 = (int8_t)Index_u8;
1490  break;
1491  }
1492  }
1493  MPRINTF("New Session index created at: %d\n", Index_i8);
1494  CurrentSessions.ActiveSessions[Index_u8].SenderId_u16 = SenderId_u16;
1495  }
1496  //@Fixme: Add Handling for case of not created session here..
1497  MPRINTF("GetCurrentSendersSessionIndex found index at %d\n", Index_i8);
1498  return Index_i8;
1499 }
1500 
1501 static int8_t GetCurrentSendersADCSessionIndex(uint16_t SenderId_u16)
1502 {
1503  int8_t Index_i8 = -1;
1504  MPRINTF("Search for sender: %d\n", SenderId_u16);
1505  for (uint8_t Index_u8 = 0; Index_u8 < MAX_NUMBER_OF_SENSORS_ON_BUS; Index_u8++)
1506  {
1507  MPRINTF("CurrentADCSessions.ActiveSessions[%d].SenderId_u16:%d\n", Index_u8,
1509  if (CurrentADCSessions.Dumps[Index_u8].SenderId_u16 == SenderId_u16)
1510  {
1511  Index_i8 = (int8_t)Index_u8;
1512  break;
1513  }
1514  }
1515  if (Index_i8 == -1)
1516  {
1517  // No session for this sensor-id yet - try to create one
1518  // 1. Find free index:
1519  uint8_t Index_u8 = 0;
1520  for (Index_u8 = 0; Index_u8 < MAX_NUMBER_OF_SENSORS_ON_BUS; Index_u8++)
1521  {
1522  MPRINTF("CurrentSessions.ActiveSessions[%d].SenderId_u16:%d\n", Index_u8,
1524  if (CurrentADCSessions.Dumps[Index_u8].SenderId_u16 == 0)
1525  {
1526  Index_i8 = (int8_t)Index_u8;
1527  break;
1528  }
1529  }
1530  MPRINTF("New Session index created at: %d\n", Index_i8);
1531  CurrentADCSessions.Dumps[Index_u8].SenderId_u16 = SenderId_u16;
1532  }
1533  MPRINTF("GetCurrentSendersSessionIndex found index at %d\n", Index_i8);
1534  return Index_i8;
1535 }
1536 
1537 static bool CloseSessionRecord_b(uint16_t SenderId_u16)
1538 {
1539  MPRINTF("CloseSessionRecord_b\n");
1540  int8_t CurrentSenderSessionIndex_i8 = GetCurrentSendersSessionIndex(SenderId_u16);
1541  if (CurrentSenderSessionIndex_i8 != -1)
1542  {
1544  GetCurrentSessionsActiveSessions(CurrentSenderSessionIndex_i8)) == RUNNING)
1545  {
1546  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8].SessionState = COMPLETE;
1547  MPRINTF("CloseSessionRecord_b: SessionIndex for Sender %d found: %d!\n", SenderId_u16,
1548  CurrentSenderSessionIndex_i8);
1549  return true;
1550  }
1551  }
1552 
1553  return false;
1554 }
1555 
1556 static bool CloseADCSessionRecord_b(uint16_t SenderId_u16)
1557 {
1558  MPRINTF("CloseSessionRecord_b\n");
1559  int8_t CurrentSenderADCSessionIndex_i8 = GetCurrentSendersADCSessionIndex(SenderId_u16);
1560  if (CurrentSenderADCSessionIndex_i8 != -1)
1561  {
1562  CurrentADCSessions.Dumps[CurrentSenderADCSessionIndex_i8].SessionState = COMPLETE;
1563  MPRINTF("ADC-Session closed\n");
1564  MPRINTF("ReceivedDumpSize_u32:%d\n",
1565  CurrentADCSessions.Dumps[CurrentSenderADCSessionIndex_i8].ReceivedDumpSize_u32);
1566  return true;
1567  }
1568  return false;
1569 }
1570 
1571 static void PrintADCBlob(uint16_t SenderId_u16)
1572 {
1573  int8_t CurrentSenderADCSessionIndex_i8 = GetCurrentSendersADCSessionIndex(SenderId_u16);
1574  if (CurrentSenderADCSessionIndex_i8 != -1)
1575  {
1576  // CurrentADCSessions.Dumps[CurrentSenderADCSessionIndex_i8].SessionState = false;
1577 #ifndef NOREALPRINTF
1578  uint32_t ExpectedDumpSize_u32 =
1579  CurrentADCSessions.Dumps[CurrentSenderADCSessionIndex_i8].ExpectedDumpSize_u32;
1580  uint16_t SenderId_u16 = CurrentADCSessions.Dumps[CurrentSenderADCSessionIndex_i8].SenderId_u16;
1581 #endif
1582  uint32_t DumpSize_u32 =
1583  CurrentADCSessions.Dumps[CurrentSenderADCSessionIndex_i8].ReceivedDumpSize_u32;
1584 
1585 #ifndef NOREALPRINTF
1586  MPRINTF("SenderId_u16:%d\n", SenderId_u16);
1587  MPRINTF("ExpectedDumpSize_u32:%d\n", ExpectedDumpSize_u32);
1588 #endif
1589  MPRINTF("ReceivedDumpSize_u32:%d\n", DumpSize_u32);
1590  for (uint32_t Idx_u32 = 0; Idx_u32 < DumpSize_u32; Idx_u32++)
1591  {
1592  MPRINTF("0x%02X ",
1593  CurrentADCSessions.Dumps[CurrentSenderADCSessionIndex_i8].DumpBlob_pu8[Idx_u32]);
1594  if (((Idx_u32 + 1) % NUMBER_OF_ADC_DUMP_DATAPOINTS_PER_LINE == 0) && (Idx_u32 > 0))
1595  {
1596  MPRINTF("\n");
1597  }
1598  }
1599  MPRINTF("\n");
1600  }
1601  else
1602  {
1603  MPRINTF("Waring, tried to print none existing data-blob\n");
1604  }
1605 }
1606 
1607 static bool AllSessionsActive_b()
1608 {
1609  MPRINTF("AllSessionsActive_b NumberOfSensorsASessionStartIsExpectedFrom_u8:%d\n",
1611  for (uint8_t Idx_u8 = 0; Idx_u8 < NumberOfSensorsASessionStartIsExpectedFrom_u8; Idx_u8++)
1612  {
1614  {
1615  return false;
1616  }
1617  }
1618  return true;
1619 }
1620 
1621 static bool AllSessionsClosed_b()
1622 {
1623  for (uint8_t Idx_u8 = 0; Idx_u8 < CurrentSessions.NumberOfActiveSessions_u8; Idx_u8++)
1624  {
1626  {
1627  return false;
1628  }
1629  }
1630  return true;
1631 }
1632 
1634 {
1635  MPRINTF("CurrentADCSessions.NumberOfActiveSessions_u8:%d\n",
1637  for (uint8_t Idx_u8 = 0; Idx_u8 < CurrentADCSessions.NumberOfActiveSessions_u8; Idx_u8++)
1638  {
1640  {
1641  return false;
1642  }
1643  }
1644  return true;
1645 }
1646 
1647 static bool IsSessionEndFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1648 {
1649  PrintPayload(ReceivedPayload_pu8);
1650  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_EOS)
1651  {
1652  MPRINTF("End of Session Request Detected!\n");
1653  if (CloseSessionRecord_b(SenderId_u16))
1654  {
1655  MPRINTF("Session no longer active\n");
1656 
1657  uint16_t keepCurrentTarget_u16 = GetCurrentTarget_u16();
1658  SetCurrentTarget_u16(SenderId_u16);
1659 
1660  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
1661  {
1663  GetCurrentTarget_u16() == 0)
1664  {
1665  if (KnownSensors[Idx_u8].SensorMode != SENSOR_MODE_CONTINUOUS_TRANSMIT_LISTEN)
1666  {
1667  ACKSessionEnd();
1668  }
1669  }
1670  }
1671  SetCurrentTarget_u16(keepCurrentTarget_u16);
1672 
1673  if (SessionEndCallback != NULL)
1674  {
1675  SessionEndCallback(SenderId_u16);
1676  }
1677  if (AllSessionsClosed_b())
1678  {
1679  int sem_count = 0;
1680  sem_getvalue(&wait_session_end_sem, &sem_count);
1681  if (sem_count == 0)
1682  {
1683  sem_post(&wait_session_end_sem);
1684  }
1685  }
1686  }
1687  else if (CloseADCSessionRecord_b(SenderId_u16))
1688  {
1689  MPRINTF("ADC-Session no longer active\n");
1690 
1691  uint16_t keepCurrentTarget_u16 = GetCurrentTarget_u16();
1692  SetCurrentTarget_u16(SenderId_u16);
1693  ACKSessionEnd();
1694  SetCurrentTarget_u16(keepCurrentTarget_u16);
1695 
1696  if (ADCDUmpEndCallback != NULL)
1697  {
1698  ADCDUmpEndCallback(SenderId_u16);
1699  }
1700  if (AllADCSessionsClosed_b())
1701  {
1702  MPRINTF("AllADCSessionsClosed\n");
1703  int sem_count = 0;
1704  sem_getvalue(&wait_adc_session_end_sem, &sem_count);
1705  if (sem_count == 0)
1706  {
1707  sem_post(&wait_adc_session_end_sem);
1708  }
1709  }
1710  }
1711  else
1712  {
1713  MPRINTF(
1714  "Warning: Could not close Session. Probably because no corresponding session start was "
1715  "recorded\n");
1716  }
1717 
1718  return true;
1719  }
1720  return false;
1721 }
1722 
1723 static bool IsNearFieldFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1724 {
1725  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == POINT_TYPE_BYTE_NEAR_FIELD)
1726  {
1727  MPRINTF("NearFieldFrame detected\n");
1728  int8_t CurrentSenderSessionIndex_i8 = GetCurrentSendersSessionIndex(SenderId_u16);
1729  if (CurrentSenderSessionIndex_i8 != -1)
1730  {
1731  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8].NearFieldPoint_b = true;
1732  return true;
1733  }
1734  MPRINTF(
1735  "Warning: Could not record NearFieldFrame. Probably because no corresponding session start "
1736  "was recorded\n");
1737  }
1738  return false;
1739 }
1740 
1741 static bool IsNoiseLevelFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1742 {
1743  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == POINT_TYPE_BYTE_NOISE_LEVEL)
1744  {
1745  MPRINTF("NoiseLevelFrame detected\n");
1746  int8_t CurrentSenderSessionIndex_i8 = GetCurrentSendersSessionIndex(SenderId_u16);
1747  if (CurrentSenderSessionIndex_i8 != -1)
1748  {
1749  uint16_t NoiseLevel_u16 = 0;
1750  memcpy(&NoiseLevel_u16, &ReceivedPayload_pu8[SUBCONTROL_BYTE_IDX], sizeof(NoiseLevel_u16));
1751  /* Ensure Endianness */
1752  NoiseLevel_u16 = le16toh(NoiseLevel_u16);
1753  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8].NoiseLevel_u16 = NoiseLevel_u16;
1754  return true;
1755  }
1756  MPRINTF(
1757  "Warning: Could not record NoiseLevelFrame. Probably because no corresponding session "
1758  "start was recorded\n");
1759  }
1760  return false;
1761 }
1762 
1763 static bool Is1DFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1764 {
1765  bool retval_b = false;
1766  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == POINT_TYPE_BYTE_1D)
1767  {
1768  MPRINTF("1DFrame detected\n");
1769  int8_t CurrentSenderSessionIndex_i8 = GetCurrentSendersSessionIndex(SenderId_u16);
1770  if (CurrentSenderSessionIndex_i8 != -1)
1771  {
1772  uint8_t NumberOf1DPoints_u8 =
1773  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8].NumberOf1DPoints;
1774  if (NumberOf1DPoints_u8 < MAX_NUMBER_OF_POINTS_PER_SESSION)
1775  {
1776  uint16_t VectorLength_u16 = 0;
1777  memcpy(&VectorLength_u16, &ReceivedPayload_pu8[SUBCONTROL_BYTE_IDX],
1778  sizeof(VectorLength_u16));
1779  /* Ensure Endianness */
1780  VectorLength_u16 = le16toh(VectorLength_u16);
1781  uint8_t Intensity_u8 = ReceivedPayload_pu8[PARAM_BYTE_2_IDX];
1782  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8]
1783  .Point1D_tp[NumberOf1DPoints_u8]
1784  .VectorLength_u16 = VectorLength_u16;
1785  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8]
1786  .Point1D_tp[NumberOf1DPoints_u8]
1787  .Intensity_u8 = Intensity_u8;
1788  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8].NumberOf1DPoints++;
1789  MPRINTF("VectorLength_u16:%d\n", VectorLength_u16);
1790  MPRINTF("Intensity_u8:%d\n", Intensity_u8);
1791  retval_b = true;
1792  }
1793  else
1794  {
1795  MPRINTF("Error: Could not record 1DFrame. More 1D Datapoints send then expected!\n");
1796  }
1797  }
1798  else
1799  {
1800  MPRINTF(
1801  "Warning: Could not record 1DFrame. Probably because no corresponding session start was "
1802  "recorded\n");
1803  }
1804  }
1805  return retval_b;
1806 }
1807 
1808 static bool Is3DFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1809 {
1810  bool retval_b = false;
1811  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == POINT_TYPE_BYTE_3D)
1812  {
1813  MPRINTF("3DFrame detected\n");
1814  int8_t CurrentSenderSessionIndex_i8 = GetCurrentSendersSessionIndex(SenderId_u16);
1815  if (CurrentSenderSessionIndex_i8 != -1)
1816  {
1817  uint8_t NumberOf3DPoints_u8 =
1818  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8].NumberOf3DPoints;
1819  if (NumberOf3DPoints_u8 < MAX_NUMBER_OF_POINTS_PER_SESSION)
1820  {
1821  int16_t X_i16 = 0;
1822  int16_t Y_i16 = 0;
1823  int16_t Z_i16 = 0;
1824  /* Get Values */
1825  memcpy(&X_i16, &ReceivedPayload_pu8[SUBCONTROL_BYTE_IDX], sizeof(X_i16));
1826  memcpy(&Y_i16, &ReceivedPayload_pu8[PARAM_BYTE_2_IDX], sizeof(Y_i16));
1827  memcpy(&Z_i16, &ReceivedPayload_pu8[PARAM_BYTE_4_IDX], sizeof(Z_i16));
1828  /* Ensure Endianness */
1829  X_i16 = le16toh(X_i16);
1830  Y_i16 = le16toh(Y_i16);
1831  Z_i16 = le16toh(Z_i16);
1832  uint8_t Intensity_u8 = ReceivedPayload_pu8[PARAM_BYTE_6_IDX];
1833 
1834  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8]
1835  .Point3D_tp[NumberOf3DPoints_u8]
1836  .X_i16 = X_i16;
1837  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8]
1838  .Point3D_tp[NumberOf3DPoints_u8]
1839  .Y_i16 = Y_i16;
1840  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8]
1841  .Point3D_tp[NumberOf3DPoints_u8]
1842  .Z_i16 = Z_i16;
1843  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8]
1844  .Point3D_tp[NumberOf3DPoints_u8]
1845  .Intensity_u8 = Intensity_u8;
1846  CurrentSessions.ActiveSessions[CurrentSenderSessionIndex_i8].NumberOf3DPoints++;
1847  PrintPayload(ReceivedPayload_pu8);
1848 
1849  MPRINTF("X_i16:%d\n", X_i16);
1850  MPRINTF("Y_i16:%d\n", Y_i16);
1851  MPRINTF("Z_i16:%d\n", Z_i16);
1852  MPRINTF("Intensity_u8:%d\n", Intensity_u8);
1853  retval_b = true;
1854  }
1855  else
1856  {
1857  MPRINTF("Error: Could not record 3DFrame. More 3D Datapoints send then expected!\n");
1858  }
1859  }
1860  else
1861  {
1862  MPRINTF(
1863  "Warning: Could not record 3DFrame. Probably because no corresponding session start was "
1864  "recorded\n");
1865  }
1866  }
1867  return retval_b;
1868 }
1877 static bool IsReadyFrame(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1878 {
1879  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_READY &&
1880  !(ReceivedPayload_pu8[PARAM_BYTE_1_IDX] == STATE_BL_WAIT_FOR_INIT ||
1881  ReceivedPayload_pu8[PARAM_BYTE_1_IDX] == STATE_BL_RX_APP ||
1882  ReceivedPayload_pu8[PARAM_BYTE_1_IDX] == STATE_BL_PROCESSING_APP ||
1883  ReceivedPayload_pu8[PARAM_BYTE_1_IDX] == STATE_BL_FLASH_APP ||
1884  ReceivedPayload_pu8[PARAM_BYTE_1_IDX] == STATE_BL_RDY_TO_LAUNCH ||
1885  ReceivedPayload_pu8[PARAM_BYTE_1_IDX] == STATE_BL_LAUNCHING_APP))
1886  {
1887  if (RdyCallback != NULL)
1888  {
1889  // Execute Callback function if one has been registered
1890  RdyCallback(SenderId_u16);
1891  }
1892  int sem_count = 0;
1893  sem_getvalue(&wait_ready_sem, &sem_count);
1894  if (sem_count == 0)
1895  {
1896  sem_post(&wait_ready_sem);
1897  }
1898  return true;
1899  }
1900  return false;
1901 }
1902 
1903 static bool IsSessionDataFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1904 {
1905  return Is1DFrame_b(SenderId_u16, ReceivedPayload_pu8) ||
1906  Is3DFrame_b(SenderId_u16, ReceivedPayload_pu8) ||
1907  IsNearFieldFrame_b(SenderId_u16, ReceivedPayload_pu8) ||
1908  IsNoiseLevelFrame_b(SenderId_u16, ReceivedPayload_pu8);
1909 }
1910 
1911 static bool IsLogMessage(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8)
1912 {
1913  MPRINTF("IsLogMessage\n");
1914  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_LOG_DEBUG ||
1915  ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_LOG_INFO ||
1916  ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_LOG_WARN ||
1917  ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_LOG_ERROR)
1918  {
1919  if (LogMsgCallback != NULL)
1920  {
1921  // Execute Callback function if one has been registered
1922  LogMsgCallback(SenderId_u16, ReceivedPayload_pu8);
1923  }
1924  return true;
1925  }
1926  return false;
1927 }
1928 
1929 static bool IsADCDumpStartFrame_b(uint16_t SenderId_u16, const uint8_t* ReceivedPayload_pu8)
1930 {
1931  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == CONTROL_BYTE_BEGIN_ADC_DUMP_SESSION)
1932  {
1933  uint32_t ADCDumpSize_u32 = 0;
1934  /*Get Value */
1935  memcpy(&ADCDumpSize_u32, &ReceivedPayload_pu8[PARAM_BYTE_1_IDX], sizeof(ADCDumpSize_u32));
1936  /* Ensure Endianness */
1937  ADCDumpSize_u32 = le32toh(ADCDumpSize_u32);
1938  ADCDumpSize_u32 = ADCDumpSize_u32 * CAN_MAX_FRAME_LEN;
1939  MPRINTF("Got ADC Dump Start Frame \n");
1940  MPRINTF("Current Sender: %d\n", SenderId_u16);
1941  MPRINTF("Promoted ADC Dumpsize: %d\n", ADCDumpSize_u32);
1942  int8_t CurrentSendersADCSessionIndex_i8 = GetCurrentSendersADCSessionIndex(SenderId_u16);
1943  if (CurrentSendersADCSessionIndex_i8 != -1)
1944  {
1945  // There is already data -> free data-pointer
1946  free(CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].DumpBlob_pu8);
1947  }
1948  else
1949  {
1950  CurrentSendersADCSessionIndex_i8 = CurrentADCSessions.NumberOfActiveSessions_u8;
1952  }
1953  MPRINTF("GetCurrentSendersADCSessionIndex: %d\n", CurrentSendersADCSessionIndex_i8);
1954  // Reset ADC-Session Data
1955  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].SenderId_u16 = SenderId_u16;
1956  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].ReceivedDumpSize_u32 = 0;
1957  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].ExpectedDumpSize_u32 =
1958  ADCDumpSize_u32;
1959  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].DumpBlob_pu8 =
1960  malloc(ADCDumpSize_u32);
1961  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].SessionState = RUNNING;
1962  if (ADCDumpStartRequestCallback != NULL)
1963  {
1964  // Execute Callback function if one has been registered
1965  ADCDumpStartRequestCallback(SenderId_u16, ADCDumpSize_u32);
1966  }
1967  ACKADCDumpStart(SenderId_u16);
1968  return true;
1969  }
1970 
1971  return false;
1972 }
1973 
1974 static bool IsADCDataFrame_b(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8, uint8_t len)
1975 {
1976  if (ReceivedPayload_pu8[CONTROL_BYTE_IDX] == ADC_FRAME_TYPE_DATA)
1977  {
1978  int8_t CurrentSendersADCSessionIndex_i8 = GetCurrentSendersADCSessionIndex(SenderId_u16);
1979  if (CurrentSendersADCSessionIndex_i8 != -1)
1980  {
1981  // There is already data -> free data-pointer
1982  uint32_t CurrentIndex_u32 =
1983  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].ReceivedDumpSize_u32;
1984  // Add Sanity-Check - only add data until allocated memory is full...
1985  uint32_t MaxIndex_u32 =
1986  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].ExpectedDumpSize_u32;
1987  if ((CurrentIndex_u32 + CAN_MAX_FRAME_LEN) <= MaxIndex_u32)
1988  {
1989  // Only copy from after the control byte
1990  memcpy(&CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8]
1991  .DumpBlob_pu8[CurrentIndex_u32],
1992  ReceivedPayload_pu8 + SUBCONTROL_BYTE_IDX, len - SUBCONTROL_BYTE_IDX);
1993  CurrentADCSessions.Dumps[CurrentSendersADCSessionIndex_i8].ReceivedDumpSize_u32 +=
1994  len - SUBCONTROL_BYTE_IDX;
1995  }
1996  else
1997  {
1998  MPRINTF("Warning - Received more data in dump than expected. Will not store this data\n");
1999  }
2000  }
2001  else
2002  {
2003  MPRINTF("WARNING - Received ADC-DATA-FRAME NOT BELONGING TO AN KNOWN SESSION\n");
2004  }
2005  return true;
2006  }
2007  return false;
2008 }
2009 
2010 static bool ParseMessage_b(uint16_t SenderId_u16, uint8_t* msg, uint8_t len)
2011 {
2012  MPRINTF("ParseMessage_b\n");
2013  if (IsSessionDataFrame_b(SenderId_u16, msg) || EvaluateACKStatus_b(SenderId_u16, msg) ||
2014  IsACKResponse_b(msg) || IsSessionStartFrame_b(SenderId_u16, msg) ||
2015  IsSessionEndFrame_b(SenderId_u16, msg) || IsReadyFrame(SenderId_u16, msg) ||
2016  IsLogMessage(SenderId_u16, msg) || IsADCDataFrame_b(SenderId_u16, msg, len) ||
2017  IsADCDumpStartFrame_b(SenderId_u16, msg))
2018  {
2019  SetCurrentStatusInformant_u16(SenderId_u16);
2020  return true;
2021  }
2022  return false;
2023 }
2024 #ifdef CAN_AVAILABLE
2025 
2026 static void FrameReadCallback(struct can_frame* frame)
2027 {
2028  MPRINTF("Got CAN Frame\n");
2029  if (frame->can_id <= UINT16_MAX)
2030  {
2031  uint16_t SenderId_u16 = frame->can_id;
2032  uint8_t Payload_u8p[CAN_MAX_FRAME_LEN] = {0};
2033  memcpy(Payload_u8p, frame->data,
2034  frame->can_dlc > CAN_MAX_FRAME_LEN ? CAN_MAX_FRAME_LEN : frame->can_dlc);
2035  PrintPayload(Payload_u8p);
2036 
2037  if (ParseMessage_b(SenderId_u16, Payload_u8p, frame->can_dlc))
2038  {
2040  SenderId_u16,
2041  0); //@Fixme: Callback must report interface name or better internal interface id..
2042  }
2043  else
2044  {
2045  MPRINTF("Warning - Not evaluable CAN-payload received.\n");
2046  PrintPayload(Payload_u8p);
2047  }
2048  }
2049  else
2050  {
2051  MPRINTF("Warning - This message from this sender ID %02X cannot be processed: ", frame->can_id);
2052  uint8_t Payload_u8p[CAN_MAX_FRAME_LEN] = {0};
2053  memcpy(Payload_u8p, frame->data,
2054  frame->can_dlc > CAN_MAX_FRAME_LEN ? CAN_MAX_FRAME_LEN : frame->can_dlc);
2055  PrintPayload(Payload_u8p);
2056  }
2057 }
2058 #endif
2059 
2060 static void UARTReadCallback(uint8_t* ReceivedUARTMsg_pu8, uint16_t UARTMsgLength_u16,
2061  uint8_t InterfaceId_u8)
2062 {
2063  MPRINTF("Got UART msg\n");
2064  uint16_t SenderId_u16 = 1; //@Fixme: Need to find a way to identify UART-Senders and incorporate
2065  // them in sender-scheme
2066  uint8_t SensorIndex = 0;
2067  for (SensorIndex = 0; SensorIndex < GetNumberOfKnownSensors(); SensorIndex++)
2068  {
2069  if (KnownSensors[SensorIndex].InterfaceIndex_u8 == InterfaceId_u8)
2070  {
2071  SenderId_u16 = KnownSensors[SensorIndex].InterfaceSensorId_u16;
2072  break;
2073  }
2074  }
2075  for (uint16_t Idx_u16 = 0; Idx_u16 < UARTMsgLength_u16; Idx_u16++)
2076  {
2077  MPRINTF("%02X ", ReceivedUARTMsg_pu8[Idx_u16]);
2078  switch (CurrentUARTMsg_t[SensorIndex].CurrentMessageState)
2079  {
2082 
2083  if (ReceivedUARTMsg_pu8[Idx_u16] == UART_START_FLAG)
2084  {
2085  /* If last byte was start-byte - first byte of next msg contains length */
2086  MPRINTF("Found Start Flag\n");
2087  CurrentUARTMsg_t[SensorIndex].CurrentMessageState =
2089  }
2090  break;
2092 
2093  /* Last MSG only contained a Start MSG before "cut off"*/
2094  CurrentUARTMsg_t[SensorIndex].CurrentMessageState =
2096  CurrentUARTMsg_t[SensorIndex].PayloadLen_u8 =
2097  ReceivedUARTMsg_pu8[Idx_u16] - UART_OVERHEAD_LENGTH;
2098  MPRINTF("Got Length: %d\n", CurrentUARTMsg_t[SensorIndex].PayloadLen_u8);
2099  break;
2101  MPRINTF("Payload\n");
2102 
2103  /* We got a start and know how many bytes we want to receive */
2104  /* Check if the current msg contains all bytes */
2105  CurrentUARTMsg_t[SensorIndex]
2107  ReceivedUARTMsg_pu8[Idx_u16];
2108 
2110  if (CurrentUARTMsg_t[SensorIndex].CurrentPayloadIndex_u8 ==
2111  CurrentUARTMsg_t[SensorIndex].PayloadLen_u8)
2112  {
2113  /* Got all bytes */
2115  }
2116 
2117  break;
2119  MPRINTF("Found Checksum\n");
2120  CurrentUARTMsg_t[SensorIndex].Checksum_u8 = ReceivedUARTMsg_pu8[Idx_u16];
2122  break;
2124  MPRINTF("Found Checksum\n");
2125  CurrentUARTMsg_t[SensorIndex].CurrentPayloadIndex_u8 = 0;
2127  uint8_t Payload_u8p[UART_MAX_FRAME_LEN] = {0};
2128  memcpy(Payload_u8p, CurrentUARTMsg_t[SensorIndex].Payload_pu8,
2129  CurrentUARTMsg_t[SensorIndex].PayloadLen_u8 >= UART_MAX_FRAME_LEN
2131  : CurrentUARTMsg_t[SensorIndex].PayloadLen_u8);
2132  if (ReceivedUARTMsg_pu8[Idx_u16] == UART_END_FLAG)
2133  {
2134  MPRINTF("Received complete uart message\n");
2135 
2136  if (ValidateUARTChecksum(&CurrentUARTMsg_t[SensorIndex]))
2137  {
2138  MPRINTF("Got this Msg from Sender. %d\n", SenderId_u16);
2139  PrintPayload(Payload_u8p);
2140  if (ParseMessage_b(SenderId_u16, Payload_u8p, UARTMsgLength_u16))
2141  {
2143  SenderId_u16,
2144  InterfaceId_u8); //@Fixme: Callback function must report interface name / id
2145  }
2146  else
2147  {
2148  MPRINTF("Warning - Not evaluable UART-payload received from Sender %d:\n",
2149  SenderId_u16);
2150  PrintPayload(Payload_u8p);
2151  MPRINTF("\n");
2152  for (int i = 0; i < UARTMsgLength_u16; i++)
2153  {
2154  MPRINTF("%02X ", ReceivedUARTMsg_pu8[i]);
2155  }
2156  MPRINTF("\n");
2157  }
2158  }
2159  else
2160  {
2161  MPRINTF("Warning - This uart message cannot be processed - Checksum Fail ");
2162  PrintPayload(Payload_u8p);
2163  }
2164  }
2165  else
2166  {
2167  MPRINTF("------------------------------------------------\n");
2168  MPRINTF("ERROR in UART Message - END FLAG NOT FOUND!\n");
2169  MPRINTF("Current Index in UART-MSG:%d (%02X)\n", Idx_u16, ReceivedUARTMsg_pu8[Idx_u16]);
2170  MPRINTF("Current UART-MSG-Len:%d\n", UARTMsgLength_u16);
2171  MPRINTF("Current UART-MSG: ");
2172  for (uint16_t Index = 0; Index < UARTMsgLength_u16; Index++)
2173  {
2174  MPRINTF("%02X ", ReceivedUARTMsg_pu8[Index]);
2175  }
2176  MPRINTF("\n");
2177  MPRINTF("CurrentUARTMsg_t:\n");
2178  MPRINTF("PayloadLen_u8:%02X\n", CurrentUARTMsg_t[SensorIndex].PayloadLen_u8);
2179  MPRINTF("Payload:\n");
2180  PrintPayload(Payload_u8p);
2181  MPRINTF("Checksum:%02X\n", CurrentUARTMsg_t[SensorIndex].Checksum_u8);
2182  MPRINTF("------------------------------------------------\n");
2183  }
2184 
2185  break;
2186  default:
2187  MPRINTF("INTERNAL ERROR: Unexpected UART Message State!\n");
2188  }
2189  }
2190  MPRINTF("\n");
2191 }
2192 
2194 {
2195  MPRINTF("RequestVersion\n");
2196  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2197  uint16_t length_u16 = 2;
2198 
2199  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_VERSION;
2200  payload_pu8[SUBCONTROL_BYTE_IDX] = TargetComponent_t;
2201  WaitForACK(payload_pu8, length_u16);
2202  Version_t retval;
2209  return retval;
2210 }
2211 
2212 static void Init_Semaphores()
2213 {
2214  if (!SemaphoresInit_b)
2215  {
2216  sem_init(&wait_ack_sem, 1, 1);
2217  sem_init(&wait_session_start_sem, 1, 1);
2218  sem_init(&wait_session_end_sem, 1, 1);
2219  sem_init(&wait_adc_session_end_sem, 1, 1);
2220  sem_init(&wait_ready_sem, 1, 1);
2221  SemaphoresInit_b = true;
2222  }
2223 }
2224 
2225 void InitInterface(char* InterfaceName, uint32_t DataRate_u32, CommsInterfaceType_t Interface_t)
2226 {
2227  Init_Semaphores();
2228  if (GetInterfaceIndex_i16(InterfaceName) == -1)
2229  {
2230  /* Interface not in Interface List */
2231  switch (Interface_t)
2232  {
2233 #ifdef CAN_AVAILABLE
2234  case IF_CAN:
2235  if (!GetConnectedToCANBus())
2236  {
2237  RegisterReadCallback(FrameReadCallback);
2238  SetupSocket(InterfaceName, DataRate_u32);
2239  SetConnectedToCANBus(true);
2240  AddInterfaceToInterfaceList(Interface_t, InterfaceName);
2241  }
2242  else
2243  {
2244  MPRINTF("Warning: An attempt was made to connect to the sensor repeatedly\n");
2245  }
2246  break;
2247 #endif
2248 #ifdef UART_AVAILABLE
2249  case IF_UART:
2250  //@Fixme - iterate interface list - only add if interface not in list yet
2252  SetupUARTPort(InterfaceName, DataRate_u32, NumberOfKnownInterfaces_u8);
2253  /*TODO: Add Interface Setup Code here */
2254  AddInterfaceToInterfaceList(Interface_t, InterfaceName);
2255  uint16_t UartNodeId_u16 = GetUARTNodeId(NumberOfKnownInterfaces_u8 - 1);
2257  ConnectedToCUART_b = true;
2258  break;
2259 #endif
2260 #ifdef USB_AVAILABLE
2261  case IF_USB:
2262  if (!ConnectedToUSB_b)
2263  {
2264  /*TODO: Add Interface Setup Code here */
2265  }
2266  AddInterfaceToInterfaceList(Interface_t, InterfaceName);
2267  break;
2268 #endif
2269  default:
2270  MPRINTF("Interface currently unsupported\n");
2271  }
2272  }
2273  else
2274  {
2275  MPRINTF("WARNING - An attempt was made to initialize the same interface repeatedly!\n");
2276  }
2277 }
2278 
2280 {
2281  switch (Interface_t)
2282  {
2283  case IF_CAN:
2284 #ifdef CAN_AVAILABLE
2285  if (GetConnectedToCANBus())
2286  {
2287  DeinitSocket();
2288  SetConnectedToCANBus(false);
2289  }
2290  else
2291  {
2292  MPRINTF(
2293  "An attempt was made to disconnect the connection to the sensor, although no "
2294  "connection has yet been established\n");
2295  }
2296 #endif
2297  break;
2298  case IF_UART:
2299 #ifdef UART_AVAILABLE
2300  if (ConnectedToCUART_b)
2301  {
2302  DeinitUARTPort();
2303  }
2304 #endif
2305  break;
2306  case IF_USB:
2307  if (ConnectedToUSB_b)
2308  {
2309  /*TODO: Add Interface Deinit Code here */
2310  }
2311  break;
2312  default:
2313  MPRINTF("Interface currently unsupported\n");
2314  }
2315 }
2316 
2318 {
2319  // Iterate all Responses
2320  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfSensorsACKIsExpectedFrom(); Idx_u8++)
2321  {
2323  {
2324  return false;
2325  }
2326  }
2327  return true;
2328 }
2329 
2331 {
2332  MPRINTF("RequestReboot\n");
2333  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2334  uint16_t length_u16 = 2;
2335 
2337  payload_pu8[SUBCONTROL_BYTE_IDX] = ACTION_BYTE_REBOOT;
2338  WaitForACK(payload_pu8, length_u16);
2339  bool result_b = RequestWasSuccessful_b();
2340  if (result_b)
2341  {
2342  /* Reboot command worked - remove Current-Target from SenderList*/
2344  }
2345  return result_b;
2346 }
2347 
2349 {
2350  MPRINTF("RequestMeasurement\n");
2352  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2353  uint16_t length_u16 = 2;
2354 
2357  WaitForACK(payload_pu8, length_u16);
2358  return RequestWasSuccessful_b();
2359 }
2360 
2362 {
2363  MPRINTF("RequestFactoryReset\n");
2364  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2365  uint16_t length_u16 = 2;
2366 
2369  WaitForACK(payload_pu8, length_u16);
2370  bool result_b = RequestWasSuccessful_b();
2371  if (result_b)
2372  {
2373  /* Reboot command worked - remove Current-Target from SenderList */
2375  }
2376  return result_b;
2377 }
2378 
2380 {
2381  MPRINTF("RequestStoreSettings\n");
2382  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2383  uint16_t length_u16 = 2;
2384 
2387  WaitForACK(payload_pu8, length_u16);
2388  return RequestWasSuccessful_b();
2389 }
2390 
2392 {
2393  MPRINTF("RequestLoadSettings\n");
2394  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2395  uint16_t length_u16 = 2;
2396 
2399  WaitForACK(payload_pu8, length_u16);
2400  bool result_b = RequestWasSuccessful_b();
2401  if (result_b)
2402  {
2403  /* Reboot command worked - remove Current-Target from SenderList*/
2405  }
2406  return result_b;
2407 }
2408 
2409 void SetSessionStateExpected(uint16_t TargetSensorId_u16)
2410 {
2411  if (TargetSensorId_u16 == MULTICAST_ID)
2412  {
2413  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
2414  {
2415  MPRINTF("Session State for Sessionindex %d - SensorId %d is set to EXPECTED\n", Idx_u8,
2418  }
2419  }
2420  else
2421  {
2422  MPRINTF("Trying to GetCurrentSendersSessionIndex\n");
2423  uint8_t TargetIndex_u8 = GetCurrentSendersSessionIndex(TargetSensorId_u16);
2424  MPRINTF("Session State for Sessionindex %d - SensorId %d is will be set to EXPECTED\n",
2425  TargetIndex_u8, CurrentSessions.ActiveSessions[TargetIndex_u8].SenderId_u16);
2427  MPRINTF("Session State for Sessionindex %d - SensorId %d is set to EXPECTED\n", TargetIndex_u8,
2428  CurrentSessions.ActiveSessions[TargetIndex_u8].SenderId_u16);
2429  }
2430 }
2431 
2432 void SetADCSessionStateExpected(uint16_t TargetSensorId_u16)
2433 {
2434  if (TargetSensorId_u16 == MULTICAST_ID)
2435  {
2436  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
2437  {
2439  }
2440  }
2441  else
2442  {
2443  uint8_t TargetIndex_u8 = GetCurrentSendersADCSessionIndex(TargetSensorId_u16);
2444  MPRINTF("ADC Session State for Sessionindex %d - SensorId %d is will be set to EXPECTED\n",
2445  TargetIndex_u8, CurrentADCSessions.Dumps[TargetIndex_u8].SenderId_u16);
2446  CurrentADCSessions.Dumps[TargetIndex_u8].SessionState = EXPECTED;
2447  }
2448 }
2449 
2450 bool GetSessionRunning_b(uint16_t TargetSensorId_u16)
2451 {
2452  bool AllSessionsStarted_b = true;
2453  MPRINTF("GetSessionRunning_b TargetSensorId_u16:%d\n", TargetSensorId_u16);
2454  if (TargetSensorId_u16 == MULTICAST_ID)
2455  {
2456  MPRINTF("GetSessionRunning_b / NumberOfKnownSensors:%d\n", GetNumberOfKnownSensors());
2457  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
2458  {
2460  RUNNING) // All Sessions Running?
2461  {
2462  AllSessionsStarted_b = false;
2463  break;
2464  }
2465  }
2466  }
2467  else
2468  {
2469  int8_t SenderIndex_i8 = GetCurrentSendersSessionIndex(GetCurrentTarget_u16());
2471  RUNNING)
2472  {
2473  AllSessionsStarted_b = false;
2474  }
2475  }
2476  return AllSessionsStarted_b;
2477 }
2478 
2479 bool GetSessionComplete_b(uint16_t TargetSensorId_u16)
2480 {
2481  bool AllSessionsComplete_b = true;
2482  if (TargetSensorId_u16 == MULTICAST_ID)
2483  {
2484  MPRINTF("GetSessionComplete_b / NumberOfKnownSensors:%d\n", GetNumberOfKnownSensors());
2485  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
2486  {
2488  COMPLETE) // All Sessions Running?
2489  {
2490  AllSessionsComplete_b = false;
2491  break;
2492  }
2493  }
2494  }
2495  else
2496  {
2497  int8_t SenderIndex_i8 = GetCurrentSendersSessionIndex(GetCurrentTarget_u16());
2499  COMPLETE)
2500  {
2501  AllSessionsComplete_b = false;
2502  }
2503  }
2504  return AllSessionsComplete_b;
2505 }
2506 
2507 bool GetADCSessionRunning_b(uint16_t TargetSensorId_u16)
2508 {
2509  bool AllSessionsStarted_b = true;
2510  if (TargetSensorId_u16 == MULTICAST_ID)
2511  {
2512  MPRINTF("GetADCSessionRunning_b / NumberOfKnownSensors:%d\n", GetNumberOfKnownSensors());
2513  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
2514  {
2515  if (CurrentADCSessions.Dumps[Idx_u8].SessionState != RUNNING) // All Sessions Running?
2516  {
2517  AllSessionsStarted_b = false;
2518  break;
2519  }
2520  }
2521  }
2522  else
2523  {
2524  int8_t SenderIndex_i8 = GetCurrentSendersADCSessionIndex(GetCurrentTarget_u16());
2525  if (CurrentADCSessions.Dumps[SenderIndex_i8].SessionState != RUNNING)
2526  {
2527  AllSessionsStarted_b = false;
2528  }
2529  }
2530  return AllSessionsStarted_b;
2531 }
2532 
2533 bool GetADCSessionComplete_b(uint16_t TargetSensorId_u16)
2534 {
2535  bool AllSessionsComplete_b = true;
2536  if (TargetSensorId_u16 == MULTICAST_ID)
2537  {
2538  MPRINTF("GetADCSessionComplete_b / NumberOfKnownSensors:%d\n", GetNumberOfKnownSensors());
2539  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
2540  {
2541  if (CurrentADCSessions.Dumps[Idx_u8].SessionState != COMPLETE) // All Sessions Running?
2542  {
2543  AllSessionsComplete_b = false;
2544  break;
2545  }
2546  }
2547  }
2548  else
2549  {
2550  int8_t SenderIndex_i8 = GetCurrentSendersADCSessionIndex(GetCurrentTarget_u16());
2551  if (CurrentADCSessions.Dumps[SenderIndex_i8].SessionState != COMPLETE)
2552  {
2553  AllSessionsComplete_b = false;
2554  }
2555  }
2556  return AllSessionsComplete_b;
2557 }
2558 
2560 {
2561  MPRINTF("RequestADCDump\n");
2563  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2564  uint16_t length_u16 = 2;
2565 
2568  WaitForACK(payload_pu8, length_u16);
2569  return RequestWasSuccessful_b();
2570 }
2571 
2572 // Setter
2573 
2574 static bool SetParameterSuccessful_b(const uint8_t* request, const uint8_t* response)
2575 {
2576  MPRINTF("SetParameterSuccessful_b\n");
2577  PrintPayload(request);
2579  if (request != NULL && response != NULL)
2580  {
2585  }
2586  return false;
2587 }
2588 
2589 static bool ActionRequestSuccessful_b(const uint8_t* request, const uint8_t* response)
2590 {
2591  if (request != NULL && response != NULL)
2592  {
2595  }
2596  return false;
2597 }
2598 
2599 // ADC
2600 
2601 bool SetParameterADCUseFixedFrameRate(bool UseFixedFrameRate_b)
2602 {
2603  MPRINTF("SetParameterADCUseFixedFrameRate\n");
2604  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2605  uint16_t length_u16 = SET_U8_LEN;
2606 
2607  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2610  payload_pu8[PARAM_BYTE_2_IDX] = UseFixedFrameRate_b;
2611  WaitForACK(payload_pu8, length_u16);
2612  return RequestWasSuccessful_b();
2613 }
2614 
2615 bool SetParameterADCFixedFrameRate(uint8_t FrameRate_u8)
2616 {
2617  MPRINTF("SetParameterADCFixedFrameRate\n");
2618  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2619  uint16_t length_u16 = SET_U8_LEN;
2620 
2621  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2624  payload_pu8[PARAM_BYTE_2_IDX] = FrameRate_u8;
2625  WaitForACK(payload_pu8, length_u16);
2626  return RequestWasSuccessful_b();
2627 }
2628 
2629 // Transducer
2630 
2631 bool SetParameterTransducerVolume(uint8_t Volume_u8)
2632 {
2633  MPRINTF("SetParameterTransducerVolume\n");
2634  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2635  uint16_t length_u16 = SET_U8_LEN;
2636 
2637  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2640  payload_pu8[PARAM_BYTE_2_IDX] = Volume_u8;
2641  WaitForACK(payload_pu8, length_u16);
2642  return RequestWasSuccessful_b();
2643 }
2644 
2645 bool SetParameterTransducerNumOfPulses(uint8_t NumOfPulses_u8)
2646 {
2647  MPRINTF("SetParameterTransducerNumOfPulses\n");
2648  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2649  uint16_t length_u16 = SET_U8_LEN;
2650 
2651  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2654  payload_pu8[PARAM_BYTE_2_IDX] = NumOfPulses_u8;
2655  WaitForACK(payload_pu8, length_u16);
2656  return RequestWasSuccessful_b();
2657 }
2658 
2660 {
2661  MPRINTF("SetParameterSignalProcessingTemperature\n");
2662  int32_t Temperature_i32 = (int32_t)(Temperature_f * FLOAT_CONVERSION_FACTOR);
2663  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2664  uint16_t length_u16 = SET_U32_LEN;
2665  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2668  /* Ensure Endianness fits */
2669  Temperature_i32 = htole32(Temperature_i32);
2670  /* Copy Bytes to payload */
2671  memcpy(&payload_pu8[PARAM_BYTE_2_IDX], &Temperature_i32, sizeof(Temperature_i32));
2672  WaitForACK(payload_pu8, length_u16);
2673  return RequestWasSuccessful_b();
2674 }
2675 
2676 bool SetParameterSignalProcessingHumidity(uint8_t Humidity_u8)
2677 {
2678  MPRINTF("SetParameterSignalProcessingHumidity\n");
2679  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2680  uint16_t length_u16 = SET_U8_LEN;
2681 
2682  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2685  payload_pu8[PARAM_BYTE_2_IDX] = Humidity_u8;
2686  WaitForACK(payload_pu8, length_u16);
2687  return RequestWasSuccessful_b();
2688 }
2689 
2691 {
2692  MPRINTF("SetParameterSignalProcessingNoiseLevelThresholdFactor\n");
2693  uint16_t Threshold_u16 = (uint16_t)(Factor_f * FLOAT_CONVERSION_FACTOR);
2694  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2695  uint16_t length_u16 = SET_U16_LEN;
2696  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2699  /* Ensure Endianness fits */
2700  Threshold_u16 = htole16(Threshold_u16);
2701  /* Copy Bytes to payload */
2702  memcpy(&payload_pu8[PARAM_BYTE_2_IDX], &Threshold_u16, sizeof(Threshold_u16));
2703  WaitForACK(payload_pu8, length_u16);
2704  return RequestWasSuccessful_b();
2705 }
2706 
2708 {
2709  MPRINTF("SetParameterSignalProcessingHumidity\n");
2710  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2711  uint16_t length_u16 = SET_U8_LEN;
2712 
2713  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2716  payload_pu8[PARAM_BYTE_2_IDX] = Threshold_u8;
2717  WaitForACK(payload_pu8, length_u16);
2718  return RequestWasSuccessful_b();
2719 }
2720 
2722 {
2723  MPRINTF("SetParameterSignalProcessingEnableNearFieldDetection\n");
2724  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2725  uint16_t length_u16 = SET_U8_LEN;
2726 
2727  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2730  payload_pu8[PARAM_BYTE_2_IDX] = Enable_b;
2731  WaitForACK(payload_pu8, length_u16);
2732  return RequestWasSuccessful_b();
2733 }
2734 
2736 {
2737  MPRINTF("SetParameterSignalProcessingEnableMultipathFilter\n");
2738  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2739  uint16_t length_u16 = SET_U8_LEN;
2740 
2741  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2744  payload_pu8[PARAM_BYTE_2_IDX] = Enable_b;
2745  WaitForACK(payload_pu8, length_u16);
2746  return RequestWasSuccessful_b();
2747 }
2748 
2750 {
2751  MPRINTF("SetParameterSignalProcessingEnableAutoGain\n");
2752  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2753  uint16_t length_u16 = SET_U8_LEN;
2754 
2755  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2758  payload_pu8[PARAM_BYTE_2_IDX] = Enable_b;
2759  WaitForACK(payload_pu8, length_u16);
2760  return RequestWasSuccessful_b();
2761 }
2762 
2763 // System
2764 
2765 bool SetParameterSystemNodeID(uint16_t NodeID_u16)
2766 {
2767  bool result_b = false;
2769  {
2770  MPRINTF("SetParameterSystemNodeID\n");
2771  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2772  uint16_t length_u16 = SET_U16_LEN;
2773 
2774  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2777  /* Ensure Endianness fits */
2778  NodeID_u16 = htole16(NodeID_u16);
2779  /* Copy Bytes to payload */
2780  memcpy(&payload_pu8[PARAM_BYTE_2_IDX], &NodeID_u16, sizeof(NodeID_u16));
2781 
2782  WaitForACK(payload_pu8, length_u16);
2783  result_b = RequestWasSuccessful_b();
2784  if (result_b)
2785  {
2786  /* Changing NodeId worked - replace CurrentStatusInformant_u16 (reporter of the ack msg) with
2787  * NodeID_u16*/
2789  }
2790  }
2791  else
2792  {
2793  MPRINTF("Set Node ID does not support MULTICAST_ID!\n");
2794  }
2795  return result_b;
2796 }
2797 
2799 {
2800  MPRINTF("SetParameterSystemLogLevel\n");
2801  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2802  uint16_t length_u16 = SET_U8_LEN;
2803 
2804  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2807  payload_pu8[PARAM_BYTE_2_IDX] = LogLevel_t;
2808  WaitForACK(payload_pu8, length_u16);
2809  return RequestWasSuccessful_b();
2810 }
2811 
2813 {
2814  MPRINTF("SetParameterSystemMode\n");
2815  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2816  uint16_t length_u16 = SET_U8_LEN;
2817 
2818  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_SET;
2821  payload_pu8[PARAM_BYTE_2_IDX] = Mode_t;
2822  WaitForACK(payload_pu8, length_u16);
2823  bool result_b = RequestWasSuccessful_b();
2824  if (result_b)
2825  {
2826  for (uint8_t idx_u8 = 0; idx_u8 < GetNumberOfKnownSensors(); idx_u8++)
2827  {
2829  GetCurrentTarget_u16() == 0)
2830  {
2831  MPRINTF("Sensor Index %d Mode set to %d\n", idx_u8, Mode_t);
2832  KnownSensors[idx_u8].SensorMode = Mode_t;
2833  }
2834  }
2835  }
2836 
2837  return result_b;
2838 }
2839 
2840 // Getter
2841 
2842 bool GetBoolFromPayload_b(const uint8_t* Payload_pu8)
2843 {
2844  bool retval = false;
2845  uint8_t CurrentACK_u8 = Payload_pu8[CONTROL_BYTE_IDX];
2846  if (CurrentACK_u8 != CONTROL_BYTE_NACK)
2847  {
2848  if (Payload_pu8[PARAM_BYTE_2_IDX] != 0)
2849  {
2850  retval = true;
2851  }
2852  }
2853  return retval;
2854 }
2855 
2856 uint8_t GetU8FromPayload_u8(const uint8_t* Payload_pu8)
2857 {
2858  uint8_t retval = 0;
2859  uint8_t CurrentACK_u8 = Payload_pu8[CONTROL_BYTE_IDX];
2860  if (CurrentACK_u8 != CONTROL_BYTE_NACK)
2861  {
2862  retval = Payload_pu8[PARAM_BYTE_2_IDX];
2863  }
2864  return retval;
2865 }
2866 
2867 uint8_t GetU8FromTwoArgumentPayload_u8(const uint8_t* Payload_pu8)
2868 {
2869  uint8_t retval = 0;
2870  uint8_t CurrentACK_u8 = Payload_pu8[CONTROL_BYTE_IDX];
2871  if (CurrentACK_u8 != CONTROL_BYTE_NACK)
2872  {
2873  retval = Payload_pu8[PARAM_BYTE_3_IDX];
2874  }
2875  return retval;
2876 }
2877 
2878 uint16_t GetU16FromPayload_u16(const uint8_t* Payload_pu8)
2879 {
2880  uint16_t retval = 0;
2881  uint8_t CurrentACK_u8 = Payload_pu8[CONTROL_BYTE_IDX];
2882  if (CurrentACK_u8 != CONTROL_BYTE_NACK)
2883  {
2884  PrintPayload(Payload_pu8);
2885  /* Get Payload Value */
2886  uint16_t PayloadValue_u16 = 0;
2887  memcpy(&PayloadValue_u16, &Payload_pu8[PARAM_BYTE_2_IDX], sizeof(PayloadValue_u16));
2888  /* Ensure Endianness */
2889  retval = le16toh(PayloadValue_u16);
2890  }
2891  return retval;
2892 }
2893 
2894 uint16_t GetU16FromTwoArgumentPayload_u16(const uint8_t* Payload_pu8)
2895 {
2896  uint16_t retval = 0;
2897  uint8_t CurrentACK_u8 = Payload_pu8[CONTROL_BYTE_IDX];
2898  if (CurrentACK_u8 != CONTROL_BYTE_NACK)
2899  {
2900  /* Get Payload Value */
2901  uint16_t PayloadValue_u16 = 0;
2902  memcpy(&PayloadValue_u16, &Payload_pu8[PARAM_BYTE_3_IDX], sizeof(PayloadValue_u16));
2903  /* Ensure Endianness */
2904  retval = le16toh(PayloadValue_u16);
2905  }
2906  return retval;
2907 }
2908 
2909 int32_t GetI32FromPayload_i32(const uint8_t* Payload_pu8)
2910 {
2911  int32_t retval = 0;
2912  uint8_t CurrentACK_u8 = Payload_pu8[CONTROL_BYTE_IDX];
2913  if (CurrentACK_u8 != CONTROL_BYTE_NACK)
2914  {
2915  /* Get Payload Value */
2916  int32_t PayloadValue_i32 = 0;
2917  memcpy(&PayloadValue_i32, &Payload_pu8[PARAM_BYTE_2_IDX], sizeof(PayloadValue_i32));
2918  /* Ensure Endianness */
2919  retval = le32toh(PayloadValue_i32);
2920  }
2921  return retval;
2922 }
2923 
2924 int32_t GetI32FromTwoArgumentPayload_i32(const uint8_t* Payload_pu8)
2925 {
2926  int32_t retval = 0;
2927  uint8_t CurrentACK_u8 = Payload_pu8[CONTROL_BYTE_IDX];
2928  if (CurrentACK_u8 != CONTROL_BYTE_NACK)
2929  {
2930  /* Get Payload Value */
2931  int32_t PayloadValue_i32 = 0;
2932  memcpy(&PayloadValue_i32, &Payload_pu8[PARAM_BYTE_3_IDX], sizeof(PayloadValue_i32));
2933  /* Ensure Endianness */
2934  retval = le32toh(PayloadValue_i32);
2935  }
2936  return retval;
2937 }
2938 
2940 {
2941  MPRINTF("GetParameterADCUseFixedFrameRate\n");
2942  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2943  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
2944 
2945  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
2948  WaitForACK(payload_pu8, length_u16);
2949  return GetBoolFromPayload_b(
2951 }
2952 
2954 {
2955  MPRINTF("GetParameterADCFixedFrameRate\n");
2956  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2957  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
2958 
2959  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
2962  WaitForACK(payload_pu8, length_u16);
2963  return GetU8FromPayload_u8(
2965 }
2966 
2967 // Transducer
2968 
2970 {
2971  MPRINTF("GetParameterTransducerVolume\n");
2972  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2973  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
2974 
2975  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
2978  WaitForACK(payload_pu8, length_u16);
2979  return GetU8FromPayload_u8(
2981 }
2982 
2984 {
2985  MPRINTF("GetParameterTransducerNumOfPulses\n");
2986  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
2987  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
2988 
2989  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
2992  WaitForACK(payload_pu8, length_u16);
2993  return GetU8FromPayload_u8(
2995 }
2996 
2998 {
2999  MPRINTF("GetParameterSignalProcessingTemperature_f\n");
3000  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3001  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3002 
3003  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3006  WaitForACK(payload_pu8, length_u16);
3007  int32_t payload_value_i32 = GetI32FromPayload_i32(
3010  MPRINTF("payload_value_i32: %d\n", payload_value_i32);
3011  float TemperatureInDegrees_f = (float)payload_value_i32 / (float)FLOAT_CONVERSION_FACTOR;
3012  return TemperatureInDegrees_f;
3013 }
3014 
3016 {
3017  MPRINTF("GetParameterSignalProcessingHumidity_u8\n");
3018  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3019  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3020 
3021  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3024  WaitForACK(payload_pu8, length_u16);
3025  return GetU8FromPayload_u8(
3027 }
3028 
3030 {
3031  MPRINTF("GetParameterSignalProcessingNoiseLevelThresholdFactor_f\n");
3032  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3033  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3034 
3035  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3038  WaitForACK(payload_pu8, length_u16);
3039  int32_t payload_value_i32 = GetI32FromPayload_i32(
3041  float payload_value_f = (float)payload_value_i32 / (float)FLOAT_CONVERSION_FACTOR;
3042  return payload_value_f;
3043 }
3044 
3046 {
3047  MPRINTF("GetParameterSignalProcessingNoiseRatioThreshold_u8\n");
3048  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3049  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3050 
3051  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3054  WaitForACK(payload_pu8, length_u16);
3055  return GetU8FromPayload_u8(
3057 }
3058 
3060 {
3061  MPRINTF("GetParameterSignalProcessingEnableNearFieldDetection_b\n");
3062  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3063  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3064 
3065  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3068  WaitForACK(payload_pu8, length_u16);
3069  return GetBoolFromPayload_b(
3071 }
3072 
3074 {
3075  MPRINTF("GetParameterSignalProcessingEnableMultipathFilter_b\n");
3076  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3077  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3078 
3079  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3082  WaitForACK(payload_pu8, length_u16);
3083  return GetBoolFromPayload_b(
3085 }
3086 
3088 {
3089  MPRINTF("GetParameterSignalProcessingEnableAutoGain_b\n");
3090  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3091  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3092 
3093  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3096  WaitForACK(payload_pu8, length_u16);
3097  return GetBoolFromPayload_b(
3099 }
3100 
3101 // System
3102 
3104 {
3105  MPRINTF("GetParameterSystemNodeID\n");
3106  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3107  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3108 
3109  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3112  WaitForACK(payload_pu8, length_u16);
3113  return GetU16FromPayload_u16(
3115 }
3116 
3117 static uint16_t GetUARTNodeId(uint8_t InterfaceId_u8)
3118 {
3119  MPRINTF("GetUARTNodeId for Interface-Id: %d\n", InterfaceId_u8);
3120  MPRINTF("InterfaceName_cp: %s\n", KnownInterfaces_tp[InterfaceId_u8].InterfaceName);
3121  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3122  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3123  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3126  uint16_t TmpCurrentTarget_u16 = GetCurrentTarget_u16();
3127  uint8_t TmpNumberOfKnownSensors_8 = GetNumberOfKnownSensors();
3130  SendViaUART(payload_pu8, length_u16, InterfaceId_u8);
3131  WaitForACKNoSend(payload_pu8);
3132  SetCurrentTarget_u16(TmpCurrentTarget_u16);
3133  SetNumberOfKnownSensors(TmpNumberOfKnownSensors_8);
3134  return GetU16FromPayload_u16(
3136 }
3137 
3139 {
3140  MPRINTF("GetParameterSystemMCUTemperature_f\n");
3141  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3142  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3143 
3144  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3147  WaitForACK(payload_pu8, length_u16);
3148  int32_t payload_value_i32 = GetI32FromPayload_i32(
3151  MPRINTF("payload_value_i32: %d\n", payload_value_i32);
3152  float TemperaturInDegree_f = (float)payload_value_i32 / (float)FLOAT_CONVERSION_FACTOR;
3153  return TemperaturInDegree_f;
3154 }
3155 
3157 {
3158  MPRINTF("GetParameterSystemLogLevel\n");
3159  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3160  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3161 
3162  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3165  WaitForACK(payload_pu8, length_u16);
3168 }
3169 
3171 {
3172  MPRINTF("GetParameterSystemResetReason_t\n");
3173  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3174  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3175 
3176  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3179  WaitForACK(payload_pu8, length_u16);
3182 }
3183 
3185 {
3186  MPRINTF("GetParameterSystemSensorState_t\n");
3187  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3188  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3189 
3190  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3193  WaitForACK(payload_pu8, length_u16);
3196 }
3197 
3199 {
3200  MPRINTF("GetParameterSystemUniqueID_t\n");
3201  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3202  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN + 1;
3203 
3204  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3207  payload_pu8[PARAM_BYTE_2_IDX] = Index_u8;
3208  WaitForACK(payload_pu8, length_u16);
3209  UID_t retval;
3210  memcpy(retval.values,
3213  UID_SIZE);
3214  return retval;
3215 }
3216 
3218 {
3219  MPRINTF("GetParameterSystemMode\n");
3220  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3221  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3222 
3223  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3226  WaitForACK(payload_pu8, length_u16);
3229 }
3230 
3232 {
3233  MPRINTF("GetParameterSystemCalibrationState_b\n");
3234  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3235  uint16_t length_u16 = STANDARD_GET_MESSAGE_LEN;
3236 
3237  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_GET;
3240  WaitForACK(payload_pu8, length_u16);
3241  return (bool)GetU8FromPayload_u8(
3243 }
3244 
3245 void ACKSessionStart(uint16_t TargetSensor_u16)
3246 {
3247  MPRINTF("ACKSessionStart\n");
3248  int8_t Index_i8 = GetCurrentSendersSessionIndex(TargetSensor_u16);
3249  if (Index_i8 == -1)
3250  {
3251  MPRINTF("Error - attempted ack to nonexistent session\n");
3252  }
3253  else
3254  {
3255  uint16_t TmpTarget_u16 = GetCurrentTarget_u16();
3256  SetCurrentTarget_u16(TargetSensor_u16);
3257  uint8_t PromotedSessionSize_u8 = CurrentSessions.ActiveSessions[Index_i8].NumberOfPoints_u8;
3258  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3259  uint16_t length_u16 = START_POINT_SESSION_ACK_LEN;
3260 
3261  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_ACK;
3263  payload_pu8[PARAM_BYTE_1_IDX] = 0;
3264  payload_pu8[PARAM_BYTE_2_IDX] = PromotedSessionSize_u8;
3265  SendCommand(payload_pu8, length_u16);
3266  SetCurrentTarget_u16(TmpTarget_u16);
3267  }
3268 }
3269 
3270 void ACKADCDumpStart(uint16_t TargetSensor_u16)
3271 {
3272  MPRINTF("ACKADCDumpStart\n");
3273  int8_t Index_i8 = GetCurrentSendersADCSessionIndex(TargetSensor_u16);
3274  uint16_t TmpCurrentTarget_u16 = GetCurrentTarget_u16();
3275  SetCurrentTarget_u16(TargetSensor_u16);
3276  if (Index_i8 == -1)
3277  {
3278  MPRINTF("Error - attempted ack to nonexistent dump\n");
3279  }
3280  else
3281  {
3282  uint32_t PromotedDumpSize_u32 =
3284  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3285  uint16_t length_u16 = START_ADC_DUMP_SESSION_ACK_LEN;
3286 
3287  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_ACK;
3289  payload_pu8[PARAM_BYTE_1_IDX] = 0;
3290  /* Ensure Endianness fits */
3291  PromotedDumpSize_u32 = htole32(PromotedDumpSize_u32);
3292  /* Copy Bytes to payload */
3293  memcpy(&payload_pu8[PARAM_BYTE_2_IDX], &PromotedDumpSize_u32, sizeof(PromotedDumpSize_u32));
3294  SendCommand(payload_pu8, length_u16);
3295  }
3296  SetCurrentTarget_u16(TmpCurrentTarget_u16);
3297 }
3298 
3300 {
3301  uint8_t payload_pu8[CAN_MAX_FRAME_LEN] = {0};
3302  uint16_t length_u16 = EOS_ACK_LEN;
3303 
3304  payload_pu8[CONTROL_BYTE_IDX] = CONTROL_BYTE_ACK;
3305  payload_pu8[SUBCONTROL_BYTE_IDX] = CONTROL_BYTE_EOS;
3306  SendCommand(payload_pu8, length_u16);
3307 }
3308 
3309 void RegisterSessionStartCallback(void (*Callback)(uint16_t Sender_u16))
3310 {
3311  MPRINTF("RegisterSessionStartCallback\n");
3312  SessionStartCallback = Callback;
3313 }
3314 
3315 void* WaitForACKTimeout(void* vargp)
3316 {
3317  int timeout = *((int*)vargp);
3318  usleep(timeout);
3319  MPRINTF("Timeout occurred WaitForACK\n");
3320  sem_post(&wait_ack_sem);
3321  pthread_exit(0);
3322 }
3323 
3324 void* WaitForSessionStartTimeout(void* vargp)
3325 {
3326  int timeout = *((int*)vargp);
3327  usleep(timeout);
3328  MPRINTF("Timeout occurred SessionStart\n");
3329  sem_post(&wait_session_start_sem);
3330  pthread_exit(0);
3331 }
3332 
3333 void* WaitForSessionEndTimeout(void* vargp)
3334 {
3335  int timeout = *((int*)vargp);
3336  usleep(timeout);
3337  MPRINTF("Timeout occurred SessionEnd\n");
3338  sem_post(&wait_session_end_sem);
3339  pthread_exit(0);
3340 }
3341 
3343 {
3345  {
3346  pthread_create(&timeoutID, NULL, WaitForSessionStartTimeout, &timeoutmSeconds);
3347  MPRINTF("Not all Sessions Started yet - wait for: %d sensors\n",
3349  sem_wait(&wait_session_start_sem);
3350  sem_wait(&wait_session_start_sem);
3351  sem_post(&wait_session_start_sem);
3352  pthread_cancel(timeoutID);
3353  pthread_join(timeoutID, NULL);
3354  }
3356 }
3357 
3358 void RegisterPointSessionEndCallback(void (*Callback)(uint16_t Sender_u16))
3359 {
3360  MPRINTF("RegisterPointSessionEndCallback\n");
3361  SessionEndCallback = Callback;
3362 }
3363 
3364 void RegisterADCDumpSessionEndCallback(void (*Callback)(uint16_t Sender_u16))
3365 {
3366  MPRINTF("RegisterPointSessionEndCallback\n");
3367  ADCDUmpEndCallback = Callback;
3368 }
3369 
3371 {
3373  {
3374  pthread_create(&timeoutID, NULL, WaitForSessionEndTimeout, &timeoutmSeconds);
3375  sem_wait(&wait_session_end_sem);
3376  sem_wait(&wait_session_end_sem);
3377  sem_post(&wait_session_end_sem);
3378  pthread_cancel(timeoutID);
3379  pthread_join(timeoutID, NULL);
3380  }
3382 }
3383 
3385 {
3387  {
3388  sem_wait(&wait_adc_session_end_sem);
3389  sem_wait(&wait_adc_session_end_sem);
3390  sem_post(&wait_adc_session_end_sem);
3391  }
3393 }
3394 
3395 uint16_t WaitForReady()
3396 {
3397  sem_wait(&wait_ready_sem);
3398  sem_wait(&wait_ready_sem);
3399  sem_post(&wait_ready_sem);
3401 }
3402 
3403 void RegisterRdyCallback(void (*Callback)(uint16_t Sender_u16))
3404 {
3405  MPRINTF("RegisterRdyCallback\n");
3406  RdyCallback = Callback;
3407 }
3408 
3409 void RegisterLogMsgCallback(void (*Callback)(uint16_t Sender_u16, uint8_t* ReceivedPayload_pu8))
3410 {
3411  MPRINTF("RegisterLogMsgCallback\n");
3412  LogMsgCallback = Callback;
3413 }
3414 
3415 void RegisterADCDumpStartRequestCallback(void (*Callback)(uint16_t Sender_u16,
3416  uint32_t ADCDumpSize_32))
3417 {
3418  MPRINTF("ADCDumpStartRequestCallback\n");
3419  ADCDumpStartRequestCallback = Callback;
3420 }
3421 
3422 Sensor_Session_t* GetSessionData(uint16_t Sender_u16)
3423 {
3424  MPRINTF("GetSessionData\n");
3425  Sensor_Session_t* RequestedSessionData = NULL;
3426  int8_t Index_i8 = GetCurrentSendersSessionIndex(Sender_u16);
3427  MPRINTF("Current Index: %d\n", Index_i8);
3428  if (Index_i8 == -1)
3429  {
3430  MPRINTF("Error - attempted access to nonexistent session data\n");
3431  }
3432  else
3433  {
3435  {
3436  MPRINTF("Warning attempted access to incomplete session!\n");
3437  }
3438  RequestedSessionData = GetCurrentSessionsActiveSessions(Index_i8);
3439  }
3440  return RequestedSessionData;
3441 }
3442 
3443 ADCDump_t* GetADCDumpData(uint16_t Sender_u16)
3444 {
3445  MPRINTF("GetADCDumpData\n");
3446  ADCDump_t* RequestedDumpData = NULL;
3447  int8_t Index_i8 = GetCurrentSendersADCSessionIndex(Sender_u16);
3448  if (Index_i8 == -1)
3449  {
3450  MPRINTF("Error - attempted access to nonexistent dump data\n");
3451  }
3452  else
3453  {
3454  if (CurrentADCSessions.Dumps[Index_i8].SessionState != COMPLETE)
3455  {
3456  MPRINTF("Warning attempted access to incomplete dump!\n");
3457  }
3458  RequestedDumpData = &CurrentADCSessions.Dumps[Index_i8];
3459  }
3460  return RequestedDumpData;
3461 }
3462 
3463 static void ReplaceIdInListOfKnownSensors(uint16_t OldId_u16, uint16_t NewId_u16)
3464 {
3465  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
3466  {
3467  if (GetInterfaceSensorIdFromSensor(GetKnownSensor(Idx_u8)) == OldId_u16)
3468  {
3469  /* Sender found - replace now */
3470  KnownSensors[Idx_u8].InterfaceSensorId_u16 = NewId_u16;
3471  }
3472  }
3473 }
3474 
3476 {
3477  for (uint8_t Idx_u8 = 0; Idx_u8 < MAX_NUMBER_OF_SENSORS_ON_BUS; Idx_u8++)
3478  {
3479  KnownSensors[Idx_u8].InterfaceSensorId_u16 = 0;
3480  }
3482 }
3483 
3484 static void RemoveSenderFromList(uint16_t Sender_u16)
3485 {
3486  if (Sender_u16 == MULTICAST_ID)
3487  {
3489  }
3490  else
3491  {
3492  bool FoundSender_b = false;
3493  for (uint8_t Idx_u8 = 0; Idx_u8 < GetNumberOfKnownSensors(); Idx_u8++)
3494  {
3495  // Get postion of sender to be removed
3496  if (GetInterfaceSensorIdFromSensor(GetKnownSensor(Idx_u8)) == Sender_u16)
3497  {
3498  FoundSender_b = true;
3499  }
3500  // If position was once found - move items afterwars one step up
3501  if (FoundSender_b)
3502  {
3503  if ((Idx_u8 + 1) < MAX_NUMBER_OF_SENSORS_ON_BUS)
3504  {
3505  KnownSensors[Idx_u8] = KnownSensors[Idx_u8 + 1];
3506  }
3507  else
3508  {
3509  KnownSensors[Idx_u8].InterfaceSensorId_u16 = 0;
3510  KnownSensors[Idx_u8].InterfaceIndex_u8 = 0;
3511  }
3512  }
3513  }
3514  if (FoundSender_b)
3515  {
3517  }
3518  }
3519 }
3520 
3521 void ParseLogMessageToText(char* Output_p8, uint16_t SenderId_u16,
3522  const uint8_t* ReceivedPayload_pu8)
3523 {
3524  int32_t Idx_i32 = sprintf(Output_p8, "Sensor 0x%03X - ", SenderId_u16);
3525  bool ValidSeverityByte_B = true;
3526  switch (ReceivedPayload_pu8[LOGGING_SEVERITY_BYTE])
3527  {
3529  Idx_i32 += sprintf(Output_p8 + Idx_i32, "[Debug] - ");
3530  break;
3531  case CONTROL_BYTE_LOG_INFO:
3532  Idx_i32 += sprintf(Output_p8 + Idx_i32, "[Info] - ");
3533  break;
3534  case CONTROL_BYTE_LOG_WARN:
3535  Idx_i32 += sprintf(Output_p8 + Idx_i32, "[Warn] - ");
3536  break;
3538  Idx_i32 += sprintf(Output_p8 + Idx_i32, "[Error] - ");
3539  break;
3540  default:
3541  ValidSeverityByte_B = false;
3542  break;
3543  }
3544 
3545  if (ValidSeverityByte_B)
3546  {
3547  switch (ReceivedPayload_pu8[LOGGING_CATEGORY_BYTE])
3548  {
3549  case LOG_CAT_RESET_REASON:
3550  ParseResetReasonLogMessageToText(Output_p8 + Idx_i32, ReceivedPayload_pu8);
3551  break;
3552  case LOG_CAT_BOOTLOADER:
3553  ParseBootloaderLogMessageToText(Output_p8 + Idx_i32, ReceivedPayload_pu8);
3554  break;
3555  case LOG_CAT_COMMUNICATION:
3556  case LOG_CAT_PERIPHERAL:
3557  case LOG_CAT_USER:
3558  break;
3559  case LOG_CAT_SELF_CHECK:
3560  ParseSelfCheckLogMessageToText(Output_p8 + Idx_i32, ReceivedPayload_pu8);
3561  break;
3563  ParseSignalProcessingLogMessageToText(Output_p8 + Idx_i32, ReceivedPayload_pu8);
3564  break;
3565  case LOG_CAT_SOFTWARE:
3566  ParseSoftwareLogMessageToText(Output_p8 + Idx_i32, ReceivedPayload_pu8);
3567  break;
3568  case LOG_CAT_STRING:
3569  ParseStringLogMessageToText(Output_p8 + Idx_i32, ReceivedPayload_pu8);
3570  break;
3571  case LOG_CAT_CALIBRATION:
3572  ParseCalibrationLogMessageToText(Output_p8 + Idx_i32, ReceivedPayload_pu8);
3573  break;
3574  default:
3575  Idx_i32 += sprintf(Output_p8 + Idx_i32, "Invalid log message received: ");
3576  for (int i = 0; i < CAN_MAX_FRAME_LEN; ++i)
3577  {
3578  Idx_i32 += sprintf(Output_p8 + Idx_i32, "0x%02X ", ReceivedPayload_pu8[i]);
3579  }
3580  break;
3581  }
3582  }
3583 }
3584 
3585 void ParseResetReasonLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8)
3586 {
3587  if (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1] < RESET_REASON_END)
3588  {
3589  sprintf(Output_p8, "A reset occurred due to %s",
3590  kResetReasonStrings[ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1]]);
3591  }
3592  else
3593  {
3594  sprintf(Output_p8, "A reset occurred due to unknown reason - code: %d",
3595  (int)ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1]);
3596  }
3597 }
3598 
3599 void ParseBootloaderLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8)
3600 {
3601  switch (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1])
3602  {
3604  sprintf(Output_p8, "The bootloader cannot install older firmware versions");
3605  break;
3606  case BL_STATUS_SIZE_ERROR:
3607  sprintf(Output_p8, "The size of the firmware update is too large");
3608  break;
3609  case BL_STATUS_CRC_ERROR:
3610  sprintf(Output_p8, "The CRC is incorrect");
3611  break;
3613  sprintf(Output_p8, "The firmware signature cannot be verified");
3614  break;
3615  case BL_STATUS_INIT_ERROR:
3616  sprintf(Output_p8, "The bootloader hasn't been initialised");
3617  break;
3619  uint16_t PacketNumber_u16 = 0;
3620  memcpy(&PacketNumber_u16, ReceivedPayload_pu8 + LOGGING_ISSUE_BYTE_2, 2);
3621  sprintf(Output_p8,
3622  "The last received firmware packet number was not as expected. Expected firmware "
3623  "packet number %d",
3624  PacketNumber_u16);
3625  }
3626  break;
3628  sprintf(Output_p8, "The firmware is not compatible with this version of hardware");
3629  break;
3630  case BL_STATUS_MODEL_ERROR:
3631  sprintf(Output_p8, "The firmware is not compatible with this sensor model");
3632  break;
3634  sprintf(Output_p8, "More than one FW update init commands has been received");
3635  break;
3637  sprintf(Output_p8, "The firmware is not ready to be launched");
3638  break;
3639  case BL_STATUS_NEXT_STATE:
3640  if (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1] < STATE_APP_IDLE)
3641  {
3642  sprintf(Output_p8, "The bootloader next state is %s",
3643  kSensorStateStrings[ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]]);
3644  }
3645  else
3646  {
3647  sprintf(Output_p8, "The bootloader next state is not recognised - code: %d",
3648  (int)ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]);
3649  }
3650  break;
3652  sprintf(Output_p8, "The firmware could not be properly stored in flash memory");
3653  break;
3654  default:
3655  sprintf(Output_p8, "Not recognized bootloader log message received");
3656  break;
3657  }
3658 }
3659 
3660 void ParseSelfCheckLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8)
3661 {
3662  switch (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1])
3663  {
3664  case SC_STATUS_SENSOR_OK:
3665  sprintf(Output_p8, "Sensor status is OK");
3666  break;
3668  sprintf(Output_p8, "Microphone %d is likely covered",
3669  ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]);
3670  break;
3672  sprintf(Output_p8,
3673  "The transducer is likely covered - or all three microphones may be covered");
3674  break;
3675  case SC_STATUS_PGA_OK:
3676  sprintf(Output_p8, "PGA %d status is OK", ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]);
3677  break;
3679  sprintf(Output_p8, "PGA %d malfunction", ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]);
3680  break;
3682  sprintf(Output_p8, "PGA %d status could not be determined",
3683  ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]);
3684  break;
3685  default:
3686  sprintf(Output_p8, "Not recognized self-check log message received");
3687  break;
3688  }
3689 }
3690 
3691 void ParseSignalProcessingLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8)
3692 {
3693  switch (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1])
3694  {
3696  sprintf(Output_p8, "The signal processing modules could not be initialized");
3697  break;
3699  sprintf(Output_p8, "The near field binary detection has been disbaled");
3700  break;
3702  sprintf(Output_p8, "The speed of sound could not be calculated in this frame");
3703  break;
3705  sprintf(Output_p8, "No echoes were found");
3706  break;
3708  sprintf(Output_p8, "The ADC signal entered clipping");
3709  break;
3711  sprintf(Output_p8, "No 3D points could be calculated");
3712  break;
3714  sprintf(Output_p8, "Tracking error %d", ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]);
3715  break;
3717  sprintf(Output_p8, "Kalman error %d", ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2]);
3718  break;
3720  sprintf(Output_p8, "Point buffer full");
3721  break;
3723  sprintf(Output_p8, "Timer overflow");
3724  break;
3725  default:
3726  sprintf(Output_p8, "Not recognized signal processing log message received");
3727  break;
3728  }
3729 }
3730 
3731 void ParseSoftwareLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8)
3732 {
3733  switch (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1])
3734  {
3736  sprintf(Output_p8, "A memory allocation has failed");
3737  break;
3739  sprintf(Output_p8, "A system reboot is required");
3740  break;
3742  sprintf(Output_p8, "The settings in flash memory could not be loaded");
3743  break;
3745  sprintf(Output_p8, "The settings could not be saved to flash memory");
3746  break;
3748  sprintf(Output_p8, "The factory defaults are being written to flash memory");
3749  break;
3750  default:
3751  sprintf(Output_p8, "Not recognized software log message received");
3752  break;
3753  }
3754 }
3755 
3756 void ParseStringLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8)
3757 {
3758  uint8_t Len_u8 = ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2];
3759  memcpy(Output_p8, ReceivedPayload_pu8 + LOGGING_ISSUE_BYTE_3, Len_u8);
3760  Output_p8[Len_u8] = '\0';
3761 }
3762 
3763 void ParseCalibrationLogMessageToText(char* Output_p8, const uint8_t* ReceivedPayload_pu8)
3764 {
3765  switch (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_1])
3766  {
3768  sprintf(Output_p8, "The sensor has not yet been calibrated");
3769  break;
3771  if (ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_2] == CALIBRATION_STAGE_RESONANT_FREQ)
3772  {
3773  sprintf(Output_p8, "The resonant frequency calibration routine is %d%% complete",
3774  (int)ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_3]);
3775  }
3776  else
3777  {
3778  sprintf(Output_p8, "The near-field detection calibration routine is %d%% complete",
3779  (int)ReceivedPayload_pu8[LOGGING_ISSUE_BYTE_3]);
3780  }
3781  break;
3783  sprintf(Output_p8, "The calibration routine is finished");
3784  break;
3786  sprintf(Output_p8, "The calibration routine could not be initialized");
3787  break;
3789  sprintf(Output_p8, "An invalid calibration frame was recorded");
3790  break;
3791  default:
3792  sprintf(Output_p8, "Not recognized calibration log message received");
3793  break;
3794  }
3795 }
SetParameterADCUseFixedFrameRate
bool SetParameterADCUseFixedFrameRate(bool UseFixedFrameRate_b)
Blocking Request to use the fixed framerate for current target sensor.
Definition: sensor_lib.c:2601
IsADCDumpStartFrame_b
static bool IsADCDumpStartFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received payload represents an ADC-Dump Start Message. If so the new adc sessio...
Definition: sensor_lib.c:1929
response
const std::string response
Interface_t
struct Interface_t Interface_t
RequestReboot
bool RequestReboot()
Request selected sensor to reboot.
Definition: sensor_lib.c:2330
CONTROL_BYTE_GET
@ CONTROL_BYTE_GET
Definition: message_flags.h:105
ADCDump_Data_t
struct ADCDump_Data_t ADCDump_Data_t
GetParameterSystemSensorMode_t
SensorMode_t GetParameterSystemSensorMode_t()
Blocking Request to read the Sensor Mode from current sensor.
Definition: sensor_lib.c:3217
SYS_PARAM_BYTE_UNIQUE_ID
@ SYS_PARAM_BYTE_UNIQUE_ID
Definition: message_flags.h:223
BL_STATUS_FLASH_INCOMPLETE_ERROR
@ BL_STATUS_FLASH_INCOMPLETE_ERROR
Definition: custom_types.h:187
SessionState_t
SessionState_t
Definition: sensor_lib.h:53
SessionStartCallback
static void(* SessionStartCallback)(uint16_t Sender_u16)
Definition: sensor_lib.c:722
SIG_PRO_ISSUE_KALMAN_ERROR
@ SIG_PRO_ISSUE_KALMAN_ERROR
Definition: custom_types.h:169
GetParameterSystemSensorState_t
SensorState_t GetParameterSystemSensorState_t()
Blocking Request to read the Sensor State from current sensor.
Definition: sensor_lib.c:3184
BL_STATUS_INIT_ERROR
@ BL_STATUS_INIT_ERROR
Definition: custom_types.h:180
ParseBootloaderLogMessageToText
void ParseBootloaderLogMessageToText(char *Output_p8, const uint8_t *ReceivedPayload_pu8)
Parses Bootloader specific log messages into human readable text.
Definition: sensor_lib.c:3599
SemaphoresInit_b
static bool SemaphoresInit_b
Definition: sensor_lib.c:743
GetBoolFromPayload_b
bool GetBoolFromPayload_b(const uint8_t *Payload_pu8)
Is called from Getter functions to extract values from payload. In this case a bool-value.
Definition: sensor_lib.c:2842
UartPayload_pu8
static uint8_t UartPayload_pu8[UART_MAX_FRAME_LEN]
Definition: sensor_lib.c:744
GetCurrentStatusInformant_u16
static uint16_t GetCurrentStatusInformant_u16()
Definition: sensor_lib.c:892
CONTROL_BYTE_LOG_WARN
@ CONTROL_BYTE_LOG_WARN
Definition: message_flags.h:116
GetCurrentACKStatus
ACK_Status_t * GetCurrentACKStatus(uint8_t index)
Is called internally to get the current ACKStatus.
Definition: sensor_lib.c:908
RequestFactoryReset
bool RequestFactoryReset()
Request selected sensor to reset to factory defaults.
Definition: sensor_lib.c:2361
GetU16FromPayload_u16
uint16_t GetU16FromPayload_u16(const uint8_t *Payload_pu8)
Is called from Getter functions to extract values from payload. In this case a uint16-value.
Definition: sensor_lib.c:2878
UART_MAX_FRAME_LEN
#define UART_MAX_FRAME_LEN
Definition: message_flags.h:16
DeinitUARTPort
int DeinitUARTPort()
Called from the can-library, this function will close the socket and take care of ReceiverThread term...
Definition: uartinterface.c:204
Interface_t::SensorInterface_t
CommsInterfaceType_t SensorInterface_t
Definition: sensor_lib.c:184
SIG_PRO_ISSUE_CLIPPING
@ SIG_PRO_ISSUE_CLIPPING
Definition: custom_types.h:166
GetParameterSystemResetReason_t
ResetReason_t GetParameterSystemResetReason_t()
Blocking Request to read the last Reset Reason from current sensor.
Definition: sensor_lib.c:3170
LOG_CAT_COMMUNICATION
@ LOG_CAT_COMMUNICATION
Definition: custom_types.h:115
LOG_CAT_PERIPHERAL
@ LOG_CAT_PERIPHERAL
Definition: custom_types.h:116
UART_MESSAGE_STATE_UNKNOWN
@ UART_MESSAGE_STATE_UNKNOWN
Definition: sensor_lib.c:165
timeoutmSeconds
static int timeoutmSeconds
Definition: sensor_lib.c:749
SetWaitForACKForACKStatus
static void SetWaitForACKForACKStatus(ACK_Status_t *ackstatus, bool waitforack)
Definition: sensor_lib.c:933
SetParameterSuccessful_b
static bool SetParameterSuccessful_b(const uint8_t *request, const uint8_t *response)
Compares request and response payload and validates if the response indicates a success when setting ...
Definition: sensor_lib.c:2574
Is3DFrame_b
static bool Is3DFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received point-data-payload is a 3D-Point-Data. If so, the associated session i...
Definition: sensor_lib.c:1808
CurrentUARTMsg_t
static UART_Msg_t CurrentUARTMsg_t[MAX_NUMBER_OF_SENSORS_ON_BUS]
Definition: sensor_lib.c:745
PARAM_BYTE_6_IDX
#define PARAM_BYTE_6_IDX
Offset of 7'th parameter in Payload.
Definition: sensor_lib.c:102
CommsInterfaceType_t
CommsInterfaceType_t
Definition: custom_types.h:10
PrintPayload
static void PrintPayload(const uint8_t *payload)
Only for debugging - print the content of payload to stdout.
Definition: sensor_lib.c:1147
SetParameterSignalProcessingNoiseRatioThreshold
bool SetParameterSignalProcessingNoiseRatioThreshold(uint8_t Threshold_u8)
Blocking Request to set the Noise Ratio Threshold for current target sensor.
Definition: sensor_lib.c:2707
RequestVersion_t
Version_t RequestVersion_t(VersionByte_t TargetComponent_t)
Blocking - Request transmition of the current version of selected component from selected sensor.
Definition: sensor_lib.c:2193
ParseSignalProcessingLogMessageToText
void ParseSignalProcessingLogMessageToText(char *Output_p8, const uint8_t *ReceivedPayload_pu8)
Parses signal processing specific log messages into human readable text.
Definition: sensor_lib.c:3691
GetU8FromTwoArgumentPayload_u8
uint8_t GetU8FromTwoArgumentPayload_u8(const uint8_t *Payload_pu8)
Is called from Getter functions to extract values from payload. In this case a uint8-value.
Definition: sensor_lib.c:2867
SetNumberOfKnownSensors
static void SetNumberOfKnownSensors(uint8_t newvalue)
Definition: sensor_lib.c:808
CurrentADCSessions
ADCDump_Data_t CurrentADCSessions
Definition: sensor_lib.c:719
SIGPRO_PARAM_BYTE_ENABLE_AUTO_GAIN
@ SIGPRO_PARAM_BYTE_ENABLE_AUTO_GAIN
Definition: message_flags.h:212
GetSessionComplete_b
bool GetSessionComplete_b(uint16_t TargetSensorId_u16)
Definition: sensor_lib.c:2479
SIG_PRO_ISSUE_VSOUND_CAL_ERROR
@ SIG_PRO_ISSUE_VSOUND_CAL_ERROR
Definition: custom_types.h:164
GetParameterSystemUniqueID_t
UID_t GetParameterSystemUniqueID_t(uint8_t Index_u8)
Blocking Request to read the Unique ID from current sensor.
Definition: sensor_lib.c:3198
SC_STATUS_PGA_MALFUNCTION
@ SC_STATUS_PGA_MALFUNCTION
Definition: custom_types.h:132
ACK_Status_t
Definition: sensor_lib.h:93
BL_STATUS_SIZE_ERROR
@ BL_STATUS_SIZE_ERROR
Definition: custom_types.h:177
BL_STATUS_SIGNATURE_ERROR
@ BL_STATUS_SIGNATURE_ERROR
Definition: custom_types.h:179
VersionByte_t
VersionByte_t
Definition: message_flags.h:143
ADCDUmpEndCallback
static void(* ADCDUmpEndCallback)(uint16_t Sender_u16)
Definition: sensor_lib.c:726
GetParameterTransducerNumOfPulses_u8
uint8_t GetParameterTransducerNumOfPulses_u8()
Blocking Request to read the current Transducer Number of Pulses from current sensor.
Definition: sensor_lib.c:2983
RESET_REASON_END
@ RESET_REASON_END
Definition: custom_types.h:87
ParseSoftwareLogMessageToText
void ParseSoftwareLogMessageToText(char *Output_p8, const uint8_t *ReceivedPayload_pu8)
Parses software-issue specific log messages into human readable text.
Definition: sensor_lib.c:3731
MAX_NUMBER_OF_SENSORS_ON_BUS
#define MAX_NUMBER_OF_SENSORS_ON_BUS
If this define is set, the library will use the linux socket interface.
Definition: sensor_lib_config.h:35
IsNearFieldFrame_b
static bool IsNearFieldFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received point-data-payload is a near-filed-information. If so,...
Definition: sensor_lib.c:1723
ConnectedToCANBus_b
static bool ConnectedToCANBus_b
Definition: sensor_lib.c:697
UART_MESSAGE_STATE_VALIDATE_MSG_END
@ UART_MESSAGE_STATE_VALIDATE_MSG_END
Definition: sensor_lib.c:170
ACK_Status_t::SenderId_u16
uint16_t SenderId_u16
Definition: sensor_lib.h:95
wait_session_end_sem
static sem_t wait_session_end_sem
Definition: sensor_lib.c:738
GetKnownSensors
Sensor_t * GetKnownSensors()
Returns pointer to array containing all known sensors. With GetNumberOfKnownSensors() users can get l...
Definition: sensor_lib.c:765
Point3D_t::Intensity_u8
uint8_t Intensity_u8
Definition: sensor_lib.h:44
mutex_numberofknownsensors
static pthread_mutex_t mutex_numberofknownsensors
Definition: sensor_lib.c:757
WaitForSessionEndTimeout
void * WaitForSessionEndTimeout(void *vargp)
Definition: sensor_lib.c:3333
CONTROL_BYTE_ACK
@ CONTROL_BYTE_ACK
Definition: message_flags.h:83
SetCurrentSessionsNumberOfActiveSessions_u8
static void SetCurrentSessionsNumberOfActiveSessions_u8(uint8_t newvalue)
Definition: sensor_lib.c:840
STATE_BL_RX_APP
@ STATE_BL_RX_APP
Definition: custom_types.h:28
ADC_PARAM_BYTE_USE_FIXED_FRAME_RATE
@ ADC_PARAM_BYTE_USE_FIXED_FRAME_RATE
Definition: message_flags.h:194
Version_t::hotfix
uint8_t hotfix
Definition: custom_structs.h:16
SetTargetSensor
void SetTargetSensor(uint16_t TargetSensor_u16)
With this function, the user can set the current target-id, all comming messages will be send to.
Definition: sensor_lib.c:1337
ACKSessionEnd
void ACKSessionEnd()
Accept Session End for current sensor.
Definition: sensor_lib.c:3299
SessionEndCallback
static void(* SessionEndCallback)(uint16_t Sender_u16)
Definition: sensor_lib.c:724
CONTROL_BYTE_TRIGGER_ACTION_ACK
@ CONTROL_BYTE_TRIGGER_ACTION_ACK
Definition: message_flags.h:93
GetParameterSignalProcessingEnableNearFieldDetection_b
bool GetParameterSignalProcessingEnableNearFieldDetection_b()
Blocking Request to read whether near field detection is enabled in the current sensor.
Definition: sensor_lib.c:3059
DeinitInterface
void DeinitInterface(CommsInterfaceType_t Interface_t)
Instruction to deinit the specified interface type.
Definition: sensor_lib.c:2279
GetParameterSignalProcessingTemperature_f
float GetParameterSignalProcessingTemperature_f()
Blocking Request to read the current Transducer Temperature setting from current sensor.
Definition: sensor_lib.c:2997
LOG_CAT_STRING
@ LOG_CAT_STRING
Definition: custom_types.h:121
START_POINT_SESSION_ACK_LEN
#define START_POINT_SESSION_ACK_LEN
Definition: message_flags.h:37
SetCurrentTarget_u16
static void SetCurrentTarget_u16(uint16_t newvalue)
Definition: sensor_lib.c:824
CONTROL_BYTE_BEGIN_ADC_DUMP_SESSION
@ CONTROL_BYTE_BEGIN_ADC_DUMP_SESSION
Definition: message_flags.h:89
GetParameterSignalProcessingEnableAutoGain_b
bool GetParameterSignalProcessingEnableAutoGain_b()
Blocking Request to read whether auto gain is enabled in the current sensor.
Definition: sensor_lib.c:3087
GetInterfaceIndex_i16
static int16_t GetInterfaceIndex_i16(char *InterfaceName)
Definition: sensor_lib.c:997
RequestLoadSettings
bool RequestLoadSettings()
Request selected sensor to load saved settings.
Definition: sensor_lib.c:2391
GetParameterTransducerVolume_u8
uint8_t GetParameterTransducerVolume_u8()
Blocking Request to read the current Transducer Volume from current sensor.
Definition: sensor_lib.c:2969
PARAM_BYTE_3_IDX
#define PARAM_BYTE_3_IDX
Definition: message_flags.h:21
SetParameterSignalProcessingEnableNearFieldDetection
bool SetParameterSignalProcessingEnableNearFieldDetection(bool Enable_b)
Blocking Request to enable near field detection for current target sensor.
Definition: sensor_lib.c:2721
Sensor_Session_t::SessionState
SessionState_t SessionState
Definition: sensor_lib.h:63
ConnectedToCUART_b
static bool ConnectedToCUART_b
Definition: sensor_lib.c:699
SetConnectedToCANBus
static void SetConnectedToCANBus(bool newvalue)
Definition: sensor_lib.c:965
GetParameterSystemLogLevel_t
LogLevel_t GetParameterSystemLogLevel_t()
Blocking Request to read the current System Log Level from current sensor.
Definition: sensor_lib.c:3156
IsSessionDataFrame_b
static bool IsSessionDataFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received payload represents a Session-Data-Information.
Definition: sensor_lib.c:1903
Sensor_Session_t::NumberOf1DPoints
uint8_t NumberOf1DPoints
Definition: sensor_lib.h:68
ACTION_BYTE_FACTORY_DEFAULTS
@ ACTION_BYTE_FACTORY_DEFAULTS
Definition: message_flags.h:133
Sensor_t
Definition: sensor_lib.h:83
PARAM_BYTE_2_IDX
#define PARAM_BYTE_2_IDX
Definition: message_flags.h:20
kSensorStateStrings
static const char * kSensorStateStrings[]
Definition: custom_types.h:52
ResetListOfKnownSensors
static void ResetListOfKnownSensors()
Clears the list of known Sensors.
Definition: sensor_lib.c:3475
Is1DFrame_b
static bool Is1DFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received point-data-payload is a 1D-Point-Data. If so, the associated session i...
Definition: sensor_lib.c:1763
UART_MESSAGE_STATE_READ_CHECKSUM
@ UART_MESSAGE_STATE_READ_CHECKSUM
Definition: sensor_lib.c:169
Point1D_t::VectorLength_u16
uint16_t VectorLength_u16
Definition: sensor_lib.h:49
LogLevel_t
LogLevel_t
Definition: custom_types.h:101
PARAM_BYTE_1_IDX
#define PARAM_BYTE_1_IDX
Definition: message_flags.h:19
WaitForADCSessionEnd
uint16_t WaitForADCSessionEnd()
Blocking Function call to wait for SessionEnd Payload.
Definition: sensor_lib.c:3384
Sensor_t::InterfaceIndex_u8
uint8_t InterfaceIndex_u8
Definition: sensor_lib.h:86
Interface_t
Definition: sensor_lib.c:182
LOG_CAT_BOOTLOADER
@ LOG_CAT_BOOTLOADER
Definition: custom_types.h:114
Session_Data_t
struct Session_Data_t Session_Data_t
SensorState_t
SensorState_t
Definition: custom_types.h:24
LOG_CAT_RESET_REASON
@ LOG_CAT_RESET_REASON
Definition: custom_types.h:113
GetInterfaceSensorIdFromSensor
static uint16_t GetInterfaceSensorIdFromSensor(Sensor_t *sensor)
Definition: sensor_lib.c:883
SW_ISSUE_MALLOC_FAILED
@ SW_ISSUE_MALLOC_FAILED
Definition: custom_types.h:138
RegisterRdyCallback
void RegisterRdyCallback(void(*Callback)(uint16_t Sender_u16))
Interface function to register a callback function that is called whenever an Ready Payload is receiv...
Definition: sensor_lib.c:3403
WaitForACKTimeout
void * WaitForACKTimeout(void *vargp)
Definition: sensor_lib.c:3315
SendCommand
static void SendCommand(uint8_t *payload, uint16_t length)
Generic Send-Function. Takes Payload, length and interface as arguments. Atm. only CAN-Bus is impleme...
Definition: sensor_lib.c:1105
GetNumberOfSensorsACKIsExpectedFrom
static uint8_t GetNumberOfSensorsACKIsExpectedFrom()
Definition: sensor_lib.c:783
SW_ISSUE_LOAD_FROM_FLASH_FAILED
@ SW_ISSUE_LOAD_FROM_FLASH_FAILED
Definition: custom_types.h:140
IsReadyFrame
static bool IsReadyFrame(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received payload represents a "Ready"-Information. If so and a callback has bee...
Definition: sensor_lib.c:1877
GetCurrentTarget_u16
static uint16_t GetCurrentTarget_u16()
Definition: sensor_lib.c:815
Point3D_t::X_i16
int16_t X_i16
Definition: sensor_lib.h:41
GetParameterSystemCalibrationState_b
bool GetParameterSystemCalibrationState_b()
Blocking Request to read whether the current sensor has been calibrated.
Definition: sensor_lib.c:3231
LOG_CAT_USER
@ LOG_CAT_USER
Definition: custom_types.h:117
SetParameterADCFixedFrameRate
bool SetParameterADCFixedFrameRate(uint8_t FrameRate_u8)
Blocking Request to set the fixed framerate for current target sensor.
Definition: sensor_lib.c:2615
SIGPRO_PARAM_BYTE_ENABLE_DIRECT_MULTIPATH_FILTER
@ SIGPRO_PARAM_BYTE_ENABLE_DIRECT_MULTIPATH_FILTER
Definition: message_flags.h:211
STANDARD_GET_MESSAGE_LEN
#define STANDARD_GET_MESSAGE_LEN
Definition: message_flags.h:55
WaitForSessionEnd
uint16_t WaitForSessionEnd()
Blocking Function call to wait for SessionEnd Payload.
Definition: sensor_lib.c:3370
SetParameterTransducerVolume
bool SetParameterTransducerVolume(uint8_t Volume_u8)
Blocking Request to set the Transducer Volume for current target sensor.
Definition: sensor_lib.c:2631
LOG_CAT_SELF_CHECK
@ LOG_CAT_SELF_CHECK
Definition: custom_types.h:118
GetADCDumpData
ADCDump_t * GetADCDumpData(uint16_t Sender_u16)
Interface function to get current ADC-Dump from SenderId.
Definition: sensor_lib.c:3443
ACK_Status_t::WaitForACK_b
bool WaitForACK_b
Definition: sensor_lib.h:96
UART_PAYLOAD_START_OFFSET
#define UART_PAYLOAD_START_OFFSET
Definition: uart_wrapper.h:17
SetParameterSignalProcessingEnableMultipathFilter
bool SetParameterSignalProcessingEnableMultipathFilter(bool Enable_b)
Blocking Request to enable near the multipath filter for current target sensor.
Definition: sensor_lib.c:2735
RegisterSessionStartCallback
void RegisterSessionStartCallback(void(*Callback)(uint16_t Sender_u16))
Interface function to register a callback function that is called whenever an SessionStart Payload is...
Definition: sensor_lib.c:3309
NUMBER_OF_ADC_DUMP_DATAPOINTS_PER_LINE
#define NUMBER_OF_ADC_DUMP_DATAPOINTS_PER_LINE
Maximum Number of Datapoints copied from a ADC-Dump Data-Frame.
Definition: sensor_lib.c:131
ACK_Status_t::ACK_b
bool ACK_b
Definition: sensor_lib.h:97
SetADCSessionStateExpected
void SetADCSessionStateExpected(uint16_t TargetSensorId_u16)
Definition: sensor_lib.c:2432
GetCurrentSendersSessionIndex
static int8_t GetCurrentSendersSessionIndex(uint16_t SenderId_u16)
Definition: sensor_lib.c:1465
CALIBRATION_STAGE_RESONANT_FREQ
@ CALIBRATION_STAGE_RESONANT_FREQ
Definition: custom_types.h:156
LOGGING_ISSUE_BYTE_2
#define LOGGING_ISSUE_BYTE_2
Definition: message_flags.h:76
mutex_currentstatusinformant
static pthread_mutex_t mutex_currentstatusinformant
Definition: sensor_lib.c:750
mutex_knownsensor
static pthread_mutex_t mutex_knownsensor
Definition: sensor_lib.c:752
LOG_CAT_SIGNAL_PROCESSING
@ LOG_CAT_SIGNAL_PROCESSING
Definition: custom_types.h:119
ParseStringLogMessageToText
void ParseStringLogMessageToText(char *Output_p8, const uint8_t *ReceivedPayload_pu8)
Parses string log messages into human readable text.
Definition: sensor_lib.c:3756
PrintADCBlob
static void PrintADCBlob(uint16_t SenderId_u16)
Debug Function to print.
Definition: sensor_lib.c:1571
STATE_BL_RDY_TO_LAUNCH
@ STATE_BL_RDY_TO_LAUNCH
Definition: custom_types.h:31
CALIBRATION_ISSUE_CALIBRATION_PROGRESS
@ CALIBRATION_ISSUE_CALIBRATION_PROGRESS
Definition: custom_types.h:148
SetParameterTransducerNumOfPulses
bool SetParameterTransducerNumOfPulses(uint8_t NumOfPulses_u8)
Blocking Request to set the Number of Transducer Pulses for current target sensor.
Definition: sensor_lib.c:2645
AddInterfaceToInterfaceList
static void AddInterfaceToInterfaceList(CommsInterfaceType_t SensorInterface_t, char *InterfaceName_cp)
Definition: sensor_lib.c:1011
SIG_PRO_ISSUE_NEAR_FIELD_DETECTION_DISABLED
@ SIG_PRO_ISSUE_NEAR_FIELD_DETECTION_DISABLED
Definition: custom_types.h:163
GetParameterADCFixedFrameRate_u8
uint8_t GetParameterADCFixedFrameRate_u8()
Blocking Request to read the current set ADC-Framerate from current sensor.
Definition: sensor_lib.c:2953
ADCDumpStartRequestCallback
static void(* ADCDumpStartRequestCallback)(uint16_t Sender_u16, uint32_t ADCDumpSize_u32)
Definition: sensor_lib.c:730
TRANSDUCER_PARAM_BYTE_NUMBER_PULSES
@ TRANSDUCER_PARAM_BYTE_NUMBER_PULSES
Definition: message_flags.h:201
BL_STATUS_HW_VERSION_ERROR
@ BL_STATUS_HW_VERSION_ERROR
Definition: custom_types.h:182
ParseMessage_b
static bool ParseMessage_b(uint16_t SenderId_u16, uint8_t *msg, uint8_t len)
Iterates the payload over all known message types, which in turn trigger their actions....
Definition: sensor_lib.c:2010
MULTICAST_ID
#define MULTICAST_ID
CAN-ID used if commands shall be send to all Sensors for example, to determine active sensors in the ...
Definition: sensor_lib.c:93
GetResponsePayloadFromACKStatus
uint8_t * GetResponsePayloadFromACKStatus(ACK_Status_t *ackstatus)
Is called internally to extract the payload of a response.
Definition: sensor_lib.c:988
CONTROL_BYTE_SET_ACK
@ CONTROL_BYTE_SET_ACK
Definition: message_flags.h:102
Sensor_Session_t::Point1D_tp
Point1D_t Point1D_tp[MAX_NUMBER_OF_POINTS_PER_SESSION]
Definition: sensor_lib.h:70
CurrentTarget_u16
static uint16_t CurrentTarget_u16
Definition: sensor_lib.c:693
ValidateUARTChecksum
static bool ValidateUARTChecksum(UART_Msg_t *ReceivedUARTMsg_pt)
Definition: sensor_lib.c:1043
ACTION_BYTE_ADC_DUMP
@ ACTION_BYTE_ADC_DUMP
Definition: message_flags.h:136
ACKSessionStart
void ACKSessionStart(uint16_t TargetSensor_u16)
Accept session start for the target sensor.
Definition: sensor_lib.c:3245
BL_STATUS_NEXT_STATE
@ BL_STATUS_NEXT_STATE
Definition: custom_types.h:186
CONTROL_BYTE_BEGIN_POINT_OUTPUT_SESSION
@ CONTROL_BYTE_BEGIN_POINT_OUTPUT_SESSION
Definition: message_flags.h:88
SetParameterSignalProcessingNoiseLevelThresholdFactor
bool SetParameterSignalProcessingNoiseLevelThresholdFactor(float Factor_f)
Blocking Request to set the Noise Level Threshold Factor for current target sensor.
Definition: sensor_lib.c:2690
SIG_PRO_ISSUE_NO_ECHOES_FOUND
@ SIG_PRO_ISSUE_NO_ECHOES_FOUND
Definition: custom_types.h:165
SYS_PARAM_BYTE_CALIBRATION_STATE
@ SYS_PARAM_BYTE_CALIBRATION_STATE
Definition: message_flags.h:224
GetNumberOfKnownSensors
uint8_t GetNumberOfKnownSensors()
Returns number of known sensors. With GetKnownSensors() users an pointer to an array containing the I...
Definition: sensor_lib.c:799
StartNewSessionRecord_b
static bool StartNewSessionRecord_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Starts a new point session recording for the given sender ID. The new session is initialized with the...
Definition: sensor_lib.c:1378
UART_Msg_t::CurrentMessageState
UARTMessageState_t CurrentMessageState
Definition: sensor_lib.c:175
socketinterface.h
This file contains the linux-can-socket interface prototypes.
POINT_TYPE_BYTE_NEAR_FIELD
@ POINT_TYPE_BYTE_NEAR_FIELD
Definition: message_flags.h:159
SetResponsePayloadForACKStatus
static void SetResponsePayloadForACKStatus(ACK_Status_t *ackstatus, uint8_t *payload, uint16_t len)
Definition: sensor_lib.c:981
UARTReadCallback
static void UARTReadCallback(uint8_t *ReceivedUARTMsg_pu8, uint16_t UARTMsgLength_u16, uint8_t InterfaceId_u8)
This function can be registered in uart-interfaces as callback to be called if a uart message is rece...
Definition: sensor_lib.c:2060
RequestMeasurement
bool RequestMeasurement()
Send's a request to start a new measurement.
Definition: sensor_lib.c:2348
RegisterADCDumpSessionEndCallback
void RegisterADCDumpSessionEndCallback(void(*Callback)(uint16_t Sender_u16))
Interface function to register a callback function that is called whenever an SessionEnd Payload for ...
Definition: sensor_lib.c:3364
ADCDump_Data_t::NumberOfActiveSessions_u8
uint8_t NumberOfActiveSessions_u8
Definition: sensor_lib.c:159
ACKADCDumpStart
void ACKADCDumpStart(uint16_t TargetSensor_u16)
Accept ADCDump start for the target sensor.
Definition: sensor_lib.c:3270
CONTROL_BYTE_SET
@ CONTROL_BYTE_SET
Definition: message_flags.h:101
NumberOfKnownSensors_u8
static uint8_t NumberOfKnownSensors_u8
Definition: sensor_lib.c:705
PARAM_GROUP_BYTE_ADC
@ PARAM_GROUP_BYTE_ADC
Definition: message_flags.h:123
SetParameterSystemLogLevel
bool SetParameterSystemLogLevel(LogLevel_t LogLevel_t)
Blocking Request to set the Loglevel for current target sensor.
Definition: sensor_lib.c:2798
ADCDump_Data_t
Definition: sensor_lib.c:157
KnownSensors
static Sensor_t KnownSensors[MAX_NUMBER_OF_SENSORS_ON_BUS]
Definition: sensor_lib.c:703
SIG_PRO_ISSUE_NO_VALID_POINTS_FOUND
@ SIG_PRO_ISSUE_NO_VALID_POINTS_FOUND
Definition: custom_types.h:167
CONTROL_BYTE_EOS
@ CONTROL_BYTE_EOS
Definition: message_flags.h:82
SendViaCAN
static void SendViaCAN(uint8_t *payload, uint16_t length)
Definition: sensor_lib.c:1051
KnownInterfaces_tp
static Interface_t KnownInterfaces_tp[MAX_NUMBER_OF_SENSORS_ON_BUS]
Definition: sensor_lib.c:747
ACTION_BYTE_STORE_SETTINGS
@ ACTION_BYTE_STORE_SETTINGS
Definition: message_flags.h:134
SC_STATUS_TRANSDUCER_MALFUNCTION
@ SC_STATUS_TRANSDUCER_MALFUNCTION
Definition: custom_types.h:130
STATE_APP_IDLE
@ STATE_APP_IDLE
Definition: custom_types.h:35
wait_adc_session_end_sem
static sem_t wait_adc_session_end_sem
Definition: sensor_lib.c:739
WaitForReady
uint16_t WaitForReady()
Blocking Function call to wait for Ready Payload.
Definition: sensor_lib.c:3395
Sensor_Session_t::NumberOf3DPoints
uint8_t NumberOf3DPoints
Definition: sensor_lib.h:69
CONTROL_BYTE_LOG_INFO
@ CONTROL_BYTE_LOG_INFO
Definition: message_flags.h:115
STATE_BL_WAIT_FOR_INIT
@ STATE_BL_WAIT_FOR_INIT
Definition: custom_types.h:27
ResetReason_t
ResetReason_t
Definition: custom_types.h:77
Sensor_Session_t::NumberOfPoints_u8
uint8_t NumberOfPoints_u8
Definition: sensor_lib.h:65
PARAM_GROUP_BYTE_SIGNAL_PROCESSING
@ PARAM_GROUP_BYTE_SIGNAL_PROCESSING
Definition: message_flags.h:125
ParseLogMessageToText
void ParseLogMessageToText(char *Output_p8, uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Parses log messages into human readable text.
Definition: sensor_lib.c:3521
mutex_currentsessions
static pthread_mutex_t mutex_currentsessions
Definition: sensor_lib.c:754
UART_Msg_t::CurrentPayloadIndex_u8
uint8_t CurrentPayloadIndex_u8
Definition: sensor_lib.c:177
ParseSelfCheckLogMessageToText
void ParseSelfCheckLogMessageToText(char *Output_p8, const uint8_t *ReceivedPayload_pu8)
Parses self check specific log messages into human readable text.
Definition: sensor_lib.c:3660
WaitForSessionStartTimeout
void * WaitForSessionStartTimeout(void *vargp)
Definition: sensor_lib.c:3324
TRANSDUCER_PARAM_BYTE_VOLUME
@ TRANSDUCER_PARAM_BYTE_VOLUME
Definition: message_flags.h:200
TIMEOUT_M_SECONDS
#define TIMEOUT_M_SECONDS
Definition: sensor_lib.h:31
SW_ISSUE_STORING_FACTORY_DEFAULTS_IN_FLASH
@ SW_ISSUE_STORING_FACTORY_DEFAULTS_IN_FLASH
Definition: custom_types.h:142
WaitForACK
void WaitForACK(uint8_t *payload, uint16_t length_u16)
This function is called from blocking Set* Functions and blocks until the wait_ack_sem is unlocked by...
Definition: sensor_lib.c:1316
mutex_numberofsensorsackisexpectedfrom
static pthread_mutex_t mutex_numberofsensorsackisexpectedfrom
Definition: sensor_lib.c:758
mutex_getdatafromsensor
static pthread_mutex_t mutex_getdatafromsensor
Definition: sensor_lib.c:753
CloseSessionRecord_b
static bool CloseSessionRecord_b(uint16_t SenderId_u16)
Definition: sensor_lib.c:1537
kResetReasonStrings
static const char * kResetReasonStrings[]
Definition: custom_types.h:90
Sensor_t::SensorMode
enum SensorMode_t SensorMode
Definition: sensor_lib.h:87
SW_ISSUE_REBOOT_REQUIRED
@ SW_ISSUE_REBOOT_REQUIRED
Definition: custom_types.h:139
ADCDump_t::DumpBlob_pu8
uint8_t * DumpBlob_pu8
Definition: sensor_lib.h:80
RdyCallback
static void(* RdyCallback)(uint16_t Sender_u16)
Definition: sensor_lib.c:728
CONTROL_BYTE_LOG_ERROR
@ CONTROL_BYTE_LOG_ERROR
Definition: message_flags.h:117
REQUEST_RESPONSE_INDEX
#define REQUEST_RESPONSE_INDEX
If a Getter-Function is called while current sender is multicast id, this index of CurrentACKStatus....
Definition: sensor_lib.c:141
Sensor_Session_t::SenderId_u16
uint16_t SenderId_u16
Definition: sensor_lib.h:64
mutex_knownsensors
static pthread_mutex_t mutex_knownsensors
Definition: sensor_lib.c:751
IsADCDataFrame_b
static bool IsADCDataFrame_b(uint16_t SenderId_u16, uint8_t *ReceivedPayload_pu8, uint8_t len)
Validates whether the received payload represents an ADC-Data Message. If so and there is an open adc...
Definition: sensor_lib.c:1974
GetSessionStateFromSensorSession
static SessionState_t GetSessionStateFromSensorSession(Sensor_Session_t *session)
Definition: sensor_lib.c:865
IsSessionEndFrame_b
static bool IsSessionEndFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received message contains an EOS command. If so, CloseSessionRecord_b or CloseA...
Definition: sensor_lib.c:1647
UARTMessageState_t
UARTMessageState_t
Definition: sensor_lib.c:163
CALIBRATION_ISSUE_BAD_FRAME
@ CALIBRATION_ISSUE_BAD_FRAME
Definition: custom_types.h:151
PARAM_GROUP_BYTE_TRANSDUCER
@ PARAM_GROUP_BYTE_TRANSDUCER
Definition: message_flags.h:124
CONTROL_BYTE_LOG_DEBUG
@ CONTROL_BYTE_LOG_DEBUG
Definition: message_flags.h:114
FLOAT_CONVERSION_FACTOR
#define FLOAT_CONVERSION_FACTOR
Sensor delivers data in 0.001 degree. This factor is usesed do calculate from and to degree.
Definition: sensor_lib.c:136
CALIBRATION_ISSUE_INIT_ERROR
@ CALIBRATION_ISSUE_INIT_ERROR
Definition: custom_types.h:150
SET_U8_LEN
#define SET_U8_LEN
Number of Bytes that needs to be transmitted if 1 U8 value is set via a set-parameter function.
Definition: sensor_lib.c:107
SC_STATUS_MIC_MALFUNCTION
@ SC_STATUS_MIC_MALFUNCTION
Definition: custom_types.h:129
BL_STATUS_APP_VERSION_ERROR
@ BL_STATUS_APP_VERSION_ERROR
Definition: custom_types.h:176
UART_LENGTH_IDX
#define UART_LENGTH_IDX
Definition: uart_wrapper.h:19
Point3D_t::Y_i16
int16_t Y_i16
Definition: sensor_lib.h:42
GetADCSessionComplete_b
bool GetADCSessionComplete_b(uint16_t TargetSensorId_u16)
Definition: sensor_lib.c:2533
ConnectedToUSB_b
static bool ConnectedToUSB_b
Definition: sensor_lib.c:701
GetCurrentSessionsActiveSessions
static Sensor_Session_t * GetCurrentSessionsActiveSessions(uint8_t index)
Definition: sensor_lib.c:847
ActionRequestSuccessful_b
static bool ActionRequestSuccessful_b(const uint8_t *request, const uint8_t *response)
Compares request and response payload and validates if the response indicates a success of the reques...
Definition: sensor_lib.c:2589
CONTROL_BYTE_IDX
#define CONTROL_BYTE_IDX
Definition: message_flags.h:17
GetParameterSystemNodeID_u16
uint16_t GetParameterSystemNodeID_u16()
Blocking Request to read the current NodeID setting from current sensor.
Definition: sensor_lib.c:3103
BL_STATUS_EXPECTED_PACKET
@ BL_STATUS_EXPECTED_PACKET
Definition: custom_types.h:181
uart_wrapper.h
Header for UART wrapper.
timeoutID
static pthread_t timeoutID
Definition: sensor_lib.c:748
WriteUARTPayload
int WriteUARTPayload(uint8_t *Payload_pu8, uint8_t Length_u8, uint8_t InterfaceId_u8)
Called to send messages to can socket.
Definition: uartinterface.c:140
GetWaitForACKFromACKStatus
static bool GetWaitForACKFromACKStatus(ACK_Status_t *ackstatus)
Definition: sensor_lib.c:940
LOGGING_ISSUE_BYTE_1
#define LOGGING_ISSUE_BYTE_1
Definition: message_flags.h:75
Session_Data_t::NumberOfActiveSessions_u8
uint8_t NumberOfActiveSessions_u8
Definition: sensor_lib.c:150
SW_ISSUE_SAVE_FROM_FLASH_FAILED
@ SW_ISSUE_SAVE_FROM_FLASH_FAILED
Definition: custom_types.h:141
PrintKnownSensors
static void PrintKnownSensors()
Definition: sensor_lib.c:1079
IsACKResponse_b
static bool IsACKResponse_b(const uint8_t *ReceivedPayload_pu8)
Validates whether the received message contains an ACK message. No more feature atm.
Definition: sensor_lib.c:1369
SYS_PARAM_BYTE_LOG_LEVEL
@ SYS_PARAM_BYTE_LOG_LEVEL
Definition: message_flags.h:219
GetCurrentSessionsNumberOfActiveSessions_u8
static uint8_t GetCurrentSessionsNumberOfActiveSessions_u8()
Definition: sensor_lib.c:831
SetNumberOfSensorsACKIsExpectedFrom
static void SetNumberOfSensorsACKIsExpectedFrom(uint8_t newvalue)
Definition: sensor_lib.c:792
ACK_STATUS_BYTE_SUCCESS
@ ACK_STATUS_BYTE_SUCCESS
Definition: message_flags.h:181
GetSessionData
Sensor_Session_t * GetSessionData(uint16_t Sender_u16)
Interface function to query current session-data (ongoing and closed session)
Definition: sensor_lib.c:3422
GetU16FromTwoArgumentPayload_u16
uint16_t GetU16FromTwoArgumentPayload_u16(const uint8_t *Payload_pu8)
Is called from Getter functions to extract values from payload. In this case a uint16-value.
Definition: sensor_lib.c:2894
SIG_PRO_ISSUE_TRACKING_ERROR
@ SIG_PRO_ISSUE_TRACKING_ERROR
Definition: custom_types.h:168
GetI32FromPayload_i32
int32_t GetI32FromPayload_i32(const uint8_t *Payload_pu8)
Is called from Getter functions to extract values from payload. In this case a i32-value.
Definition: sensor_lib.c:2909
GetSessionRunning_b
bool GetSessionRunning_b(uint16_t TargetSensorId_u16)
Definition: sensor_lib.c:2450
Point3D_t::Z_i16
int16_t Z_i16
Definition: sensor_lib.h:43
BL_STATUS_CRC_ERROR
@ BL_STATUS_CRC_ERROR
Definition: custom_types.h:178
LOG_CAT_CALIBRATION
@ LOG_CAT_CALIBRATION
Definition: custom_types.h:122
Sensor_t::InterfaceSensorId_u16
uint16_t InterfaceSensorId_u16
Definition: sensor_lib.h:85
GetParameterSignalProcessingHumidity_u8
uint8_t GetParameterSignalProcessingHumidity_u8()
Blocking Request to read the current Transducer Humidity setting from current sensor.
Definition: sensor_lib.c:3015
ADCDump_t::ReceivedDumpSize_u32
uint32_t ReceivedDumpSize_u32
Definition: sensor_lib.h:79
CAN_MAX_FRAME_LEN
#define CAN_MAX_FRAME_LEN
Definition: message_flags.h:15
LogMsgCallback
static void(* LogMsgCallback)(uint16_t Sender_u16, uint8_t *ReceivedPayload_pu8)
Definition: sensor_lib.c:733
InitInterface
void InitInterface(char *InterfaceName, uint32_t DataRate_u32, CommsInterfaceType_t Interface_t)
Instruction to initialize the specified interface with the specified bit rate. Will also initialize t...
Definition: sensor_lib.c:2225
LOGGING_CATEGORY_BYTE
#define LOGGING_CATEGORY_BYTE
Definition: message_flags.h:74
LOGGING_ISSUE_BYTE_3
#define LOGGING_ISSUE_BYTE_3
Definition: message_flags.h:77
ADCDump_t::SessionState
SessionState_t SessionState
Definition: sensor_lib.h:76
SYS_PARAM_BYTE_SENSOR_MODE
@ SYS_PARAM_BYTE_SENSOR_MODE
Definition: message_flags.h:222
UART_MESSAGE_STATE_TRANSMIT_COMPLETE
@ UART_MESSAGE_STATE_TRANSMIT_COMPLETE
Definition: sensor_lib.c:168
GetParameterADCUseFixedFrameRate_b
bool GetParameterADCUseFixedFrameRate_b()
Blocking Request to read the "Use fixed framerate" value from current sensor.
Definition: sensor_lib.c:2939
SendViaUART
static void SendViaUART(uint8_t *payload, uint16_t length, uint8_t InterfaceId_u8)
Definition: sensor_lib.c:1064
SENSOR_MODE_CONTINUOUS_TRANSMIT_LISTEN
@ SENSOR_MODE_CONTINUOUS_TRANSMIT_LISTEN
Definition: custom_types.h:67
ADC_PARAM_BYTE_FRAME_RATE
@ ADC_PARAM_BYTE_FRAME_RATE
Definition: message_flags.h:195
EvaluateACKStatus_b
static bool EvaluateACKStatus_b(uint16_t SenderId_u16, uint8_t *ReceivedPayload_pu8)
Validates whether the received message was sent by one of the sensors we expect an answer from and,...
Definition: sensor_lib.c:1243
SetACKForACKStatus
static void SetACKForACKStatus(ACK_Status_t *ackstatus, bool ack)
Definition: sensor_lib.c:949
ACTION_BYTE_LOAD_SETTINGS
@ ACTION_BYTE_LOAD_SETTINGS
Definition: message_flags.h:135
IsNoiseLevelFrame_b
static bool IsNoiseLevelFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received point-data-payload is a noise-level-information. If so,...
Definition: sensor_lib.c:1741
SetCurrentStatusInformant_u16
static void SetCurrentStatusInformant_u16(uint16_t newvalue)
Definition: sensor_lib.c:901
Version_t
Definition: custom_structs.h:12
CurrentSessions
Session_Data_t CurrentSessions
Definition: sensor_lib.c:717
wait_ack_payload_pu8
static uint8_t wait_ack_payload_pu8[CAN_MAX_FRAME_LEN]
Definition: sensor_lib.c:710
START_ADC_DUMP_SESSION_ACK_LEN
#define START_ADC_DUMP_SESSION_ACK_LEN
Definition: message_flags.h:38
wait_ack_sem
static sem_t wait_ack_sem
Definition: sensor_lib.c:708
SIG_PRO_ISSUE_POINT_BUFFER_FULL
@ SIG_PRO_ISSUE_POINT_BUFFER_FULL
Definition: custom_types.h:170
GetParameterSignalProcessingEnableMultipathFilter_b
bool GetParameterSignalProcessingEnableMultipathFilter_b()
Blocking Request to read whether the multipath filter is enabled in the current sensor.
Definition: sensor_lib.c:3073
SC_STATUS_SENSOR_OK
@ SC_STATUS_SENSOR_OK
Definition: custom_types.h:128
Session_Data_t::ActiveSessions
Sensor_Session_t ActiveSessions[MAX_NUMBER_OF_SENSORS_ON_BUS]
Definition: sensor_lib.c:152
CALIBRATION_ISSUE_CALIBRATION_FINISHED
@ CALIBRATION_ISSUE_CALIBRATION_FINISHED
Definition: custom_types.h:149
GetKnownSensor
static Sensor_t * GetKnownSensor(uint8_t index)
Definition: sensor_lib.c:874
SYS_PARAM_BYTE_MCU_TEMPERATURE
@ SYS_PARAM_BYTE_MCU_TEMPERATURE
Definition: message_flags.h:218
SetParameterSystemSensorMode
bool SetParameterSystemSensorMode(SensorMode_t Mode_t)
Blocking Request to set the Sensor Mode for current target sensor.
Definition: sensor_lib.c:2812
mutex_currentackstatus
static pthread_mutex_t mutex_currentackstatus
Definition: sensor_lib.c:756
CalculateUARTChecksum
uint8_t CalculateUARTChecksum(const uint8_t *Payload_pu8, uint8_t PayloadLength_u8)
Definition: sensor_lib.c:1030
MPRINTF
#define MPRINTF(f_,...)
Definition: sensor_lib_config.h:53
uartinterface.h
This file contains the linux-uart interface prototypes.
UART_Msg_t
Definition: sensor_lib.c:173
UART_END_FLAG
#define UART_END_FLAG
Definition: uart_wrapper.h:15
LOGGING_SEVERITY_BYTE
#define LOGGING_SEVERITY_BYTE
Definition: message_flags.h:73
SensorMode_t
SensorMode_t
Definition: custom_types.h:65
CloseADCSessionRecord_b
static bool CloseADCSessionRecord_b(uint16_t SenderId_u16)
Definition: sensor_lib.c:1556
SIGPRO_PARAM_BYTE_ENABLE_NEAR_FIELD_DETECTION
@ SIGPRO_PARAM_BYTE_ENABLE_NEAR_FIELD_DETECTION
Definition: message_flags.h:210
RequestADCDump
bool RequestADCDump()
Request selected sensor to create an ADC-Dump.
Definition: sensor_lib.c:2559
IF_CAN
@ IF_CAN
Definition: custom_types.h:13
Sensor_Session_t::NoiseLevel_u16
uint16_t NoiseLevel_u16
Definition: sensor_lib.h:66
UART_Msg_t::Payload_pu8
uint8_t Payload_pu8[CAN_MAX_FRAME_LEN]
Definition: sensor_lib.c:178
CALIBRATION_ISSUE_NOT_CALIBRATED
@ CALIBRATION_ISSUE_NOT_CALIBRATED
Definition: custom_types.h:147
EOS_ACK_LEN
#define EOS_ACK_LEN
Definition: message_flags.h:39
GetADCSessionRunning_b
bool GetADCSessionRunning_b(uint16_t TargetSensorId_u16)
Definition: sensor_lib.c:2507
UID_t
Definition: sensor_lib.h:34
Point1D_t::Intensity_u8
uint8_t Intensity_u8
Definition: sensor_lib.h:50
SetSessionStateExpected
void SetSessionStateExpected(uint16_t TargetSensorId_u16)
Definition: sensor_lib.c:2409
Sensor_Session_t::NearFieldPoint_b
bool NearFieldPoint_b
Definition: sensor_lib.h:67
AddSenderToKnownSensors
static void AddSenderToKnownSensors(uint16_t Sender_u16, uint8_t SensorInterfaceIndex_u8)
Tries to add the station with the Sender_u32 list of known stations.
Definition: sensor_lib.c:1339
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
UID_t::values
uint8_t values[UID_SIZE]
Definition: sensor_lib.h:36
SIGPRO_PARAM_BYTE_NOISE_LEVEL_THRESHOLD_FACTOR
@ SIGPRO_PARAM_BYTE_NOISE_LEVEL_THRESHOLD_FACTOR
Definition: message_flags.h:208
UID_SIZE
#define UID_SIZE
Definition: sensor_lib.h:29
MAX_NUMBER_OF_POINTS_PER_SESSION
#define MAX_NUMBER_OF_POINTS_PER_SESSION
Upper Limit of suppored POINT Data per Point Data Session. 3D OR 2D. A maximum of 2x as much point da...
Definition: sensor_lib_config.h:40
wait_session_start_sem
static sem_t wait_session_start_sem
Definition: sensor_lib.c:736
SIG_PRO_ISSUE_INIT_ERROR
@ SIG_PRO_ISSUE_INIT_ERROR
Definition: custom_types.h:162
GetWaitACKPayload
static uint8_t * GetWaitACKPayload()
Definition: sensor_lib.c:774
WaitForSessionStart
uint16_t WaitForSessionStart()
Blocking Function call to wait for SessionStart Payload.
Definition: sensor_lib.c:3342
Version_t::major
uint8_t major
Definition: custom_structs.h:14
SYS_PARAM_BYTE_RESET_REASON
@ SYS_PARAM_BYTE_RESET_REASON
Definition: message_flags.h:220
BL_STATUS_MODEL_ERROR
@ BL_STATUS_MODEL_ERROR
Definition: custom_types.h:183
SetupUARTPort
int SetupUARTPort(char *InterfaceName_cp, uint32_t InterfaceBitrate_u32, uint8_t InterfaceId_u8)
Called from the library, this function will take care of all linux-related uart-setup,...
Definition: uartinterface.c:189
UART_START_FLAG_IDX
#define UART_START_FLAG_IDX
Definition: uart_wrapper.h:18
SC_STATUS_PGA_OK
@ SC_STATUS_PGA_OK
Definition: custom_types.h:131
ParseCalibrationLogMessageToText
void ParseCalibrationLogMessageToText(char *Output_p8, const uint8_t *ReceivedPayload_pu8)
Parses calibration related log messages into human readable text.
Definition: sensor_lib.c:3763
GetI32FromTwoArgumentPayload_i32
int32_t GetI32FromTwoArgumentPayload_i32(const uint8_t *Payload_pu8)
Is called from Getter functions to extract values from two argument payload. In this case a i32-value...
Definition: sensor_lib.c:2924
GetSenderIdFromSensorSession
static uint16_t GetSenderIdFromSensorSession(Sensor_Session_t *session)
Definition: sensor_lib.c:856
ADCDump_t::ExpectedDumpSize_u32
uint32_t ExpectedDumpSize_u32
Definition: sensor_lib.h:78
mutex_currenttarget
static pthread_mutex_t mutex_currenttarget
Definition: sensor_lib.c:755
PARAM_BYTE_4_IDX
#define PARAM_BYTE_4_IDX
Definition: message_flags.h:22
SIGPRO_PARAM_BYTE_RELATIVE_HUMIDITY
@ SIGPRO_PARAM_BYTE_RELATIVE_HUMIDITY
Definition: message_flags.h:207
ACTION_BYTE_MEASUREMENT
@ ACTION_BYTE_MEASUREMENT
Definition: message_flags.h:132
UART_START_FLAG
#define UART_START_FLAG
Definition: uart_wrapper.h:14
STATE_BL_FLASH_APP
@ STATE_BL_FLASH_APP
Definition: custom_types.h:30
GetACKFromACKStatus
static bool GetACKFromACKStatus(ACK_Status_t *ackstatus)
Definition: sensor_lib.c:956
Sensor_Session_t
Definition: sensor_lib.h:61
UART_MESSAGE_STATE_IN_TRANSMIT_READ_PAYLOAD
@ UART_MESSAGE_STATE_IN_TRANSMIT_READ_PAYLOAD
Definition: sensor_lib.c:167
SC_STATUS_PGA_CANNOT_CHECK
@ SC_STATUS_PGA_CANNOT_CHECK
Definition: custom_types.h:133
UART_Msg_t
struct UART_Msg_t UART_Msg_t
SetSenderIdForACKStatus
static void SetSenderIdForACKStatus(ACK_Status_t *ackstatus, uint16_t senderId)
Definition: sensor_lib.c:917
GetParameterSignalProcessingNoiseRatioThreshold_u8
uint8_t GetParameterSignalProcessingNoiseRatioThreshold_u8()
Blocking Request to read the current Noise Ratio Threshold from current sensor.
Definition: sensor_lib.c:3045
UART_Msg_t::Checksum_u8
uint8_t Checksum_u8
Definition: sensor_lib.c:179
sensor_lib.h
This file contains the highlevel interface prototypes to the low-level Protocol.
SIGPRO_PARAM_BYTE_NOISE_RATIO_THRESHOLD
@ SIGPRO_PARAM_BYTE_NOISE_RATIO_THRESHOLD
Definition: message_flags.h:209
RegisterLogMsgCallback
void RegisterLogMsgCallback(void(*Callback)(uint16_t Sender_u16, uint8_t *ReceivedPayload_pu8))
Interface function to register a callback function that is called whenever a Logmessage Payload is re...
Definition: sensor_lib.c:3409
GetParameterSystemMCUTemperature_f
float GetParameterSystemMCUTemperature_f()
Blocking Request to read the current MCU Temperature from current sensor.
Definition: sensor_lib.c:3138
AllSessionsClosed_b
static bool AllSessionsClosed_b()
Definition: sensor_lib.c:1621
POINT_TYPE_BYTE_1D
@ POINT_TYPE_BYTE_1D
Definition: message_flags.h:161
GetUARTNodeId
static uint16_t GetUARTNodeId(uint8_t InterfaceId_u8)
Definition: sensor_lib.c:3117
ACTION_BYTE_REBOOT
@ ACTION_BYTE_REBOOT
Definition: message_flags.h:131
BL_STATUS_NOT_RDY_TO_LAUNCH
@ BL_STATUS_NOT_RDY_TO_LAUNCH
Definition: custom_types.h:185
IF_USB
@ IF_USB
Definition: custom_types.h:15
ReplaceIdInListOfKnownSensors
static void ReplaceIdInListOfKnownSensors(uint16_t OldId_u16, uint16_t NewId_u16)
Replaces one known sensor-id with another. Called if Change-Node-Id Request is executed.
Definition: sensor_lib.c:3463
SetParameterSignalProcessingHumidity
bool SetParameterSignalProcessingHumidity(uint8_t Humidity_u8)
Blocking Request to set the Humidity for current target sensor.
Definition: sensor_lib.c:2676
CONTROL_BYTE_NACK
@ CONTROL_BYTE_NACK
Definition: message_flags.h:84
CONTROL_BYTE_TRIGGER_ACTION
@ CONTROL_BYTE_TRIGGER_ACTION
Definition: message_flags.h:92
POINT_TYPE_BYTE_3D
@ POINT_TYPE_BYTE_3D
Definition: message_flags.h:158
GetParameterSignalProcessingNoiseLevelThresholdFactor_f
float GetParameterSignalProcessingNoiseLevelThresholdFactor_f()
Blocking Request to read the current Noise Level Threshold Factor from current sensor.
Definition: sensor_lib.c:3029
Version_t::minor
uint8_t minor
Definition: custom_structs.h:15
SYS_PARAM_BYTE_NODE_ID
@ SYS_PARAM_BYTE_NODE_ID
Definition: message_flags.h:217
RequestStoreSettings
bool RequestStoreSettings()
Request selected sensor to store current settings.
Definition: sensor_lib.c:2379
PARAM_GROUP_BYTE_SYSTEM
@ PARAM_GROUP_BYTE_SYSTEM
Definition: message_flags.h:126
ADCDump_t::SenderId_u16
uint16_t SenderId_u16
Definition: sensor_lib.h:77
UART_Msg_t::PayloadLen_u8
uint8_t PayloadLen_u8
Definition: sensor_lib.c:176
RemoveSenderFromList
static void RemoveSenderFromList(uint16_t Sender_u16)
Will remove Sender_u16 from list of known sensors.
Definition: sensor_lib.c:3484
GetConnectedToCANBus
static bool GetConnectedToCANBus()
Definition: sensor_lib.c:972
Session_Data_t
Definition: sensor_lib.c:148
WaitForACKNoSend
static void WaitForACKNoSend(uint8_t *payload)
Definition: sensor_lib.c:1329
RegisterADCDumpStartRequestCallback
void RegisterADCDumpStartRequestCallback(void(*Callback)(uint16_t Sender_u16, uint32_t ADCDumpSize_32))
Interface function to register a callback function that is called whenever an ADC-Dump Start Payload ...
Definition: sensor_lib.c:3415
Sensor_Session_t::Point3D_tp
Point3D_t Point3D_tp[MAX_NUMBER_OF_POINTS_PER_SESSION]
Definition: sensor_lib.h:71
mutex_waitackpayload
static pthread_mutex_t mutex_waitackpayload
Definition: sensor_lib.c:759
IsSessionStartFrame_b
static bool IsSessionStartFrame_b(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Validates whether the received message contains an Session-Start command. If so, StartNewSessionRecor...
Definition: sensor_lib.c:1415
RUNNING
@ RUNNING
Definition: sensor_lib.h:57
SIG_PRO_ISSUE_TIMER_ERROR
@ SIG_PRO_ISSUE_TIMER_ERROR
Definition: custom_types.h:171
ADCDump_Data_t::Dumps
ADCDump_t Dumps[MAX_NUMBER_OF_SENSORS_ON_BUS]
Definition: sensor_lib.c:160
NumberOfSensorsACKIsExpectedFrom_u8
static uint8_t NumberOfSensorsACKIsExpectedFrom_u8
Definition: sensor_lib.c:712
CONTROL_BYTE_READY
@ CONTROL_BYTE_READY
Definition: message_flags.h:85
CONTROL_BYTE_VERSION
@ CONTROL_BYTE_VERSION
Definition: message_flags.h:110
Interface_t::InterfaceName
char InterfaceName[DEVICE_NAME_LEN]
Definition: sensor_lib.c:185
mutex_connectedtocanbus
static pthread_mutex_t mutex_connectedtocanbus
Definition: sensor_lib.c:760
RegisterUARTReadCallback
void RegisterUARTReadCallback(void(*Callback)(uint8_t *UARTMsg_pu8, uint16_t UARTMsgSize_u16, uint8_t InterfaceId_u8))
This function is called by the library to set a callback function for incoming can-traffic.
Definition: uartinterface.c:126
SetParameterSystemNodeID
bool SetParameterSystemNodeID(uint16_t NodeID_u16)
Blocking Request to set a new NodeID for current target sensor.
Definition: sensor_lib.c:2765
DEVICE_NAME_LEN
#define DEVICE_NAME_LEN
Definition: sensor_lib_config.h:59
SYS_PARAM_BYTE_SENSOR_STATE
@ SYS_PARAM_BYTE_SENSOR_STATE
Definition: message_flags.h:221
STATE_BL_PROCESSING_APP
@ STATE_BL_PROCESSING_APP
Definition: custom_types.h:29
ACK_Status_t::ResponsePayload_pu8
uint8_t ResponsePayload_pu8[CAN_MAX_FRAME_LEN]
Definition: sensor_lib.h:98
CurrentACKStatus
static ACK_Status_t CurrentACKStatus[MAX_NUMBER_OF_SENSORS_ON_BUS]
Definition: sensor_lib.c:714
NumberOfSensorsASessionStartIsExpectedFrom_u8
static uint8_t NumberOfSensorsASessionStartIsExpectedFrom_u8
Definition: sensor_lib.c:706
LOG_CAT_SOFTWARE
@ LOG_CAT_SOFTWARE
Definition: custom_types.h:120
Init_Semaphores
static void Init_Semaphores()
Inits all Semaphores needed for Operation. If more Semaphores are added, init them here,...
Definition: sensor_lib.c:2212
ADCDump_t
Definition: sensor_lib.h:74
IsLogMessage
static bool IsLogMessage(uint16_t SenderId_u16, uint8_t *ReceivedPayload_pu8)
Validates whether the received payload represents a LogMessage. If so and a callback has been registe...
Definition: sensor_lib.c:1911
AllSessionsActive_b
static bool AllSessionsActive_b()
Definition: sensor_lib.c:1607
ConfigureACKStatus
static void ConfigureACKStatus(uint8_t *payload)
This function is called from WaitForACK and configures CurrentACKStatus-Struct-Array....
Definition: sensor_lib.c:1187
BL_STATUS_MULTI_INIT_ERROR
@ BL_STATUS_MULTI_INIT_ERROR
Definition: custom_types.h:184
SetParameterSignalProcessingEnableAutoGain
bool SetParameterSignalProcessingEnableAutoGain(bool Enable_b)
Blocking Request to enable auto gain for current target sensor.
Definition: sensor_lib.c:2749
AllADCSessionsClosed_b
static bool AllADCSessionsClosed_b()
Definition: sensor_lib.c:1633
ParseResetReasonLogMessageToText
void ParseResetReasonLogMessageToText(char *Output_p8, const uint8_t *ReceivedPayload_pu8)
Definition: sensor_lib.c:3585
SIGPRO_PARAM_BYTE_TEMPERATURE
@ SIGPRO_PARAM_BYTE_TEMPERATURE
Definition: message_flags.h:206
GetSenderIdFromACKStatus
static uint16_t GetSenderIdFromACKStatus(ACK_Status_t *ackstatus)
Definition: sensor_lib.c:924
SetParameterSignalProcessingTemperature
bool SetParameterSignalProcessingTemperature(float Temperature_f)
Blocking Request to set the Temperature for current target sensor.
Definition: sensor_lib.c:2659
UART_OVERHEAD_LENGTH
#define UART_OVERHEAD_LENGTH
Definition: uart_wrapper.h:16
SET_U32_LEN
#define SET_U32_LEN
Number of Bytes that needs to be transmitted if 1 U32 value is set via a set-parameter function.
Definition: sensor_lib.c:127
STATE_BL_LAUNCHING_APP
@ STATE_BL_LAUNCHING_APP
Definition: custom_types.h:32
CurrentStatusInformant_u16
static uint16_t CurrentStatusInformant_u16
Definition: sensor_lib.c:695
UART_MESSAGE_STATE_IN_TRANSMIT_SIZE_UNKNOWN
@ UART_MESSAGE_STATE_IN_TRANSMIT_SIZE_UNKNOWN
Definition: sensor_lib.c:166
GetU8FromPayload_u8
uint8_t GetU8FromPayload_u8(const uint8_t *Payload_pu8)
Is called from Getter functions to extract values from payload. In this case a uint8-value.
Definition: sensor_lib.c:2856
PrintKnownInterfaces
static void PrintKnownInterfaces()
Definition: sensor_lib.c:1092
COMPLETE
@ COMPLETE
Definition: sensor_lib.h:58
RequestWasSuccessful_b
bool RequestWasSuccessful_b()
Definition: sensor_lib.c:2317
ADC_FRAME_TYPE_DATA
@ ADC_FRAME_TYPE_DATA
Definition: message_flags.h:166
wait_ready_sem
static sem_t wait_ready_sem
Definition: sensor_lib.c:741
POINT_TYPE_BYTE_NOISE_LEVEL
@ POINT_TYPE_BYTE_NOISE_LEVEL
Definition: message_flags.h:160
SET_U16_LEN
#define SET_U16_LEN
Number of Bytes that needs to be transmitted if 1 U16 value is set via a set-parameter function.
Definition: sensor_lib.c:122
NumberOfKnownInterfaces_u8
uint8_t NumberOfKnownInterfaces_u8
Definition: sensor_lib.c:746
EXPECTED
@ EXPECTED
Definition: sensor_lib.h:56
SUBCONTROL_BYTE_IDX
#define SUBCONTROL_BYTE_IDX
Definition: message_flags.h:18
IF_UART
@ IF_UART
Definition: custom_types.h:14
GetCurrentSendersADCSessionIndex
static int8_t GetCurrentSendersADCSessionIndex(uint16_t SenderId_u16)
Definition: sensor_lib.c:1501
RegisterPointSessionEndCallback
void RegisterPointSessionEndCallback(void(*Callback)(uint16_t Sender_u16))
Interface function to register a callback function that is called whenever an SessionEnd Payload is r...
Definition: sensor_lib.c:3358


toposens_echo_driver
Author(s): Tobias Roth , Dennis Maier , Baris Yazici
autogenerated on Wed Mar 2 2022 01:12:32