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
57#define CCA_SS_THRESHOLD -95
59const struct simInterface radio_interface;
71 RSSI_NO_SIGNAL = -110,
82char simInDataBuffer[COOJA_RADIO_BUFSIZE];
84rtimer_clock_t simLastPacketTimestamp = 0;
85char simOutDataBuffer[COOJA_RADIO_BUFSIZE];
88int simSignalStrength = RSSI_NO_SIGNAL;
89int simLastSignalStrength = RSSI_NO_SIGNAL;
91int simRadioChannel = 26;
92int simLQI = LQI_NO_SIGNAL;
93int simLastLQI = LQI_NO_SIGNAL;
97static const void *pending_data;
100static int poll_mode = 0;
101static int auto_ack = 0;
102static int addr_filter = 0;
103static int send_on_cca = (COOJA_TRANSMIT_ON_CCA != 0);
105PROCESS(cooja_radio_process,
"cooja radio process");
108set_send_on_cca(uint8_t enable)
110 send_on_cca = enable;
114set_frame_filtering(
int enable)
116 addr_filter = enable;
120set_auto_ack(
int enable)
126set_poll_mode(
int enable)
132radio_set_channel(
int channel)
134 simRadioChannel = channel;
138radio_set_txpower(
unsigned char power)
145radio_signal_strength_last(
void)
147 return simLastSignalStrength;
151radio_signal_strength_current(
void)
153 return simSignalStrength;
163int radio_lqi_last(
void)
172 ENERGEST_ON(ENERGEST_TYPE_LISTEN);
180 ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
186doInterfaceActionsBeforeTick(
void)
193 simLastSignalStrength = simSignalStrength;
204doInterfaceActionsAfterTick(
void)
209radio_read(
void *buf,
unsigned short bufsize)
216 if(bufsize < simInSize) {
221 memcpy(buf, simInDataBuffer, simInSize);
224 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, radio_signal_strength_last());
225 packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, radio_lqi_last() );
234 if(simSignalStrength > CCA_SS_THRESHOLD) {
241radio_send(
const void *payload,
unsigned short payload_len)
244 int radio_was_on = simRadioHWOn;
246 if(payload_len > COOJA_RADIO_BUFSIZE) {
249 if(payload_len == 0) {
257 ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT);
261 ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
264#if COOJA_SIMULATE_TURNAROUND
265 simProcessRunValue = 1;
267 if(payload_len > 3) {
268 simProcessRunValue = 1;
274 if(COOJA_TRANSMIT_ON_CCA && send_on_cca && !channel_clear()) {
278 memcpy(simOutDataBuffer, payload, payload_len);
279 simOutSize = payload_len;
282 while(simOutSize > 0) {
290 ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN);
292 ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
295 simRadioHWOn = radio_was_on;
300prepare_packet(
const void *data,
unsigned short len)
302 if(len > COOJA_RADIO_BUFSIZE) {
310transmit_packet(
unsigned short len)
313 if(pending_data != NULL) {
314 ret = radio_send(pending_data, len);
320receiving_packet(
void)
328 return !simReceiving && simInSize > 0;
347 NETSTACK_MAC.
input();
384 *value = radio_signal_strength_last();
388 *value = radio_lqi_last();
392 *value = radio_signal_strength_current();
395 case RADIO_CONST_MAX_PAYLOAD_LEN:
440 radio_set_channel(value);
448get_object(radio_param_t param,
void *dest,
size_t size)
451 if(size !=
sizeof(rtimer_clock_t) || !dest) {
454 *(rtimer_clock_t *)dest = (rtimer_clock_t)simLastPacketTimestamp;
461set_object(radio_param_t param,
const void *src,
size_t size)
484SIM_INTERFACE(radio_interface,
485 doInterfaceActionsBeforeTick,
486 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_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.