[cart] first unuseful version for cart

This commit is contained in:
giomba 2019-04-11 17:46:54 +02:00
parent 55f248f517
commit ef9cde532f
8 changed files with 218 additions and 0 deletions

14
project/Giomba/Makefile Normal file
View File

@ -0,0 +1,14 @@
CONTIKI_PROJECT = cart
PROJECT_SOURCEFILES += sendrecv.c
PLATFORMS_ONLY = cc26x0-cc13x0
all: $(CONTIKI_PROJECT)
CONTIKI = ../..
PLATFORMS_EXCLUDE = nrf52dk
#use this to enable TSCH: MAKE_MAC = MAKE_MAC_TSCH
MAKE_MAC ?= MAKE_MAC_CSMA
MAKE_NET = MAKE_NET_NULLNET
include $(CONTIKI)/Makefile.include

93
project/Giomba/cart.c Normal file
View File

@ -0,0 +1,93 @@
#include <stdio.h>
#include <string.h>
#include "os/dev/leds.h"
#include "batmon-sensor.h"
#include "../common/supermarket_net.h"
#include "event.h"
#include "log.h"
#include "sendrecv.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 */
/*** Variables initialization ***/
/* Finite State Machine Status */
status = CASHOUT;
/* Network initialization */
nullnet_buf = net_buffer;
nullnet_set_input_callback(net_recv);
/* fixme garbage */
etimer_set(&broadcast_timer, 10 * CLOCK_SECOND);
/* now actually start */
printf("Hello! I'm the cart.\n");
while (true) {
PROCESS_WAIT_EVENT();
switch(status) {
case NOT_ASSOCIATED:
s_not_associated(ev, data);
break;
break;
case ASSOCIATED: break;
case SHOPPING: break;
case CASHOUT: break;
default: status = NOT_ASSOCIATED; break;
}
/*
if (ev == PROCESS_EVENT_TIMER) {
printf("Transmitting %d...\n", counter);
sprintf(message, "#%d Hello. It's me. -- by Adele", counter);
nullnet_len = strlen(message) + 1;
counter++;
NETSTACK_NETWORK.output(&destination_address);
etimer_reset(&my_timer);
}
*/
}
PROCESS_END();
}

8
project/Giomba/event.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef EVENT_H
#define EVENT_H
enum CartEvent {
CART_EVENT_ASSOCIATED
} event;
#endif

9
project/Giomba/log.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef LOG_H
#define LOG_H
#include "sys/log.h"
#define LOG_MODULE "Cart"
#define LOG_LEVEL LOG_LEVEL_INFO
#endif

View File

@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/*---------------------------------------------------------------------------*/
/* Enable the ROM bootloader */
#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1
/*---------------------------------------------------------------------------*/
/* Change to match your configuration */
#define IEEE802154_CONF_PANID 0xABCD
#define IEEE802154_CONF_DEFAULT_CHANNEL 25
#define RF_BLE_CONF_ENABLED 1
/*---------------------------------------------------------------------------*/
#endif /* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/

30
project/Giomba/sendrecv.c Normal file
View File

@ -0,0 +1,30 @@
#include "sendrecv.h"
struct MacPkt pkt;
void net_recv(const void* data, uint16_t len, const linkaddr_t* src, const linkaddr_t* dst) {
/* discard too long packet */
if (len > 128) {
LOG_INFO("[WW] dropping too long packet %d\n", len);
return;
}
/* fill packet to pass to upper processing layer */
memcpy(pkt.data, data, len);
pkt.len = len;
pkt.src = *src;
pkt.dst = *dst;
LOG_INFO("Received %d bytes from ", len); LOG_INFO_LLADDR(src); LOG_INFO("\n");
switch ( ((struct Msg*)data)->type ) {
case ASSOCIATION_REPLY_MSG:
event = CART_EVENT_ASSOCIATED;
process_post(&cart_main_process, PROCESS_EVENT_MSG, NULL);
break;
default:
LOG_INFO("[W] message type unknown\n");
break;
}
}

31
project/Giomba/sendrecv.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef SENDRECV_H
#define SENDRECV_H
#include <string.h>
#include "net/netstack.h"
#include "net/nullnet/nullnet.h"
#include "os/net/linkaddr.h"
#include "../common/supermarket_net.h"
#include "event.h"
#include "log.h"
struct MacPkt {
char data[128];
uint16_t len;
linkaddr_t src;
linkaddr_t dst;
};
extern void* ResetISR;
extern struct MacPkt pkt;
extern struct process cart_main_process;
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);
#endif

View File

@ -0,0 +1,19 @@
#ifndef SUPERMARKET_NET_H
#define SUPERMARKET_NET_H
enum MsgType {
ASSOCIATION_REQUEST_MSG,
ASSOCIATION_REPLY_MSG,
BATTERY_STATUS_MSG,
ASSIGNMENT_MSG,
PRODUCT_MSG,
CASHOUT_MSG,
ITEM_ELEM_MSG
};
struct Msg {
enum MsgType type;
int test;
};
#endif