2010-11-24 11:20:27 +01:00
|
|
|
#include <stdio.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-19 20:10:09 +01:00
|
|
|
|
|
|
|
#define SHELL_STACK_SIZE (4096)
|
2010-11-24 11:20:27 +01:00
|
|
|
#define RADIO_STACK_SIZE (4096)
|
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-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 10:23:46 +01:00
|
|
|
int c;
|
2010-11-24 21:45:38 +01:00
|
|
|
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
tcmd.data = &c;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
2010-11-26 10:23:46 +01:00
|
|
|
if (sscanf(chan, "tchan %i", &c) > 0) {
|
|
|
|
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) {
|
|
|
|
int a;
|
|
|
|
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
tcmd.data = &a;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
|
|
|
if (sscanf(addr, "taddr %i", &a) > 0) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
p.length = 10;
|
|
|
|
p.dst = 5;
|
|
|
|
|
|
|
|
mesg.type = SND_PKT;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
|
|
|
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
|
|
|
response = mesg.content.value;
|
|
|
|
printf("Packet send: %lu\n", response);
|
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;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
msg_receive(&m);
|
|
|
|
printf("Received message of type %i: %lX\n", m.type, m.content.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|