Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Jul 9, 2024
1 parent 4b6a566 commit 641bd80
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 58 deletions.
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ SRC = $(SRCDIR)/dm_ansi.f90 \
$(SRCDIR)/dm_base64.f90 \
$(SRCDIR)/dm_beat.f90 \
$(SRCDIR)/dm_block.f90 \
$(SRCDIR)/dm_c.f90 \
$(SRCDIR)/dm_cgi.f90 \
$(SRCDIR)/dm_cgi_router.f90 \
$(SRCDIR)/dm_compat.f90 \
$(SRCDIR)/dm_config.f90 \
$(SRCDIR)/dm_const.f90 \
$(SRCDIR)/dm_csv.f90 \
Expand Down Expand Up @@ -312,9 +312,9 @@ OBJ = dm_ansi.o \
dm_base64.o \
dm_beat.o \
dm_block.o \
dm_c.o \
dm_cgi.o \
dm_cgi_router.o \
dm_compat.o \
dm_config.o \
dm_const.o \
dm_csv.o \
Expand Down Expand Up @@ -409,11 +409,9 @@ all:
@echo
@echo " freebsd - FreeBSD release build (x86-64, aarch64)."
@echo " freebsd_debug - FreeBSD debug build (x86-64, aarch64)."
@echo " freebsd_release - FreeBSD release build (x86-64, aarch64)."
@echo " linux - Linux release build (x86-64)."
@echo " linux_aarch64 - Linux release build (aarch64)."
@echo " linux_debug - Linux debug build (x86-64)."
@echo " linux_release - Linux release build (x86-64)."
@echo
@echo "For an overview of all available targets, select target <help>."

Expand All @@ -426,7 +424,7 @@ app: $(DMAPI) $(DMBACKUP) $(DMBEAT) $(DMDB) $(DMDBCTL) $(DMEXPORT) $(DMFEED) \
$(DMUUID) $(DMWEB)

# Tests target.
test: dmtestapi dmtestascii dmtestatom dmtestbase64 dmtestcgi dmtestcompat \
test: dmtestapi dmtestascii dmtestatom dmtestbase64 dmtestc dmtestcgi \
dmtestconfig dmtestcsv dmtestdb dmtestdp dmtestfile dmtesthash dmtesthdf5 \
dmtesthtml dmtestid dmtestlog dmtestlogger dmtestlua dmtestjob dmtestjson \
dmtestmail dmtestmodbus dmtestmqtt dmtestmqueue dmtestnml dmtestobserv \
Expand Down Expand Up @@ -532,7 +530,7 @@ $(OBJ): $(SRC)
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_version.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_kind.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_platform.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_compat.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_c.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_ascii.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_const.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_error.f90
Expand Down Expand Up @@ -650,12 +648,12 @@ dmtestatom: test/dmtestatom.f90 $(TARGET)
dmtestbase64: test/dmtestbase64.f90 $(TARGET)
$(FC) $(FFLAGS) $(LDFLAGS) -o dmtestbase64 test/dmtestbase64.f90 $(TARGET) $(LDLIBS)

dmtestc: test/dmtestc.f90 $(TARGET)
$(FC) $(FFLAGS) $(LDFLAGS) -o dmtestc test/dmtestc.f90 $(TARGET) $(LDLIBS)

dmtestcgi: test/dmtestcgi.f90 $(TARGET)
$(FC) $(FFLAGS) $(LDFLAGS) -o dmtestcgi test/dmtestcgi.f90 $(TARGET) $(LDLIBS)

dmtestcompat: test/dmtestcompat.f90 $(TARGET)
$(FC) $(FFLAGS) $(LDFLAGS) -o dmtestcompat test/dmtestcompat.f90 $(TARGET) $(LDLIBS)

dmtestconfig: test/dmtestconfig.f90 $(TARGET)
$(FC) $(FFLAGS) $(LDFLAGS) -o dmtestconfig test/dmtestconfig.f90 $(TARGET) $(LIBLUA54) $(LDLIBS)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ semaphores.

