36#include "sys/cooja_mt.h"
37#include "lib/simEnvChange.h"
44#include "dev/cooja-radio.h"
51#ifdef COOJA_RADIO_CONF_BUFSIZE
52#define COOJA_RADIO_BUFSIZE COOJA_RADIO_CONF_BUFSIZE
54#define COOJA_RADIO_BUFSIZE 125
59#define CCA_SS_THRESHOLD -95
61const struct simInterface radio_interface;
73 RSSI_NO_SIGNAL = -110,
84char simInDataBuffer[COOJA_RADIO_BUFSIZE];
86rtimer_clock_t simLastPacketTimestamp = 0;
87char simOutDataBuffer[COOJA_RADIO_BUFSIZE];
90int simSignalStrength = RSSI_NO_SIGNAL;
91int simLastSignalStrength = RSSI_NO_SIGNAL;
93int simRadioChannel = MAX_CHANNEL;
94int simLQI = LQI_NO_SIGNAL;
95int simLastLQI = LQI_NO_SIGNAL;
99static const void *pending_data;
102static int poll_mode = 0;
103static int auto_ack = 0;
104static int addr_filter = 0;
105static int send_on_cca = (COOJA_TRANSMIT_ON_CCA != 0);
107PROCESS(cooja_radio_process,
"cooja radio process");
110set_send_on_cca(uint8_t enable)
112 send_on_cca = enable;
116set_frame_filtering(
int enable)
118 addr_filter = enable;
122set_auto_ack(
int enable)
128set_poll_mode(
int enable)
134radio_set_channel(
int channel)
136 simRadioChannel = channel;
140radio_set_txpower(
unsigned char power)
147radio_signal_strength_last(
void)
149 return simLastSignalStrength;
153radio_signal_strength_current(
void)
155 return simSignalStrength;
165int radio_lqi_last(
void)
174 ENERGEST_ON(ENERGEST_TYPE_LISTEN);
182 ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
188doInterfaceActionsBeforeTick(
void)
195 simLastSignalStrength = simSignalStrength;
206doInterfaceActionsAfterTick(
void)
211radio_read(
void *buf,
unsigned short bufsize)
218 if(bufsize < simInSize) {
223 memcpy(buf, simInDataBuffer, simInSize);
226 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, radio_signal_strength_last());
227 packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, radio_lqi_last() );
236 if(simSignalStrength > CCA_SS_THRESHOLD) {
243radio_send(
const void *payload,
unsigned short payload_len)
246 int radio_was_on = simRadioHWOn;
248 if(payload_len > COOJA_RADIO_BUFSIZE) {
251 if(payload_len == 0) {
259 ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT);
263 ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
266#if COOJA_SIMULATE_TURNAROUND
267 simProcessRunValue = 1;
269 if(payload_len > 3) {
270 simProcessRunValue = 1;
276 if(COOJA_TRANSMIT_ON_CCA && send_on_cca && !channel_clear()) {
280 memcpy(simOutDataBuffer, payload, payload_len);
281 simOutSize = payload_len;
284 while(simOutSize > 0) {
292 ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN);
294 ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
297 simRadioHWOn = radio_was_on;
302prepare_packet(
const void *data,
unsigned short len)
304 if(len > COOJA_RADIO_BUFSIZE) {
312transmit_packet(
unsigned short len)
315 if(pending_data != NULL) {
316 ret = radio_send(pending_data, len);
322receiving_packet(
void)
330 return !simReceiving && simInSize > 0;
349 NETSTACK_MAC.
input();
386 *value = radio_signal_strength_last();
390 *value = radio_lqi_last();
394 *value = radio_signal_strength_current();
397 case RADIO_CONST_MAX_PAYLOAD_LEN:
401 *value = simRadioChannel;
404 *value = MIN_CHANNEL;
407 *value = MAX_CHANNEL;
451 radio_set_channel(value);
459get_object(radio_param_t param,
void *dest,
size_t size)
462 if(size !=
sizeof(rtimer_clock_t) || !dest) {
465 *(rtimer_clock_t *)dest = (rtimer_clock_t)simLastPacketTimestamp;
472set_object(radio_param_t param,
const void *src,
size_t size)
495SIM_INTERFACE(radio_interface,
496 doInterfaceActionsBeforeTick,
497 doInterfaceActionsAfterTick);
Header file for the energy estimation mechanism.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
void packetbuf_clear(void)
Clear and reset the packetbuf.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
void process_poll(struct process *p)
Request a process to be polled.
#define RADIO_RX_MODE_ADDRESS_FILTER
Enable address-based frame filtering.
#define RADIO_RX_MODE_POLL_MODE
Enable/disable/get the state of radio driver poll mode operation.
#define RADIO_TX_MODE_SEND_ON_CCA
Radio TX mode control / retrieval.
enum radio_result_e radio_result_t
Radio return values when setting or getting radio parameters.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio.
#define RADIO_RX_MODE_AUTOACK
Enable automatic transmission of ACK frames.
@ RADIO_RESULT_NOT_SUPPORTED
The parameter is not supported.
@ RADIO_RESULT_INVALID_VALUE
The value argument was incorrect.
@ RADIO_RESULT_OK
The parameter was set/read successfully.
@ RADIO_PARAM_RSSI
Received signal strength indicator in dBm.
@ RADIO_PARAM_LAST_PACKET_TIMESTAMP
Last packet timestamp, of type rtimer_clock_t.
@ RADIO_PARAM_LAST_RSSI
The RSSI value of the last received packet.
@ RADIO_PARAM_RX_MODE
Radio receiver mode determines if the radio has address filter (RADIO_RX_MODE_ADDRESS_FILTER) and aut...
@ RADIO_PARAM_CHANNEL
Channel used for radio communication.
@ RADIO_PARAM_LAST_LINK_QUALITY
Link quality indicator of the last received packet.
@ RADIO_CONST_CHANNEL_MAX
The highest radio channel number.
@ RADIO_CONST_CHANNEL_MIN
The lowest radio channel number.
@ RADIO_PARAM_TX_MODE
Radio transmission mode determines if the radio has send on CCA (RADIO_TX_MODE_SEND_ON_CCA) enabled o...
@ RADIO_TX_COLLISION
TX failed due to a collision.
@ RADIO_TX_ERR
An error occurred during transmission.
@ RADIO_TX_OK
TX was successful and where an ACK was requested one was received.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Packet buffer (packetbuf) management.
Header file for the radio API.
void(* input)(void)
Callback for getting notified of incoming packet.
The structure of a Contiki-NG radio device driver.
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
int(* init)(void)
Initialise the radio hardware.
int(* receiving_packet)(void)
Check if the radio driver is currently receiving a packet.
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
int(* pending_packet)(void)
Check if a packet has been received and is available in the radio driver's buffers.
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.
int(* channel_clear)(void)
Perform a Clear-Channel Assessment (CCA) to find out if there is a packet in the air or not.