libvisiontransfer  10.6.0
datachannel-imu-bno080.h
1 /*******************************************************************************
2  * Copyright (c) 2023 Allied Vision Technologies GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 // DataChannel protocol definition for the BNO080 IMU sensor
16 
17 #ifndef VISIONTRANSFER_DATACHANNEL_IMU_BNO080_H
18 #define VISIONTRANSFER_DATACHANNEL_IMU_BNO080_H
19 
20 #include <visiontransfer/datachannelservicebase.h>
21 #include <visiontransfer/sensorringbuffer.h>
22 
23 #include <vector>
24 #include <stdexcept>
25 
26 namespace visiontransfer {
27 namespace internal {
28 
29 // TODO IMPLEMENT_ME / Not active at the moment:
33 class DataChannelIMUBNO080Commands {
34 public:
35  enum Command {
36  BNOReserved,
37  BNOReset,
38  BNOEnableSensors,
39  BNORateLimit,
40  BNOReports
41  };
42 };
43 
47 class DataChannelIMUBNO080Util {
48  static DataChannelIMUBNO080Commands::Command getCommand(unsigned char* data, int datalen) {
49  if (datalen < 2) throw std::runtime_error("Buffer too small");
50  return (DataChannelIMUBNO080Commands::Command) ntohs(*((uint16_t*) data));
51  }
52  static int packResetMessage(unsigned char* data, int datalen) {
53  if (datalen < 2) throw std::runtime_error("Buffer too small");
54  *((uint16_t*)data) = htons(DataChannelIMUBNO080Commands::BNOReset);
55  return 2;
56  }
57 };
58 
59 
66 private:
67  static constexpr int RINGBUFFER_SIZE = 2048;
68 public:
69  // These are inspected and consumed by the DataChannelService
70  SensorDataRingBuffer<TimestampedVector, RINGBUFFER_SIZE> ringbufXYZ[6]; // for sensors 0x01 .. 0x06 (w/o 5)
71  TimestampedVector lastXYZ[6]; // cache the most recent value for each channel
72  SensorDataRingBuffer<TimestampedQuaternion, RINGBUFFER_SIZE> ringbufRotationQuaternion; // for 0x05, Rot Vec
73  TimestampedQuaternion lastRotationQuaternion;
74  SensorDataRingBuffer<TimestampedScalar, RINGBUFFER_SIZE> ringbufScalar[5]; // 0x0a .. 0x0e (temp, pressure..)
75  TimestampedScalar lastScalar[5];
76 public:
78  DataChannel::Type getChannelType() const override { return DataChannel::Types::BNO080; }
79  int handleSensorInputRecord(unsigned char* data, int datalen, uint64_t baseTime);
80  void handleChunk(unsigned char* data, int datalen);
81  int handleMessage(DataChannelMessage& message, sockaddr_in* sender) override;
82  bool initialize() override { return true; }
83  int startService() override { return 1; }
84  int stopService() override { return 1; }
85 };
86 
87 }} // namespaces
88 
89 #endif
90 
visiontransfer::internal::DataChannelMessage
Definition: datachannelservicebase.h:71
visiontransfer::TimestampedQuaternion
Encapsulate a 4D (quaternion) sensor report, containing X, Y, Z, W, as well as timestamp and status f...
Definition: sensordata.h:80
visiontransfer::internal::ClientSideDataChannelIMUBNO080::startService
int startService() override
startService() implementations can start devices, launch an IO-blocked worker thread etc.
Definition: datachannel-imu-bno080.h:107
visiontransfer::internal::DataChannel
Base class all data channel services derive from (once on the server side, once on the API side)
Definition: datachannelservicebase.h:83
visiontransfer::TimestampedVector
Encapsulate a 3D sensor report, containing X, Y, Z, as well as timestamp and status fields.
Definition: sensordata.h:64
visiontransfer::internal::SensorDataRingBuffer
Definition: sensorringbuffer.h:42
visiontransfer::internal::ClientSideDataChannelIMUBNO080::initialize
bool initialize() override
When initialize() implementations return false, the service will be deactivated.
Definition: datachannel-imu-bno080.h:106
visiontransfer::TimestampedScalar
Encapsulate a scalar sensor measurement, containing the value, as well as timestamp and status fields...
Definition: sensordata.h:51
visiontransfer::internal::ClientSideDataChannelIMUBNO080::handleMessage
int handleMessage(DataChannelMessage &message, sockaddr_in *sender) override
Channel-dependent message handlers in respective channel implementations.
Definition: datachannel-imu-bno080.cpp:169
visiontransfer::internal::ClientSideDataChannelIMUBNO080
Encapsulated receiver with ring buffers for IMU / environment sensor data.
Definition: datachannel-imu-bno080.h:89
Allied Vision