From ef9cde532fd4f58e19eb9d8987165b08d6cd3221 Mon Sep 17 00:00:00 2001 From: giomba Date: Thu, 11 Apr 2019 17:46:54 +0200 Subject: [PATCH 1/6] [cart] first unuseful version for cart --- project/Giomba/Makefile | 14 +++++ project/Giomba/cart.c | 93 ++++++++++++++++++++++++++++++++ project/Giomba/event.h | 8 +++ project/Giomba/log.h | 9 ++++ project/Giomba/project-conf.h | 14 +++++ project/Giomba/sendrecv.c | 30 +++++++++++ project/Giomba/sendrecv.h | 31 +++++++++++ project/common/supermarket_net.h | 19 +++++++ 8 files changed, 218 insertions(+) create mode 100644 project/Giomba/Makefile create mode 100644 project/Giomba/cart.c create mode 100644 project/Giomba/event.h create mode 100644 project/Giomba/log.h create mode 100644 project/Giomba/project-conf.h create mode 100644 project/Giomba/sendrecv.c create mode 100644 project/Giomba/sendrecv.h create mode 100644 project/common/supermarket_net.h diff --git a/project/Giomba/Makefile b/project/Giomba/Makefile new file mode 100644 index 000000000..e1950411d --- /dev/null +++ b/project/Giomba/Makefile @@ -0,0 +1,14 @@ +CONTIKI_PROJECT = cart +PROJECT_SOURCEFILES += sendrecv.c +PLATFORMS_ONLY = cc26x0-cc13x0 + +all: $(CONTIKI_PROJECT) + +CONTIKI = ../.. + +PLATFORMS_EXCLUDE = nrf52dk + +#use this to enable TSCH: MAKE_MAC = MAKE_MAC_TSCH +MAKE_MAC ?= MAKE_MAC_CSMA +MAKE_NET = MAKE_NET_NULLNET +include $(CONTIKI)/Makefile.include diff --git a/project/Giomba/cart.c b/project/Giomba/cart.c new file mode 100644 index 000000000..c6a96c2fa --- /dev/null +++ b/project/Giomba/cart.c @@ -0,0 +1,93 @@ +#include +#include + +#include "os/dev/leds.h" +#include "batmon-sensor.h" + +#include "../common/supermarket_net.h" +#include "event.h" +#include "log.h" +#include "sendrecv.h" + +//static linkaddr_t destination_address = {{ 0x00, 0x12, 0x4b, 0x00, 0x0f, 0x8f, 0x18, 0x11 }}; + +PROCESS(cart_main_process, "Cart Process"); +AUTOSTART_PROCESSES(&cart_main_process); + +enum CartStatus { + NOT_ASSOCIATED, + ASSOCIATED, + SHOPPING, + CASHOUT +} status; + +static uint8_t net_buffer[256]; +static struct etimer broadcast_timer; + +void s_not_associated(process_event_t ev, process_data_t data) { + if (ev == PROCESS_EVENT_TIMER) { + // send broadcast message to request association with assigner + if (etimer_expired(&broadcast_timer)) { + //net_send(/*TODO*/); + } + } + else if (ev == PROCESS_EVENT_MSG && *((enum CartEvent*)data) == CART_EVENT_ASSOCIATED) { + status = ASSOCIATED; + } +} + + +PROCESS_THREAD(cart_main_process, ev, data) { + PROCESS_BEGIN(); +// SENSORS_ACTIVATE(batmon_sensor); + + /* Local variables allocation */ + + /*** Variables initialization ***/ + /* Finite State Machine Status */ + status = CASHOUT; + + /* Network initialization */ + nullnet_buf = net_buffer; + nullnet_set_input_callback(net_recv); + + + + /* fixme garbage */ + etimer_set(&broadcast_timer, 10 * CLOCK_SECOND); + + + + /* now actually start */ + printf("Hello! I'm the cart.\n"); + + while (true) { + PROCESS_WAIT_EVENT(); + + switch(status) { + case NOT_ASSOCIATED: + s_not_associated(ev, data); + break; + break; + case ASSOCIATED: break; + case SHOPPING: break; + case CASHOUT: break; + default: status = NOT_ASSOCIATED; break; + } + +/* + if (ev == PROCESS_EVENT_TIMER) { + printf("Transmitting %d...\n", counter); + sprintf(message, "#%d Hello. It's me. -- by Adele", counter); + nullnet_len = strlen(message) + 1; + counter++; + NETSTACK_NETWORK.output(&destination_address); + etimer_reset(&my_timer); + } +*/ + } + + PROCESS_END(); +} + + diff --git a/project/Giomba/event.h b/project/Giomba/event.h new file mode 100644 index 000000000..f938ff1ab --- /dev/null +++ b/project/Giomba/event.h @@ -0,0 +1,8 @@ +#ifndef EVENT_H +#define EVENT_H + +enum CartEvent { + CART_EVENT_ASSOCIATED +} event; + +#endif diff --git a/project/Giomba/log.h b/project/Giomba/log.h new file mode 100644 index 000000000..3ac99a677 --- /dev/null +++ b/project/Giomba/log.h @@ -0,0 +1,9 @@ +#ifndef LOG_H +#define LOG_H + +#include "sys/log.h" + +#define LOG_MODULE "Cart" +#define LOG_LEVEL LOG_LEVEL_INFO + +#endif diff --git a/project/Giomba/project-conf.h b/project/Giomba/project-conf.h new file mode 100644 index 000000000..d0333ca1f --- /dev/null +++ b/project/Giomba/project-conf.h @@ -0,0 +1,14 @@ +/*---------------------------------------------------------------------------*/ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ +/*---------------------------------------------------------------------------*/ +/* Enable the ROM bootloader */ +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1 +/*---------------------------------------------------------------------------*/ +/* Change to match your configuration */ +#define IEEE802154_CONF_PANID 0xABCD +#define IEEE802154_CONF_DEFAULT_CHANNEL 25 +#define RF_BLE_CONF_ENABLED 1 +/*---------------------------------------------------------------------------*/ +#endif /* PROJECT_CONF_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/project/Giomba/sendrecv.c b/project/Giomba/sendrecv.c new file mode 100644 index 000000000..d09d39256 --- /dev/null +++ b/project/Giomba/sendrecv.c @@ -0,0 +1,30 @@ +#include "sendrecv.h" + +struct MacPkt pkt; + +void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst) { + /* discard too long packet */ + if (len > 128) { + LOG_INFO("[WW] dropping too long packet %d\n", len); + return; + } + + /* fill packet to pass to upper processing layer */ + memcpy(pkt.data, data, len); + pkt.len = len; + pkt.src = *src; + pkt.dst = *dst; + + LOG_INFO("Received %d bytes from ", len); LOG_INFO_LLADDR(src); LOG_INFO("\n"); + + switch ( ((struct Msg*)data)->type ) { + case ASSOCIATION_REPLY_MSG: + event = CART_EVENT_ASSOCIATED; + process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL); + break; + default: + LOG_INFO("[W] message type unknown\n"); + break; + } +} + diff --git a/project/Giomba/sendrecv.h b/project/Giomba/sendrecv.h new file mode 100644 index 000000000..7c7755c1d --- /dev/null +++ b/project/Giomba/sendrecv.h @@ -0,0 +1,31 @@ +#ifndef SENDRECV_H +#define SENDRECV_H + +#include + +#include "net/netstack.h" +#include "net/nullnet/nullnet.h" +#include "os/net/linkaddr.h" + +#include "../common/supermarket_net.h" + +#include "event.h" +#include "log.h" + +struct MacPkt { + char data[128]; + uint16_t len; + linkaddr_t src; + linkaddr_t dst; +}; + +extern void* ResetISR; + +extern struct MacPkt pkt; + +extern struct process cart_main_process; + +void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst); +void net_send(const void* data, uint16_t len, const linkaddr_t* dst); + +#endif diff --git a/project/common/supermarket_net.h b/project/common/supermarket_net.h new file mode 100644 index 000000000..7a84eaa07 --- /dev/null +++ b/project/common/supermarket_net.h @@ -0,0 +1,19 @@ +#ifndef SUPERMARKET_NET_H +#define SUPERMARKET_NET_H + +enum MsgType { + ASSOCIATION_REQUEST_MSG, + ASSOCIATION_REPLY_MSG, + BATTERY_STATUS_MSG, + ASSIGNMENT_MSG, + PRODUCT_MSG, + CASHOUT_MSG, + ITEM_ELEM_MSG +}; + +struct Msg { + enum MsgType type; + int test; +}; + +#endif From 477963987fd14c69f150de03dac5713411571a89 Mon Sep 17 00:00:00 2001 From: giomba Date: Fri, 12 Apr 2019 14:56:37 +0200 Subject: [PATCH 2/6] [cart] Now cart should associate --- project/Giomba/Makefile | 2 +- project/Giomba/cart.c | 44 +++++++-------------------------------- project/Giomba/sendrecv.c | 13 ++++++++++++ project/Giomba/sendrecv.h | 1 + project/Giomba/status.c | 26 +++++++++++++++++++++++ project/Giomba/status.h | 24 +++++++++++++++++++++ 6 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 project/Giomba/status.c create mode 100644 project/Giomba/status.h diff --git a/project/Giomba/Makefile b/project/Giomba/Makefile index e1950411d..7af95bd48 100644 --- a/project/Giomba/Makefile +++ b/project/Giomba/Makefile @@ -1,5 +1,5 @@ CONTIKI_PROJECT = cart -PROJECT_SOURCEFILES += sendrecv.c +PROJECT_SOURCEFILES += sendrecv.c status.c PLATFORMS_ONLY = cc26x0-cc13x0 all: $(CONTIKI_PROJECT) diff --git a/project/Giomba/cart.c b/project/Giomba/cart.c index c6a96c2fa..ac026592a 100644 --- a/project/Giomba/cart.c +++ b/project/Giomba/cart.c @@ -8,57 +8,27 @@ #include "event.h" #include "log.h" #include "sendrecv.h" +#include "status.h" //static linkaddr_t destination_address = {{ 0x00, 0x12, 0x4b, 0x00, 0x0f, 0x8f, 0x18, 0x11 }}; + PROCESS(cart_main_process, "Cart Process"); AUTOSTART_PROCESSES(&cart_main_process); -enum CartStatus { - NOT_ASSOCIATED, - ASSOCIATED, - SHOPPING, - CASHOUT -} status; - -static uint8_t net_buffer[256]; -static struct etimer broadcast_timer; - -void s_not_associated(process_event_t ev, process_data_t data) { - if (ev == PROCESS_EVENT_TIMER) { - // send broadcast message to request association with assigner - if (etimer_expired(&broadcast_timer)) { - //net_send(/*TODO*/); - } - } - else if (ev == PROCESS_EVENT_MSG && *((enum CartEvent*)data) == CART_EVENT_ASSOCIATED) { - status = ASSOCIATED; - } -} - - PROCESS_THREAD(cart_main_process, ev, data) { PROCESS_BEGIN(); -// SENSORS_ACTIVATE(batmon_sensor); - - /* Local variables allocation */ + // SENSORS_ACTIVATE(batmon_sensor); /*** Variables initialization ***/ - /* Finite State Machine Status */ - status = CASHOUT; - /* Network initialization */ - nullnet_buf = net_buffer; - nullnet_set_input_callback(net_recv); - - - - /* fixme garbage */ + status = NOT_ASSOCIATED; etimer_set(&broadcast_timer, 10 * CLOCK_SECOND); + /*** Subsystem initialization ***/ + net_init(); - - /* now actually start */ + /* START */ printf("Hello! I'm the cart.\n"); while (true) { diff --git a/project/Giomba/sendrecv.c b/project/Giomba/sendrecv.c index d09d39256..2abb49459 100644 --- a/project/Giomba/sendrecv.c +++ b/project/Giomba/sendrecv.c @@ -2,6 +2,13 @@ struct MacPkt pkt; +uint8_t net_buffer[256]; + +void net_init() { + nullnet_buf = net_buffer; + nullnet_set_input_callback(net_recv); +} + void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst) { /* discard too long packet */ if (len > 128) { @@ -28,3 +35,9 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka } } +void net_send(const void* data, uint16_t len, const linkaddr_t* dst) { + memcpy(net_buffer, data, len); + nullnet_len = len; + NETSTACK_NETWORK.output(dst); +} + diff --git a/project/Giomba/sendrecv.h b/project/Giomba/sendrecv.h index 7c7755c1d..46b75d040 100644 --- a/project/Giomba/sendrecv.h +++ b/project/Giomba/sendrecv.h @@ -25,6 +25,7 @@ extern struct MacPkt pkt; extern struct process cart_main_process; +void net_init(void); void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst); void net_send(const void* data, uint16_t len, const linkaddr_t* dst); diff --git a/project/Giomba/status.c b/project/Giomba/status.c new file mode 100644 index 000000000..530265f87 --- /dev/null +++ b/project/Giomba/status.c @@ -0,0 +1,26 @@ +#include "status.h" + +enum CartStatus status; +struct etimer broadcast_timer; +linkaddr_t assigner_address; + +void s_not_associated(process_event_t ev, process_data_t data) { + if (ev == PROCESS_EVENT_TIMER) { + /* at time expiration, send broadcast message to request association with assigner */ + if (etimer_expired(&broadcast_timer)) { + printf("[I] Sending association request msg\n"); + struct Msg msg; + msg.type = ASSOCIATION_REQUEST_MSG; + net_send(&msg, sizeof(msg), NULL); + etimer_reset(&broadcast_timer); + } + } + else /* if a msg is received from network and represents an association event, then associate */ + if (ev == PROCESS_EVENT_MSG && *((enum CartEvent*)data) == CART_EVENT_ASSOCIATED) { + printf("[I] Associated with Assigner\n"); + assigner_address = pkt.src; + status = ASSOCIATED; + } +} + + diff --git a/project/Giomba/status.h b/project/Giomba/status.h new file mode 100644 index 000000000..7a4c8c1f4 --- /dev/null +++ b/project/Giomba/status.h @@ -0,0 +1,24 @@ +#ifndef STATUS_H +#define STATUS_H + +#include "contiki.h" +#include "sys/etimer.h" +#include "sys/process.h" + +#include "../common/supermarket_net.h" +#include "event.h" +#include "sendrecv.h" + +enum CartStatus { + NOT_ASSOCIATED, + ASSOCIATED, + SHOPPING, + CASHOUT +}; + +extern enum CartStatus status; +extern struct etimer broadcast_timer; + +void s_not_associated(process_event_t ev, process_data_t data); + +#endif From e62c4d5501248453c6df151689c281643e2ddb6c Mon Sep 17 00:00:00 2001 From: Daniela Date: Fri, 12 Apr 2019 15:14:52 +0200 Subject: [PATCH 3/6] first version of Assigner --- project/Assigner/Makefile | 14 ++ project/Assigner/assigner.c | 244 ++++++++++++++++++++++++++++++++ project/Assigner/assigner_fun.c | 85 +++++++++++ project/Assigner/assigner_fun.h | 27 ++++ project/Assigner/project-conf.h | 43 ++++++ project/msg.h | 71 ++++++++++ 6 files changed, 484 insertions(+) create mode 100644 project/Assigner/Makefile create mode 100644 project/Assigner/assigner.c create mode 100644 project/Assigner/assigner_fun.c create mode 100644 project/Assigner/assigner_fun.h create mode 100644 project/Assigner/project-conf.h create mode 100644 project/msg.h diff --git a/project/Assigner/Makefile b/project/Assigner/Makefile new file mode 100644 index 000000000..0f43eda36 --- /dev/null +++ b/project/Assigner/Makefile @@ -0,0 +1,14 @@ +CONTIKI_PROJECT = assigner + +PLATFORMS_ONLY = cc26x0-cc13x0 +all: $(CONTIKI_PROJECT) + +CONTIKI = ../.. +PROJECT_SOURCEFILES += assigner_fun.c + +PLATFORMS_EXCLUDE = nrf52dk + +#use this to enable TSCH: MAKE_MAC = MAKE_MAC_TSCH +MAKE_MAC ?= MAKE_MAC_CSMA +MAKE_NET = MAKE_NET_NULLNET +include $(CONTIKI)/Makefile.include diff --git a/project/Assigner/assigner.c b/project/Assigner/assigner.c new file mode 100644 index 000000000..5880b7503 --- /dev/null +++ b/project/Assigner/assigner.c @@ -0,0 +1,244 @@ +#include "contiki.h" +#include "net/netstack.h" +#include "net/nullnet/nullnet.h" +#include +#include +#include +#include "sys/log.h" +#include "sys/clock.h" +#include "sys/ctimer.h" +#include "os/dev/leds.h" +#include "os/dev/serial-line.h" +#include "arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.h" + +#include "../msg.h" +#include "assigner_fun.h" + +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO +#define OPENING_PERIOD (300*CLOCK_SECOND) + + +/*typedef struct cart +{ + linkaddr_t* cart_address; + uint8_t battery_status; + bool assigned; + uint32_t customer_id; + struct cart *next; +}cart;*/ + + + +/*typedef struct assigner_msg +{ + enum message_type msg_type; + //assoc_req_msg request; + //assoc_reply_msg reply; + uint8_t battery_percentage; + uint32_t customer_id; +}assigner_msg; +*/ + +PROCESS(assigner_process, "Assigner process"); +AUTOSTART_PROCESSES(&assigner_process); + +cart* cart_list = NULL; +static bool supermarket_open = true; +/* +//function invoked in order to looking for the most charged cart to assign to the new arrived client +static cart* cart_selection() +{ + uint8_t highest_battery = 0; + cart* selected = NULL; + cart* current = cart_list; + while(current) + { + if(!current->assigned && current->battery_status > highest_battery) + { + highest_battery = current->battery_status; + selected = current; + } + current = current->next; + } + return selected; +} + +//Insert a new cart in the list with the battery info just arrived +static bool insert_cart(uint8_t new_req_battery, linkaddr_t* mac_cart_addr) +{ + cart* new_arrived_cart = (cart*)malloc(sizeof(cart)); + if(new_arrived_cart==NULL) + { + printf("Association Failed"); + return false; + } + else + { + new_arrived_cart->cart_address = mac_cart_addr; + new_arrived_cart->battery_status = new_req_battery; + new_arrived_cart->assigned = false; + new_arrived_cart->next = cart_list; + cart_list = new_arrived_cart; + } + return true; +} + +//Upgrade the battery status of a cart +static bool bat_upgrade(linkaddr_t* src_cart_addr, uint8_t battery_level) +{ + cart* c = cart_list; + //for(c; c && (c->cart_address != src_cart_addr); c = c->next); + while(c) + { + if(c->cart_address != src_cart_addr) + c = c->next; + else + break; + } + if(!c) + { + LOG_INFO("Cart not associated yet!\n"); + return false; + } + c->battery_status = battery_level; + c->assigned = false; //a battery status is sent only when the cart is in his place, not with a client. So if the cart was out and the the battery status is received, it is now come back in place. + return true; +} +*/ + +//Handle the incoming messages, according to the msg_type +static void input_callback(const void* data, uint16_t len, const linkaddr_t* source_address, const linkaddr_t* destination_address) +{ + a_msg received_msg; + linkaddr_t* src = (linkaddr_t*)source_address; + + //if(len == sizeof((a_msg *)data)) + + memcpy (&received_msg, data, sizeof ((a_msg *)data)); + LOG_INFO("Received data from: "); + LOG_INFO_LLADDR(source_address); + LOG_INFO("\n"); + + if(received_msg.msg_type == ASSOCIATION_REQUEST_MSG) + { + //accendere led blu (x mes broadcast) + if(insert_cart(received_msg.battery_percentage, src)) + { + a_msg notification; + notification.msg_type = ASSOCIATION_REPLY_MSG; + LOG_INFO("Sending acknowledgment of successfull association\n"); + + nullnet_buf = (uint8_t*)¬ification; + nullnet_len = sizeof(notification); + NETSTACK_NETWORK.output(src); + } + LOG_INFO("New cart associated\n"); + } + + if(received_msg.msg_type == BATTERY_STATUS_MSG) + { + //accendere led purple (mex unicast) + if(bat_upgrade(src, received_msg.battery_percentage)) + { + LOG_INFO("Battery level upgraded of "); + LOG_INFO_LLADDR(src); + LOG_INFO("\n"); + } + } + +} + +//callback function for the ctimer that checks if all the carts have been replaced when the supermarket close +void check(void *ptr) +{ + supermarket_open = !supermarket_open; + if(!supermarket_open) + { + printf("Supermarket closed\n"); + cart* c = cart_list; + while(c) + { + if(c->assigned) + printf("Customer id %d hasn't replaced his cart\n", (int)c->customer_id); + c = c->next; + } + } + else + printf("Supermarket is open!\n"); + process_poll(&assigner_process); + +} + +PROCESS_THREAD(assigner_process, ev, data) +{ + + static uint8_t customer_id; + static a_msg selection_msg; + linkaddr_t* dest_addr; + static struct ctimer opening_timer; + + PROCESS_BEGIN(); + + cc26xx_uart_set_input(serial_line_input_byte); + serial_line_init(); + + nullnet_set_input_callback(input_callback); + + ctimer_set(&opening_timer, OPENING_PERIOD, check, NULL); + + printf("Supermarket is open!\n"); + printf("Welcome! Please, insert your card id\n"); + + while (true) + { + PROCESS_WAIT_EVENT(); + if(ev == serial_line_event_message) + { + if(!supermarket_open) + { + printf("Supermarket is closed! Please, come back tomorrow!\n"); + leds_on(LEDS_RED); + } + else + { + printf("Customer's id: %s\n", (char*)data); + customer_id = atoi(data); + printf("id: %d\n", (int)customer_id); + + cart* cart_selected = cart_selection(); + if(!cart_selected) + { + printf("No cart available!\n"); + leds_on(LEDS_RED); + } + + else + { + cart_selected->assigned = true; + cart_selected->customer_id = customer_id; + + + //send a notification to the selected cart with the associated customer id + selection_msg.msg_type = ASSIGNMENT_MSG; + selection_msg.customer_id = customer_id; + + dest_addr = cart_selected->cart_address; + + nullnet_buf = (uint8_t*)&selection_msg; + nullnet_len = sizeof(selection_msg); + NETSTACK_NETWORK.output(dest_addr); + + printf("Cart unblocked!\n"); + leds_on(LEDS_GREEN); + } + } + } + + else if(ev == PROCESS_EVENT_POLL) + ctimer_reset(&opening_timer); + } + + PROCESS_END(); +} + diff --git a/project/Assigner/assigner_fun.c b/project/Assigner/assigner_fun.c new file mode 100644 index 000000000..9b726b3af --- /dev/null +++ b/project/Assigner/assigner_fun.c @@ -0,0 +1,85 @@ +#include "contiki.h" +#include "net/netstack.h" +#include "net/nullnet/nullnet.h" +#include +#include +#include +#include "sys/log.h" +#include "sys/clock.h" +#include "sys/ctimer.h" +#include "os/dev/leds.h" +#include "os/dev/serial-line.h" +#include "arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.h" + +#include "../msg.h" +#include "assigner_fun.h" + +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +extern cart* cart_list; + +//struct cart cart; + +//function invoked in order to looking for the most charged cart to assign to the new arrived client +cart* cart_selection() +{ + uint8_t highest_battery = 0; + cart* selected = NULL; + cart* current = cart_list; + while(current) + { + if(!current->assigned && current->battery_status > highest_battery) + { + highest_battery = current->battery_status; + selected = current; + } + current = current->next; + } + return selected; +} + +//Insert a new cart in the list with the battery info just arrived +bool insert_cart(uint8_t new_req_battery, linkaddr_t* mac_cart_addr) +{ + cart* new_arrived_cart = (cart*)malloc(sizeof(cart)); + if(new_arrived_cart==NULL) + { + printf("Association Failed"); + return false; + } + else + { + new_arrived_cart->cart_address = mac_cart_addr; + new_arrived_cart->battery_status = new_req_battery; + new_arrived_cart->assigned = false; + new_arrived_cart->next = cart_list; + cart_list = new_arrived_cart; + } + return true; +} + +//Upgrade the battery status of a cart +bool bat_upgrade(linkaddr_t* src_cart_addr, uint8_t battery_level) +{ + cart* c = cart_list; + //for(c; c && (c->cart_address != src_cart_addr); c = c->next); + while(c) + { + if(c->cart_address != src_cart_addr) + c = c->next; + else + break; + } + if(!c) + { + LOG_INFO("Cart not associated yet!\n"); + return false; + } + c->battery_status = battery_level; + c->assigned = false; //a battery status is sent only when the cart is in his place, not with a client. So if the cart was out and the the battery status is received, it is now come back in place. + return true; +} + + + diff --git a/project/Assigner/assigner_fun.h b/project/Assigner/assigner_fun.h new file mode 100644 index 000000000..aecd013ba --- /dev/null +++ b/project/Assigner/assigner_fun.h @@ -0,0 +1,27 @@ +#include "contiki.h" +#include "net/netstack.h" +#include "net/nullnet/nullnet.h" +#include +#include +#include +#include "sys/log.h" +#include "sys/clock.h" +#include "sys/ctimer.h" +#include "os/dev/leds.h" +#include "os/dev/serial-line.h" +#include "arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.h" + +typedef struct cart +{ + linkaddr_t* cart_address; + uint8_t battery_status; + bool assigned; + uint32_t customer_id; + struct cart *next; +}cart; + +cart* cart_selection(); +bool insert_cart(uint8_t new_req_battery, linkaddr_t* mac_cart_addr); +bool bat_upgrade(linkaddr_t* src_cart_addr, uint8_t battery_level); +//static void input_callback(const void* data, uint16_t len, const linkaddr_t* source_address, const linkaddr_t* destination_address); +//void check(void *ptr); diff --git a/project/Assigner/project-conf.h b/project/Assigner/project-conf.h new file mode 100644 index 000000000..3cbc0da86 --- /dev/null +++ b/project/Assigner/project-conf.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ +/*---------------------------------------------------------------------------*/ +/* Enable the ROM bootloader */ +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1 +/*---------------------------------------------------------------------------*/ +/* Change to match your configuration */ +#define IEEE802154_CONF_PANID 0xABCD +#define IEEE802154_CONF_DEFAULT_CHANNEL 25 +#define RF_BLE_CONF_ENABLED 1 +/*---------------------------------------------------------------------------*/ +#endif /* PROJECT_CONF_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/project/msg.h b/project/msg.h new file mode 100644 index 000000000..958e72679 --- /dev/null +++ b/project/msg.h @@ -0,0 +1,71 @@ + +enum message_type{ASSOCIATION_REQUEST_MSG, ASSOCIATION_REPLY_MSG, BATTERY_STATUS_MSG, ASSIGNMENT_MSG, CASH_OUT_MSG, PRODUCT_MSG, ITEM_ELEM_MSG, BASKET_MSG, START_OF_LIST_PRODUCTS_MSG}; + +/*typedef struct assoc_req_msg +{ + uint8_t battery_percentage; + +}assoc_req_msg; + + +typedef struct assoc_reply_msg +{ + //linkaddr_t* assigner_address; +}assoc_reply_msg; + + +typedef struct battery_msg +{ + uint8_t battery_percentage; +}battery_msg; + + +typedef struct assign_msg +{ + uint32_t customer_id; +}assing_msg; +*/ + +typedef struct basket_msg +{ + uint8_t n_products; + uint8_t customer_id; + linkaddr_t* address; + + +}basket_msg; + + +typedef struct cash_out_msg +{ + uint8_t customer_id; +}cash_out_msg; + + +typedef struct product_msg{ + + uint8_t customer_id; + uint8_t product_id; + float prize; + +}product_msg; + +//-----------------------Definition of the type of messages exchanged between the modules, with their useful informations. The significant fields are discriminated by the msg_type --------- + + +typedef struct assigner_msg //Message for communications between assigner and carts +{ + enum message_type msg_type; + //assoc_req_msg request; + //assoc_reply_msg reply; + uint8_t battery_percentage; + uint32_t customer_id; +}a_msg; + +typedef struct cash_desk_msg +{ + enum message_type msg_type; + cash_out_msg cash_out; + product_msg product; + basket_msg basket; +}cd_msg; From 3393ab58773853080639e2fef9a702a182cad490 Mon Sep 17 00:00:00 2001 From: "natalija.zlatkova@gmail.com" Date: Fri, 12 Apr 2019 16:20:00 +0200 Subject: [PATCH 4/6] modified version that saves up memory --- project/Natalia/cassa.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/project/Natalia/cassa.c b/project/Natalia/cassa.c index 0af02d040..0fe235fff 100644 --- a/project/Natalia/cassa.c +++ b/project/Natalia/cassa.c @@ -19,6 +19,7 @@ enum message_type{CASH_OUT_MSG, PRODUCT_MSG, ITEM_ELEM_MSG, BASKET_MSG, START_OF typedef struct basket_msg { + enum message_type msg_type; uint8_t n_products; uint8_t customer_id; linkaddr_t* address; @@ -28,6 +29,7 @@ typedef struct basket_msg typedef struct user_invoice { + enum message_type msg_type; uint8_t n_prods; float total_sum; uint8_t customer_id; @@ -39,11 +41,13 @@ typedef struct user_invoice typedef struct cash_out_msg { + enum message_type msg_type; uint8_t customer_id; }cash_out_msg; typedef struct product_msg{ + enum message_type msg_type; uint8_t customer_id; uint8_t product_id; float prize; @@ -52,12 +56,7 @@ typedef struct product_msg{ typedef struct msg{ enum message_type msg_type; - cash_out_msg cash_out; - product_msg product; - basket_msg basket; - - }msg; PROCESS(cassa_main_process, "Cassa process"); @@ -104,12 +103,13 @@ static void input_callback(const void* data, uint16_t len, const linkaddr_t* sou //we need to receive an additional message to start the process of receiving the products because if we start receiving the products immediately //in the case of parallel processes we wouldnt know to what client and what basket that product is assosiated with if (received_msg.msg_type == BASKET_MSG) { + basket_msg *basket = (basket_msg*) (&received_msg); uint8_t index = index_free_spot(invoices); if (index != -1 ) { - invoices[index].n_prods = received_msg.basket.n_products; + invoices[index].n_prods = basket->n_products; invoices[index].total_sum = 0; - invoices[index].customer_id = received_msg.basket.customer_id; - invoices[index].address_basket = received_msg.basket.address; + invoices[index].customer_id = basket->customer_id; + invoices[index].address_basket = basket->address; msg start_sending_list; start_sending_list.msg_type = START_OF_LIST_PRODUCTS_MSG; @@ -126,10 +126,11 @@ static void input_callback(const void* data, uint16_t len, const linkaddr_t* sou printf("Reached max number of customers"); } if (received_msg.msg_type == PRODUCT_MSG) { - uint8_t index = invoice_index(received_msg.product.customer_id, invoices); + product_msg *product = (product_msg*)(&received_msg); + uint8_t index = invoice_index(product->customer_id, invoices); if (index != -1) { if (invoices[index].n_prods > 0) { - invoices[index].total_sum += received_msg.product.prize; + invoices[index].total_sum += product->prize; invoices[index].n_prods--; } if (invoices[index].n_prods == 0) { @@ -146,7 +147,7 @@ PROCESS_THREAD(cassa_main_process, ev, data) { PROCESS_BEGIN(); static uint8_t customer_id; - static msg bro_customer_id; + static cash_out_msg bro_customer_id; cc26xx_uart_set_input(serial_line_input_byte); serial_line_init(); @@ -165,7 +166,7 @@ PROCESS_THREAD(cassa_main_process, ev, data) { printf("id: %d\n", (int)customer_id); bro_customer_id.msg_type = CASH_OUT_MSG; - bro_customer_id.cash_out.customer_id = customer_id; + bro_customer_id.customer_id = customer_id; LOG_INFO("Sending BROADCAST customer id: %d\n", (int)customer_id); LOG_INFO_LLADDR(NULL); From aafd37dd59cf534be7778f36431cc48adb0a3673 Mon Sep 17 00:00:00 2001 From: Daniela Date: Fri, 12 Apr 2019 16:30:01 +0200 Subject: [PATCH 5/6] Cassa and Supermarket updated --- project/Natalia/cassa.c | 43 +---------------- project/common/supermarket_net.h | 82 ++++++++++++++++++++++++++++---- project/msg.h | 71 --------------------------- 3 files changed, 75 insertions(+), 121 deletions(-) delete mode 100644 project/msg.h diff --git a/project/Natalia/cassa.c b/project/Natalia/cassa.c index 0fe235fff..5c21a54b9 100644 --- a/project/Natalia/cassa.c +++ b/project/Natalia/cassa.c @@ -10,54 +10,13 @@ #include "arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.h" #include +#include "../common/supermarket_net.h" #define MAX_CUSTOMERS 20 -enum message_type{CASH_OUT_MSG, PRODUCT_MSG, ITEM_ELEM_MSG, BASKET_MSG, START_OF_LIST_PRODUCTS_MSG}; -typedef struct basket_msg -{ - enum message_type msg_type; - uint8_t n_products; - uint8_t customer_id; - linkaddr_t* address; - - -}basket_msg; - -typedef struct user_invoice -{ - enum message_type msg_type; - uint8_t n_prods; - float total_sum; - uint8_t customer_id; - linkaddr_t* address_basket; - uint8_t empty; - - -}user_invoice; - -typedef struct cash_out_msg -{ - enum message_type msg_type; - uint8_t customer_id; -}cash_out_msg; - -typedef struct product_msg{ - - enum message_type msg_type; - uint8_t customer_id; - uint8_t product_id; - float prize; - -}product_msg; - -typedef struct msg{ - enum message_type msg_type; - -}msg; PROCESS(cassa_main_process, "Cassa process"); AUTOSTART_PROCESSES(&cassa_main_process); diff --git a/project/common/supermarket_net.h b/project/common/supermarket_net.h index 7a84eaa07..66606fd25 100644 --- a/project/common/supermarket_net.h +++ b/project/common/supermarket_net.h @@ -1,19 +1,85 @@ #ifndef SUPERMARKET_NET_H #define SUPERMARKET_NET_H -enum MsgType { +enum message_type { ASSOCIATION_REQUEST_MSG, ASSOCIATION_REPLY_MSG, BATTERY_STATUS_MSG, ASSIGNMENT_MSG, - PRODUCT_MSG, - CASHOUT_MSG, - ITEM_ELEM_MSG + CASH_OUT_MSG, + PRODUCT_MSG, + ITEM_ELEM_MSG, + BASKET_MSG, + START_OF_LIST_PRODUCTS_MSG }; -struct Msg { - enum MsgType type; - int test; -}; + +typedef struct msg { + enum message_type msg_type; +}msg; + +typedef struct assoc_req_msg +{ + enum message_type msg_type; + uint8_t battery_percentage; + +}assoc_req_msg; + + +typedef struct assoc_reply_msg +{ + enum message_type msg_type; +}assoc_reply_msg; + + +typedef struct battery_msg +{ + enum message_type msg_type; + uint8_t battery_percentage; +}battery_msg; + + +typedef struct assign_msg +{ + enum message_type msg_type; + uint32_t customer_id; +}assing_msg; + + +typedef struct basket_msg +{ + enum message_type msg_type; + uint8_t n_products; + uint8_t customer_id; + linkaddr_t* address; +}basket_msg; + + +typedef struct cash_out_msg +{ + enum message_type msg_type; + uint8_t customer_id; +}cash_out_msg; + + +typedef struct product_msg +{ + enum message_type msg_type; + uint8_t customer_id; + uint8_t product_id; + float prize; + +}product_msg; + +typedef struct user_invoice +{ + uint8_t n_prods; + float total_sum; + uint8_t customer_id; + linkaddr_t* address_basket; + uint8_t empty; + + +}user_invoice; #endif diff --git a/project/msg.h b/project/msg.h deleted file mode 100644 index 958e72679..000000000 --- a/project/msg.h +++ /dev/null @@ -1,71 +0,0 @@ - -enum message_type{ASSOCIATION_REQUEST_MSG, ASSOCIATION_REPLY_MSG, BATTERY_STATUS_MSG, ASSIGNMENT_MSG, CASH_OUT_MSG, PRODUCT_MSG, ITEM_ELEM_MSG, BASKET_MSG, START_OF_LIST_PRODUCTS_MSG}; - -/*typedef struct assoc_req_msg -{ - uint8_t battery_percentage; - -}assoc_req_msg; - - -typedef struct assoc_reply_msg -{ - //linkaddr_t* assigner_address; -}assoc_reply_msg; - - -typedef struct battery_msg -{ - uint8_t battery_percentage; -}battery_msg; - - -typedef struct assign_msg -{ - uint32_t customer_id; -}assing_msg; -*/ - -typedef struct basket_msg -{ - uint8_t n_products; - uint8_t customer_id; - linkaddr_t* address; - - -}basket_msg; - - -typedef struct cash_out_msg -{ - uint8_t customer_id; -}cash_out_msg; - - -typedef struct product_msg{ - - uint8_t customer_id; - uint8_t product_id; - float prize; - -}product_msg; - -//-----------------------Definition of the type of messages exchanged between the modules, with their useful informations. The significant fields are discriminated by the msg_type --------- - - -typedef struct assigner_msg //Message for communications between assigner and carts -{ - enum message_type msg_type; - //assoc_req_msg request; - //assoc_reply_msg reply; - uint8_t battery_percentage; - uint32_t customer_id; -}a_msg; - -typedef struct cash_desk_msg -{ - enum message_type msg_type; - cash_out_msg cash_out; - product_msg product; - basket_msg basket; -}cd_msg; From 90ea7bb4c138c6ac314efcb1e3c6974e911d2676 Mon Sep 17 00:00:00 2001 From: "natalija.zlatkova@gmail.com" Date: Fri, 12 Apr 2019 16:41:39 +0200 Subject: [PATCH 6/6] deleted adress field in basket structure --- project/Natalia/cassa.c | 2 +- project/common/supermarket_net.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project/Natalia/cassa.c b/project/Natalia/cassa.c index 5c21a54b9..8c29b2915 100644 --- a/project/Natalia/cassa.c +++ b/project/Natalia/cassa.c @@ -68,7 +68,7 @@ static void input_callback(const void* data, uint16_t len, const linkaddr_t* sou invoices[index].n_prods = basket->n_products; invoices[index].total_sum = 0; invoices[index].customer_id = basket->customer_id; - invoices[index].address_basket = basket->address; + invoices[index].address_basket = source_address; msg start_sending_list; start_sending_list.msg_type = START_OF_LIST_PRODUCTS_MSG; diff --git a/project/common/supermarket_net.h b/project/common/supermarket_net.h index 66606fd25..fa7af55ee 100644 --- a/project/common/supermarket_net.h +++ b/project/common/supermarket_net.h @@ -51,7 +51,7 @@ typedef struct basket_msg enum message_type msg_type; uint8_t n_products; uint8_t customer_id; - linkaddr_t* address; + }basket_msg;