##// END OF EJS Templates
GRESB WIP.
Jeandet Alexis -
r71:81feb673e028 GRESB
parent child
Show More
@@ -105,20 +105,166 void GR_ESB_bridge::setVirtualLink(qint3
105
105
106 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
106 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
107 {
107 {
108 // TODO write ME!
108 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))];
109 Q_UNUSED(count)
109 char *RMAPAckBuff;
110 Q_UNUSED(Value)
110 int transactionID = 0;
111 Q_UNUSED(address)
111 int written=0;
112 return 0;
112 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
113 QProgressBar* progress=NULL;
114 SocExplorerAutoProgressBar autopb;
115 if(count>RMAP_MAX_XFER_SIZE)
116 {
117 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
118 autopb.setProgressBar(progress);
119 }
120 //Quite stupide loop, I guess that I always get the number of byte I asked for!
121 while(count>=RMAP_MAX_XFER_SIZE)
122 {
123 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
124 {
125 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+0] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
126 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
127 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
128 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written])&0xFF);
129 }
130 transactionID=manager->getRMAPtransactionID();
131 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
132 RMAP_build_tx_request_header(
133 this->manager->destinationLogicalAddress,
134 this->manager->destinationKey,
135 this->manager->sourceLogicalAddress,
136 transactionID,
137 address+(written*4),
138 RMAP_MAX_XFER_SIZE*4,
139 writeBuffer);
140 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4));
141 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
142 free(RMAPAckBuff);
143 written+=RMAP_MAX_XFER_SIZE;
144 count-=RMAP_MAX_XFER_SIZE;
145 progress->setValue(written);
146 qApp->processEvents();
147 }
148 if(count>0)
149 {
150 for(int i=0;i<((int)count);i++)
151 {
152 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+0] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
153 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
154 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
155 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written])&0xFF);
156 }
157 transactionID=manager->getRMAPtransactionID();
158 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
159 RMAP_build_tx_request_header(
160 this->manager->destinationLogicalAddress,
161 this->manager->destinationKey,
162 this->manager->sourceLogicalAddress,
163 transactionID,
164 address+(written*4),
165 count*4,
166 writeBuffer);
167 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4));
168 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
169 free(RMAPAckBuff);
170 written+=count;
171 if(progress!=NULL)
172 {
173 progress->setValue(written);
174 qApp->processEvents();
175 }
176 }
177 return written;
113 }
178 }
114
179
115 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
180 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
116 {
181 {
117 // TODO write ME!
182 char requestBuffer[RMAP_READ_HEADER_MIN_SZ];
118 Q_UNUSED(Value)
183 char* RMAP_AnswerBuffer;
119 Q_UNUSED(count)
184 requestBuffer[0]=this->manager->linkNumber;//Link number
120 Q_UNUSED(address)
185 int transactionID = 0;
121 return 0;
186 int read=0;
187 QProgressBar* progress=NULL;
188 SocExplorerAutoProgressBar autopb;
189 if(count>RMAP_MAX_XFER_SIZE)
190 {
191 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
192 autopb.setProgressBar(progress);
193 }
194 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
195
196 //Quite stupide loop, I guess that I always get the number of byte I asked for!
197 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
198 {
199 transactionID = manager->getRMAPtransactionID();
200 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
201 RMAP_build_rx_request_header(
202 this->manager->destinationLogicalAddress,
203 this->manager->destinationKey,
204 this->manager->sourceLogicalAddress,
205 transactionID,
206 address+(read*4),
207 RMAP_MAX_XFER_SIZE*4,
208 requestBuffer);
209 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ);
210 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
211 if(len==-1)
212 {
213 this->toggleBridgeConnection();
214 return 0;
215 }
216 for(int i=0;i<((len-13)/4);i++)
217 {
218 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
219 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
220 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
221 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
222 }
223 free(RMAP_AnswerBuffer);
224 read+=RMAP_MAX_XFER_SIZE;
225 count-=RMAP_MAX_XFER_SIZE;
226 progress->setValue(read);
227 qApp->processEvents();
228 }
229 if((int)count>0)
230 {
231 transactionID = manager->getRMAPtransactionID();
232 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
233 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
234 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
235 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
236 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
237 RMAP_build_rx_request_header(
238 this->manager->destinationLogicalAddress,
239 this->manager->destinationKey,
240 this->manager->sourceLogicalAddress,
241 transactionID,
242 address+(read*4),
243 count*4,
244 requestBuffer);
245 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ);
246 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
247 if(len==-1)
248 {
249 this->toggleBridgeConnection();
250 return 0;
251 }
252 for(int i=0;i<((len-13)/4);i++)
253 {
254 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
255 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
256 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
257 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
258 }
259 free(RMAP_AnswerBuffer);
260 read+=count;
261 if(progress!=NULL)
262 {
263 progress->setValue(read);
264 qApp->processEvents();
265 }
266 }
267 return read;
122 }
268 }
123
269
124 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
270 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
@@ -128,34 +274,65 int GR_ESB_bridge::pushRMAPPacket(char *
128
274
129
275
130 GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
276 GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
131 :QThread((QObject*)parent)
277 :abstractSpwManager(plugin, parent)
132 {
278 {
133 this->Read_soc = new QTcpSocket(this);
279 this->Read_soc = new QTcpSocket(this);
134 this->Write_soc = new QTcpSocket(this);
280 this->Write_soc = new QTcpSocket(this);
135 this->RMAPtimeout = 2000;
136 this->handleMutex = new QMutex(QMutex::NonRecursive);
137 this->RMAP_AnswersSem = new QSemaphore(0);
138 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
139 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
140 this->plugin = plugin;
141 connected = false;
142 this->moveToThread(this);
143 }
281 }
144
282
145 GR_ESB_Manager::~GR_ESB_Manager()
283 GR_ESB_Manager::~GR_ESB_Manager()
146 {
284 {
147
148 }
285 }
149
286
150 void GR_ESB_Manager::run()
287 void GR_ESB_Manager::run()
151 {
288 {
289 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
152 SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
290 SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
153 while (!this->isInterruptionRequested())
291 while (!this->isInterruptionRequested())
154 {
292 {
155 if(this->connected)
293 if(this->connected)
156 {
294 {
157 handleMutex->lock();
295 handleMutex->lock();
158 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
296 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",5);
297 if(Read_soc->waitForReadyRead(100))
298 {
299 QByteArray data = Read_soc->readAll();
300 int PacketLen= ((int)data.at(2)& 0x0FF) + (((int)data.at(3)& 0x0FF)<<8) + (((int)data.at(4)& 0x0FF)<<16);
301 if(data[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
302 {
303 RMAP_Answer* packet;
304 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
305 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(PacketLen),2);
306 char* packetbuffer = (char*)malloc(PacketLen);
307 memcpy(packetbuffer,data.data(),PacketLen);
308 this->handleMutex->unlock();
309 if(PacketLen==8)
310 {
311 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,PacketLen);
312 }
313 else
314 {
315 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,PacketLen);
316 }
317 RMAP_AnswersMtx->lock();
318 RMAP_Answers.append(packet);
319 RMAP_AnswersMtx->unlock();
320 RMAP_AnswersSem->release();
321 }
322 else //any non-rmap packet will be pushed to the network
323 {
324 char* packetbuffer = (char*)malloc(PacketLen);
325 memcpy(packetbuffer,data.data(),PacketLen);
326 emit emitPacket(packetbuffer,PacketLen);
327 this->handleMutex->unlock();
328 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
329 }
330
331 }
332 else
333 {
334 handleMutex->unlock();
335 }
159
336
160 }
337 }
161 else
338 else
@@ -212,31 +389,43 bool GR_ESB_Manager::disconnectBridge()
212 return true;
389 return true;
213 }
390 }
214
391
215 int GR_ESB_Manager::getRMAPtransactionID()
216 {
217 // TODO write ME!
218 return -1;
219 }
220
221 int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer)
222 {
223 // TODO write ME!
224 Q_UNUSED(transactionID)
225 Q_UNUSED(buffer)
226 return -1;
227 }
228
392
229 bool GR_ESB_Manager::sendPacket(char *packet, int size)
393 bool GR_ESB_Manager::sendPacket(char *packet, int size)
230 {
394 {
231 // TODO write ME!
395 bool result = false;
232 Q_UNUSED(packet)
396 char protocoleIdentifier;
233 Q_UNUSED(size)
397 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
234 return false;
398 if(Q_UNLIKELY(this->Write_soc->state()!=QAbstractSocket::ConnectedState))
399 {
400 SocExplorerEngine::message(this->plugin,"Socket closed",2);
401 //TODO handle disconnection
402 }
403 char* SPWpacket = (char*)malloc(size+4);
404 if(SPWpacket!=NULL)
405 {
406 SPWpacket[0]=0; //Protocol = spw
407 memcpy(SPWpacket+4,packet,size);
408 SPWpacket[1]=size & 0x0FF;
409 SPWpacket[2]=(size>>8) & 0x0FF;
410 SPWpacket[3]=(size>>16) & 0x0FF;
411 }
412 this->handleMutex->lock();
413 result = ((size+4) == this->Write_soc->write(SPWpacket,size+4));
414 this->handleMutex->unlock();
415 if (Q_UNLIKELY(!result))
416 {
417 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
418 return false;
419 }
420 else
421 {
422 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
423 // read the protocole identifier
424 protocoleIdentifier = packet[2];
425 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
426 emit ccsdsPacketTransmittedToSpw();
427 SocExplorerEngine::message(this->plugin,"Packet sent",2);
428 }
429 return true;
235 }
430 }
236
431
237 void GR_ESB_Manager::pushRmapPacket(char *packet, int len)
238 {
239 // TODO write ME!
240 Q_UNUSED(packet)
241 Q_UNUSED(len)
242 }
@@ -24,7 +24,7 const struct gresb_Conf_str gresb_Conf[]
24 };
24 };
25
25
26
26
27 class GR_ESB_Manager: public QThread
27 class GR_ESB_Manager: public abstractSpwManager
28 {
28 {
29 Q_OBJECT
29 Q_OBJECT
30 public:
30 public:
@@ -33,28 +33,19 public:
33 void run();
33 void run();
34 bool connectBridge();
34 bool connectBridge();
35 bool disconnectBridge();
35 bool disconnectBridge();
36 int getRMAPtransactionID();
37 int getRMAPanswer(int transactionID,char** buffer);
38 bool sendPacket(char* packet,int size);
36 bool sendPacket(char* packet,int size);
39
37
40 signals:
38 signals:
41 void emitPacket(char* packet,int size);
39 void emitPacket(char* packet,int size);
42 private:
40 private:
43 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
44 QSemaphore* RMAP_AnswersSem;
45 void pushRmapPacket(char* packet,int len);
41 void pushRmapPacket(char* packet,int len);
46 socexplorerplugin* plugin;
47 bool connected;
48 char* SPWPacketBuff;
42 char* SPWPacketBuff;
49 QList<RMAP_Answer*> RMAP_Answers;
50 QList<int> RMAP_pending_transaction_IDs;
51
43
52 public:
44 public:
53 QTcpSocket* Read_soc;
45 QTcpSocket* Read_soc;
54 QTcpSocket* Write_soc;
46 QTcpSocket* Write_soc;
55 QString IP;
47 QString IP;
56 int virtualLinkIndex;
48 int virtualLinkIndex;
57 int RMAPtimeout;
58 };
49 };
59
50
60
51
@@ -40,11 +40,11 stardundeeSPW_USB::stardundeeSPW_USB(soc
40 Q_UNUSED(parent)
40 Q_UNUSED(parent)
41 this->manager = new stardundeeSPW_USB_Manager(parent,this);
41 this->manager = new stardundeeSPW_USB_Manager(parent,this);
42 makeGUI(parent);
42 makeGUI(parent);
43 this->manager->start();
44 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
43 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
45 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
44 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
46 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
45 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
47 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
46 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
47 this->manager->start();
48 }
48 }
49
49
50 stardundeeSPW_USB::~stardundeeSPW_USB()
50 stardundeeSPW_USB::~stardundeeSPW_USB()
@@ -400,16 +400,8 void stardundeeSPW_USB::sendPacketComing
400 }
400 }
401
401
402 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
402 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
403 :QThread((QObject*)parent)
403 :abstractSpwManager(plugin, parent)
404 {
404 {
405 this->RMAPtimeout = 2000;
406 this->handleMutex = new QMutex(QMutex::NonRecursive);
407 // this->handleMutex = new QMutex(QMutex::Recursive);
408 this->RMAP_AnswersSem = new QSemaphore(0);
409 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
410 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
411 this->plugin = plugin;
412 connected = false;
413 // TODO remove this crap!
405 // TODO remove this crap!
414 this->initDialog();
406 this->initDialog();
415 // this->moveToThread(this);
407 // this->moveToThread(this);
@@ -417,10 +409,6 stardundeeSPW_USB_Manager::stardundeeSPW
417
409
418 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
410 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
419 {
411 {
420 this->terminate();
421 while (!this->isFinished()) {
422 this->usleep(1000);
423 }
424 }
412 }
425
413
426 void stardundeeSPW_USB_Manager::run()
414 void stardundeeSPW_USB_Manager::run()
@@ -926,84 +914,6 bool stardundeeSPW_USB_Manager::disconne
926 return true;
914 return true;
927 }
915 }
928
916
929 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
930 {
931 this->RMAP_pending_transaction_IDsMtx->lock();
932 int ID=0;
933 bool found=true;
934 while(ID<511)
935 {
936 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
937 {
938 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
939 }
940 if(found==true)break;
941 ID++;
942 found = true;
943 }
944 if(found)
945 {
946 RMAP_pending_transaction_IDs.append(ID);
947 }
948 this->RMAP_pending_transaction_IDsMtx->unlock();
949 return ID;
950 }
951
952 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
953 {
954 QTime timeout;
955 *buffer=NULL;
956 int count=0;
957 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
958 timeout.start();
959 while (*buffer==NULL)
960 {
961 this->RMAP_AnswersMtx->lock();
962 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
963 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
964 for(int i=0;i<RMAP_Answers.count();i++)
965 {
966 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
967 if(RMAP_Answers[i]->transactionID==transactionID)
968 {
969 this->RMAP_pending_transaction_IDsMtx->lock();
970 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
971 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
972 {
973 if(RMAP_pending_transaction_IDs[j]==transactionID)
974 {
975 RMAP_pending_transaction_IDs.removeAt(j);
976 }
977 }
978 this->RMAP_pending_transaction_IDsMtx->unlock();
979 *buffer = RMAP_Answers[i]->data;
980 count = RMAP_Answers[i]->len;
981 RMAP_Answer* tmp=RMAP_Answers[i];
982 RMAP_Answers.removeAt(i);
983 delete tmp;
984 }
985 }
986 this->RMAP_AnswersMtx->unlock();
987 //if no answer found in the stack wait until a new packet is pushed
988 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
989 if(*buffer==NULL)
990 {
991 while (0==this->RMAP_AnswersSem->available())
992 {
993 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
994 if(timeout.elapsed()>=RMAPtimeout)
995 {
996 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
997 return -1;
998 }
999 usleep(1000);
1000 }
1001 this->RMAP_AnswersSem->acquire();
1002 }
1003 }
1004 return count;
1005 }
1006
1007 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
917 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
1008 {
918 {
1009 char protocoleIdentifier;
919 char protocoleIdentifier;
@@ -1032,15 +942,6 bool stardundeeSPW_USB_Manager::sendPack
1032 return true;
942 return true;
1033 }
943 }
1034
944
1035 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
1036 {
1037 char* packetbuffer = (char*)malloc(len);
1038 memcpy(packetbuffer,packet,len);
1039 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
1040 RMAP_AnswersMtx->lock();
1041 RMAP_Answers.append(RMPAPpacket);
1042 RMAP_AnswersMtx->unlock();
1043 }
1044
945
1045 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
946 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
1046 {
947 {
@@ -41,7 +41,7
41 #define BRICK_IS_SET_AS_AN_INTERFACE true
41 #define BRICK_IS_SET_AS_AN_INTERFACE true
42 #define BRICK_IS_SET_AS_A_ROUTER false
42 #define BRICK_IS_SET_AS_A_ROUTER false
43
43
44 class stardundeeSPW_USB_Manager: public QThread
44 class stardundeeSPW_USB_Manager: public abstractSpwManager
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
@@ -58,8 +58,6 public:
58 void setTimecodeFrequency(double requestedFrequency);
58 void setTimecodeFrequency(double requestedFrequency);
59 unsigned int getLinkStatus(unsigned char link);
59 unsigned int getLinkStatus(unsigned char link);
60 bool disconnectBridge();
60 bool disconnectBridge();
61 int getRMAPtransactionID();
62 int getRMAPanswer(int transactionID,char** buffer);
63 bool sendPacket(char* packet,int size);
61 bool sendPacket(char* packet,int size);
64
62
65 signals:
63 signals:
@@ -75,15 +73,8 public slots:
75 int getLinkNumber( void );
73 int getLinkNumber( void );
76
74
77 private:
75 private:
78 QMutex *handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
79 QSemaphore* RMAP_AnswersSem;
76 QSemaphore* RMAP_AnswersSem;
80 void pushRmapPacket(char* packet,int len);
81 star_device_handle hDevice;
77 star_device_handle hDevice;
82 socexplorerplugin* plugin;
83 bool connected;
84 char* SPWPacketBuff;
85 QList<RMAP_Answer*> RMAP_Answers;
86 QList<int> RMAP_pending_transaction_IDs;
87
78
88 QLabel *starDundeeStatusQueryDialogLabel;
79 QLabel *starDundeeStatusQueryDialogLabel;
89 QPushButton *starDundeeStatusQueryRetryButton;
80 QPushButton *starDundeeStatusQueryRetryButton;
@@ -96,13 +87,8 private:
96
87
97 public:
88 public:
98 int selectedBrick;
89 int selectedBrick;
99 int linkNumber;
100 int brickList;
90 int brickList;
101 int linkSpeed;
91 int linkSpeed;
102 int sourceLogicalAddress;
103 int destinationLogicalAddress;
104 int destinationKey;
105 int RMAPtimeout;
106 double timecodeFrequency;
92 double timecodeFrequency;
107 bool interfaceMode; // 1 => interface mode, 0 => router mode
93 bool interfaceMode; // 1 => interface mode, 0 => router mode
108 };
94 };
@@ -20,6 +20,8
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "abstractspwbridge.h"
22 #include "abstractspwbridge.h"
23 #include <QTime>
24 #include <socexplorerengine.h>
23
25
24 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
26 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
25 :QObject((QObject*)parent)
27 :QObject((QObject*)parent)
@@ -54,3 +56,121 bool abstractSpwBridge::disconnectBridge
54
56
55
57
56
58
59
60
61 abstractSpwManager::abstractSpwManager(socexplorerplugin *plugin, QObject *parent)
62 :QThread((QObject*)parent)
63 {
64 this->RMAPtimeout = 2000;
65 this->handleMutex = new QMutex(QMutex::NonRecursive);
66 this->RMAP_AnswersSem = new QSemaphore(0);
67 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
68 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
69 this->plugin = plugin;
70 connected = false;
71 }
72
73 abstractSpwManager::~abstractSpwManager()
74 {
75 this->terminate();
76 while (!this->isFinished())
77 {
78 this->usleep(1000);
79 }
80 }
81
82 int abstractSpwManager::getRMAPtransactionID()
83 {
84 this->RMAP_pending_transaction_IDsMtx->lock();
85 int ID=0;
86 bool found=true;
87 while(ID<511)
88 {
89 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
90 {
91 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
92 }
93 if(found==true)break;
94 ID++;
95 found = true;
96 }
97 if(found)
98 {
99 RMAP_pending_transaction_IDs.append(ID);
100 }
101 this->RMAP_pending_transaction_IDsMtx->unlock();
102 return ID;
103 }
104
105 int abstractSpwManager::getRMAPanswer(int transactionID, char **buffer)
106 {
107
108 QTime timeout;
109 *buffer=NULL;
110 int count=0;
111 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
112 timeout.start();
113 while (*buffer==NULL)
114 {
115 this->RMAP_AnswersMtx->lock();
116 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
117 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
118 for(int i=0;i<RMAP_Answers.count();i++)
119 {
120 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
121 if(RMAP_Answers[i]->transactionID==transactionID)
122 {
123 this->RMAP_pending_transaction_IDsMtx->lock();
124 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
125 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
126 {
127 if(RMAP_pending_transaction_IDs[j]==transactionID)
128 {
129 RMAP_pending_transaction_IDs.removeAt(j);
130 }
131 }
132 this->RMAP_pending_transaction_IDsMtx->unlock();
133 *buffer = RMAP_Answers[i]->data;
134 count = RMAP_Answers[i]->len;
135 RMAP_Answer* tmp=RMAP_Answers[i];
136 RMAP_Answers.removeAt(i);
137 delete tmp;
138 }
139 }
140 this->RMAP_AnswersMtx->unlock();
141 //if no answer found in the stack wait until a new packet is pushed
142 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
143 if(*buffer==NULL)
144 {
145 while (0==this->RMAP_AnswersSem->available())
146 {
147 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
148 if(timeout.elapsed()>=RMAPtimeout)
149 {
150 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
151 return -1;
152 }
153 usleep(1000);
154 }
155 this->RMAP_AnswersSem->acquire();
156 }
157 }
158 return count;
159 }
160
161 int abstractSpwManager::getLinkNumber()
162 {
163 return this->linkNumber;
164 }
165
166 void abstractSpwManager::pushRmapPacket(char *packet, int len)
167 {
168 char* packetbuffer = (char*)malloc(len);
169 memcpy(packetbuffer,packet,len);
170 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
171 RMAP_AnswersMtx->lock();
172 RMAP_Answers.append(RMPAPpacket);
173 RMAP_AnswersMtx->unlock();
174 }
175
176
@@ -23,6 +23,9
23 #define ABSTRACTSPWBRIDGE_H
23 #define ABSTRACTSPWBRIDGE_H
24
24
25 #include <QObject>
25 #include <QObject>
26 #include <QThread>
27 #include <QMutex>
28 #include <QSemaphore>
26 #include <socexplorerplugin.h>
29 #include <socexplorerplugin.h>
27 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
30 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
28 #include <spw.h>
31 #include <spw.h>
@@ -65,4 +68,43 private:
65
68
66 };
69 };
67
70
71 class abstractSpwManager: public QThread
72 {
73 Q_OBJECT
74 public:
75 explicit abstractSpwManager(socexplorerplugin *plugin = 0,QObject* parent=0);
76 ~abstractSpwManager();
77 virtual void run(){}
78 virtual bool connectBridge()=0;
79 virtual bool disconnectBridge()=0;
80 int getRMAPtransactionID();
81 int getRMAPanswer(int transactionID,char** buffer);
82 virtual bool sendPacket(char* packet,int size)=0;
83 int RMAPtimeout;
84 int linkNumber;
85 int sourceLogicalAddress;
86 int destinationLogicalAddress;
87 int destinationKey;
88 signals:
89 void emitPacket(char* packet,int size);
90 void bytesReceivedFromSpw( unsigned int );
91 void bytesTransmittedToSpw( unsigned int);
92 void ccsdsPacketTransmittedToSpw( void );
93
94 public slots:
95 int getLinkNumber();
96
97 protected:
98 QList<RMAP_Answer*> RMAP_Answers;
99 QList<int> RMAP_pending_transaction_IDs;
100 QMutex *handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
101 QSemaphore* RMAP_AnswersSem;
102 socexplorerplugin* plugin;
103 bool connected;
104 void pushRmapPacket(char* packet,int len);
105
106 };
107
108
109
68 #endif // ABSTRACTSPWBRIDGE_H
110 #endif // ABSTRACTSPWBRIDGE_H
General Comments 0
You need to be logged in to leave comments. Login now