diff --git a/gateway/gateway.c b/gateway/gateway.c index b3a004e..b635f89 100644 --- a/gateway/gateway.c +++ b/gateway/gateway.c @@ -50,13 +50,20 @@ static void bsort(int arr[][2]) { static void init_power_received(struct unicast_conn *c, const linkaddr_t *from) { int cow_id = from->u8[0]; - int *test = (int *)packetbuf_dataptr(); + int * test = (int *)packetbuf_dataptr(); + int i; + printf("Init message received from cow %d :", cow_id); + for (i = 0; i < NUMBER_OF_COWS; i++) { - RSSIarray[cow_id - 1][i] = *(test + i); - printf("Init message received from cow %d : %d \n",from->u8[0], *(test + i)); + RSSIarray[cow_id - 2][i] = *(test + i); + printf("%d -> %d ; ", i, *(test + i)); } - + printf("\n"); + + char *ack = "Ack"; + packetbuf_copyfrom(ack, sizeof(ack)); + unicast_send(c, from); } static const struct unicast_callbacks unicast_callbacks = {init_power_received}; @@ -66,10 +73,10 @@ PROCESS_THREAD (herd_monitor_gateway, ev, data) { PROCESS_EXITHANDLER(unicast_close(&uc);) - static struct etimer et; PROCESS_BEGIN(); - + + static struct etimer et; unicast_open(&uc, 146, &unicast_callbacks); printf("GATEWAY is waiting....\n"); diff --git a/node/node.c b/node/node.c index f22b318..eb6a398 100644 --- a/node/node.c +++ b/node/node.c @@ -20,10 +20,11 @@ PROCESS (herd_monitor_node, "Herd monitor - node"); AUTOSTART_PROCESSES (&herd_monitor_node); -static int8_t neighbour_list[NUMBER_OF_COWS + 1]; +static int neighbour_list[NUMBER_OF_COWS + 1]; static void reset_neighbour_list() { + printf("Reseting list... \n"); int i; for (i = 0; i < NUMBER_OF_COWS; i++) { @@ -35,12 +36,12 @@ static void reset_neighbour_list() static void init_broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) { int cow_id = from->u8[0]; - int8_t rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI); - neighbour_list[cow_id - 1] = rssi; + int rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI); + neighbour_list[cow_id - 2] = rssi; - /*printf("broadcast message received from cow %d.%d with rssi %d : '%s'\n", - from->u8[0],from->u8[1], rssi, (char *)packetbuf_dataptr()); - */ + printf("broadcast message received from cow %d with rssi %d \n", + cow_id, rssi); + } static void init_send_to_gateway(struct unicast_conn *c) @@ -48,7 +49,7 @@ static void init_send_to_gateway(struct unicast_conn *c) static linkaddr_t addr; addr.u8[0] = 1; addr.u8[1] = 0; - packetbuf_copyfrom(neighbour_list, 5); + packetbuf_copyfrom(neighbour_list, sizeof(neighbour_list)); unicast_send(c, &addr); printf("Neighbour list sent to the gateway\n"); @@ -61,16 +62,23 @@ static void init_ack_received() init_timedout = false; } +static void test_list() +{ + printf("List: "); + int i; + for (i = 0; i < 15; i++) { + printf("%d -> %d;", i, neighbour_list[i]); + } + printf("\n"); +} + PROCESS_THREAD (herd_monitor_node, ev, data) { static struct etimer et; - - reset_neighbour_list(); - - //PROCESS_EXITHANDLER(broadcast_close(&broadcast);) PROCESS_BEGIN(); + reset_neighbour_list(); /********************************************************** @@ -94,7 +102,6 @@ PROCESS_THREAD (herd_monitor_node, ev, data) } broadcast_close(&broadcast); printf("initialization broadcasting completed\n"); - // WAIT 5 SECONDS TO SEND GATHERED RSSI VALUES etimer_set(&et, CLOCK_SECOND * 5); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); @@ -104,16 +111,15 @@ PROCESS_THREAD (herd_monitor_node, ev, data) PROCESS_EXITHANDLER(unicast_close(&uc);) unicast_open(&uc, 146, &unicast_callbacks); - static linkaddr_t addr; - addr.u8[0] = 1; - addr.u8[1] = 0; - packetbuf_copyfrom(neighbour_list, 5); - unicast_send(&uc, &addr); - + init_send_to_gateway(&uc); + int retryCount; for (retryCount = 0; retryCount < 15; retryCount++) { etimer_set(&et, CLOCK_SECOND * 3); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + if (init_ack_received) { + break; + } printf("Failed to send neighbour_list. Retrying....\n"); init_send_to_gateway(&uc); } diff --git a/simulation.csc b/simulation.csc index 61c3d38..a60d92d 100644 --- a/simulation.csc +++ b/simulation.csc @@ -60,12 +60,32 @@ org.contikios.cooja.mspmote.interfaces.MspLED org.contikios.cooja.mspmote.interfaces.MspDebugOutput + + org.contikios.cooja.mspmote.Z1MoteType + z13 + Z1 - Unicast + [CONTIKI_DIR]/examples/rime/example-unicast.c + make example-unicast.z1 TARGET=z1 + [CONTIKI_DIR]/examples/rime/example-unicast.z1 + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.MspButton + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspDefaultSerial + org.contikios.cooja.mspmote.interfaces.MspLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.interfaces.Position - 61.073558288932624 - 13.85165049173941 + 80.77398167403715 + 57.46967673705475 0.0 @@ -82,8 +102,8 @@ org.contikios.cooja.interfaces.Position - 97.6801509807386 - 78.22011704654204 + 111.82708380308215 + 83.87889017547946 0.0 @@ -100,8 +120,8 @@ org.contikios.cooja.interfaces.Position - 46.07487715597834 - 7.233647151771752 + 87.22959082097778 + 71.79510421373963 0.0 @@ -136,8 +156,8 @@ org.contikios.cooja.interfaces.Position - 90.10592992447995 - 80.15716584187881 + 71.58630877523021 + 18.425095344379656 0.0 @@ -154,8 +174,8 @@ org.contikios.cooja.interfaces.Position - 53.78607935206482 - 10.48596658916789 + 71.30888134116846 + 1.1015536195247577 0.0 @@ -184,23 +204,23 @@ org.contikios.cooja.plugins.skins.IDVisualizerSkin org.contikios.cooja.plugins.skins.AddressVisualizerSkin org.contikios.cooja.plugins.skins.UDGMVisualizerSkin - 5.1304213940246575 0.0 0.0 5.1304213940246575 -186.16247388862877 13.524705532088301 + 3.887768514255855 0.0 0.0 3.887768514255855 -102.3941790870374 65.49042473354797 400 - 2 + 0 497 - 1 - 1 + 52 + 107 org.contikios.cooja.plugins.LogListener - + ID:1 1520 - 1 + 2 240 400 160 @@ -240,7 +260,7 @@ org.contikios.cooja.plugins.SimControl 280 - 0 + 1 160 400 0