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
69 RSSI_NO_SIGNAL = -110,
80char simInDataBuffer[COOJA_RADIO_BUFSIZE];
82rtimer_clock_t simLastPacketTimestamp = 0;
83char simOutDataBuffer[COOJA_RADIO_BUFSIZE];
86int simSignalStrength = RSSI_NO_SIGNAL;
87int simLastSignalStrength = RSSI_NO_SIGNAL;
89int simRadioChannel = MAX_CHANNEL;
90int simLQI = LQI_NO_SIGNAL;
91int simLastLQI = LQI_NO_SIGNAL;
95static const void *pending_data;
98static int poll_mode = 0;
99static int auto_ack = 0;
100static int addr_filter = 0;
101static int send_on_cca = (COOJA_TRANSMIT_ON_CCA != 0);
103PROCESS(cooja_radio_process,
"cooja radio process");
106set_send_on_cca(uint8_t enable)
108 send_on_cca = enable;
112set_frame_filtering(
int enable)
114 addr_filter = enable;
118set_auto_ack(
int enable)
124set_poll_mode(
int enable)
130radio_set_channel(
int channel)
132 simRadioChannel = channel;
136radio_set_txpower(
unsigned char power)
143radio_signal_strength_last(
void)
145 return simLastSignalStrength;
149radio_signal_strength_current(
void)
151 return simSignalStrength;
161int radio_lqi_last(
void)
170 ENERGEST_ON(ENERGEST_TYPE_LISTEN);
178 ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
184doInterfaceActionsBeforeTick(
void)
191 simLastSignalStrength = simSignalStrength;
202radio_read(
void *buf,
unsigned short bufsize)
209 if(bufsize < simInSize) {
214 memcpy(buf, simInDataBuffer, simInSize);
217 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, radio_signal_strength_last());
218 packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, radio_lqi_last() );
227 if(simSignalStrength > CCA_SS_THRESHOLD) {
234radio_send(
const void *payload,
unsigned short payload_len)
237 int radio_was_on = simRadioHWOn;
239 if(payload_len > COOJA_RADIO_BUFSIZE) {
242 if(payload_len == 0) {
250 ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT);
254 ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
257#if COOJA_SIMULATE_TURNAROUND
258 simProcessRunValue = 1;
260 if(payload_len > 3) {
261 simProcessRunValue = 1;
267 if(COOJA_TRANSMIT_ON_CCA && send_on_cca && !channel_clear()) {
271 memcpy(simOutDataBuffer, payload, payload_len);
272 simOutSize = payload_len;
275 while(simOutSize > 0) {
283 ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN);
285 ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
288 simRadioHWOn = radio_was_on;
293prepare_packet(
const void *data,
unsigned short len)
295 if(len > COOJA_RADIO_BUFSIZE) {
303transmit_packet(
unsigned short len)
306 if(pending_data != NULL) {
307 ret = radio_send(pending_data, len);
313receiving_packet(
void)
321 return !simReceiving && simInSize > 0;
340 NETSTACK_MAC.
input();
377 *value = radio_signal_strength_last();
381 *value = radio_lqi_last();
385 *value = radio_signal_strength_current();
388 case RADIO_CONST_MAX_PAYLOAD_LEN:
392 *value = simRadioChannel;
395 *value = MIN_CHANNEL;
398 *value = MAX_CHANNEL;
442 radio_set_channel(value);
450get_object(radio_param_t param,
void *dest,
size_t size)
453 if(size !=
sizeof(rtimer_clock_t) || !dest) {
456 *(rtimer_clock_t *)dest = (rtimer_clock_t)simLastPacketTimestamp;
463set_object(radio_param_t param,
const void *src,
size_t size)
486COOJA_PRE_TICK_ACTION(COOJA_RADIO_INIT_PRIO, doInterfaceActionsBeforeTick)
Header file for the energy estimation mechanism.
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_THREAD(name, ev, data)
Define the body of 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.