[Assigner] Bugs fixed in handling mac addresses. Some other adjustments in Assigner Module

This commit is contained in:
Daniela 2019-04-14 18:53:33 +02:00
commit 35a8bcce3d
6 changed files with 45 additions and 35 deletions

View File

@ -20,7 +20,8 @@ PROCESS_THREAD(cart_main_process, ev, data) {
// SENSORS_ACTIVATE(batmon_sensor); // SENSORS_ACTIVATE(batmon_sensor);
/*** Variables initialization ***/ /*** Variables initialization ***/
status = NOT_ASSOCIATED; // status = NOT_ASSOCIATED; // TODO DEBUG
status = SHOPPING;
etimer_set(&broadcast_timer, 5 * CLOCK_SECOND); etimer_set(&broadcast_timer, 5 * CLOCK_SECOND);
/*** Subsystem initialization ***/ /*** Subsystem initialization ***/

View File

@ -33,7 +33,7 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka
event = CART_EVENT_ASSIGNED; event = CART_EVENT_ASSIGNED;
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL); process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break; break;
case PRODUCT_MSG: case ITEM_MSG:
event = CART_EVENT_NEW_PRODUCT; event = CART_EVENT_NEW_PRODUCT;
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL); process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break; break;

View File

@ -6,7 +6,7 @@ enum CartStatus status;
struct etimer broadcast_timer; struct etimer broadcast_timer;
linkaddr_t assigner_address; linkaddr_t assigner_address;
linkaddr_t cash_address; linkaddr_t cash_address;
uint32_t customer_id; uint32_t customer_id = 1234;
uint8_t nprod; uint8_t nprod;
product_t list[MAX_PRODUCT]; product_t list[MAX_PRODUCT];
@ -42,11 +42,10 @@ void s_associated(process_event_t ev, process_data_t data) {
} }
if (ev == PROCESS_EVENT_MSG && event == CART_EVENT_ASSIGNED) { if (ev == PROCESS_EVENT_MSG && event == CART_EVENT_ASSIGNED) {
/* cart has been assigned to a new customer */ /* cart has been assigned to a new customer */
printf("[I] Assigned to customer\n");
customer_id = ((assign_msg*)pkt.data)->customer_id; customer_id = ((assign_msg*)pkt.data)->customer_id;
printf("[I] Assigned to customer id %d\n", (int)customer_id);
status = SHOPPING; status = SHOPPING;
} }
} }
void s_shopping(process_event_t ev, process_data_t data) { void s_shopping(process_event_t ev, process_data_t data) {
@ -63,26 +62,36 @@ void s_shopping(process_event_t ev, process_data_t data) {
} }
if (event == CART_EVENT_CASH_OUT) { if (event == CART_EVENT_CASH_OUT) {
/* answer the cash if you are the one with that customer_id */ /* answer the cash if you are the one with that customer_id */
basket_msg m; if (((cash_out_msg*)pkt.data)->customer_id == customer_id) {
m.n_products = nprod - 1; printf("[I] It's me! I'm cashing out :-)\n");
m.customer_id = customer_id; /* TODO -- is this really needed? */ basket_msg m;
net_send(&m, sizeof(m), &cash_address); m.msg_type = BASKET_MSG;
status = CASH_OUT_WAIT4ACK; m.n_products = nprod - 1;
m.customer_id = customer_id; /* TODO -- is this really needed? */
net_send(&m, sizeof(m), &cash_address);
status = CASH_OUT_WAIT4ACK;
}
else {
printf("[I] I am customer id %d; customer id %d is cashing out nearby\n", (int)customer_id, (int)((cash_out_msg*)pkt.data)->customer_id );
}
} }
} }
} }
void s_cash_out_wait4ack(process_event_t ev, process_data_t data) { void s_cash_out_wait4ack(process_event_t ev, process_data_t data) {
/* Just wait for cash ack */ /* Just wait for cash ack */
if (ev == CART_EVENT_CASH_OUT_ACK) { if (event == CART_EVENT_CASH_OUT_ACK) {
printf("[I] Acknoweledgment received fromc cash. Now I'll send the list.\n");
status = CASH_OUT_SEND_LIST; status = CASH_OUT_SEND_LIST;
/* this wakes up the process that otherwise would wait indefinitely for an event that will never occurr */
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
} }
} }
void s_cash_out_send_list(process_event_t ev, process_data_t data) { void s_cash_out_send_list(process_event_t ev, process_data_t data) {
/* Send list, then go back to initial state */ /* Send list, then go back to initial state */
for (uint8_t i = 0; i < nprod; ++i) { for (uint8_t i = 0; i < nprod; ++i) {
printf("[I] Sending product %d of %d...", i, nprod - 1); printf("[I] Sending product %d of %d...\n", i, nprod - 1);
product_msg m; product_msg m;
m.msg_type = PRODUCT_MSG; m.msg_type = PRODUCT_MSG;
m.customer_id = customer_id; m.customer_id = customer_id;
@ -95,6 +104,8 @@ void s_cash_out_send_list(process_event_t ev, process_data_t data) {
customer_id = 0; customer_id = 0;
memset(&cash_address, 0, sizeof(cash_address)); memset(&cash_address, 0, sizeof(cash_address));
printf("[I] END. Go back to ASSOCIATED status\n");
etimer_reset(&broadcast_timer);
status = ASSOCIATED; status = ASSOCIATED;
} }

View File

@ -20,9 +20,9 @@ typedef struct user_invoice
{ {
uint8_t n_prods; uint8_t n_prods;
float total_sum; float total_sum;
uint8_t customer_id; uint32_t customer_id;
uint8_t empty; uint8_t empty;
linkaddr_t* address_basket; linkaddr_t address_basket;
}user_invoice; }user_invoice;
@ -63,9 +63,9 @@ static void input_callback(const void* data, uint16_t len, const linkaddr_t* sou
static user_invoice invoices[MAX_CUSTOMERS]; static user_invoice invoices[MAX_CUSTOMERS];
if (len == sizeof(*data)) { // if (len == sizeof(*data)) {
memcpy (&received_msg, data, sizeof ((msg *)data)); memcpy (&received_msg, data, sizeof(received_msg));
LOG_INFO("Received data"); LOG_INFO("Received data ");
LOG_INFO_LLADDR(source_address); //this is the link layer address LOG_INFO_LLADDR(source_address); //this is the link layer address
LOG_INFO("\n"); LOG_INFO("\n");
//we need to receive an additional message to start the process of receiving the products because if we start receiving the products immediately //we need to receive an additional message to start the process of receiving the products because if we start receiving the products immediately
@ -77,25 +77,23 @@ static void input_callback(const void* data, uint16_t len, const linkaddr_t* sou
invoices[index].n_prods = basket->n_products; invoices[index].n_prods = basket->n_products;
invoices[index].total_sum = 0; invoices[index].total_sum = 0;
invoices[index].customer_id = basket->customer_id; invoices[index].customer_id = basket->customer_id;
memcpy(&invoices[index].address_basket, source_address, sizeof(*source_address)); memcpy(&invoices[index].address_basket, source_address, sizeof(linkaddr_t));
// invoices[index].address_basket = source_address; // invoices[index].address_basket = source_address;
msg start_sending_list; msg start_sending_list;
start_sending_list.msg_type = START_OF_LIST_PRODUCTS_MSG; start_sending_list.msg_type = START_OF_LIST_PRODUCTS_MSG;
nullnet_buf = (uint8_t*)&start_sending_list; nullnet_buf = (uint8_t*)&start_sending_list;
LOG_INFO("Sending acknowledgment to start sending list of products"); LOG_INFO("Sending acknowledgment to start sending list of products to ");
LOG_INFO_("\n"); LOG_INFO_LLADDR(&(invoices[index].address_basket));
nullnet_len = sizeof(start_sending_list); nullnet_len = sizeof(start_sending_list);
NETSTACK_NETWORK.output((invoices[index].address_basket)); NETSTACK_NETWORK.output(&(invoices[index].address_basket));
} else } else
printf("Reached max number of customers"); printf("Reached max number of customers\n");
} }
if (received_msg.msg_type == PRODUCT_MSG) { if (received_msg.msg_type == PRODUCT_MSG) {
product_msg *product = (product_msg*)(&received_msg); product_msg *product = (product_msg*)(&received_msg);
printf("Received id: %d, price %f\n", (int)product->product_id, product->price);
uint8_t index = invoice_index(product->customer_id, invoices); uint8_t index = invoice_index(product->customer_id, invoices);
if (index != -1) { if (index != -1) {
if (invoices[index].n_prods > 0) { if (invoices[index].n_prods > 0) {
@ -107,15 +105,15 @@ static void input_callback(const void* data, uint16_t len, const linkaddr_t* sou
invoices[index].empty = 1; invoices[index].empty = 1;
} }
}else }else
printf("Customer with that id is not associated to any basket!"); printf("Customer with that id is not associated to any basket!\n");
} }
} // }
} }
PROCESS_THREAD(cassa_main_process, ev, data) { PROCESS_THREAD(cassa_main_process, ev, data) {
PROCESS_BEGIN(); PROCESS_BEGIN();
static uint8_t customer_id; static uint32_t customer_id;
static cash_out_msg bro_customer_id; static cash_out_msg bro_customer_id;
cc26xx_uart_set_input(serial_line_input_byte); cc26xx_uart_set_input(serial_line_input_byte);

View File

@ -51,7 +51,7 @@ typedef struct basket_msg
{ {
enum message_type msg_type; enum message_type msg_type;
uint8_t n_products; uint8_t n_products;
uint8_t customer_id; /* TODO: why? you already know it */ uint32_t customer_id;
}basket_msg; }basket_msg;
typedef struct item_msg typedef struct item_msg
@ -63,15 +63,15 @@ typedef struct item_msg
typedef struct cash_out_msg typedef struct cash_out_msg
{ {
enum message_type msg_type; enum message_type msg_type;
uint8_t customer_id; uint32_t customer_id;
}cash_out_msg; }cash_out_msg;
typedef struct product_msg typedef struct product_msg
{ {
enum message_type msg_type; enum message_type msg_type;
uint8_t customer_id; uint32_t customer_id;
uint8_t product_id; uint32_t product_id;
float price; float price;
}product_msg; }product_msg;

View File

@ -16,9 +16,9 @@
#define LOG_MODULE "App" #define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_INFO #define LOG_LEVEL LOG_LEVEL_INFO
// !! TO INIT WITH CART MAC ADDRESS !! // /* Hardcoded MAC Address for cart */
static linkaddr_t dest_addr = {{0x00, 0x12, 0x4b, 0x00, 0x0f, 0x82, 0x18, 0x04}}; /* This is used only to emulate the RFID tag */
static linkaddr_t dest_addr = {{0x00, 0x12, 0x4b, 0x00, 0x0f, 0x24, 0x18, 0x04}};
product_t product_list[] = { product_t product_list[] = {
{ 1, "21/12/19", 1.05 }, { 1, "21/12/19", 1.05 },