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

This commit is contained in:
francescobarbarulo 2019-04-12 17:51:12 +02:00
commit 268e8b624f
7 changed files with 44 additions and 19 deletions

1
project/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.swp

View File

@ -21,9 +21,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;
etimer_set(&broadcast_timer, 10 * CLOCK_SECOND); etimer_set(&broadcast_timer, 5 * CLOCK_SECOND);
/*** Subsystem initialization ***/ /*** Subsystem initialization ***/
net_init(); net_init();
@ -39,7 +38,9 @@ PROCESS_THREAD(cart_main_process, ev, data) {
s_not_associated(ev, data); s_not_associated(ev, data);
break; break;
break; break;
case ASSOCIATED: break; case ASSOCIATED:
s_associated(ev, data);
break;
case SHOPPING: break; case SHOPPING: break;
case CASHOUT: break; case CASHOUT: break;
default: status = NOT_ASSOCIATED; break; default: status = NOT_ASSOCIATED; break;

View File

@ -2,7 +2,8 @@
#define EVENT_H #define EVENT_H
enum CartEvent { enum CartEvent {
CART_EVENT_ASSOCIATED CART_EVENT_ASSOCIATED,
CART_EVENT_ASSIGNED
} event; } event;
#endif #endif

View File

@ -24,11 +24,15 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka
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("\n");
switch ( ((struct Msg*)data)->type ) { switch ( ((msg*)data)->msg_type ) {
case ASSOCIATION_REPLY_MSG: case ASSOCIATION_REPLY_MSG:
event = CART_EVENT_ASSOCIATED; event = CART_EVENT_ASSOCIATED;
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL); process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break; break;
case ASSIGNMENT_MSG:
event = CART_EVENT_ASSIGNED;
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break;
default: default:
LOG_INFO("[W] message type unknown\n"); LOG_INFO("[W] message type unknown\n");
break; break;

View File

@ -3,15 +3,16 @@
enum CartStatus status; enum CartStatus status;
struct etimer broadcast_timer; struct etimer broadcast_timer;
linkaddr_t assigner_address; linkaddr_t assigner_address;
uint32_t customer_id;
void s_not_associated(process_event_t ev, process_data_t data) { void s_not_associated(process_event_t ev, process_data_t data) {
if (ev == PROCESS_EVENT_TIMER) { if (ev == PROCESS_EVENT_TIMER) {
/* at time expiration, send broadcast message to request association with assigner */ /* at time expiration, send broadcast message to request association with assigner */
if (etimer_expired(&broadcast_timer)) { if (etimer_expired(&broadcast_timer)) {
printf("[I] Sending association request msg\n"); printf("[I] Sending association request msg\n");
struct Msg msg; msg m;
msg.type = ASSOCIATION_REQUEST_MSG; m.msg_type = ASSOCIATION_REQUEST_MSG;
net_send(&msg, sizeof(msg), NULL); net_send(&m, sizeof(m), NULL);
etimer_reset(&broadcast_timer); etimer_reset(&broadcast_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 battery_msg m;
m.msg_type = BATTERY_STATUS_MSG;
m.battery_percentage = 77;
net_send(&m, sizeof(m), &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 = ((assign_msg*)pkt.data)->customer_id;
status = SHOPPING;
}
}

View File

@ -20,5 +20,6 @@ extern enum CartStatus status;
extern struct etimer broadcast_timer; extern struct etimer broadcast_timer;
void s_not_associated(process_event_t ev, process_data_t data); void s_not_associated(process_event_t ev, process_data_t data);
void s_associated(process_event_t ev, process_data_t data);
#endif #endif

View File

@ -7,18 +7,17 @@ enum message_type {
BATTERY_STATUS_MSG, BATTERY_STATUS_MSG,
ASSIGNMENT_MSG, ASSIGNMENT_MSG,
CASH_OUT_MSG, CASH_OUT_MSG,
PRODUCT_MSG, PRODUCT_MSG,
ITEM_ELEM_MSG, ITEM_ELEM_MSG,
BASKET_MSG, BASKET_MSG,
START_OF_LIST_PRODUCTS_MSG START_OF_LIST_PRODUCTS_MSG
}; };
typedef struct msg { typedef struct msg {
enum message_type msg_type; enum message_type msg_type;
}msg; }msg;
typedef struct assoc_req_msg typedef struct assoc_req_msg
{ {
enum message_type msg_type; enum message_type msg_type;
uint8_t battery_percentage; uint8_t battery_percentage;
@ -43,15 +42,14 @@ typedef struct assign_msg
{ {
enum message_type msg_type; enum message_type msg_type;
uint32_t customer_id; uint32_t customer_id;
}assing_msg; }assign_msg;
typedef struct basket_msg 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; uint8_t customer_id;
}basket_msg; }basket_msg;
@ -64,7 +62,7 @@ typedef struct 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; uint8_t customer_id;
uint8_t product_id; uint8_t product_id;
float prize; float prize;
@ -76,10 +74,9 @@ typedef struct user_invoice
uint8_t n_prods; uint8_t n_prods;
float total_sum; float total_sum;
uint8_t customer_id; uint8_t customer_id;
linkaddr_t* address_basket;
uint8_t empty; uint8_t empty;
}user_invoice; }user_invoice;
#endif #endif