From b3eaad66d037b10c63d526931a377b6fc483e180 Mon Sep 17 00:00:00 2001 From: giomba Date: Fri, 12 Apr 2019 16:10:52 +0200 Subject: [PATCH 1/4] [repo] added a gitignore --- project/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 project/.gitignore diff --git a/project/.gitignore b/project/.gitignore new file mode 100644 index 000000000..1377554eb --- /dev/null +++ b/project/.gitignore @@ -0,0 +1 @@ +*.swp From b38dccc3256b8e002a9782fead93ba0ad6f2c823 Mon Sep 17 00:00:00 2001 From: giomba Date: Fri, 12 Apr 2019 16:30:05 +0200 Subject: [PATCH 2/4] [cart] not working --- project/Giomba/cart.c | 7 ++++--- project/Giomba/event.h | 3 ++- project/Giomba/sendrecv.c | 4 ++++ project/Giomba/status.c | 20 ++++++++++++++++++++ project/Giomba/status.h | 1 + project/common/supermarket_net.h | 29 ++++++++++++++++++++++++++++- 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/project/Giomba/cart.c b/project/Giomba/cart.c index ac026592a..29bf94fdd 100644 --- a/project/Giomba/cart.c +++ b/project/Giomba/cart.c @@ -21,9 +21,8 @@ PROCESS_THREAD(cart_main_process, ev, data) { // SENSORS_ACTIVATE(batmon_sensor); /*** Variables initialization ***/ - status = NOT_ASSOCIATED; - etimer_set(&broadcast_timer, 10 * CLOCK_SECOND); + etimer_set(&broadcast_timer, 5 * CLOCK_SECOND); /*** Subsystem initialization ***/ net_init(); @@ -39,7 +38,9 @@ PROCESS_THREAD(cart_main_process, ev, data) { s_not_associated(ev, data); break; break; - case ASSOCIATED: break; + case ASSOCIATED: + s_associated(ev, data); + break; case SHOPPING: break; case CASHOUT: break; default: status = NOT_ASSOCIATED; break; diff --git a/project/Giomba/event.h b/project/Giomba/event.h index f938ff1ab..803a3e5e0 100644 --- a/project/Giomba/event.h +++ b/project/Giomba/event.h @@ -2,7 +2,8 @@ #define EVENT_H enum CartEvent { - CART_EVENT_ASSOCIATED + CART_EVENT_ASSOCIATED, + CART_EVENT_ASSIGNED } event; #endif diff --git a/project/Giomba/sendrecv.c b/project/Giomba/sendrecv.c index 2abb49459..dc76a2b5a 100644 --- a/project/Giomba/sendrecv.c +++ b/project/Giomba/sendrecv.c @@ -29,6 +29,10 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka event = CART_EVENT_ASSOCIATED; process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL); break; + case ASSIGNMENT_MSG: + event = CART_EVENT_ASSIGNED; + process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL); + break; default: LOG_INFO("[W] message type unknown\n"); break; diff --git a/project/Giomba/status.c b/project/Giomba/status.c index 530265f87..645cf5f81 100644 --- a/project/Giomba/status.c +++ b/project/Giomba/status.c @@ -3,6 +3,7 @@ enum CartStatus status; struct etimer broadcast_timer; linkaddr_t assigner_address; +uint32_t customer_id; void s_not_associated(process_event_t ev, process_data_t data) { if (ev == PROCESS_EVENT_TIMER) { @@ -23,4 +24,23 @@ void s_not_associated(process_event_t ev, process_data_t data) { } } +void s_associated(process_event_t ev, process_data_t data) { + if (ev == PROCESS_EVENT_TIMER) { + /* now send battery level */ + printf("[I] Sending battery level\n"); + struct MsgBatteryStatus msg; + msg.type = BATTERY_STATUS_MSG; + msg.battery_percentage = 77; + net_send(&msg, sizeof(msg), &assigner_address); + etimer_reset(&broadcast_timer); + } + if (ev == PROCESS_EVENT_MSG && *((enum CartEvent*)data) == CART_EVENT_ASSIGNED) { + /* cart has been assigned to a new customer */ + printf("[I] Assigned to customer\n"); + customer_id = ((MsgAssignment*)pkt.data)->customer_id; + status = SHOPPING; + } + +} + diff --git a/project/Giomba/status.h b/project/Giomba/status.h index 7a4c8c1f4..b8c55af01 100644 --- a/project/Giomba/status.h +++ b/project/Giomba/status.h @@ -20,5 +20,6 @@ extern enum CartStatus status; extern struct etimer broadcast_timer; void s_not_associated(process_event_t ev, process_data_t data); +void s_associated(process_event_t ev, process_data_t data); #endif diff --git a/project/common/supermarket_net.h b/project/common/supermarket_net.h index 7a84eaa07..0a954bdd0 100644 --- a/project/common/supermarket_net.h +++ b/project/common/supermarket_net.h @@ -13,7 +13,34 @@ enum MsgType { struct Msg { enum MsgType type; - int test; + uint8_t test; +}; + +struct MsgBatteryStatus { + enum MsgType type; + uint8_t battery_percentage; +}; + +struct MsgAssignment { + enum MsgType type; + uint32_t customer_id; +}; + +struct MsgProduct { + enum MsgType type; + uint32_t product_id; + float price; +}; + +struct MsgCashOut { + enum MsgType type; + uint32_t customer_id; +}; + +struct MsgItemElem { + enum MsgType type; + float price; + bool last; }; #endif From abadc65caf9d5076f439b699fa1e70c1191d9a83 Mon Sep 17 00:00:00 2001 From: francescobarbarulo Date: Fri, 12 Apr 2019 16:44:20 +0200 Subject: [PATCH 3/4] First version of product --- project/product/Makefile | 12 +++++ project/product/product.c | 92 ++++++++++++++++++++++++++++++++++ project/product/project-conf.h | 46 +++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 project/product/Makefile create mode 100644 project/product/product.c create mode 100644 project/product/project-conf.h diff --git a/project/product/Makefile b/project/product/Makefile new file mode 100644 index 000000000..f971c57c5 --- /dev/null +++ b/project/product/Makefile @@ -0,0 +1,12 @@ +CONTIKI_PROJECT = product +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/product/product.c b/project/product/product.c new file mode 100644 index 000000000..9a2c125a8 --- /dev/null +++ b/project/product/product.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2017, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +#include "net/netstack.h" +#include "net/nullnet/nullnet.h" +#include "os/net/linkaddr.h" +#include "os/dev/button-hal.h" +#include "os/dev/leds.h" +#include +#include +#include +#include "sys/log.h" +#include "sys/clock.h" +#include "contiki.h" + +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +static linkaddr_t dest_addr = {{0x00, 0x12, 0x4b, 0x00, 0x0f, 0x82, 0x18, 0x04}}; + + +struct Product { + char name[20]; + char expiration_date[8]; // gg/mm/yy + double price; +}; + +struct Product product_list[] = { + { "latte" , "21/12/19", 1.05 }, + { "pane" , "12/05/19", 3.25 }, + { "cioccolato", "05/05/21", 2.50 } +}; + + +PROCESS(product_proc, "product random generator"); +AUTOSTART_PROCESSES(&product_proc); + +void scan_product(struct Product *p){ + nullnet_buf = (uint8_t *)p; + nullnet_len = sizeof(*p); + NETSTACK_NETWORK.output(&dest_addr); + LOG_INFO("Product %s scanned from ", p->name); + LOG_INFO_LLADDR(&dest_addr); + LOG_INFO_("\n"); +} + +PROCESS_THREAD(product_proc, ev, data){ + PROCESS_BEGIN(); + // init random number generator + unsigned int magic_seed = 12; + srand(magic_seed); + + while(1) { + PROCESS_YIELD(); + if (ev == button_hal_press_event){ + + // product generation + unsigned int index = rand() % 3; + scan_product(&product_list[index]); + } + } + PROCESS_END(); +} diff --git a/project/product/project-conf.h b/project/product/project-conf.h new file mode 100644 index 000000000..39dfaaf54 --- /dev/null +++ b/project/product/project-conf.h @@ -0,0 +1,46 @@ +/* + * 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 +/*---------------------------------------------------------------------------*/ +/* log */ +#define LOG_CONF_LEVEL_NULLNET LOG_LEVEL_DBG +/*---------------------------------------------------------------------------*/ +#endif /* PROJECT_CONF_H_ */ +/*---------------------------------------------------------------------------*/ From e7bf80de713b20ff5a1b574a7f09481fcc8227cf Mon Sep 17 00:00:00 2001 From: francescobarbarulo Date: Fri, 12 Apr 2019 17:50:48 +0200 Subject: [PATCH 4/4] Added some comments --- project/product/product.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project/product/product.c b/project/product/product.c index 9a2c125a8..22ff3e416 100644 --- a/project/product/product.c +++ b/project/product/product.c @@ -45,6 +45,7 @@ #define LOG_MODULE "App" #define LOG_LEVEL LOG_LEVEL_INFO +// !! TO INIT WITH CART MAC ADDRESS !! // static linkaddr_t dest_addr = {{0x00, 0x12, 0x4b, 0x00, 0x0f, 0x82, 0x18, 0x04}}; @@ -76,13 +77,12 @@ void scan_product(struct Product *p){ PROCESS_THREAD(product_proc, ev, data){ PROCESS_BEGIN(); // init random number generator - unsigned int magic_seed = 12; + unsigned int magic_seed = 12; // oooh :o srand(magic_seed); - + while(1) { PROCESS_YIELD(); if (ev == button_hal_press_event){ - // product generation unsigned int index = rand() % 3; scan_product(&product_list[index]);