DMPACK includes modules for:

* sensor control (RS-232/422/485, 1-Wire, Modbus RTU/TCP, file system, sub-process)
* sensor control (RS-232/422/485, Modbus RTU/TCP, 1-Wire, sub-process, file system)
* SQLite database access
* message passing via POSIX message queues
* inter-process communication via POSIX semaphores
* process synchronisation via POSIX semaphores
* data serialisation (ASCII, CSV, JSON, JSON Lines, HDF5, Fortran 95 Namelist)
* server-side web applications (CGI, FastCGI)
* HTTP-RPC API for remote procedure calls
Expand Down
6 changes: 3 additions & 3 deletions adoc/dmserial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dmserial - reads observations from TTY/PTY
*dmserial* --version

*dmserial* --*config* _file_ [--*name* _name_] [--*node* _id_] [--*sensor* _id_]
[--*logger* _name_] [--*tty* _path_] [--*baudrate* _n_] [--*bytesize* _n_]
[--*logger* _name_] [--*path* _path_] [--*baudrate* _n_] [--*bytesize* _n_]
[--*stopbits* _n_] [--*parity* _name_] [--*timeout* _n_] [--*format* _name_]
[--*output* _file_] [--*dtr*] [--*rts*] [--*debug*] [--*verbose*]

Expand Down Expand Up @@ -94,8 +94,8 @@ GeoCOM API functions.
*--timeout*, *-T* _n_::
Connection timeout in seconds.

*--tty*, *-Y* _path_::
Path to TTY/PTY device (for example, `/dev/ttyU0`).
*--path*, *-p* _path_::
Path to TTY/PTY device (for example, `/dev/ttyUSB0`).

*--verbose*, *-V*::
Print log messages to _stderr_.
Expand Down
42 changes: 21 additions & 21 deletions app/dmserial.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ program dmserial
integer :: output_type = OUTPUT_NONE !! Output type.
character(len=FORMAT_NAME_LEN) :: format_name = ' ' !! Output format name.
integer :: format = FORMAT_NONE !! Output format.
character(len=FILE_PATH_LEN) :: tty = ' ' !! Path of TTY/PTY device (required).
character(len=FILE_PATH_LEN) :: path = ' ' !! Path of TTY/PTY device (required).
integer :: baud_rate = 9600 !! Baud rate (required).
integer :: byte_size = 8 !! Byte size (required).
character(len=TTY_PARITY_NAME_LEN) :: parity = 'none' !! Parity name (required).
Expand Down Expand Up @@ -58,7 +58,7 @@ program dmserial

