Flair
Framework Libre Air
HostEthController.h
1 // %flair:license{
2 // This file is part of the Flair framework distributed under the
3 // CECILL-C License, Version 1.0.
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 // purpose: Base class for host side remote controls that talks to target
14 // side through ethernet connection
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 {
27 namespace core {
28 class FrameworkManager;
29 class cvmatrix;
30 class TcpSocket;
31 class Socket;
32 class Mutex;
33 }
34 namespace gui {
35 class Tab;
36 class TabWidget;
37 class DataPlot1D;
38 }
39 }
40 
41 namespace flair {
42 namespace sensor {
43 enum class ControllerAction;
44 
57 public:
58  HostEthController(const core::FrameworkManager *parent, std::string name,
59  std::string address, int port, uint32_t period = 10,
60  uint32_t _bitsPerAxis = 7, uint8_t priority = 0);
62  void DrawUserInterface();
63 
64 protected:
65  std::string controllerName;
66  core::TcpSocket *controlSocket; // connection to the target
67  core::Socket *dataSocket;
68  std::string targetAddress;
69  int targetPort;
70  gui::Tab *tab;
71  gui::TabWidget *tabWidget;
72  virtual bool IsDataFrameReady() { return true; };
73  virtual void CompleteDataFrameGrab(){};
74  // int8_t *datas;
75  // uint8_t dataSize;
76  char *dataFrameBuffer;
77  size_t dataFrameSize;
78  virtual void ProcessMessage(core::Message *controllerAction){};
79 
80  virtual std::string GetAxisDescription(unsigned int axis);
81  virtual void
82  GetAxisData() = 0; // responsible for getting the axis data from the hardware
83  unsigned int axisNumber;
84  core::cvmatrix *axis;
85  gui::DataPlot1D **axisPlot;
86  uint32_t bitsPerAxis;
87  uint32_t nativeBitsPerAxis;
88 
89  virtual std::string GetButtonDescription(unsigned int button);
90  virtual void GetButtonData() = 0; // responsible for getting the button data
91  // from the hardware
92  unsigned int buttonNumber;
93  core::cvmatrix *button;
94  uint8_t buttonOffset;
95  bool meaningfulDataAvailable;
96 
97 private:
98  class DataSender : public core::Thread {
99  public:
100  DataSender(Object *parent, HostEthController *hostEthController,
101  std::string name, uint8_t priority = 0);
102  void Run();
103 
104  private:
105  HostEthController *hostEthController;
106  };
107  DataSender *dataSender;
108 
109  bool ControllerInitialization();
110  bool ConnectedWithTarget();
111  void SendControllerInfo();
112  void Run();
113  void BuildDataFrame();
114  bool writeBits(uint16_t value, uint8_t valueSizeInBits, char *buffer,
115  uint8_t offsetInBits);
116  core::Mutex *connectionEstablishedMutex;
117 };
118 }
119 }
120 
121 #endif // HOSTETHCONTROLLER_H
Abstract class for input/ouput system.
Definition: IODevice.h:45
namespace of the flair Framework
Definition: Ahrs.h:19
Class defining a matrix of kind CvMat.
Definition: cvmatrix.h:33
Class defining a mutex.
Definition: Mutex.h:29
Class encapsulating a TCP socket.
Definition: TcpSocket.h:25
Class encapsulating a UDP socket. It assumes packets are coming from only one distant host on a given...
Definition: Socket.h:31
Abstract class for input/ouput system.
Main class of the Framework library.
Definition: FrameworkManager.h:45
Class displaying a QTabWidget on the ground station.
Definition: TabWidget.h:29
Abstract class for a thread.
Base Class for host side remote controls that talks to target side through ethernet connection...
Definition: HostEthController.h:56
Abstract class for a thread.
Definition: Thread.h:38
Definition: Object.h:35
Class displaying a 1D plot on the ground station.
Definition: DataPlot1D.h:33
Class displaying a QTab on the ground station.
Definition: Tab.h:29
Object(const Object *parent=NULL, std::string name="", std::string type="")
Constructor.