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

View File

@ -2,7 +2,8 @@
#define EVENT_H
enum CartEvent {
CART_EVENT_ASSOCIATED
CART_EVENT_ASSOCIATED,
CART_EVENT_ASSIGNED
} event;
#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");
switch ( ((struct Msg*)data)->type ) {
switch ( ((msg*)data)->msg_type ) {
case ASSOCIATION_REPLY_MSG:
event = CART_EVENT_ASSOCIATED;
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break;
case ASSIGNMENT_MSG:
event = CART_EVENT_ASSIGNED;
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break;
default:
LOG_INFO("[W] message type unknown\n");
break;

View File

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

View File

@ -13,7 +13,6 @@ enum message_type {
START_OF_LIST_PRODUCTS_MSG
};
typedef struct msg {
enum message_type msg_type;
}msg;
@ -43,7 +42,7 @@ typedef struct assign_msg
{
enum message_type msg_type;
uint32_t customer_id;
}assing_msg;
}assign_msg;
typedef struct basket_msg
@ -51,7 +50,6 @@ typedef struct basket_msg
enum message_type msg_type;
uint8_t n_products;
uint8_t customer_id;
}basket_msg;
@ -76,7 +74,6 @@ typedef struct user_invoice
uint8_t n_prods;
float total_sum;
uint8_t customer_id;
linkaddr_t* address_basket;
uint8_t empty;