CANopen diagnostics and map data over HTTPS: /can.html (interfaces, nodes with heartbeat state and last EMCY, decoded signals, every COB-ID with role, count, rate and last data); signals can mark an invalid raw value (esphome-canopen's unknown) and NaN gives no value; the CAN reader never dies and a broken can.json only turns CAN off; the GNSS node mcu-stm32-xiao-c5-2 (0x21) and host networking for the car's server in docs; bin/pull-maps.sh pulls map data from GET /api/sync/maps(/file) with SYNC_TOKEN instead of rsync over SSH, resuming cut-off downloads
This commit is contained in:
1 parent
a3e5fefaf1
commit
6a0d6194fe
9 files changed
+365
-43
No files matched your search
+15
-1
@@ -144,6 +144,20 @@ class AppTest < Minitest::Test
|
||||
assert_equal 401, request.get("/api/sync/source/x").status
|
||||
assert_equal 401, request.post("/api/sync/apply", input: "{}").status
|
||||
assert_equal 401, request.put("/api/sync/source/x", input: "x").status
|
||||
assert_equal 401, request.get("/api/sync/maps", **logged_in_env).status
|
||||
assert_equal 401, request.get("/api/sync/maps/file", params: { "path" => "offline.pmtiles" }).status
|
||||
end
|
||||
|
||||
def test_map_data_offered_to_clients_is_only_the_map_files
|
||||
data = Maptool::App::DATA_DIR
|
||||
files = %w[terrain.pmtiles places/SK.sqlite places/.rsync-partial/SK.sqlite routing/tiles.tar.part routing/service.sh can.json]
|
||||
files.each { |f| FileUtils.mkdir_p(File.dirname(File.join(data, f))); File.write(File.join(data, f), "x") }
|
||||
offered = Maptool::App.map_sync_files
|
||||
assert_includes offered.keys, "terrain.pmtiles"
|
||||
assert_includes offered.keys, "places/SK.sqlite"
|
||||
refute(offered.keys.any? { |f| f.include?(".rsync-partial") || f.end_with?(".part") || %w[can.json routing/service.sh].include?(f) })
|
||||
ensure
|
||||
files.each { |f| FileUtils.rm_f(File.join(data, f)) }
|
||||
end
|
||||
|
||||
def test_the_sync_button_is_only_a_clients
|
||||
@@ -154,7 +168,7 @@ class AppTest < Minitest::Test
|
||||
|
||||
def test_can_requires_login_and_is_off_without_a_config
|
||||
assert_equal 401, request.get("/api/can").status
|
||||
assert_equal({ "interfaces" => {}, "nodes" => {}, "signals" => {}, "available" => false }, json_body(request.get("/api/can", **logged_in_env)))
|
||||
assert_equal({ "interfaces" => {}, "nodes" => {}, "signals" => {}, "frames" => [], "available" => false }, json_body(request.get("/api/can", **logged_in_env)))
|
||||
end
|
||||
|
||||
# MQTT messages land in the tracker / ITS-G5 parts of /api/live.
|
||||
|
||||
@@ -42,6 +42,12 @@ class CanTest < Minitest::Test
|
||||
assert_empty decoder.decode(Frame.new(0x0F1, "\0\0\0\0\0".b, false))
|
||||
assert_in_delta(-15.0, decoder.decode(Frame.new(0x281, [250].pack("s<"), false))["temp"])
|
||||
assert_empty decoder.decode(Frame.new(0x181, "\x01".b, false)), "too short for the i32s"
|
||||
# esphome-canopen's Sensor16 (min..max over 0..65534, 65535 unknown) and a NaN float: no value.
|
||||
alt = Maptool::Can::Decoder.new([{ "name" => "alt", "id" => "0x4A1", "type" => "u16", "scale" => 9500.0 / 65534, "offset" => -500, "invalid" => 65535 },
|
||||
{ "name" => "lat", "id" => "0x3A1", "type" => "f32" }])
|
||||
assert_in_delta 9000, alt.decode(Frame.new(0x4A1, [65534].pack("S<"), false))["alt"], 1e-6
|
||||
assert_empty alt.decode(Frame.new(0x4A1, [65535].pack("S<"), false))
|
||||
assert_empty alt.decode(Frame.new(0x3A1, [Float::NAN].pack("e"), false))
|
||||
assert_raises(ArgumentError) { Maptool::Can::Decoder.new([{ "name" => "x", "id" => 1, "type" => "u64" }]) }
|
||||
end
|
||||
|
||||
@@ -53,6 +59,13 @@ class CanTest < Minitest::Test
|
||||
assert_equal({ frames: 2, last_frame_at: 2.0 }, snapshot[:interfaces]["vcan0"])
|
||||
assert_equal({ seen_at: 1.0, state: "operational" }, snapshot[:nodes][5])
|
||||
assert_equal({ value: 49.1, at: 2.0 }, snapshot[:signals]["gnss.lat"])
|
||||
|
||||
store.record("vcan0", Frame.new(0x181, "".b, false), {}, at: 2.5)
|
||||
store.record("vcan0", Frame.new(0x085, [0x8130, 0x11].pack("S<C"), false), {}, at: 3.0)
|
||||
snapshot = store.snapshot
|
||||
tpdo = snapshot[:frames].find { |f| f[:id] == 0x181 }
|
||||
assert_equal [:tpdo1, 1, 2, 0.5], tpdo.values_at(:role, :node, :count, :interval)
|
||||
assert_equal({ code: 0x8130, register: 0x11, at: 3.0 }, snapshot[:nodes][5][:emcy])
|
||||
end
|
||||
|
||||
# Over a real SocketCAN interface when there is one:
|
||||
|
||||
Reference in new issue
Block a user