##// END OF EJS Templates
Some cleaning.
jeandet -
r59:e7cdc214d72a default
parent child
Show More
@@ -23,6 +23,7
23 #include "ui_spwtcppacketserver.h"
23 #include "ui_spwtcppacketserver.h"
24 #include <QNetworkInterface>
24 #include <QNetworkInterface>
25 #include <QByteArray>
25 #include <QByteArray>
26 #include <socexplorerengine.h>
26
27
27 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
28 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
28 QWidget(parent),
29 QWidget(parent),
@@ -161,8 +162,15 void SpwTcpPacketServer::sendSPWPacketUs
161 + ( (unsigned char) data[2] ) * 256
162 + ( (unsigned char) data[2] ) * 256
162 + (unsigned char) data[3];
163 + (unsigned char) data[3];
163 char* SPWpacket = (char*)malloc(size);
164 char* SPWpacket = (char*)malloc(size);
164 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
165 if(SPWpacket!=NULL)
165 emit sendSPWPacket(SPWpacket,size);
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 onePacketReceived();
194 onePacketReceived();
187 if(data[0]==(char)0) // Protocole = 0 => Host to SpaceWire packet transmission
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 char* SPWpacket = (char*)malloc(size);
203 char* SPWpacket = (char*)malloc(size);
191 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
204 if(SPWpacket!=NULL)
192 emit sendSPWPacket(SPWpacket,size);
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 }while(soc->bytesAvailable()!=0);
214 }while(soc->bytesAvailable()!=0);
195 }
215 }
General Comments 0
You need to be logged in to leave comments. Login now