/*! * \file client.c * * \author Christos Choutouridis AEM:8997 */ #include #include #include #include #include #include #include #include #include "client.h" static bool_t ping (devAEM_t dev) { char_t cmd[72]; devIP_t ip = AEM2ip (dev); // ask host to ping and make a little pre-process before take the answer sprintf (cmd, "test $(ping -c1 -w%d %u.%u.%u.%u| grep received |cut -d' ' -f4) = 1", settings.pingTimeout, ip.A, ip.B, ip.C, ip.D ); return (system(cmd) == 0) ? true:false; } static size_t seeker (void) { size_t cnt =0; // count devices on range log_debug ("Debug: Pinging devices...\n"); for (int i=0 ; itext, strlen(msg->text), MSG_CONFIRM) == -1) { ret = false; log_debug ("Debug: Sending failed\n"); break; } log_debug ("Debug: Sending succeed\n"); } while (0); close (sock); log_debug ("Debug: Closing socket\n"); return ret; } static status_t client (void) { msg_t msg; // new message buffer while (true) { sleep (settings.msgInterval); // Idle until the time comes memset ((void*)&msg, 0, sizeof (msg)); // create a new message cMsg_make (&msg.cMsg); msg.sender = settings.me; log_debug ("Debug: Message created for %d\n", msg.cMsg.to); statsUpdateCreate (&msg); msgList_acquire (); // try to lock resources mIter_t at = msgList_add (&msgList, &msg); // Add message to msgList log_debug ("Debug: Message added to msgList at %d\n", at); if (!seeker ()) { // If we are alone skip the rest msgList_release (); // but unlock resources first continue; } log_debug ("Debug: Devices found on range\n"); mIter_t it = msgList_begin (&msgList); // get a message iterator // begin with old messages first // for each message -> for each recipient for (size_t i=0 ; i