[4] | 1 | // %flair:license{
|
---|
[13] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[4] | 4 | // %flair:license}
|
---|
| 5 | // created: 2015/03/30
|
---|
| 6 | // filename: HostEthController.h
|
---|
| 7 | //
|
---|
| 8 | // author: Gildas Bayard
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
[13] | 13 | // purpose: Base class for host side remote controls that talks to target
|
---|
| 14 | // side through ethernet connection
|
---|
[4] | 15 | //
|
---|
| 16 | //
|
---|
| 17 | /*********************************************************************/
|
---|
| 18 |
|
---|
| 19 | #ifndef HOSTETHCONTROLLER_H
|
---|
| 20 | #define HOSTETHCONTROLLER_H
|
---|
| 21 |
|
---|
| 22 | #include <IODevice.h>
|
---|
| 23 | #include <Thread.h>
|
---|
| 24 | #include <stdint.h>
|
---|
| 25 |
|
---|
| 26 | namespace flair {
|
---|
[13] | 27 | namespace core {
|
---|
| 28 | class cvmatrix;
|
---|
| 29 | class TcpSocket;
|
---|
[50] | 30 | class UdpSocket;
|
---|
[13] | 31 | class Mutex;
|
---|
[4] | 32 | }
|
---|
[13] | 33 | namespace gui {
|
---|
| 34 | class Tab;
|
---|
| 35 | class TabWidget;
|
---|
| 36 | class DataPlot1D;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
[4] | 39 |
|
---|
[13] | 40 | namespace flair {
|
---|
| 41 | namespace sensor {
|
---|
| 42 | enum class ControllerAction;
|
---|
[4] | 43 |
|
---|
[13] | 44 | /*! \class HostEthController
|
---|
| 45 | *
|
---|
| 46 | * \brief Base Class for host side remote controls that talks to target side
|
---|
| 47 | *through ethernet connection
|
---|
| 48 | *
|
---|
| 49 | * There are 2 communication channels:
|
---|
| 50 | * - 1 connection with the ground station to display the values. Output for
|
---|
| 51 | *analog sticks is normalized in the range [-1, 1] (float values)
|
---|
| 52 | * - 1 connection with the target to send the controller values (and receive
|
---|
| 53 | *controller state modification requests)
|
---|
| 54 | */
|
---|
| 55 | class HostEthController : public core::Thread, public core::IODevice {
|
---|
| 56 | public:
|
---|
[50] | 57 | HostEthController(std::string name,
|
---|
[13] | 58 | std::string address, int port, uint32_t period = 10,
|
---|
| 59 | uint32_t _bitsPerAxis = 7, uint8_t priority = 0);
|
---|
| 60 | ~HostEthController();
|
---|
| 61 | void DrawUserInterface();
|
---|
[4] | 62 |
|
---|
[13] | 63 | protected:
|
---|
| 64 | std::string controllerName;
|
---|
| 65 | core::TcpSocket *controlSocket; // connection to the target
|
---|
[50] | 66 | core::UdpSocket *dataSocket;
|
---|
[13] | 67 | std::string targetAddress;
|
---|
| 68 | int targetPort;
|
---|
| 69 | gui::Tab *tab;
|
---|
| 70 | gui::TabWidget *tabWidget;
|
---|
| 71 | virtual bool IsDataFrameReady() { return true; };
|
---|
| 72 | virtual void CompleteDataFrameGrab(){};
|
---|
| 73 | // int8_t *datas;
|
---|
| 74 | // uint8_t dataSize;
|
---|
| 75 | char *dataFrameBuffer;
|
---|
| 76 | size_t dataFrameSize;
|
---|
| 77 | virtual void ProcessMessage(core::Message *controllerAction){};
|
---|
[4] | 78 |
|
---|
[13] | 79 | virtual std::string GetAxisDescription(unsigned int axis);
|
---|
| 80 | virtual void
|
---|
| 81 | GetAxisData() = 0; // responsible for getting the axis data from the hardware
|
---|
| 82 | unsigned int axisNumber;
|
---|
| 83 | core::cvmatrix *axis;
|
---|
| 84 | gui::DataPlot1D **axisPlot;
|
---|
| 85 | uint32_t bitsPerAxis;
|
---|
| 86 | uint32_t nativeBitsPerAxis;
|
---|
[4] | 87 |
|
---|
[13] | 88 | virtual std::string GetButtonDescription(unsigned int button);
|
---|
| 89 | virtual void GetButtonData() = 0; // responsible for getting the button data
|
---|
| 90 | // from the hardware
|
---|
| 91 | unsigned int buttonNumber;
|
---|
| 92 | core::cvmatrix *button;
|
---|
| 93 | uint8_t buttonOffset;
|
---|
| 94 | bool meaningfulDataAvailable;
|
---|
[4] | 95 |
|
---|
[13] | 96 | private:
|
---|
| 97 | class DataSender : public core::Thread {
|
---|
| 98 | public:
|
---|
| 99 | DataSender(Object *parent, HostEthController *hostEthController,
|
---|
| 100 | std::string name, uint8_t priority = 0);
|
---|
| 101 | void Run();
|
---|
[4] | 102 |
|
---|
[13] | 103 | private:
|
---|
| 104 | HostEthController *hostEthController;
|
---|
| 105 | };
|
---|
| 106 | DataSender *dataSender;
|
---|
[4] | 107 |
|
---|
[13] | 108 | bool ControllerInitialization();
|
---|
| 109 | bool ConnectedWithTarget();
|
---|
| 110 | void SendControllerInfo();
|
---|
| 111 | void Run();
|
---|
| 112 | void BuildDataFrame();
|
---|
| 113 | bool writeBits(uint16_t value, uint8_t valueSizeInBits, char *buffer,
|
---|
| 114 | uint8_t offsetInBits);
|
---|
| 115 | core::Mutex *connectionEstablishedMutex;
|
---|
| 116 | };
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[4] | 120 | #endif // HOSTETHCONTROLLER_H
|
---|