Skip to content

Commit 815a339

Browse files
Li-TianmingLi.Tianming
andauthored
MSP_OSD code changes to support OpenIPC, DJI O3/O4 OSD rendering (#24695)
* Change MSP_OSD message content and rendering process * Finish MSP_OSD battery message construct * Finish MSP_OSD `display message` construct HOL|DSAM|N * Finish MSP_FC_VARIANT(0x02) message BTFL * Finish MSP_OSD RSSI message 📶10% * Finish MSP_OSD GPS message 🛰 10 🌐000.000000 🌐00.000000 * Finish MSP_OSD PITCH ROLL message 🔃-10.5 🔁13.2 * Change struct filed name * Change OSD message postion * Finish MSP_OSD PITCH Altitude message 🔝15.2 * Finish MSP_OSD distanceToHome message 🏠5000 * Add Hide/Show option for ALT and homeDist * Format the code by `make format` * Clean up stray text * Remove other commented out dead code * Change `sprintf()` to `snprintf()` * Add msg field comment in `display_message` construct * Init str buffer to 0, Change refresh rate back to 100ms * Explicit conversion float to double --------- Co-authored-by: Li.Tianming <Li.Tianming@example.com> Co-authored-by: Li.Tianming <Li.Tianming>
1 parent 38548de commit 815a339

9 files changed

Lines changed: 428 additions & 51 deletions

File tree

boards/hkust/nxt-dual/default.px4board

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CONFIG_COMMON_DIFFERENTIAL_PRESSURE=y
1717
CONFIG_COMMON_DISTANCE_SENSOR=y
1818
CONFIG_DRIVERS_DSHOT=y
1919
CONFIG_DRIVERS_GPS=y
20+
CONFIG_DRIVERS_OSD_MSP_OSD=y
2021
CONFIG_DRIVERS_IMU_BOSCH_BMI088=y
2122
CONFIG_DRIVERS_IRLOCK=y
2223
CONFIG_COMMON_LIGHT=y

src/drivers/osd/msp_osd/MessageDisplay/MessageDisplay.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ void MessageDisplay::set(const MessageDisplayType mode, const char *string)
5656
if (strcmp(flight_mode_msg, string) != 0) {
5757
flight_mode_msg[MSG_BUFFER_SIZE - 1] = '\0';
5858
strncpy(flight_mode_msg, string, MSG_BUFFER_SIZE - 1);
59+
60+
for (int i = 0; i < (MSG_BUFFER_SIZE - 1); ++i) {
61+
if (flight_mode_msg[i] >= 'a' && flight_mode_msg[i] <= 'z') {
62+
flight_mode_msg[i] = flight_mode_msg[i] - 32; // toupper
63+
}
64+
}
65+
5966
updated_ = true;
6067
}
6168

src/drivers/osd/msp_osd/MspV1.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,32 @@ bool MspV1::Send(const uint8_t message_id, const void *payload)
107107

108108
packet[0] = '$';
109109
packet[1] = 'M';
110-
packet[2] = '<';
110+
packet[2] = '>';
111+
packet[3] = payload_size;
112+
packet[4] = message_id;
113+
114+
crc = payload_size ^ message_id;
115+
116+
memcpy(packet + MSP_FRAME_START_SIZE, payload, payload_size);
117+
118+
for (uint32_t i = 0; i < payload_size; i ++) {
119+
crc ^= packet[MSP_FRAME_START_SIZE + i];
120+
}
121+
122+
packet[MSP_FRAME_START_SIZE + payload_size] = crc;
123+
124+
int packet_size = MSP_FRAME_START_SIZE + payload_size + MSP_CRC_SIZE;
125+
return write(_fd, packet, packet_size) == packet_size;
126+
}
127+
128+
bool MspV1::Send(const uint8_t message_id, const void *payload, uint32_t payload_size)
129+
{
130+
uint8_t packet[MSP_FRAME_START_SIZE + payload_size + MSP_CRC_SIZE];
131+
uint8_t crc;
132+
133+
packet[0] = '$';
134+
packet[1] = 'M';
135+
packet[2] = '>';
111136
packet[3] = payload_size;
112137
packet[4] = message_id;
113138

src/drivers/osd/msp_osd/MspV1.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MspV1
3939
MspV1(int fd);
4040
int GetMessageSize(int message_type);
4141
bool Send(const uint8_t message_id, const void *payload);
42+
bool Send(const uint8_t message_id, const void *payload, uint32_t payload_size);
4243

4344
private:
4445
int _fd{-1};

src/drivers/osd/msp_osd/msp_defines.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#define MSP_MODE_TURNASSIST 27
112112
#define MSP_MODE_NAVLAUNCH 28
113113
#define MSP_MODE_AUTOTRIM 29
114+
#define MSP_CMD_DISPLAYPORT 182
114115

115116
struct msp_esc_sensor_data_t {
116117
uint8_t motor_count;
@@ -288,6 +289,25 @@ struct msp_attitude_t {
288289
int16_t yaw;
289290
} __attribute__((packed));
290291

292+
struct msp_rendor_pitch_t {
293+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
294+
uint8_t screenYPosition;
295+
uint8_t screenXPosition;
296+
uint8_t iconAttrs = 0x00;
297+
uint8_t iconIndex = 0x15; //PITCH icon
298+
299+
char str[6]; // -00.0
300+
} __attribute__((packed));
301+
302+
struct msp_rendor_roll_t {
303+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
304+
uint8_t screenYPosition;
305+
uint8_t screenXPosition;
306+
uint8_t iconAttrs = 0x00;
307+
uint8_t iconIndex = 0x14; //ROLL icon
308+
309+
char str[6]; // -00.0
310+
} __attribute__((packed));
291311

292312
// MSP_ALTITUDE reply
293313
struct msp_altitude_t {
@@ -297,6 +317,17 @@ struct msp_altitude_t {
297317
} __attribute__((packed));
298318

299319

320+
struct msp_rendor_altitude_t {
321+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
322+
uint8_t screenYPosition;
323+
uint8_t screenXPosition;
324+
uint8_t iconAttrs = 0x00;
325+
uint8_t iconIndex = 0x7F; //ALT icon
326+
327+
char str[8]; // -0000.0 // 9999.9 meter
328+
} __attribute__((packed));
329+
330+
300331
// MSP_SONAR_ALTITUDE reply
301332
struct msp_sonar_altitude_t {
302333
int32_t altitude;
@@ -311,6 +342,16 @@ struct msp_analog_t {
311342
int16_t amperage; // send amperage in 0.01 A steps, range is -320A to 320A
312343
} __attribute__((packed));
313344

345+
struct msp_rendor_rssi_t {
346+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
347+
uint8_t screenYPosition;
348+
uint8_t screenXPosition;
349+
uint8_t iconAttrs = 0x00;
350+
uint8_t iconIndex = 0x01; //RSSI icon
351+
352+
char str[4]; // 100%
353+
} __attribute__((packed));
354+
314355

315356
// MSP_ARMING_CONFIG reply
316357
struct msp_arming_config_t {
@@ -392,6 +433,38 @@ struct msp_raw_gps_t {
392433
uint16_t hdop;
393434
} __attribute__((packed));
394435

436+
struct msp_rendor_latitude_t {
437+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
438+
uint8_t screenYPosition;
439+
uint8_t screenXPosition;
440+
uint8_t iconAttrs = 0x00;
441+
uint8_t iconIndex = 0x89; //LAT icon
442+
443+
char str[11]; // -00.0000000
444+
} __attribute__((packed));
445+
446+
447+
struct msp_rendor_longitude_t {
448+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
449+
uint8_t screenYPosition;
450+
uint8_t screenXPosition;
451+
uint8_t iconAttrs = 0x00;
452+
uint8_t iconIndex = 0x98; //LON icon
453+
454+
char str[12]; // -000.0000000
455+
} __attribute__((packed));
456+
457+
struct msp_rendor_satellites_used_t {
458+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
459+
uint8_t screenYPosition;
460+
uint8_t screenXPosition;
461+
uint8_t iconAttrs = 0x00;
462+
uint8_t iconIndex = 0x1E; //satellites icon
463+
uint8_t iconIndex2 = 0x1F; //satellites icon
464+
465+
char str[2]; // 99
466+
} __attribute__((packed));
467+
395468

396469
// MSP_COMP_GPS reply
397470
struct msp_comp_gps_t {
@@ -400,6 +473,16 @@ struct msp_comp_gps_t {
400473
uint8_t heartbeat; // toggles 0 and 1 for each change
401474
} __attribute__((packed));
402475

476+
struct msp_rendor_distanceToHome_t {
477+
uint8_t subCommand = 0x03; // 0x03 subcommand write string. fixed
478+
uint8_t screenYPosition;
479+
uint8_t screenXPosition;
480+
uint8_t iconAttrs = 0x00; //
481+
uint8_t iconIndex = 0x71; //distanceToHome icon
482+
483+
char str[6]; // 65536
484+
} __attribute__((packed));
485+
403486

404487
// values for msp_nav_status_t.mode
405488
#define MSP_NAV_STATUS_MODE_NONE 0
@@ -788,6 +871,15 @@ struct msp_battery_state_t {
788871
uint16_t batteryVoltage;
789872
} __attribute__((packed));
790873

874+
struct msp_rendor_battery_state_t {
875+
uint8_t subCommand; // 0x03 write string. fixed
876+
uint8_t screenYPosition;
877+
uint8_t screenXPosition;
878+
uint8_t iconAttrs;
879+
uint8_t iconIndex;
880+
char str[5];
881+
} __attribute__((packed));
882+
791883
// MSP_STATUS reply customized for BF/DJI
792884
struct msp_status_BF_t {
793885
uint16_t task_delta_time;

0 commit comments

Comments
 (0)