diff --git a/config/dmserial.conf.sample b/config/dmserial.conf.sample index 6593920..a019bd4 100644 --- a/config/dmserial.conf.sample +++ b/config/dmserial.conf.sample @@ -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 `\\`. -- @@ -32,19 +28,54 @@ -- 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 = { { @@ -52,16 +83,19 @@ observ_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 = { { @@ -83,8 +117,8 @@ observ_meter = { dmserial = { logger = "", - node = "dummy-node", - sensor = "dkrf400", + node = node_id, + sensor = sensor_id, output = "", format = "", tty = "/dev/ttyU0", @@ -92,10 +126,19 @@ dmserial = { 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". @@ -103,11 +146,11 @@ dmserial = { 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, diff --git a/src/dm_mqueue_util.f90 b/src/dm_mqueue_util.f90 index 1b912c0..8b53725 100644 --- a/src/dm_mqueue_util.f90 +++ b/src/dm_mqueue_util.f90 @@ -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 diff --git a/src/dm_tty.f90 b/src/dm_tty.f90 index c649cdd..b9768cf 100644 --- a/src/dm_tty.f90 +++ b/src/dm_tty.f90 @@ -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 @@ -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) @@ -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)