adc_dump_save_example.c
Go to the documentation of this file.
1 
7 #include <stdio.h>
8 #include "example_common.h"
9 #include "toposens/sensor_lib.h"
10 
11 static void RequestADCDumpCallback(uint16_t SenderId_u16, uint32_t DataSize_u32);
12 static void ADCDumpEndCallback(uint16_t SenderId_u16);
13 static void LogMsgCallback(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8);
14 
15 static void ADCDumpExample(char* filename)
16 {
17  printf("-----------------ADCDumpExample-----------------\n");
19  printf("-----------------SetParameterSystemSensorMode-----------------\n");
21  printf("-----------------RequestMeasurement-----------------\n");
23  printf("-----------------WaitForSessionEnd(adc session)-----------------\n");
24  uint16_t sender_u16 = WaitForADCSessionEnd();
25  ADCDump_t* DumpData_t = GetADCDumpData(sender_u16);
26 
27  if (DumpData_t != NULL)
28  {
29  SaveADCBlobData(DumpData_t, filename);
30  }
31 
32  printf("-----------------WaitForSessionEnd (point session)-----------------\n");
33  sender_u16 = WaitForSessionEnd();
34  Sensor_Session_t* session_data = GetSessionData(sender_u16);
35  PrintSessionData(session_data);
36  printf("-----------------ADCDumpExample Complete-----------------\n");
37 }
38 
39 int main(int argc, char** argv)
40 {
41  if (argc < 2)
42  {
43  fprintf(stderr, "Pass filename as first argument.\n");
44  return -1;
45  }
49 
50  InitInterface("can0", 1000000, IF_CAN);
51  RequestReboot();
52  WaitForReady();
53 
54  Sensor_t* Sensors = GetKnownSensors();
55  uint8_t NumberOfSensors = GetNumberOfKnownSensors();
56  printf("NumberOfSensors:%d\n", NumberOfSensors);
57  for (int i = 0; i < NumberOfSensors; i++)
58  {
59  printf("%d Sensor on Bus: %d\n", i, Sensors[i].InterfaceSensorId_u16);
60  }
61 
62  ADCDumpExample(argv[1]);
64  return 0;
65 }
66 
67 static void ADCDumpEndCallback(uint16_t SenderId_u16)
68 {
69  printf("Got ADC Dump End Callback from Sender:%d\n", SenderId_u16);
70 }
71 
72 static void RequestADCDumpCallback(uint16_t SenderId_u16, uint32_t DataSize_u32)
73 {
74  printf("Got ADC-Dump Request Sender:%d\n", SenderId_u16);
75  printf("Got ADC-Dump Request Size:%d\n", DataSize_u32);
76 }
77 
78 static void LogMsgCallback(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8)
79 {
80  PrintLogMessage(SenderId_u16, ReceivedPayload_pu8);
81 }
Library containing common functions that are used in the various examples.
bool RequestReboot()
Request selected sensor to reboot.
Definition: sensor_lib.c:2330
void SaveADCBlobData(ADCDump_t *ADCDump, const char *filepath)
void DeinitInterface(CommsInterfaceType_t Interface_t)
Instruction to deinit the specified interface type.
Definition: sensor_lib.c:2279
Sensor_t * GetKnownSensors()
Returns pointer to array containing all known sensors. With GetNumberOfKnownSensors() users can get l...
Definition: sensor_lib.c:765
uint16_t WaitForADCSessionEnd()
Blocking Function call to wait for SessionEnd Payload.
Definition: sensor_lib.c:3384
static void ADCDumpExample(char *filename)
static void ADCDumpEndCallback(uint16_t SenderId_u16)
static void RequestADCDumpCallback(uint16_t SenderId_u16, uint32_t DataSize_u32)
static void LogMsgCallback(uint16_t SenderId_u16, uint8_t *ReceivedPayload_pu8)
uint16_t WaitForSessionEnd()
Blocking Function call to wait for SessionEnd Payload.
Definition: sensor_lib.c:3370
ADCDump_t * GetADCDumpData(uint16_t Sender_u16)
Interface function to get current ADC-Dump from SenderId.
Definition: sensor_lib.c:3443
uint8_t GetNumberOfKnownSensors()
Returns number of known sensors. With GetKnownSensors() users an pointer to an array containing the I...
Definition: sensor_lib.c:799
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
uint16_t WaitForReady()
Blocking Function call to wait for Ready Payload.
Definition: sensor_lib.c:3395
int main(int argc, char **argv)
bool RequestMeasurement()
Send&#39;s a request to start a new measurement.
Definition: sensor_lib.c:2348
Sensor_Session_t * GetSessionData(uint16_t Sender_u16)
Interface function to query current session-data (ongoing and closed session)
Definition: sensor_lib.c:3422
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
void PrintSessionData(Sensor_Session_t *Session)
This file contains the highlevel interface prototypes to the low-level Protocol.
bool SetParameterSystemSensorMode(SensorMode_t Mode_t)
Blocking Request to set the Sensor Mode for current target sensor.
Definition: sensor_lib.c:2812
bool RequestADCDump()
Request selected sensor to create an ADC-Dump.
Definition: sensor_lib.c:2559
void PrintLogMessage(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
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
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


toposens_echo_driver
Author(s): Tobias Roth , Dennis Maier , Baris Yazici
autogenerated on Mon Feb 28 2022 23:57:42