/*! * \file client.c * This file contains all the client and device search functionalities. * * \author Christos Choutouridis AEM:8997 */ #include #include #include #include #include #include #include #include #include "client.h" /*! * Transmit buffer */ static char_t tx_buffer [MSG_TEXT_SIZE]; /*! * Ping functionality. We use system and pass a test command in order to * find out if a particular device is on range. * @param dev The device to ping * @return The status of the operation * @arg true The device was on range and replyed to our ping * @arg false The device wasn't on range */ 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", (int)settings.pingTimeout, ip.A, ip.B, ip.C, ip.D ); return (system(cmd) == 0) ? true:false; } /*! * Search for devices on range and mark the time of first and last sight * @return The number of devices on range */ static size_t seeker (void) { size_t cnt =0; // count devices on range sleep (settings.seekerInterval); log_debug ("Debug: Pinging devices...\n"); devList_acquire (); for (int i=0 ; i for each recipient for (size_t i=0 ; i