2023-04-12 04:35:08 -03:00
|
|
|
local mavlink_msgs = require("mavlink/mavlink_msgs")
|
2023-04-05 04:09:10 -03:00
|
|
|
|
2023-04-12 04:35:08 -03:00
|
|
|
local msg_map = {}
|
2023-04-05 04:09:10 -03:00
|
|
|
|
2023-04-12 04:35:08 -03:00
|
|
|
local heartbeat_msgid = mavlink_msgs.get_msgid("HEARTBEAT")
|
2023-04-05 04:09:10 -03:00
|
|
|
|
|
|
|
msg_map[heartbeat_msgid] = "HEARTBEAT"
|
|
|
|
-- initialise mavlink rx with number of messages, and buffer depth
|
|
|
|
mavlink.init(1, 10)
|
|
|
|
-- register message id to receive
|
2023-05-14 03:01:57 -03:00
|
|
|
mavlink.register_rx_msgid(heartbeat_msgid)
|
2023-04-12 04:35:08 -03:00
|
|
|
local test_named_value = 0.0
|
2023-04-05 04:09:10 -03:00
|
|
|
function str_to_bytes(str)
|
2023-04-12 04:35:08 -03:00
|
|
|
local str_len = string.len(str)
|
|
|
|
local bytes = {}
|
2023-04-05 04:09:10 -03:00
|
|
|
for i = 1, str_len do
|
|
|
|
bytes[i] = string.byte(str, i)
|
|
|
|
end
|
|
|
|
return bytes
|
|
|
|
end
|
|
|
|
function update()
|
2023-05-03 06:45:13 -03:00
|
|
|
local msg,chan,timestamp_ms = mavlink.receive_chan()
|
2023-04-05 04:09:10 -03:00
|
|
|
if msg then
|
2023-06-20 18:32:56 -03:00
|
|
|
gcs:send_text(6, string.format("Received message on channel %d at %s", chan, tostring(timestamp_ms)))
|
2023-04-12 04:35:08 -03:00
|
|
|
local parsed_msg = mavlink_msgs.decode(msg, msg_map)
|
2023-04-05 04:09:10 -03:00
|
|
|
if parsed_msg.msgid == heartbeat_msgid then
|
|
|
|
gcs:send_text(6, string.format("Received heartbeat from %d", parsed_msg.sysid))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
gcs:send_text(6, "No heartbeat received")
|
|
|
|
end
|
|
|
|
test_named_value = test_named_value + 1.0
|
|
|
|
-- send named value float
|
2023-05-03 06:45:13 -03:00
|
|
|
mavlink.send_chan(0, mavlink_msgs.encode("NAMED_VALUE_FLOAT", {time_boot_ms = millis():toint(), name = str_to_bytes("test"), value = test_named_value}))
|
2023-04-05 04:09:10 -03:00
|
|
|
return update, 1000
|
|
|
|
end
|
|
|
|
|
|
|
|
return update()
|