source: flair-src/branches/mavlink/lib/FlairSensorActuator/src/HostEthController.h@ 111

Last change on this file since 111 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 3.3 KB
Line 
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
26namespace flair {
27namespace core {
28class FrameworkManager;
29class cvmatrix;
30class TcpSocket;
31class Socket;
32class Mutex;
33}
34namespace gui {
35class Tab;
36class TabWidget;
37class DataPlot1D;
38}
39}
40
41namespace flair {
42namespace sensor {
43enum class ControllerAction;
44
45/*! \class HostEthController
46*
47* \brief Base Class for host side remote controls that talks to target side
48*through ethernet connection
49*
50* There are 2 communication channels:
51* - 1 connection with the ground station to display the values. Output for
52*analog sticks is normalized in the range [-1, 1] (float values)
53* - 1 connection with the target to send the controller values (and receive
54*controller state modification requests)
55*/
56class HostEthController : public core::Thread, public core::IODevice {
57public:
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);
61 ~HostEthController();
62 void DrawUserInterface();
63
64protected:
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
97private:
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
Note: See TracBrowser for help on using the repository browser.