[cart] minor fixes -- not FSM looks very good and stable

This commit is contained in:
giomba 2019-05-03 17:21:16 +02:00
parent 25f28c16c2
commit a051841635
2 changed files with 9 additions and 5 deletions

View File

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

View File

@ -8,6 +8,7 @@ linkaddr_t assigner_address;
linkaddr_t cash_address;
uint32_t customer_id = 1234;
uint8_t nprod = 0;
uint16_t totalPrice = 0;
uint8_t nprod_index = 0; //variable used to keep track of the index of the product to be sent
product_t list[MAX_PRODUCT];
@ -57,6 +58,7 @@ void s_shopping(process_event_t ev, process_data_t data) {
item_msg* m = (item_msg*)pkt.data;
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);
totalPrice+=list[nprod].price;
nprod++;
} else {
printf("[W] Too many products. Dropping.\n");
@ -93,6 +95,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) {
/* Send list, then go back to initial state */
printf("[I] Total price is %d\n", totalPrice);
if (nprod_index<nprod) {
LOG_INFO("[I] Sending product %d of %d: id %d, price: %d\n", nprod_index, nprod - 1, (int)list[nprod_index].product_id, (int)list[nprod_index].price);
@ -112,7 +115,8 @@ void s_cash_out_send_list(process_event_t ev, process_data_t data) {
printf("[I] END. Go back to ASSOCIATED status\n");
etimer_restart(&broadcast_timer);
status = SHOPPING;
totalPrice = 0;
status = ASSOCIATED;
}
}