[cart] Now cart should associate

This commit is contained in:
giomba 2019-04-12 14:56:37 +02:00
parent ef9cde532f
commit 477963987f
6 changed files with 72 additions and 38 deletions

View File

@ -1,5 +1,5 @@
CONTIKI_PROJECT = cart
PROJECT_SOURCEFILES += sendrecv.c
PROJECT_SOURCEFILES += sendrecv.c status.c
PLATFORMS_ONLY = cc26x0-cc13x0
all: $(CONTIKI_PROJECT)

View File

@ -8,57 +8,27 @@
#include "event.h"
#include "log.h"
#include "sendrecv.h"
#include "status.h"
//static linkaddr_t destination_address = {{ 0x00, 0x12, 0x4b, 0x00, 0x0f, 0x8f, 0x18, 0x11 }};
PROCESS(cart_main_process, "Cart Process");
AUTOSTART_PROCESSES(&cart_main_process);
enum CartStatus {
NOT_ASSOCIATED,
ASSOCIATED,
SHOPPING,
CASHOUT
} status;
static uint8_t net_buffer[256];
static struct etimer broadcast_timer;
void s_not_associated(process_event_t ev, process_data_t data) {
if (ev == PROCESS_EVENT_TIMER) {
// send broadcast message to request association with assigner
if (etimer_expired(&broadcast_timer)) {
//net_send(/*TODO*/);
}
}
else if (ev == PROCESS_EVENT_MSG && *((enum CartEvent*)data) == CART_EVENT_ASSOCIATED) {
status = ASSOCIATED;
}
}
PROCESS_THREAD(cart_main_process, ev, data) {
PROCESS_BEGIN();
// SENSORS_ACTIVATE(batmon_sensor);
/* Local variables allocation */
// SENSORS_ACTIVATE(batmon_sensor);
/*** Variables initialization ***/
/* Finite State Machine Status */
status = CASHOUT;
/* Network initialization */
nullnet_buf = net_buffer;
nullnet_set_input_callback(net_recv);
/* fixme garbage */
status = NOT_ASSOCIATED;
etimer_set(&broadcast_timer, 10 * CLOCK_SECOND);
/*** Subsystem initialization ***/
net_init();
/* now actually start */
/* START */
printf("Hello! I'm the cart.\n");
while (true) {

View File

@ -2,6 +2,13 @@
struct MacPkt pkt;
uint8_t net_buffer[256];
void net_init() {
nullnet_buf = net_buffer;
nullnet_set_input_callback(net_recv);
}
void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst) {
/* discard too long packet */
if (len > 128) {
@ -28,3 +35,9 @@ void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linka
}
}
void net_send(const void* data, uint16_t len, const linkaddr_t* dst) {
memcpy(net_buffer, data, len);
nullnet_len = len;
NETSTACK_NETWORK.output(dst);
}

View File

@ -25,6 +25,7 @@ extern struct MacPkt pkt;
extern struct process cart_main_process;
void net_init(void);
void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst);
void net_send(const void* data, uint16_t len, const linkaddr_t* dst);

26
project/Giomba/status.c Normal file
View File

@ -0,0 +1,26 @@
#include "status.h"
enum CartStatus status;
struct etimer broadcast_timer;
linkaddr_t assigner_address;
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);
etimer_reset(&broadcast_timer);
}
}
else /* if a msg is received from network and represents an association event, then associate */
if (ev == PROCESS_EVENT_MSG && *((enum CartEvent*)data) == CART_EVENT_ASSOCIATED) {
printf("[I] Associated with Assigner\n");
assigner_address = pkt.src;
status = ASSOCIATED;
}
}

24
project/Giomba/status.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef STATUS_H
#define STATUS_H
#include "contiki.h"
#include "sys/etimer.h"
#include "sys/process.h"
#include "../common/supermarket_net.h"
#include "event.h"
#include "sendrecv.h"
enum CartStatus {
NOT_ASSOCIATED,
ASSOCIATED,
SHOPPING,
CASHOUT
};
extern enum CartStatus status;
extern struct etimer broadcast_timer;
void s_not_associated(process_event_t ev, process_data_t data);
#endif