[cart] not working
This commit is contained in:
parent
b3eaad66d0
commit
b38dccc325
@ -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;
|
||||
|
@ -2,7 +2,8 @@
|
||||
#define EVENT_H
|
||||
|
||||
enum CartEvent {
|
||||
CART_EVENT_ASSOCIATED
|
||||
CART_EVENT_ASSOCIATED,
|
||||
CART_EVENT_ASSIGNED
|
||||
} event;
|
||||
|
||||
#endif
|
||||
|
@ -29,6 +29,10 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka
|
||||
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;
|
||||
|
@ -3,6 +3,7 @@
|
||||
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) {
|
||||
@ -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 MsgBatteryStatus msg;
|
||||
msg.type = BATTERY_STATUS_MSG;
|
||||
msg.battery_percentage = 77;
|
||||
net_send(&msg, sizeof(msg), &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 = ((MsgAssignment*)pkt.data)->customer_id;
|
||||
status = SHOPPING;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -13,7 +13,34 @@ enum MsgType {
|
||||
|
||||
struct Msg {
|
||||
enum MsgType type;
|
||||
int test;
|
||||
uint8_t test;
|
||||
};
|
||||
|
||||
struct MsgBatteryStatus {
|
||||
enum MsgType type;
|
||||
uint8_t battery_percentage;
|
||||
};
|
||||
|
||||
struct MsgAssignment {
|
||||
enum MsgType type;
|
||||
uint32_t customer_id;
|
||||
};
|
||||
|
||||
struct MsgProduct {
|
||||
enum MsgType type;
|
||||
uint32_t product_id;
|
||||
float price;
|
||||
};
|
||||
|
||||
struct MsgCashOut {
|
||||
enum MsgType type;
|
||||
uint32_t customer_id;
|
||||
};
|
||||
|
||||
struct MsgItemElem {
|
||||
enum MsgType type;
|
||||
float price;
|
||||
bool last;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user