2019-12-24 12:25:50 +01:00
|
|
|
ham_radio.digiline_effector_transmitter = function(pos, _, channel, msg)
|
|
|
|
-- static channels for transmitter
|
|
|
|
local command_channel = ham_radio.settings.digiline_channel
|
2019-12-08 18:07:18 +01:00
|
|
|
local rds_channel = ham_radio.settings.digiline_rds_channel
|
2019-12-08 00:29:27 +01:00
|
|
|
|
2019-12-08 18:07:18 +01:00
|
|
|
if channel ~= command_channel and channel ~= rds_channel then
|
2019-12-08 00:29:27 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
2019-12-08 18:07:18 +01:00
|
|
|
-- RDS channel - text message
|
|
|
|
if channel == rds_channel then
|
2019-12-08 15:48:36 +01:00
|
|
|
if type(msg) == "string" then
|
2019-12-08 18:07:18 +01:00
|
|
|
meta:set_string("rds_message", msg)
|
2019-12-08 15:48:36 +01:00
|
|
|
ham_radio.transmitter_update_infotext(meta)
|
|
|
|
ham_radio.save_transmitter(pos, meta)
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- command channel
|
|
|
|
|
|
|
|
if type(msg) ~= "table" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-12-08 00:29:27 +01:00
|
|
|
if msg.command == "get" then
|
2019-12-13 12:11:59 +01:00
|
|
|
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
|
2019-12-08 00:29:27 +01:00
|
|
|
frequency = meta:get_string("frequency"),
|
2019-12-08 18:07:18 +01:00
|
|
|
rds_message = meta:get_string("rds_message"),
|
2019-12-08 00:29:27 +01:00
|
|
|
})
|
|
|
|
|
2019-12-13 12:11:59 +01:00
|
|
|
elseif msg.command == "frequency" or msg.command == "set_frequency" then
|
2019-12-08 00:29:27 +01:00
|
|
|
local new_frequency = msg.value
|
2019-12-13 12:11:59 +01:00
|
|
|
local validate = ham_radio.validate_frequency(new_frequency)
|
|
|
|
if validate.result then
|
2019-12-08 00:29:27 +01:00
|
|
|
meta:set_string("frequency", new_frequency)
|
|
|
|
ham_radio.transmitter_update_infotext(meta)
|
|
|
|
ham_radio.save_transmitter(pos, meta)
|
|
|
|
end
|
2019-12-13 12:11:59 +01:00
|
|
|
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
|
|
|
|
update = 'frequency',
|
|
|
|
success = validate.result,
|
|
|
|
message = validate.message
|
|
|
|
})
|
2019-12-08 00:29:27 +01:00
|
|
|
|
2019-12-13 12:11:59 +01:00
|
|
|
elseif msg.command == "rds" or msg.command == "message" or msg.command == "rds_message" or msg.command == "set_rds_message" then
|
2019-12-08 18:07:18 +01:00
|
|
|
meta:set_string("rds_message", msg.value)
|
2019-12-08 00:29:27 +01:00
|
|
|
ham_radio.transmitter_update_infotext(meta)
|
|
|
|
ham_radio.save_transmitter(pos, meta)
|
2019-12-13 12:11:59 +01:00
|
|
|
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
|
|
|
|
update = 'rds_message',
|
|
|
|
success = true
|
|
|
|
})
|
2019-12-08 00:29:27 +01:00
|
|
|
end
|
2019-12-24 12:25:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
ham_radio.digiline_effector_receiver = function(pos, _, channel, msg)
|
|
|
|
-- static channel for receiver
|
|
|
|
local command_channel = ham_radio.settings.digiline_receiver_channel
|
|
|
|
|
|
|
|
if channel ~= command_channel or type(msg) ~= "table" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
|
|
|
if msg.command == "get" then
|
|
|
|
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
|
|
|
|
frequency = meta:get_string("frequency"),
|
|
|
|
rds_message = meta:get_string("rds_message"),
|
|
|
|
})
|
|
|
|
|
|
|
|
elseif msg.command == "frequency" or msg.command == "set_frequency" then
|
|
|
|
local new_frequency = msg.value
|
|
|
|
local validate = ham_radio.validate_frequency(new_frequency, true)
|
|
|
|
if validate.result then
|
|
|
|
meta:set_string("frequency", new_frequency)
|
|
|
|
end
|
|
|
|
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
|
|
|
|
update = 'frequency',
|
|
|
|
success = validate.result,
|
|
|
|
message = validate.message
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-12-08 00:29:27 +01:00
|
|
|
end
|