adc_dump.cpp
Go to the documentation of this file.
2 
3 #include <ros/ros.h>
4 
6 
7 namespace toposens_echo_driver
8 {
9 auto requestAdcDump(RequestAdcDump::Request& req, RequestAdcDump::Response& res) -> bool
10 {
11  bool success = true;
12  ROS_INFO("ADC Dump requested! Request: [sensor_id=%d, file_path=%s].", req.sensor_id,
13  req.file_path.c_str());
14 
15  if (!toposens_echo_driver::SetTargetSensor(req.sensor_id))
16  {
17  res.success = false;
18  return false;
19  }
20 
21  success &= RequestADCDump();
22 
23  ROS_DEBUG("SetParameterSystemSensorMode");
25  ROS_DEBUG("RequestMeasurement");
26  success &= RequestMeasurement();
27  ROS_DEBUG("WaitForSessionStart");
28  const auto sender_u16 = WaitForSessionStart();
29 
30  ROS_DEBUG("WaitForSessionEnd");
31  const auto sender_u16_end = WaitForSessionEnd();
32  if (sender_u16 != sender_u16_end)
33  {
34  ROS_WARN("Unexpected: Received different sender IDs for session start and end!");
35  }
36  ROS_DEBUG("WaitForADCSessionEnd");
38 
39  ADCDump_t* DumpData_t = GetADCDumpData(sender_u16);
40  if (DumpData_t != nullptr)
41  {
42  success &= saveAdcBlobData(DumpData_t, req.file_path.c_str());
43  }
44  else
45  {
46  ROS_ERROR("Could not retrieve ADC Dump Data!");
47  success = false;
48  }
49 
50  res.success = success;
51  ROS_INFO(
52  "ADC Dump request finished! Request: [sensor_id=%d, file_path=%s]. Sending back response: "
53  "[success=%d]!",
54  req.sensor_id, req.file_path.c_str(), res.success);
55 
56  return success;
57 }
58 
59 auto saveAdcBlobData(ADCDump_t* adc_dump, const char* file_path) -> bool
60 {
61  bool success = true;
62  uint32_t DumpSize_u32 = adc_dump->ReceivedDumpSize_u32;
63 
64  // TODO(tobi) Use ofstream instead
65  FILE* fptr;
66  fptr = fopen(file_path, "wb");
67 
68  if (fptr == nullptr)
69  {
70  ROS_ERROR("ADC Dump file open error!");
71  success = false;
72  return success;
73  }
74 
75  size_t number_of_bytes_written = fwrite(adc_dump->DumpBlob_pu8, 1, DumpSize_u32, fptr);
76 
77  if (number_of_bytes_written == DumpSize_u32)
78  {
79  ROS_DEBUG("Save sucessful");
80  }
81  else
82  {
83  ROS_ERROR("ADC Dump file write error!");
84  success = false;
85  }
86 
87  fclose(fptr);
88 
89  return success;
90 }
91 
92 void requestAdcDumpCallback(uint16_t sender_id, uint32_t data_size) {}
93 
94 void adcDumpEndCallback(uint16_t sender_id) {}
95 
96 } // namespace toposens_echo_driver
toposens_echo_driver::requestAdcDump
bool requestAdcDump(RequestAdcDump::Request &req, RequestAdcDump::Response &res)
ROS Service Callback for ADC Dump Requests.
Definition: adc_dump.cpp:9
lib_utils.h
ros.h
toposens_echo_driver::SetTargetSensor
auto SetTargetSensor(uint16_t TargetSensor_u16) -> bool
Checks if TargetSensor_u16 is known and sets current target accordingly.
Definition: lib_utils.cpp:35
toposens_echo_driver::requestAdcDumpCallback
void requestAdcDumpCallback(uint16_t sender_id, uint32_t data_size)
Callback for device driver library.
Definition: adc_dump.cpp:92
toposens_echo_driver::adcDumpEndCallback
void adcDumpEndCallback(uint16_t sender_id)
Callback for device driver library.
Definition: adc_dump.cpp:94
WaitForADCSessionEnd
uint16_t WaitForADCSessionEnd()
Blocking Function call to wait for SessionEnd Payload.
Definition: sensor_lib.c:3384
WaitForSessionEnd
uint16_t WaitForSessionEnd()
Blocking Function call to wait for SessionEnd Payload.
Definition: sensor_lib.c:3370
GetADCDumpData
ADCDump_t * GetADCDumpData(uint16_t Sender_u16)
Interface function to get current ADC-Dump from SenderId.
Definition: sensor_lib.c:3443
RequestMeasurement
bool RequestMeasurement()
Send's a request to start a new measurement.
Definition: sensor_lib.c:2348
ROS_DEBUG
#define ROS_DEBUG(...)
ROS_WARN
#define ROS_WARN(...)
toposens_echo_driver
Definition: adc_dump.h:8
SENSOR_MODE_SINGLE_SHOT_TRANSMIT_LISTEN
@ SENSOR_MODE_SINGLE_SHOT_TRANSMIT_LISTEN
Definition: custom_types.h:68
toposens_echo_driver::saveAdcBlobData
auto saveAdcBlobData(ADCDump_t *adc_dump, const char *file_path) -> bool
Saves given adc_dump to file file_path.
Definition: adc_dump.cpp:59
SetParameterSystemSensorMode
bool SetParameterSystemSensorMode(SensorMode_t Mode_t)
Blocking Request to set the Sensor Mode for current target sensor.
Definition: sensor_lib.c:2812
adc_dump.h
RequestADCDump
bool RequestADCDump()
Request selected sensor to create an ADC-Dump.
Definition: sensor_lib.c:2559
WaitForSessionStart
uint16_t WaitForSessionStart()
Blocking Function call to wait for SessionStart Payload.
Definition: sensor_lib.c:3342
ROS_ERROR
#define ROS_ERROR(...)
ROS_INFO
#define ROS_INFO(...)
ADCDump_t
Definition: sensor_lib.h:74


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