mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-26 06:53:52 +01:00
[drivers/cc1100_ng sys/transceiver]
' added a monitor mode [sys/shell projects/test_cc1100_ng] ' moved shell commands to get/set channel and address and sending a packet from userapp to default shell command set
This commit is contained in:
parent
0a8448b6a1
commit
f5ab5c27bb
@ -86,7 +86,7 @@ char cc1100_conf[] = {
|
||||
0xAD, // SYNC0
|
||||
0x3D, // PKTLEN (maximum value of packet length byte = 61)
|
||||
0x06, // PKTCTRL1
|
||||
0x45, // PKTCTRL0 (variable packet length)
|
||||
0x45, // PKTCTRL0 (variable packet length)
|
||||
0xFF, // ADDR
|
||||
CC1100_DEFAULT_CHANNR*10, // CHANNR
|
||||
0x0B, // FSCTRL1
|
||||
|
||||
@ -110,6 +110,15 @@ radio_address_t cc1100_set_address(radio_address_t address) {
|
||||
return radio_address;
|
||||
}
|
||||
|
||||
void cc1100_set_monitor(uint8_t mode) {
|
||||
if (mode) {
|
||||
write_register(CC1100_PKTCTRL1, (0x04));
|
||||
}
|
||||
else {
|
||||
write_register(CC1100_PKTCTRL1, (0x06));
|
||||
}
|
||||
}
|
||||
|
||||
void cc1100_setup_rx_mode(void) {
|
||||
// Stay in RX mode until end of packet
|
||||
cc1100_spi_write_reg(CC1100_MCSM2, 0x07);
|
||||
|
||||
@ -116,6 +116,7 @@ int16_t cc1100_get_channel(void);
|
||||
|
||||
radio_address_t cc1100_set_address(radio_address_t addr);
|
||||
radio_address_t cc1100_get_address(void);
|
||||
void cc1100_set_monitor(uint8_t mode);
|
||||
|
||||
void cc1100_print_config(void);
|
||||
#endif
|
||||
|
||||
@ -13,82 +13,24 @@
|
||||
|
||||
#define SHELL_STACK_SIZE (2048)
|
||||
#define RADIO_STACK_SIZE (2048)
|
||||
#define TEXT_SIZE CC1100_MAX_DATA_LENGTH
|
||||
|
||||
int transceiver_pid;
|
||||
char shell_stack_buffer[SHELL_STACK_SIZE];
|
||||
char radio_stack_buffer[RADIO_STACK_SIZE];
|
||||
char text_msg[TEXT_SIZE];
|
||||
|
||||
void trans_chan(char *chan);
|
||||
void trans_addr(char *addr);
|
||||
void trans_send(char *mesg);
|
||||
|
||||
msg mesg;
|
||||
transceiver_command_t tcmd;
|
||||
void mon_handler(char *mode);
|
||||
|
||||
shell_t shell;
|
||||
const shell_command_t sc[] = {
|
||||
{"tchan", "Set the channel for cc1100", trans_chan},
|
||||
{"taddr", "Set the address for cc1100", trans_addr},
|
||||
{"tsnd", "Sends a CC1100 packet", trans_send},
|
||||
{"mon", "", mon_handler},
|
||||
{NULL, NULL, NULL}};
|
||||
|
||||
void trans_chan(char *chan) {
|
||||
int16_t c;
|
||||
void mon_handler(char *mode) {
|
||||
unsigned int m;
|
||||
|
||||
tcmd.transceivers = TRANSCEIVER_CC1100;
|
||||
tcmd.data = &c;
|
||||
mesg.content.ptr = (char*) &tcmd;
|
||||
if (sscanf(chan, "tchan %hi", &c) > 0) {
|
||||
printf("Trying to set channel %i\n", c);
|
||||
mesg.type = SET_CHANNEL;
|
||||
}
|
||||
else {
|
||||
mesg.type = GET_CHANNEL;
|
||||
}
|
||||
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
||||
printf("Got channel: %i\n", c);
|
||||
}
|
||||
|
||||
void trans_addr(char *addr) {
|
||||
int16_t a;
|
||||
|
||||
tcmd.transceivers = TRANSCEIVER_CC1100;
|
||||
tcmd.data = &a;
|
||||
mesg.content.ptr = (char*) &tcmd;
|
||||
if (sscanf(addr, "taddr %hi", &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;
|
||||
uint16_t addr;
|
||||
|
||||
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>");
|
||||
}
|
||||
sscanf(mode, "mon %u", &m);
|
||||
printf("Setting monitor mode: %u\n", m);
|
||||
cc1100_set_monitor(m);
|
||||
}
|
||||
|
||||
void shell_runner(void) {
|
||||
|
||||
@ -29,6 +29,7 @@ enum transceiver_msg_type_t {
|
||||
SET_CHANNEL, ///< Set a new channel
|
||||
GET_ADDRESS, ///< Get the radio address
|
||||
SET_ADDRESS, ///< Set the radio address
|
||||
SET_MONITOR, ///< Set transceiver to monitor mode (disable address checking)
|
||||
|
||||
/* Error messages */
|
||||
ENOBUFFER, ///< No buffer left
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
SubDir TOP sys shell ;
|
||||
|
||||
Module shell : shell.c ;
|
||||
Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c cc1100.c : shell ;
|
||||
Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c cc1100.c cc1100_ng.c : shell ;
|
||||
|
||||
Module ps : ps.c ;
|
||||
|
||||
|
||||
@ -26,6 +26,14 @@ extern void _cc1100_get_address_handler(char *unused);
|
||||
extern void _cc1100_set_address_handler(char *ptr);
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_TRANSCEIVER
|
||||
#ifdef MODULE_CC110X_NG
|
||||
extern void _cc1100_ng_get_set_address_handler(char *addr);
|
||||
extern void _cc1100_ng_get_set_channel_handler(char *chan);
|
||||
extern void _cc1100_ng_send_handler(char *pkt);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const shell_command_t _shell_command_list[] = {
|
||||
#ifdef MODULE_PS
|
||||
{"ps", "Prints information about running threads.", _ps_handler},
|
||||
@ -46,6 +54,13 @@ const shell_command_t _shell_command_list[] = {
|
||||
#ifdef MODULE_CC110X
|
||||
{"cc1100_get_address", "", _cc1100_get_address_handler},
|
||||
{"cc1100_set_address", "", _cc1100_set_address_handler},
|
||||
#endif
|
||||
#ifdef MODULE_TRANSCEIVER
|
||||
#ifdef MODULE_CC110X_NG
|
||||
{"addr", "Gets or sets the address for the CC1100 transceiver", _cc1100_ng_get_set_address_handler},
|
||||
{"chan", "Gets or sets the channel for the CC1100 transceiver", _cc1100_ng_get_set_channel_handler},
|
||||
{"txtsnd", "Sends a text message to a given node via the CC1100 transceiver", _cc1100_ng_send_handler},
|
||||
#endif
|
||||
#endif
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
@ -51,6 +51,7 @@ static int16_t get_channel(transceiver_type_t t);
|
||||
static int16_t set_channel(transceiver_type_t t, void *channel);
|
||||
static int16_t get_address(transceiver_type_t t);
|
||||
static int16_t set_address(transceiver_type_t t, void *address);
|
||||
static void set_monitor(transceiver_type_t t, void *mode);
|
||||
|
||||
/*------------------------------------------------------------------------------------*/
|
||||
/* Transceiver init */
|
||||
@ -142,6 +143,9 @@ void run(void) {
|
||||
*((int16_t*) cmd->data) = set_address(cmd->transceivers, cmd->data);
|
||||
msg_reply(&m, &m);
|
||||
break;
|
||||
case SET_MONITOR:
|
||||
set_monitor(cmd->transceivers, cmd->data);
|
||||
break;
|
||||
default:
|
||||
DEBUG("Unknown message received\n");
|
||||
break;
|
||||
@ -335,3 +339,19 @@ static int16_t set_address(transceiver_type_t t, void *address) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Set the transceiver device into monitor mode (disabling address check)
|
||||
*
|
||||
* @param t The transceiver device
|
||||
* @param mode 1 for enabling monitor mode, 0 for enabling address check
|
||||
*/
|
||||
static void set_monitor(transceiver_type_t t, void *mode) {
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
cc1100_set_monitor(*((uint8_t*) mode));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user