diff --git a/Makefile b/Makefile index 47c57e3..a5f87d9 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 \ @@ -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 ." @@ -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 \ @@ -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 @@ -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) diff --git a/README.md b/README.md index ad07d80..af48629 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/adoc/dmserial.adoc b/adoc/dmserial.adoc index d889983..f66af61 100644 --- a/adoc/dmserial.adoc +++ b/adoc/dmserial.adoc @@ -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*] @@ -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_. diff --git a/app/dmserial.f90 b/app/dmserial.f90 index 0440f4d..3100c9a 100644 --- a/app/dmserial.f90 +++ b/app/dmserial.f90 @@ -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). @@ -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, & @@ -176,9 +176,9 @@ integer function read_args(app) result(rc) arg_type('logger', short='l', type=ARG_TYPE_ID), & ! -l, --logger arg_type('node', short='N', type=ARG_TYPE_ID), & ! -N, --node arg_type('sensor', short='S', type=ARG_TYPE_ID), & ! -S, --sensor - arg_type('tty', short='Y', type=ARG_TYPE_STRING), & ! -T, --tty arg_type('output', short='o', type=ARG_TYPE_STRING), & ! -o, --output arg_type('format', short='f', type=ARG_TYPE_STRING), & ! -f, --format + arg_type('path', short='p', type=ARG_TYPE_STRING), & ! -p, --path arg_type('baudrate', short='B', type=ARG_TYPE_INTEGER), & ! -B, --baudrate arg_type('bytesize', short='Z', type=ARG_TYPE_INTEGER), & ! -Z, --bytesize arg_type('parity', short='P', type=ARG_TYPE_STRING), & ! -P, --parity @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/config/dmserial.conf.sample b/config/dmserial.conf.sample index f8010ee..7dc8ea0 100644 --- a/config/dmserial.conf.sample +++ b/config/dmserial.conf.sample @@ -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 @@ -119,7 +119,7 @@ dmserial = { sensor = sensor_id, output = "", format = "", - tty = "/dev/ttyU0", + path = "/dev/ttyU0", baudrate = 9600, bytesize = 8, parity = "none", diff --git a/fpm.toml b/fpm.toml index beda7c5..84ef89a 100644 --- a/fpm.toml +++ b/fpm.toml @@ -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" diff --git a/man/dmserial.1 b/man/dmserial.1 index 9acef31..8c2308f 100644 --- a/man/dmserial.1 +++ b/man/dmserial.1 @@ -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 @@ -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" @@ -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 diff --git a/runtests.sh b/runtests.sh index 94015f8..e0d6ebf 100644 --- a/runtests.sh +++ b/runtests.sh @@ -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 \ diff --git a/src/dm_compat.f90 b/src/dm_c.f90 similarity index 98% rename from src/dm_compat.f90 rename to src/dm_c.f90 index 01f9be2..b661345 100644 --- a/src/dm_compat.f90 +++ b/src/dm_c.f90 @@ -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 @@ -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 diff --git a/src/dm_file.f90 b/src/dm_file.f90 index e13d970..1048513 100644 --- a/src/dm_file.f90 +++ b/src/dm_file.f90 @@ -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. diff --git a/src/dm_modbus.f90 b/src/dm_modbus.f90 index e5df71c..d637009 100644 --- a/src/dm_modbus.f90 +++ b/src/dm_modbus.f90 @@ -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: @@ -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) diff --git a/src/dm_tty.f90 b/src/dm_tty.f90 index f09b2a7..9ad2398 100644 --- a/src/dm_tty.f90 +++ b/src/dm_tty.f90 @@ -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. diff --git a/src/dmpack.f90 b/src/dmpack.f90 index 64b158a..8a87bef 100644 --- a/src/dmpack.f90 +++ b/src/dmpack.f90 @@ -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 diff --git a/test/dmtestcompat.f90 b/test/dmtestc.f90 similarity index 86% rename from test/dmtestcompat.f90 rename to test/dmtestc.f90 index d39dedd..cdb568c 100644 --- a/test/dmtestcompat.f90 +++ b/test/dmtestc.f90 @@ -1,13 +1,13 @@ -! dmtestcompat.f90 +! dmtestc.f90 ! ! Author: Philipp Engel ! Licence: ISC -program dmtestcompat +program dmtestc !! Test program for C interoperability. use :: dmpack implicit none (type, external) - character(len=*), parameter :: TEST_NAME = 'dmtestcompat' + character(len=*), parameter :: TEST_NAME = 'dmtestc' integer, parameter :: NTESTS = 1 type(test_type) :: tests(NTESTS) @@ -31,4 +31,4 @@ logical function test01() result(stat) stat = TEST_PASSED end function test01 -end program dmtestcompat +end program dmtestc