Skip to content

Commit

Permalink
Add more sensors to Jeti telemetry (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
robthomson authored Dec 30, 2024
1 parent cc9dcb8 commit ac113d2
Showing 1 changed file with 116 additions and 5 deletions.
121 changes: 116 additions & 5 deletions src/main/telemetry/jetiexbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "build/debug.h"
#include "fc/runtime_config.h"
#include "config/feature.h"
#include "fc/rc_adjustments.h"

#include "common/utils.h"
#include "common/bitarray.h"
Expand All @@ -38,7 +39,7 @@
#include "drivers/serial_uart.h"
#include "drivers/time.h"


#include "flight/governor.h"
#include "flight/position.h"
#include "flight/imu.h"

Expand All @@ -51,6 +52,8 @@
#include "sensors/battery.h"
#include "sensors/sensors.h"
#include "sensors/acceleration.h"
#include "sensors/esc_sensor.h"
#include "sensors/adcinternal.h"

#include "telemetry/jetiexbus.h"
#include "telemetry/telemetry.h"
Expand All @@ -65,6 +68,10 @@
#define EXTEL_MAX_PAYLOAD (EXTEL_MAX_LEN - EXTEL_OVERHEAD)
#define EXBUS_MAX_REQUEST_BUFFER_SIZE (EXBUS_OVERHEAD + EXTEL_MAX_LEN)

#ifdef USE_ESC_SENSOR_TELEMETRY
escSensorData_t *escData;
#endif

enum exTelHeader_e {
EXTEL_HEADER_SYNC = 0,
EXTEL_HEADER_TYPE_LEN,
Expand Down Expand Up @@ -116,7 +123,7 @@ typedef struct exBusSensor_s {
// list of telemetry messages
// after every 15 sensors a new header has to be inserted (e.g. "BF D2")
const exBusSensor_t jetiExSensors[] = {
{"BF D1", "", EX_TYPE_DES, 0 }, // device descripton
{"Rotorflight D1", "", EX_TYPE_DES, 0 }, // device descripton
{"Voltage", "V", EX_TYPE_22b, DECIMAL_MASK(1)},
{"Current", "A", EX_TYPE_22b, DECIMAL_MASK(2)},
{"Altitude", "m", EX_TYPE_22b, DECIMAL_MASK(2)},
Expand All @@ -132,12 +139,22 @@ const exBusSensor_t jetiExSensors[] = {
{"GPS Speed", "m/s", EX_TYPE_22b, DECIMAL_MASK(2)},
{"GPS H-Distance", "m", EX_TYPE_22b, DECIMAL_MASK(0)},
{"GPS H-Direction", "\xB0", EX_TYPE_22b, DECIMAL_MASK(1)},
{"BF D2", "", EX_TYPE_DES, 0 }, // device descripton
{"Rotorflight D2", "", EX_TYPE_DES, 0 }, // device descripton
{"GPS Heading", "\xB0", EX_TYPE_22b, DECIMAL_MASK(1)},
{"GPS Altitude", "m", EX_TYPE_22b, DECIMAL_MASK(2)},
{"G-Force X", "", EX_TYPE_22b, DECIMAL_MASK(3)},
{"G-Force Y", "", EX_TYPE_22b, DECIMAL_MASK(3)},
{"G-Force Z", "", EX_TYPE_22b, DECIMAL_MASK(3)}
{"G-Force Z", "", EX_TYPE_22b, DECIMAL_MASK(3)},
{"Headspeed", "rpm", EX_TYPE_22b, DECIMAL_MASK(0)},
{"Tailspeed", "rpm", EX_TYPE_22b, DECIMAL_MASK(0)},
{"Arming Flags", "", EX_TYPE_22b, DECIMAL_MASK(0)},
{"PID Profile", "", EX_TYPE_22b, DECIMAL_MASK(0)},
{"RATES Profile", "", EX_TYPE_22b, DECIMAL_MASK(0)},
{"Governor", "", EX_TYPE_22b, DECIMAL_MASK(0)},
{"Thr. Control", "", EX_TYPE_22b, DECIMAL_MASK(0)},
{"Adj. Function", "", EX_TYPE_22b, DECIMAL_MASK(0)},
{"Adj. Value", "", EX_TYPE_22b, DECIMAL_MASK(0)},
{"ESC. Temp.", "\xB0", EX_TYPE_22b, DECIMAL_MASK(1)},
};

// after every 15 sensors increment the step by 2 (e.g. ...EX_VAL15, EX_VAL16 = 17) to skip the device description
Expand All @@ -157,11 +174,22 @@ enum exSensors_e {
EX_GPS_SPEED,
EX_GPS_DISTANCE_TO_HOME,
EX_GPS_DIRECTION_TO_HOME,
//D2
EX_GPS_HEADING = 17,
EX_GPS_ALTITUDE,
EX_GFORCE_X,
EX_GFORCE_Y,
EX_GFORCE_Z
EX_GFORCE_Z,
EX_HEADSPEED,
EX_TAILSPEED,
EX_ARMING_FLAGS,
EX_PID_PROFILE,
EX_RATES_PROFILE,
EX_GOVERNOR_MODE,
EX_THROTTLE_CONTROL,
EX_ADJFUNC,
EX_ADJVALUE,
EX_ESCTEMP,
};

union{
Expand Down Expand Up @@ -267,6 +295,22 @@ void initJetiExBusTelemetry(void)

enableGpsTelemetry(featureIsEnabled(FEATURE_GPS));


bitArraySet(&exSensorEnabled, EX_HEADSPEED);
bitArraySet(&exSensorEnabled, EX_TAILSPEED);
bitArraySet(&exSensorEnabled, EX_ARMING_FLAGS);
bitArraySet(&exSensorEnabled, EX_PID_PROFILE);
bitArraySet(&exSensorEnabled, EX_RATES_PROFILE);
bitArraySet(&exSensorEnabled, EX_GOVERNOR_MODE);
bitArraySet(&exSensorEnabled, EX_THROTTLE_CONTROL);
bitArraySet(&exSensorEnabled, EX_ADJFUNC);
bitArraySet(&exSensorEnabled, EX_ADJVALUE);


#ifdef USE_ESC_SENSOR_TELEMETRY
bitArraySet(&exSensorEnabled, EX_ESCTEMP);
#endif

firstActiveSensor = getNextActiveSensor(0); // find the first active sensor
}

Expand Down Expand Up @@ -391,11 +435,78 @@ int32_t getSensorValue(uint8_t sensor)
break;
#endif

case EX_HEADSPEED:
return telemetrySensorValue(TELEM_HEADSPEED);
break;

case EX_TAILSPEED:
return telemetrySensorValue(TELEM_TAILSPEED);
break;

case EX_ARMING_FLAGS:
return telemetrySensorValue(TELEM_ARMING_FLAGS);
break;

case EX_PID_PROFILE:
return telemetrySensorValue(TELEM_PID_PROFILE);
break;

case EX_RATES_PROFILE:
return telemetrySensorValue(TELEM_RATES_PROFILE);
break;

case EX_GOVERNOR_MODE:
if (!ARMING_FLAG(ARMED)) {
if (isArmingDisabled())
return 100; //DISABLED
else
return 101; //DISAMED
} else {
/*
0, //"OFF",
1, //"IDLE",
2, // "SPOOLUP",
3, //"RECOVERY",
4, //"ACTIVE",
5, //"THR-OFF",
6, //"LOST-HS",
7, //"AUTOROT",
8, //"BAILOUT",
*/
return getGovernorState();
}
break;

case EX_THROTTLE_CONTROL:
return telemetrySensorValue(TELEM_THROTTLE_CONTROL);
break;

case EX_ADJFUNC:
return getAdjustmentsRangeFunc();
break;

case EX_ADJVALUE:
return getAdjustmentsRangeValue();
break;


#ifdef USE_ESC_SENSOR_TELEMETRY
case EX_ESCTEMP:
escData = getEscSensorData(0);
if (escData != NULL) {
return (escData->temperature);
}
return 0;
break;
#endif


default:
return -1;
}
}


uint8_t getNextActiveSensor(uint8_t currentSensor)
{
while( ++currentSensor < JETI_EX_SENSOR_COUNT) {
Expand Down

0 comments on commit ac113d2

Please sign in to comment.