Skip to content

Commit 7f8ce52

Browse files
committed
fix: improve firmware version parsing in OnFirmwareVersionQuery function
1 parent aa98867 commit 7f8ce52

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/tools/livox_scan.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,26 @@ static void OnFirmwareVersionQuery(livox_status status,
173173
void* /*client_data*/) {
174174
DeviceEntry* dev = FindDeviceByHandle(handle);
175175

176-
if (dev) {
177-
if (status == kLivoxLidarStatusSuccess && response && response->ret_code == 0) {
178-
// Parse firmware version from response data
179-
// The format is typically a param_num followed by key-value pairs
180-
if (response->param_num > 0 && response->data[0]) {
181-
// Simple extraction - firmware version is typically a string
182-
dev->config.firmware_version = std::string(reinterpret_cast<const char*>(response->data));
176+
if (dev && status == kLivoxLidarStatusSuccess && response && response->ret_code == 0) {
177+
uint16_t off = 0;
178+
for (uint8_t i = 0; i < response->param_num; ++i) {
179+
LivoxLidarKeyValueParam* kv = reinterpret_cast<LivoxLidarKeyValueParam*>(&response->data[off]);
180+
if (kv->key == kKeyVersionApp && kv->length >= 4) {
181+
// version_app is uint8_t[4]: [major, minor, patch, build]
182+
char buf[32];
183+
snprintf(buf, sizeof(buf), "%u.%u.%u.%u",
184+
(uint8_t)kv->value[0], (uint8_t)kv->value[1],
185+
(uint8_t)kv->value[2], (uint8_t)kv->value[3]);
186+
dev->config.firmware_version = buf;
187+
break;
183188
}
189+
off += sizeof(uint16_t) * 2 + kv->length;
184190
}
185-
186191
std::cout << "[info] Firmware query response for " << dev->lidar_ip
187-
<< " (status=" << status << ")\n";
192+
<< ": " << dev->config.firmware_version << "\n";
188193
}
189194

190195
g_scan.pending_queries--;
191-
std::cout << "[info] Pending queries: " << g_scan.pending_queries.load() << "\n";
192196
}
193197

194198
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)