n_frames_single_shot_example_uart.c
Go to the documentation of this file.
1 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <termios.h> //Used for UART
10 #include <unistd.h>
11 #include "example_common.h"
12 #include "toposens/sensor_lib.h"
13 
14 #define PORT "/dev/ttyUSB0"
15 #define BAUDRATE B115200
16 
17 static void LogMsgCallback(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8);
18 
19 static void SingleShotMeasurement()
20 {
22 
24  uint16_t current_sensing_sensor = WaitForSessionStart();
25  uint16_t sender = WaitForSessionEnd();
26  Sensor_Session_t* session_data = GetSessionData(sender);
27  PrintSessionData(session_data);
28 }
29 
30 int main(int argc, char** argv)
31 {
32  int num_of_frames = 0;
33  int c;
34 
35  if (argc < 2)
36  {
37  fprintf(stderr, "Pass -n argument.\n");
38  return -1;
39  }
40 
41  while ((c = getopt(argc, argv, "n:")) != -1) switch (c)
42  {
43  case 'n':
44  num_of_frames = atoi(optarg);
45  if (num_of_frames < 0) num_of_frames = 0;
46  break;
47  case '?':
48  if (optopt == 'n')
49  fprintf(stderr, "Option -%c requires an argument.\n", optopt);
50  else
51  fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
52  return 1;
53  default:;
54  }
55 
58  if (RequestReboot())
59  {
60  printf("Blocking Reboot Request worked\n");
61  }
62  else
63  {
64  printf("Blocking Reboot Request worked but did not got the right ack\n");
65  }
66  WaitForReady();
67 
68  printf("Starting measurement\n");
69  int i;
70  for (i = 0; i < num_of_frames; i++)
71  {
73  }
74 
76  return 0;
77 }
78 
79 static void LogMsgCallback(uint16_t SenderId_u16, uint8_t* ReceivedPayload_pu8)
80 {
81  PrintLogMessage(SenderId_u16, ReceivedPayload_pu8);
82 }
SingleShotMeasurement
static void SingleShotMeasurement()
Definition: n_frames_single_shot_example_uart.c:19
PORT
#define PORT
Definition: n_frames_single_shot_example_uart.c:14
RequestReboot
bool RequestReboot()
Request selected sensor to reboot.
Definition: sensor_lib.c:2330
BAUDRATE
#define BAUDRATE
Definition: n_frames_single_shot_example_uart.c:15
DeinitInterface
void DeinitInterface(CommsInterfaceType_t Interface_t)
Instruction to deinit the specified interface type.
Definition: sensor_lib.c:2279
WaitForSessionEnd
uint16_t WaitForSessionEnd()
Blocking Function call to wait for SessionEnd Payload.
Definition: sensor_lib.c:3370
RequestMeasurement
bool RequestMeasurement()
Send's a request to start a new measurement.
Definition: sensor_lib.c:2348
WaitForReady
uint16_t WaitForReady()
Blocking Function call to wait for Ready Payload.
Definition: sensor_lib.c:3395
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
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
PrintSessionData
void PrintSessionData(Sensor_Session_t *Session)
Definition: example_common.c:85
SENSOR_MODE_SINGLE_SHOT_TRANSMIT_LISTEN
@ SENSOR_MODE_SINGLE_SHOT_TRANSMIT_LISTEN
Definition: custom_types.h:68
SetParameterSystemSensorMode
bool SetParameterSystemSensorMode(SensorMode_t Mode_t)
Blocking Request to set the Sensor Mode for current target sensor.
Definition: sensor_lib.c:2812
LogMsgCallback
static void LogMsgCallback(uint16_t SenderId_u16, uint8_t *ReceivedPayload_pu8)
Definition: n_frames_single_shot_example_uart.c:79
WaitForSessionStart
uint16_t WaitForSessionStart()
Blocking Function call to wait for SessionStart Payload.
Definition: sensor_lib.c:3342
Sensor_Session_t
Definition: sensor_lib.h:61
sensor_lib.h
This file contains the highlevel interface prototypes to the low-level Protocol.
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
example_common.h
Library containing common functions that are used in the various examples.
PrintLogMessage
void PrintLogMessage(uint16_t SenderId_u16, const uint8_t *ReceivedPayload_pu8)
Definition: example_common.c:154
main
int main(int argc, char **argv)
Definition: n_frames_single_shot_example_uart.c:30
IF_UART
@ IF_UART
Definition: custom_types.h:14


toposens-library
Author(s): Andrej Wallwitz, Thomas Böhm , Sebastian Kruber
autogenerated on Wed Apr 27 2022 08:10:01