some changes to remove possible warnings

This commit is contained in:
Dhanya Maliakal 2017-05-11 14:41:07 +02:00
parent 95bf19a417
commit f53770a2fc
4 changed files with 45 additions and 30 deletions

View File

@ -206,7 +206,7 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
static pthread_mutex_t Mutex; static pthread_mutex_t Mutex;
/** GeneralData (Detector Data) object */ /** GeneralData (Detector Data) object */
static const GeneralData* generalData; const GeneralData* generalData;
/** Fifo structure */ /** Fifo structure */
Fifo* fifo; Fifo* fifo;
@ -241,10 +241,10 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
uint32_t* dynamicRange; uint32_t* dynamicRange;
/**Number of complete Packets caught for an entire acquisition (including all scans) */ /**Number of complete Packets caught for an entire acquisition (including all scans) */
uint64_t numTotalPacketsCaught; volatile uint64_t numTotalPacketsCaught;
/** Number of complete Packets caught for each real time acquisition (eg. for each scan) */ /** Number of complete Packets caught for each real time acquisition (eg. for each scan) */
uint64_t numPacketsCaught; volatile uint64_t numPacketsCaught;
/** Frame Number of First Frame of an entire Acquisition (including all scans) */ /** Frame Number of First Frame of an entire Acquisition (including all scans) */
uint64_t firstAcquisitionIndex; uint64_t firstAcquisitionIndex;

View File

