2010-11-24 11:20:27 +01:00
|
|
|
#include <stdio.h>
|
2010-11-26 17:06:54 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
#include <shell.h>
|
|
|
|
#include <board_uart0.h>
|
|
|
|
#include <posix_io.h>
|
|
|
|
#include <thread.h>
|
|
|
|
#include <board.h>
|
|
|
|
#include <hwtimer.h>
|
2010-11-24 11:20:27 +01:00
|
|
|
#include <msg.h>
|
|
|
|
#include <transceiver.h>
|
2010-11-26 17:06:54 +01:00
|
|
|
#include <cc1100_ng.h>
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-26 17:06:54 +01:00
|
|
|
#define SHELL_STACK_SIZE (2048)
|
|
|
|
#define RADIO_STACK_SIZE (2048)
|
|
|
|
#define TEXT_SIZE CC1100_MAX_DATA_LENGTH
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
int transceiver_pid;
|
2010-11-19 20:10:09 +01:00
|
|
|
char shell_stack_buffer[SHELL_STACK_SIZE];
|
2010-11-24 11:20:27 +01:00
|
|
|
char radio_stack_buffer[RADIO_STACK_SIZE];
|
2010-11-26 17:06:54 +01:00
|
|
|
char text_msg[TEXT_SIZE];
|
2010-11-24 11:20:27 +01:00
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
void trans_chan(char *chan);
|
2010-11-26 10:23:46 +01:00
|
|
|
void trans_addr(char *addr);
|
|
|
|
void trans_send(char *mesg);
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
msg mesg;
|
|
|
|
transceiver_command_t tcmd;
|
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
shell_t shell;
|
2010-11-24 11:20:27 +01:00
|
|
|
const shell_command_t sc[] = {
|
2010-11-24 21:45:38 +01:00
|
|
|
{"tchan", "Set the channel for cc1100", trans_chan},
|
2010-11-26 10:23:46 +01:00
|
|
|
{"taddr", "Set the address for cc1100", trans_addr},
|
|
|
|
{"tsnd", "Sends a CC1100 packet", trans_send},
|
2010-11-24 11:20:27 +01:00
|
|
|
{NULL, NULL, NULL}};
|
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
void trans_chan(char *chan) {
|
2010-11-26 17:06:54 +01:00
|
|
|
int16_t c;
|
2010-11-24 21:45:38 +01:00
|
|
|
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
tcmd.data = &c;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
2010-11-26 17:06:54 +01:00
|
|
|
if (sscanf(chan, "tchan %hi", &c) > 0) {
|
2010-11-26 10:23:46 +01:00
|
|
|
printf("Trying to set channel %i\n", c);
|
2010-11-24 21:45:38 +01:00
|
|
|
mesg.type = SET_CHANNEL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mesg.type = GET_CHANNEL;
|
|
|
|
}
|
|
|
|
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
2010-11-26 10:23:46 +01:00
|
|
|
printf("Got channel: %i\n", c);
|
2010-11-24 11:20:27 +01:00
|
|
|
}
|
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
void trans_addr(char *addr) {
|
2010-11-26 17:06:54 +01:00
|
|
|
int16_t a;
|
2010-11-26 10:23:46 +01:00
|
|
|
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
tcmd.data = &a;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
2010-11-26 17:06:54 +01:00
|
|
|
if (sscanf(addr, "taddr %hi", &a) > 0) {
|
2010-11-26 10:23:46 +01:00
|
|
|
printf("Trying to set address %i\n", a);
|
|
|
|
mesg.type = SET_ADDRESS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mesg.type = GET_ADDRESS;
|
|
|
|
}
|
|
|
|
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
|
|
|
printf("Got address: %i\n", a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trans_send(char *text) {
|
|
|
|
radio_packet_t p;
|
|
|
|
uint32_t response;
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
tcmd.data = &p;
|
2010-11-26 17:06:54 +01:00
|
|
|
uint16_t addr;
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2010-11-26 17:06:54 +01:00
|
|
|
if (sscanf(text, "tsnd %hu %s", &(addr), text_msg) == 2) {
|
|
|
|
p.data = (uint8_t*) text_msg;
|
|
|
|
p.length = strlen(text_msg);
|
|
|
|
p.dst = addr;
|
|
|
|
mesg.type = SND_PKT;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
|
|
|
printf("Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data);
|
|
|
|
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
|
|
|
response = mesg.content.value;
|
|
|
|
printf("Packet send: %lu\n", response);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("Usage:\ttsnd <ADDR> <MSG>");
|
|
|
|
}
|
2010-11-24 11:20:27 +01:00
|
|
|
}
|
2010-11-19 20:10:09 +01:00
|
|
|
|
|
|
|
void shell_runner(void) {
|
|
|
|
shell_init(&shell, sc, uart0_readc, uart0_putc);
|
|
|
|
posix_open(uart0_handler_pid, 0);
|
|
|
|
shell_run(&shell);
|
|
|
|
}
|
|
|
|
|
2010-11-24 11:20:27 +01:00
|
|
|
void radio(void) {
|
|
|
|
msg m;
|
2010-11-26 17:06:54 +01:00
|
|
|
radio_packet_t *p;
|
|
|
|
uint8_t i;
|
2010-11-24 11:20:27 +01:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
msg_receive(&m);
|
2010-11-26 17:06:54 +01:00
|
|
|
printf("Received message of type %i:\n", m.type);
|
|
|
|
if (m.type == PKT_PENDING) {
|
|
|
|
p = (radio_packet_t*) m.content.ptr;
|
|
|
|
printf("Packet waiting, process...\n");
|
|
|
|
printf("\tLength:\t%u\n", p->length);
|
|
|
|
printf("\tSrc:\t%u\n", p->src);
|
|
|
|
printf("\tDst:\t%u\n", p->dst);
|
|
|
|
|
|
|
|
for (i = 0; i < p->length; i++) {
|
|
|
|
printf("%02X ", p->data[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2010-11-24 11:20:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
int main(void) {
|
2010-11-26 10:23:46 +01:00
|
|
|
int radio_pid;
|
|
|
|
thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell");
|
2010-11-24 21:45:38 +01:00
|
|
|
radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
|
2010-11-26 10:23:46 +01:00
|
|
|
transceiver_init(TRANSCEIVER_CC1100);
|
|
|
|
transceiver_pid = transceiver_start();
|
|
|
|
transceiver_register(TRANSCEIVER_CC1100, radio_pid);
|
2010-11-19 20:10:09 +01:00
|
|
|
|
|
|
|
while (1) {
|
2010-11-24 11:20:27 +01:00
|
|
|
// LED_GREEN_TOGGLE;
|
2010-11-19 20:10:09 +01:00
|
|
|
hwtimer_wait(1000 * 1000);
|
|
|
|
}
|
|
|
|
}
|