##// END OF EJS Templates
Working Snapshot
Jeandet Alexis -
r1:ca5cf5cd2804 Working Snapshot default
parent child
Show More
@@ -3,7 +3,7
3 3
4 4 #include <QObject>
5 5 #include <socexplorerplugin.h>
6 #define RMAP_MAX_XFER_SIZE 3000 //slightly less than 16kBytes
6 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
7 7 #include <spw.h>
8 8
9 9 class abstractSpwBridge : public QObject
@@ -27,54 +27,66 int stardundeeSPW_USB::pushRMAPPacket(ch
27 27
28 28 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
29 29 {
30 //Add transactionID!
31 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE)+1];
30 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
32 31 writeBuffer[0]=1;//Link number
33 32 int transactionID = 0;
34 33 int written=0;
35 34 SocExplorerEngine::message(this->plugin,"Enter Write function");
35 QProgressBar* progress=NULL;
36 if(count>RMAP_MAX_XFER_SIZE)
37 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
36 38 //Quite stupide loop, I guess that I always get the number of byte I asked for!
37 for(;count>=RMAP_MAX_XFER_SIZE;count-=RMAP_MAX_XFER_SIZE)
39 while(count>=RMAP_MAX_XFER_SIZE)
38 40 {
39 41 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
40 42 {
41 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char) ((unsigned int) Value[written+i]>>24);
42 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char) ((unsigned int) Value[written+i]>>16);
43 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char) ((unsigned int) Value[written+i]>>8);
44 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char) ((unsigned int) Value[written+i]);
43 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
44 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
45 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
46 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
45 47 }
46 RMAP_build_tx_request_header(254,2,1,transactionID,address+written,RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
48 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
47 49 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
48 50 written+=RMAP_MAX_XFER_SIZE;
51 count-=RMAP_MAX_XFER_SIZE;
52 progress->setValue(written);
53 qApp->processEvents();
49 54 }
50 55 if(count>0)
51 56 {
52 57 for(int i=0;i<((int)count);i++)
53 58 {
54 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char) ((unsigned int) Value[written+i]>>24);
55 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char) ((unsigned int) Value[written+i]>>16);
56 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char) ((unsigned int) Value[written+i]>>8);
57 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char) ((unsigned int) Value[written+i]);
59 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
60 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
61 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
62 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
58 63 }
59 RMAP_build_tx_request_header(254,2,1,transactionID,address+written,count*4,writeBuffer+1);
64 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
60 65 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
61 // QHexEdit* viewer = new QHexEdit();
62 // viewer->setData(QByteArray(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4)+1));
63 // viewer->show();
64 66 written+=count;
67 if(progress!=NULL)
68 {
69 progress->setValue(written);
70 qApp->processEvents();
71 }
72 }
73 if(progress!=NULL)
74 {
75 SocExplorerEngine::deleteProgressBar(progress);
65 76 }
66 77 return written;
67 78 }
68 79
69 80 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
70 81 {
71 //Add transactionID!
72 82 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
73 83 char* RMAP_AnswerBuffer;
74 84 requestBuffer[0]=1;//Link number
75 85 int transactionID = 0;
76 86 int read=0;
77 // SocExplorerEngine::message(this->plugin,"Enter read function");
87 QProgressBar* progress=NULL;
88 if(count>RMAP_MAX_XFER_SIZE)
89 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
78 90 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
79 91
80 92 //Quite stupide loop, I guess that I always get the number of byte I asked for!
@@ -85,13 +97,18 unsigned int stardundeeSPW_USB::Read(uns
85 97 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
86 98 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
87 99 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
88 for(int i=0;i<(len/4);i++)
100 for(int i=0;i<((len-13)/4);i++)
89 101 {
90 Value[read+i]=((unsigned int)(RMAP_AnswerBuffer[i])<<24) + ((unsigned int)(RMAP_AnswerBuffer[i+1])<<16) + ((unsigned int)(RMAP_AnswerBuffer[i+2])<<8) + ((unsigned int)(RMAP_AnswerBuffer[i+3]));
102 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
103 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
104 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
105 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
91 106 }
92 107 free(RMAP_AnswerBuffer);
93 108 read+=RMAP_MAX_XFER_SIZE;
94 109 count-=RMAP_MAX_XFER_SIZE;
110 progress->setValue(read);
111 qApp->processEvents();
95 112 }
96 113 if((int)count>0)
97 114 {
@@ -104,12 +121,24 unsigned int stardundeeSPW_USB::Read(uns
104 121 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
105 122 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
106 123 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
107 for(int i=0;i<(len/4);i++)
124 for(int i=0;i<((len-13)/4);i++)
108 125 {
109 Value[read+i]=((unsigned int)(RMAP_AnswerBuffer[i])<<24) + ((unsigned int)(RMAP_AnswerBuffer[i+1])<<16) + ((unsigned int)(RMAP_AnswerBuffer[i+2])<<8) + ((unsigned int)(RMAP_AnswerBuffer[i+3]));
126 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
127 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
128 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
129 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
110 130 }
111 131 free(RMAP_AnswerBuffer);
112 132 read+=count;
133 if(progress!=NULL)
134 {
135 progress->setValue(read);
136 qApp->processEvents();
137 }
138 }
139 if(progress!=NULL)
140 {
141 SocExplorerEngine::deleteProgressBar(progress);
113 142 }
114 143 return read;
115 144 }
@@ -140,7 +169,7 void stardundeeSPW_USB_Manager::run()
140 169 USB_SPACEWIRE_ID pIdentifier=NULL;
141 170 USB_SPACEWIRE_STATUS stat;
142 171 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
143 char buffer[RMAP_MAX_XFER_SIZE*4];
172 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
144 173 while (!this->isInterruptionRequested())
145 174 {
146 175 if(this->connected)
@@ -150,7 +179,7 void stardundeeSPW_USB_Manager::run()
150 179 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
151 180 {
152 181 SocExplorerEngine::message(this->plugin,"Got packet");
153 stat = USBSpaceWire_ReadPackets(hDevice, buffer, RMAP_MAX_XFER_SIZE*4,1, 1, &properties, &pIdentifier);
182 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
154 183 if (stat == TRANSFER_SUCCESS)
155 184 {
156 185 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
@@ -163,16 +192,27 void stardundeeSPW_USB_Manager::run()
163 192 {
164 193 SocExplorerEngine::message(this->plugin,"Got RMAP packet");
165 194 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
166 char* packetbuffer = (char*)malloc(properties.len-13);
167 memcpy(packetbuffer,buffer+12,properties.len-13);
168 USBSpaceWire_FreeRead(hDevice, pIdentifier);
169 pIdentifier = NULL;
170 handleMutex->unlock();
171 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
172 RMAP_AnswersMtx->lock();
173 RMAP_Answers.append(packet);
174 RMAP_AnswersMtx->unlock();
175 RMAP_AnswersSem->release();
195 if(properties.len>8)
196 {
197 char* packetbuffer = (char*)malloc(properties.len);
198 memcpy(packetbuffer,buffer,properties.len);
199 USBSpaceWire_FreeRead(hDevice, pIdentifier);
200 pIdentifier = NULL;
201 handleMutex->unlock();
202 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
203 RMAP_AnswersMtx->lock();
204 RMAP_Answers.append(packet);
205 RMAP_AnswersMtx->unlock();
206 RMAP_AnswersSem->release();
207
208 }
209 else //it's a RMAP write response
210 {
211 USBSpaceWire_FreeRead(hDevice, pIdentifier);
212 pIdentifier = NULL;
213 handleMutex->unlock();
214 }
215
176 216 }
177 217 else //any non-rmap packet will be pushed to the network
178 218 {
General Comments 0
You need to be logged in to leave comments. Login now