mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
LP-190: Adds support for OpenLRS protocol to OPLinkMini
This commit is contained in:
parent
021eb21008
commit
aa21761f4c
@ -40,9 +40,9 @@
|
||||
#include <pios_thread.h>
|
||||
#include <taskinfo.h>
|
||||
|
||||
#include "openlrs.h"
|
||||
#include "flightstatus.h"
|
||||
#include "flightbatterystate.h"
|
||||
#include "oplinksettings.h"
|
||||
#include "oplinkstatus.h"
|
||||
|
||||
#include "pios_rfm22b_regs.h"
|
||||
@ -481,7 +481,7 @@ static void tx_packet(struct pios_openlrs_dev *openlrs_dev, uint8_t *pkt, uint8_
|
||||
}
|
||||
}
|
||||
|
||||
static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_t len) // duration is now in half seconds.
|
||||
static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_t len __attribute__((unused))) // duration is now in half seconds.
|
||||
{
|
||||
DEBUG_PRINTF(2, "beacon_tone: %d %d\r\n", hz, len * 2);
|
||||
int16_t d = 500000 / hz; // better resolution
|
||||
@ -496,6 +496,8 @@ static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_
|
||||
|
||||
rfm22_claimBus(openlrs_dev);
|
||||
|
||||
// This need fixed for F1
|
||||
#ifdef GPIO_Mode_OUT
|
||||
GPIO_TypeDef *gpio = openlrs_dev->cfg.spi_cfg->mosi.gpio;
|
||||
uint16_t pin_source = openlrs_dev->cfg.spi_cfg->mosi.init.GPIO_Pin;
|
||||
uint8_t remap = openlrs_dev->cfg.spi_cfg->remap;
|
||||
@ -529,7 +531,7 @@ static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_
|
||||
|
||||
GPIO_Init(gpio, (GPIO_InitTypeDef *)&openlrs_dev->cfg.spi_cfg->mosi.init);
|
||||
GPIO_PinAFConfig(gpio, pin_source, remap);
|
||||
|
||||
#endif /* ifdef GPIO_Mode_OUT */
|
||||
rfm22_releaseBus(openlrs_dev);
|
||||
|
||||
#if defined(PIOS_LED_LINK)
|
||||
@ -719,8 +721,8 @@ static uint8_t pios_openlrs_bind_receive(struct pios_openlrs_dev *openlrs_dev, u
|
||||
rxb = 'B';
|
||||
tx_packet(openlrs_dev, &rxb, 1); // ACK that we got bound
|
||||
|
||||
OpenLRSData binding;
|
||||
OpenLRSGet(&binding);
|
||||
OPLinkSettingsData binding;
|
||||
OPLinkSettingsGet(&binding);
|
||||
binding.version = openlrs_dev->bind_data.version;
|
||||
binding.serial_baudrate = openlrs_dev->bind_data.serial_baudrate;
|
||||
binding.rf_frequency = openlrs_dev->bind_data.rf_frequency;
|
||||
@ -729,14 +731,14 @@ static uint8_t pios_openlrs_bind_receive(struct pios_openlrs_dev *openlrs_dev, u
|
||||
binding.rf_channel_spacing = openlrs_dev->bind_data.rf_channel_spacing;
|
||||
binding.modem_params = openlrs_dev->bind_data.modem_params;
|
||||
binding.flags = openlrs_dev->bind_data.flags;
|
||||
for (uint32_t j = 0; j < OPENLRS_HOPCHANNEL_NUMELEM; j++) {
|
||||
for (uint32_t j = 0; j < OPLINKSETTINGS_HOPCHANNEL_NUMELEM; j++) {
|
||||
binding.hopchannel[j] = openlrs_dev->bind_data.hopchannel[j];
|
||||
}
|
||||
binding.beacon_frequency = openlrs_dev->beacon_frequency;
|
||||
binding.beacon_delay = openlrs_dev->beacon_delay;
|
||||
binding.beacon_period = openlrs_dev->beacon_period;
|
||||
OpenLRSSet(&binding);
|
||||
UAVObjSave(OpenLRSHandle(), 0);
|
||||
OPLinkSettingsSet(&binding);
|
||||
UAVObjSave(OPLinkSettingsHandle(), 0);
|
||||
|
||||
#if defined(PIOS_LED_LINK)
|
||||
PIOS_LED_Toggle(PIOS_LED_LINK);
|
||||
@ -788,11 +790,13 @@ static void pios_openlrs_setup(struct pios_openlrs_dev *openlrs_dev, bool bind)
|
||||
#endif
|
||||
|
||||
if (bind) {
|
||||
oplink_status.LinkState = OPLINKSTATUS_LINKSTATE_BINDING;
|
||||
if (pios_openlrs_bind_receive(openlrs_dev, 0)) {
|
||||
// TODO: save binding settings bindWriteEeprom();
|
||||
DEBUG_PRINTF(2, "Saved bind data to EEPROM (not really yet -- TODO)\r\n");
|
||||
}
|
||||
}
|
||||
oplink_status.LinkState = OPLINKSTATUS_LINKSTATE_BOUND;
|
||||
|
||||
DEBUG_PRINTF(2, "Entering normal mode\r\n");
|
||||
|
||||
@ -874,6 +878,9 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
|
||||
PIOS_OpenLRS_Rcvr_UpdateChannels(openlrs_dev->openlrs_rcvr_id, openlrs_dev->ppm);
|
||||
#endif
|
||||
}
|
||||
if (openlrs_dev->ppm_callback) {
|
||||
openlrs_dev->ppm_callback(openlrs_dev->ppm);
|
||||
}
|
||||
} else {
|
||||
// Not PPM data. Push into serial RX buffer.
|
||||
if ((openlrs_dev->rx_buf[0] & 0x38) == 0x38) {
|
||||
@ -890,9 +897,9 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
|
||||
}
|
||||
|
||||
// Flag to indicate ever got a link
|
||||
openlrs_dev->link_acquired |= true;
|
||||
oplink_status.LinkState = OPLINKSTATUS_LINKSTATE_CONNECTED;
|
||||
openlrs_dev->beacon_armed = false; // when receiving packets make sure beacon cannot emit
|
||||
openlrs_dev->link_acquired |= true;
|
||||
oplink_status.LinkState = OPLINKSTATUS_LINKSTATE_CONNECTED;
|
||||
openlrs_dev->beacon_armed = false; // when receiving packets make sure beacon cannot emit
|
||||
|
||||
// When telemetry is enabled we ack packets and send info about FC back
|
||||
if (openlrs_dev->bind_data.flags & TELEMETRY_MASK) {
|
||||
@ -962,7 +969,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
|
||||
} else if ((openlrs_dev->numberOfLostPackets >= openlrs_dev->hopcount) && (PIOS_DELAY_GetuSSince(openlrs_dev->lastPacketTimeUs) > (getInterval(&openlrs_dev->bind_data) * openlrs_dev->hopcount))) {
|
||||
DEBUG_PRINTF(2, "ORLS WARN: Trying to resync\r\n");
|
||||
// hop slowly to allow resync with TX
|
||||
oplink_status.LinkQuality = 0;
|
||||
oplink_status.LinkQuality = 0;
|
||||
openlrs_dev->willhop = 1;
|
||||
openlrs_dev->lastPacketTimeUs = timeUs;
|
||||
}
|
||||
@ -1039,8 +1046,10 @@ uint8_t PIOS_OpenLRS_RSSI_Get(void)
|
||||
if (oplink_status.LinkState != OPLINKSTATUS_LINKSTATE_CONNECTED) {
|
||||
return 0;
|
||||
} else {
|
||||
OpenLRSData openlrs_data;
|
||||
OpenLRSGet(&openlrs_data);
|
||||
OPLinkStatusData openlrs_status;
|
||||
OPLinkStatusGet(&openlrs_status);
|
||||
OPLinkSettingsData openlrs_data;
|
||||
OPLinkSettingsGet(&openlrs_data);
|
||||
|
||||
uint16_t LQ = oplink_status.LinkQuality & 0x7fff;
|
||||
// count number of 1s in LinkQuality
|
||||
@ -1051,16 +1060,16 @@ uint8_t PIOS_OpenLRS_RSSI_Get(void)
|
||||
LQ = (LQ * 0x0101) >> 8;
|
||||
|
||||
switch (openlrs_data.RSSI_Type) {
|
||||
case OPENLRS_RSSI_TYPE_COMBINED:
|
||||
case OPLINKSETTINGS_RSSI_TYPE_COMBINED:
|
||||
if ((uint8_t)LQ == 15) {
|
||||
return (uint8_t)((oplink_status.RSSI >> 1) + 128);
|
||||
} else {
|
||||
return LQ * 9;
|
||||
}
|
||||
case OPENLRS_RSSI_TYPE_RSSI:
|
||||
return oplink_status.RSSI;
|
||||
case OPLINKSETTINGS_RSSI_TYPE_RSSI:
|
||||
return openlrs_status.RSSI;
|
||||
|
||||
case OPENLRS_RSSI_TYPE_LINKQUALITY:
|
||||
case OPLINKSETTINGS_RSSI_TYPE_LINKQUALITY:
|
||||
return (uint8_t)(LQ << 4);
|
||||
|
||||
default:
|
||||
@ -1091,6 +1100,24 @@ void PIOS_OpenLRS_RegisterRcvr(uint32_t openlrs_id, uint32_t openlrs_rcvr_id)
|
||||
openlrs_dev->openlrs_rcvr_id = openlrs_rcvr_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a OpenLRS_Rcvr interface to inform of PPM packets using a generic callback.
|
||||
*
|
||||
* @param[in] openlrs_id The OpenLRS device ID.
|
||||
* @param[in] callback The callback function.
|
||||
*/
|
||||
void PIOS_OpenLRS_RegisterPPMCallback(uint32_t openlrs_id, PIOS_OpenLRS_PPMReceivedCallback callback)
|
||||
{
|
||||
struct pios_openlrs_dev *openlrs_dev =
|
||||
(struct pios_openlrs_dev *)openlrs_id;
|
||||
|
||||
if (!pios_openlrs_validate(openlrs_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
openlrs_dev->ppm_callback = callback;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Task and device setup
|
||||
*****************************************************************************/
|
||||
@ -1142,12 +1169,13 @@ int32_t PIOS_OpenLRS_Init(uint32_t *openlrs_id, uint32_t spi_id,
|
||||
|
||||
// Initialize the "PPM" callback.
|
||||
openlrs_dev->openlrs_rcvr_id = 0;
|
||||
openlrs_dev->ppm_callback = 0;
|
||||
|
||||
OpenLRSInitialize();
|
||||
OPLinkSettingsInitialize();
|
||||
OPLinkStatusInitialize();
|
||||
DEBUG_PRINTF(2, "OpenLRS UAVOs Initialized\r\n");
|
||||
OpenLRSData binding;
|
||||
OpenLRSGet(&binding);
|
||||
OPLinkSettingsData binding;
|
||||
OPLinkSettingsGet(&binding);
|
||||
if (binding.version == BINDING_VERSION) {
|
||||
openlrs_dev->bind_data.version = binding.version;
|
||||
openlrs_dev->bind_data.serial_baudrate = binding.serial_baudrate;
|
||||
@ -1157,7 +1185,7 @@ int32_t PIOS_OpenLRS_Init(uint32_t *openlrs_id, uint32_t spi_id,
|
||||
openlrs_dev->bind_data.rf_channel_spacing = binding.rf_channel_spacing;
|
||||
openlrs_dev->bind_data.modem_params = binding.modem_params;
|
||||
openlrs_dev->bind_data.flags = binding.flags;
|
||||
for (uint32_t i = 0; i < OPENLRS_HOPCHANNEL_NUMELEM; i++) {
|
||||
for (uint32_t i = 0; i < OPLINKSETTINGS_HOPCHANNEL_NUMELEM; i++) {
|
||||
openlrs_dev->bind_data.hopchannel[i] = binding.hopchannel[i];
|
||||
}
|
||||
}
|
||||
@ -1258,7 +1286,7 @@ static void pios_openlrs_task(void *parameters)
|
||||
// We timed out to sample RSSI
|
||||
if (openlrs_dev->numberOfLostPackets < 2) {
|
||||
openlrs_dev->lastRSSITimeUs = openlrs_dev->lastPacketTimeUs;
|
||||
oplink_status.RSSI = rfmGetRSSI(openlrs_dev); // Read the RSSI value
|
||||
oplink_status.RSSI = rfmGetRSSI(openlrs_dev); // Read the RSSI value
|
||||
|
||||
// DEBUG_PRINTF(3, "Sampled RSSI: %d %d\r\n", oplink_status.RSSI, delay);
|
||||
}
|
||||
|
@ -39,10 +39,13 @@ struct pios_openlrs_cfg {
|
||||
enum gpio_direction gpio_direction; /* Definition comes from pios_rfm22b.h */
|
||||
};
|
||||
|
||||
typedef void (*PIOS_OpenLRS_PPMReceivedCallback)(const int16_t *channels);
|
||||
|
||||
extern int32_t PIOS_OpenLRS_Init(uint32_t *openlrs_id, uint32_t spi_id,
|
||||
uint32_t slave_num, const struct pios_openlrs_cfg *cfg);
|
||||
|
||||
extern void PIOS_OpenLRS_RegisterRcvr(uint32_t openlrs_id, uint32_t rfm22b_rcvr_id);
|
||||
extern void PIOS_OpenLRS_RegisterPPMCallback(uint32_t openlrs_id, PIOS_OpenLRS_PPMReceivedCallback callback);
|
||||
extern uint8_t PIOS_OpenLRS_RSSI_Get(void);
|
||||
#endif /* PIOS_OPENLRS_H */
|
||||
/**
|
||||
|
@ -160,6 +160,9 @@ struct pios_openlrs_dev {
|
||||
// RFM22B RCVR interface
|
||||
uintptr_t openlrs_rcvr_id;
|
||||
|
||||
// PPM callback.
|
||||
PIOS_OpenLRS_PPMReceivedCallback ppm_callback;
|
||||
|
||||
// Flag to indicate if link every acquired
|
||||
bool link_acquired;
|
||||
|
||||
|
@ -298,8 +298,6 @@ static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config = {
|
||||
},
|
||||
};
|
||||
|
||||
#include <pios_rfm22b_priv.h>
|
||||
|
||||
struct pios_rfm22b_cfg pios_rfm22b_cfg = {
|
||||
.spi_cfg = &pios_spi_rfm22b_cfg,
|
||||
.exti_cfg = &pios_exti_rfm22b_cfg,
|
||||
@ -314,6 +312,51 @@ const struct pios_rfm22b_cfg *PIOS_BOARD_HW_DEFS_GetRfm22Cfg(__attribute__((unus
|
||||
return &pios_rfm22b_cfg;
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_OPENLRS)
|
||||
|
||||
#include <pios_openlrs_priv.h>
|
||||
|
||||
static const struct pios_exti_cfg pios_exti_openlrs_cfg __exti_config = {
|
||||
.vector = PIOS_OpenLRS_EXT_Int,
|
||||
.line = EXTI_Line2,
|
||||
.pin = {
|
||||
.gpio = GPIOA,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_2,
|
||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||
},
|
||||
},
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = EXTI2_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.exti = {
|
||||
.init = {
|
||||
.EXTI_Line = EXTI_Line2,
|
||||
.EXTI_Mode = EXTI_Mode_Interrupt,
|
||||
.EXTI_Trigger = EXTI_Trigger_Falling,
|
||||
.EXTI_LineCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
struct pios_openlrs_cfg pios_openlrs_cfg = {
|
||||
.spi_cfg = &pios_spi_rfm22b_cfg,
|
||||
.exti_cfg = &pios_exti_openlrs_cfg,
|
||||
};
|
||||
|
||||
// ! Compatibility layer for various hardware revisions
|
||||
const struct pios_openlrs_cfg *PIOS_BOARD_HW_DEFS_GetOpenLRSCfg(__attribute__((unused)) uint32_t board_revision)
|
||||
{
|
||||
return &pios_openlrs_cfg;
|
||||
}
|
||||
|
||||
#endif /* PIOS_INCLUDE_OpenLRS */
|
||||
|
||||
#endif /* PIOS_INCLUDE_RFM22B */
|
||||
|
||||
#if defined(PIOS_INCLUDE_ADC)
|
||||
|
@ -59,6 +59,8 @@ ifndef TESTAPP
|
||||
SRC += $(FLIGHT_UAVOBJ_DIR)/objectpersistence.c
|
||||
SRC += $(FLIGHT_UAVOBJ_DIR)/oplinkreceiver.c
|
||||
SRC += $(FLIGHT_UAVOBJ_DIR)/radiocombridgestats.c
|
||||
SRC += $(FLIGHT_UAVOBJ_DIR)/flightbatterystate.c
|
||||
SRC += $(FLIGHT_UAVOBJ_DIR)/flightstatus.c
|
||||
else
|
||||
## Test Code
|
||||
SRC += $(OPTESTS)/test_common.c
|
||||
|
@ -120,6 +120,7 @@
|
||||
#define PIOS_INCLUDE_RFM22B
|
||||
#define PIOS_INCLUDE_RFM22B_COM
|
||||
#define PIOS_INCLUDE_PPM_OUT
|
||||
#define PIOS_INCLUDE_OPENLRS
|
||||
/* #define PIOS_RFM22B_DEBUG_ON_TELEM */
|
||||
|
||||
/* PIOS misc peripherals */
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <pios_board_info.h>
|
||||
#include <pios_ppm_out.h>
|
||||
#include <oplinksettings.h>
|
||||
#include <pios_openlrs.h>
|
||||
#include <taskinfo.h>
|
||||
#ifdef PIOS_INCLUDE_SERVO
|
||||
#include <pios_servo.h>
|
||||
@ -225,6 +226,7 @@ void PIOS_Board_Init(void)
|
||||
OPLinkSettingsData oplinkSettings;
|
||||
OPLinkSettingsGet(&oplinkSettings);
|
||||
bool is_coordinator = (oplinkSettings.Protocol == OPLINKSETTINGS_PROTOCOL_OPLINKCOORDINATOR);
|
||||
bool openlrs = (oplinkSettings.Protocol == OPLINKSETTINGS_PROTOCOL_OPENLRS);
|
||||
bool is_oneway = (oplinkSettings.OneWay == OPLINKSETTINGS_ONEWAY_TRUE);
|
||||
bool ppm_only = (oplinkSettings.PPMOnly == OPLINKSETTINGS_PPMONLY_TRUE);
|
||||
bool ppm_mode = false;
|
||||
@ -365,91 +367,103 @@ void PIOS_Board_Init(void)
|
||||
|
||||
/* Initalize the RFM22B radio COM device. */
|
||||
if (oplinkSettings.MaxRFPower != OPLINKSETTINGS_MAXRFPOWER_0) {
|
||||
oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_ENABLED;
|
||||
if (openlrs) {
|
||||
#if defined(PIOS_INCLUDE_OPENLRS)
|
||||
const struct pios_openlrs_cfg *openlrs_cfg = PIOS_BOARD_HW_DEFS_GetOpenLRSCfg(bdinfo->board_rev);
|
||||
uint32_t openlrs_id;
|
||||
|
||||
// Configure the RFM22B device
|
||||
const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev);
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_ENABLED;
|
||||
|
||||
// Configure the radio com interface
|
||||
uint8_t *rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_RFM22B_RF_RX_BUF_LEN);
|
||||
uint8_t *tx_buffer = (uint8_t *)pios_malloc(PIOS_COM_RFM22B_RF_TX_BUF_LEN);
|
||||
PIOS_Assert(rx_buffer);
|
||||
PIOS_Assert(tx_buffer);
|
||||
if (PIOS_COM_Init(&pios_com_rfm22b_id, &pios_rfm22b_com_driver, pios_rfm22b_id,
|
||||
rx_buffer, PIOS_COM_RFM22B_RF_RX_BUF_LEN,
|
||||
tx_buffer, PIOS_COM_RFM22B_RF_TX_BUF_LEN)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
PIOS_OpenLRS_Init(&openlrs_id, PIOS_RFM22_SPI_PORT, 0, openlrs_cfg);
|
||||
PIOS_OpenLRS_RegisterPPMCallback(openlrs_id, PIOS_Board_PPM_callback);
|
||||
#endif /* PIOS_INCLUDE_OPENLRS */
|
||||
} else {
|
||||
oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_ENABLED;
|
||||
|
||||
// Set the RF data rate on the modem to ~2X the selected buad rate because the modem is half duplex.
|
||||
enum rfm22b_datarate datarate = RFM22_datarate_64000;
|
||||
switch (oplinkSettings.ComSpeed) {
|
||||
case OPLINKSETTINGS_COMSPEED_4800:
|
||||
datarate = RFM22_datarate_9600;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_9600:
|
||||
datarate = RFM22_datarate_19200;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_19200:
|
||||
datarate = RFM22_datarate_32000;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_38400:
|
||||
datarate = RFM22_datarate_64000;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_57600:
|
||||
datarate = RFM22_datarate_100000;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_115200:
|
||||
datarate = RFM22_datarate_192000;
|
||||
break;
|
||||
}
|
||||
// Configure the RFM22B device
|
||||
const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev);
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
/* Set the modem Tx power level */
|
||||
switch (oplinkSettings.MaxRFPower) {
|
||||
case OPLINKSETTINGS_MAXRFPOWER_125:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_0);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_16:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_1);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_316:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_2);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_63:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_3);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_126:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_4);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_25:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_5);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_50:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_6);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_100:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_7);
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
// Configure the radio com interface
|
||||
uint8_t *rx_buffer = (uint8_t *)pios_malloc(PIOS_COM_RFM22B_RF_RX_BUF_LEN);
|
||||
uint8_t *tx_buffer = (uint8_t *)pios_malloc(PIOS_COM_RFM22B_RF_TX_BUF_LEN);
|
||||
PIOS_Assert(rx_buffer);
|
||||
PIOS_Assert(tx_buffer);
|
||||
if (PIOS_COM_Init(&pios_com_rfm22b_id, &pios_rfm22b_com_driver, pios_rfm22b_id,
|
||||
rx_buffer, PIOS_COM_RFM22B_RF_RX_BUF_LEN,
|
||||
tx_buffer, PIOS_COM_RFM22B_RF_TX_BUF_LEN)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
// Set the radio configuration parameters.
|
||||
PIOS_RFM22B_SetDeviceID(pios_rfm22b_id, oplinkSettings.CustomDeviceID);
|
||||
PIOS_RFM22B_SetCoordinatorID(pios_rfm22b_id, oplinkSettings.CoordID);
|
||||
PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, is_oneway, ppm_mode, ppm_only);
|
||||
// Set the RF data rate on the modem to ~2X the selected buad rate because the modem is half duplex.
|
||||
enum rfm22b_datarate datarate = RFM22_datarate_64000;
|
||||
switch (oplinkSettings.ComSpeed) {
|
||||
case OPLINKSETTINGS_COMSPEED_4800:
|
||||
datarate = RFM22_datarate_9600;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_9600:
|
||||
datarate = RFM22_datarate_19200;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_19200:
|
||||
datarate = RFM22_datarate_32000;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_38400:
|
||||
datarate = RFM22_datarate_64000;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_57600:
|
||||
datarate = RFM22_datarate_100000;
|
||||
break;
|
||||
case OPLINKSETTINGS_COMSPEED_115200:
|
||||
datarate = RFM22_datarate_192000;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set the PPM callback if we should be receiving PPM. */
|
||||
if (ppm_mode || (ppm_only && !is_coordinator)) {
|
||||
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback);
|
||||
}
|
||||
/* Set the modem Tx power level */
|
||||
switch (oplinkSettings.MaxRFPower) {
|
||||
case OPLINKSETTINGS_MAXRFPOWER_125:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_0);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_16:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_1);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_316:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_2);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_63:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_3);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_126:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_4);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_25:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_5);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_50:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_6);
|
||||
break;
|
||||
case OPLINKSETTINGS_MAXRFPOWER_100:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_7);
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
// Reinitialize the modem to affect the changes.
|
||||
PIOS_RFM22B_Reinit(pios_rfm22b_id);
|
||||
// Set the radio configuration parameters.
|
||||
PIOS_RFM22B_SetDeviceID(pios_rfm22b_id, oplinkSettings.CustomDeviceID);
|
||||
PIOS_RFM22B_SetCoordinatorID(pios_rfm22b_id, oplinkSettings.CoordID);
|
||||
PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, is_oneway, ppm_mode, ppm_only);
|
||||
|
||||
/* Set the PPM callback if we should be receiving PPM. */
|
||||
if (ppm_mode || (ppm_only && !is_coordinator)) {
|
||||
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback);
|
||||
}
|
||||
|
||||
// Reinitialize the modem to affect the changes.
|
||||
PIOS_RFM22B_Reinit(pios_rfm22b_id);
|
||||
} // openlrs
|
||||
} else {
|
||||
oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_DISABLED;
|
||||
}
|
||||
|
@ -103,7 +103,6 @@ UAVOBJS = \
|
||||
$${UAVOBJ_XML_DIR}/mpugyroaccelsettings.xml \
|
||||
$${UAVOBJ_XML_DIR}/nedaccel.xml \
|
||||
$${UAVOBJ_XML_DIR}/objectpersistence.xml \
|
||||
$${UAVOBJ_XML_DIR}/openlrs.xml \
|
||||
$${UAVOBJ_XML_DIR}/oplinkreceiver.xml \
|
||||
$${UAVOBJ_XML_DIR}/oplinksettings.xml \
|
||||
$${UAVOBJ_XML_DIR}/oplinkstatus.xml \
|
||||
|
@ -1,28 +0,0 @@
|
||||
<xml>
|
||||
<object name="OpenLRS" singleinstance="true" settings="true" category="System">
|
||||
<description>Binding settings for OpenLRS</description>
|
||||
|
||||
<field name="version" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="serial_baudrate" units="" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_frequency" units="" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_magic" units="" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_power" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_channel_spacing" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="hopchannel" units="" type="uint8" elements="24" defaultvalue="0"/>
|
||||
<field name="modem_params" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="flags" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
|
||||
<!-- beacon options -->
|
||||
<field name="beacon_frequency" units="" type="uint32" elements="1" defaultvalue="462712500"/>
|
||||
<field name="beacon_delay" units="s" type="uint8" elements="1" defaultvalue="30"/>
|
||||
<field name="beacon_period" units="s" type="uint8" elements="1" defaultvalue="15"/>
|
||||
|
||||
<field name="failsafe_delay" units="ms" type="uint32" elements="1" defaultvalue="1000"/>
|
||||
<field name="RSSI_Type" units="function" type="enum" elements="1" options="Combined,RSSI,LinkQuality" defaultvalue="Combined"/>
|
||||
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
|
||||
<telemetryflight acked="true" updatemode="onchange" period="0"/>
|
||||
<logging updatemode="manual" period="0"/>
|
||||
</object>
|
||||
</xml>
|
@ -15,6 +15,25 @@
|
||||
<field name="MaxChannel" units="" type="uint8" elements="1" defaultvalue="250"/>
|
||||
<field name="CustomDeviceID" units="hex" type="uint32" elements="1" defaultvalue="0"/>
|
||||
|
||||
<!-- OpenLRS options -->
|
||||
<field name="version" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="serial_baudrate" units="" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_frequency" units="" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_magic" units="" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_power" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="rf_channel_spacing" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="hopchannel" units="" type="uint8" elements="24" defaultvalue="0"/>
|
||||
<field name="modem_params" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="flags" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
|
||||
<!-- beacon options -->
|
||||
<field name="beacon_frequency" units="" type="uint32" elements="1" defaultvalue="462712500"/>
|
||||
<field name="beacon_delay" units="s" type="uint8" elements="1" defaultvalue="30"/>
|
||||
<field name="beacon_period" units="s" type="uint8" elements="1" defaultvalue="15"/>
|
||||
|
||||
<field name="failsafe_delay" units="ms" type="uint32" elements="1" defaultvalue="1000"/>
|
||||
<field name="RSSI_Type" units="function" type="enum" elements="1" options="Combined,RSSI,LinkQuality" defaultvalue="Combined"/>
|
||||
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
|
||||
<telemetryflight acked="true" updatemode="onchange" period="0"/>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<field name="RXRate" units="Bps" type="uint16" elements="1" defaultvalue="0"/>
|
||||
<field name="TXSeq" units="" type="uint16" elements="1" defaultvalue="0"/>
|
||||
<field name="RXSeq" units="" type="uint16" elements="1" defaultvalue="0"/>
|
||||
<field name="LinkState" units="function" type="enum" elements="1" options="Disabled,Enabled,Disconnected,Connecting,Connected" defaultvalue="Disabled"/>
|
||||
<field name="LinkState" units="function" type="enum" elements="1" options="Disabled,Enabled,Binding,Bound,Disconnected,Connecting,Connected" defaultvalue="Disabled"/>
|
||||
<field name="PairIDs" units="hex" type="uint32" elements="4" defaultvalue="0"/>
|
||||
<field name="PairSignalStrengths" units="dBm" type="int8" elements="4" defaultvalue="-127"/>
|
||||
<field name="TXPacketRate" units="packet/s" type="uint16" elements="1" defaultvalue="0"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user