Skip to content
Snippets Groups Projects
Commit 19db4217 authored by NATAF Emmanuel's avatar NATAF Emmanuel
Browse files

Corrections

parent c9144924
Branches
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#define LOG_LEVEL LOG_LEVEL_INFO #define LOG_LEVEL LOG_LEVEL_INFO
#if !NETSTACK_CONF_WITH_IPV6 || !UIP_CONF_ROUTER || !UIP_IPV6_MULTICAST || !UIP_CONF_IPV6_RPL #if !NETSTACK_CONF_WITH_IPV6 || !UIP_CONF_ROUTER || !UIP_CONF_IPV6_RPL
#error "This example can not work with the current contiki configuration" #error "This example can not work with the current contiki configuration"
#error "Check the values of: NETSTACK_CONF_WITH_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL" #error "Check the values of: NETSTACK_CONF_WITH_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL"
#endif #endif
...@@ -52,12 +52,10 @@ ...@@ -52,12 +52,10 @@
#define UDP_SERVER_PORT 5678 #define UDP_SERVER_PORT 5678
#define RDV_CLIENT_PORT 8766 #define RDV_CLIENT_PORT 8766
#define RDV_SERVER_PORT 5679 #define RDV_SERVER_PORT 5679
#define MCAST_SINK_UDP_PORT 3001 /* Host byte order */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define DATA_ACK_MAX_TIME 20
#define RECORD_DATA_SIZE 100 #define RECORD_DATA_SIZE 100
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static struct simple_udp_connection udp_conn;//, rdv_conn; static struct simple_udp_connection udp_conn;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static uint8_t rtc_buffer[sizeof(simple_td_map)]; static uint8_t rtc_buffer[sizeof(simple_td_map)];
static simple_td_map *simple_td = (simple_td_map *)rtc_buffer; static simple_td_map *simple_td = (simple_td_map *)rtc_buffer;
...@@ -77,6 +75,7 @@ static uint8_t files_sended; ...@@ -77,6 +75,7 @@ static uint8_t files_sended;
static uint8_t rdv; static uint8_t rdv;
static uint8_t rdv_req[9]; static uint8_t rdv_req[9];
static int max_int_tx; static int max_int_tx;
static uint8_t pkts_nb;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct data_file_handler { struct data_file_handler {
int fd; int fd;
...@@ -85,7 +84,7 @@ struct data_file_handler { ...@@ -85,7 +84,7 @@ struct data_file_handler {
char name[15]; char name[15];
void (*backup)(void); void (*backup)(void);
}; };
static char CFS_EOF = (char) -2; static char CFS_EOF = (char) -1;
static struct data_file_handler data_files[4]; static struct data_file_handler data_files[4];
static uint8_t i_file; static uint8_t i_file;
static int file_read; static int file_read;
...@@ -97,14 +96,10 @@ static uint32_t sense_nb; ...@@ -97,14 +96,10 @@ static uint32_t sense_nb;
static uint64_t start_time; static uint64_t start_time;
static uint64_t start_of_rdv; static uint64_t start_of_rdv;
static uint64_t start_of_tx; static uint64_t start_of_tx;
//static uint8_t state;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static uip_ipaddr_t dest_ipaddr; static uip_ipaddr_t dest_ipaddr;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static char send_data[RECORD_DATA_SIZE]; static char send_data[RECORD_DATA_SIZE];
//static uint8_t msg_seqno;
//static uint64_t itts;
//static int ite2;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS(node_process, "LT-WSN Node"); PROCESS(node_process, "LT-WSN Node");
PROCESS(rdv_process, "Rdv"); PROCESS(rdv_process, "Rdv");
...@@ -287,6 +282,31 @@ static void backup(){ ...@@ -287,6 +282,31 @@ static void backup(){
data_files[i_file].backup(); data_files[i_file].backup();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int backups_size(){
int size = 0;
int fd = cfs_open("lt-bckp", CFS_READ);
if (fd != -1){
uint8_t recdt[RECORD_DATA_SIZE];
int fr = cfs_read(fd, recdt, sizeof(uint64_t) + sizeof(ltdata_t));
while(fr > 1){
size++;
fr = cfs_read(fd, recdt, sizeof(uint64_t) + sizeof(ltdata_t));
}
cfs_close(fd);
}
int fg = cfs_open("energest-bckp", CFS_READ);
if (fg != 1) {
uint8_t recnrg[40];
int fn = cfs_read(fg, recnrg, 40);
while(fn > 1) {
size++;
fn = cfs_read(fg, recnrg, 40);
}
cfs_close(fg);
}
return size;
}
/*---------------------------------------------------------------------------*/
static int read_conf(){ static int read_conf(){
uint8_t buf[48]; uint8_t buf[48];
int fconf = cfs_open("conf", CFS_READ); int fconf = cfs_open("conf", CFS_READ);
...@@ -324,7 +344,7 @@ static int write_conf(){ ...@@ -324,7 +344,7 @@ static int write_conf(){
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int its_time_to_send(){ static int its_time_to_send(){
return sense_count > sense_nb; return sense_count >= sense_nb;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void sensing(){ static void sensing(){
...@@ -409,30 +429,23 @@ PROCESS_THREAD(tx_process, ev, data) ...@@ -409,30 +429,23 @@ PROCESS_THREAD(tx_process, ev, data)
files_sended = 0; files_sended = 0;
uint8_t pkts_nb = 0; pkts_nb = 0;
if(sense_nb != 0){ if(sense_nb != 0){
pkts_nb = sense_nb * 2; pkts_nb = sense_nb * 2;
if (data_files[0].fd != -1) pkts_nb += backups_size();
pkts_nb = pkts_nb + sense_nb;
if (data_files[1].fd != -1)
pkts_nb = pkts_nb + sense_nb;
#if defined(UIP_STATS) || defined(RPL_STATS) #if defined(UIP_STATS) || defined(RPL_STATS)
pkts_nb = pkts_nb + 1; pkts_nb = pkts_nb + 1;
#endif #endif
} }
else { else {
pkts_nb = 2; pkts_nb = 2;
if (data_files[0].fd != -1) pkts_nb += backups_size();
pkts_nb = pkts_nb + 1;
if (data_files[1].fd != -1)
pkts_nb = pkts_nb + 1;
#if defined(UIP_STATS) || defined(RPL_STATS) #if defined(UIP_STATS) || defined(RPL_STATS)
pkts_nb = pkts_nb + 1; pkts_nb = pkts_nb + 1;
#endif #endif
} }
max_int_tx = tx_time_slot / pkts_nb;
pkts_nb++;
LOG_INFO("max int %d\n", max_int_tx);
start_of_tx = clock_time(); start_of_tx = clock_time();
...@@ -454,9 +467,14 @@ PROCESS_THREAD(tx_process, ev, data) ...@@ -454,9 +467,14 @@ PROCESS_THREAD(tx_process, ev, data)
netuse /= CLOCK_SECOND; netuse /= CLOCK_SECOND;
memcpy(&send_data[1],&netuse, sizeof(uint64_t)); memcpy(&send_data[1],&netuse, sizeof(uint64_t));
start_of_tx = clock_time(); start_of_tx = clock_time();
random_init((uint16_t)start_of_tx); random_init((uint16_t)start_of_tx);
if (netuse < tx_time_slot){
max_int_tx = (tx_time_slot - netuse) / pkts_nb;
} else
max_int_tx = tx_time_slot / pkts_nb;
i_file = 0; i_file = 0;
for (i_file = 0; i_file < 4; i_file++){ for (i_file = 0; i_file < 4; i_file++){
if (data_files[i_file].fd != -1){ if (data_files[i_file].fd != -1){
...@@ -505,7 +523,14 @@ PROCESS_THREAD(tx_process, ev, data) ...@@ -505,7 +523,14 @@ PROCESS_THREAD(tx_process, ev, data)
msg_acked = 0; msg_acked = 0;
while(!msg_acked){ while(!msg_acked){
simple_udp_sendto(&udp_conn, send_data, 1 + sizeof(uint64_t) + sizeof(ltstatsdata_t), &dest_ipaddr); simple_udp_sendto(&udp_conn, send_data, 1 + sizeof(uint64_t) + sizeof(ltstatsdata_t), &dest_ipaddr);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ack_timer)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ack_timer)|| etimer_expired(&tx_timer));
if (etimer_expired(&tx_timer)){
etimer_stop(&onesec_timer);
backup();
tx_ok = 0;
process_post(&node_process,tx_event, &tx_ok);
PROCESS_EXIT();
}
if (etimer_expired(&ack_timer)) if (etimer_expired(&ack_timer))
etimer_restart(&ack_timer); etimer_restart(&ack_timer);
} }
...@@ -547,7 +572,7 @@ PROCESS_THREAD(rdv_process, ev, data) ...@@ -547,7 +572,7 @@ PROCESS_THREAD(rdv_process, ev, data)
start_of_rdv = clock_time(); start_of_rdv = clock_time();
etimer_set(&rdv_timer, rdv_time_slot * CLOCK_SECOND); etimer_set(&rdv_timer, rdv_time_slot * CLOCK_SECOND);
rdv_guard_time = rdv_time_slot - (rdv_time_slot / 4); rdv_guard_time = (rdv_time_slot - (rdv_time_slot / 4))/2;
NETSTACK_MAC.on(); NETSTACK_MAC.on();
simple_udp_register(&udp_conn, UDP_CLIENT_PORT, NULL, simple_udp_register(&udp_conn, UDP_CLIENT_PORT, NULL,
UDP_SERVER_PORT,rdv_callback); UDP_SERVER_PORT,rdv_callback);
...@@ -582,18 +607,18 @@ PROCESS_THREAD(rdv_process, ev, data) ...@@ -582,18 +607,18 @@ PROCESS_THREAD(rdv_process, ev, data)
LOG_INFO("No Network\n"); LOG_INFO("No Network\n");
etimer_set(&onesec_timer, CLOCK_SECOND); etimer_set(&onesec_timer, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&onesec_timer) || etimer_expired(&rdv_timer)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&onesec_timer) || etimer_expired(&rdv_timer));
if (data == &onesec_timer) { if (etimer_expired(&rdv_timer)) {
leds_on(LEDS_BLUE);
etimer_restart(&onesec_timer);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&onesec_timer)) ;
}
else if (data == &rdv_timer) {
rdv_ok = 0; rdv_ok = 0;
etimer_stop(&ack_timer); etimer_stop(&ack_timer);
etimer_stop(&onesec_timer); etimer_stop(&onesec_timer);
process_post(&node_process, rdv_event, &rdv_ok); process_post(&node_process, rdv_event, &rdv_ok);
PROCESS_EXIT(); PROCESS_EXIT();
} }
if (etimer_expired(&onesec_timer)) {
leds_on(LEDS_BLUE);
etimer_restart(&onesec_timer);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&onesec_timer)) ;
}
} }
} }
leds_off(LEDS_ALL); leds_off(LEDS_ALL);
...@@ -609,12 +634,6 @@ PROCESS_THREAD(rdv_process, ev, data) ...@@ -609,12 +634,6 @@ PROCESS_THREAD(rdv_process, ev, data)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define BOOT 0
#define SENSING 1
#define RDV 2
#define TX 3
#define SLEEP 4
PROCESS_THREAD(node_process, ev, data) PROCESS_THREAD(node_process, ev, data)
{ {
...@@ -630,11 +649,8 @@ PROCESS_THREAD(node_process, ev, data) ...@@ -630,11 +649,8 @@ PROCESS_THREAD(node_process, ev, data)
if (read_conf()){ if (read_conf()){
if (its_time_to_send()){ if (its_time_to_send()){
// while(!tx_ok){ process_start(&tx_process, NULL);
process_start(&tx_process, NULL); PROCESS_WAIT_EVENT_UNTIL(ev == tx_event);
PROCESS_WAIT_EVENT_UNTIL(ev == tx_event);
//tx_ok = *((uint8_t*)data);
//}
leds_on(LEDS_BLUE); leds_on(LEDS_BLUE);
etimer_set(&onesec_timer, CLOCK_SECOND/2); etimer_set(&onesec_timer, CLOCK_SECOND/2);
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "dev/leds.h" #include "dev/leds.h"
#include "dev/sys-ctrl.h" #include "dev/sys-ctrl.h"
#include "lib/list.h" #include "lib/list.h"
//#include "power-mgmt.h"
#include "rtcc.h" #include "rtcc.h"
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
...@@ -36,7 +35,7 @@ ...@@ -36,7 +35,7 @@
#define SEND_INTERVAL 2 #define SEND_INTERVAL 2
#if !NETSTACK_CONF_WITH_IPV6 || !UIP_CONF_ROUTER || !UIP_IPV6_MULTICAST || !UIP_CONF_IPV6_RPL #if !NETSTACK_CONF_WITH_IPV6 || !UIP_CONF_ROUTER || !UIP_CONF_IPV6_RPL
#error "This example can not work with the current contiki configuration" #error "This example can not work with the current contiki configuration"
#error "Check the values of: NETSTACK_CONF_WITH_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL" #error "Check the values of: NETSTACK_CONF_WITH_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL"
#endif #endif
...@@ -57,19 +56,13 @@ ...@@ -57,19 +56,13 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define TEST_ALARM_SECOND 15 #define TEST_ALARM_SECOND 15
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
//static uint8_t rtc_buffer[sizeof(simple_td_map)]; static struct simple_udp_connection server_conn;
//static simple_td_map *simple_td = (simple_td_map *)rtc_buffer;
//static uint64_t date_seconds = DATE_SECONDS;
/*---------------------------------------------------------------------------*/
static struct simple_udp_connection server_conn;//, rdv_conn;
PROCESS(node_process, "RPL Node"); PROCESS(node_process, "RPL Node");
AUTOSTART_PROCESSES(&node_process); AUTOSTART_PROCESSES(&node_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define MAX_PAYLOAD_LEN 44 #define MAX_PAYLOAD_LEN 100
#define MCAST_SINK_UDP_PORT 3001 /* Host byte order */
static uint64_t _CYCLE_DURATION = CYCLE_DURATION; static uint64_t _CYCLE_DURATION = CYCLE_DURATION;
static uint32_t _SLEEP_FREQUENCY = SLEEP_FREQUENCY; static uint32_t _SLEEP_FREQUENCY = SLEEP_FREQUENCY;
...@@ -245,7 +238,7 @@ PT_THREAD(cmd_date(struct pt *pt, shell_output_func output, char *args)) ...@@ -245,7 +238,7 @@ PT_THREAD(cmd_date(struct pt *pt, shell_output_func output, char *args))
/* Get argument (date in sec) */ /* Get argument (date in sec) */
SHELL_ARGS_NEXT(args, next_args); SHELL_ARGS_NEXT(args, next_args);
if(args == NULL) { if(args == NULL) {
SHELL_OUTPUT(output, "date in seconds ?\n"); SHELL_OUTPUT(output, "%llu\n", tsch_get_network_uptime_ticks() / CLOCK_SECOND);
PT_EXIT(pt); PT_EXIT(pt);
} }
date = atoll(args); date = atoll(args);
...@@ -265,7 +258,7 @@ static struct shell_command_set_t sensing_shell_command_set = { ...@@ -265,7 +258,7 @@ static struct shell_command_set_t sensing_shell_command_set = {
.commands = sensing_shell_commands, .commands = sensing_shell_commands,
}; };
static uint8_t tsch_cnx = 0; static uint8_t tsch_cnx;
static struct etimer rdv_timer,join_tsch_timer; static struct etimer rdv_timer,join_tsch_timer;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(node_process, ev, data) PROCESS_THREAD(node_process, ev, data)
...@@ -275,21 +268,19 @@ PROCESS_THREAD(node_process, ev, data) ...@@ -275,21 +268,19 @@ PROCESS_THREAD(node_process, ev, data)
shell_command_set_register(&sensing_shell_command_set); shell_command_set_register(&sensing_shell_command_set);
NETSTACK_MAC.on(); NETSTACK_MAC.on();
NETSTACK_ROUTING.root_start(); NETSTACK_ROUTING.root_start();
etimer_set(&join_tsch_timer, CLOCK_SECOND); etimer_set(&join_tsch_timer, CLOCK_SECOND);
tsch_cnx = 0;
while(!tsch_cnx){ while(!tsch_cnx){
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&join_tsch_timer)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&join_tsch_timer));
if (data == &join_tsch_timer){ tsch_time = tsch_get_network_uptime_ticks();
tsch_time = tsch_get_network_uptime_ticks(); LOG_INFO("tsch time %llu\n", tsch_time);
LOG_INFO("tsch time %llu\n", tsch_time); if (tsch_time != -1)
if (tsch_time != -1) tsch_cnx = 1;
tsch_cnx = 1; else
else etimer_set(&join_tsch_timer, CLOCK_SECOND);
etimer_set(&join_tsch_timer, CLOCK_SECOND);
}
} }
simple_udp_register(&server_conn, UDP_SERVER_PORT, NULL, simple_udp_register(&server_conn, UDP_SERVER_PORT, NULL,
...@@ -299,7 +290,7 @@ PROCESS_THREAD(node_process, ev, data) ...@@ -299,7 +290,7 @@ PROCESS_THREAD(node_process, ev, data)
while(1) { while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&rdv_timer)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&rdv_timer));
rdv_update(); rdv_update();
etimer_restart(&rdv_timer); etimer_reset(&rdv_timer);
} }
PROCESS_END(); PROCESS_END();
} }
......
...@@ -15,15 +15,6 @@ ...@@ -15,15 +15,6 @@
#define DATAFILE "lt-data" #define DATAFILE "lt-data"
/*******************************************************/
/******************* Configure Multicast ***************/
/*******************************************************/
#ifndef UIP_MCAST6_CONF_ENGINE
#define UIP_MCAST6_CONF_ENGINE UIP_MCAST6_ENGINE_MPL
#endif
#define UIP_MCAST6_ROUTE_CONF_ROUTES 1
#define LPM_CONF_MAX_PM 1 #define LPM_CONF_MAX_PM 1
...@@ -34,7 +25,7 @@ ...@@ -34,7 +25,7 @@
#ifdef DEFAULT_RDV_CONF_TIME_SLOT #ifdef DEFAULT_RDV_CONF_TIME_SLOT
#define DEFAULT_RDV_TIME_SLOT DEFAULT_RDV_CONF_TIME_SLOT #define DEFAULT_RDV_TIME_SLOT DEFAULT_RDV_CONF_TIME_SLOT
#else #else
#define DEFAULT_RDV_TIME_SLOT 30 #define DEFAULT_RDV_TIME_SLOT 60
#endif #endif
#define RETRY_RDV_TIME 10 #define RETRY_RDV_TIME 10
...@@ -44,14 +35,9 @@ ...@@ -44,14 +35,9 @@
#ifdef NETWORKING_CONF_TIME_SLOT #ifdef NETWORKING_CONF_TIME_SLOT
#define NETWORKING_TIME_SLOT NETWORKING_CONF_TIME_SLOT #define NETWORKING_TIME_SLOT NETWORKING_CONF_TIME_SLOT
#else #else
#define NETWORKING_TIME_SLOT 30 #define NETWORKING_TIME_SLOT 60
#endif #endif
#ifdef DEEP_CONF_MAX
#define DEEP_MAX DEEP_CONF_MAX
#else
#define DEEP_MAX 1
#endif
#ifdef CYCLE_CONF_DURATION #ifdef CYCLE_CONF_DURATION
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment