source: libs/libSamgar/inc/Samgar.h @ 445

Revision 445, 6.2 KB checked in by lmalek, 10 years ago (diff)

Samgar edition by WRUT. Based on Qt. Initial import.

Line 
1#ifndef SAMGAR_H
2#define SAMGAR_H
3/*! \file Samhar.h
4 * File contains definition of the structure ModuleStruct, class
5 * DataPort and class SamgarModule
6 */
7#include <yarp/os/all.h>
8#include <iostream>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string>
12#include <list>
13#include <yarp/sig/all.h> //image stuff
14#include <math.h>
15#include <cxtypes.h>
16#include <fstream>
17
18#include <SamgarVars.h>
19
20using namespace std;
21using namespace yarp::os; // network stuff
22using namespace yarp::sig;// image stuff
23
24namespace Samgar{
25  /*! \brief Structure containin basic information about module
26   */
27  struct ModuleStruct
28  {
29    string name; //! module name
30    /*! module category
31     *
32     * \todo maybe it should be standarized like it is in player?
33     */
34    string catagory;
35    string subcatagory; //! module subcategory
36  };
37 
38  bool operator==(ModuleStruct x, ModuleStruct y);
39  bool operator>(ModuleStruct x, ModuleStruct y);
40
41
42  /*! \brief Port for SAMGAR
43   *  This class extends standard BufferedPort<Bottle> from the YARP
44   *
45   *  \todo Maybe it should be based on template or just allow to send any
46   *  Portable objects from YARP?
47   */
48  class DataPort : public BufferedPort<Bottle>
49  {
50  private:
51    ModuleState *Status; //! SAMGAR module state \see ModuleState
52
53    Bottle SavedBottle; //! some storage for the Bottle
54                        //! \todo why only for one?
55 
56  public: 
57
58    /*! what should be done when the data is being read
59     */
60    virtual void onRead(Bottle& b);
61
62    /*! get Bottel from the port, and clear Bottle storage in the DataPort
63     */
64    Bottle getBottle();
65   
66    /*! \brief constructor
67     * /todo add default constructor
68     */
69    DataPort(ModuleState *modulState);
70  };
71
72  /*! \brief SAMGAR main class
73   */
74  class SamgarModule : public BufferedPort<Bottle>
75  {
76  private :
77
78    std::string fullModuleName;
79    std::string imagePortName;
80
81    ModuleState currentmode;
82    ModuleMode modulemode;
83    bool DoIWantModules;
84
85    /* lists all the ports available for a module */
86    list<DataPort*> PortList;
87    list<std::string> portNameList;
88    /* Iterator for port lists */
89    //list<DataPort*>::iterator ItPort;
90    /* module specific data */
91    string MyName,MyCatagory, MySubCatagory, MyType;
92    /* a special port for images only */
93    BufferedPort<ImageOf<PixelBgr> > YarpImagePort;
94
95    /* a special image holder */
96    ImageOf<PixelBgr> yarpImage;
97    /* only for internal use , use acessor methods to retrive data */
98    bool GetDataFromPort(string NameOfPort,int TypeOfData, void *data);
99    //                 int *I = 0, float *F = 0, double *D = 0,
100    //                   string *S = 0, Bottle *B = 0);
101    /* Only for internal use , user acessor methods to send data */
102    void SendData(DataType type, string port, void* data);
103
104  public :
105    void GetAvailPlatforms(void);
106
107    ModuleState getCurrentState();
108
109    // you can acess this list whenever you want really
110    // should all be good , it should work and be updated etc
111    list<ModuleStruct> ListOfKnownModules;
112    list<string> ListOfKnownPlatforms;
113
114    void TurnOnModuleListener(void);
115
116    BufferedPort<Bottle> TempPort;
117       
118    void SendAllModulesCommand(int cm);
119
120    void SendModuleCommand(string name,int cm);
121    /* A interupt module method, takes the core data ie respond
122     * with type, pause stop etc
123     */
124    virtual void onRead(Bottle& b) ;
125       
126    /* constructor method, give the module a name and catagories,
127     * ie locomotion,wheel. only put in type continuas run/ interupt
128     * run
129     */
130    SamgarModule(string NameOfModule,string Catagory,string SubCatagory,ModuleMode Type);
131
132    /* a a port to your module with a given name */
133    void AddPortS(string outputname);
134    /* give a name and setup the image port */
135    void SetupImagePort(string outputname);
136    /* get the int data of port named, also give it the memory
137     * locatoin of interger to be chaned, returns true if new data
138     * avail
139     */
140    bool GetIntData(string NameOfPort,int *I);
141    /* get the float data of port named, also give it the memory
142     * locatoin of float to be chaned, returns true if new data avail
143     */
144    bool GetFloatData(string NameOfPort,float *I);
145    /* get the double data of port named, also give it the memory
146     * locatoin of double to be chaned, returns true if new data avail
147     */
148    bool GetDoubleData(string NameOfPort,double *I);
149    /* get the string data of port named, also give it the memory
150     * locatoin of string to be chaned, returns true if new data avail
151     */
152    bool GetStringData(string NameOfPort,string *I);
153    /* get the Bottle data of port named, also give it the memory
154     * locatoin of string to be chaned, returns true if new data avail
155     */
156    bool GetBottleData(string NameOfPort,Bottle *B);
157
158    /* send data to port */
159    void SendIntData(string port,int data);
160    /* send data to port */
161    void SendFloatData(string port,float data);
162    /* send data to port */
163    void SendDoubleData(string port,double data);
164    /* send data to port */
165    void SendStringData(string port,string data);
166    /* send data to port */
167    void SendBottleData(string port,Bottle data);
168
169    /* send a picture on port in YARP native Bgr form */
170    void SendPictureYarpNative(ImageOf<PixelBgr> Image);
171    /* get a picture on port in YARP native Bgr form */
172    ImageOf<PixelBgr> RecivePictureYarpNative(void);
173    /* for open CV, Send image to port */
174    void SendPictureOCVNative( IplImage* Image);
175    /* for open CV, Get image from port */
176    IplImage* RecivePictureOCVNative(void);
177    /* if a interupt port then this ends the current run, intill anyport
178     * gets new data, its also needid as it allows stopping and pausing
179     * of the program
180     */
181    void SucceedFail(bool Awns,double additoinaldata);
182    /* Send data to the main gui log */
183    void SendToLog(string LogData,int priority);
184    /* Migrate */
185    void Migrate(string migratewhere);
186    /* find possible migrates */
187    list<string> WherePossMigrate(void);
188
189    bool checkConnection();
190
191  };
192
193} // namespace Samgar
194
195#endif // SAMGAR_H
Note: See TracBrowser for help on using the repository browser.