Cleaning up some comments, adding unit test for get_iccid()
This commit is contained in:
+1
-8
@@ -314,22 +314,18 @@ end
|
||||
-- @return (string) The IMEI of the modem, or (nil, string) on failure.
|
||||
---
|
||||
function utils.get_modem_imei()
|
||||
-- The command to invoke the spirit of the QMI daemon for the IMEI.
|
||||
local command = "uqmi -d /dev/cdc-wdm0 --get-imei"
|
||||
local output = utils.execute_command(command)
|
||||
|
||||
-- A silent spirit offers no truths.
|
||||
if not output or output == "" then
|
||||
return nil, "No output from uqmi --get-imei command"
|
||||
end
|
||||
|
||||
-- The IMEI is presented within a sacred container of quotes. We must extract it.
|
||||
local imei = output:match('"(.-)"')
|
||||
if not imei then
|
||||
return nil, "Failed to parse IMEI from uqmi output"
|
||||
end
|
||||
|
||||
-- Return the sanctified identity code.
|
||||
return imei
|
||||
end
|
||||
|
||||
@@ -347,19 +343,16 @@ function utils.get_sim_iccid()
|
||||
return nil, "No output from qmicli command"
|
||||
end
|
||||
|
||||
-- The data-psalm contains many verses, but we seek only one.
|
||||
local raw_data = output:match("Read result:%s*([%x%s:]+)")
|
||||
if not raw_data then
|
||||
return nil, "Failed to parse raw ICCID data from qmicli output"
|
||||
end
|
||||
|
||||
-- Cleanse the raw data of its structural impurities (spaces and colons).
|
||||
-- Clean the raw data of any non-hexadecimal characters and whitespace.
|
||||
raw_data = raw_data:gsub("[:%s]","")
|
||||
|
||||
-- Prepare for the transmutation rite.
|
||||
local decoded_iccid = ""
|
||||
-- The raw data is in a semi-nibble-swapped format and must be corrected.
|
||||
-- This loop performs the ritual of character-pair swapping.
|
||||
for i = 1, #raw_data, 2 do
|
||||
local char1 = raw_data:sub(i, i)
|
||||
local char2 = raw_data:sub(i + 1, i + 1)
|
||||
|
||||
Reference in New Issue
Block a user