source: flair-src/trunk/lib/FlairSensorActuator/src/HostEthController.h@ 3

Last change on this file since 3 was 3, checked in by Sanahuja Guillaume, 8 years ago

sensoractuator

File size: 3.6 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 side through ethernet connection
14//
15//
16/*********************************************************************/
17
18#ifndef HOSTETHCONTROLLER_H
19#define HOSTETHCONTROLLER_H
20
21#include <IODevice.h>
22#include <Thread.h>
23#include <stdint.h>
24
25namespace flair {
26 namespace core {
27 class FrameworkManager;
28 class cvmatrix;
29 class TcpSocket;
30 class Socket;
31 class Mutex;
32 }
33 namespace gui {
34 class Tab;
35 class TabWidget;
36 class DataPlot1D;
37 }
38}
39
40namespace flair { namespace sensor {
41 enum class ControllerAction;
42
43 /*! \class HostEthController
44 *
45 * \brief Base Class for host side remote controls that talks to target side through ethernet connection
46 *
47 * There are 2 communication channels:
48 * - 1 connection with the ground station to display the values. Output for analog sticks is normalized in the range [-1, 1] (float values)
49 * - 1 connection with the target to send the controller values (and receive controller state modification requests)
50 */
51 class HostEthController : public core::Thread, public core::IODevice {
52 public:
53 HostEthController(const core::FrameworkManager* parent,std::string name,std::string address,int port,uint32_t period=10,uint32_t _bitsPerAxis=7,uint8_t priority=0);
54 ~HostEthController();
55 void DrawUserInterface();
56 protected:
57 std::string controllerName;
58 core::TcpSocket *controlSocket; //connection to the target
59 core::Socket *dataSocket;
60 std::string targetAddress;
61 int targetPort;
62 gui::Tab *tab;
63 gui::TabWidget *tabWidget;
64 virtual bool IsDataFrameReady() { return true;};
65 virtual void CompleteDataFrameGrab() {};
66// int8_t *datas;
67// uint8_t dataSize;
68 char *dataFrameBuffer;
69 size_t dataFrameSize;
70 virtual void ProcessMessage(core::Message *controllerAction) {};
71
72 virtual std::string GetAxisDescription(unsigned int axis);
73 virtual void GetAxisData()=0; //responsible for getting the axis data from the hardware
74 unsigned int axisNumber;
75 core::cvmatrix* axis;
76 gui::DataPlot1D **axisPlot;
77 uint32_t bitsPerAxis;
78 uint32_t nativeBitsPerAxis;
79
80 virtual std::string GetButtonDescription(unsigned int button);
81 virtual void GetButtonData()=0; //responsible for getting the button data from the hardware
82 unsigned int buttonNumber;
83 core::cvmatrix* button;
84 uint8_t buttonOffset;
85 bool meaningfulDataAvailable;
86
87 private:
88 class DataSender : public core::Thread {
89 public:
90 DataSender(Object* parent,HostEthController* hostEthController,std::string name,uint8_t priority=0);
91 void Run();
92 private:
93 HostEthController* hostEthController;
94 };
95 DataSender *dataSender;
96
97 bool ControllerInitialization();
98 bool ConnectedWithTarget();
99 void SendControllerInfo();
100 void Run();
101 void BuildDataFrame();
102 bool writeBits(uint16_t value,uint8_t valueSizeInBits,char *buffer,uint8_t offsetInBits);
103 core::Mutex *connectionEstablishedMutex;
104 };
105
106}}
107
108#endif // HOSTETHCONTROLLER_H
Note: See TracBrowser for help on using the repository browser.