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