Skip to content

Commit a9b78a5

Browse files
committed
Implement flexible config req- & response- packages. See PR79 of open_mower_ros
1 parent 267df89 commit a9b78a5

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

Firmware/LowLevel/src/datatypes.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define PACKET_ID_LL_STATUS 1
2424
#define PACKET_ID_LL_IMU 2
2525
#define PACKET_ID_LL_UI_EVENT 3
26+
#define PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ 0x21 // ll_high_level_config and request config from receiver
27+
#define PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP 0x22 // ll_high_level_config response
2628
#define PACKET_ID_LL_HEARTBEAT 0x42
2729
#define PACKET_ID_LL_HIGH_LEVEL_STATE 0x43
2830

@@ -117,4 +119,23 @@ struct ll_ui_event {
117119
} __attribute__((packed));
118120
#pragma pack(pop)
119121

122+
#define LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION 1 // Max. comms packet version supported by this open_mower LL FW
123+
#define LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V 1 << 0 // Enable full sound via mower_config env var "OM_DFP_IS_5V"
124+
#define LL_HIGH_LEVEL_CONFIG_BIT_EMERGENCY_INVERSE 1 << 1 // Sample, for possible future usage, i.e. for SA-Type emergency
125+
126+
typedef char iso639_1[2]; // Two char ISO 639-1 language code
127+
128+
#pragma pack(push, 1)
129+
struct ll_high_level_config {
130+
uint8_t type;
131+
uint8_t comms_version = LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION; // Increasing comms packet-version number for packet compatibility (n > 0)
132+
uint8_t config_bitmask = 0; // See LL_HIGH_LEVEL_CONFIG_BIT_*
133+
int8_t volume; // Volume (0-100%) feedback (if directly changed via CoverUI)
134+
iso639_1 language; // ISO 639-1 (2-char) language code (en, de, ...)
135+
uint16_t spare1 = 0; // Spare for future use
136+
uint16_t spare2 = 0; // Spare for future use
137+
uint16_t crc;
138+
} __attribute__((packed));
139+
#pragma pack(pop)
140+
120141
#endif

Firmware/LowLevel/src/main.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ uint16_t ui_version = 0; // Last received UI firmware version
123123
uint8_t ui_topic_bitmask = Topic_set_leds; // UI subscription, default to Set_LEDs
124124
uint16_t ui_interval = 1000; // UI send msg (LED/State) interval (ms)
125125

126+
// Some vars related to PACKET_ID_LL_HIGH_LEVEL_CONFIG_*
127+
uint8_t comms_version = 0; // comms packet version (>0 if implemented)
128+
uint8_t config_bitmask = 0; // See LL_HIGH_LEVEL_CONFIG_BIT_*
129+
126130
void sendMessage(void *message, size_t size);
127131
void sendUIMessage(void *message, size_t size);
128132
void onPacketReceived(const uint8_t *buffer, size_t size);
@@ -556,6 +560,15 @@ void onUIPacketReceived(const uint8_t *buffer, size_t size) {
556560
}
557561
}
558562

563+
void sendConfigMessage(uint8_t pkt_type) {
564+
struct ll_high_level_config ll_config;
565+
ll_config.type = pkt_type;
566+
ll_config.config_bitmask = config_bitmask;
567+
ll_config.volume = 80; // FIXME: Adapt once nv_config or improve-sound got merged
568+
strcpy(ll_config.language, "en"); // FIXME: Adapt once nv_config or improve-sound got merged
569+
sendMessage(&ll_config, sizeof(struct ll_high_level_config));
570+
}
571+
559572
void onPacketReceived(const uint8_t *buffer, size_t size) {
560573
// sanity check for CRC to work (1 type, 1 data, 2 CRC)
561574
if (size < 4)
@@ -572,7 +585,6 @@ void onPacketReceived(const uint8_t *buffer, size_t size) {
572585

573586
// CRC and packet is OK, reset watchdog
574587
last_heartbeat_millis = millis();
575-
ROS_running = true;
576588
struct ll_heartbeat *heartbeat = (struct ll_heartbeat *) buffer;
577589
if (heartbeat->emergency_release_requested) {
578590
emergency_latch = false;
@@ -581,10 +593,31 @@ void onPacketReceived(const uint8_t *buffer, size_t size) {
581593
if (heartbeat->emergency_requested) {
582594
emergency_latch = true;
583595
}
596+
if (!ROS_running) {
597+
// ROS is running (again (i.e. due to restart after reconfiguration))
598+
ROS_running = true;
599+
600+
// Send current LL config (and request HL config response)
601+
sendConfigMessage(PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ);
602+
}
584603
} else if (buffer[0] == PACKET_ID_LL_HIGH_LEVEL_STATE && size == sizeof(struct ll_high_level_state)) {
585604
// copy the state
586605
last_high_level_state = *((struct ll_high_level_state *) buffer);
587606
}
607+
else if ((buffer[0] == PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ || buffer[0] == PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP) && size == sizeof(struct ll_high_level_config))
608+
{
609+
// Read and handle received config
610+
struct ll_high_level_config *pkt = (struct ll_high_level_config *)buffer;
611+
if (pkt->comms_version <= LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION)
612+
comms_version = pkt->comms_version;
613+
else
614+
comms_version = LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION;
615+
config_bitmask = pkt->config_bitmask; // Take over as sent. HL is leading (for now)
616+
// FIXME: Assign volume & language if not already stored in flash-config
617+
618+
if (buffer[0] == PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ)
619+
sendConfigMessage(PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP);
620+
}
588621
}
589622

590623
// returns true, if it's a good idea to charge the battery (current, voltages, ...)

0 commit comments

Comments
 (0)