##// 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,9 +162,16 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);
165 if(SPWpacket!=NULL)
166 {
164 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
167 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
165 emit sendSPWPacket(SPWpacket,size);
168 emit sendSPWPacket(SPWpacket,size);
166 }
169 }
170 else
171 {
172 //TODO print some message
173 }
174 }
167 }
175 }
168
176
169 void SpwTcpPacketServer::readReady()
177 void SpwTcpPacketServer::readReady()
@@ -186,11 +194,23 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);
204 if(SPWpacket!=NULL)
205 {
191 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
206 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
192 emit sendSPWPacket(SPWpacket,size);
207 emit sendSPWPacket(SPWpacket,size);
193 }
208 }
209 else
210 {
211 //TODO print some message
212 }
213 }
194 }while(soc->bytesAvailable()!=0);
214 }while(soc->bytesAvailable()!=0);
195 }
215 }
196 }
216 }
General Comments 0
You need to be logged in to leave comments. Login now