Skip to content

Commit

Permalink
Merge pull request #133 from raul-ortega/development
Browse files Browse the repository at this point in the history
11.2.0 RC2 to master
  • Loading branch information
raul-ortega authored Oct 28, 2024
2 parents 03df6b7 + 4b8b6cc commit 377019a
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 192 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ HIGHEND_SRC = \
telemetry/nmea.c \
telemetry/ltm.c \
telemetry/position_estimation_log.c \
telemetry/forward.c \
sensors/sonar.c \
sensors/barometer.c

Expand Down
6 changes: 6 additions & 0 deletions src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,12 @@ static void resetConf(void)
//ALTITUDE
masterConfig.altitude_priority = 0;

// LAST HOME POSITION
masterConfig.restore_last_home = 0;
masterConfig.home_lat = 0;
masterConfig.home_lon = 0;
masterConfig.home_alt = 0;

/////////////////////////////

// copy first profile into remaining profile
Expand Down
4 changes: 4 additions & 0 deletions src/main/config/config_master.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ typedef struct master_t {
uint8_t max_speed_filter;
uint8_t altitude_priority;
uint8_t pan_inverted;
uint8_t restore_last_home;
int32_t home_lat;
int32_t home_lon;
int16_t home_alt;
} master_t;

extern master_t masterConfig;
Expand Down
5 changes: 4 additions & 1 deletion src/main/io/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ extern bool gotFix;
extern bool gotTelemetry;
extern bool lostTelemetry;
extern bool homeSet_BY_GPS;
extern bool homeSet_BY_LAST;
extern bool homeSet;
extern bool homeReset;

