Skip to content

Commit 48d7a52

Browse files
committed
fix msgbroker
1 parent f94232c commit 48d7a52

File tree

7 files changed

+27
-32
lines changed

7 files changed

+27
-32
lines changed

platformio.ini

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
;default_envs = ESP32-S3
1818
;default_envs = RP2040
1919
;default_envs = RP2350A
20-
;default_envs = RP2350B
20+
default_envs = RP2350B
2121
;default_envs = STM32F411
2222

2323
[env]
@@ -63,15 +63,14 @@ build_flags =
6363
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
6464
framework = arduino
6565
board_build.core = earlephilhower
66-
; Enable FreeRTOS & TinyUSB
6766
build_flags =
68-
-D PIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS
69-
-D USE_TINYUSB
70-
; Use a recent arduino-pico version (the version included in maxgerhardt/platform-raspberrypi is lagging behind arduino-pico releases)
71-
; Note: a fixed version is used here, not #master, to prevent long downloads each time the source repository is updated
67+
-D PIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS ; Required: Enable FreeRTOS
68+
; -D USE_TINYUSB ; Optional but not recommended: It adds USB SDCARD mass storage, but USB Serial does not work nicely with USE_TINYUSB
69+
70+
; Use arduino-pico version 5 or later. A fixed version is used here, not #master, to prevent long downloads each time the source repository is updated
7271
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#5.5.0
7372

74-
;optional Debugprobe debugger - see Appendix A "Getting started with Raspberry Pi Pico-series"
73+
; Optional: Debugprobe debugger - see Appendix A "Getting started with Raspberry Pi Pico-series"
7574
;debug_tool = cmsis-dap
7675
;upload_protocol = cmsis-dap
7776
;debug_speed = 30000

src/cli/msp/private/MspProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ void MspProcessor::processCommand(MspMessage& m, MspResponse& r)
468468
r.writeU16(lrintf(imu.gx * 4)); //deg/s / 4
469469
r.writeU16(lrintf(imu.gy * 4));
470470
r.writeU16(lrintf(imu.gz * 4));
471-
r.writeU16(lrintf(mag.mx * 100)); //dimensionless in BF with scale options 100 to 10000
472-
r.writeU16(lrintf(mag.my * 100));
473-
r.writeU16(lrintf(mag.mz * 100));
471+
r.writeU16(lrintf(mag.mx * 10)); //dimensionless in BF with scale options 100 to 10000
472+
r.writeU16(lrintf(mag.my * 10));
473+
r.writeU16(lrintf(mag.mz * 10));
474474
break;
475475
}
476476

src/gps/gps.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ struct GpsState {
7070
bool have_undulation = false; // do we have a value for the undulation
7171
};
7272

