@@ -205,7 +205,7 @@ static void client (void) { | |||||
msg_t msg; // new message buffer | msg_t msg; // new message buffer | ||||
while (true) { | while (true) { | ||||
// Idle until the time comes | // Idle until the time comes | ||||
sleep (settings.msgInterval + (rand()%settings.msgRand)); | |||||
sleep (settings.msgInterval + (rand()%(5*settings.msgInterval))); | |||||
memset ((void*)&msg, 0, sizeof (msg)); // create a new message | memset ((void*)&msg, 0, sizeof (msg)); // create a new message | ||||
cMsg_make (&msg.cMsg); | cMsg_make (&msg.cMsg); | ||||
msg.sender = settings.me; | msg.sender = settings.me; | ||||
@@ -345,7 +345,7 @@ bool_t cMsg_equal (cMsg_t* m1, cMsg_t* m2) { | |||||
if (m1->from != m2->from) return false; | if (m1->from != m2->from) return false; | ||||
if (m1->to != m2->to) return false; | if (m1->to != m2->to) return false; | ||||
if (m1->ts != m2->ts) return false; | if (m1->ts != m2->ts) return false; | ||||
if (strncmp (m1->text, m2->text, sizeof(m1->text))) | |||||
if (strncmp (m1->text, m2->text, strlen(m1->text))) | |||||
return false; | return false; | ||||
return true; | return true; | ||||
} | } | ||||
@@ -34,10 +34,23 @@ static void listen_handler (devAEM_t dev, char_t* buffer, size_t size) { | |||||
mIter_t myCopy = msgList_find (&msgList, &msg); // try to find message in msgList | mIter_t myCopy = msgList_find (&msgList, &msg); // try to find message in msgList | ||||
if (myCopy == -1) { | if (myCopy == -1) { | ||||
// We don't have a copy, accept and store it | // We don't have a copy, accept and store it | ||||
msgList_add (&msgList, &msg); | |||||
mIter_t slot = msgList_add (&msgList, &msg); | |||||
msgList_release (); | msgList_release (); | ||||
statsUpdateIn (&msg, false); // message process | statsUpdateIn (&msg, false); // message process | ||||
log_msg_in (&msg); // log | log_msg_in (&msg); // log | ||||
// Processing... | |||||
devList_acquire(); | |||||
dIter_t d = devList_getIter (dev); | |||||
dIter_t f = devList_getIter (msg.cMsg.from); | |||||
devList_release(); | |||||
msgList_acquire (); | |||||
// Do not echo message to sender, he already has it | |||||
msgList.m[slot].recipients[d] = true; | |||||
// don't push back message to creator, he already has it | |||||
msgList.m[slot].recipients[f] = true; | |||||
msgList_release (); | |||||
} | } | ||||
else { | else { | ||||
// We have a copy | // We have a copy | ||||
@@ -45,18 +58,6 @@ static void listen_handler (devAEM_t dev, char_t* buffer, size_t size) { | |||||
statsUpdateIn (&msg, true); // message process | statsUpdateIn (&msg, true); // message process | ||||
log_debug ("Debug: Duplicate message from: %d\n", msg.sender); | log_debug ("Debug: Duplicate message from: %d\n", msg.sender); | ||||
} | } | ||||
// Processing... | |||||
devList_acquire(); | |||||
dIter_t d = devList_getIter (dev); | |||||
dIter_t f = devList_getIter (msg.cMsg.from); | |||||
devList_release(); | |||||
msgList_acquire (); | |||||
// Do not echo message to sender, he already has it | |||||
msgList.m[myCopy].recipients[d] = true; | |||||
// don't push back message to creator, he already has it | |||||
msgList.m[myCopy].recipients[f] = true; | |||||
msgList_release (); | |||||
} | } | ||||
/*! | /*! | ||||
@@ -30,7 +30,7 @@ stats_t stats; //!< Statistical data | |||||
/*! | /*! | ||||
* CLI short options | * CLI short options | ||||
*/ | */ | ||||
const char *short_opt = "v:i:p:s:w:th"; | |||||
const char *short_opt = "v:i:m:p:s:w:th"; | |||||
/*! | /*! | ||||
* CLI long options | * CLI long options | ||||
@@ -38,6 +38,7 @@ const char *short_opt = "v:i:p:s:w:th"; | |||||
const struct option long_opt[] = { | const struct option long_opt[] = { | ||||
{"outlevel", required_argument, NULL, 'v'}, | {"outlevel", required_argument, NULL, 'v'}, | ||||
{"interval", required_argument, NULL, 'i'}, | {"interval", required_argument, NULL, 'i'}, | ||||
{"msginterval", required_argument, NULL, 'm'}, | |||||
{"pingtimeout",required_argument, NULL, 'p'}, | {"pingtimeout",required_argument, NULL, 'p'}, | ||||
{"sendtimeout",required_argument, NULL, 's'}, | {"sendtimeout",required_argument, NULL, 's'}, | ||||
{"who", required_argument, NULL, 'w'}, | {"who", required_argument, NULL, 'w'}, | ||||
@@ -70,6 +71,7 @@ int parse_args (settings_t *s, int argc, char const *argv[]) { | |||||
if (s->outLevel < OUTLEVEL_0) s->outLevel = OUTLEVEL_0; | if (s->outLevel < OUTLEVEL_0) s->outLevel = OUTLEVEL_0; | ||||
break; | break; | ||||
case 'i': s->seekerInterval = atoi (optarg); break; | case 'i': s->seekerInterval = atoi (optarg); break; | ||||
case 'm': s->msgInterval = atoi (optarg); break; | |||||
case 'p': s->pingTimeout = atoi (optarg); break; | case 'p': s->pingTimeout = atoi (optarg); break; | ||||
case 's': s->sendTimeout.tv_sec = atoi (optarg); break; | case 's': s->sendTimeout.tv_sec = atoi (optarg); break; | ||||
case 'w': s->me = atoi (optarg); break; | case 'w': s->me = atoi (optarg); break; | ||||
@@ -78,6 +80,7 @@ int parse_args (settings_t *s, int argc, char const *argv[]) { | |||||
printf ("Syntax:\nrtes_final [-t] [-v num] [-i num] [-p num] [-s num] [-w num]\n\n"); | printf ("Syntax:\nrtes_final [-t] [-v num] [-i num] [-p num] [-s num] [-w num]\n\n"); | ||||
printf ("-v, --outlevel num: Change the verbosity of the program, num can be 0, 1 or 2\n"); | printf ("-v, --outlevel num: Change the verbosity of the program, num can be 0, 1 or 2\n"); | ||||
printf ("-i, --interval sec: Set the interval of the seeker in [sec]\n"); | printf ("-i, --interval sec: Set the interval of the seeker in [sec]\n"); | ||||
printf ("-m, --msginterval sec: Set the interval of the client in [sec]\n"); | |||||
printf ("-p, --pingtimeout sec: Set the ping timeout in [sec]\n"); | printf ("-p, --pingtimeout sec: Set the ping timeout in [sec]\n"); | ||||
printf ("-s, --sendtimeout sec: Set the connect/send timeout in [sec]\n"); | printf ("-s, --sendtimeout sec: Set the connect/send timeout in [sec]\n"); | ||||
printf ("-w, --who AEM: Select the AEM of the device\n"); | printf ("-w, --who AEM: Select the AEM of the device\n"); | ||||
@@ -19,20 +19,12 @@ | |||||
/*! | /*! | ||||
* AEM list | * AEM list | ||||
*/ | */ | ||||
#define AEMLIST_SIZE (10) | |||||
#define AEMLIST { \ | |||||
7700, \ | |||||
8261, \ | |||||
8765, \ | |||||
8844, \ | |||||
8880, \ | |||||
8861, \ | |||||
8877, \ | |||||
8941, \ | |||||
8934, \ | |||||
8997 \ | |||||
} | |||||
#define AEMLIST_SIZE (6) | |||||
#define AEMLIST_0 { 7700, 8261, 8765, 8844, 8880, 8861, 8877, 8941, 8934, 8997 } | |||||
#define AEMLIST_1 { 8918, 8929, 8997, 8880, 8844, 8861 } | |||||
#define AEMLIST AEMLIST_1 | |||||
/*! | /*! | ||||
* General options | * General options | ||||
@@ -219,7 +211,6 @@ typedef struct { | |||||
uint16_t port; | uint16_t port; | ||||
time_t seekerInterval; | time_t seekerInterval; | ||||
time_t msgInterval; | time_t msgInterval; | ||||
time_t msgRand; | |||||
outLevel_en outLevel; | outLevel_en outLevel; | ||||
time_t pingTimeout; | time_t pingTimeout; | ||||
timeval_t sendTimeout; | timeval_t sendTimeout; | ||||
@@ -233,11 +224,10 @@ extern settings_t settings; | |||||
.port = 2288, \ | .port = 2288, \ | ||||
.seekerInterval = 30, \ | .seekerInterval = 30, \ | ||||
.msgInterval = 60, \ | .msgInterval = 60, \ | ||||
.msgRand = 240, \ | |||||
.outLevel = OUTLEVEL_1, \ | .outLevel = OUTLEVEL_1, \ | ||||
.pingTimeout = 1, \ | .pingTimeout = 1, \ | ||||
.sendTimeout = {4, 0}, \ | .sendTimeout = {4, 0}, \ | ||||
.trackTime = true \ | |||||
.trackTime = false \ | |||||
} | } | ||||
//! @} | //! @} | ||||