From d7e3b0a70ebd65ee5dc0286bfe0e1372285c15a3 Mon Sep 17 00:00:00 2001 From: giomba Date: Wed, 8 May 2019 18:47:58 +0200 Subject: [PATCH] [product + cart] single product / multiple cart now when you press a button on the cart you notify the product launchpad about your presence; then the product launchpad always sends packets to you; this allows the use of multiple carts with only a single product --- project/Giomba/status.c | 8 +++++++- project/Giomba/status.h | 2 ++ project/common/supermarket_net.h | 3 ++- project/product/product.c | 15 ++++++++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/project/Giomba/status.c b/project/Giomba/status.c index 003683509..5eb3bc09e 100644 --- a/project/Giomba/status.c +++ b/project/Giomba/status.c @@ -73,7 +73,7 @@ void s_shopping(process_event_t ev, process_data_t data) { basket_msg m; m.msg_type = BASKET_MSG; m.n_products = nprod; - m.customer_id = customer_id; /* TODO -- is this really needed? */ + m.customer_id = customer_id; /* this is needed to handle multiple customers at the cash register */ net_send(&m, sizeof(m), &cash_address); status = CASH_OUT_WAIT4ACK; } @@ -82,6 +82,12 @@ void s_shopping(process_event_t ev, process_data_t data) { } } } + if (ev == button_hal_release_event) { /* any button will do */ + /* ask product to send items to me */ + msg m; + m.msg_type = START_SHOPPING_MSG; + net_send(&m, sizeof(m), NULL); + } } void s_cash_out_wait4ack(process_event_t ev, process_data_t data) { diff --git a/project/Giomba/status.h b/project/Giomba/status.h index ca52dfc88..27915b340 100644 --- a/project/Giomba/status.h +++ b/project/Giomba/status.h @@ -5,6 +5,8 @@ #include "sys/etimer.h" #include "sys/process.h" +#include "os/dev/button-hal.h" + #include "../common/supermarket_net.h" #include "event.h" #include "sendrecv.h" diff --git a/project/common/supermarket_net.h b/project/common/supermarket_net.h index acaea11a0..a9ba4aba4 100644 --- a/project/common/supermarket_net.h +++ b/project/common/supermarket_net.h @@ -15,7 +15,8 @@ enum message_type { PRODUCT_PARTIAL_LIST_MSG, /* from cart to cash */ BASKET_MSG, START_OF_LIST_PRODUCTS_MSG, - PRODUCT_PARTIAL_LIST_ACK /* everytime the cash register receives a product message, it sends an ack to the cart so that the cart can send the next product message */ + PRODUCT_PARTIAL_LIST_ACK, /* everytime the cash register receives a product message, it sends an ack to the cart so that the cart can send the next product message */ + START_SHOPPING_MSG }; typedef struct msg { diff --git a/project/product/product.c b/project/product/product.c index b42e909b5..6822e40cc 100644 --- a/project/product/product.c +++ b/project/product/product.c @@ -16,8 +16,7 @@ #define LOG_MODULE "App" #define LOG_LEVEL LOG_LEVEL_INFO -/* Hardcoded MAC Address for cart */ -/* This is used only to emulate the RFID tag */ +/* MAC Address for cart -- This emulates the RFID tag */ static linkaddr_t dest_addr = {{0x00, 0x12, 0x4b, 0x00, 0x0f, 0x82, 0x00, 0x04}}; product_t product_list[] = { @@ -43,12 +42,22 @@ void scan_product(product_t* p){ LOG_INFO_("\n"); } +void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst) { + if (((msg*)data)->msg_type == START_SHOPPING_MSG) { + printf("Now sending products to new cart\n"); + memcpy(&dest_addr, src, sizeof(src)); + } +} + PROCESS_THREAD(product_proc, ev, data){ PROCESS_BEGIN(); // init random number generator - unsigned int magic_seed = 12; // oooh :o + unsigned int magic_seed = 12; srand(magic_seed); + // init network subsystem + nullnet_set_input_callback(net_recv); + while(1) { PROCESS_YIELD(); if (ev == button_hal_press_event){