##// END OF EJS Templates
Minor updates
leroy -
r3:bf349cb3902d default
parent child
Show More
@@ -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-06T08:47:47. -->
3 <!-- Written by Qt Creator 2.4.1, 2012-12-07T14:08:53. -->
4 4 <qtcreator>
5 5 <data>
6 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -47,8 +47,6 rmapplugin::rmapplugin(QWidget *parent)
47 47 connect(this->pyObject,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
48 48 /*==============*/
49 49
50 //connect(UI->rmapOpenCommunicationButton, SIGNAL(clicked()), this, SLOT(RMAP_CONNECT()));
51 //connect(UI->rmapCloseCommunicationButton, SIGNAL(clicked()), this, SLOT(RMAP_DISCONNECT()));
52 50 connect(UI->rmapOpenCommunicationButton, SIGNAL(clicked()), this, SLOT(openBridge()));
53 51 connect(UI->rmapCloseCommunicationButton, SIGNAL(clicked()), this, SLOT(closeBridge()));
54 52 connect(RMAPSend_SOCKET, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(RMAPSendConnectionState(QAbstractSocket::SocketState)));
@@ -76,7 +74,7 rmapplugin::rmapplugin(QWidget *parent)
76 74 connect(this, SIGNAL(gresbIsOpen(bool)), this, SLOT(gresbSelection(bool)));
77 75
78 76 // Star Dundee
79 connect(this->UI->starDundee, SIGNAL(starDundeeIsOpen(bool)), this, SLOT(activatePluginViaStarDundee(bool)));
77 connect(this->UI->starDundee, SIGNAL(isOpen(bool)), this, SLOT(activatePluginViaStarDundee(bool)));
80 78 connect(this->UI->starDundee, SIGNAL(RMAP_write_reply_setText(QString)), this, SLOT(RMAP_write_reply_setText(QString)));
81 79 connect(this->UI->starDundee, SIGNAL(appendToLog(QString)), this, SLOT(appendToLog(QString)));
82 80
@@ -99,7 +97,7 unsigned int rmapplugin::Write(unsigned
99 97 result = WriteGRESB(Value, count, address);
100 98 break;
101 99 case selectedBridgeIsStarDundee :
102 result = this->WriteStarDundee(Value, count, address);
100 result = UI->starDundee->Write(Value, count, address);
103 101 break;
104 102 default:
105 103 result = 1;
@@ -117,7 +115,7 unsigned int rmapplugin::Read(unsigned i
117 115 result = ReadGRESB(Value, count, address);
118 116 break;
119 117 case selectedBridgeIsStarDundee :
120 result = this->ReadStarDundee(Value, count, address);
118 result = UI->starDundee->Read(Value, count, address);
121 119 break;
122 120 default:
123 121 result = 1;
@@ -440,25 +438,29 unsigned int rmapplugin::ReadBLOCK(unsig
440 438 return dataLength;
441 439 }
442 440
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
457 441 ////////
458 442 // SLOTS
459 443
460 444 unsigned int rmapplugin::WriteSPW(char *Value, unsigned int count, char targetLogicalAddress, char userApplication) // SLOT
461 445 {
446 unsigned int result;
447 switch(currentBridge)
448 {
449 case selectedBridgeIsGRESB :
450 result = WriteSPWGRESB(Value, count, targetLogicalAddress, userApplication);
451 break;
452 case selectedBridgeIsStarDundee :
453 result = UI->starDundee->WriteSPW(Value, count, targetLogicalAddress, userApplication);
454 break;
455 default:
456 result = 1;
457 break;
458 }
459 return result;
460 }
461
462 unsigned int rmapplugin::WriteSPWGRESB(char *Value, unsigned int count, char targetLogicalAddress, char userApplication)
463 {
462 464 char protocoleIdentifier = 0x02;
463 465 char reserved = 0x00;
464 466 char gresbProtocole = 0x00;
@@ -616,7 +618,7 void rmapplugin::openBridge()
616 618 RMAP_CONNECT();
617 619 break;
618 620 case selectedBridgeIsStarDundee :
619 this->UI->starDundee->OpenStarDundee();
621 this->UI->starDundee->Open();
620 622 break;
621 623 default:
622 624 break;
@@ -631,7 +633,7 void rmapplugin::closeBridge()
631 633 RMAP_DISCONNECT();
632 634 break;
633 635 case selectedBridgeIsStarDundee :
634 this->UI->starDundee->CloseStarDundee();
636 this->UI->starDundee->Close();
635 637 break;
636 638 default:
637 639 break;
@@ -796,16 +798,6 int rmapplugin::GRESBStatusQuery() // SL
796 798 return 0;
797 799 }
798 800
799 void rmapplugin::displayOnConsole(QString message)
800 {
801 this->UI->console->append(message);
802 }
803
804 void rmapplugin::activatePluginViaStarDundee(bool flag)
805 {
806 emit activateSig(flag);
807 }
808
809 801 void rmapplugin::RMAP_write_reply_setText(QString text)
810 802 {
811 803 this->UI->RMAP_write_reply->setText(text);
@@ -927,10 +919,5 void rmapplugin::gresbSelection(bool fla
927 919 if (flag == false) UI->selection_GROUPBOX->setEnabled(true);
928 920 }
929 921
930 // SLOTS
931 void rmapplugin::bridgeHasChanged(selectedBridge bridge)
932 {
933 currentBridge = bridge;
934 }
935 922
936 923
@@ -54,8 +54,7 public:
54 54 int charTab_TO_int(char *charTab);
55 55 unsigned int ReadGRESB(unsigned int *Value,unsigned int count,unsigned int address=0);
56 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);
57 unsigned int WriteSPWGRESB(char *Value, unsigned int count, char targetLogicalAddress, char userApplication);
59 58
60 59 public slots:
61 60 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
@@ -66,7 +65,7 public slots:
66 65 void send_TC_LFR_UPDATE_TIME();
67 66 void reset_TC_LFR_UPDATE_TIME();
68 67 int GRESBStatusQuery();
69 void displayOnConsole(QString message);
68 void displayOnConsole(QString message) {this->UI->console->append(message);}
70 69 //
71 70 void RMAP_CONNECT();
72 71 void RMAP_DISCONNECT();
@@ -81,10 +80,10 public slots:
81 80 void GRESBConnectionState(QAbstractSocket::SocketState socketState);
82 81 //
83 82 void gresbSelection(bool flag);
84 void activatePluginViaStarDundee(bool flag);
83 void activatePluginViaStarDundee(bool flag) {emit activateSig(flag);}
85 84 void RMAP_write_reply_setText(QString text);
86 85 void appendToLog(QString text);
87 void bridgeHasChanged(selectedBridge bridge);
86 void bridgeHasChanged(selectedBridge bridge) {currentBridge = bridge;}
88 87
89 88 signals:
90 89 void ccsdsPacketReadyRead(char *ccsdsPacket, unsigned int size);
@@ -45,7 +45,8 HEADERS += \
45 45 stardundee.h \
46 46 ../spw_usb_driver_v2.61/inc/spw_usb_api.h \
47 47 ../spw_usb_driver_v2.61/inc/spw_config_library.h \
48 gresb.h
48 gresb.h \
49 bridge.h
49 50
50 51
51 52 SOURCES += \
@@ -59,7 +60,8 SOURCES += \
59 60 spectralmatricesdmasimulator.cpp \
60 61 rmappluginpythonwrapper.cpp \
61 62 stardundee.cpp \
62 gresb.cpp
63 gresb.cpp \
64 bridge.cpp
63 65
64 66
65 67
@@ -47,21 +47,21 rmapPluginUI::rmapPluginUI(QWidget *pare
47 47 generalParameters_GROUPBOX = new QGroupBox(tr("General parameters"));
48 48
49 49 //*** QLABEL ***//
50 gresbBridgeIPLabel = new QLabel(tr("GRESB Bridge IP: "));
51 gresbVirtualLinkLabel = new QLabel(tr("GRESB Virtual Link: "));
52 spwLinkLabel = new QLabel(tr("GRESB SPW Link: "));
50 gresbBridgeIPLabel = new QLabel(tr("Bridge IP: "));
51 gresbVirtualLinkLabel = new QLabel(tr("Virtual Link: "));
52 spwLinkLabel = new QLabel(tr("SPW Link: "));
53 53 rmapSourceLogicalAddressLabel = new QLabel(tr("RMAP Source Logical Address: "));
54 54 rmapTargetLogicalAddressLabel = new QLabel(tr("RMAP Target Logical Address: "));
55 55 rmapSendStateLabel = new QLabel(tr("RMAP Send Socket State: waiting for connection"));
56 56 rmapReceiveStateLabel = new QLabel(tr("RMAP Receive Socket State: waiting for connection"));
57 57 logFileName = new QLabel;
58 gresbStatusQueryLabel = new QLabel(tr("GRESB status query socket (port 3010): waiting for connection"));
58 gresbStatusQueryLabel = new QLabel(tr("Status query socket (port 3010): waiting for connection"));
59 59 gresbStatusQueryDialogLabel = new QLabel(tr("sockets opened but SpaceWire link not running"));
60 60 sendCCSDSCommandLabel = new QLabel(tr("Address of the target"));
61 61
62 62 //*** QPUSHBUTTON ***//
63 rmapOpenCommunicationButton = new QPushButton(tr("Open RMAP Communication"));
64 rmapCloseCommunicationButton = new QPushButton(tr("Close RMAP Communication"));
63 rmapOpenCommunicationButton = new QPushButton(tr("Open selected bridge"));
64 rmapCloseCommunicationButton = new QPushButton(tr("Close selected bridge"));
65 65 rmapOpenCommunicationButton->setEnabled(false);
66 66 rmapCloseCommunicationButton->setEnabled(false);
67 67 logFileChooseButton = new QPushButton(tr("Choose file"));
@@ -86,7 +86,6 rmapPluginUI::rmapPluginUI(QWidget *pare
86 86 rmapSourceLogicalAddressSpinBox->setRange(0, 255);
87 87 rmapSourceLogicalAddressSpinBox->setValue(33);
88 88 rmapTargetLogicalAddressSpinBox->setRange(0, 255);
89 rmapTargetLogicalAddressSpinBox->setValue(254);
90 89 spwLinkSpinBox->setRange(0, 2);
91 90 spwLinkSpinBox->setValue(0);
92 91 CCSDSTargetLogicalAddressSpinBox->setRange(0,255);
@@ -130,11 +129,11 rmapPluginUI::rmapPluginUI(QWidget *pare
130 129 generalParameters_LAYOUT->addWidget(logFileChooseButton, 0, 1, 1, 1);
131 130 generalParameters_LAYOUT->addWidget(rmapTargetLogicalAddressLabel, 1, 0, 0);
132 131 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);
132 generalParameters_LAYOUT->addWidget(rmapOpenCommunicationButton, 2, 0, 1, 1);
133 generalParameters_LAYOUT->addWidget(rmapCloseCommunicationButton, 2, 1, 1, 1);
134 generalParameters_LAYOUT->addWidget(RMAP_write_verify, 3, 0, 1, 2);
135 generalParameters_LAYOUT->addWidget(RMAP_write_reply, 4, 0, 1, 2);
136 generalParameters_LAYOUT->setRowStretch(5, 1);
138 137 generalParameters_LAYOUT->setColumnStretch(2, 1);
139 138
140 139 gresb_GROUPBOX->setLayout(connectionLayout);
@@ -188,14 +187,16 rmapPluginUI::rmapPluginUI(QWidget *pare
188 187 connect(this->clearConsoleButton, SIGNAL(clicked()), this->console, SLOT(clear()));
189 188 connect(this->selectGRESB_BUTTON, SIGNAL(clicked()), this, SLOT(selectionBetweenGresbAndStarDundee()));
190 189 connect(this->selectStarDundee_BUTTON, SIGNAL(clicked()), this, SLOT(selectionBetweenGresbAndStarDundee()));
191 connect(this->starDundee, SIGNAL(starDundeeIsOpen(bool)), this, SLOT(starDundeeIsOpen(bool)));
190 connect(this->starDundee, SIGNAL(isOpen(bool)), this, SLOT(isOpen(bool)));
191 connect(this->rmapTargetLogicalAddressSpinBox, SIGNAL(valueChanged(int)), this->starDundee, SLOT(targetHasChanged(int)));
192 192
193 193 // command code
194 194 connect(this->RMAP_write_reply, SIGNAL(clicked()), this, SLOT(getCommandCode()));
195 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)));
196 connect(this, SIGNAL(commandCodeHasChanged(RMAP_command_codes)), this->starDundee, SLOT(commandCodeHasChanged(RMAP_command_codes)));
197 197
198 198 getCommandCode(); // init the command code value
199 rmapTargetLogicalAddressSpinBox->setValue(254);
199 200 }
200 201
201 202 void rmapPluginUI::connectPort()
@@ -304,7 +305,7 void rmapPluginUI::selectionBetweenGresb
304 305 }
305 306 }
306 307
307 void rmapPluginUI::starDundeeIsOpen(bool flag)
308 void rmapPluginUI::isOpen(bool flag)
308 309 {
309 310 if (flag == true)
310 311 {
@@ -118,13 +118,14 public slots:
118 118
119 119 private slots:
120 120 void selectionBetweenGresbAndStarDundee();
121 void starDundeeIsOpen(bool flag);
121 void isOpen(bool flag);
122 122
123 123 signals:
124 124 void connectPortsig(QString PortName,int baudrate);
125 125 void setLogFileName(QString FileName);
126 126 void commandCodeHasChanged(RMAP_command_codes commandCode);
127 127 void bridgeHasChanged(selectedBridge bridge);
128 void targetHasChanged(unsigned char target);
128 129
129 130 private:
130 131 QLabel *gresbBridgeIPLabel;
This diff has been collapsed as it changes many lines, (628 lines changed) Show them Hide them
@@ -5,21 +5,20
5 5 StarDundee::StarDundee(QWidget *parent) :
6 6 QWidget(parent)
7 7 {
8 // Packet receiver
9 rmapPacketSEMAPHORE = new QSemaphore;
10 ccsdsPacketSEMAPHORE = new QSemaphore;
11 rmapPacket = (char*) malloc(RMAP_MAX_PACKET_LENGTH);
12 ccsdsPacket = (unsigned char*) malloc(CCSDS_MAX_PACKET_LENGTH);
13 spwPacket = (char*) malloc( qMax(RMAP_MAX_PACKET_LENGTH, CCSDS_MAX_PACKET_LENGTH) );
14
8 15 commandCode = invalid0; // initialization of the cmmand code for the RMAP transfers
9 rmapPacket = (unsigned char*) malloc(RMAP_MAX_PACKET_LENGTH);
10 16
11 rmapTargetLogicalAddress = 0xfe;
12 17 rmapSourceLogicalAddress = 0x20;
13 18 connection_LAYOUT = new QGridLayout;
14 19
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)"));
19
20 20 usbDeviceNumber_LABEL = new QLabel(tr("USB device number: "));
21 21 linkNumber_LABEL = new QLabel(tr("SpaceWire link number: "));
22 routingTableEntry_LABEL = new QLabel(tr("Target logical address: "));
23 22 sourceLogicalAddress_LABEL = new QLabel(tr("Source logical address: "));
24 23
25 24 usbDeviceNumber_SPINBOX = new QSpinBox;
@@ -28,48 +27,34 StarDundee::StarDundee(QWidget *parent)
28 27 linkNumber_SPINBOX = new QSpinBox;
29 28 linkNumber_SPINBOX->setRange(1,2);
30 29 linkNumber_SPINBOX->setValue(1);
31 routingTableEntry_SPINBOX = new QSpinBox;
32 routingTableEntry_SPINBOX->setRange(0, 254);
33 routingTableEntry_SPINBOX->setValue(254);
34 30 sourceLogicalAddress_SPINBOX = new QSpinBox;
35 31 sourceLogicalAddress_SPINBOX->setRange(0,254);
36 32 sourceLogicalAddress_SPINBOX->setValue(32);
37 33
38 sendPacket_BUTTON->setEnabled(false);
39 sendRMAPPacket_BUTTON->setEnabled(false);
40 readRMAPPacket_BUTTON->setEnabled(false);
41 getRoutingTableEntry_BUTTON->setEnabled(false);
42
43 34 connection_LAYOUT->addWidget(usbDeviceNumber_LABEL, 0, 0, 1, 1);
44 35 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);
36 connection_LAYOUT->addWidget(linkNumber_LABEL, 1, 0, 1, 1);
37 connection_LAYOUT->addWidget(linkNumber_SPINBOX, 1, 1, 1, 1);
38 connection_LAYOUT->addWidget(sourceLogicalAddress_LABEL, 2, 0, 1, 1);
39 connection_LAYOUT->addWidget(sourceLogicalAddress_SPINBOX, 2, 1, 1, 1);
55 40
56 connection_LAYOUT->setRowStretch(8, 1);
41 connection_LAYOUT->setRowStretch(3, 1);
57 42 connection_LAYOUT->setColumnStretch(2, 1);
58 43
59 44 this->setLayout(connection_LAYOUT);
60 45
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()));
46 connect(this->sourceLogicalAddress_SPINBOX, SIGNAL(valueChanged(int)), this, SLOT(sourceHasChanged(int)));
65 47 }
66 48
67 49 StarDundee::~StarDundee()
68 50 {
51 free(rmapPacket);
52 free(ccsdsPacket);
53 free(spwPacket);
69 54 USBSpaceWire_Close(hDevice); // Close the device
70 55 }
71 56
72 unsigned int StarDundee::OpenStarDundee()
57 unsigned int StarDundee::Open()
73 58 {
74 59 int status;
75 60 U32 statusControl;
@@ -126,7 +111,7 unsigned int StarDundee::OpenStarDundee(
126 111 }
127 112
128 113 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET 254 <=> 0xfe
129 tableEntry = routingTableEntry_SPINBOX->value();
114 tableEntry = rmapTargetLogicalAddress;
130 115 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
131 116 {
132 117 emit sendMessage("Could not clear routing table entry " + QString::number(tableEntry));
@@ -166,32 +151,26 unsigned int StarDundee::OpenStarDundee(
166 151
167 152 emit sendMessage("The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
168 153
169 sendPacket_BUTTON->setEnabled(true);
170 sendRMAPPacket_BUTTON->setEnabled(true);
171 readRMAPPacket_BUTTON->setEnabled(true);
172 getRoutingTableEntry_BUTTON->setEnabled(true);
154 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
155 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
173 156
174 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
157 // initialize SPW packet semaphores
158 while (rmapPacketSEMAPHORE->available()!=0) rmapPacketSEMAPHORE->acquire();
159 while (ccsdsPacketSEMAPHORE->available()!=0) ccsdsPacketSEMAPHORE->acquire();
175 160
176 emit starDundeeIsOpen(true);
177
178 emit sendMessage("command code: " + QString::number(commandCode,16) );
161 emit isOpen(true);
179 162
180 163 return 1;
181 164 }
182 165
183 unsigned int StarDundee::CloseStarDundee()
166 unsigned int StarDundee::Close()
184 167 {
185 168 USBSpaceWire_Close(hDevice); // Close the device
186 169 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 170
192 171 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
193 172
194 emit starDundeeIsOpen(false);
173 emit isOpen(false);
195 174
196 175 return 1;
197 176 }
@@ -203,7 +182,7 unsigned int StarDundee::GetRoutingTable
203 182 int portNum;
204 183 int tableEntry;
205 184
206 tableEntry = routingTableEntry_SPINBOX->value();
185 tableEntry = rmapTargetLogicalAddress;
207 186
208 187 // Set the path and return path to the device
209 188 CFGSpaceWire_StackClear();
@@ -239,177 +218,182 unsigned int StarDundee::GetRoutingTable
239 218 return 1;
240 219 }
241 220
242 unsigned int StarDundee::SendPacket()
221 unsigned int StarDundee::Write(unsigned int *Value, unsigned int count, unsigned int address)
243 222 {
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.
223 unsigned int remainingCount = count;
224 unsigned int iOffset = 0;
225 QString console_message;
226 char* data;
227
228 if(rmapPacketSEMAPHORE->available()!=0)
229 {
230 emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP request already running, WRITE access stopped");
231 return 1;
232 }
233
234 emit this->RMAP_write_reply_setText("reply to the write command required\nlast reply status: unavailable");
235
236 data = (char*) malloc(READ_WRITE_MAX_COUNTS*4);
237
238 emit appendToLog(QString("*** START *** WRITE ")+ QString::number(count) + QString(" word(s) @0x")+ QString::number(address,16));
239
240 while (remainingCount > READ_WRITE_MAX_COUNTS)
241 {
242 for (int i = 0; i<READ_WRITE_MAX_COUNTS; i++)
243 {
244 data[i*4+3] = (char) ((unsigned int) Value[i+iOffset]);
245 data[i*4+2] = (char) ((unsigned int) Value[i+iOffset]>>8);
246 data[i*4+1] = (char) ((unsigned int) Value[i+iOffset]>>16);
247 data[i*4+0] = (char) ((unsigned int) Value[i+iOffset]>>24);
248 }
249
250 console_message.sprintf("remainingCount: %d => ", remainingCount);
251 emit appendToLog(console_message + QString("Write ")+ QString::number(READ_WRITE_MAX_COUNTS*4) + QString(" byte(s) @0x")+ QString::number(address,16));
247 252
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 if(WriteBLOCK(data, READ_WRITE_MAX_COUNTS*4, address)==0)
254 {
255 emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP write command failed");
256 return 1;
257 }
258
259 remainingCount = remainingCount - READ_WRITE_MAX_COUNTS;
260 address = address + READ_WRITE_MAX_COUNTS * 4;
261 iOffset = iOffset + READ_WRITE_MAX_COUNTS;
262 }
263
264 if (remainingCount > 0)
253 265 {
254 emit sendMessage("Error: Could not send the packet");
255 }
256 else emit sendMessage("The packet has been successfully sent");
266 for (unsigned int i = 0; i<remainingCount; i++)
267 {
268 data[i*4+3] = (char) ((unsigned int) Value[i+iOffset]);
269 data[i*4+2] = (char) ((unsigned int) Value[i+iOffset]>>8);
270 data[i*4+1] = (char) ((unsigned int) Value[i+iOffset]>>16);
271 data[i*4+0] = (char) ((unsigned int) Value[i+iOffset]>>24);
272 }
273
274 console_message.sprintf("remainingCount: %d => ", remainingCount);
275 emit appendToLog(console_message + QString("Write ")+ QString::number(remainingCount*4) + QString(" byte(s) @0x")+ QString::number(address,16));
257 276
258 // Free the send
259 USBSpaceWire_FreeSend(hDevice, pIdentifier);
277 if (WriteBLOCK(data, remainingCount*4, address)==0)
278 {
279 emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP write command failed");
280 return 1;
281 }
282 }
260 283
261 return 1;
284 emit appendToLog(QString("*** STOP *** WRITE"));
285 free(data);
286 return count;
262 287 }
263 288
264 unsigned int StarDundee::SendRMAP()
289 unsigned int StarDundee::Read(unsigned int *Value, unsigned int count, unsigned int address)
265 290 {
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;
291 unsigned int remainingCount = count;
292 unsigned int iOffset = 0;
293 QString console_message;
294
295 if(rmapPacketSEMAPHORE->available()!=0)
296 {
297 emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP request already running, READ access stopped");
298 return 1;
299 }
300 emit appendToLog(QString("*** START *** READ ")+ QString::number(count) + QString(" word(s) @0x")+ QString::number(address,16));
301
302 while (remainingCount > READ_WRITE_MAX_COUNTS)
303 {
304 console_message.sprintf("remainingCount: %d => ", remainingCount);
305 emit appendToLog(console_message + QString("Read ")+ QString::number(4*READ_WRITE_MAX_COUNTS) + QString(" byte(s) @0x")+ QString::number(address,16));
306
307 if (this->ReadBLOCK(READ_WRITE_MAX_COUNTS*4, address)==0)
308 {
309 emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP packet not received");
310 return 1;
311 }
312
313 for(int i=0;i<READ_WRITE_MAX_COUNTS;i++)
314 {
315 Value[i+iOffset] = (unsigned char) rmapPacket[i*4+RMAP_READ_REPLY_HEADER_LENGTH];
316 for(int j=1;j<4;j++)
317 {
318 Value[i+iOffset]= ((unsigned char) (rmapPacket[i*4+j+RMAP_READ_REPLY_HEADER_LENGTH]))
319 + Value[i+iOffset]*256;
320 }
321 }
322
323 remainingCount = remainingCount - READ_WRITE_MAX_COUNTS;
324 address = address + READ_WRITE_MAX_COUNTS * 4;
325 iOffset = iOffset + READ_WRITE_MAX_COUNTS;
326 this->acquireRMAPSemaphore();
327 }
328
329 if (remainingCount > 0)
330 {
331 console_message.sprintf("remainingCount: %d => ", remainingCount);
332 emit appendToLog(console_message + QString("Read ")+ QString::number(4*remainingCount) + QString(" byte(s) @0x")+ QString::number(address,16));
333
334 if (this->ReadBLOCK(4*remainingCount, address)==0)
335 {
336 emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP packet not received");
337 return 1;
338 }
339
340 for(unsigned int i=0;i<remainingCount;i++)
341 {
342 Value[i+iOffset] = (unsigned char) rmapPacket[i*4+RMAP_READ_REPLY_HEADER_LENGTH];
343 for(int j=1;j<4;j++)
344 {
345 Value[i+iOffset]= ((unsigned char)(rmapPacket[i*4+j+RMAP_READ_REPLY_HEADER_LENGTH])) + Value[i+iOffset]*256;
346 }
347 }
348 this->acquireRMAPSemaphore();
349 }
350
351 emit appendToLog(QString("*** STOP *** READ "));
352 return count;
275 353 }
276 354
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));
289 return 1;
290 }
291
292 unsigned int StarDundee::ReadStarDundee(unsigned int *Value, unsigned int count, unsigned int address)
355 unsigned int StarDundee::WriteBLOCK(char *data, unsigned int nbBytes, unsigned int address)
293 356 {
294 357 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;
358 char * packet;
359 unsigned char offset, headerSize, CRCSize;
360 char* aux;
361 unsigned int totalSize;
362 int errorCode;
363 QString console_message;
303 364
304 //**********************
305 // SEND THE READ COMMAND
306 nbBytes = 4 * count;
307 if (nbBytes > 4)
365 if (getLinkStatus(this->linkNumber_SPINBOX->value()) == 0)
308 366 {
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);
367 this->Close();
368 return 1;
324 369 }
325 370
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,
371 RMAPCommand = new RMAP(this->commandCode,
383 372 rmapTargetLogicalAddress,
384 373 rmapSourceLogicalAddress,
385 374 address,
386 dataSize,
387 dataCHAR);
388 free(dataCHAR);
375 nbBytes,
376 data);
389 377 headerSize = sizeof(RMAPCommand->RMAPHeader);
390 378 CRCSize = 1;
391 379
392 380 //*************************
393 381 // 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];
382 totalSize = headerSize + nbBytes + CRCSize;
383 packet = (char*) malloc( totalSize );
384 aux = (char*) ((void*) &RMAPCommand->RMAPHeader);
385 for(unsigned int i = 0; i<headerSize; i++) packet[i] = aux[i];
398 386 offset = headerSize;
399 for(unsigned int i = 0; i<count; i++)
387 for(unsigned int i = 0; i<nbBytes; i++)
400 388 {
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;
389 packet[i+offset] = data[i];
406 390 }
407 data[offset] = RMAPCommand->dataCRC;
391 packet[nbBytes+offset] = RMAPCommand->dataCRC;
408 392
409 //************
393 //****************
410 394 // SEND THE PACKET
411 395 result = USBSpaceWire_SendPacket(hDevice,
412 data,
396 packet,
413 397 totalSize,
414 398 BWAIT_1, &pIdentifier);
415 399 if (result != TRANSFER_SUCCESS)
@@ -425,42 +409,25 unsigned int StarDundee::WriteStarDundee
425 409 //**************
426 410 // Free the send
427 411 USBSpaceWire_FreeSend(hDevice, pIdentifier);
428 free(data);
412 free(packet);
429 413
430 414 if ( (commandCode == writeSingle_noVer_Rep) | (commandCode == writeInc_noVer_Rep) |
431 415 (commandCode == writeSingle_ver_rep) | (commandCode == writeInc_ver_rep) )
432 416 {
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)
417 // WAIT FOR THE RMAP REPLY PACKET
418 errorCode = this->receiveSPWPacket(1);
419 if (errorCode<=0)
439 420 {
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
421 emit appendToLog("WARNING === in function WriteBLOCK of rmapplugin *** RMAP packet reception failed with code " + QString::number(errorCode));
422 return 0;
448 423 }
449 if(properties.len != 8)
424 if(rmapPacketSize != 8)
450 425 {
451 emit appendToLog("WARNING === in function WRITE (with reply) of rmapplugin *** write reply format not compliant\n");
452 return 1;
426 console_message.sprintf("WARNING === in function WRITE (with reply) of rmapplugin *** write reply format not compliant\n");
427 emit appendToLog(console_message);
428 return 0;
453 429 }
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
430 switch (this->rmapPacket[3]) // byte 4 is the status byte in the reply
464 431 {
465 432 case 0:
466 433 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 0 Successfull");
@@ -514,16 +481,233 unsigned int StarDundee::WriteStarDundee
514 481 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: 12 Invalid target logical address");
515 482 break;
516 483 }
484 this->acquireRMAPSemaphore();
517 485 }
518 486 else
519 487 emit RMAP_write_reply_setText("reply to the write command required\nlast reply status: unavailable");
520 return count;
488
489 return nbBytes;
490 }
491
492 unsigned int StarDundee::ReadBLOCK(unsigned int nbBytes, unsigned int address)
493 {
494 int errorCode;
495 RMAP *RMAPCommand;
496 unsigned int dataLength;
497
498 //**********************
499 // Check the link status
500 if ( getLinkStatus( this->linkNumber_SPINBOX->value() ) == 0 )
501 {
502 this->Close();
503 emit appendToLog("WARNING === in function WriteSPW of StarDundee *** SPW link not running\n");
504 return 0;
505 }
506
507 //**********************
508 // SEND THE READ COMMAND
509 if (nbBytes > 4)
510 {
511 RMAPCommand = new RMAP(read_Inc,
512 rmapTargetLogicalAddress,
513 rmapSourceLogicalAddress,
514 address,
515 nbBytes,
516 NULL);
517 }
518 else
519 {
520 RMAPCommand = new RMAP(read_Single,
521 rmapTargetLogicalAddress,
522 rmapSourceLogicalAddress,
523 address,
524 nbBytes,
525 NULL);
526 }
527 result = USBSpaceWire_SendPacket(hDevice,
528 (unsigned char*) ((void*) &RMAPCommand->RMAPHeader),
529 sizeof(RMAPCommand->RMAPHeader),
530 BWAIT_1, &pIdentifier);
531 if (result != TRANSFER_SUCCESS) emit sendMessage("ERR *** ReadStarDundee *** ReadBLOCK *** sending the READ command ");
532 else emit sendMessage("OK *** ReadStarDundee *** ReadBLOCK *** sending the READ command");
533
534 //*********************************
535 // RECEIVE THE INCOMING RMAP PACKET
536 errorCode = this->receiveSPWPacket(1); // request ID 1 is for RMAP packet
537 if (errorCode<=0)
538 {
539 emit appendToLog("WARNING === in function ReadBLOCK of StarDundee *** RMAP packet reception failed with code " + QString::number(errorCode));
540 return 0;
541 }
542 dataLength = rmapPacketSize - RMAP_READ_REPLY_HEADER_LENGTH - RMAP_DATA_CRC_LENGTH;
543 if(dataLength != nbBytes)
544 {
545 emit appendToLog("WARNING === in function READ of StarDundee *** number of data received ("
546 +QString::number(dataLength)
547 +") not equal to number of data requested ("
548 +QString::number(nbBytes)
549 +")");
550 return 0;
551 }
552 return dataLength;
521 553 }
522 554
523 //******
524 // SLOTS
555 unsigned int StarDundee::WriteSPW(char *Value, unsigned int count, char targetLogicalAddress, char userApplication)
556 {
557 char protocoleIdentifier = 0x02;
558 char reserved = 0x00;
559 char *SPWData;
560 unsigned int totalSize;
561
562 if (count>248)
563 {
564 emit appendToLog("WARNING === in function WRITE of rmapplugin *** CCSDS packet size > 248 bytes\n");
565 return 1;
566 }
567
568 emit appendToLog("*** START *** Send CCSDS packet of "+ QString::number(count) + " byte(s)");
569
570 if ( getLinkStatus( this->linkNumber_SPINBOX->value() ) == 0 )
571 {
572 this->Close();
573 emit appendToLog("WARNING === in function WriteSPW of StarDundee *** SPW link not running\n");
574 return 1;
575 }
576
577 totalSize = count + 4;
578 SPWData = (char*) malloc(totalSize);
579 // SPW HEADER
580 SPWData[0] = targetLogicalAddress;
581 SPWData[1] = protocoleIdentifier;
582 SPWData[2] = reserved;
583 SPWData[3] = userApplication;
584 // CCSDS PACKET
585 for (unsigned int i = 0; i<count; i++)
586 {
587 SPWData[i+4] = Value[i];
588 }
589
590 //************
591 // SEND THE PACKET
592 result = USBSpaceWire_SendPacket(hDevice,
593 SPWData,
594 totalSize,
595 BWAIT_1, &pIdentifier);
596 if (result != TRANSFER_SUCCESS)
597 {
598 emit sendMessage("ERROR *** WriteSPW when sending packet of size "
599 + QString::number(totalSize) +", with code: " + QString::number(result));
600 USBSpaceWire_FreeSend(hDevice, pIdentifier);
601 free(SPWData);
602 return 0;
603 }
604 else emit sendMessage("OK *** WriteSPW when sending packet of size " + QString::number(totalSize));
605
606 //**************
607 // Free the send
608 USBSpaceWire_FreeSend(hDevice, pIdentifier);
609 free(SPWData);
610
611 emit appendToLog(QString("*** CCSDS packet sent"));
612
613 return 1;
614 }
615
616 unsigned int StarDundee::getLinkStatus(unsigned char link)
617 {
618 U32 statusControl, errorStatus, portType;
619 U32 linkStatus, operatingSpeed, outputPortConnection;
620 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
525 621
526 void StarDundee::updateCommandCode(RMAP_command_codes code)
622 // Read the link status control register
623 if (CFGSpaceWire_GetLinkStatusControl(hDevice, 1, &statusControl) != CFG_TRANSFER_SUCCESS)
624 {
625 emit appendToLog("Could not read link status control for link" + QString::number(link));
626 }
627 else
628 {
629 // Display the link status control register properties
630 CFGSpaceWire_LSPortType(statusControl, &portType);
631 if (portType == CFG_CONFIGURATION_PORT)
632 {
633 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
634 //emit appendToLog("Configuration port error status = " + QString::number(errorStatus));
635 }
636 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
637 {
638 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
639 //emit appendToLog("External port error status = " + QString::number(errorStatus));
640 }
641 else
642 {
643 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
644 //emit appendToLog("SpaceWire link error status = " + QString::number(errorStatus));
645 }
646 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
647 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
648 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
649 CFGSpaceWire_LSIsStart(statusControl, &isStart);
650 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
651 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
652 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
653 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
654 //emit appendToLog("The link state is = " + QString::number(linkStatus));
655 //emit appendToLog("The link is running = " + QString::number(isLinkRunning));
656 //emit appendToLog("The autostart bit is enabled = " + QString::number(isAutoStart));
657 //emit appendToLog("The start bit is enabled = " + QString::number(isStart));
658 //emit appendToLog("The link is disabled = " + QString::number(isDisabled));
659 //emit appendToLog("The tri-state bit is enabled = " + QString::number(isAutoStart));
660 //emit appendToLog("The operating speed is = " + QString::number(operatingSpeed));
661 //emit appendToLog("This port is currently connected to output port = " + QString::number(outputPortConnection));
662 }
663 if (linkStatus == 5) return 1;
664 else return 0;
665 }
666
667 int StarDundee::receiveSPWPacket(unsigned char requestID) // SLOT
527 668 {
528 this->commandCode = code;
669 unsigned int packetLength;
670 unsigned int nbBytes;
671 unsigned nPacketNum;
672 USB_SPACEWIRE_PACKET_PROPERTIES properties; // The properties of the read
673
674 if (requestID==1)
675 {
676 if (rmapPacketSEMAPHORE->available()) return rmapPacketSize;
677 }
678
679 //********************
680 // TRY TO RECEIVE DATA
681 nbBytes = qMax(RMAP_MAX_PACKET_LENGTH, CCSDS_MAX_PACKET_LENGTH); // maximum size of the packet to receive
682 nPacketNum = 1;
683 result = USBSpaceWire_ReadPackets(hDevice, spwPacket, nbBytes, nPacketNum, BWAIT_1, &properties, &pIdentifier);
684 if (result != TRANSFER_SUCCESS) emit sendMessage("Error: Could not receive the packet");
685 else
686 {
687 emit sendMessage("A packet of length " + QString::number(properties.len) + " has been successfully received");
688 USBSpaceWire_FreeRead(hDevice, pIdentifier); // Free the receive
689 }
690 packetLength = properties.len;
691
692 switch(spwPacket[1]) // byte 1 is the protocole identifier in the SPW packet
693 {
694 case 1: // 0x01 is the protocole identifier for RMAP packets
695 if (rmapPacketSEMAPHORE->available()!=0) return -3; // ERROR === previous RMAP packet not processed yet
696 for(unsigned int i=0; i<packetLength; i++) rmapPacket[i] = spwPacket[i];
697 rmapPacketSize = packetLength;
698 rmapPacketSEMAPHORE->release();
699 emit sendMessage("RMAP packet of size " + QString::number(packetLength) + " received");
700 return packetLength;
701
702 case 2: // 0x02 is the protocole identifier for CCSDS packets
703 if (ccsdsPacketSEMAPHORE->available()!=0) return -4; // ERROR === previous CCSDS packet not processed yet
704 for(unsigned int i=0; i<packetLength; i++) ccsdsPacket[i] = spwPacket[i];
705 ccsdsPacketSize = packetLength;
706 ccsdsPacketSEMAPHORE->release();
707 emit(ccsdsPacketAvailable(ccsdsPacket, packetLength));
708 return packetLength;
709 }
710 return 0;
529 711 }
712
713
@@ -8,6 +8,7
8 8 #include <QGridLayout>
9 9 #include <QSpinBox>
10 10 #include <QLabel>
11 #include <QSemaphore>
11 12 #include "rmapoperations.h"
12 13
13 14 #define BWAIT_0 0
@@ -19,54 +20,63 class StarDundee : public QWidget
19 20 public:
20 21 explicit StarDundee(QWidget *parent = 0);
21 22 ~StarDundee();
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);
23 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
24 unsigned int Read(unsigned int *Value,unsigned int count,unsigned int address=0);
25 unsigned int WriteStarDundee(unsigned int *Value, unsigned int count, unsigned int address);
26 unsigned int WriteSPW(char *Value, unsigned int count, char targetLogicalAddress, char userApplication);
27 unsigned int getLinkStatus(unsigned char link);
24 28
25 29 signals:
26 30 void sendMessage(QString message);
27 void starDundeeIsOpen(bool);
31 void isOpen(bool);
28 32 void RMAP_write_reply_setText(QString);
29 33 void appendToLog(QString);
34 void ccsdsPacketAvailable(unsigned char*, unsigned int);
30 35
31 36 public slots:
32 unsigned int OpenStarDundee();
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);
37 unsigned int Open();
38 unsigned int Close();
39 int receiveSPWPacket(unsigned char requestID);
40 void commandCodeHasChanged(RMAP_command_codes code) {this->commandCode = code;}
41 void targetHasChanged(int target) {rmapTargetLogicalAddress = (unsigned char) target;}
42 void sourceHasChanged(int target) {rmapSourceLogicalAddress = (unsigned char) target;}
39 43
40 44 private:
41 char rmapTargetLogicalAddress ;
42 char rmapSourceLogicalAddress ;
45 unsigned int GetRoutingTableEntry();
46 unsigned int WriteBLOCK(char *data,unsigned int nbBytes,unsigned int address=0);
47 unsigned int ReadBLOCK(unsigned int nbBytes,unsigned int address=0);
48 void acquireRMAPSemaphore() {rmapPacketSEMAPHORE->acquire();}
49 void acquireCCSDSSemaphore() {ccsdsPacketSEMAPHORE->acquire();}
43 50
44 QPushButton *sendPacket_BUTTON;
45 QPushButton *sendRMAPPacket_BUTTON;
46 QPushButton *readRMAPPacket_BUTTON;
47 QPushButton *getRoutingTableEntry_BUTTON;
51 unsigned char rmapTargetLogicalAddress ;
52 unsigned char rmapSourceLogicalAddress ;
53
54 RMAP_command_codes commandCode;
48 55
49 56 QLabel *usbDeviceNumber_LABEL;
50 57 QLabel *linkNumber_LABEL;
51 QLabel *routingTableEntry_LABEL;
52 58 QLabel *sourceLogicalAddress_LABEL;
53 59
54 60 QSpinBox *usbDeviceNumber_SPINBOX;
55 61 QSpinBox *linkNumber_SPINBOX;
56 QSpinBox *routingTableEntry_SPINBOX;
57 62 QSpinBox *sourceLogicalAddress_SPINBOX;
58 63
59 64 QGridLayout *connection_LAYOUT;
60 65
61 66 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 67 USB_SPACEWIRE_ID pIdentifier; // A pointer to a variable which will be set to contain a unique identifier for the send
64 68
65 RMAP_command_codes commandCode;
66
67 69 star_device_handle hDevice; // Handle to the SpaceWire device
68 70 USB_SPACEWIRE_STATUS result; // The result of the send operation
69 71
72 // Packet receiver
73 QSemaphore *rmapPacketSEMAPHORE;
74 QSemaphore *ccsdsPacketSEMAPHORE;
75 char* rmapPacket; // The buffer to receive RMAP READ packets
76 unsigned char *ccsdsPacket;
77 char *spwPacket;
78 unsigned int rmapPacketSize;
79 unsigned int ccsdsPacketSize;
70 80 };
71 81
72 82 #endif // STARDUNDEE_H
General Comments 0
You need to be logged in to leave comments. Login now