Commit c1a8ccee authored by Robert Hartung's avatar Robert Hartung
Browse files

version before going into the basement

parent d93fcde0
......@@ -18,7 +18,12 @@ CFLAGS += -DDEBUG_ASSERT_VERBOSE
CFLAGS += -DGNRC_PKTBUF_SIZE=512
CFLAGS += -DSHELL_NO_ECHO -DSHELL_NO_PROMPT
#DEVELHELP ?= 1
CFLAGS += -DNDEBUG
BAUD := 9600
CFLAGS += -DUART_STDIO_BAUDRATE=9600
DEVELHELP ?= 1
# No debug information
#CFLAGS += -DNDEBUG
include $(RIOTBASE)/Makefile.include
......@@ -35,19 +35,28 @@
#include "net/gnrc/netif/ieee802154.h"
#define SEND_INTERVAL (1)
#define RCV_QUEUE_SIZE (16)
#define MAX_PAYLOAD_LENGTH (64)
#define RCV_QUEUE_SIZE (8)
#define MAX_PAYLOAD_LENGTH (32)
#define MAGIC_STRING "IBREVAL\0"
#define SHELL_BUFFER_SIZE (256)
#ifndef NODE_ID
#error NODE_ID undefined
#endif
/// 512 required for samr21-xpro, 256 sufficient for INGA and telosb
char dump_thread_stack[1024+255];
char send_thread_stack[1024+255];
static msg_t dump_thread_msg_queue[RCV_QUEUE_SIZE];
static msg_t send_thread_msg_queue[RCV_QUEUE_SIZE];
#ifdef BOARD_SAMR21_XPRO
char dump_thread_stack[1024+256];
char send_thread_stack[1024+256];
#else
char dump_thread_stack[512+256];
char send_thread_stack[512+256];
#endif
//static msg_t dump_thread_msg_queue[RCV_QUEUE_SIZE];
//static msg_t send_thread_msg_queue[RCV_QUEUE_SIZE];
char line_buf[SHELL_BUFFER_SIZE];
typedef struct /*__attribute__((packed))*/ {
char magic_string[8];
......@@ -102,12 +111,40 @@ int shell_payload(int argc, char** argv) {
return 0;
}
int shell_memdump(int argc, char** argv) {
(void) argc;
(void) argv;
//irq_disable();
/// TODO(rh): dump memory
const uint8_t *addr = (const uint8_t*)0x1800;
while(addr < (const uint8_t*)0x2600) {
uint8_t i = 0;
printf("%04X: ",addr);
while(i<0xF) {
printf("%02X ", *(addr+i));
i++;
}
i = 0;
while(i<0xF) {
char c = *(addr+i);
printf("%c", (c >= ' ' && c <= '~') ? c : '.');
i++;
}
addr += 0xF;
puts("");
}
//irq_enable();
return 0;
}
shell_command_t eval_shell_commands[] = {
{"tx", "Sends packets", shell_tx},
{"payload", "Sets or prints the payload", shell_payload},
{"memdump", "Prints the memory", shell_memdump},
{NULL, NULL, NULL}
};
/*
static void _dump(gnrc_pktsnip_t *pkt) {
gnrc_pktsnip_t *snip = pkt;
gnrc_pktsnip_t *payload = NULL;
......@@ -115,7 +152,10 @@ static void _dump(gnrc_pktsnip_t *pkt) {
eval_message_t *packet;
gnrc_netif_hdr_t *hdr;
uint8_t len;
char serialbuffer[255];
char serialbuffer[256];
printf("serialbuffer: from %p to %p\n", serialbuffer, serialbuffer+256);
// printf("_dump: %d %d\n", gnrc_netreg_num(GNRC_NETTYPE_UNDEF, 0), gnrc_netreg_num(GNRC_NETTYPE_NETIF, 0));
while(snip != NULL) {
switch(snip->type) {
......@@ -131,58 +171,57 @@ static void _dump(gnrc_pktsnip_t *pkt) {
if(hdr->crc_valid) {
if(strcmp(packet->magic_string, MAGIC_STRING) == 0) {
puts("<magic:found");
int length = sprintf(serialbuffer, "%u|%u|%d|%u", packet->node_id, packet->seq_nr, hdr->rssi, hdr->lqi);
uint8_t sum = 0;
for(uint8_t i=0; i<length; i++) {
sum += serialbuffer[i];
if(length > 0) {
printf("<magic:ok=%u/%u\n", length, strlen( serialbuffer ));
uint8_t sum = 0;
for(uint8_t i=0; i<length; i++) {
sum += serialbuffer[i];
}
printf("<%s=%02X\n", serialbuffer, sum);
}
else {
printf("<magic:length_error:%d\n", length);
}
printf("<%s=%02X\n", serialbuffer, sum);
} else {
printf("<valid\n");
/// This is another packet, ignore it!
}
} else {
/* Make sure a corrupt packet does not exceed payload size */
/// Make sure a corrupt packet does not exceed payload size
len = payload->size;
if(len > sizeof(eval_message_t)) {
len = sizeof(eval_message_t);
}
/* Pointer to data */
/// Pointer to data
data = (uint8_t*)payload->data;
uint8_t i,
sum = 0,
length = 0;
length += snprintf(&serialbuffer[0], sizeof(serialbuffer) - length, "%d|%u|%d|", hdr->rssi, hdr->lqi, len);
/* Print each single byte */
for(i=0; i<len; i++) {
/// Even though " %02X" is only three characters long, we need to pass 4 because of the null terminator for the string!
length += snprintf(&serialbuffer[length], sizeof(serialbuffer) - length, " %02X", data[i]);
}
int tmp;
tmp = snprintf(&serialbuffer[length], sizeof(serialbuffer) - length, "%d|%u|%u|", hdr->rssi, hdr->lqi, len);
if(tmp > 0) {
length += tmp;
/// Print each single byte
for(i=0; i<len; i++) {
/// Even though " %02X" is only three characters long, we need to pass 4 because of the null terminator for the string!
tmp = snprintf(&serialbuffer[length], sizeof(serialbuffer) - length, " %02X", data[i]);
if(tmp > 0) {
length += tmp;
} else {
puts("!length error 2");
break;
}
}
for(i=0; i<length; i++) {
sum += serialbuffer[i];
}
/*
[SAMR21] line received: '> <40| 09 12 FC FF 00 00 0A C6 B9 3A 97 03 00 6F 0D 00 28 43 74 50 04 B9 3A 97 03 00 6F 0D 00 00 C3 D7 EE 15 FE 3E 07 D5 2B E3=64'
[SAMR21] line received: '<40| 09 12 FC FF 00 00 09 C6 B9 3A 97 03 00 6F 0D 00 28 EF D8 9A 02 58 C6 97 03 00 6F 0D 00 00 D4 14 0C C8 49 65 34 7D DE 8F=77'
[SAMR21] line received: '<40| 09 12 FC '
[SAMR21] line received: 'Context before hardfault:'
*/
printf("<%s=%02X\n", serialbuffer, sum);
/*
printf("Contents(%02d):", len);
for(uint8_t i=0; i<len; i++) {
printf(" %02X", data[i]);
}
printf(" | ");
for(uint8_t i=0; i<len; i++) {
if(data[i] >= ' ' && data[i] <= '~') {
printf("%c", data[i]);
} else {
printf(".");
for(i=0; i<length; i++) {
sum += serialbuffer[i];
}
printf("<%s=%02X\n", serialbuffer, sum);
} else {
puts("!length error 1");
}
puts("");
*/
}
break;
default :
......@@ -193,16 +232,28 @@ static void _dump(gnrc_pktsnip_t *pkt) {
}
gnrc_pktbuf_release(pkt);
}
*/
static char serialbuffer[256];
void *dump_thread(void *arg)
{
(void) arg;
msg_t dump_thread_msg_queue[RCV_QUEUE_SIZE];
msg_init_queue(dump_thread_msg_queue, RCV_QUEUE_SIZE);
gnrc_netreg_entry_t me_reg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, sched_active_pid);
gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &me_reg);
msg_t msg;
gnrc_pktsnip_t *snip = NULL;
gnrc_pktsnip_t *payload = NULL;
uint8_t *data;
eval_message_t *packet;
gnrc_netif_hdr_t *hdr;
uint8_t len;
memset(serialbuffer, sizeof(serialbuffer), 0x00);
while(1) {
if(msg_receive(&msg) != 1) {
puts("Unable to receive message");
......@@ -211,11 +262,95 @@ void *dump_thread(void *arg)
//printf("[dump_thread] message received: %d\n", msg.type);
switch(msg.type) {
case GNRC_NETAPI_MSG_TYPE_RCV :
_dump( msg.content.ptr );
//irq_disable();
//_dump( msg.content.ptr );
snip = msg.content.ptr;
payload = NULL;
// printf("_dump: %d %d\n", gnrc_netreg_num(GNRC_NETTYPE_UNDEF, 0), gnrc_netreg_num(GNRC_NETTYPE_NETIF, 0));
while(snip != NULL) {
switch(snip->type) {
case GNRC_NETTYPE_UNDEF :
payload = snip;
break;
case GNRC_NETTYPE_NETIF :
hdr = snip->data;
//printf("HDR: %d %d %d\n", hdr->rssi, hdr->lqi, hdr->crc_valid);
//puts("OK");
if(payload == NULL) {
puts("!whoops? NULL pointer");
}
packet = (eval_message_t*)payload->data;
if(hdr->crc_valid) {
if(strcmp(packet->magic_string, MAGIC_STRING) == 0) {
puts("<magic:found");
int length = sprintf(serialbuffer, "%u|%u|%d|%u", packet->node_id, packet->seq_nr, hdr->rssi, hdr->lqi);
if(length > 0) {
printf("<magic:ok=%u/%u\n", length, strlen( serialbuffer ));
uint8_t sum = 0;
for(uint8_t i=0; i<length; i++) {
sum += serialbuffer[i];
}
printf("<%s=%02X\n", serialbuffer, sum);
}
else {
printf("<magic:length_error:%d\n", length);
}
} else {
printf("<valid\n");
/// This is another packet, ignore it!
}
} else {
/* Make sure a corrupt packet does not exceed payload size */
len = payload->size;
if(len > sizeof(eval_message_t)) {
len = sizeof(eval_message_t);
}
/* Pointer to data */
data = (uint8_t*)payload->data;
uint8_t i,
sum = 0,
length = 0;
int tmp;
tmp = snprintf(&serialbuffer[length], sizeof(serialbuffer) - length, "%d|%u|%u|", hdr->rssi, hdr->lqi, len);
if(tmp > 0) {
length += tmp;
/* Print each single byte */
for(i=0; i<len; i++) {
/// Even though " %02X" is only three characters long, we need to pass 4 because of the null terminator for the string!
tmp = snprintf(&serialbuffer[length], sizeof(serialbuffer) - length, " %02X", data[i]);
if(tmp > 0) {
length += tmp;
} else {
puts("!length error 2");
break;
}
}
for(i=0; i<length; i++) {
sum += serialbuffer[i];
}
printf("<%s=%02X\n", serialbuffer, sum);
} else {
puts("!length error 1");
}
}
break;
default :
printf("snip of type %d\n", snip->type);
break;
}
snip = snip->next;
}
gnrc_pktbuf_release(msg.content.ptr);
//irq_enable();
break;
default :
puts("ERROR: Unknown message type???");
/// gnrc_pktbuf_release( msg.content.ptr );
//gnrc_pktbuf_release( msg.content.ptr );
break;
}
}
......@@ -223,6 +358,8 @@ void *dump_thread(void *arg)
return NULL;
}
static char serialbuffer2[32];
void *send_thread(void *arg)
{
gnrc_netif_t *ieee802154_netif = arg;
......@@ -281,9 +418,11 @@ void *send_thread(void *arg)
uint8_t flags = 0 | GNRC_NETIF_HDR_FLAGS_BROADCAST;
eval_message.payload_length = snprintf((char*)eval_message.payload, MAX_PAYLOAD_LENGTH, "Hello from %2d", NODE_ID);
msg_t send_thread_msg_queue[RCV_QUEUE_SIZE];
msg_init_queue(send_thread_msg_queue, RCV_QUEUE_SIZE);
msg_t msg;
char serialbuffer[255];
memset(serialbuffer, sizeof(serialbuffer2), 0x00);
while(1) {
msg_receive(&msg);
......@@ -329,12 +468,14 @@ void *send_thread(void *arg)
printf("ERROR: unable to send: %d\n", ret);
gnrc_pktbuf_release(pkt);
} else {
//irq_disable();
uint8_t sum = 0;
uint8_t length = snprintf(serialbuffer, 255, "%u", eval_message.seq_nr);
uint8_t length = snprintf(serialbuffer2, sizeof(serialbuffer2), "%u", eval_message.seq_nr);
for(uint8_t i=0; i<length; i++) {
sum += serialbuffer[i];
sum += serialbuffer2[i];
}
printf(">%s=%02X\n", serialbuffer, sum);
printf(">%s=%02X\n", serialbuffer2, sum);
//irq_enable();
}
}
return NULL;
......@@ -343,23 +484,27 @@ void *send_thread(void *arg)
int main(void)
{
/// +1 -> INGA working, but TelosB/Sky not
thread_create(dump_thread_stack, sizeof(dump_thread_stack), THREAD_PRIORITY_MAIN + 1, 0, dump_thread, NULL, "dump_thread");
thread_create(dump_thread_stack, sizeof(dump_thread_stack), THREAD_PRIORITY_MAIN + 1, THREAD_CREATE_STACKTEST, dump_thread, NULL, "dump_thread");
gnrc_netif_t *netif = NULL;
if((netif = gnrc_netif_iter(netif))) {
gnrc_netif_t *ieee802154_netif = netif;
printf("Found gnrc netif: %d %d", netif->pid, ieee802154_netif->pid);
printf("Found gnrc netif: %d %d\n", netif->pid, ieee802154_netif->pid);
/// +2 -> INGA working, but TelosB/Sky not
send_thread_pid = thread_create(send_thread_stack, sizeof(send_thread_stack), THREAD_PRIORITY_MAIN + 2, 0, send_thread, ieee802154_netif, "send_thread");
send_thread_pid = thread_create(send_thread_stack, sizeof(send_thread_stack), THREAD_PRIORITY_MAIN + 2, THREAD_CREATE_STACKTEST, send_thread, ieee802154_netif, "send_thread");
}
else {
puts("Unable to find netif");
}
(void) puts("Welcome to RIOT!");
printf("This is node %d\n", NODE_ID);
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(eval_shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
printf("This is node %d.\n", NODE_ID);
printf("line_buf from %p to %p\n", line_buf, line_buf + sizeof(line_buf));
printf("serialbuffer: from %p to %p\n", serialbuffer, serialbuffer+sizeof(serialbuffer));
printf("serialbuffer2: from %p to %p\n", serialbuffer2, serialbuffer2+sizeof(serialbuffer2));
shell_run(eval_shell_commands, line_buf, SHELL_BUFFER_SIZE);
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment