Move common telemetry code to telemetry_common.c/.h

This commit is contained in:
Dominic Clifton 2014-04-06 23:07:58 +01:00
parent d73094396d
commit 1cbe166c49
9 changed files with 100 additions and 55 deletions

View File

@ -55,6 +55,7 @@ COMMON_SRC = startup_stm32f10x_md_gcc.S \
sbus.c \ sbus.c \
sumd.c \ sumd.c \
spektrum.c \ spektrum.c \
telemetry_common.c \
telemetry_frsky.c \ telemetry_frsky.c \
drv_gpio.c \ drv_gpio.c \
drv_i2c.c \ drv_i2c.c \

View File

@ -1,6 +1,8 @@
#include "board.h" #include "board.h"
#include "mw.h" #include "mw.h"
#include "telemetry_common.h"
core_t core; core_t core;
extern rcReadRawDataPtr rcReadRawFunc; extern rcReadRawDataPtr rcReadRawFunc;

View File

@ -1,6 +1,8 @@
#include "board.h" #include "board.h"
#include "mw.h" #include "mw.h"
#include "telemetry_common.h"
// June 2013 V2.2-dev // June 2013 V2.2-dev
flags_t f; flags_t f;

View File

@ -477,7 +477,3 @@ void GPS_reset_nav(void);
void GPS_set_next_wp(int32_t* lat, int32_t* lon); void GPS_set_next_wp(int32_t* lat, int32_t* lon);
int32_t wrap_18000(int32_t error); int32_t wrap_18000(int32_t error);
// telemetry
void initTelemetry(void);
void updateTelemetryState(void);
void sendTelemetry(void);

View File

@ -1,6 +1,8 @@
#include "board.h" #include "board.h"
#include "mw.h" #include "mw.h"
#include "telemetry_common.h"
// Multiwii Serial Protocol 0 // Multiwii Serial Protocol 0
#define MSP_VERSION 0 #define MSP_VERSION 0
#define CAP_PLATFORM_32BIT ((uint32_t)1 << 31) #define CAP_PLATFORM_32BIT ((uint32_t)1 << 31)

51
src/telemetry_common.c Normal file
View File

@ -0,0 +1,51 @@
#include "board.h"
#include "mw.h"
#include "telemetry_frsky.h"
void initTelemetry(void)
{
// Sanity check for softserial vs. telemetry port
if (!feature(FEATURE_SOFTSERIAL))
mcfg.telemetry_softserial = TELEMETRY_UART;
if (mcfg.telemetry_softserial == TELEMETRY_SOFTSERIAL_1)
core.telemport = &(softSerialPorts[0].port);
else if (mcfg.telemetry_softserial == TELEMETRY_SOFTSERIAL_2)
core.telemport = &(softSerialPorts[1].port);
else
core.telemport = core.mainport;
}
void updateTelemetryState(void) {
updateFrSkyTelemetryState();
}
bool isTelemetryEnabled(void)
{
bool telemetryCurrentlyEnabled = true;
if (mcfg.telemetry_softserial == TELEMETRY_UART) {
if (!mcfg.telemetry_switch)
telemetryCurrentlyEnabled = f.ARMED;
else
telemetryCurrentlyEnabled = rcOptions[BOXTELEMETRY];
}
return telemetryCurrentlyEnabled;
}
bool isFrSkyTelemetryEnabled(void)
{
return mcfg.telemetry_provider == TELEMETRY_PROVIDER_FRSKY;
}
void sendTelemetry(void)
{
if (!isTelemetryEnabled())
return;
if (isFrSkyTelemetryEnabled()) {
sendFrSkyTelemetry();
}
}

17
src/telemetry_common.h Normal file
View File

@ -0,0 +1,17 @@
/*
* telemetry_common.h
*
* Created on: 6 Apr 2014
* Author: Hydra
*/
#ifndef TELEMETRY_COMMON_H_
#define TELEMETRY_COMMON_H_
// telemetry
void initTelemetry(void);
void updateTelemetryState(void);
void sendTelemetry(void);
bool isTelemetryEnabled(void);
#endif /* TELEMETRY_COMMON_H_ */

View File

@ -4,6 +4,9 @@
#include "board.h" #include "board.h"
#include "mw.h" #include "mw.h"
#include "telemetry_common.h"
#include "telemetry_frsky.h"
#define CYCLETIME 125 #define CYCLETIME 125
#define PROTOCOL_HEADER 0x5E #define PROTOCOL_HEADER 0x5E
@ -212,56 +215,28 @@ static void sendHeading(void)
serialize16(0); serialize16(0);
} }
static bool telemetryEnabled = false; static bool frSkyTelemetryEnabled = false;
void initTelemetry(void) bool shouldChangeTelemetryStateNow(bool frSkyTelemetryCurrentlyEnabled)
{ {
// Sanity check for softserial vs. telemetry port return frSkyTelemetryCurrentlyEnabled != frSkyTelemetryEnabled;
if (!feature(FEATURE_SOFTSERIAL))
mcfg.telemetry_softserial = TELEMETRY_UART;
if (mcfg.telemetry_softserial == TELEMETRY_SOFTSERIAL_1)
core.telemport = &(softSerialPorts[0].port);
else if (mcfg.telemetry_softserial == TELEMETRY_SOFTSERIAL_2)
core.telemport = &(softSerialPorts[1].port);
else
core.telemport = core.mainport;
} }
bool isTelemetryEnabled() void updateFrSkyTelemetryState(void)
{ {
bool telemetryCurrentlyEnabled = true; bool frSkyTelemetryCurrentlyEnabled = isTelemetryEnabled();
if (mcfg.telemetry_softserial == TELEMETRY_UART) { if (!shouldChangeTelemetryStateNow(frSkyTelemetryCurrentlyEnabled)) {
if (!mcfg.telemetry_switch)
telemetryCurrentlyEnabled = f.ARMED;
else
telemetryCurrentlyEnabled = rcOptions[BOXTELEMETRY];
}
return telemetryCurrentlyEnabled;
}
bool shouldChangeTelemetryStateNow(bool telemetryCurrentlyEnabled)
{
return telemetryCurrentlyEnabled != telemetryEnabled;
}
void updateTelemetryState(void)
{
bool telemetryCurrentlyEnabled = isTelemetryEnabled();
if (!shouldChangeTelemetryStateNow(telemetryCurrentlyEnabled)) {
return; return;
} }
if (mcfg.telemetry_softserial == TELEMETRY_UART && mcfg.telemetry_provider == TELEMETRY_PROVIDER_FRSKY) { if (mcfg.telemetry_softserial == TELEMETRY_UART && mcfg.telemetry_provider == TELEMETRY_PROVIDER_FRSKY) {
if (telemetryCurrentlyEnabled) if (frSkyTelemetryCurrentlyEnabled)
serialInit(9600); serialInit(9600);
else else
serialInit(mcfg.serial_baudrate); serialInit(mcfg.serial_baudrate);
} }
telemetryEnabled = telemetryCurrentlyEnabled; frSkyTelemetryEnabled = frSkyTelemetryCurrentlyEnabled;
} }
static uint32_t lastCycleTime = 0; static uint32_t lastCycleTime = 0;
@ -325,18 +300,3 @@ void sendFrSkyTelemetry(void)
} }
} }
bool isFrSkyTelemetryEnabled(void)
{
return mcfg.telemetry_provider == TELEMETRY_PROVIDER_FRSKY;
}
void sendTelemetry(void)
{
if (!isTelemetryEnabled())
return;
if (isFrSkyTelemetryEnabled()) {
sendFrSkyTelemetry();
}
}

14
src/telemetry_frsky.h Normal file
View File

@ -0,0 +1,14 @@
/*
* telemetry_frsky.h
*
* Created on: 6 Apr 2014
* Author: Hydra
*/
#ifndef TELEMETRY_FRSKY_H_
#define TELEMETRY_FRSKY_H_
void sendFrSkyTelemetry(void);
void updateFrSkyTelemetryState(void);
#endif /* TELEMETRY_FRSKY_H_ */