feat: add radio support stubs for no plugins configuration
This commit is contained in:
parent
eb5c8024d5
commit
10cb4bdb4a
|
|
@ -88,6 +88,7 @@ add_library(webots-controller::webots_controller ALIAS webots_controller)
|
|||
|
||||
if(WIN32)
|
||||
set_target_properties(webots_controller PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
target_link_libraries(webots_controller PRIVATE ws2_32)
|
||||
endif()
|
||||
|
||||
target_include_directories(webots_controller
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "html_robot_window_private.h"
|
||||
#include "remote_control_private.h"
|
||||
#include "robot_window_private.h"
|
||||
#include "device_private.h"
|
||||
|
||||
#include <webots/radio.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
|
@ -108,3 +115,200 @@ void *wb_remote_control_custom_function(void *arg) {
|
|||
(void)arg;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void radio_plugins_disabled(const char *function_name) {
|
||||
fprintf(stderr, "Error: %s(): radio support is unavailable because plugins are disabled.\n", function_name);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int length;
|
||||
char *body;
|
||||
char *destination;
|
||||
} NoPluginsRadioMessage;
|
||||
|
||||
void wb_radio_init(WbDevice *d) {
|
||||
(void)d;
|
||||
}
|
||||
|
||||
WbRadioMessage wb_radio_message_new(int length, const char *body, const char *destination) {
|
||||
if (length < 0 || (length > 0 && body == NULL) || destination == NULL) {
|
||||
fprintf(stderr, "Error: %s(): invalid argument.\n", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NoPluginsRadioMessage *msg = malloc(sizeof(NoPluginsRadioMessage));
|
||||
if (msg == NULL)
|
||||
return NULL;
|
||||
|
||||
msg->length = length;
|
||||
msg->body = NULL;
|
||||
msg->destination = NULL;
|
||||
|
||||
if (length > 0) {
|
||||
msg->body = malloc((size_t)length);
|
||||
if (msg->body == NULL) {
|
||||
free(msg);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(msg->body, body, (size_t)length);
|
||||
}
|
||||
|
||||
msg->destination = malloc(strlen(destination) + 1);
|
||||
if (msg->destination == NULL) {
|
||||
free(msg->body);
|
||||
free(msg);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(msg->destination, destination);
|
||||
return msg;
|
||||
}
|
||||
|
||||
void wb_radio_message_delete(WbRadioMessage msg) {
|
||||
NoPluginsRadioMessage *message = (NoPluginsRadioMessage *)msg;
|
||||
if (message == NULL)
|
||||
return;
|
||||
free(message->body);
|
||||
free(message->destination);
|
||||
free(message);
|
||||
}
|
||||
|
||||
const char *wb_radio_message_get_destination(WbRadioMessage msg) {
|
||||
const NoPluginsRadioMessage *message = (const NoPluginsRadioMessage *)msg;
|
||||
return message ? message->destination : NULL;
|
||||
}
|
||||
|
||||
int wb_radio_message_get_length(WbRadioMessage msg) {
|
||||
const NoPluginsRadioMessage *message = (const NoPluginsRadioMessage *)msg;
|
||||
return message ? message->length : 0;
|
||||
}
|
||||
|
||||
const char *wb_radio_message_get_body(WbRadioMessage msg) {
|
||||
const NoPluginsRadioMessage *message = (const NoPluginsRadioMessage *)msg;
|
||||
return message ? message->body : NULL;
|
||||
}
|
||||
|
||||
void wb_radio_enable(WbDeviceTag tag, int sampling_period) {
|
||||
(void)tag;
|
||||
(void)sampling_period;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
void wb_radio_disable(WbDeviceTag tag) {
|
||||
(void)tag;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
void wb_radio_set_address(WbDeviceTag tag, const char *address) {
|
||||
(void)tag;
|
||||
(void)address;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
const char *wb_radio_get_address(WbDeviceTag tag) {
|
||||
(void)tag;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wb_radio_set_frequency(WbDeviceTag tag, double hz) {
|
||||
(void)tag;
|
||||
(void)hz;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
double wb_radio_get_frequency(WbDeviceTag tag) {
|
||||
(void)tag;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return NAN;
|
||||
}
|
||||
|
||||
void wb_radio_set_channel(WbDeviceTag tag, int channel) {
|
||||
(void)tag;
|
||||
(void)channel;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
int wb_radio_get_channel(WbDeviceTag tag) {
|
||||
(void)tag;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void wb_radio_set_bitrate(WbDeviceTag tag, int bits_per_second) {
|
||||
(void)tag;
|
||||
(void)bits_per_second;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
int wb_radio_get_bitrate(WbDeviceTag tag) {
|
||||
(void)tag;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wb_radio_set_rx_sensitivity(WbDeviceTag tag, double dBm) {
|
||||
(void)tag;
|
||||
(void)dBm;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
double wb_radio_get_rx_sensitivity(WbDeviceTag tag) {
|
||||
(void)tag;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return NAN;
|
||||
}
|
||||
|
||||
void wb_radio_set_tx_power(WbDeviceTag tag, double dBm) {
|
||||
(void)tag;
|
||||
(void)dBm;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
double wb_radio_get_tx_power(WbDeviceTag tag) {
|
||||
(void)tag;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return NAN;
|
||||
}
|
||||
|
||||
void wb_radio_set_callback(WbDeviceTag tag, void (*callback)(const WbRadioEvent)) {
|
||||
(void)tag;
|
||||
(void)callback;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
||||
WbDeviceTag wb_radio_event_get_radio(const WbRadioEvent event) {
|
||||
(void)event;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *wb_radio_event_get_data(const WbRadioEvent event) {
|
||||
(void)event;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int wb_radio_event_get_data_size(const WbRadioEvent event) {
|
||||
(void)event;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *wb_radio_event_get_emitter(const WbRadioEvent event) {
|
||||
(void)event;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
double wb_radio_event_get_rssi(const WbRadioEvent event) {
|
||||
(void)event;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
return NAN;
|
||||
}
|
||||
|
||||
void wb_radio_send(WbDeviceTag tag, const WbRadioMessage msg, double delay) {
|
||||
(void)tag;
|
||||
(void)msg;
|
||||
(void)delay;
|
||||
radio_plugins_disabled(__FUNCTION__);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue