##// END OF EJS Templates
First version with the Star Dundee bridge operational
paul@pc-solar1.lab-lpp.local -
r1:45ff379330d3 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: Thu Nov 29 09:03:10 2012
3 # Generated by qmake (2.01a) (Qt 4.8.3) on: Thu Nov 29 14:02:20 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-11-29T13:08:48. -->
3 <!-- Written by Qt Creator 2.4.1, 2012-12-06T08:47:47. -->
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: Thu Nov 29 09:38:20 2012
3 # Generated by qmake (2.01a) (Qt 4.8.3) on: Mon Dec 3 13:45:43 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
@@ -16,7 +16,7 CXXFLAGS = -pipe -O2 -g -pipe -Wall
16 16 INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtGui -I/usr/include -I. -I../common_PLE -I../spw_usb_driver_v2.61/inc -I/usr/include/lppmon/pluginsInterface -I/usr/include/PythonQt -Imoc
17 17 LINK = g++
18 18 LFLAGS = -Wl,-O1 -Wl,-z,relro -shared -Wl,-soname,librmapplugin.so.1
19 LIBS = $(SUBLIBS) -L/usr/lib64 ../spw_usb_driver_v2.61/lib/libSpaceWireUSBAPI.so -ldl -lutil -lm -lpython2.7 -lPythonQt_QtAll -lPythonQt -lQtGui -lQtNetwork -lQtCore -lpthread
19 LIBS = $(SUBLIBS) -L/usr/lib64 ../spw_usb_driver_v2.61/lib/x86_64/libSpaceWireUSBAPI.so ../spw_usb_driver_v2.61/lib/x86_64/libConfigLibraryUSB.so -ldl -lutil -lm -lpython2.7 -lPythonQt_QtAll -lPythonQt -lQtGui -lQtNetwork -lQtCore -lpthread
20 20 AR = ar cqs
21 21 RANLIB =
22 22 QMAKE = /usr/bin/qmake-qt4
@@ -53,6 +53,7 SOURCES = rmapplugin.cpp \
53 53 spectralmatricesdmasimulator.cpp \
54 54 rmappluginpythonwrapper.cpp \
55 55 stardundee.cpp \
56 gresb.cpp \
56 57 /usr/include/lppmon/pluginsInterface/lppmonplugininterface.cpp moc/moc_rmappluginui.cpp \
57 58 moc/moc_rmapplugin.cpp \
58 59 moc/moc_spwpacketreceiver.cpp \
@@ -61,6 +62,7 SOURCES = rmapplugin.cpp \
61 62 moc/moc_spectralmatricesdmasimulator.cpp \
62 63 moc/moc_rmappluginpythonwrapper.cpp \
63 64 moc/moc_stardundee.cpp \
65 moc/moc_gresb.cpp \
64 66 moc/moc_genericPySysdriver.cpp \
65 67 moc/moc_lppmonplugin.cpp
66 68 OBJECTS = obj/rmapplugin.o \
@@ -73,6 +75,7 OBJECTS = obj/rmapplugin.o \
73 75 obj/spectralmatricesdmasimulator.o \
74 76 obj/rmappluginpythonwrapper.o \
75 77 obj/stardundee.o \
78 obj/gresb.o \
76 79 obj/lppmonplugininterface.o \
77 80 obj/moc_rmappluginui.o \
78 81 obj/moc_rmapplugin.o \
@@ -82,6 +85,7 OBJECTS = obj/rmapplugin.o \
82 85 obj/moc_spectralmatricesdmasimulator.o \
83 86 obj/moc_rmappluginpythonwrapper.o \
84 87 obj/moc_stardundee.o \
88 obj/moc_gresb.o \
85 89 obj/moc_genericPySysdriver.o \
86 90 obj/moc_lppmonplugin.o
87 91 DIST = /usr/lib64/qt4/mkspecs/common/unix.conf \
@@ -229,7 +233,7 qmake: FORCE
229 233
230 234 dist:
231 235 @$(CHK_DIR_EXISTS) obj/rmapplugin1.0.0 || $(MKDIR) obj/rmapplugin1.0.0
232 $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/rmapplugin1.0.0/ && $(COPY_FILE) --parents rmappluginui.h rmapplugin.h rmapoperations.h ccsds.h spwpacketreceiver.h ../common_PLE/qipdialogbox.h ../common_PLE/gresbstatusenquiry.h spectralmatricesdmasimulator.h rmappluginpythonwrapper.h stardundee.h ../spw_usb_driver_v2.61/inc/spw_usb_api.h /usr/include/genericPySysdriver.h /usr/include/lppmonplugin.h obj/rmapplugin1.0.0/ && $(COPY_FILE) --parents rmapplugin.cpp rmappluginui.cpp rmapoperations.cpp ccsds.cpp spwpacketreceiver.cpp ../common_PLE/qipdialogbox.cpp ../common_PLE/gresbstatusenquiry.cpp spectralmatricesdmasimulator.cpp rmappluginpythonwrapper.cpp stardundee.cpp /usr/include/lppmon/pluginsInterface/lppmonplugininterface.cpp obj/rmapplugin1.0.0/ && (cd `dirname obj/rmapplugin1.0.0` && $(TAR) rmapplugin1.0.0.tar rmapplugin1.0.0 && $(COMPRESS) rmapplugin1.0.0.tar) && $(MOVE) `dirname obj/rmapplugin1.0.0`/rmapplugin1.0.0.tar.gz . && $(DEL_FILE) -r obj/rmapplugin1.0.0
236 $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/rmapplugin1.0.0/ && $(COPY_FILE) --parents rmappluginui.h rmapplugin.h rmapoperations.h ccsds.h spwpacketreceiver.h ../common_PLE/qipdialogbox.h ../common_PLE/gresbstatusenquiry.h spectralmatricesdmasimulator.h rmappluginpythonwrapper.h stardundee.h ../spw_usb_driver_v2.61/inc/spw_usb_api.h ../spw_usb_driver_v2.61/inc/spw_config_library.h gresb.h /usr/include/genericPySysdriver.h /usr/include/lppmonplugin.h obj/rmapplugin1.0.0/ && $(COPY_FILE) --parents rmapplugin.cpp rmappluginui.cpp rmapoperations.cpp ccsds.cpp spwpacketreceiver.cpp ../common_PLE/qipdialogbox.cpp ../common_PLE/gresbstatusenquiry.cpp spectralmatricesdmasimulator.cpp rmappluginpythonwrapper.cpp stardundee.cpp gresb.cpp /usr/include/lppmon/pluginsInterface/lppmonplugininterface.cpp obj/rmapplugin1.0.0/ && (cd `dirname obj/rmapplugin1.0.0` && $(TAR) rmapplugin1.0.0.tar rmapplugin1.0.0 && $(COMPRESS) rmapplugin1.0.0.tar) && $(MOVE) `dirname obj/rmapplugin1.0.0`/rmapplugin1.0.0.tar.gz . && $(DEL_FILE) -r obj/rmapplugin1.0.0
233 237
234 238
235 239 clean:compiler_clean
@@ -251,17 +255,19 mocclean: compiler_moc_header_clean comp
251 255
252 256 mocables: compiler_moc_header_make_all compiler_moc_source_make_all
253 257
254 compiler_moc_header_make_all: moc/moc_rmappluginui.cpp moc/moc_rmapplugin.cpp moc/moc_spwpacketreceiver.cpp moc/moc_qipdialogbox.cpp moc/moc_gresbstatusenquiry.cpp moc/moc_spectralmatricesdmasimulator.cpp moc/moc_rmappluginpythonwrapper.cpp moc/moc_stardundee.cpp moc/moc_genericPySysdriver.cpp moc/moc_lppmonplugin.cpp
258 compiler_moc_header_make_all: moc/moc_rmappluginui.cpp moc/moc_rmapplugin.cpp moc/moc_spwpacketreceiver.cpp moc/moc_qipdialogbox.cpp moc/moc_gresbstatusenquiry.cpp moc/moc_spectralmatricesdmasimulator.cpp moc/moc_rmappluginpythonwrapper.cpp moc/moc_stardundee.cpp moc/moc_gresb.cpp moc/moc_genericPySysdriver.cpp moc/moc_lppmonplugin.cpp
255 259 compiler_moc_header_clean:
256 -$(DEL_FILE) moc/moc_rmappluginui.cpp moc/moc_rmapplugin.cpp moc/moc_spwpacketreceiver.cpp moc/moc_qipdialogbox.cpp moc/moc_gresbstatusenquiry.cpp moc/moc_spectralmatricesdmasimulator.cpp moc/moc_rmappluginpythonwrapper.cpp moc/moc_stardundee.cpp moc/moc_genericPySysdriver.cpp moc/moc_lppmonplugin.cpp
260 -$(DEL_FILE) moc/moc_rmappluginui.cpp moc/moc_rmapplugin.cpp moc/moc_spwpacketreceiver.cpp moc/moc_qipdialogbox.cpp moc/moc_gresbstatusenquiry.cpp moc/moc_spectralmatricesdmasimulator.cpp moc/moc_rmappluginpythonwrapper.cpp moc/moc_stardundee.cpp moc/moc_gresb.cpp moc/moc_genericPySysdriver.cpp moc/moc_lppmonplugin.cpp
257 261 moc/moc_rmappluginui.cpp: rmapoperations.h \
258 262 spectralmatricesdmasimulator.h \
263 stardundee.h \
259 264 rmappluginui.h
260 265 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) rmappluginui.h -o moc/moc_rmappluginui.cpp
261 266
262 267 moc/moc_rmapplugin.cpp: rmappluginui.h \
263 268 rmapoperations.h \
264 269 spectralmatricesdmasimulator.h \
270 stardundee.h \
265 271 ccsds.h \
266 272 spwpacketreceiver.h \
267 273 rmapplugin.h
@@ -285,6 +291,9 moc/moc_rmappluginpythonwrapper.cpp: rma
285 291 moc/moc_stardundee.cpp: stardundee.h
286 292 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) stardundee.h -o moc/moc_stardundee.cpp
287 293
294 moc/moc_gresb.cpp: gresb.h
295 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) gresb.h -o moc/moc_gresb.cpp
296
288 297 moc/moc_genericPySysdriver.cpp: /usr/include/genericPySysdriver.h
289 298 /usr/lib64/qt4/bin/moc $(DEFINES) $(INCPATH) /usr/include/genericPySysdriver.h -o moc/moc_genericPySysdriver.cpp
290 299
@@ -314,6 +323,7 obj/rmapplugin.o: rmapplugin.cpp rmapplu
314 323 rmappluginui.h \
315 324 rmapoperations.h \
316 325 spectralmatricesdmasimulator.h \
326 stardundee.h \
317 327 ccsds.h \
318 328 spwpacketreceiver.h \
319 329 rmappluginpythonwrapper.h
@@ -323,6 +333,7 obj/rmappluginui.o: rmappluginui.cpp rma
323 333 rmappluginui.h \
324 334 rmapoperations.h \
325 335 spectralmatricesdmasimulator.h \
336 stardundee.h \
326 337 ccsds.h \
327 338 spwpacketreceiver.h
328 339 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/rmappluginui.o rmappluginui.cpp
@@ -348,9 +359,13 obj/spectralmatricesdmasimulator.o: spec
348 359 obj/rmappluginpythonwrapper.o: rmappluginpythonwrapper.cpp rmappluginpythonwrapper.h
349 360 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/rmappluginpythonwrapper.o rmappluginpythonwrapper.cpp
350 361
351 obj/stardundee.o: stardundee.cpp stardundee.h
362 obj/stardundee.o: stardundee.cpp stardundee.h \
363 rmapoperations.h
352 364 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/stardundee.o stardundee.cpp
353 365
366 obj/gresb.o: gresb.cpp gresb.h
367 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/gresb.o gresb.cpp
368
354 369 obj/lppmonplugininterface.o: /usr/include/lppmon/pluginsInterface/lppmonplugininterface.cpp /usr/include/lppmon/pluginsInterface/lppmonplugininterface.h \
355 370 /usr/include/lppmon/pluginsInterface/lppmonplugininterface_global.h
356 371 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/lppmonplugininterface.o /usr/include/lppmon/pluginsInterface/lppmonplugininterface.cpp
@@ -379,6 +394,9 obj/moc_rmappluginpythonwrapper.o: moc/m
379 394 obj/moc_stardundee.o: moc/moc_stardundee.cpp
380 395 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/moc_stardundee.o moc/moc_stardundee.cpp
381 396
397 obj/moc_gresb.o: moc/moc_gresb.cpp
398 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/moc_gresb.o moc/moc_gresb.cpp
399
382 400 obj/moc_genericPySysdriver.o: moc/moc_genericPySysdriver.cpp
383 401 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/moc_genericPySysdriver.o moc/moc_genericPySysdriver.cpp
384 402
@@ -16,7 +16,7 RMAP::RMAP(RMAP_command_codes commandCod
16 16 SPWPacketSize = sizeof(RMAPHeader) + nbBytes + 1 ; // SPW Packet = Header + Data + dataCRC
17 17 dataCRC = RMAPCalculateDataCRC(data, nbBytes);
18 18 }
19 GRESBHeader.GRESBProtocoleID = 0x00; // packets with protocole ID 0 have SpaceWire a packet as payload
19 GRESBHeader.GRESBProtocoleID = 0x00; // packets with protocole ID 0 have a SpaceWire packet as payload
20 20 GRESBHeader.SPWPacketSize2 = (SPWPacketSize>>16);
21 21 GRESBHeader.SPWPacketSize1 = (SPWPacketSize>>8);
22 22 GRESBHeader.SPWPacketSize0 = (SPWPacketSize);
@@ -3,6 +3,14
3 3
4 4 #include "qhexspinbox.h"
5 5
6 #define READ_WRITE_MAX_COUNTS 4096 // in words
7 #define RMAP_MAX_DATA_LENGTH 4*READ_WRITE_MAX_COUNTS // in bytes, shall be lower than the limit size of SPW packet of the GRESB bridge
8 #define RMAP_READ_REPLY_HEADER_LENGTH 12 // in bytes => ECSS
9 #define RMAP_READ_COMMAND_HEADER_LENGTH 16 // in bytes => ECSS
10 #define RMAP_DATA_CRC_LENGTH 1 // in bytes => ECSS
11 #define RMAP_MAX_PACKET_LENGTH RMAP_READ_REPLY_HEADER_LENGTH + RMAP_MAX_DATA_LENGTH + RMAP_DATA_CRC_LENGTH
12 #define CCSDS_MAX_PACKET_LENGTH 4412 // in bytes, specified in the LFR Software Requirements Specification
13
6 14 static const unsigned char RMAP_CRCTable[] = {
7 15 0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75,
8 16 0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b,
@@ -39,6 +39,7 rmapplugin::rmapplugin(QWidget *parent)
39 39 timeCode = 0;
40 40 time_COARSE = 0;
41 41 time_FINE = 0;
42 currentBridge = selectedBridgeIsUnknown;
42 43
43 44 /*Python wrapper*/
44 45 this->pyObject = new rmappluginPythonWrapper();
@@ -46,8 +47,10 rmapplugin::rmapplugin(QWidget *parent)
46 47 connect(this->pyObject,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
47 48 /*==============*/
48 49
49 connect(UI->rmapOpenCommunicationButton, SIGNAL(clicked()), this, SLOT(RMAP_CONNECT()));
50 connect(UI->rmapCloseCommunicationButton, SIGNAL(clicked()), this, SLOT(RMAP_DISCONNECT()));
50 //connect(UI->rmapOpenCommunicationButton, SIGNAL(clicked()), this, SLOT(RMAP_CONNECT()));
51 //connect(UI->rmapCloseCommunicationButton, SIGNAL(clicked()), this, SLOT(RMAP_DISCONNECT()));
52 connect(UI->rmapOpenCommunicationButton, SIGNAL(clicked()), this, SLOT(openBridge()));
53 connect(UI->rmapCloseCommunicationButton, SIGNAL(clicked()), this, SLOT(closeBridge()));
51 54 connect(RMAPSend_SOCKET, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(RMAPSendConnectionState(QAbstractSocket::SocketState)));
52 55 connect(RMAPReceive_SOCKET, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(RMAPReceiveConnectionState(QAbstractSocket::SocketState)));
53 56 connect(GRESBStatusQuery_SOCKET, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(GRESBConnectionState(QAbstractSocket::SocketState)));
@@ -68,6 +71,16 rmapplugin::rmapplugin(QWidget *parent)
68 71 connect(this->UI->spectralMatricesDMASimulator, SIGNAL(rmapplugginRead(uint*,uint,uint)), this, SLOT(Read(uint*,uint,uint)));
69 72 connect(this->UI->spectralMatricesDMASimulator, SIGNAL(rmapplugginWrite(uint*,uint,uint)), this, SLOT(Write(uint*,uint,uint)));
70 73 connect(this->UI->spectralMatricesDMASimulator, SIGNAL(sendMessage(QString)), this, SLOT(displayOnConsole(QString)));
74
75 // GRESB
76 connect(this, SIGNAL(gresbIsOpen(bool)), this, SLOT(gresbSelection(bool)));
77
78 // Star Dundee
79 connect(this->UI->starDundee, SIGNAL(starDundeeIsOpen(bool)), this, SLOT(activatePluginViaStarDundee(bool)));
80 connect(this->UI->starDundee, SIGNAL(RMAP_write_reply_setText(QString)), this, SLOT(RMAP_write_reply_setText(QString)));
81 connect(this->UI->starDundee, SIGNAL(appendToLog(QString)), this, SLOT(appendToLog(QString)));
82
83 connect(this->UI, SIGNAL(bridgeHasChanged(selectedBridge)), this, SLOT(bridgeHasChanged(selectedBridge)));
71 84 }
72 85
73 86 rmapplugin::~rmapplugin()
@@ -79,20 +92,52 rmapplugin::~rmapplugin()
79 92
80 93 unsigned int rmapplugin::Write(unsigned int *Value, unsigned int count, unsigned int address)
81 94 {
95 unsigned int result;
96 switch(currentBridge)
97 {
98 case selectedBridgeIsGRESB :
99 result = WriteGRESB(Value, count, address);
100 break;
101 case selectedBridgeIsStarDundee :
102 result = this->WriteStarDundee(Value, count, address);
103 break;
104 default:
105 result = 1;
106 break;
107 }
108 return result;
109 }
110
111 unsigned int rmapplugin::Read(unsigned int *Value, unsigned int count, unsigned int address)
112 {
113 unsigned int result;
114 switch(currentBridge)
115 {
116 case selectedBridgeIsGRESB :
117 result = ReadGRESB(Value, count, address);
118 break;
119 case selectedBridgeIsStarDundee :
120 result = this->ReadStarDundee(Value, count, address);
121 break;
122 default:
123 result = 1;
124 break;
125 }
126 return result;
127 }
128
129 unsigned int rmapplugin::WriteGRESB(unsigned int *Value, unsigned int count, unsigned int address)
130 {
82 131 unsigned int remainingCount = count;
83 132 unsigned int iOffset = 0;
84 133 QString console_message;
85 134 char* data;
86 135
87 unsigned char command = 0x08; // initialize command at 0b00001000 for write
88
89 136 if(spwPacketReceiverOBJECT->rmapPacketSEMAPHORE->available()!=0)
90 137 {
91 138 APPENDTOLOG("WARNING === in function WRITE of rmapplugin *** RMAP request already running, WRITE access stopped");
92 139 return 1;
93 140 }
94 if (UI->RMAP_write_verify->isChecked()) command = command + (1<<2);
95 if (UI->RMAP_write_reply->isChecked()) command = command + (1<<1);
96 141
97 142 UI->RMAP_write_reply->setText("reply to the write command required\nlast reply status: unavailable");
98 143
@@ -149,7 +194,7 unsigned int rmapplugin::Write(unsigned
149 194 return count;
150 195 }
151 196
152 unsigned int rmapplugin::Read(unsigned int *Value, unsigned int count, unsigned int address)
197 unsigned int rmapplugin::ReadGRESB(unsigned int *Value, unsigned int count, unsigned int address)
153 198 {
154 199 unsigned int remainingCount = count;
155 200 unsigned int iOffset = 0;
@@ -214,74 +259,6 unsigned int rmapplugin::Read(unsigned i
214 259 return count;
215 260 }
216 261
217 unsigned int rmapplugin::ReadBLOCK(unsigned int nbBytes, unsigned int address)
218 {
219 int errorCode;
220 RMAP *RMAPCommand;
221 QTime RMAPTimeout;
222 unsigned int dataLength;
223 if (GRESBStatusQueryRequest(LinkStatus, UI->spwLinkSpinBox->value()) == 1)
224 {
225 RMAP_DISCONNECT();
226 return 1;
227 }
228
229 if (nbBytes > 4)
230 {
231 RMAPCommand = new RMAP(read_Inc,
232 UI->rmapTargetLogicalAddressSpinBox->value(),
233 UI->rmapSourceLogicalAddressSpinBox->value(),
234 address,
235 nbBytes,
236 NULL);
237 }
238 else
239 {
240 RMAPCommand = new RMAP(read_Single,
241 UI->rmapTargetLogicalAddressSpinBox->value(),
242 UI->rmapSourceLogicalAddressSpinBox->value(),
243 address,
244 nbBytes,
245 NULL);
246 }
247
248 // SEND THE GRESB HEADER FOR THE RMAP READ COMMAND
249 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->GRESBHeader), 4);
250 // SEND THE SPACEWIRE PACKET FOR THE RMAP READ COMMAND
251 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->RMAPHeader), sizeof(RMAPCommand->RMAPHeader));
252 RMAPSend_SOCKET->waitForBytesWritten(100);
253 RMAPTimeout.start();
254 // write timeout
255 while(RMAPSend_SOCKET->bytesToWrite() > 0)
256 {
257 RMAPSend_SOCKET->waitForBytesWritten(100);
258 if(RMAPTimeout.elapsed()>1000)
259 {
260 APPENDTOLOG("WARNING === in function READ of rmapplugin *** sending Read RMAP Command timeout\n");
261 return 0;
262 }
263 }
264
265 // RECEIVE THE INCOMING RMAP PACKET
266 errorCode = spwPacketReceiverOBJECT->receiveSPWPacket(1); // request ID 1 is for RMAP packet
267 if (errorCode<=0)
268 {
269 APPENDTOLOG("WARNING === in function ReadBLOCK of rmapplugin *** RMAP packet reception failed with code " + QString::number(errorCode));
270 return 0;
271 }
272 dataLength = spwPacketReceiverOBJECT->rmapPacketSize - RMAP_READ_REPLY_HEADER_LENGTH - RMAP_DATA_CRC_LENGTH;
273 if(dataLength != nbBytes)
274 {
275 APPENDTOLOG("WARNING === in function READ of rmapplugin *** number of data received ("
276 +QString::number(dataLength)
277 +") not equal to number of data requested ("
278 +QString::number(READ_WRITE_MAX_COUNTS*4)
279 +")");
280 return 0;
281 }
282 return dataLength;
283 }
284
285 262 unsigned int rmapplugin::WriteBLOCK(char *data, unsigned int nbBytes, unsigned int address)
286 263 {
287 264 QTime RMAPTimeout;
@@ -395,6 +372,88 unsigned int rmapplugin::WriteBLOCK(char
395 372 return nbBytes;
396 373 }
397 374
375 unsigned int rmapplugin::ReadBLOCK(unsigned int nbBytes, unsigned int address)
376 {
377 int errorCode;
378 RMAP *RMAPCommand;
379 QTime RMAPTimeout;
380 unsigned int dataLength;
381 if (GRESBStatusQueryRequest(LinkStatus, UI->spwLinkSpinBox->value()) == 1)
382 {
383 RMAP_DISCONNECT();
384 return 1;
385 }
386
387 if (nbBytes > 4)
388 {
389 RMAPCommand = new RMAP(read_Inc,
390 UI->rmapTargetLogicalAddressSpinBox->value(),
391 UI->rmapSourceLogicalAddressSpinBox->value(),
392 address,
393 nbBytes,
394 NULL);
395 }
396 else
397 {
398 RMAPCommand = new RMAP(read_Single,
399 UI->rmapTargetLogicalAddressSpinBox->value(),
400 UI->rmapSourceLogicalAddressSpinBox->value(),
401 address,
402 nbBytes,
403 NULL);
404 }
405
406 // SEND THE GRESB HEADER FOR THE RMAP READ COMMAND
407 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->GRESBHeader), 4);
408 // SEND THE SPACEWIRE PACKET FOR THE RMAP READ COMMAND
409 RMAPSend_SOCKET->write((char*) ((void*) &RMAPCommand->RMAPHeader), sizeof(RMAPCommand->RMAPHeader));
410 RMAPSend_SOCKET->waitForBytesWritten(100);
411 RMAPTimeout.start();
412 // write timeout
413 while(RMAPSend_SOCKET->bytesToWrite() > 0)
414 {
415 RMAPSend_SOCKET->waitForBytesWritten(100);
416 if(RMAPTimeout.elapsed()>1000)
417 {
418 APPENDTOLOG("WARNING === in function READ of rmapplugin *** sending Read RMAP Command timeout\n");
419 return 0;
420 }
421 }
422
423 // RECEIVE THE INCOMING RMAP PACKET
424 errorCode = spwPacketReceiverOBJECT->receiveSPWPacket(1); // request ID 1 is for RMAP packet
425 if (errorCode<=0)
426 {
427 APPENDTOLOG("WARNING === in function ReadBLOCK of rmapplugin *** RMAP packet reception failed with code " + QString::number(errorCode));
428 return 0;
429 }
430 dataLength = spwPacketReceiverOBJECT->rmapPacketSize - RMAP_READ_REPLY_HEADER_LENGTH - RMAP_DATA_CRC_LENGTH;
431 if(dataLength != nbBytes)
432 {
433 APPENDTOLOG("WARNING === in function READ of rmapplugin *** number of data received ("
434 +QString::number(dataLength)
435 +") not equal to number of data requested ("
436 +QString::number(READ_WRITE_MAX_COUNTS*4)
437 +")");
438 return 0;
439 }
440 return dataLength;
441 }
442
443 unsigned int rmapplugin::WriteStarDundee(unsigned int *Value, unsigned int count, unsigned int address)
444 {
445 unsigned int result;
446 result = UI->starDundee->WriteStarDundee(Value, count, address);
447 return result;
448 }
449
450 unsigned int rmapplugin::ReadStarDundee(unsigned int *Value, unsigned int count, unsigned int address)
451 {
452 unsigned int result;
453 result = UI->starDundee->ReadStarDundee(Value, count, address);
454 return result;
455 }
456
398 457 ////////
399 458 // SLOTS
400 459
@@ -549,6 +608,36 void rmapplugin::reset_TC_LFR_UPDATE_TIM
549 608 time_FINE = 0;
550 609 }
551 610
611 void rmapplugin::openBridge()
612 {
613 switch(currentBridge)
614 {
615 case selectedBridgeIsGRESB :
616 RMAP_CONNECT();
617 break;
618 case selectedBridgeIsStarDundee :
619 this->UI->starDundee->OpenStarDundee();
620 break;
621 default:
622 break;
623 }
624 }
625
626 void rmapplugin::closeBridge()
627 {
628 switch(currentBridge)
629 {
630 case selectedBridgeIsGRESB :
631 RMAP_DISCONNECT();
632 break;
633 case selectedBridgeIsStarDundee :
634 this->UI->starDundee->CloseStarDundee();
635 break;
636 default:
637 break;
638 }
639 }
640
552 641 void rmapplugin::RMAP_CONNECT() // SLOT
553 642 {
554 643 bool spwRunning = true;
@@ -575,6 +664,7 void rmapplugin::RMAP_CONNECT() // SLOT
575 664 {
576 665 APPENDTOLOG(QString("SpaceWire running on virtual link ")+ QString::number(UI->spwLinkSpinBox->value()));
577 666 emit this->activateSig(true);
667 emit gresbIsOpen(true);
578 668 }
579 669 }
580 670
@@ -584,6 +674,7 void rmapplugin::RMAP_DISCONNECT() // SL
584 674 RMAPReceive_SOCKET->disconnectFromHost();
585 675 GRESBStatusQuery_SOCKET->disconnectFromHost();
586 676 emit this->activateSig(false);
677 emit gresbIsOpen(false);
587 678 }
588 679
589 680 void rmapplugin::RMAPSendConnectionState(QAbstractSocket::SocketState socketState) // SLOT
@@ -710,6 +801,21 void rmapplugin::displayOnConsole(QStrin
710 801 this->UI->console->append(message);
711 802 }
712 803
804 void rmapplugin::activatePluginViaStarDundee(bool flag)
805 {
806 emit activateSig(flag);
807 }
808
809 void rmapplugin::RMAP_write_reply_setText(QString text)
810 {
811 this->UI->RMAP_write_reply->setText(text);
812 }
813
814 void rmapplugin::appendToLog(QString text)
815 {
816 APPENDTOLOG(text);
817 }
818
713 819 /////////////////////
714 820 // INTERNAL FUNCTIONS
715 821
@@ -815,3 +921,16 int rmapplugin::charTab_TO_int(char *cha
815 921 return result;
816 922 }
817 923
924 void rmapplugin::gresbSelection(bool flag)
925 {
926 if (flag == true) UI->selection_GROUPBOX->setEnabled(false);
927 if (flag == false) UI->selection_GROUPBOX->setEnabled(true);
928 }
929
930 // SLOTS
931 void rmapplugin::bridgeHasChanged(selectedBridge bridge)
932 {
933 currentBridge = bridge;
934 }
935
936
@@ -52,6 +52,10 public:
52 52 ~rmapplugin();
53 53 int GRESBStatusQueryRequest(GresbStatusQueryOption option, char link);
54 54 int charTab_TO_int(char *charTab);
55 unsigned int ReadGRESB(unsigned int *Value,unsigned int count,unsigned int address=0);
56 unsigned int WriteGRESB(unsigned int *Value,unsigned int count,unsigned int address=0);
57 unsigned int ReadStarDundee(unsigned int *Value, unsigned int count, unsigned int address=0);
58 unsigned int WriteStarDundee(unsigned int *Value, unsigned int count, unsigned int address=0);
55 59
56 60 public slots:
57 61 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
@@ -66,6 +70,8 public slots:
66 70 //
67 71 void RMAP_CONNECT();
68 72 void RMAP_DISCONNECT();
73 void openBridge();
74 void closeBridge();
69 75 int RMAPSendReadCommand();
70 76 int RMAPSendWriteCommand();
71 77 void reTestSPWLink();
@@ -73,11 +79,19 public slots:
73 79 void RMAPSendConnectionState(QAbstractSocket::SocketState socketState);
74 80 void RMAPReceiveConnectionState(QAbstractSocket::SocketState socketState);
75 81 void GRESBConnectionState(QAbstractSocket::SocketState socketState);
82 //
83 void gresbSelection(bool flag);
84 void activatePluginViaStarDundee(bool flag);
85 void RMAP_write_reply_setText(QString text);
86 void appendToLog(QString text);
87 void bridgeHasChanged(selectedBridge bridge);
76 88
77 89 signals:
78 90 void ccsdsPacketReadyRead(char *ccsdsPacket, unsigned int size);
91 void gresbIsOpen(bool);
79 92
80 93 private:
94 selectedBridge currentBridge;
81 95 rmapPluginUI* UI;
82 96 QTcpSocket* GRESBStatusQuery_SOCKET;
83 97 QTcpSocket* RMAPSend_SOCKET;
@@ -22,7 +22,8 DEFINES += driver_PID=0
22 22 QT += network
23 23
24 24
25 LIBS += ../spw_usb_driver_v2.61/lib/libSpaceWireUSBAPI.so
25 LIBS += ../spw_usb_driver_v2.61/lib/x86_64/libSpaceWireUSBAPI.so \
26 ../spw_usb_driver_v2.61/lib/x86_64/libConfigLibraryUSB.so
26 27
27 28
28 29 INCLUDEPATH += \
@@ -42,7 +43,9 HEADERS += \
42 43 spectralmatricesdmasimulator.h \
43 44 rmappluginpythonwrapper.h \
44 45 stardundee.h \
45 ../spw_usb_driver_v2.61/inc/spw_usb_api.h
46 ../spw_usb_driver_v2.61/inc/spw_usb_api.h \
47 ../spw_usb_driver_v2.61/inc/spw_config_library.h \
48 gresb.h
46 49
47 50
48 51 SOURCES += \
@@ -55,7 +58,8 SOURCES += \
55 58 ../common_PLE/gresbstatusenquiry.cpp \
56 59 spectralmatricesdmasimulator.cpp \
57 60 rmappluginpythonwrapper.cpp \
58 stardundee.cpp
61 stardundee.cpp \
62 gresb.cpp
59 63
60 64
61 65
@@ -32,10 +32,19 rmapPluginUI::rmapPluginUI(QWidget *pare
32 32 QWidget* spwTabWidgetPage3 = new QWidget;
33 33 QWidget* spwTabWidgetPage4 = new QWidget;
34 34 QWidget* spwTabWidgetPage5 = new QWidget;
35 bridgeWidget = new QWidget;
35 36 mainLayout = new QVBoxLayout;
36 37 connectionLayout = new QGridLayout;
37 38 ccsdsLayout = new QVBoxLayout;
38 39 consoleLayout = new QVBoxLayout;
40 selectionLayout = new QVBoxLayout;
41 bridgeSelection_LAYOUT = new QGridLayout;
42 generalParameters_LAYOUT = new QGridLayout;
43
44 gresb_GROUPBOX = new QGroupBox(tr("GRESB bridge parameters"));
45 stardundee_GROUPBOX = new QGroupBox(tr("Star Dundee brick parameters"));
46 selection_GROUPBOX = new QGroupBox(tr("Bridge selection"));
47 generalParameters_GROUPBOX = new QGroupBox(tr("General parameters"));
39 48
40 49 //*** QLABEL ***//
41 50 gresbBridgeIPLabel = new QLabel(tr("GRESB Bridge IP: "));
@@ -53,6 +62,7 rmapPluginUI::rmapPluginUI(QWidget *pare
53 62 //*** QPUSHBUTTON ***//
54 63 rmapOpenCommunicationButton = new QPushButton(tr("Open RMAP Communication"));
55 64 rmapCloseCommunicationButton = new QPushButton(tr("Close RMAP Communication"));
65 rmapOpenCommunicationButton->setEnabled(false);
56 66 rmapCloseCommunicationButton->setEnabled(false);
57 67 logFileChooseButton = new QPushButton(tr("Choose file"));
58 68 gresbStatusQueryRetryButton = new QPushButton(tr("Retry"));
@@ -62,6 +72,9 rmapPluginUI::rmapPluginUI(QWidget *pare
62 72 reset_TC_LFR_UPDATE_TIME_Button = new QPushButton(tr("reset the TC_LFR_UPDATE_TIME Packet coarse and fine times"));
63 73 clearConsoleButton = new QPushButton(tr("Clear"));
64 74
75 selectGRESB_BUTTON = new QRadioButton(tr("GRESB"));
76 selectStarDundee_BUTTON = new QRadioButton(tr("Star Dundee"));
77
65 78 //*** SPINBOX ***//
66 79 gresbVirtualLinkSpinBox = new QSpinBox;
67 80 rmapSourceLogicalAddressSpinBox = new QSpinBox;
@@ -81,6 +94,7 rmapPluginUI::rmapPluginUI(QWidget *pare
81 94
82 95 //*** MISC **//
83 96 starDundee = new StarDundee;
97 gresbBridge = new gresb;
84 98 console = new QTextEdit;
85 99 gresbBridgeIPDialogBox = new QIPDialogBox;
86 100 gresbStatusQueryDialog = new QDialog;
@@ -96,24 +110,43 rmapPluginUI::rmapPluginUI(QWidget *pare
96 110 connectionLayout->addWidget(gresbBridgeIPDialogBox, 0, 1, 0);
97 111 connectionLayout->addWidget(gresbVirtualLinkLabel, 1, 0, 0);
98 112 connectionLayout->addWidget(gresbVirtualLinkSpinBox, 1, 1, 0);
99 connectionLayout->addWidget(rmapSourceLogicalAddressLabel, 2, 0, 0);
100 connectionLayout->addWidget(rmapSourceLogicalAddressSpinBox, 2, 1, 0);
101 connectionLayout->addWidget(spwLinkLabel, 3, 0, 0);
102 connectionLayout->addWidget(spwLinkSpinBox, 3, 1, 0);
103 connectionLayout->addWidget(rmapTargetLogicalAddressLabel, 4, 0, 0);
104 connectionLayout->addWidget(rmapTargetLogicalAddressSpinBox, 4, 1, 0);
105 connectionLayout->addWidget(rmapOpenCommunicationButton, 5, 0, 1, 2);
106 connectionLayout->addWidget(rmapCloseCommunicationButton, 6, 0, 1, 2);
107 connectionLayout->addWidget(rmapSendStateLabel, 7, 0, 1, 2);
108 connectionLayout->addWidget(rmapReceiveStateLabel, 8, 0, 1, 2);
109 connectionLayout->addWidget(gresbStatusQueryLabel, 9, 0, 1, 2);
110 connectionLayout->addWidget(logEnableCheckBox, 10, 0, 0);
111 connectionLayout->addWidget(logFileChooseButton, 10, 1, 0);
112 connectionLayout->addWidget(RMAP_write_verify, 11, 0, 1, 2);
113 connectionLayout->addWidget(RMAP_write_reply, 12, 0, 1, 2);
113 connectionLayout->addWidget(spwLinkLabel, 2, 0, 0);
114 connectionLayout->addWidget(spwLinkSpinBox, 2, 1, 0);
115 connectionLayout->addWidget(rmapSourceLogicalAddressLabel, 3, 0, 0);
116 connectionLayout->addWidget(rmapSourceLogicalAddressSpinBox, 3, 1, 0);
117 connectionLayout->addWidget(rmapSendStateLabel, 4, 0, 1, 2);
118 connectionLayout->addWidget(rmapReceiveStateLabel, 5, 0, 1, 2);
119 connectionLayout->addWidget(gresbStatusQueryLabel, 6, 0, 1, 2);
120
121 connectionLayout->setRowStretch(7, 1);
122 connectionLayout->setColumnStretch(2, 1);
123
124 bridgeSelection_LAYOUT->addWidget(selectGRESB_BUTTON, 0, 0, 1, 1);
125 bridgeSelection_LAYOUT->addWidget(selectStarDundee_BUTTON, 0, 1, 1, 1);
126 bridgeSelection_LAYOUT->setRowStretch(1, 1);
127 bridgeSelection_LAYOUT->setColumnStretch(2, 1);
114 128
115 connectionLayout->setRowStretch(13, 1);
116 connectionLayout->setColumnStretch(2, 1);
129 generalParameters_LAYOUT->addWidget(logEnableCheckBox, 0, 0, 1, 1);
130 generalParameters_LAYOUT->addWidget(logFileChooseButton, 0, 1, 1, 1);
131 generalParameters_LAYOUT->addWidget(rmapTargetLogicalAddressLabel, 1, 0, 0);
132 generalParameters_LAYOUT->addWidget(rmapTargetLogicalAddressSpinBox, 1, 1, 0);
133 generalParameters_LAYOUT->addWidget(rmapOpenCommunicationButton, 2, 0, 1, 2);
134 generalParameters_LAYOUT->addWidget(rmapCloseCommunicationButton, 3, 0, 1, 2);
135 generalParameters_LAYOUT->addWidget(RMAP_write_verify, 4, 0, 1, 2);
136 generalParameters_LAYOUT->addWidget(RMAP_write_reply, 5, 0, 1, 2);
137 generalParameters_LAYOUT->setRowStretch(6, 1);
138 generalParameters_LAYOUT->setColumnStretch(2, 1);
139
140 gresb_GROUPBOX->setLayout(connectionLayout);
141 gresb_GROUPBOX->setVisible(false);
142 stardundee_GROUPBOX->setLayout(starDundee->layout());
143 stardundee_GROUPBOX->setVisible(false);
144 selection_GROUPBOX->setLayout(bridgeSelection_LAYOUT);
145 generalParameters_GROUPBOX->setLayout(generalParameters_LAYOUT);
146 selectionLayout->addWidget(selection_GROUPBOX);
147 selectionLayout->addWidget(generalParameters_GROUPBOX);
148 selectionLayout->addWidget(gresb_GROUPBOX);
149 selectionLayout->addWidget(stardundee_GROUPBOX);
117 150
118 151 ccsdsLayout->addWidget(sendCCSDSCommandButton);
119 152 ccsdsLayout->addWidget(send_TC_LFR_UPDATE_TIME_Button);
@@ -133,13 +166,14 rmapPluginUI::rmapPluginUI(QWidget *pare
133 166 spwTabWidget->addTab(spwTabWidgetPage2, tr("status"));
134 167 spwTabWidget->addTab(spwTabWidgetPage3, tr("console"));
135 168 spwTabWidget->addTab(spwTabWidgetPage4, tr("DMA"));
136 spwTabWidget->addTab(spwTabWidgetPage5, tr("Star Dundee"));
137 spwTabWidgetPage0->setLayout(connectionLayout);
169 spwTabWidget->addTab(spwTabWidgetPage5, tr("gresb"));
170
171 spwTabWidgetPage0->setLayout(selectionLayout);
138 172 spwTabWidgetPage1->setLayout(ccsdsLayout);
139 173 spwTabWidgetPage2->setLayout(this->spwLinkStatusEnquiry->mainLayout);
140 174 spwTabWidgetPage3->setLayout(consoleLayout);
141 175 spwTabWidgetPage4->setLayout(spectralMatricesDMASimulator->mainLayout);
142 spwTabWidgetPage5->setLayout(starDundee->layout());
176 spwTabWidgetPage5->setLayout(gresbBridge->layout());
143 177 mainLayout->addWidget(spwTabWidget);
144 178 setLayout(mainLayout);
145 179
@@ -152,6 +186,16 rmapPluginUI::rmapPluginUI(QWidget *pare
152 186
153 187 connect(gresbStatusQueryAbortButton, SIGNAL(clicked()), gresbStatusQueryDialog, SLOT(reject()));
154 188 connect(this->clearConsoleButton, SIGNAL(clicked()), this->console, SLOT(clear()));
189 connect(this->selectGRESB_BUTTON, SIGNAL(clicked()), this, SLOT(selectionBetweenGresbAndStarDundee()));
190 connect(this->selectStarDundee_BUTTON, SIGNAL(clicked()), this, SLOT(selectionBetweenGresbAndStarDundee()));
191 connect(this->starDundee, SIGNAL(starDundeeIsOpen(bool)), this, SLOT(starDundeeIsOpen(bool)));
192
193 // command code
194 connect(this->RMAP_write_reply, SIGNAL(clicked()), this, SLOT(getCommandCode()));
195 connect(this->RMAP_write_verify, SIGNAL(clicked()), this, SLOT(getCommandCode()));
196 connect(this, SIGNAL(commandCodeHasChanged(RMAP_command_codes)), this->starDundee, SLOT(updateCommandCode(RMAP_command_codes)));
197
198 getCommandCode(); // init the command code value
155 199 }
156 200
157 201 void rmapPluginUI::connectPort()
@@ -169,7 +213,6 void rmapPluginUI::setConnected(bool con
169 213 ui->OpenPort->setText(tr("Open port"));*/
170 214 }
171 215
172
173 216 rmapPluginUI::~rmapPluginUI()
174 217 {
175 218 //delete ui;
@@ -232,9 +275,49 void rmapPluginUI::closeEvent(QCloseEven
232 275
233 276 RMAP_command_codes rmapPluginUI::getCommandCode()
234 277 {
235 if (RMAP_write_verify->isChecked() and RMAP_write_reply->isChecked()) return writeSingle_ver_rep;
236 if (RMAP_write_verify->isChecked() and !RMAP_write_reply->isChecked()) return writeSingle_ver_noRep;
237 if (!RMAP_write_verify->isChecked() and RMAP_write_reply->isChecked()) return writeSingle_noVer_Rep;
238 if (!RMAP_write_verify->isChecked() and !RMAP_write_reply->isChecked()) return writeSingle_noVer_noRep;
239 else return invalid0;
278 RMAP_command_codes commandCode = invalid0;
279 if (RMAP_write_verify->isChecked() and RMAP_write_reply->isChecked()) commandCode = writeSingle_ver_rep;
280 if (RMAP_write_verify->isChecked() and !RMAP_write_reply->isChecked()) commandCode = writeSingle_ver_noRep;
281 if (!RMAP_write_verify->isChecked() and RMAP_write_reply->isChecked()) commandCode = writeSingle_noVer_Rep;
282 if (!RMAP_write_verify->isChecked() and !RMAP_write_reply->isChecked()) commandCode = writeSingle_noVer_noRep;
283 emit commandCodeHasChanged(commandCode);
284 return commandCode;
240 285 }
286
287 // SLOT
288
289 void rmapPluginUI::selectionBetweenGresbAndStarDundee() //SLOT
290 {
291 if (selectGRESB_BUTTON->isChecked())
292 {
293 gresb_GROUPBOX->setVisible(true);
294 stardundee_GROUPBOX->setVisible(false);
295 rmapOpenCommunicationButton->setEnabled(true);
296 emit bridgeHasChanged(selectedBridgeIsGRESB);
297 }
298 if (selectStarDundee_BUTTON->isChecked())
299 {
300 stardundee_GROUPBOX->setVisible(true);
301 gresb_GROUPBOX->setVisible(false);
302 rmapOpenCommunicationButton->setEnabled(true);
303 emit bridgeHasChanged(selectedBridgeIsStarDundee);
304 }
305 }
306
307 void rmapPluginUI::starDundeeIsOpen(bool flag)
308 {
309 if (flag == true)
310 {
311 selection_GROUPBOX->setEnabled(false);
312 this->rmapOpenCommunicationButton->setEnabled(false);
313 this->rmapCloseCommunicationButton->setEnabled(true);
314 }
315 if (flag == false)
316 {
317 selection_GROUPBOX->setEnabled(true);
318 this->rmapOpenCommunicationButton->setEnabled(true);
319 this->rmapCloseCommunicationButton->setEnabled(false);
320 }
321 }
322
323
@@ -42,6 +42,15
42 42 #include <QTextEdit>
43 43 #include "spectralmatricesdmasimulator.h"
44 44 #include <stardundee.h>
45 #include <gresb.h>
46 #include <QRadioButton>
47 #include <QGroupBox>
48
49 enum selectedBridge{
50 selectedBridgeIsUnknown,
51 selectedBridgeIsGRESB,
52 selectedBridgeIsStarDundee
53 };
45 54
46 55 class rmapPluginUI : public QWidget
47 56 {
@@ -61,6 +70,11 public:
61 70 QPushButton* reset_TC_LFR_UPDATE_TIME_Button;
62 71 QPushButton* clearConsoleButton;
63 72
73 QRadioButton* selectGRESB_BUTTON;
74 QRadioButton* selectStarDundee_BUTTON;
75
76 QGroupBox *selection_GROUPBOX;
77
64 78 QSpinBox* gresbVirtualLinkSpinBox;
65 79 QSpinBox* spwLinkSpinBox;
66 80 QSpinBox* rmapSourceLogicalAddressSpinBox;
@@ -89,39 +103,56 public:
89 103
90 104 StarDundee *starDundee;
91 105
106 gresb *gresbBridge;
107
92 108 bool islogfileenable();
93 109 void appendToLogFile(const QString & text);
94 110 void closeEvent(QCloseEvent *event);
95 RMAP_command_codes getCommandCode();
96 111
97 112 public slots:
98 113 void setConnected(bool connected);
99 114 void connectPort();
100 115 void chooseLogFile();
101 116 void logFileEnDisable(int state);
117 RMAP_command_codes getCommandCode();
118
119 private slots:
120 void selectionBetweenGresbAndStarDundee();
121 void starDundeeIsOpen(bool flag);
102 122
103 123 signals:
104 124 void connectPortsig(QString PortName,int baudrate);
105 125 void setLogFileName(QString FileName);
126 void commandCodeHasChanged(RMAP_command_codes commandCode);
127 void bridgeHasChanged(selectedBridge bridge);
106 128
107 129 private:
108 QLabel* gresbBridgeIPLabel;
109 QLabel* gresbVirtualLinkLabel;
110 QLabel* spwLinkLabel;
111 QLabel* rmapSourceLogicalAddressLabel;
112 QLabel* rmapTargetLogicalAddressLabel;
130 QLabel *gresbBridgeIPLabel;
131 QLabel *gresbVirtualLinkLabel;
132 QLabel *spwLinkLabel;
133 QLabel *rmapSourceLogicalAddressLabel;
134 QLabel *rmapTargetLogicalAddressLabel;
113 135 QLabel *logFileName;
114 136
115 QVBoxLayout* mainLayout;
116 QGridLayout* connectionLayout;
117 QVBoxLayout* ccsdsLayout;
118 QVBoxLayout* consoleLayout;
119 QGridLayout* gresbStatusQueryDialogLayout;
137 QGridLayout *bridgeSelection_LAYOUT;
138 QVBoxLayout *selectionLayout;
139 QVBoxLayout *mainLayout;
140 QGridLayout *connectionLayout;
141 QVBoxLayout *ccsdsLayout;
142 QVBoxLayout *consoleLayout;
143 QGridLayout *gresbStatusQueryDialogLayout;
144 QGridLayout *generalParameters_LAYOUT;
120 145
121 QTabWidget* spwTabWidget;
146 QTabWidget *spwTabWidget;
147
148 QWidget* bridgeWidget;
122 149
123 QFile* logFile;
124 QTextStream* logFileStrm;
150 QGroupBox *gresb_GROUPBOX;
151 QGroupBox *stardundee_GROUPBOX;
152 QGroupBox *generalParameters_GROUPBOX;
153
154 QFile *logFile;
155 QTextStream *logFileStrm;
125 156 bool logFileEn;
126 157
127 158 };
@@ -1,5 +1,6
1 1 #include "spwpacketreceiver.h"
2 2 #include <QTime>
3 #include "rmapoperations.h"
3 4
4 5 spwpacketreceiver::spwpacketreceiver(QObject *parent) :
5 6 QObject(parent)
@@ -4,14 +4,6
4 4 #include <QSemaphore>
5 5 #include <QTcpSocket>
6 6
7 #define READ_WRITE_MAX_COUNTS 4096 // in words
8 #define RMAP_MAX_DATA_LENGTH 4*READ_WRITE_MAX_COUNTS // in bytes, shall be lower than the limit size of SPW packet of the GRESB bridge
9 #define RMAP_READ_REPLY_HEADER_LENGTH 12 // in bytes => ECSS
10 #define RMAP_READ_COMMAND_HEADER_LENGTH 16 // in bytes => ECSS
11 #define RMAP_DATA_CRC_LENGTH 1 // in bytes => ECSS
12 #define RMAP_MAX_PACKET_LENGTH RMAP_READ_REPLY_HEADER_LENGTH + RMAP_MAX_DATA_LENGTH + RMAP_DATA_CRC_LENGTH
13 #define CCSDS_MAX_PACKET_LENGTH 4412 // in bytes, specified in the LFR Software Requirements Specification
14
15 7 class spwpacketreceiver : public QObject
16 8 {
17 9 Q_OBJECT
This diff has been collapsed as it changes many lines, (506 lines changed) Show them Hide them
@@ -1,30 +1,67
1 1 #include "stardundee.h"
2 #include <QTime>
3 #include <math.h>
2 4
3 5 StarDundee::StarDundee(QWidget *parent) :
4 6 QWidget(parent)
5 7 {
8 commandCode = invalid0; // initialization of the cmmand code for the RMAP transfers
9 rmapPacket = (unsigned char*) malloc(RMAP_MAX_PACKET_LENGTH);
10
11 rmapTargetLogicalAddress = 0xfe;
12 rmapSourceLogicalAddress = 0x20;
6 13 connection_LAYOUT = new QGridLayout;
7 14
8 openCommunication_BUTTON = new QPushButton(tr("Open communication link"));
9 closeCommunication_BUTTON = new QPushButton(tr("Close communication link"));
15 sendPacket_BUTTON = new QPushButton(tr("Send a packet"));
16 sendRMAPPacket_BUTTON = new QPushButton(tr("Write RMAP packet to the specified target"));
17 readRMAPPacket_BUTTON = new QPushButton(tr("Read RMAP packet from the specified target"));
18 getRoutingTableEntry_BUTTON = new QPushButton(tr("Get routing table entry (target logical address)"));
10 19
11 20 usbDeviceNumber_LABEL = new QLabel(tr("USB device number: "));
21 linkNumber_LABEL = new QLabel(tr("SpaceWire link number: "));
22 routingTableEntry_LABEL = new QLabel(tr("Target logical address: "));
23 sourceLogicalAddress_LABEL = new QLabel(tr("Source logical address: "));
12 24
13 25 usbDeviceNumber_SPINBOX = new QSpinBox;
14 26 usbDeviceNumber_SPINBOX->setRange(0,32);
15 27 usbDeviceNumber_SPINBOX->setValue(0);
28 linkNumber_SPINBOX = new QSpinBox;
29 linkNumber_SPINBOX->setRange(1,2);
30 linkNumber_SPINBOX->setValue(1);
31 routingTableEntry_SPINBOX = new QSpinBox;
32 routingTableEntry_SPINBOX->setRange(0, 254);
33 routingTableEntry_SPINBOX->setValue(254);
34 sourceLogicalAddress_SPINBOX = new QSpinBox;
35 sourceLogicalAddress_SPINBOX->setRange(0,254);
36 sourceLogicalAddress_SPINBOX->setValue(32);
16 37
17 closeCommunication_BUTTON->setEnabled(false);
38 sendPacket_BUTTON->setEnabled(false);
39 sendRMAPPacket_BUTTON->setEnabled(false);
40 readRMAPPacket_BUTTON->setEnabled(false);
41 getRoutingTableEntry_BUTTON->setEnabled(false);
18 42
19 connection_LAYOUT->addWidget(openCommunication_BUTTON, 0, 0, 1, 2);
20 connection_LAYOUT->addWidget(closeCommunication_BUTTON, 1, 0, 1, 2);
21 connection_LAYOUT->addWidget(usbDeviceNumber_LABEL, 2, 0, 1, 1);
22 connection_LAYOUT->addWidget(usbDeviceNumber_SPINBOX, 2, 1, 1, 1);
43 connection_LAYOUT->addWidget(usbDeviceNumber_LABEL, 0, 0, 1, 1);
44 connection_LAYOUT->addWidget(usbDeviceNumber_SPINBOX, 0, 1, 1, 1);
45 connection_LAYOUT->addWidget(sendPacket_BUTTON, 1, 0, 1, 2);
46 connection_LAYOUT->addWidget(linkNumber_LABEL, 2, 0, 1, 1);
47 connection_LAYOUT->addWidget(linkNumber_SPINBOX, 2, 1, 1, 1);
48 connection_LAYOUT->addWidget(sourceLogicalAddress_LABEL, 3, 0, 1, 1);
49 connection_LAYOUT->addWidget(sourceLogicalAddress_SPINBOX, 3, 1, 1, 1);
50 connection_LAYOUT->addWidget(routingTableEntry_LABEL, 4, 0, 1, 1);
51 connection_LAYOUT->addWidget(routingTableEntry_SPINBOX, 4, 1, 1, 1);
52 connection_LAYOUT->addWidget(sendRMAPPacket_BUTTON, 5, 0, 1, 2);
53 connection_LAYOUT->addWidget(readRMAPPacket_BUTTON, 6, 0, 1, 2);
54 connection_LAYOUT->addWidget(getRoutingTableEntry_BUTTON, 7, 0, 1, 2);
55
56 connection_LAYOUT->setRowStretch(8, 1);
57 connection_LAYOUT->setColumnStretch(2, 1);
23 58
24 59 this->setLayout(connection_LAYOUT);
25 60
26 connect(this->openCommunication_BUTTON, SIGNAL(clicked()), this, SLOT(OpenStarDundee()));
27 connect(this->closeCommunication_BUTTON, SIGNAL(clicked()), this, SLOT(CloseStarDundee()));
61 connect(this->sendPacket_BUTTON, SIGNAL(clicked()), this, SLOT(SendPacket()));
62 connect(this->readRMAPPacket_BUTTON, SIGNAL(clicked()),this, SLOT(ReadRMAP()));
63 connect(this->sendRMAPPacket_BUTTON, SIGNAL(clicked()), this, SLOT(SendRMAP()));
64 connect(this->getRoutingTableEntry_BUTTON, SIGNAL(clicked()), this, SLOT(GetRoutingTableEntry()));
28 65 }
29 66
30 67 StarDundee::~StarDundee()
@@ -34,22 +71,459 StarDundee::~StarDundee()
34 71
35 72 unsigned int StarDundee::OpenStarDundee()
36 73 {
37 if (!USBSpaceWire_Open(&hDevice, 0)) // Open the first device
74 int status;
75 U32 statusControl;
76 U32 routingTableEntry;
77 int tableEntry;
78
79 if (!USBSpaceWire_Open(&hDevice, usbDeviceNumber_SPINBOX->value())) // Open the USB device
38 80 {
39 81 emit sendMessage("stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
40 82 return -1;
41 83 }
42 openCommunication_BUTTON->setEnabled(false);
43 closeCommunication_BUTTON->setEnabled(true);
44 emit sendMessage("stardundee *** Open *** USBSpaceWire_Open(&hDevice, 0)) successful");
84 emit sendMessage("stardundee *** Open *** USBSpaceWire_Open successful, device number: "
85 + QString::number(usbDeviceNumber_SPINBOX->value()));
86
87 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
88 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP
89 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
90
91 // Set the path and return path to the device
92 CFGSpaceWire_StackClear();
93 CFGSpaceWire_AddrStackPush(0);
94 CFGSpaceWire_AddrStackPush(254);
95 CFGSpaceWire_RetAddrStackPush(254);
96
97 // set the base transmit rate to 100 MHz
98 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
99 if (status != CFG_TRANSFER_SUCCESS)
100 {
101 emit sendMessage("ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
102 }
103 else emit sendMessage("OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
104 // read the link status
105 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber_SPINBOX->value(), &statusControl) != CFG_TRANSFER_SUCCESS)
106 {
107 emit sendMessage("Could not read link status control for link " + QString::number(linkNumber_SPINBOX->value()));
108 }
109 else
110 {
111 emit sendMessage("OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber_SPINBOX->value()));
112
113 // Set the link status control register properties
114 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
115 CFGSpaceWire_LSEnableStart(&statusControl, 1);
116 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
117 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
118 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
119
120 // Set the link status control register
121 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber_SPINBOX->value(), statusControl) != CFG_TRANSFER_SUCCESS)
122 {
123 emit sendMessage("Could not set the link status control for link " + QString::number(linkNumber_SPINBOX->value()));
124 }
125 else emit sendMessage("Set the link status control for link " + QString::number(linkNumber_SPINBOX->value()));
126 }
127
128 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET 254 <=> 0xfe
129 tableEntry = routingTableEntry_SPINBOX->value();
130 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
131 {
132 emit sendMessage("Could not clear routing table entry " + QString::number(tableEntry));
133 }
134 else emit sendMessage("Routing table entry [" + QString::number(tableEntry) + "] cleared");
135 // Build the routing table entry to route out of port 1 with header deletion disabled and priority normal
136 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
137 (1<<linkNumber_SPINBOX->value()), // 0x02 = 0000 0010
138 0,
139 0);
140 // Set the routing table entry for logical address tableEntry
141 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
142 {
143 emit sendMessage("Could not set routing table entry [" + QString::number(tableEntry) + "]");
144 }
145 else emit sendMessage("Routing table entry [" + QString::number(tableEntry) + "] set" );
146
147 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET 32 <=> 0x20
148 tableEntry = sourceLogicalAddress_SPINBOX->value();
149 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
150 {
151 emit sendMessage("Could not clear routing table entry " + QString::number(tableEntry));
152 }
153 else emit sendMessage("Routing table entry [" + QString::number(tableEntry) + "] cleared");
154
155 // Build the routing table entry to route out of port 3 with header deletion disabled and priority normal
156 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
157 (1<<3), // 0x02 = 0000 0010
158 0,
159 0);
160 // Set the routing table entry for logical address tableEntry
161 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
162 {
163 emit sendMessage("Could not set routing table entry [" + QString::number(tableEntry) + "]");
164 }
165 else emit sendMessage("Routing table entry [" + QString::number(tableEntry) + "] set" );
166
167 emit sendMessage("The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
168
169 sendPacket_BUTTON->setEnabled(true);
170 sendRMAPPacket_BUTTON->setEnabled(true);
171 readRMAPPacket_BUTTON->setEnabled(true);
172 getRoutingTableEntry_BUTTON->setEnabled(true);
173
174 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
175
176 emit starDundeeIsOpen(true);
177
178 emit sendMessage("command code: " + QString::number(commandCode,16) );
179
45 180 return 1;
46 181 }
47 182
48 183 unsigned int StarDundee::CloseStarDundee()
49 184 {
50 185 USBSpaceWire_Close(hDevice); // Close the device
51 emit sendMessage("stardundee *** Close *** USBSpaceWire_Close(hDevice)");
52 openCommunication_BUTTON->setEnabled(true);
53 closeCommunication_BUTTON->setEnabled(false);
186 emit sendMessage("stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(usbDeviceNumber_SPINBOX->value()));
187 sendPacket_BUTTON->setEnabled(false);
188 sendRMAPPacket_BUTTON->setEnabled(false);
189 readRMAPPacket_BUTTON->setEnabled(false);
190 getRoutingTableEntry_BUTTON->setEnabled(false);
191
192 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
193
194 emit starDundeeIsOpen(false);
195
196 return 1;
197 }
198
199 unsigned int StarDundee::GetRoutingTableEntry()
200 {
201 U32 routingTableEntry, outputPorts;
202 char enabled, delHead, priority;
203 int portNum;
204 int tableEntry;
205
206 tableEntry = routingTableEntry_SPINBOX->value();
207
208 // Set the path and return path to the device
209 CFGSpaceWire_StackClear();
210 CFGSpaceWire_AddrStackPush(0);
211 CFGSpaceWire_AddrStackPush(254);
212 CFGSpaceWire_RetAddrStackPush(254);
213
214 // Read the routing table entry
215 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
216 {
217 emit sendMessage("Could not read routing table entry [" + QString::number(tableEntry) + "]");
218 }
219 else
220 {
221 // Display the routing table entry properties
222 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
223 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
224 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
225 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
226 emit sendMessage("CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
227 emit sendMessage("CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
228 emit sendMessage("CFGSpaceWire_RTIsPriority : " + QString::number(priority));
229 emit sendMessage("CFGSpaceWire_RTGetOutputPorts : ");
230 for (portNum = 0; portNum < 32; portNum++)
231 {
232 if (outputPorts & (1 << portNum))
233 {
234 emit sendMessage(QString::number(portNum));
235 }
236 }
237 }
238
239 return 1;
240 }
241
242 unsigned int StarDundee::SendPacket()
243 {
244 U32 nBufferSize; // The amount of data, in bytes, to be transmitted.
245 char bWait; // If bWait is 0 then the transfer is started and the function returns immediately.
246 // If bWait is not 0 then the function will return only when the transfer is completed or an error is detected.
247
248 nBufferSize = 10;
249 bWait = 1;
250 // Send the packet and wait on it completing
251 result = USBSpaceWire_SendPacket(hDevice, pBuffer, nBufferSize, bWait, &pIdentifier);
252 if (result != TRANSFER_SUCCESS)
253 {
254 emit sendMessage("Error: Could not send the packet");
255 }
256 else emit sendMessage("The packet has been successfully sent");
257
258 // Free the send
259 USBSpaceWire_FreeSend(hDevice, pIdentifier);
260
261 return 1;
262 }
263
264 unsigned int StarDundee::SendRMAP()
265 {
266 unsigned int Value[4];
267 unsigned int count = 4;
268 unsigned int address = 0x40000000;
269 Value[0] = 0xabcd1234;
270 Value[1] = 0xbb;
271 Value[2] = 0xab;
272 Value[3] = 0xcd;
273 WriteStarDundee(Value, count, address);
274 return 1;
275 }
276
277 unsigned int StarDundee::ReadRMAP()
278 {
279 unsigned int Value[100000];
280 unsigned int count = 100000;
281 unsigned int address = 0x40000000;
282 unsigned int result;
283 result = ReadStarDundee(Value, count, address);
284 emit sendMessage("ReadRMAP, nbBytes: " + QString::number(result));
285 emit sendMessage("Value[0]: " + QString::number(Value[0], 16));
286 emit sendMessage("Value[1]: " + QString::number(Value[1], 16));
287 emit sendMessage("Value[2]: " + QString::number(Value[2], 16));
288 emit sendMessage("Value[3]: " + QString::number(Value[3], 16));
54 289 return 1;
55 290 }
291
292 unsigned int StarDundee::ReadStarDundee(unsigned int *Value, unsigned int count, unsigned int address)
293 {
294 RMAP *RMAPCommand;
295 rmap_read_reply_PcktHdr_t rmapReplyHeader;
296 USB_SPACEWIRE_STATUS result; // The result of the receive operation
297 USB_SPACEWIRE_PACKET_PROPERTIES properties; // The properties of the read
298 unsigned int nbBytes;
299 unsigned char* packet;
300 U32 nPacketNum;
301 unsigned int offset;
302 unsigned int i;
303
304 //**********************
305 // SEND THE READ COMMAND
306 nbBytes = 4 * count;
307 if (nbBytes > 4)
308 {
309 RMAPCommand = new RMAP(read_Inc, // build the command
310 rmapTargetLogicalAddress,
311 rmapSourceLogicalAddress,
312 address,
313 nbBytes,
314 NULL);
315 }
316 else
317 {
318 RMAPCommand = new RMAP(read_Single, // build the command
319 rmapTargetLogicalAddress,
320 rmapSourceLogicalAddress,
321 address,
322 nbBytes,
323 NULL);
324 }
325
326 result = USBSpaceWire_SendPacket(hDevice,
327 (unsigned char*) ((void*) &RMAPCommand->RMAPHeader),
328 sizeof(RMAPCommand->RMAPHeader),
329 BWAIT_1, &pIdentifier);
330 if (result != TRANSFER_SUCCESS) emit sendMessage("ERROR *** ReadStarDundee when sending the READ command ");
331 else emit sendMessage("OK *** ReadStarDundee when sending the READ command");
332
333 //*****************
334 // RECEIVE THE DATA
335 nbBytes = sizeof(rmapReplyHeader) + 4 * count + 1; // 1 is for the data CRC
336 packet = (unsigned char *) malloc(nbBytes);
337 nPacketNum = 1;
338 result = USBSpaceWire_ReadPackets(hDevice, packet, nbBytes, nPacketNum, BWAIT_1, &properties, &pIdentifier);
339 if (result != TRANSFER_SUCCESS) emit sendMessage("Error: Could not receive the packet");
340 else
341 {
342 emit sendMessage("A packet of length " + QString::number(properties.len) + " has been successfully received");
343 offset = sizeof(rmapReplyHeader);
344 for(i=0; i<count; i++)
345 {
346 Value[i] = packet[offset+3];
347 Value[i] = Value[i] + packet[offset+2] * pow(2, 8);
348 Value[i] = Value[i] + packet[offset+1] * pow(2, 16);
349 Value[i] = Value[i] + packet[offset+0] * pow(2, 24);
350 offset = offset + 4;
351 }
352 free(packet);
353 USBSpaceWire_FreeRead(hDevice, pIdentifier); // Free the receive
354 return count;
355 }
356
357 return 1;
358 }
359
360 unsigned int StarDundee::WriteStarDundee(unsigned int *Value, unsigned int count, unsigned int address)
361 {
362 RMAP *RMAPCommand;
363 unsigned char *data;
364 char *dataCHAR;
365 unsigned char *aux;
366 unsigned int offset;
367 U32 dataSize, headerSize, CRCSize, totalSize; // sizes in bytes
368 U32 nPacketNum;
369 USB_SPACEWIRE_PACKET_PROPERTIES properties; // The properties of the read
370 rmap_write_reply_t rmapReplyHeader;
371
372 dataSize = count * 4;
373 dataCHAR = (char *) malloc(dataSize);
374 for (unsigned int i = 0; i<count; i++)
375 {
376 dataCHAR[i*4+3] = (char) ((unsigned int) Value[i]);
377 dataCHAR[i*4+2] = (char) ((unsigned int) Value[i]>>8);
378 dataCHAR[i*4+1] = (char) ((unsigned int) Value[i]>>16);
379 dataCHAR[i*4+0] = (char) ((unsigned int) Value[i]>>24);
380 }
381
382 RMAPCommand = new RMAP(commandCode,
383 rmapTargetLogicalAddress,
384 rmapSourceLogicalAddress,
385 address,
386 dataSize,
387 dataCHAR);
388 free(dataCHAR);
389 headerSize = sizeof(RMAPCommand->RMAPHeader);
390 CRCSize = 1;
391
392 //*************************
393 // BUILD THE PACKET TO SEND
394 totalSize = headerSize + dataSize + CRCSize;
395 data = (unsigned char*) malloc( totalSize );
396 aux = (unsigned char*) ((void*) &RMAPCommand->RMAPHeader);
397 for(unsigned int i = 0; i<headerSize; i++) data[i] = aux[i];
398 offset = headerSize;
399 for(unsigned int i = 0; i<count; i++)
400 {
401 data[offset+3] = (unsigned char) (Value[i]);
402 data[offset+2] = (unsigned char) (Value[i]>>8);
403 data[offset+1] = (unsigned char) (Value[i]>>16);
404 data[offset] = (unsigned char) (Value[i]>>24);
405 offset = offset + 4;
406 }
407 data[offset] = RMAPCommand->dataCRC;
408
409 //************
410 // SEND THE PACKET
411 result = USBSpaceWire_SendPacket(hDevice,
412 data,
413 totalSize,
414 BWAIT_1, &pIdentifier);
415 if (result != TRANSFER_SUCCESS)
416 {
417 emit sendMessage("ERROR *** WriteStarDundee when sending packet of size "
418 + QString::number(totalSize) +", with code: " + QString::number(result));
419 USBSpaceWire_FreeSend(hDevice, pIdentifier);
420 free(data);
421 return 1;
422 }
423 else emit sendMessage("OK *** WriteStarDundee when sending packet of size " + QString::number(totalSize));
424
425 //**************
426 // Free the send
427 USBSpaceWire_FreeSend(hDevice, pIdentifier);
428 free(data);
429
430 if ( (commandCode == writeSingle_noVer_Rep) | (commandCode == writeInc_noVer_Rep) |
431 (commandCode == writeSingle_ver_rep) | (commandCode == writeInc_ver_rep) )
432 {
433 //***********************
434 // RECEIVE THE RMAP REPLY
435 totalSize = sizeof(rmapReplyHeader);
436 nPacketNum = 1;
437 result = USBSpaceWire_ReadPackets(hDevice, (char *) &rmapReplyHeader, totalSize, nPacketNum, BWAIT_1, &properties, &pIdentifier);
438 if (result != TRANSFER_SUCCESS)
439 {
440 emit sendMessage("Error: Could not receive the RMAP reply");
441 USBSpaceWire_FreeRead(hDevice, pIdentifier); // Free the receive
442 return 1;
443 }
444 else
445 {
446 emit sendMessage("An RMAP reply of length " + QString::number(properties.len) + " has been successfully received");
447 USBSpaceWire_FreeRead(hDevice, pIdentifier); // Free the receive
448 }
449 if(properties.len != 8)
450 {
451 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** write reply format not compliant\n");
452 return 1;
453 }
454 emit sendMessage("data CRC " + QString::number(RMAPCommand->dataCRC, 16) );
455 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.initiatorLogicalAddress, 16) );
456 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.protocolIdentifier, 16) );
457 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.instruction, 16) );
458 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.status, 16) );
459 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.targetLogicalAddress, 16) );
460 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.transactionIdentifier1, 16) );
461 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.transactionIdentifier2, 16) );
462 emit sendMessage("rmapReplyHeader " + QString::number(rmapReplyHeader.headerCRC, 16) );
463 switch (rmapReplyHeader.status) // byte 4 is the status byte in the reply
464 {
465 case 0:
466 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 0 Successfull");
467 break;
468 case 1:
469 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** General error code");
470 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 1 General error code");
471 break;
472 case 2:
473 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Unused RMAP packet type or command code");
474 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 2 Unused RMAP packet type or command code");
475 break;
476 case 3:
477 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Invalid key");
478 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 3 Invalid key");
479 break;
480 case 4:
481 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Invalid data CRC");
482 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 4 Invalid data CRC");
483 break;
484 case 5:
485 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Early EOP");
486 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 5 Early EOP");
487 break;
488 case 6:
489 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Too much data");
490 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 6 Too much data");
491 break;
492 case 7:
493 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** EEP");
494 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 7 EEP");
495 break;
496 case 8:
497 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Reserved");
498 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 8 Reserved");
499 break;
500 case 9:
501 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Verify buffer overrun");
502 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 9 Verify buffer overrun");
503 break;
504 case 10:
505 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** RMAP command not implemented or not authorised");
506 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 10 RMAP command not implemented or not authorised");
507 break;
508 case 11:
509 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** RMW data length error");
510 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 11 RMAP RMW data length error");
511 break;
512 case 12:
513 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** Invalid target logical address");
514 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 12 Invalid target logical address");
515 break;
516 }
517 }
518 else
519 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: unavailable");
520 return count;
521 }
522
523 //******
524 // SLOTS
525
526 void StarDundee::updateCommandCode(RMAP_command_codes code)
527 {
528 this->commandCode = code;
529 }
@@ -3,10 +3,15
3 3
4 4 #include <QWidget>
5 5 #include "spw_usb_api.h"
6 #include "spw_config_library.h"
6 7 #include <QPushButton>
7 8 #include <QGridLayout>
8 9 #include <QSpinBox>
9 10 #include <QLabel>
11 #include "rmapoperations.h"
12
13 #define BWAIT_0 0
14 #define BWAIT_1 1
10 15
11 16 class StarDundee : public QWidget
12 17 {
@@ -14,24 +19,53 class StarDundee : public QWidget
14 19 public:
15 20 explicit StarDundee(QWidget *parent = 0);
16 21 ~StarDundee();
17 star_device_handle hDevice;// Handle to the SpaceWire device
18 QGridLayout *connection_LAYOUT;
22 unsigned int WriteStarDundee(unsigned int *Value,unsigned int count,unsigned int address=0);
23 unsigned int ReadStarDundee(unsigned int *Value,unsigned int count,unsigned int address=0);
19 24
20 25 signals:
21 26 void sendMessage(QString message);
27 void starDundeeIsOpen(bool);
28 void RMAP_write_reply_setText(QString);
29 void appendToLog(QString);
22 30
23 31 public slots:
24 32 unsigned int OpenStarDundee();
25 33 unsigned int CloseStarDundee();
34 unsigned int SendPacket();
35 unsigned int SendRMAP();
36 unsigned int ReadRMAP();
37 unsigned int GetRoutingTableEntry();
38 void updateCommandCode(RMAP_command_codes code);
26 39
27 40 private:
41 char rmapTargetLogicalAddress ;
42 char rmapSourceLogicalAddress ;
28 43
29 QPushButton *openCommunication_BUTTON;
30 QPushButton *closeCommunication_BUTTON;
44 QPushButton *sendPacket_BUTTON;
45 QPushButton *sendRMAPPacket_BUTTON;
46 QPushButton *readRMAPPacket_BUTTON;
47 QPushButton *getRoutingTableEntry_BUTTON;
31 48
32 49 QLabel *usbDeviceNumber_LABEL;
50 QLabel *linkNumber_LABEL;
51 QLabel *routingTableEntry_LABEL;
52 QLabel *sourceLogicalAddress_LABEL;
33 53
34 54 QSpinBox *usbDeviceNumber_SPINBOX;
55 QSpinBox *linkNumber_SPINBOX;
56 QSpinBox *routingTableEntry_SPINBOX;
57 QSpinBox *sourceLogicalAddress_SPINBOX;
58
59 QGridLayout *connection_LAYOUT;
60
61 unsigned char pBuffer[10]; // Pointer to the start of the user buffer from which to transmit data
62 unsigned char* rmapPacket; // The buffer to receive RMAP READ packets
63 USB_SPACEWIRE_ID pIdentifier; // A pointer to a variable which will be set to contain a unique identifier for the send
64
65 RMAP_command_codes commandCode;
66
67 star_device_handle hDevice; // Handle to the SpaceWire device
68 USB_SPACEWIRE_STATUS result; // The result of the send operation
35 69
36 70 };
37 71
General Comments 0
You need to be logged in to leave comments. Login now