[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
This commit is contained in:
giomba 2019-05-08 18:47:58 +02:00
parent 35f5041b7f
commit d7e3b0a70e
4 changed files with 23 additions and 5 deletions

View File

@ -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) {

View File

@ -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"

View File

@ -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 {

View File

@ -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){