Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bluetooth clients to position message #216

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions desktop_sim/desktop_hardware_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ bool hm_bleClientSend(int bleClientId, const uint8_t *data, uint16_t numBytes) {
CircularBuffer_s *hm_bleClientGetRxBuffer(int bleClientId) { return nullptr; }
void hm_bleTick() {}

uint8_t hm_bleGetAllClientsConnected(int chipId) {
// todo
return 0;
}

LineCutterData_s dummyData[2] = {{
.lineCutterNumber = 1,
},
Expand Down
9 changes: 9 additions & 0 deletions system/hardware_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,15 @@ bool hm_bleClientConnected(int bleClientId) {
return false;
}

uint8_t hm_bleGetAllClientsConnected(int chipId) {
#if HAS_DEV(BLE_CHIP_NRF)
if (IS_DEVICE(chipId, BLE_CHIP_NRF)) {
return bleChipNrf[chipId - FIRST_ID_BLE_CHIP_NRF].connectedClients;
}
#endif // HAS_DEV(BLE_CLIENT_STD)
return 0;
}

bool hm_bleClientSend(int bleClientId, const uint8_t *data, uint16_t numBytes) {
#if HAS_DEV(BLE_CLIENT_STD)
if (IS_DEVICE(bleClientId, BLE_CLIENT_STD)) {
Expand Down
1 change: 1 addition & 0 deletions system/hardware_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ CircularBuffer_s* hm_usbGetRxBuffer(int usbId);

/* Bluetooth functions */
bool hm_bleClientConnected(int bleClientId);
uint8_t hm_bleGetAllClientsConnected(int chipId);
bool hm_bleClientSend(int bleClientId, const uint8_t* data, uint16_t numBytes);
CircularBuffer_s* hm_bleClientGetRxBuffer(int bleClientId);

Expand Down
21 changes: 16 additions & 5 deletions system/tasks/radio_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void radioManager_transmitData(int radioId, SensorData_s *sensorData,
0,
#endif // HAS_DEV(GPS)
state,
0 // TODO bluetooth clients
hm_bleGetAllClientsConnected(FIRST_ID_BLE_CHIP_NRF)
};

transmitPacket[radioId].packetType = TELEMETRY_ID_POSITION;
Expand Down Expand Up @@ -214,8 +214,15 @@ void radioManager_transmitData(int radioId, SensorData_s *sensorData,
if (currentTime - lastSent[radioId].lineCutterLastSent >= 1000) {
for (int i = 0; i < NUM_LINE_CUTTER; i++) {
transmitPacket[radioId].packetType = TELEMETRY_ID_LINECUTTER;
transmitPacket[radioId].payload.lineCutter.data =
*hm_getLineCutterData(i);

// As long as we give the hardwaremanager a valid ID, we
// should be guaranteed a non-null pointer. That
// feels a bit sketch to me (Matt), but if it fails it'll
// fail right at boot
LineCutterData_s *data = hm_getLineCutterData(i);
transmitPacket[radioId].payload.lineCutter.data = *data;
transmitPacket[radioId].payload.lineCutter.bleId = i;

lastSent[radioId].lineCutterLastSent = currentTime;

radioManager_sendInternal(radioId);
Expand All @@ -225,8 +232,12 @@ void radioManager_transmitData(int radioId, SensorData_s *sensorData,
if (currentTime - lastSent[radioId].lineCutterVarsLastSent >= 10000) {
for (int i = 0; i < NUM_LINE_CUTTER; i++) {
transmitPacket[radioId].packetType = TELEMETRY_ID_LINECUTTER_VARS;
transmitPacket[radioId].payload.lineCutterFlightVars.data =
*hm_getLineCutterFlightVariables(i);

// See comment above
LineCutterFlightVars_s *data = hm_getLineCutterFlightVariables(i);
transmitPacket[radioId].payload.lineCutterFlightVars.data = *data;
transmitPacket[radioId].payload.lineCutterFlightVars.bleId = i;

lastSent[radioId].lineCutterVarsLastSent = currentTime;

radioManager_sendInternal(radioId);
Expand Down
17 changes: 13 additions & 4 deletions system/tasks/radio_packet_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ PACKED_STRUCT {
float temp, pos_z, vel_z, lat, lon, gps_alt, batt_volts, speedKnots,
courseDeg;
uint32_t gpsTime;
uint8_t sats, state, btClients;
// etc
uint8_t sats, state;

// bitfield showing ble clients connected to FCB
// TODO we don't really need this at 10hz do we? lol
uint8_t bleClients;
}
PositionPacket_s;

#define TELEMETRY_ID_LINECUTTER 4
PACKED_STRUCT { LineCutterData_s data; }
PACKED_STRUCT {
LineCutterData_s data;
uint8_t bleId;
}
LineCutterPacket_s;

// Uplinked string (not necessarily null-terminated)
Expand Down Expand Up @@ -74,7 +80,10 @@ PACKED_STRUCT {
HardwareStatusPacket_s;

#define TELEMETRY_ID_LINECUTTER_VARS 8
PACKED_STRUCT { LineCutterFlightVars_s data; }
PACKED_STRUCT {
LineCutterFlightVars_s data;
uint8_t bleId;
}
LineCutterVarsPacket_s;

typedef union {
Expand Down