Skip to content

Commit dae0084

Browse files
committed
AP_Scripting: use pcall to wrap CPSI parsing
cope better with serial corruption
1 parent ab7b02b commit dae0084

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

libraries/AP_Scripting/drivers/LTE_modem.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,11 @@ local function check_CPSI(s)
11211121
local system_mode, operation_mode, mcc_mnc, tac_str, scell_id_str, pcid_str, earfcn_band, ul_freq_str, dl_freq_str, tdd_cfg_str, rsrq_str, rsrp_str, rssi_str, sinr_str =
11221122
s:match("+CPSI:%s*([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([%-]?%d+),([%-]?%d+),([%-]?%d+),([%-]?%d+)")
11231123

1124-
if system_mode and sinr_str then
1124+
if not system_mode or not sinr_str then
1125+
return false
1126+
end
1127+
1128+
local ok, err = pcall(function()
11251129
-- Convert strings to numbers
11261130
local tac = tonumber(tac_str:match("0x(%w+)"), 16) or tonumber(tac_str) or 0
11271131
local scell_id = tonumber(scell_id_str) or 0
@@ -1148,9 +1152,12 @@ local function check_CPSI(s)
11481152
gcs:send_named_float('LTE_MCCMNC', mcc*100+mnc)
11491153
end
11501154
end
1151-
return true
1155+
end)
1156+
if not ok then
1157+
gcs:send_text(MAV_SEVERITY.INFO, "LTE: CPSI parse error: " .. tostring(err))
1158+
return false
11521159
end
1153-
return false
1160+
return true
11541161
end
11551162

11561163
--[[

0 commit comments

Comments
 (0)