@@ -123,6 +123,10 @@ uint16_t ui_version = 0; // Last received UI firmware version
123123uint8_t ui_topic_bitmask = Topic_set_leds; // UI subscription, default to Set_LEDs
124124uint16_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+
126130void sendMessage (void *message, size_t size);
127131void sendUIMessage (void *message, size_t size);
128132void 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+
559572void 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