@@ -23,6 +23,7 | |||
|
23 | 23 | #include "ui_spwtcppacketserver.h" |
|
24 | 24 | #include <QNetworkInterface> |
|
25 | 25 | #include <QByteArray> |
|
26 | #include <socexplorerengine.h> | |
|
26 | 27 | |
|
27 | 28 | SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) : |
|
28 | 29 | QWidget(parent), |
@@ -161,8 +162,15 void SpwTcpPacketServer::sendSPWPacketUs | |||
|
161 | 162 | + ( (unsigned char) data[2] ) * 256 |
|
162 | 163 | + (unsigned char) data[3]; |
|
163 | 164 | char* SPWpacket = (char*)malloc(size); |
|
164 | memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet | |
|
165 | emit sendSPWPacket(SPWpacket,size); | |
|
165 | if(SPWpacket!=NULL) | |
|
166 | { | |
|
167 | memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet | |
|
168 | emit sendSPWPacket(SPWpacket,size); | |
|
169 | } | |
|
170 | else | |
|
171 | { | |
|
172 | //TODO print some message | |
|
173 | } | |
|
166 | 174 | } |
|
167 | 175 | } |
|
168 | 176 | |
@@ -186,10 +194,22 void SpwTcpPacketServer::readReady() | |||
|
186 | 194 | onePacketReceived(); |
|
187 | 195 | if(data[0]==(char)0) // Protocole = 0 => Host to SpaceWire packet transmission |
|
188 | 196 | { |
|
189 | int size = (data[1]*256*256) + (data[2]*256) + data[3]; | |
|
197 | // TODO -> change heap allocation to stack risk of memory leak | |
|
198 | // if no slot conected to sendSPWPacket signal or segfault if more | |
|
199 | // than one receiver. | |
|
200 | int size = ( (unsigned char) data[1] ) * 256 * 256 | |
|
201 | + ( (unsigned char) data[2] ) * 256 | |
|
202 | + (unsigned char) data[3]; | |
|
190 | 203 | char* SPWpacket = (char*)malloc(size); |
|
191 | memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet | |
|
192 | emit sendSPWPacket(SPWpacket,size); | |
|
204 | if(SPWpacket!=NULL) | |
|
205 | { | |
|
206 | memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet | |
|
207 | emit sendSPWPacket(SPWpacket,size); | |
|
208 | } | |
|
209 | else | |
|
210 | { | |
|
211 | //TODO print some message | |
|
212 | } | |
|
193 | 213 | } |
|
194 | 214 | }while(soc->bytesAvailable()!=0); |
|
195 | 215 | } |
General Comments 0
You need to be logged in to leave comments.
Login now