Skip to content

Commit

Permalink
Minor updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Mar 8, 2024
1 parent 0024ca8 commit c97a2f6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 46 deletions.
79 changes: 61 additions & 18 deletions config/dmserial.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
-- Example configuration file for dmserial to read temperature values from a
-- DKRF400 sensor connected through USB/RS-232 on TTY `/dev/ttyU0` (9600 8N2).
--
-- Observations are forwarded to process `dmdb` via POSIX message queue. The
-- node `node-1`, the sensor `dkrf400`, and the target `meter` have to exist in
-- the database!
--
-- To run dmserial as a sole data logger, remove the receiver from the
-- observation, and set output file and format.
-- To run dmserial as a sole data logger, remove the receiver `dmdb` from
-- observation `observ_meter`, and set output file and format.
--
-- All backslashes `\` in this file have to be escaped as `\\`.
--
Expand All @@ -32,36 +28,74 @@
-- tty - Path of TTY/PTY device (for example, `/dev/ttyU0`).
-- verbose - Print logs to standard error.
--
-- Optionally, import an additional Lua file `myfile.lua` by adding the
-- following line to the configuration:
--
-- dofile("myfile.lua")
--
-- Or, if the file is a library and in the Lua search path:
--
-- require("myfile")
--

--
-- The following node id, sensor id, and target id must exist in the database,
-- or be set accordingly.
--
local node_id = "dummy-node"
local sensor_id = "dkrf400"
local target_id = "meter"

--
-- The observations to be used in jobs list. The attribute `receivers` may
-- contain a list of up to 16 processes to forward the observation to.
--
observ_start = {
--
-- Enable sensor by sending a carriage return.
-- Reads the response of the sensor but does not parse it.
--
name = "start",
target_id = target_id,
receivers = { },
requests = {
{
name = "stop",
request = "\\r",
delimiter = "\\n",
pattern = "",
delay = 500
}
}
}

observ_stop = {
--
-- Stop "Meter Mode".
-- The sensor response is not read if the delimiter is empty (as the
-- DKRF400 does not always return a response to command `s\r`).
-- Stop "Meter Mode". The sensor response is not read if the delimiter is
-- empty (as the DKRF400 does not always return a response to command `s\r`).
--
name = "stop",
target_id = "meter",
target_id = target_id,
receivers = { },
requests = {
{
name = "stop",
request = "s\\r",
delimiter = "",
pattern = "",
delay = 0
delay = 500
}
}
}

observ_meter = {
--
-- Single measurement.
-- Single measurement. Reads temperature, rel. and abs. humidity, dew
-- point, and wet-bulb temperature. The names of the responses are limited
-- to 8 characters.
--
name = "meter",
target_id = "meter",
target_id = target_id,
receivers = { "dmdb" },
requests = {
{
Expand All @@ -83,31 +117,40 @@ observ_meter = {

dmserial = {
logger = "",
node = "dummy-node",
sensor = "dkrf400",
node = node_id,
sensor = sensor_id,
output = "",
format = "",
tty = "/dev/ttyU0",
baudrate = 9600,
bytesize = 8,
parity = "none",
stopbits = 2,
timeout = 5,
timeout = 0,
dtr = true,
rts = true,
jobs = {
{
--
-- Start sensor.
--
disabled = false,
onetime = true,
observation = observ_start,
delay = 1000
},
{
--
-- Stop "Meter Mode".
--
disabled = false,
onetime = true,
observation = observ_stop,
delay = 500
delay = 1000
},
{
--
-- Measure values, wait 5 seconds, repeat.
-- Read sensor values, wait 5 seconds, repeat.
--
disabled = false,
onetime = false,
Expand Down
5 changes: 2 additions & 3 deletions src/dm_mqueue_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ integer function mqueue_forward_observ(observ, name, blocking, quiet, self) resu
end if

if (.not. quiet_) then
call dm_log_debug('sent observ ' // trim(observ%name) // ' from ' // &
trim(observ%source) // ' to mqueue /' // observ%receivers(next), &
observ=observ)
call dm_log_debug('sent observ ' // trim(observ%name) // ' to mqueue /' // &
observ%receivers(next), observ=observ)
end if
end block mqueue_block

Expand Down
50 changes: 25 additions & 25 deletions src/dm_tty.f90
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ integer function dm_tty_set_attributes(tty) result(rc)

type(tty_type), intent(inout) :: tty !! TTY type.

integer(kind=c_speed_t) :: baud_rate
integer(kind=c_int64_t) :: byte_size
integer(kind=c_int64_t) :: parity
integer(kind=c_int64_t) :: stop_bits
integer :: baud_rate
integer :: byte_size
integer :: parity
integer :: stop_bits

integer(kind=c_int), target :: stat

Expand Down Expand Up @@ -536,19 +536,19 @@ integer function dm_tty_set_attributes(tty) result(rc)
rc = E_SYSTEM

termios_block: block
integer(kind=c_int64_t) :: c_cflag
integer(kind=c_int64_t) :: c_iflag
integer(kind=c_int64_t) :: c_lflag
integer(kind=c_int64_t) :: c_oflag
type(c_termios) :: termios
integer(kind=i8) :: c_cflag
integer(kind=i8) :: c_iflag
integer(kind=i8) :: c_lflag
integer(kind=i8) :: c_oflag
type(c_termios) :: termios

! Get current attributes.
stat = c_tcgetattr(tty%fd, termios)
if (stat /= 0) return

! Set baud rate (I/O).
stat = c_cfsetispeed(termios, baud_rate); if (stat /= 0) return
stat = c_cfsetospeed(termios, baud_rate); if (stat /= 0) return
stat = c_cfsetispeed(termios, int(baud_rate, kind=c_speed_t)); if (stat /= 0) return
stat = c_cfsetospeed(termios, int(baud_rate, kind=c_speed_t)); if (stat /= 0) return

! The joy of working with unsigned integers in Fortran ...
c_iflag = dm_to_signed(termios%c_iflag)
Expand All @@ -557,26 +557,26 @@ integer function dm_tty_set_attributes(tty) result(rc)
c_lflag = dm_to_signed(termios%c_lflag)

! Input modes.
c_iflag = iand(c_iflag, not(int(IGNBRK + BRKINT + PARMRK + ISTRIP + INLCR + IGNCR + ICRNL, kind=c_int64_t))) ! No special handling of received bytes.
c_iflag = iand(c_iflag, not(int(IXON + IXOFF + IXANY, kind=c_int64_t))) ! Turn XON/XOFF control off.
c_iflag = iand(c_iflag, not(int(IGNBRK + BRKINT + PARMRK + ISTRIP + INLCR + IGNCR + ICRNL, kind=i8))) ! No special handling of received bytes.
c_iflag = iand(c_iflag, not(int(IXON + IXOFF + IXANY, kind=i8))) ! Turn XON/XOFF control off.

! Output modes.
c_oflag = iand(c_oflag, not(int(OPOST, kind=c_int64_t))) ! No special interpretation of output bytes.
c_oflag = iand(c_oflag, not(int(OPOST, kind=i8))) ! No special interpretation of output bytes.

! Control modes.
c_cflag = iand(c_cflag, not(int(CSIZE, kind=c_int64_t))) ! Unset byte size.
c_cflag = iand(c_cflag, not(int(CSTOPB, kind=c_int64_t))) ! Unset stop bits.
c_cflag = iand(c_cflag, not(int(PARENB + PARODD, kind=c_int64_t))) ! Unset parity.
c_cflag = ior (c_cflag, byte_size) ! Set byte size.
c_cflag = ior (c_cflag, stop_bits) ! Set stop bits.
c_cflag = ior (c_cflag, parity) ! Set parity.
c_cflag = ior (c_cflag, int(CLOCAL + CREAD, kind=c_int64_t)) ! Ignore modem controls, enable reading.
c_cflag = iand(c_cflag, not(int(CSIZE, kind=i8))) ! Unset byte size.
c_cflag = iand(c_cflag, not(int(CSTOPB, kind=i8))) ! Unset stop bits.
c_cflag = iand(c_cflag, not(int(PARENB + PARODD, kind=i8))) ! Unset parity.
c_cflag = ior (c_cflag, int(byte_size, kind=i8)) ! Set byte size.
c_cflag = ior (c_cflag, int(stop_bits, kind=i8)) ! Set stop bits.
c_cflag = ior (c_cflag, int(parity, kind=i8)) ! Set parity.
c_cflag = ior (c_cflag, int(CLOCAL + CREAD, kind=i8)) ! Ignore modem controls, enable reading.

! Local modes.
c_lflag = iand(c_lflag, not(int(ECHO + ECHOE + ECHONL, kind=c_int64_t))) ! No echo.
c_lflag = iand(c_lflag, not(int(IEXTEN, kind=c_int64_t))) ! No implementation-defined input processing.
c_lflag = iand(c_lflag, not(int(ICANON, kind=c_int64_t))) ! No canonical processing.
c_lflag = iand(c_lflag, not(int(ISIG, kind=c_int64_t))) ! No signal chars.
c_lflag = iand(c_lflag, not(int(ECHO + ECHOE + ECHONL, kind=i8))) ! No echo.
c_lflag = iand(c_lflag, not(int(IEXTEN, kind=i8))) ! No implementation-defined input processing.
c_lflag = iand(c_lflag, not(int(ICANON, kind=i8))) ! No canonical processing.
c_lflag = iand(c_lflag, not(int(ISIG, kind=i8))) ! No signal chars.

termios%c_iflag = dm_to_unsigned(c_iflag)
termios%c_oflag = dm_to_unsigned(c_oflag)
Expand Down

0 comments on commit c97a2f6

Please sign in to comment.