libvisiontransfer  7.0.0
datachannel-imu-bno080.h
1 /*******************************************************************************
2  * Copyright (c) 2019 Nerian Vision 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 
25 namespace visiontransfer {
26 namespace internal {
27 
28 // TODO IMPLEMENT_ME / Not active at the moment:
33 public:
34  enum Command {
35  BNOReserved,
36  BNOReset,
37  BNOEnableSensors,
38  BNORateLimit,
39  BNOReports
40  };
41 };
42 
47  static DataChannelIMUBNO080Commands::Command getCommand(unsigned char* data, int datalen) {
48  if (datalen < 2) throw std::runtime_error("Buffer too small");
49  return (DataChannelIMUBNO080Commands::Command) ntohs(*((uint16_t*) data));
50  }
51  static int packResetMessage(unsigned char* data, int datalen) {
52  if (datalen < 2) throw std::runtime_error("Buffer too small");
53  *((uint16_t*)data) = htons(DataChannelIMUBNO080Commands::BNOReset);
54  return 2;
55  }
56 };
57 
58 
65 private:
66  static constexpr int RINGBUFFER_SIZE = 2048;
67 public:
68  // These are inspected and consumed by the DataChannelService
69  SensorDataRingBuffer<TimestampedVector, RINGBUFFER_SIZE> ringbufXYZ[6]; // for sensors 0x01 .. 0x06 (w/o 5)
70  TimestampedVector lastXYZ[6]; // cache the most recent value for each channel
71  SensorDataRingBuffer<TimestampedQuaternion, RINGBUFFER_SIZE> ringbufRotationQuaternion; // for 0x05, Rot Vec
72  TimestampedQuaternion lastRotationQuaternion;
73  SensorDataRingBuffer<TimestampedScalar, RINGBUFFER_SIZE> ringbufScalar[5]; // 0x0a .. 0x0e (temp, pressure..)
74  TimestampedScalar lastScalar[5];
75 public:
77  DataChannel::Type getChannelType() const override { return DataChannel::Types::BNO080; }
78  int handleSensorInputRecord(unsigned char* data, int datalen, uint64_t baseTime);
79  void handleChunk(unsigned char* data, int datalen);
80  int handleMessage(DataChannelMessage& message, sockaddr_in* sender) override;
81  bool initialize() override { return true; }
82  int startService() override { return 1; }
83  int stopService() override { return 1; }
84 };
85 
86 }} // namespaces
87 
88 #endif
89 
Encapsulate a 4D (quaternion) sensor report, containing i, j, k, r, as well as timestamp and status f...
Definition: sensordata.h:66
Encapsulate a scalar sensor measurement, containing the value, as well as timestamp and status fields...
Definition: sensordata.h:37
Encapsulate a 3D sensor report, containing X, Y, Z, as well as timestamp and status fields...
Definition: sensordata.h:50
bool initialize() override
When initialize() implementations return false, the service will be deactivated.
Helper functions for IMU control messages.
Base class all data channel services derive from (once on the server side, once on the API side) ...
Encapsulated receiver with ring buffers for IMU / environment sensor data.
int startService() override
startService() implementations can start devices, launch an IO-blocked worker thread etc...
Commands to control the IMU/environmental sensor and its data reporting.
Nerian Vision Technologies