From 5a09d3affc63feb942e2453ccfc4143726292501 Mon Sep 17 00:00:00 2001 From: Roman Bazalevsky Date: Tue, 31 Dec 2019 17:38:14 +0300 Subject: [PATCH 1/1] =?utf8?q?=D0=9F=D1=80=D0=BE=D0=B8=D0=B7=D0=B2=D0=BE?= =?utf8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?utf8?q?=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=80=D1=82=D0=B0=20?= =?utf8?q?=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0?= =?utf8?q?=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D0=BE=D0=BC=20=D1=84=D0=B0=D0=B9?= =?utf8?q?=D0=BB=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bin/weathermon-iio | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/bin/weathermon-iio b/bin/weathermon-iio index d288edf..dcbca64 100755 --- a/bin/weathermon-iio +++ b/bin/weathermon-iio @@ -116,6 +116,20 @@ function get_mhz(record) end +function search_rs232_const(rs232,prefix,value) + + for k,v in pairs(rs232) do + + if k == prefix..value:upper() then + return v + end + + end + + return nil + +end + function init_serial_device(device,subsystem,parameters) rs232 = require("luars232") @@ -123,24 +137,33 @@ function init_serial_device(device,subsystem,parameters) pcall(function () local e, port = rs232.open(device["port"]) - - if subsystem == "mhz" then + + local baud = device["baud"]; if baud == nil then baud = 9600; end + local bits = device["bits"]; if bits == nil then bits = 8; end + local stop_bits = device["stop_bits"]; if stop_bits == nil then stop_bits = 1; end + local parity = device["parity"]; if parity == nil then parity = "NONE"; end + local flowctl = device["flowctl"]; if flowctl == nil then flowctl = "OFF"; end - assert(port:set_baud_rate(rs232.RS232_BAUD_9600) == rs232.RS232_ERR_NOERROR) - assert(port:set_data_bits(rs232.RS232_DATA_8) == rs232.RS232_ERR_NOERROR) - assert(port:set_parity(rs232.RS232_PARITY_NONE) == rs232.RS232_ERR_NOERROR) - assert(port:set_stop_bits(rs232.RS232_STOP_1) == rs232.RS232_ERR_NOERROR) - assert(port:set_flow_control(rs232.RS232_FLOW_OFF) == rs232.RS232_ERR_NOERROR) + assert(port:set_baud_rate(search_rs232_const(rs232,"RS232_BAUD_",baud)) == rs232.RS232_ERR_NOERROR) + assert(port:set_data_bits(search_rs232_const(rs232,"RS232_DATA_",bits)) == rs232.RS232_ERR_NOERROR) + assert(port:set_parity(search_rs232_const(rs232,"RS232_PARITY_",parity)) == rs232.RS232_ERR_NOERROR) + assert(port:set_stop_bits(search_rs232_const(rs232,"RS232_STOP_",stop_bits)) == rs232.RS232_ERR_NOERROR) + assert(port:set_flow_control(search_rs232_const(rs232,"RS232_FLOW_",flowctl)) == rs232.RS232_ERR_NOERROR) - getparameter = {} + getparameter = {} - getparameter["rs232"] = port + getparameter["rs232"] = port + + if subsystem == "mhz" then + getparameter["function"] = get_mhz getparameter["name"] = "CO2_PPM" getparameter["sensor"] = "MHZ19" parameters[#parameters+1] = getparameter end + + parameters[#parameters+1] = getparameter end) -- 2.34.1