Expand Down Expand Up @@ -780,7 +781,9 @@ void showTelemetryPage(void){
if(!PROTOCOL(TP_MFD)) {
if(homeSet_BY_GPS && homeSet)
tfp_sprintf(lineBuffer, "HOME SET <GPS>");
else if(!homeSet_BY_GPS && homeSet)
else if(homeSet_BY_LAST && homeSet)
tfp_sprintf(lineBuffer, "HOME SET <LAST>");
else if(homeSet)
tfp_sprintf(lineBuffer, "HOME SET <AIRCRAFT>");
else if(!homeSet || homeReset)
tfp_sprintf(lineBuffer, "HOME NOT SET");
Expand Down
1 change: 1 addition & 0 deletions src/main/io/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef enum {
FUNCTION_TELEMETRY_NMEA = (1 << 10), // 1024
FUNCTION_TELEMETRY_LTM = (1 << 11), // 2048
FUNCTION_TELEMETRY_POSEST = (1 << 12), // 4096
FUNCTION_TELEMETRY_FORWARD = (1 << 13), // 8192
} serialPortFunction_e;

typedef enum {
Expand Down
21 changes: 17 additions & 4 deletions src/main/io/serial_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ typedef enum {
VAR_INT16 = (3 << VALUE_TYPE_OFFSET),
VAR_UINT32 = (4 << VALUE_TYPE_OFFSET),
VAR_FLOAT = (5 << VALUE_TYPE_OFFSET),
VAR_INT32 = (6 << VALUE_TYPE_OFFSET),

// value section
MASTER_VALUE = (0 << VALUE_SECTION_OFFSET),
Expand Down Expand Up @@ -538,7 +539,11 @@ const clivalue_t valueTable[] = {
{ "gps_auto_baud", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.autoBaud, .config.lookup = { TABLE_OFF_ON } },
{ "gps_min_sats", VAR_UINT8 | MASTER_VALUE, &masterConfig.gps_min_sats, .config.minmax = { 4, 20 } },
{ "gps_home_beeper", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.homeBeeper, .config.lookup = { TABLE_OFF_ON } },
{ "update_home_by_local_gps", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.update_home_by_local_gps, .config.lookup = { TABLE_OFF_ON } },
{ "update_home_by_local_gps", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.update_home_by_local_gps, .config.lookup = { TABLE_OFF_ON } },
{ "restore_last_home", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.restore_last_home, .config.lookup = { TABLE_OFF_ON } },
{ "home_lat", VAR_INT32 | MASTER_VALUE, &masterConfig.home_lat, .config.minmax = { -90000000, 90000000 } },
{ "home_lon", VAR_INT32 | MASTER_VALUE, &masterConfig.home_lon, .config.minmax = { -180000000, 180000000 } },
{ "home_alt", VAR_INT16 | MASTER_VALUE, &masterConfig.home_alt, .config.minmax = { 0, 65535 } },
/*
{ "gps_pos_p", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDPOS], .config.minmax = { 0, 200 } },
{ "gps_pos_i", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDPOS], .config.minmax = { 0, 200 } },
Expand Down Expand Up @@ -733,7 +738,7 @@ const clivalue_t valueTable[] = {
{ "pan_pin", VAR_UINT8 | MASTER_VALUE, &masterConfig.pan_pin, .config.minmax = { 0, 7 } },
{ "pan0", VAR_UINT16 | MASTER_VALUE, &masterConfig.pan0, .config.minmax = { 0, 3000 } },
{ "pan0_calibrated", VAR_UINT8 | MASTER_VALUE, &masterConfig.pan0_calibrated, .config.minmax = { 0, 1 } },
{ "pan_calibration_pulse", VAR_UINT16 | MASTER_VALUE, &masterConfig.pan_calibration_pulse, .config.minmax = { 1, 1500 } },
{ "pan_calibration_pulse", VAR_UINT16 | MASTER_VALUE, &masterConfig.pan_calibration_pulse, .config.minmax = { 0, 3000 } },
{ "pan_inverted", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.pan_inverted, .config.lookup = { TABLE_OFF_ON } },
{ "min_pan_speed", VAR_UINT8 | MASTER_VALUE, &masterConfig.min_pan_speed, .config.minmax = { 0, 100 } },
{ "tilt_pin", VAR_UINT8 | MASTER_VALUE, &masterConfig.tilt_pin, .config.minmax = { 0, 7 } },
Expand Down Expand Up @@ -2227,6 +2232,10 @@ static void cliPrintVar(const clivalue_t *var, uint32_t full)
value = *(uint32_t *)ptr;
break;

case VAR_INT32:
value = *(int32_t *)ptr;
break;

case VAR_FLOAT:
printf("%s", ftoa(*(float *)ptr, buf));
if (full && (var->type & VALUE_MODE_MASK) == MODE_DIRECT) {
Expand Down Expand Up @@ -2276,6 +2285,10 @@ static void cliSetVar(const clivalue_t *var, const int_float_value_t value)
*(uint32_t *)ptr = value.int_value;
break;

case VAR_INT32:
*(int32_t *)ptr = value.int_value;
break;

case VAR_FLOAT:
*(float *)ptr = (float)value.float_value;
if(ptr==&masterConfig.offset)
Expand Down Expand Up @@ -2511,7 +2524,7 @@ static void cliMovePanServo(char *cmdline)
} else {
degrees=atoi(cmdline);
if(degrees>=0 && degrees<=360 ) {
printf("Moving pan servo to %u º\r\n", degrees);
printf("Moving pan servo to %u deg.\r\n", degrees);
SERVOTEST_HEADING=degrees;
ENABLE_SERVO(SERVOPAN_MOVE);
}
Expand All @@ -2530,7 +2543,7 @@ static void cliMoveTiltServo(char *cmdline)
} else {
degrees=atoi(cmdline);
if(degrees >=0 && degrees <= 90 ) {
printf("Moving tilt servo to %u º\r\n", degrees);
printf("Moving tilt servo to %u deg.\r\n", degrees);
SERVOTEST_TILT = degrees;
ENABLE_SERVO(SERVOTILT_MOVE);
}
Expand Down
124 changes: 124 additions & 0 deletions src/main/telemetry/forward.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#include "platform.h"

#ifdef TELEMETRY

#include "common/maths.h"
#include "common/axis.h"

#include "drivers/system.h"
#include "drivers/sensor.h"
#include "drivers/accgyro.h"
#include "drivers/gpio.h"
#include "drivers/timer.h"
#include "drivers/serial.h"


#include "sensors/sensors.h"
#include "sensors/acceleration.h"
#include "sensors/gyro.h"
#include "sensors/barometer.h"
#include "sensors/battery.h"

#include "io/serial.h"
#include "io/rc_controls.h"
#include "io/gps.h"

#include "rx/rx.h"

#include "flight/mixer.h"
#include "flight/pid.h"
#include "flight/imu.h"
#include "flight/altitudehold.h"

#include "config/runtime_config.h"
#include "config/config.h"

#include "telemetry/telemetry.h"
#include "telemetry/forward.h"

static serialPort_t *forwardPort = NULL;
static serialPortConfig_t *portConfig;

#define FORWARD_BAUDRATE 57600
#define FORWARD_INITIAL_PORT_MODE MODE_RXTX

static telemetryConfig_t *telemetryConfig;
static bool forwardTelemetryEnabled = false;
static portSharing_e forwardPortSharing;

#define CYCLETIME 125

static uint32_t lastCycleTime = 0;
static uint8_t cycleNum = 0;

void initForwardTelemetry(telemetryConfig_t *initialTelemetryConfig)
{
telemetryConfig = initialTelemetryConfig;
portConfig = findSerialPortConfig(FUNCTION_TELEMETRY_FORWARD);
forwardPortSharing = determinePortSharing(portConfig, FUNCTION_TELEMETRY_FORWARD);
}

void freeForwardTelemetryPort(void)
{
closeSerialPort(forwardPort);
forwardPort = NULL;
forwardTelemetryEnabled = false;
}

void configureForwardTelemetryPort(void)
{
if (!portConfig) {
return;
}

forwardPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_FORWARD, NULL, FORWARD_BAUDRATE, FORWARD_INITIAL_PORT_MODE, telemetryConfig->telemetry_inversion ? SERIAL_INVERTED : SERIAL_NOT_INVERTED);
if (!forwardPort) {
return;
}

forwardTelemetryEnabled = true;
}

void checkForwardTelemetryState(void)
{
bool newTelemetryEnabledValue = telemetryDetermineEnabledState(forwardPortSharing);

if (newTelemetryEnabledValue == forwardTelemetryEnabled) {
return;
}

if (newTelemetryEnabledValue)
configureForwardTelemetryPort();
else
freeForwardTelemetryPort();
}

void handleForwardTelemetry(rxConfig_t *rxConfig, uint16_t deadband3d_throttle)
{
if (!forwardTelemetryEnabled) {
return;
}

while (serialRxBytesWaiting(forwardPort) > 0) {
uint8_t c = serialRead(forwardPort);
evaluateOtherData(forwardPort,c);
}


}

void forwardTelemetry(uint8_t c){
serialWrite(forwardPort, c);
}

bool forwardEnabled(void){
return(forwardTelemetryEnabled);
}


#endif

14 changes: 14 additions & 0 deletions src/main/telemetry/forward.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "rx/rx.h"

#ifndef TELEMETRY_FORWARD_
#define TELEMETRY_FORWARD_

void handleForwardTelemetryvoid(rxConfig_t *rxConfig, uint16_t deadband3d_throttle);
void checkForwardTelemetryState(void);

void initForwardTelemetry(telemetryConfig_t *telemetryConfig);
void configureForwardTelemetryPort(void);
void freeForwardTelemetryPort(void);
bool forwardEnabled(void);

#endif /* TELEMETRY_FORWARD_ */
5 changes: 4 additions & 1 deletion src/main/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "telemetry/nmea.h"
#include "telemetry/ltm.h"
#include "telemetry/position_estimation_log.h"
#include "telemetry/forward.h"

static telemetryConfig_t *telemetryConfig;

Expand All @@ -64,7 +65,7 @@ void telemetryInit(void)
initNMEATelemetry(telemetryConfig);
initLtmTelemetry(telemetryConfig);
initPOSESTTelemetry(telemetryConfig);

initForwardTelemetry(telemetryConfig);
telemetryCheckState();
}

Expand Down Expand Up @@ -93,6 +94,7 @@ void telemetryCheckState(void)
checkNMEATelemetryState();
checkLtmTelemetryState();
checkPOSESTTelemetryState();
checkForwardTelemetryState();
}

void telemetryProcess(rxConfig_t *rxConfig, uint16_t deadband3d_throttle)
Expand All @@ -106,6 +108,7 @@ void telemetryProcess(rxConfig_t *rxConfig, uint16_t deadband3d_throttle)
handleNMEATelemetry();
handleLtmTelemetry();
handlePOSESTTelemetry();
handleForwardTelemetry();
}

#endif
25 changes: 19 additions & 6 deletions src/main/tracker/frskyx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file is part of u360gts, aka amv-open360tracker 32bits:
* https://github.com/raul-ortega/amv-open360tracker-32bits
*
* The code below is an adaptation by Raúl Ortega of the original code written by Samuel Brucksch:
* The code below is an adaptation by Raúl Ortega of the original code written by Samuel Brucksch:
* https://github.com/SamuelBrucksch/open360tracker
*
* u360gts is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -157,7 +157,20 @@ void processHubPacket(uint8_t id, uint16_t value)
}
}

bool checkSportPacket(uint8_t *packet)
bool checkSportPacket_V1(uint8_t *packet)
{
short crc = 0;
for (int i = 1; i < FRSKY_RX_PACKET_SIZE; i++) {
crc += packet[i]; //0-1FF
crc += crc >> 8; //0-100
crc &= 0x00ff;
crc += crc >> 8; //0-0FF
crc &= 0x00ff;
}
return (crc == 0x00ff);
}

static uint8_t checkSportPacket_V2(uint8_t * packet)
{
short crc = 0;
for (int i = 1; i < FRSKY_RX_PACKET_SIZE; i++) {
Expand All @@ -180,10 +193,10 @@ void processSportPacket(uint8_t *packet)
uint8_t prim = packet[1];
uint16_t appId = *((uint16_t *)(packet + 2));

if (!checkSportPacket(packet)){
telemetry_failed_cs++;
return;
}
if (!checkSportPacket_V1(packet) && !checkSportPacket_V2(packet)){
telemetry_failed_cs++;
return;
}

if(appId == GPS_STATUS) telemetry_provider = TELEMETRY_PROVIDER_APM10;

Expand Down
Loading

0 comments on commit 377019a

Please sign in to comment.