Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions libraries/AP_Scripting/applets/BatteryTag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ if BTAG_ENABLE:get() == 0 then
end

-- a handle for receiving BatteryTag messages
local batterytag_handle = DroneCAN_Handle(0, BATTERYTAG_SIGNATURE, BATTERYTAG_ID)
batterytag_handle:subscribe()
local batterytag_handles = {
DroneCAN_Handle(0, BATTERYTAG_SIGNATURE, BATTERYTAG_ID),
DroneCAN_Handle(1, BATTERYTAG_SIGNATURE, BATTERYTAG_ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this holds us until someone uses a three-interface device :-)

}
for bus, _ in pairs(batterytag_handles) do
batterytag_handles[bus]:subscribe()
end

-- a handle for sending GlobalTime messages
local globaltime_handle = DroneCAN_Handle(0, GLOBALTIME_SIGNATURE, GLOBALTIME_ID)
local globaltime_handles = {
DroneCAN_Handle(0, GLOBALTIME_SIGNATURE, GLOBALTIME_ID),
DroneCAN_Handle(1, GLOBALTIME_SIGNATURE, GLOBALTIME_ID)
}

-- ID for an arming check
local auth_id = arming:get_aux_auth_id()
Expand All @@ -76,8 +84,8 @@ local GCS_REPORT_TIME_S = 30
--[[
check for BatteryTag messages
--]]
local function check_batterytag()
local payload, nodeid = batterytag_handle:check_message()
local function check_batterytag(bus)
local payload, nodeid = batterytag_handles[bus]:check_message()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here if there is only 1 bus?

if not payload then
return
end
Expand All @@ -90,10 +98,11 @@ local function check_batterytag()
highest_cycles = num_cycles
BTAG_CUR_CYCLES:set_and_save(highest_cycles)
end
if not node_cycles[nodeid] then
gcs:send_text(MAV_SEVERITY.INFO, string.format("BatteryTag: Node %d, Cycles %d", nodeid, num_cycles))
local node_tag = string.format("%d:%d", bus, nodeid)
if not node_cycles[node_tag] then
gcs:send_text(MAV_SEVERITY.INFO, string.format("BatteryTag: Node %s, Cycles %d", node_tag, num_cycles))
end
node_cycles[nodeid] = num_cycles
node_cycles[node_tag] = num_cycles

-- log battery information
logger:write("BTAG",
Expand Down Expand Up @@ -137,7 +146,9 @@ local function check_globaltime()
local usec_hi,usec_lo = utc_usec:split()
local payload8 = string.pack("II", usec_lo:toint(), usec_hi:toint())
local payload7 = string.sub(payload8, 1, 7)
globaltime_handle:broadcast(payload7)
for bus, _ in pairs(globaltime_handles) do
globaltime_handles[bus]:broadcast(payload7)
end
end

--[[
Expand All @@ -154,15 +165,17 @@ local function check_GCS()
then
-- report battery tags at GCS_REPORT_TIME_S seconds
sent_report = true
for nodeid, cycles in pairs(node_cycles) do
gcs:send_text(MAV_SEVERITY.INFO, string.format("BatteryTag: Node %d, Cycles %d", nodeid, cycles))
for node_tag, cycles in pairs(node_cycles) do
gcs:send_text(MAV_SEVERITY.INFO, string.format("BatteryTag: Node %s, Cycles %d", node_tag, cycles))
end
end
end

local function update()
if BTAG_ENABLE:get() ~= 0 then
check_batterytag()
for bus, _ in pairs(batterytag_handles) do
check_batterytag(bus)
end
check_globaltime()
check_GCS()
end
Expand Down
Loading