[89] | 1 | /*********************************************************************
|
---|
| 2 | // created: 2007/11/13 - 10:48
|
---|
| 3 | // filename: AlascaComponent.h
|
---|
| 4 | //
|
---|
| 5 | // author: Gerald Dherbomez & Sergio Rodriguez
|
---|
| 6 | // Copyright Heudiasyc UMR UTC/CNRS 6599
|
---|
| 7 | //
|
---|
| 8 | // version: $Id: $
|
---|
| 9 | //
|
---|
| 10 | // purpose: Definition of the AlascaComponent class
|
---|
| 11 | *********************************************************************/
|
---|
| 12 |
|
---|
| 13 | #ifndef ALASCACOMPONENT_H
|
---|
| 14 | #define ALASCACOMPONENT_H
|
---|
| 15 |
|
---|
| 16 | #include "kernel/ComponentBase.h"
|
---|
| 17 | #include "kernel/DbiteFile.h"
|
---|
| 18 | #include "structure/structure_telemetre.h"
|
---|
| 19 | #include "structure/genericLidarStructures.h"
|
---|
| 20 |
|
---|
| 21 | #include <fstream>
|
---|
| 22 | #include <QThread>
|
---|
| 23 | #include <string>
|
---|
| 24 |
|
---|
| 25 | // Export macro for AlascaXT DLL for Windows only
|
---|
| 26 | #ifdef WIN32
|
---|
| 27 | # ifdef ALASCAXT_EXPORTS
|
---|
| 28 | // make DLL
|
---|
| 29 | # define ALASCAXT_API __declspec(dllexport)
|
---|
| 30 | # else
|
---|
| 31 | // use DLL
|
---|
| 32 | # define ALASCAXT_API __declspec(dllimport)
|
---|
| 33 | # endif
|
---|
| 34 | #else
|
---|
| 35 | // On other platforms, simply ignore this
|
---|
| 36 | # define ALASCAXT_API
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | class QEvent;
|
---|
| 40 |
|
---|
| 41 | namespace pacpus {
|
---|
| 42 |
|
---|
| 43 | class AlascaSocket;
|
---|
| 44 | class ShMem;
|
---|
| 45 |
|
---|
| 46 | struct ScanAlascaObject {
|
---|
| 47 | // todo...
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | // see Manual_Alasca.pdf page 27
|
---|
| 51 | struct MessageHeader {
|
---|
| 52 | unsigned long magicWord;
|
---|
| 53 | unsigned long size;
|
---|
| 54 | unsigned long dataType;
|
---|
| 55 | unsigned long timestamp;
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | // see Manual_Alasca.pdf page 28
|
---|
| 59 | struct ALASCAXT_API ScanHeader {
|
---|
| 60 | unsigned char version;
|
---|
| 61 | unsigned char scannerType;
|
---|
| 62 | unsigned char ecuId;
|
---|
| 63 | unsigned long timeStamp;
|
---|
| 64 | unsigned short startAngle;
|
---|
| 65 | unsigned short endAngle;
|
---|
| 66 | unsigned short scanCounter;
|
---|
| 67 | unsigned short numPoints;
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | // the class containing Alasca message
|
---|
| 71 | class ALASCAXT_API Message
|
---|
| 72 | {
|
---|
| 73 | public:
|
---|
| 74 | /// Constructor.
|
---|
| 75 | Message()
|
---|
| 76 | {
|
---|
| 77 | time = 0;
|
---|
| 78 | timerange = 0;
|
---|
| 79 | memset(&hMsg,0,sizeof(hMsg));
|
---|
| 80 | memset(&hScan,0,sizeof(hScan));
|
---|
| 81 | memset(body,0,sizeof(body));
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | /// Destructor.
|
---|
| 85 | ~Message(){}
|
---|
| 86 |
|
---|
| 87 | MessageHeader hMsg; // 16 bytes
|
---|
| 88 | ScanHeader hScan; // 16 bytes
|
---|
| 89 | unsigned char body[ 32 + MAX_SCAN_POINT * 12 ]; // 32 + 12N bytes where N <= 8648 - MH+SH+body
|
---|
| 90 | road_time_t time;
|
---|
| 91 | road_timerange_t timerange;
|
---|
| 92 | };
|
---|
| 93 |
|
---|
| 94 | // Structure used to stored alasca data between several decoding processes
|
---|
| 95 | struct MessagePacket {
|
---|
| 96 | road_time_t time;
|
---|
| 97 | std::string data;
|
---|
| 98 | bool previousData;
|
---|
| 99 | };
|
---|
| 100 |
|
---|
| 101 | class AlascaDataGenerator;
|
---|
| 102 |
|
---|
| 103 | class ALASCAXT_API AlascaComponent
|
---|
| 104 | : public QThread
|
---|
| 105 | , public ComponentBase
|
---|
| 106 | {
|
---|
| 107 | Q_OBJECT
|
---|
| 108 |
|
---|
| 109 | public:
|
---|
| 110 | AlascaComponent(QString name);
|
---|
| 111 | ~AlascaComponent();
|
---|
| 112 |
|
---|
| 113 | void run() {}
|
---|
| 114 |
|
---|
| 115 | virtual void stopActivity(); /*!< to stop the processing thread */
|
---|
| 116 | virtual void startActivity(); /*!< to start the processing thread */
|
---|
| 117 | virtual ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
|
---|
| 118 |
|
---|
| 119 | // decoupe le paquet en messages et remplit la liste de 'Message'
|
---|
| 120 | // remplit le message header
|
---|
| 121 | // remplit le scan header
|
---|
| 122 | // détermine si le message est complet (isFull)
|
---|
| 123 | // renvoie le nombre de pending bytes
|
---|
| 124 | void splitPacket(const char * packet, const int length, road_time_t time);
|
---|
| 125 |
|
---|
| 126 | // decoupe le message en scan
|
---|
| 127 | // remplit la structure alascaData
|
---|
| 128 | // renvoie le nombre de scan (<=8 648)
|
---|
| 129 | unsigned long processMessage(Message & msg);
|
---|
| 130 |
|
---|
| 131 | // renvoie l'index du magicWord dans le message
|
---|
| 132 | // -1 si aucun magic word trouvé
|
---|
| 133 | long findMagicWord(const char * message, const unsigned length);
|
---|
| 134 |
|
---|
| 135 | // renvoie la taille du message = 32 + body size
|
---|
| 136 | // 0 si pas trouv�
|
---|
| 137 | long getMessageSize(const char * message, const unsigned length, const long magicWordIndex);
|
---|
| 138 |
|
---|
| 139 | /// @returns @b true if the message is complete, @b false otherwise
|
---|
| 140 | bool isMessageComplete(const unsigned length, const long size);
|
---|
| 141 |
|
---|
| 142 | public Q_SLOTS:
|
---|
| 143 | //Fonction qui permet de trier les données reçues et de les enregistrer dans une structure point, puis dans un fichier binaire .dbt
|
---|
| 144 | void customEvent(QEvent * e);
|
---|
| 145 |
|
---|
| 146 | public:
|
---|
| 147 | AlascaSocket * A_socket; //on déclare pointeur de socket
|
---|
| 148 | AlascaComponent * myParent;
|
---|
| 149 |
|
---|
| 150 | private:
|
---|
| 151 | std::list<Message> msgList;
|
---|
| 152 |
|
---|
| 153 | ScanAlascaData alascaData;
|
---|
| 154 | LidarScan lidarScan;
|
---|
| 155 | ScanAlascaObject alascaObjects;
|
---|
| 156 |
|
---|
| 157 | //char * pendingBytes;
|
---|
| 158 | MessagePacket pendingBytes;
|
---|
| 159 |
|
---|
| 160 | void storePendingBytes(road_time_t time);
|
---|
| 161 | void fillMessageHeader(Message & msg);
|
---|
| 162 | void fillScanHeader(Message & msg);
|
---|
| 163 | short din70000toCentimeters(short n);
|
---|
| 164 | float din70000toMeters(short n);
|
---|
| 165 | // write the data on the disk in the dbt file and the associated binary file
|
---|
| 166 | void writeData();
|
---|
| 167 |
|
---|
| 168 | void addInputOutput();
|
---|
| 169 |
|
---|
| 170 | // AlascaDataGenerator * generator;
|
---|
| 171 |
|
---|
| 172 | AlascaXT dbtData_;
|
---|
| 173 | pacpus::DbiteFile dbtFile_;
|
---|
| 174 | std::ofstream dataFile_;
|
---|
| 175 |
|
---|
| 176 | ShMem * shmem_;
|
---|
| 177 |
|
---|
| 178 | // The alasca IP or hostname
|
---|
| 179 | QString host_;
|
---|
| 180 |
|
---|
| 181 | // The alasca port
|
---|
| 182 | int port_;
|
---|
| 183 | };
|
---|
| 184 |
|
---|
| 185 | } // namespace pacpus
|
---|
| 186 |
|
---|
| 187 | #endif // ALASCACOMPONENT_H
|
---|