! Create TTY type.
rc = create_tty(tty = tty, &
path = app%tty, &
path = app%path, &
baud_rate = app%baud_rate, &
byte_size = app%byte_size, &
parity = app%parity, &
Expand Down Expand Up @@ -176,9 +176,9 @@ integer function read_args(app) result(rc)
arg_type('logger', short='l', type=ARG_TYPE_ID), & ! -l, --logger <string>
arg_type('node', short='N', type=ARG_TYPE_ID), & ! -N, --node <string>
arg_type('sensor', short='S', type=ARG_TYPE_ID), & ! -S, --sensor <string>
arg_type('tty', short='Y', type=ARG_TYPE_STRING), & ! -T, --tty <string>
arg_type('output', short='o', type=ARG_TYPE_STRING), & ! -o, --output <string>
arg_type('format', short='f', type=ARG_TYPE_STRING), & ! -f, --format <string>
arg_type('path', short='p', type=ARG_TYPE_STRING), & ! -p, --path <string>
arg_type('baudrate', short='B', type=ARG_TYPE_INTEGER), & ! -B, --baudrate <n>
arg_type('bytesize', short='Z', type=ARG_TYPE_INTEGER), & ! -Z, --bytesize <n>
arg_type('parity', short='P', type=ARG_TYPE_STRING), & ! -P, --parity <string>
Expand Down Expand Up @@ -207,7 +207,7 @@ integer function read_args(app) result(rc)
rc = dm_arg_get(args( 5), app%sensor)
rc = dm_arg_get(args( 6), app%output)
rc = dm_arg_get(args( 7), app%format_name)
rc = dm_arg_get(args( 8), app%tty)
rc = dm_arg_get(args( 8), app%path)
rc = dm_arg_get(args( 9), app%baud_rate)
rc = dm_arg_get(args(10), app%byte_size)
rc = dm_arg_get(args(11), app%parity)
Expand Down Expand Up @@ -259,8 +259,8 @@ integer function read_args(app) result(rc)
! TTY options.
rc = E_NOT_FOUND

if (.not. dm_file_exists(app%tty)) then
call dm_error_out(rc, 'TTY ' // trim(app%tty) // ' does not exist')
if (.not. dm_file_exists(app%path)) then
call dm_error_out(rc, 'TTY ' // trim(app%path) // ' does not exist')
return
end if

Expand Down Expand Up @@ -314,19 +314,19 @@ integer function read_config(app) result(rc)
rc = dm_config_open(config, app%config, app%name, geocom=.true.)

if (dm_is_ok(rc)) then
rc = dm_config_get(config, 'baudrate', app%baud_rate)
rc = dm_config_get(config, 'bytesize', app%byte_size)
rc = dm_config_get(config, 'dtr', app%dtr)
rc = dm_config_get(config, 'format', app%format_name)
rc = dm_config_get(config, 'logger', app%logger)
rc = dm_config_get(config, 'node', app%node)
rc = dm_config_get(config, 'output', app%output)
rc = dm_config_get(config, 'parity', app%parity)
rc = dm_config_get(config, 'rts', app%rts)
rc = dm_config_get(config, 'sensor', app%sensor)
rc = dm_config_get(config, 'path', app%path)
rc = dm_config_get(config, 'baudrate', app%baud_rate)
rc = dm_config_get(config, 'bytesize', app%byte_size)
rc = dm_config_get(config, 'parity', app%parity)
rc = dm_config_get(config, 'stopbits', app%stop_bits)
rc = dm_config_get(config, 'timeout', app%timeout)
rc = dm_config_get(config, 'tty', app%tty)
rc = dm_config_get(config, 'dtr', app%dtr)
rc = dm_config_get(config, 'rts', app%rts)
rc = dm_config_get(config, 'output', app%output)
rc = dm_config_get(config, 'format', app%format_name)
rc = dm_config_get(config, 'debug', app%debug)
rc = dm_config_get(config, 'verbose', app%verbose)

Expand Down Expand Up @@ -394,7 +394,7 @@ integer function read_observ(tty, observ, node_id, sensor_id, source, debug) res
if (dm_is_error(rc)) call logger%warning('failed to flush buffers', observ=observ, error=rc)

if (debug_) then
call logger%debug('sending request to TTY ' // trim(app%tty) // ': ' // request%request, &
call logger%debug('sending request to TTY ' // trim(app%path) // ': ' // request%request, &
observ=observ, escape=.false.)
end if

Expand All @@ -404,7 +404,7 @@ integer function read_observ(tty, observ, node_id, sensor_id, source, debug) res
if (dm_is_error(rc)) then
request%error = rc
call logger%error('failed to write ' // request_name_string(request%name, i) // ' to TTY ' // &
app%tty, observ=observ, error=rc)
app%path, observ=observ, error=rc)
cycle req_loop
end if

Expand All @@ -420,12 +420,12 @@ integer function read_observ(tty, observ, node_id, sensor_id, source, debug) res
if (dm_is_error(rc)) then
request%error = rc
call logger%error('failed to read response of ' // request_name_string(request%name, i) // &
' from TTY ' // app%tty, observ=observ, error=rc)
' from TTY ' // app%path, observ=observ, error=rc)
cycle req_loop
end if

if (debug_) then
call logger%debug('received response from TTY ' // trim(app%tty) // ': ' // &
call logger%debug('received response from TTY ' // trim(app%path) // ': ' // &
request%response, observ=observ, escape=.false.)
end if

Expand Down Expand Up @@ -507,14 +507,14 @@ integer function run(app, tty) result(rc)
call logger%info('started ' // app%name)

! Try to open TTY/PTY.
call logger%debug('opening TTY ' // trim(app%tty) // ' to sensor ' // trim(app%sensor) // &
call logger%debug('opening TTY ' // trim(app%path) // ' to sensor ' // trim(app%sensor) // &
' (' // dm_itoa(tty%baud_rate) // ' ' // dm_itoa(app%byte_size) // &
dm_upper(app%parity(1:1)) // dm_itoa(app%stop_bits) // ')')

do
rc = dm_tty_open(tty)
if (dm_is_ok(rc)) exit
call logger%error('failed to open TTY ' // trim(app%tty) // ', next attempt in 5 sec', error=rc)
call logger%error('failed to open TTY ' // trim(app%path) // ', next attempt in 5 sec', error=rc)
call dm_sleep(5) ! Wait grace period.
end do

Expand Down Expand Up @@ -572,7 +572,7 @@ integer function run(app, tty) result(rc)
end do job_loop

if (dm_tty_connected(tty)) then
call logger%debug('closing TTY ' // app%tty)
call logger%debug('closing TTY ' // app%path)
call dm_tty_close(tty)
end if

Expand Down
4 changes: 2 additions & 2 deletions config/dmserial.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
-- sensor - Sensor id.
-- stopbits - Number of stop bits (1 or 2).
-- timeout - Read timeout in seconds.
-- tty - Path of TTY/PTY device (for example, `/dev/ttyU0`).
-- path - 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
Expand Down Expand Up @@ -119,7 +119,7 @@ dmserial = {
sensor = sensor_id,
output = "",
format = "",
tty = "/dev/ttyU0",
path = "/dev/ttyU0",
baudrate = 9600,
bytesize = 8,
parity = "none",
Expand Down
8 changes: 4 additions & 4 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ name = "dmtestbase64"
main = "dmtestbase64.f90"

[[test]]
name = "dmtestcgi"
main = "dmtestcgi.f90"
name = "dmtestc"
main = "dmtestc.f90"

[[test]]
name = "dmtestcompat"
main = "dmtestcompat.f90"
name = "dmtestcgi"
main = "dmtestcgi.f90"

[[test]]
name = "dmtestconfig"
Expand Down
10 changes: 5 additions & 5 deletions man/dmserial.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: dmserial
.\" Author: Philipp Engel
.\" Generator: Asciidoctor 2.0.23
.\" Date: 2024-04-23
.\" Date: 2024-07-08
.\" Manual: User Commands
.\" Source: DMSERIAL
.\" Language: English
.\"
.TH "DMSERIAL" "1" "2024-04-23" "DMSERIAL" "User Commands"
.TH "DMSERIAL" "1" "2024-07-08" "DMSERIAL" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -36,7 +36,7 @@ dmserial \- reads observations from TTY/PTY
\fBdmserial\fP \-\-version
.sp
\fBdmserial\fP \-\-\fBconfig\fP \fIfile\fP [\-\-\fBname\fP \fIname\fP] [\-\-\fBnode\fP \fIid\fP] [\-\-\fBsensor\fP \fIid\fP]
[\-\-\fBlogger\fP \fIname\fP] [\-\-\fBtty\fP \fIpath\fP] [\-\-\fBbaudrate\fP \fIn\fP] [\-\-\fBbytesize\fP \fIn\fP]
[\-\-\fBlogger\fP \fIname\fP] [\-\-\fBpath\fP \fIpath\fP] [\-\-\fBbaudrate\fP \fIn\fP] [\-\-\fBbytesize\fP \fIn\fP]
[\-\-\fBstopbits\fP \fIn\fP] [\-\-\fBparity\fP \fIname\fP] [\-\-\fBtimeout\fP \fIn\fP] [\-\-\fBformat\fP \fIname\fP]
[\-\-\fBoutput\fP \fIfile\fP] [\-\-\fBdtr\fP] [\-\-\fBrts\fP] [\-\-\fBdebug\fP] [\-\-\fBverbose\fP]
.SH "DESCRIPTION"
Expand Down Expand Up @@ -144,9 +144,9 @@ Number of stop bits (1, 2).
Connection timeout in seconds.
.RE
.sp
\fB\-\-tty\fP, \fB\-Y\fP \fIpath\fP
\fB\-\-path\fP, \fB\-p\fP \fIpath\fP
.RS 4
Path to TTY/PTY device (for example, \f(CR/dev/ttyU0\fP).
Path to TTY/PTY device (for example, \f(CR/dev/ttyUSB0\fP).
.RE
.sp
\fB\-\-verbose\fP, \fB\-V\fP
Expand Down
2 changes: 1 addition & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#
# export DM_PIPE_SKIP=1
#
TESTS="dmtestapi dmtestascii dmtestbase64 dmtestcgi dmtestcompat dmtestconfig \
TESTS="dmtestapi dmtestascii dmtestbase64 dmtestc dmtestcgi dmtestconfig \
dmtestcsv dmtestdb dmtestdp dmtestfile dmtesthash dmtesthdf5 dmtesthtml dmtestid \
dmtestlog dmtestlogger dmtestlua dmtestjob dmtestjson dmtestmail dmtestmodbus \
dmtestmqueue dmtestmqtt dmtestnml dmtestobserv dmtestpath dmtestpipe dmtestplot \
Expand Down
4 changes: 2 additions & 2 deletions src/dm_compat.f90 → src/dm_c.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
! Author: Philipp Engel
! Licence: ISC
module dm_compat
module dm_c
!! Utility procedures for C interoperability.
use, intrinsic :: iso_c_binding
use :: dm_kind
Expand Down Expand Up @@ -101,4 +101,4 @@ pure elemental function dm_uint32_to_int64(u) result(s)
s = 4294967296_i8 + int(u, kind=i8)
end if
end function dm_uint32_to_int64
end module dm_compat
end module dm_c
2 changes: 1 addition & 1 deletion src/dm_file.f90
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ integer function dm_file_status(path, status) result(rc)
!! Returns status of file at given path in `status`. The function
!! returns `E_SYSTEM` on error.
use :: unix
use :: dm_compat, only: dm_to_signed
use :: dm_c, only: dm_to_signed

character(len=*), intent(in) :: path !! File path.
type(file_status_type), intent(out) :: status !! File status type.
Expand Down
4 changes: 2 additions & 2 deletions src/dm_modbus.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module dm_modbus
!! Abstraction layer over _libmodbus_, for Modbus RTU/TCP communication.
!!
!! You may want to use function `dm_to_signed()` available in module
!! `dm_compat` to convert unsigned to signed integers.
!! `dm_c` to convert unsigned to signed integers.
!!
!! Use Modbus function code `0x03` to read holding registers from a Modbus
!! RTU connection:
Expand Down Expand Up @@ -50,7 +50,7 @@ module dm_modbus
use :: modbus
use :: modbus_rtu
use :: modbus_tcp
use :: dm_compat
use :: dm_c
use :: dm_error
use :: dm_kind
implicit none (type, external)
Expand Down
2 changes: 1 addition & 1 deletion src/dm_tty.f90
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ integer function dm_tty_set_attributes(tty) result(rc)
!! * `E_SYSTEM` if system calls failed.
!!
use :: unix
use :: dm_compat
use :: dm_c

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

Expand Down
2 changes: 1 addition & 1 deletion src/dmpack.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ module dmpack
use :: dm_base64
use :: dm_beat
use :: dm_block
use :: dm_c
use :: dm_cgi
use :: dm_cgi_router
use :: dm_compat
use :: dm_config
use :: dm_const
use :: dm_csv
Expand Down
Loading

0 comments on commit 641bd80

Please sign in to comment.