Merge branch 'master' of git.giomba.it:giomba/nes-proj

This commit is contained in:
Daniela 2019-04-18 21:58:10 +02:00
commit 957c93d472
4 changed files with 12 additions and 8 deletions

View File

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

View File

@ -22,7 +22,9 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka
pkt.src = *src; pkt.src = *src;
pkt.dst = *dst; pkt.dst = *dst;
LOG_INFO("Received %d bytes from ", len); LOG_INFO_LLADDR(src); LOG_INFO("\n"); LOG_INFO("Received %d bytes from ", len); LOG_INFO_LLADDR(src);
LOG_INFO("type %d", ((msg*)data)->msg_type);
LOG_INFO("\n");
switch ( ((msg*)data)->msg_type ) { switch ( ((msg*)data)->msg_type ) {
case ASSOCIATION_REPLY_MSG: case ASSOCIATION_REPLY_MSG:
@ -46,7 +48,7 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL); process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break; break;
default: default:
LOG_INFO("[W] message type unknown\n"); LOG_INFO("[W] message type %d unknown\n", ((msg*)data)->msg_type);
break; break;
} }
} }

View File

@ -53,9 +53,10 @@ void s_shopping(process_event_t ev, process_data_t data) {
if (event == CART_EVENT_NEW_PRODUCT) { if (event == CART_EVENT_NEW_PRODUCT) {
/* add product to list */ /* add product to list */
if (nprod < MAX_PRODUCT) { if (nprod < MAX_PRODUCT) {
printf("[I] Adding item %d to cart\n", nprod);
item_msg* m = (item_msg*)pkt.data; item_msg* m = (item_msg*)pkt.data;
memcpy(&list[nprod++], &m->p, sizeof(product_t)); memcpy(&list[nprod], &m->p, sizeof(product_t));
printf("[I] Adding item #%d, id %d, price %d to cart\n", nprod, (int)list[nprod].product_id, (int)list[nprod].price);
nprod++;
} else { } else {
printf("[W] Too many products. Dropping.\n"); printf("[W] Too many products. Dropping.\n");
} }
@ -64,6 +65,7 @@ void s_shopping(process_event_t ev, process_data_t data) {
/* answer the cash if you are the one with that customer_id */ /* answer the cash if you are the one with that customer_id */
if (((cash_out_msg*)pkt.data)->customer_id == customer_id) { if (((cash_out_msg*)pkt.data)->customer_id == customer_id) {
printf("[I] It's me! I'm cashing out :-)\n"); printf("[I] It's me! I'm cashing out :-)\n");
cash_address = pkt.src;
basket_msg m; basket_msg m;
m.msg_type = BASKET_MSG; m.msg_type = BASKET_MSG;
m.n_products = nprod - 1; m.n_products = nprod - 1;
@ -91,7 +93,7 @@ void s_cash_out_wait4ack(process_event_t ev, process_data_t data) {
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...\n", i, nprod - 1); printf("[I] Sending product %d of %d: id %d, price: %d\n", i, nprod - 1, (int)list[i].product_id, (int)list[i].price);
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;
@ -105,7 +107,7 @@ void s_cash_out_send_list(process_event_t ev, process_data_t data) {
memset(&cash_address, 0, sizeof(cash_address)); memset(&cash_address, 0, sizeof(cash_address));
printf("[I] END. Go back to ASSOCIATED status\n"); printf("[I] END. Go back to ASSOCIATED status\n");
etimer_reset(&broadcast_timer); etimer_restart(&broadcast_timer);
status = ASSOCIATED; status = ASSOCIATED;
} }

View File

@ -18,7 +18,7 @@
/* Hardcoded MAC Address for cart */ /* Hardcoded MAC Address for cart */
/* This is used only to emulate the RFID tag */ /* This is used only to emulate the RFID tag */
static linkaddr_t dest_addr = {{0x00, 0x12, 0x4b, 0x00, 0x0f, 0x24, 0x18, 0x04}}; static linkaddr_t dest_addr = {{0x00, 0x12, 0x4b, 0x00, 0x0f, 0x82, 0x18, 0x04}};
product_t product_list[] = { product_t product_list[] = {
{ 1, "21/12/19", 105 }, { 1, "21/12/19", 105 },