@ -88,7 +88,7 @@ enum communicationProtocol{
genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) :
// portno(port_number), portno(port_number),
protocol(p), protocol(p),
is_a_server(0), is_a_server(0),
socketDescriptor(-1), socketDescriptor(-1),
@ -149,7 +149,7 @@ enum communicationProtocol{
*/ */
genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, const char *eth=NULL, int hsize=0): genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, const char *eth=NULL, int hsize=0):
//portno(port_number), portno(port_number),
protocol(p), protocol(p),
is_a_server(1), is_a_server(1),
socketDescriptor(-1), socketDescriptor(-1),
@ -161,8 +161,10 @@ enum communicationProtocol{
header_packet_size(hsize) header_packet_size(hsize)
{ {
memset(&serverAddress, 0, sizeof(serverAddress)); memset(&serverAddress, 0, sizeof(serverAddress));
memset(&clientAddress, 0, sizeof(clientAddress)); memset(&clientAddress, 0, sizeof(clientAddress));
/* // you can specify an IP address: */ /* // you can specify an IP address: */
/* // or you can let it automatically select one: */ /* // or you can let it automatically select one: */
/* myaddr.sin_addr.s_addr = INADDR_ANY; */ /* myaddr.sin_addr.s_addr = INADDR_ANY; */
@ -483,15 +485,17 @@ enum communicationProtocol{
static string ipToName(string ip) { static string ipToName(string ip) {
struct ifaddrs *addrs, *iap; struct ifaddrs *addrs, *iap;
struct sockaddr_in *sa; struct sockaddr_in *sa;
char buf[32];
char buf[32];
const int buf_len = sizeof(buf);
memset(buf,0,buf_len);
strcpy(buf,"none"); strcpy(buf,"none");
getifaddrs(&addrs); getifaddrs(&addrs);
for (iap = addrs; iap != NULL; iap = iap->ifa_next) { for (iap = addrs; iap != NULL; iap = iap->ifa_next) {
if (iap->ifa_addr && (iap->ifa_flags & IFF_UP) && iap->ifa_addr->sa_family == AF_INET) { if (iap->ifa_addr && (iap->ifa_flags & IFF_UP) && iap->ifa_addr->sa_family == AF_INET) {
sa = (struct sockaddr_in *)(iap->ifa_addr); sa = (struct sockaddr_in *)(iap->ifa_addr);
inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, sizeof(buf)); inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, buf_len);
if (ip==string(buf)) { if (ip==string(buf)) {
//printf("%s\n", iap->ifa_name); //printf("%s\n", iap->ifa_name);
strcpy(buf,iap->ifa_name); strcpy(buf,iap->ifa_name);
@ -507,6 +511,8 @@ enum communicationProtocol{
struct ifreq ifr; struct ifreq ifr;
int sock, j, k; int sock, j, k;
char mac[32]; char mac[32];
const int mac_len = sizeof(mac);
memset(mac,0,mac_len);
sock=getSock(inf,&ifr); sock=getSock(inf,&ifr);
@ -515,10 +521,10 @@ enum communicationProtocol{
return string("00:00:00:00:00:00"); return string("00:00:00:00:00:00");
} }
for (j=0, k=0; j<6; j++) { for (j=0, k=0; j<6; j++) {
k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X", k+=snprintf(mac+k, mac_len-k-1, j ? ":%02X" : "%02X",
(int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]); (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
} }
mac[sizeof(mac)-1]='\0'; mac[mac_len-1]='\0';
if(sock!=1){ if(sock!=1){
close(sock); close(sock);
@ -533,6 +539,8 @@ enum communicationProtocol{
struct ifreq ifr; struct ifreq ifr;
int sock; int sock;
char *p, addr[32]; char *p, addr[32];
const int addr_len = sizeof(addr);
memset(addr,0,addr_len);
sock=getSock(inf,&ifr); sock=getSock(inf,&ifr);
@ -541,8 +549,8 @@ enum communicationProtocol{
return string("0.0.0.0"); return string("0.0.0.0");
} }
p=inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr); p=inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr);
strncpy(addr,p,sizeof(addr)-1); strncpy(addr,p,addr_len-1);
addr[sizeof(addr)-1]='\0'; addr[addr_len-1]='\0';
if(sock!=1){ if(sock!=1){
close(sock); close(sock);
@ -616,6 +624,9 @@ enum communicationProtocol{
//normal //normal
nsending=packet_size; nsending=packet_size;
while(1){ while(1){
#ifdef VERYVERBOSE
cprintf(BLUE,"%d gonna listen\n", portno); fflush(stdout);
#endif
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
//break out of loop only if read one packets size or read didnt work (cuz of shutdown) //break out of loop only if read one packets size or read didnt work (cuz of shutdown)
if(nsent<=0 || nsent == packet_size) if(nsent<=0 || nsent == packet_size)
@ -697,6 +708,7 @@ enum communicationProtocol{
protected: protected:
int portno;
communicationProtocol protocol; communicationProtocol protocol;
int is_a_server; int is_a_server;
int socketDescriptor; int socketDescriptor;

View File

@ -26,11 +26,10 @@ uint64_t Listener::RunningMask(0x0);
pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER;
const GeneralData* Listener::generalData(0);
Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) : Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) :
ThreadObject(NumberofListeners), ThreadObject(NumberofListeners),
generalData(0),
fifo(f), fifo(f),
acquisitionStartedFlag(false), acquisitionStartedFlag(false),
measurementStartedFlag(false), measurementStartedFlag(false),
@ -64,8 +63,8 @@ Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act,
Listener::~Listener() { Listener::~Listener() {
if (udpSocket) delete udpSocket; if (udpSocket) delete udpSocket;
if (carryOverPacket) delete carryOverPacket; if (carryOverPacket) delete [] carryOverPacket;
if (listeningPacket) delete listeningPacket; if (listeningPacket) delete [] listeningPacket;
ThreadObject::DestroyThread(); ThreadObject::DestroyThread();
NumberofListeners--; NumberofListeners--;
} }
@ -146,11 +145,13 @@ void Listener::ResetParametersforNewMeasurement(){
firstMeasurementIndex = 0; firstMeasurementIndex = 0;
carryOverFlag = false; carryOverFlag = false;
if (carryOverPacket) if (carryOverPacket)
delete carryOverPacket; delete [] carryOverPacket;
carryOverPacket = new char[generalData->packetSize]; carryOverPacket = new char[generalData->packetSize];
memset(carryOverPacket,0,generalData->packetSize);
if (listeningPacket) if (listeningPacket)
delete listeningPacket; delete [] listeningPacket;
listeningPacket = new char[generalData->packetSize]; listeningPacket = new char[generalData->packetSize];
memset(listeningPacket,0,generalData->packetSize);
} }
@ -191,19 +192,19 @@ int Listener::SetThreadPriority(int priority) {
} }
int Listener::CreateUDPSockets() { int Listener::CreateUDPSockets() {
ShutDownUDPSocket();
if (!(*activated)) if (!(*activated))
return OK; return OK;
//if eth is mistaken with ip address //if eth is mistaken with ip address
if (strchr(eth,'.') != NULL){ if (strchr(eth,'.') != NULL){
strcpy(eth,""); strncpy(eth,"", MAX_STR_LENGTH);
} }
if(!strlen(eth)){ if(!strlen(eth)){
FILE_LOG(logWARNING) << "eth is empty. Listening to all"; FILE_LOG(logWARNING) << "eth is empty. Listening to all";
} }
ShutDownUDPSocket();
udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP, udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP,
generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize); generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize);
int iret = udpSocket->getErrorStatus(); int iret = udpSocket->getErrorStatus();
@ -247,7 +248,7 @@ void Listener::ThreadExecution() {
} }
//get data //get data
if (*status != TRANSMITTING) { if (*status != TRANSMITTING && udpSocket) {
if (*activated) if (*activated)
rc = ListenToAnImage(buffer); rc = ListenToAnImage(buffer);
else else
@ -255,7 +256,7 @@ void Listener::ThreadExecution() {
} }
//done acquiring //done acquiring
if (*status == TRANSMITTING || ((!(*activated)) && (rc == 0))) { if ((*status == TRANSMITTING) || ( (!(*activated)) && (rc == 0)) ) {
StopListening(buffer); StopListening(buffer);
return; return;
} }
@ -288,13 +289,13 @@ void Listener::StopListening(char* buf) {
fifo->PushAddress(buf); fifo->PushAddress(buf);
StopRunning(); StopRunning();
#ifdef VERBOSE #ifdef VERBOSE
cprintf(GREEN,"%d: Listening Packets (%d) : %d\n", index, *udpPortNumber, numPacketsCaught); cprintf(GREEN,"%d: Listening Packets (%u) : %llu\n", index, *udpPortNumber, numPacketsCaught);
printf("%d: Listening Completed\n", index); printf("%d: Listening Completed\n", index);
#endif #endif
} }
/* buf includes the header */ /* buf includes the fifo header and packet header */
uint32_t Listener::ListenToAnImage(char* buf) { uint32_t Listener::ListenToAnImage(char* buf) {
uint32_t rc = 0; uint32_t rc = 0;
uint64_t fnum = 0, bid = 0; uint64_t fnum = 0, bid = 0;
@ -345,8 +346,10 @@ uint32_t Listener::ListenToAnImage(char* buf) {
while ( isHeaderEmpty || (pnum < (generalData->packetsPerFrame-1))) { while ( isHeaderEmpty || (pnum < (generalData->packetsPerFrame-1))) {
//listen to new packet //listen to new packet
int curr_rc = 0;
int curr_rc = udpSocket->ReceiveDataOnly(listeningPacket); if (udpSocket){
curr_rc = udpSocket->ReceiveDataOnly(listeningPacket);
}
if(curr_rc <= 0) { if(curr_rc <= 0) {
if (rc <= 0) return 0; //empty image if (rc <= 0) return 0; //empty image
return generalData->imageSize; //empty packet now, but not empty image return generalData->imageSize; //empty packet now, but not empty image
@ -359,7 +362,7 @@ uint32_t Listener::ListenToAnImage(char* buf) {
generalData->GetHeaderInfo(index, listeningPacket, *dynamicRange, fnum, pnum, snum, bid); generalData->GetHeaderInfo(index, listeningPacket, *dynamicRange, fnum, pnum, snum, bid);
lastCaughtFrameIndex = fnum; lastCaughtFrameIndex = fnum;
#ifdef VERBOSE #ifdef VERBOSE
if (!index) //if (!index)
cprintf(GREEN,"Listening %d: fnum:%lu, pnum:%d\n", index,fnum, pnum); cprintf(GREEN,"Listening %d: fnum:%lu, pnum:%d\n", index,fnum, pnum);
#endif #endif
if (!measurementStartedFlag) if (!measurementStartedFlag)

View File

@ -553,7 +553,7 @@ void UDPStandardImplementation::startReadout(){
if(activated){ if(activated){
//current packets caught //current packets caught
int totalP = 0,prev=-1; volatile int totalP = 0,prev=-1;
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetTotalPacketsCaught(); totalP += (*it)->GetTotalPacketsCaught();
@ -563,10 +563,11 @@ void UDPStandardImplementation::startReadout(){
//wait as long as there is change from prev totalP, //wait as long as there is change from prev totalP,
while(prev != totalP){ while(prev != totalP){
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d PrevBuffer:%d currentBuffer:%d\n",prev,totalP,prevReceivedInBuffer,currentReceivedInBuffer); cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d\n",
prev,totalP);
#endif #endif
//usleep(2*1000*1000); usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000);
usleep(5*1000);/* Need to find optimal time **/ usleep(5*1000);/* Need to find optimal time **/
prev = totalP; prev = totalP;
@ -588,7 +589,6 @@ void UDPStandardImplementation::startReadout(){
FILE_LOG(logINFO) << "Status: Transmitting"; FILE_LOG(logINFO) << "Status: Transmitting";
} }
//shut down udp sockets so as to make listeners push dummy (end) packets for processors //shut down udp sockets so as to make listeners push dummy (end) packets for processors
shutDownUDPSockets(); shutDownUDPSockets();
} }