73-
extern MsgTopic<GpsState> gps_topic;
74-
7573
struct GpsConfig {
7674
public:
7775
Cfg::gps_gizmo_enum gizmo = Cfg::gps_gizmo_enum::mf_NONE; //the gizmo to use

src/tbx/MsgBroker.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ void MsgBroker::top() {
5555
for(int i = 0; i < MF_MSGTOPIC_LIST_SIZE; i++) {
5656
MsgTopicBase *t = topic_list[i];
5757
if(t) {
58-
Serial.printf("topic:%-12s freq:%4.0fHz gen:%8d subscribers:%d\n", t->name.c_str(), t->generation / dt, (int)t->generation, t->subscriber_count());
58+
Serial.printf("topic:%-12s freq:%4.0fHz gen:%8d subscribers:%d\n", t->name, t->generation / dt, (int)t->generation, t->subscriber_count());
5959
for(int j = 0; j < MF_MSGSUB_LIST_SIZE; j++) {
6060
MsgSubscriptionBase *s = t->sub_list[j];
61-
if(s) Serial.printf(" sub:%-10s freq:%4.0fHz gen:%8d pulls:%8d missed:%8d\n", s->name.c_str(), s->pull_cnt / dt, (int)s->generation, (int)s->pull_cnt, (int)(t->generation - s->pull_cnt));
61+
if(s) Serial.printf(" sub:%-10s freq:%4.0fHz gen:%8d pulls:%8d missed:%8d\n", s->name, s->pull_cnt / dt, (int)s->generation, (int)s->pull_cnt, (int)(t->generation - s->pull_cnt));
6262
}
6363
}
6464
}
@@ -76,9 +76,9 @@ void MsgBroker::reset_stats() {
7676
//=============================================================================
7777
// MsgTopicBase
7878
//=============================================================================
79-
MsgTopicBase::MsgTopicBase(String name, int len) {
80-
Serial.printf("cr topic %s %d\n",name.c_str(),len);Serial.flush();
81-
this->name = name;
79+
MsgTopicBase::MsgTopicBase(const char *name, int len) {
80+
strncpy(this->name, name, sizeof(this->name) - 1);
81+
this->name[sizeof(this->name) - 1] = 0;
8282
queue = xQueueCreate(1, len);
8383
MsgBroker::add_topic(this);
8484
}
@@ -95,7 +95,6 @@ void MsgTopicBase::publishFromISR(void *msg) {
9595
generation++;
9696
}
9797

98-
9998
bool MsgTopicBase::pull(void *msg) {
10099
return (xQueuePeek(queue, msg, 0) == pdPASS);
101100
}
@@ -135,8 +134,9 @@ bool MsgSubscriptionBase::updated() {
135134
return (generation != topic->generation);
136135
}
137136

138-
MsgSubscriptionBase::MsgSubscriptionBase(String name, MsgTopicBase *topic) : topic{topic} {
139-
this->name = name;
137+
MsgSubscriptionBase::MsgSubscriptionBase(const char *name, MsgTopicBase *topic) : topic{topic} {
138+
strncpy(this->name, name, sizeof(this->name) - 1);
139+
this->name[sizeof(this->name) - 1] = 0;
140140
topic->add_subscription(this);
141141
}
142142

src/tbx/MsgBroker.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ SOFTWARE.
3131
#define MF_MSGSUB_LIST_SIZE 8 //max number of subscribers per topic. Used only for top() statistics
3232
#endif
3333

34-
#include <Arduino.h> //String
3534
#include "../hal/hal.h" //STM32 FreeRTOS
3635

3736
class MsgBroker;
@@ -65,11 +64,11 @@ class MsgTopicBase {
6564
friend class MsgBroker;
6665
friend class MsgSubscriptionBase;
6766

68-
String name;
67+
char name[9] = {};
6968
uint32_t generation = 0; //counts messages published to this topic
7069
MsgSubscriptionBase* sub_list[MF_MSGSUB_LIST_SIZE] = {};
7170

72-
MsgTopicBase(String name, int len);
71+
MsgTopicBase(const char* name, int len);
7372
void publish(void *msg);
7473
void publishFromISR(void *msg);
7574
bool pull(void *msg);
@@ -90,11 +89,11 @@ class MsgSubscriptionBase {
9089
friend class MsgBroker;
9190
template <class T> friend class MsgSubscription;
9291

93-
String name;
92+
char name[9] = {};
9493
uint32_t generation = 0; //last pulled topic generation
9594
uint32_t pull_cnt = 0; //pull counter
9695

97-
MsgSubscriptionBase(String name, MsgTopicBase *topic); //start a new subscription
96+
MsgSubscriptionBase(const char* name, MsgTopicBase *topic); //start a new subscription
9897
virtual ~MsgSubscriptionBase();
9998
bool pull(void *msg); //pull message: returns true if msg was pulled, returns false if no msg available
10099
bool pull_updated(void *msg); //pull updated message: returns true when updated msg available, else returns false and does not update msg
@@ -107,7 +106,7 @@ class MsgSubscriptionBase {
107106
template <class T>
108107
class MsgTopic : public MsgTopicBase {
109108
public:
110-
MsgTopic(String name) : MsgTopicBase(name, sizeof(T)) {}
109+
MsgTopic(const char* name) : MsgTopicBase(name, sizeof(T)) {}
111110
void publish(T *msg) { MsgTopicBase::publish(msg); }
112111
void publishFromISR(T *msg) { MsgTopicBase::publishFromISR(msg); }
113112
protected:
@@ -118,7 +117,7 @@ class MsgTopic : public MsgTopicBase {
118117
template <class T>
119118
class MsgSubscription : public MsgSubscriptionBase {
120119
public:
121-
MsgSubscription(String name, MsgTopic<T> *topic) : MsgSubscriptionBase(name, topic) {}
120+
MsgSubscription(const char* name, MsgTopic<T> *topic) : MsgSubscriptionBase(name, topic) {}
122121
bool pull(T *msg) { return MsgSubscriptionBase::pull(msg); }
123122
bool pull_updated(T *msg) { return MsgSubscriptionBase::pull_updated(msg); }
124123
};

src/veh/veh.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ SOFTWARE.
2929
#include "veh.h"
3030
#include "../bbx/bbx.h"
3131

32-
//global module class instance and topic
32+
//global module class instance
3333
Veh veh;
34-
MsgTopic<VehState> veh_topic = MsgTopic<VehState>("veh");
3534

3635
//returns true if flightmode changed
3736
bool Veh::setFlightmode(uint8_t flightmode) {
3837
if(_flightmode == flightmode) return false;
3938
_flightmode = flightmode;
40-
veh_topic.publish(this);
39+
topic.publish(this);
4140
bbx.log_mode();
4241
return true;
4342
}

src/veh/veh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ struct VehState {
138138
uint8_t _flightmode = 0; //current flight mode index
139139
};
140140

141-
extern MsgTopic<VehState> veh_topic;
142-
143141
class Veh : public VehState {
144142
public:
143+
MsgTopic<VehState> topic = MsgTopic<VehState>("veh");
144+
145145
static const uint8_t mav_type; //mavlink vehicle type
146146
static const uint8_t flightmode_ap_ids[6]; //mapping from flightmode to ArduPilot flight mode id
147147
static const char* flightmode_names[6]; //define flightmode name strings for telemetry

0 commit comments

Comments
 (0)