37 #include "sys/cooja_mt.h"
38 #include "lib/simEnvChange.h"
45 #include "dev/cooja-radio.h"
47 #define COOJA_RADIO_BUFSIZE PACKETBUF_SIZE
49 #define CCA_SS_THRESHOLD -95
51 const struct simInterface radio_interface;
54 char simReceiving = 0;
55 char simInDataBuffer[COOJA_RADIO_BUFSIZE];
57 char simOutDataBuffer[COOJA_RADIO_BUFSIZE];
59 char simRadioHWOn = 1;
60 int simSignalStrength = -100;
61 int simLastSignalStrength = -100;
63 int simRadioChannel = 26;
65 static const void *pending_data;
67 PROCESS(cooja_radio_process,
"cooja radio process");
71 radio_set_channel(
int channel)
73 simRadioChannel = channel;
77 radio_set_txpower(
unsigned char power)
84 radio_signal_strength_last(
void)
86 return simLastSignalStrength;
90 radio_signal_strength_current(
void)
92 return simSignalStrength;
110 doInterfaceActionsBeforeTick(
void)
117 simLastSignalStrength = simSignalStrength;
127 doInterfaceActionsAfterTick(
void)
132 radio_read(
void *buf,
unsigned short bufsize)
136 if (simInSize == 0) {
139 if(bufsize < simInSize) {
141 RIMESTATS_ADD(toolong);
145 memcpy(buf, simInDataBuffer, simInSize);
151 radio_send(
const void *payload,
unsigned short payload_len)
153 int radiostate = simRadioHWOn;
159 if(payload_len > COOJA_RADIO_BUFSIZE) {
162 if(payload_len == 0) {
170 memcpy(simOutDataBuffer, payload, payload_len);
171 simOutSize = payload_len;
174 while(simOutSize > 0) {
178 simRadioHWOn = radiostate;
183 prepare_packet(
const void *data,
unsigned short len)
190 transmit_packet(
unsigned short len)
192 int ret = RADIO_TX_ERR;
193 if(pending_data !=
NULL) {
194 ret = radio_send(pending_data, len);
200 receiving_packet(
void)
208 return !simReceiving && simInSize > 0;
214 if(simSignalStrength > CCA_SS_THRESHOLD) {
233 NETSTACK_RDC.input();
261 SIM_INTERFACE(radio_interface,
262 doInterfaceActionsBeforeTick,
263 doInterfaceActionsAfterTick);