##// END OF EJS Templates
changes on the gresb class, object ready for usage in the rmapplugin
leroy -
r7:7c1589fec151 default
parent child
Show More
@@ -1,6 +1,6
1 1 #############################################################################
2 2 # Makefile for building: PAULs_LPPMON_PLUGINS
3 # Generated by qmake (2.01a) (Qt 4.8.3) on: Mon Dec 10 08:08:24 2012
3 # Generated by qmake (2.01a) (Qt 4.8.3) on: Mon Dec 10 09:02:30 2012
4 4 # Project: PAULs_LPPMON_PLUGINS.pro
5 5 # Template: subdirs
6 6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile PAULs_LPPMON_PLUGINS.pro
@@ -1,6 +1,6
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <!DOCTYPE QtCreatorProject>
3 <!-- Written by Qt Creator 2.4.1, 2012-12-10T08:45:27. -->
3 <!-- Written by Qt Creator 2.4.1, 2012-12-10T13:26:06. -->
4 4 <qtcreator>
5 5 <data>
6 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -1,6 +1,6
1 1 #############################################################################
2 2 # Makefile for building: librmapplugin.so.1.0.0
3 # Generated by qmake (2.01a) (Qt 4.8.3) on: Mon Dec 10 08:08:25 2012
3 # Generated by qmake (2.01a) (Qt 4.8.3) on: Mon Dec 10 09:02:30 2012
4 4 # Project: rmapplugin.pro
5 5 # Template: lib
6 6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile rmapplugin.pro
@@ -266,6 +266,7 moc/moc_rmappluginui.cpp: rmapoperations
266 266 spectralmatricesdmasimulator.h \
267 267 stardundee.h \
268 268 gresb.h \
269 spwpacketreceiver.h \
269 270 rmappluginui.h
270 271 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) rmappluginui.h -o moc/moc_rmappluginui.cpp
271 272
@@ -274,8 +275,8 moc/moc_rmapplugin.cpp: rmappluginui.h \
274 275 spectralmatricesdmasimulator.h \
275 276 stardundee.h \
276 277 gresb.h \
278 spwpacketreceiver.h \
277 279 ccsds.h \
278 spwpacketreceiver.h \
279 280 rmapplugin.h
280 281 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) rmapplugin.h -o moc/moc_rmapplugin.cpp
281 282
@@ -298,7 +299,9 moc/moc_stardundee.cpp: rmapoperations.h
298 299 stardundee.h
299 300 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) stardundee.h -o moc/moc_stardundee.cpp
300 301
301 moc/moc_gresb.cpp: gresb.h
302 moc/moc_gresb.cpp: spwpacketreceiver.h \
303 rmapoperations.h \
304 gresb.h
302 305 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) gresb.h -o moc/moc_gresb.cpp
303 306
304 307 moc/moc_bridge.cpp: bridge.h
@@ -335,8 +338,8 obj/rmapplugin.o: rmapplugin.cpp rmapplu
335 338 spectralmatricesdmasimulator.h \
336 339 stardundee.h \
337 340 gresb.h \
341 spwpacketreceiver.h \
338 342 ccsds.h \
339 spwpacketreceiver.h \
340 343 rmappluginpythonwrapper.h
341 344 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/rmapplugin.o rmapplugin.cpp
342 345
@@ -346,8 +349,8 obj/rmappluginui.o: rmappluginui.cpp rma
346 349 spectralmatricesdmasimulator.h \
347 350 stardundee.h \
348 351 gresb.h \
349 ccsds.h \
350 spwpacketreceiver.h
352 spwpacketreceiver.h \
353 ccsds.h
351 354 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/rmappluginui.o rmappluginui.cpp
352 355
353 356 obj/rmapoperations.o: rmapoperations.cpp rmapoperations.h
@@ -376,7 +379,9 obj/stardundee.o: stardundee.cpp stardun
376 379 rmapoperations.h
377 380 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/stardundee.o stardundee.cpp
378 381
379 obj/gresb.o: gresb.cpp gresb.h
382 obj/gresb.o: gresb.cpp gresb.h \
383 spwpacketreceiver.h \
384 rmapoperations.h
380 385 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/gresb.o gresb.cpp
381 386
382 387 obj/bridge.o: bridge.cpp bridge.h
@@ -8,8 +8,12 gresb::gresb(QWidget *parent) :
8 8 RMAPSend_SOCKET = new QTcpSocket;
9 9 RMAPReceive_SOCKET = new QTcpSocket;
10 10 GRESBStatusQuery_SOCKET = new QTcpSocket;
11 spwPacketReceiverOBJECT = new spwpacketreceiver;
12 spwPacketReceiverOBJECT->gresbReceptionSocket = RMAPReceive_SOCKET;
11
12 rmapPacket = (char*) malloc(RMAP_MAX_PACKET_LENGTH);
13 ccsdsPacket = (unsigned char*) malloc(CCSDS_MAX_PACKET_LENGTH);
14 spwPacket = (char*) malloc( qMax(RMAP_MAX_PACKET_LENGTH, CCSDS_MAX_PACKET_LENGTH) );
15
16 commandCode = invalid0; // initialization of the command code for the RMAP transfers
13 17
14 18 //*** QLABEL ***//
15 19 gresbBridgeIPLabel = new QLabel(tr("GRESB Bridge IP: "));
@@ -69,6 +73,442 gresb::gresb(QWidget *parent) :
69 73 this->setLayout(connectionLayout);
70 74
71 75 connect(gresbStatusQueryAbortButton, SIGNAL(clicked()), gresbStatusQueryDialog, SLOT(reject()));
76 connect(this->RMAPReceive_SOCKET, SIGNAL(readyRead()), this, SLOT(receiveSPWPacket()));
77 }
78
79 gresb::~gresb()
80 {
81 free(rmapPacket);
82 free(ccsdsPacket);
83 free(spwPacket);
84 }
85
86 unsigned int gresb::Write(unsigned int *Value, unsigned int count, unsigned int address)
87 {
88 unsigned int remainingCount = count;
89 unsigned int iOffset = 0;
90 QString console_message;
91 char* data;
92
93 if(rmapPacketSEMAPHORE->available()!=0)
94 {
95 emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP request already running, WRITE access stopped");
96 return 1;
97 }
98
99 RMAP_write_reply_setText("reply to the write command required\nlast reply status: unavailable");
100
101 data = (char*) malloc(READ_WRITE_MAX_COUNTS*4);
102
103 emit appendToLog(QString("*** START *** WRITE ")+ QString::number(count) + QString(" word(s) @0x")+ QString::number(address,16));
104
105 while (remainingCount > READ_WRITE_MAX_COUNTS)
106 {
107 for (int i = 0; i<READ_WRITE_MAX_COUNTS; i++)
108 {
109 data[i*4+3] = (char) ((unsigned int) Value[i+iOffset]);
110 data[i*4+2] = (char) ((unsigned int) Value[i+iOffset]>>8);
111 data[i*4+1] = (char) ((unsigned int) Value[i+iOffset]>>16);
112 data[i*4+0] = (char) ((unsigned int) Value[i+iOffset]>>24);
113 }
114
115 console_message.sprintf("remainingCount: %d => ", remainingCount);
116 emit appendToLog(console_message + QString("Write ")+ QString::number(READ_WRITE_MAX_COUNTS*4) + QString(" byte(s) @0x")+ QString::number(address,16));
117
118 if(WriteBLOCK(data, READ_WRITE_MAX_COUNTS*4, address)==0)
119 {
120 emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP write command failed");
121 return 1;
122 }
123
124 remainingCount = remainingCount - READ_WRITE_MAX_COUNTS;
125 address = address + READ_WRITE_MAX_COUNTS * 4;
126 iOffset = iOffset + READ_WRITE_MAX_COUNTS;
127 }
128
129 if (remainingCount > 0)
130 {
131 for (unsigned int i = 0; i<remainingCount; i++)
132 {
133 data[i*4+3] = (char) ((unsigned int) Value[i+iOffset]);
134 data[i*4+2] = (char) ((unsigned int) Value[i+iOffset]>>8);
135 data[i*4+1] = (char) ((unsigned int) Value[i+iOffset]>>16);
136 data[i*4+0] = (char) ((unsigned int) Value[i+iOffset]>>24);
137 }
138
139 console_message.sprintf("remainingCount: %d => ", remainingCount);
140 emit appendToLog(console_message + QString("Write ")+ QString::number(remainingCount*4) + QString(" byte(s) @0x")+ QString::number(address,16));
141
142 if (WriteBLOCK(data, remainingCount*4, address)==0)
143 {
144 emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP write command failed");
145 return 1;
146 }
147 }
148
149 emit appendToLog(QString("*** STOP *** WRITE"));
150 free(data);
151 return count;
152 }
153
154 unsigned int gresb::Read(unsigned int *Value, unsigned int count, unsigned int address)
155 {
156 unsigned int remainingCount = count;
157 unsigned int iOffset = 0;
158 QString console_message;
159
160 if(rmapPacketSEMAPHORE->available()!=0)
161 {
162 emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP request already running, READ access stopped");
163 return 1;
164 }
165 emit appendToLog(QString("*** START *** READ ")+ QString::number(count) + QString(" word(s) @0x")+ QString::number(address,16));
166
167 while (remainingCount > READ_WRITE_MAX_COUNTS)
168 {
169 console_message.sprintf("remainingCount: %d => ", remainingCount);
170 emit appendToLog(console_message + QString("Read ")+ QString::number(4*READ_WRITE_MAX_COUNTS) + QString(" byte(s) @0x")+ QString::number(address,16));
171
172 if (ReadBLOCK(READ_WRITE_MAX_COUNTS*4, address)==0)
173 {
174 emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP packet not received");
175 return 1;
176 }
177
178 for(int i=0;i<READ_WRITE_MAX_COUNTS;i++)
179 {
180 Value[i+iOffset] = (unsigned char) rmapPacket[i*4+RMAP_READ_REPLY_HEADER_LENGTH];
181 for(int j=1;j<4;j++)
182 {
183 Value[i+iOffset]= ((unsigned char)(rmapPacket[i*4+j+RMAP_READ_REPLY_HEADER_LENGTH])) + Value[i+iOffset]*256;
184 }
185 }
186
187 remainingCount = remainingCount - READ_WRITE_MAX_COUNTS;
188 address = address + READ_WRITE_MAX_COUNTS * 4;
189 iOffset = iOffset + READ_WRITE_MAX_COUNTS;
190 acquireRMAPSemaphore();
191 }
192
193 if (remainingCount > 0)
194 {
195 console_message.sprintf("remainingCount: %d => ", remainingCount);
196 emit appendToLog(console_message + QString("Read ")+ QString::number(4*remainingCount) + QString(" byte(s) @0x")+ QString::number(address,16));
197
198 if (ReadBLOCK(4*remainingCount, address)==0)
199 {
200 emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP packet not received");
201 return 1;
202 }
203
204 for(unsigned int i=0;i<remainingCount;i++)
205 {
206 Value[i+iOffset] = (unsigned char) rmapPacket[i*4+RMAP_READ_REPLY_HEADER_LENGTH];
207 for(int j=1;j<4;j++)
208 {
209 Value[i+iOffset]= ((unsigned char)(rmapPacket[i*4+j+RMAP_READ_REPLY_HEADER_LENGTH])) + Value[i+iOffset]*256;
210 }
211 }
212 acquireRMAPSemaphore();
213 }
214
215 emit appendToLog(QString("*** STOP *** READ "));
216 return count;
217 }
218
219 unsigned int gresb::WriteBLOCK(char *data, unsigned int nbBytes, unsigned int address)
220 {
221 QTime RMAPTimeout;
222 RMAP *RMAPCommand;
223 int errorCode;
224 QString console_message;
225
226 if (GRESBStatusQueryRequest(LinkStatus, spwLinkSpinBox->value()) == 1)
227 {
228 this->Close();
229 return 1;
230 }
231
232 RMAPCommand = new RMAP(commandCode,
233 rmapTargetLogicalAddress,
234 rmapSourceLogicalAddress,
235 address,
236 nbBytes,
237 data);
238
239 // SEND GRESB HEADER
240 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->GRESBHeader), 4);
241 // SEND SPACEWIRE PACKET HEADER
242 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->RMAPHeader), sizeof(RMAPCommand->RMAPHeader));
243 // SEND DATA
244 RMAPSend_SOCKET->write( data, nbBytes);
245 // SEND DATA CRC
246 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->dataCRC), 1);
247 RMAPTimeout.start();
248 while(RMAPSend_SOCKET->bytesToWrite() > 0)
249 {
250 RMAPSend_SOCKET->waitForBytesWritten(100);
251 if(RMAPTimeout.elapsed()>1000)
252 {
253 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** sending Write RMAP Command timeout");
254 return 0;
255 }
256 }
257
258 if ( (commandCode == writeSingle_noVer_Rep) | (commandCode == writeInc_noVer_Rep) |
259 (commandCode == writeSingle_ver_rep) | (commandCode == writeInc_ver_rep) )
260 {
261 // WAIT FOR THE RMAP REPLY PACKET
262 errorCode = receiveSPWPacket(1);
263 if (errorCode<=0)
264 {
265 emit appendToLog("WARNING === in function WriteBLOCK of rmapplugin *** RMAP packet reception failed with code " + QString::number(errorCode));
266 return 0;
267 }
268 if(rmapPacketSize != 8)
269 {
270 console_message.sprintf("WARNING === in function WRITE (with reply) of rmapplugin *** write reply format not compliant\n");
271 emit appendToLog(console_message);
272 return 0;
273 }
274 switch (rmapPacket[3]) // byte 4 is the status byte in the reply
275 {
276 case 0:
277 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 0 Successfull");
278 break;
279 case 1:
280 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** General error code");
281 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 1 General error code");
282 break;
283 case 2:
284 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Unused RMAP packet type or command code");
285 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 2 Unused RMAP packet type or command code");
286 break;
287 case 3:
288 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Invalid key");
289 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 3 Invalid key");
290 break;
291 case 4:
292 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Invalid data CRC");
293 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 4 Invalid data CRC");
294 break;
295 case 5:
296 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Early EOP");
297 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 5 Early EOP");
298 break;
299 case 6:
300 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Too much data");
301 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 6 Too much data");
302 break;
303 case 7:
304 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** EEP");
305 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 7 EEP");
306 break;
307 case 8:
308 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Reserved");
309 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 8 Reserved");
310 break;
311 case 9:
312 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Verify buffer overrun");
313 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 9 Verify buffer overrun");
314 break;
315 case 10:
316 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** RMAP command not implemented or not authorised");
317 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 10 RMAP command not implemented or not authorised");
318 break;
319 case 11:
320 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** RMW data length error");
321 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 11 RMAP RMW data length error");
322 break;
323 case 12:
324 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Invalid target logical address");
325 RMAP_write_reply_setText("reply to the write command required\nlast reply status: 12 Invalid target logical address");
326 break;
327 }
328 acquireRMAPSemaphore();
329 }
330 return nbBytes;
331 }
332
333 unsigned int gresb::ReadBLOCK(unsigned int nbBytes, unsigned int address)
334 {
335 int errorCode;
336 RMAP *RMAPCommand;
337 QTime RMAPTimeout;
338 unsigned int dataLength;
339 if (GRESBStatusQueryRequest(LinkStatus, spwLinkSpinBox->value()) == 1)
340 {
341 this->Close();
342 return 1;
343 }
344
345 if (nbBytes > 4)
346 {
347 RMAPCommand = new RMAP(read_Inc,
348 rmapTargetLogicalAddress,
349 rmapSourceLogicalAddress,
350 address,
351 nbBytes,
352 NULL);
353 }
354 else
355 {
356 RMAPCommand = new RMAP(read_Single,
357 rmapTargetLogicalAddress,
358 rmapSourceLogicalAddress,
359 address,
360 nbBytes,
361 NULL);
362 }
363
364 // SEND THE GRESB HEADER FOR THE RMAP READ COMMAND
365 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->GRESBHeader), 4);
366 // SEND THE SPACEWIRE PACKET FOR THE RMAP READ COMMAND
367 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->RMAPHeader), sizeof(RMAPCommand->RMAPHeader));
368 RMAPSend_SOCKET->waitForBytesWritten(100);
369 RMAPTimeout.start();
370 // write timeout
371 while(RMAPSend_SOCKET->bytesToWrite() > 0)
372 {
373 RMAPSend_SOCKET->waitForBytesWritten(100);
374 if(RMAPTimeout.elapsed()>1000)
375 {
376 emit appendToLog("WARNING === in function READ of rmapplugin *** sending Read RMAP Command timeout\n");
377 return 0;
378 }
379 }
380
381 // RECEIVE THE INCOMING RMAP PACKET
382 errorCode = receiveSPWPacket(1); // request ID 1 is for RMAP packet
383 if (errorCode<=0)
384 {
385 emit appendToLog("WARNING === in function ReadBLOCK of rmapplugin *** RMAP packet reception failed with code " + QString::number(errorCode));
386 return 0;
387 }
388 dataLength = rmapPacketSize - RMAP_READ_REPLY_HEADER_LENGTH - RMAP_DATA_CRC_LENGTH;
389 if(dataLength != nbBytes)
390 {
391 emit appendToLog("WARNING === in function READ of rmapplugin *** number of data received ("
392 +QString::number(dataLength)
393 +") not equal to number of data requested ("
394 +QString::number(READ_WRITE_MAX_COUNTS*4)
395 +")");
396 return 0;
397 }
398 return dataLength;
399 }
400
401 unsigned int gresb::WriteSPW(char *Value, unsigned int count, char targetLogicalAddress, char userApplication)
402 {
403 char protocoleIdentifier = 0x02;
404 char reserved = 0x00;
405 char gresbProtocole = 0x00;
406 unsigned char size[3];
407 unsigned int spwPacketSize = count + 4;
408 QTime SPWTimeout;
409
410 if (count>248)
411 {
412 appendToLog("WARNING === in function WRITE of rmapplugin *** CCSDS packet size > 248 bytes\n");
413 return 1;
414 }
415
416 appendToLog(QString("*** START *** Send CCSDS packet of ")+ QString::number(count) + QString(" byte(s)"));
417
418 if (GRESBStatusQueryRequest(LinkStatus, spwLinkSpinBox->value()) == 1)
419 {
420 this->Close();
421 appendToLog("WARNING === in function WRITE of rmapplugin *** SPW link not running\n");
422 return 1;
423 }
424
425 // SEND GRESB HEADER
426 size[0] = (unsigned char) ((unsigned int) spwPacketSize>>16);
427 size[1] = (unsigned char) ((unsigned int) spwPacketSize>>8);
428 size[2] = (unsigned char) ((unsigned int) spwPacketSize);
429 RMAPSend_SOCKET->write(&gresbProtocole, 1);
430 RMAPSend_SOCKET->write((char*) size, 3);
431 // SEND SPW HEADER
432 RMAPSend_SOCKET->write(&targetLogicalAddress, 1);
433 RMAPSend_SOCKET->write(&protocoleIdentifier, 1);
434 RMAPSend_SOCKET->write(&reserved, 1);
435 RMAPSend_SOCKET->write(&userApplication, 1);
436 // SEND CCSDS PACKET
437 RMAPSend_SOCKET->write(Value, count);
438 SPWTimeout.start();
439 while(RMAPSend_SOCKET->bytesToWrite() > 0)
440 {
441 RMAPSend_SOCKET->waitForBytesWritten(100);
442 if(SPWTimeout.elapsed()>1000)
443 {
444 appendToLog("WARNING === in function WRITE of rmapplugin *** sending CCSDS packet timeout\n");
445 return 1;
446 }
447 }
448
449 appendToLog(QString("*** CCSDS packet sent"));
450
451 return count;
452 }
453
454 int gresb::receiveSPWPacket(unsigned char requestID) // SLOT
455 {
456 QTime spwPacketReceiverTimeout;
457 // GRESB HEADER
458 char RES_TR_EP; // 6 bits REserved + 1 bit TRuncated + 1 bit EP error end of packet
459 unsigned char packetLength2;
460 unsigned char packetLength1;
461 unsigned char packetLength0;
462 unsigned int packetLength;
463
464 if (requestID==1)
465 {
466 if (rmapPacketSEMAPHORE->available()) return rmapPacketSize;
467 }
468
469 RMAPReceive_SOCKET->blockSignals(1); // block the signals of the socket during packet reception
470 // READ THE GRESB HEADER OF THE INCOMING PACKET
471 spwPacketReceiverTimeout.start();
472 while(RMAPReceive_SOCKET->bytesAvailable() < 4)
473 {
474 RMAPReceive_SOCKET->waitForReadyRead(100);
475 if(spwPacketReceiverTimeout.elapsed()>1000) return -1; // ERROR === read GRSEB header TIMEOUT
476 }
477 RMAPReceive_SOCKET->read(&RES_TR_EP, 1);
478 RMAPReceive_SOCKET->read( (char*) &packetLength2, 1);
479 RMAPReceive_SOCKET->read( (char*) &packetLength1, 1);
480 RMAPReceive_SOCKET->read( (char*) &packetLength0, 1);
481 packetLength = (packetLength2<<16) + (packetLength1<<8) + (packetLength0);
482 spwPacket = (char*) malloc(packetLength);
483
484 // READ THE SPW PACKET
485 while(RMAPReceive_SOCKET->bytesAvailable() < packetLength)
486 {
487 RMAPReceive_SOCKET->waitForReadyRead(100);
488 if(spwPacketReceiverTimeout.elapsed()>1000) return -2; // ERROR === read SPW packet TIMEOUT
489 }
490 RMAPReceive_SOCKET->read( spwPacket, packetLength );
491 RMAPReceive_SOCKET->blockSignals(0);
492
493 switch(spwPacket[1]) // byte 1 is the protocole identifier in the SPW packet
494 {
495 case 1: // 0x01 is the protocole identifier for RMAP packets
496 if (rmapPacketSEMAPHORE->available()!=0) return -3; // ERROR === previous RMAP packet not processed yet
497 for(unsigned int i=0; i<packetLength; i++) rmapPacket[i] = spwPacket[i];
498 rmapPacketSize = packetLength;
499 rmapPacketSEMAPHORE->release();
500 //emit sendMessage("RMAP packet of size " + QString::number(packetLength) + " received");
501 return packetLength;
502
503 case 2: // 0x02 is the protocole identifier for CCSDS packets
504 if (ccsdsPacketSEMAPHORE->available()!=0) return -4; // ERROR === previous CCSDS packet not processed yet
505 for(unsigned int i=0; i<packetLength; i++) ccsdsPacket[i] = spwPacket[i];
506 ccsdsPacketSize = packetLength;
507 ccsdsPacketSEMAPHORE->release();
508 emit(ccsdsPacketAvailable(ccsdsPacket, packetLength));
509 return packetLength;
510 }
511 return 0;
72 512 }
73 513
74 514 void gresb::Open() // SLOT
@@ -86,8 +526,8 void gresb::Open() // SLOT
86 526 GRESBStatusQuery_SOCKET->waitForConnected(10000);
87 527 RMAPReceive_SOCKET->readAll(); // read all remaining data from the reception socket
88 528 // initialize SPW packet semaphores
89 while (spwPacketReceiverOBJECT->rmapPacketSEMAPHORE->available()!=0) spwPacketReceiverOBJECT->rmapPacketSEMAPHORE->acquire();
90 while (spwPacketReceiverOBJECT->ccsdsPacketSEMAPHORE->available()!=0) spwPacketReceiverOBJECT->ccsdsPacketSEMAPHORE->acquire();
529 while (rmapPacketSEMAPHORE->available()!=0) rmapPacketSEMAPHORE->acquire();
530 while (ccsdsPacketSEMAPHORE->available()!=0) ccsdsPacketSEMAPHORE->acquire();
91 531 if (GRESBStatusQueryRequest(LinkStatus, spwLinkSpinBox->value()) != 0)
92 532 {
93 533 spwRunning = gresbStatusQueryDialog->exec();
@@ -213,3 +653,35 int gresb::GRESBStatusQueryRequest(Gresb
213 653 }
214 654 return 0;
215 655 }
656
657 void gresb::processCCSDSPacket(unsigned char *ccsdsPacket, unsigned int size) // SLOT
658 {
659 QString message;
660 unsigned int fine_time_value = 0;
661 fine_time_value = ((unsigned int) ccsdsPacket[7]<<24)
662 + ((unsigned int) ccsdsPacket[6]<<16)
663 + ((unsigned int) ccsdsPacket[5]<<8)
664 + ((unsigned int) ccsdsPacket[4]);
665 message.append(QTime::currentTime().toString() +":" + QString::number(QTime::currentTime().msec()) + ": ");
666 message.append("size "
667 + QString::number(size)
668 +" *** header "
669 + QString::number(ccsdsPacket[0], 16)
670 + " "
671 + QString::number(ccsdsPacket[1], 16)
672 + " "
673 + QString::number(ccsdsPacket[2], 16)
674 + " "
675 + QString::number(ccsdsPacket[3], 16)
676 + " *** coarse time "
677 + QString::number(fine_time_value));
678 //+ QString::number(ccsdsPacket[4], 16)
679 //+" "
680 //+ QString::number(ccsdsPacket[5], 16)
681 //+" "
682 //+ QString::number(ccsdsPacket[6], 16)
683 //+" "
684 //+ QString::number(ccsdsPacket[7], 16));
685 ccsdsPacketSEMAPHORE->acquire();
686 emit sendMessage(message);
687 }
@@ -8,6 +8,7
8 8 #include <QGridLayout>
9 9 #include <QTcpSocket>
10 10 #include <QDialog>
11 #include <QSemaphore>
11 12
12 13 #include "gresbstatusenquiry.h"
13 14 #include "spwpacketreceiver.h"
@@ -23,7 +24,7 public:
23 24 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
24 25 unsigned int Read(unsigned int *Value,unsigned int count,unsigned int address=0);
25 26 unsigned int WriteSPW(char *Value, unsigned int count, char targetLogicalAddress, char userApplication);
26 unsigned int getLinkStatus(unsigned char link);
27 //unsigned int getLinkStatus(unsigned char link);
27 28
28 29 signals:
29 30 void sendMessage(QString message);
@@ -35,7 +36,8 signals:
35 36 public slots:
36 37 void Open();
37 38 void Close();
38 int receiveSPWPacket(unsigned char requestID);
39 int receiveSPWPacket(unsigned char requestID=0);
40 void processCCSDSPacket(unsigned char *ccsdsPacket, unsigned int size);
39 41 void commandCodeHasChanged(RMAP_command_codes code) {this->commandCode = code;}
40 42 void targetHasChanged(int target) {rmapTargetLogicalAddress = (unsigned char) target;}
41 43 void sourceHasChanged(int target) {rmapSourceLogicalAddress = (unsigned char) target;}
@@ -44,6 +46,10 private slots:
44 46 int GRESBStatusQuery();
45 47
46 48 private:
49 unsigned int WriteBLOCK(char *data,unsigned int nbBytes,unsigned int address=0);
50 unsigned int ReadBLOCK(unsigned int nbBytes,unsigned int address=0);
51 void acquireRMAPSemaphore() {rmapPacketSEMAPHORE->acquire();}
52 void acquireCCSDSSemaphore() {ccsdsPacketSEMAPHORE->acquire();}
47 53 int GRESBStatusQueryRequest(GresbStatusQueryOption option, char link);
48 54
49 55 unsigned char rmapTargetLogicalAddress ;
@@ -78,9 +84,16 private:
78 84 QTcpSocket *RMAPReceive_SOCKET;
79 85 QTcpSocket *GRESBStatusQuery_SOCKET;
80 86
81 spwpacketreceiver *spwPacketReceiverOBJECT;
87 gresbStatusEnquiry* spwLinkStatusEnquiry;
82 88
83 gresbStatusEnquiry* spwLinkStatusEnquiry;
89 // Packet receiver
90 QSemaphore *rmapPacketSEMAPHORE;
91 QSemaphore *ccsdsPacketSEMAPHORE;
92 char* rmapPacket; // The buffer to receive RMAP READ packets
93 unsigned char *ccsdsPacket;
94 char *spwPacket;
95 unsigned int rmapPacketSize;
96 unsigned int ccsdsPacketSize;
84 97 };
85 98
86 99 #endif // GRESB_H
@@ -137,6 +137,7 rmapPluginUI::rmapPluginUI(QWidget *pare
137 137 generalParameters_LAYOUT->setColumnStretch(2, 1);
138 138
139 139 gresb_GROUPBOX->setLayout(connectionLayout);
140 //gresb_GROUPBOX->setLayout(gresbBridge->layout());
140 141 gresb_GROUPBOX->setVisible(false);
141 142 stardundee_GROUPBOX->setLayout(starDundee->layout());
142 143 stardundee_GROUPBOX->setVisible(false);
@@ -199,21 +200,6 rmapPluginUI::rmapPluginUI(QWidget *pare
199 200 rmapTargetLogicalAddressSpinBox->setValue(254);
200 201 }
201 202
202 void rmapPluginUI::connectPort()
203 {
204 //emit this->connectPortsig(ui->PortName->text(),ui->PortspeedSlider->value());
205 }
206
207 void rmapPluginUI::setConnected(bool connected)
208 {
209 /*if(connected == true)
210 {
211 ui->OpenPort->setText(tr("Close port"));
212 }
213 else
214 ui->OpenPort->setText(tr("Open port"));*/
215 }
216
217 203 rmapPluginUI::~rmapPluginUI()
218 204 {
219 205 //delete ui;
@@ -110,8 +110,6 public:
110 110 void closeEvent(QCloseEvent *event);
111 111
112 112 public slots:
113 void setConnected(bool connected);
114 void connectPort();
115 113 void chooseLogFile();
116 114 void logFileEnDisable(int state);
117 115 RMAP_command_codes getCommandCode();
@@ -80,23 +80,7 int spwpacketreceiver::receiveSPWPacket(
80 80 return 0;
81 81 }
82 82
83 bool spwpacketreceiver::isRMAPPacketSemaphoreAvailable()
84 {
85 if (rmapPacketSEMAPHORE->available()!=0) return true;
86 return false;
87 }
88
89 void spwpacketreceiver::acquireRMAPSemaphore()
90 {
91 rmapPacketSEMAPHORE->acquire();
92 }
93
94 void spwpacketreceiver::acquireCCSDSSemaphore()
95 {
96 ccsdsPacketSEMAPHORE->acquire();
97 }
98
99 void spwpacketreceiver::processCCSDSPacket(unsigned char *ccsdsPacket, unsigned int size)
83 void spwpacketreceiver::processCCSDSPacket(unsigned char *ccsdsPacket, unsigned int size) // SLOT
100 84 {
101 85 QString message;
102 86 unsigned int fine_time_value = 0;
@@ -127,4 +111,3 void spwpacketreceiver::processCCSDSPack
127 111 ccsdsPacketSEMAPHORE->acquire();
128 112 emit sendMessage(message);
129 113 }
130
@@ -11,9 +11,8 public:
11 11 explicit spwpacketreceiver(QObject *parent = 0);
12 12 ~spwpacketreceiver();
13 13 int fetchRMAPPacket();
14 void acquireRMAPSemaphore();
15 void acquireCCSDSSemaphore();
16 bool isRMAPPacketSemaphoreAvailable();
14 void acquireCCSDSSemaphore() {ccsdsPacketSEMAPHORE->acquire();}
15 void acquireRMAPSemaphore() {rmapPacketSEMAPHORE->acquire();}
17 16
18 17 unsigned char* ccsdsPacket;
19 18 char* rmapPacket;
@@ -40,13 +40,14 public slots:
40 40 void sourceHasChanged(int target) {rmapSourceLogicalAddress = (unsigned char) target;}
41 41
42 42 private:
43 unsigned int getLinkStatus(unsigned char link);
44 unsigned int GetRoutingTableEntry();
45 43 unsigned int WriteBLOCK(char *data,unsigned int nbBytes,unsigned int address=0);
46 44 unsigned int ReadBLOCK(unsigned int nbBytes,unsigned int address=0);
47 45 void acquireRMAPSemaphore() {rmapPacketSEMAPHORE->acquire();}
48 46 void acquireCCSDSSemaphore() {ccsdsPacketSEMAPHORE->acquire();}
49 47
48 unsigned int getLinkStatus(unsigned char link);
49 unsigned int GetRoutingTableEntry();
50
50 51 unsigned char rmapTargetLogicalAddress ;
51 52 unsigned char rmapSourceLogicalAddress ;
52 53
General Comments 0
You need to be logged in to leave comments. Login now