Skip to content

Commit

Permalink
Minor updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Mar 6, 2024
1 parent 2e550b1 commit be5f08d
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 105 deletions.
6 changes: 3 additions & 3 deletions adoc/dmfeed.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ file modification of the feed, the output file is not updated, unless argument
*--email*, *-M* _address_::
E-mail address of feed author.

*--entries*, *-E* _count_::
Maximum number of entries in feed (default is 50).

*--force*, *-F*::
Force writing of output file. If not set, the output file will be updated
only if new log records are available.
Expand All @@ -72,9 +75,6 @@ file modification of the feed, the output file is not updated, unless argument
*--name*, *-n* _name_::
Name of instance and table in given configuration file (default is `dmfeed`).

*--entries*, *-E* _count_::
Maximum number of entries in feed (default is 50).

*--node*, *-N* _id_::
Select log messages of the given node id.

Expand Down
12 changes: 6 additions & 6 deletions app/dmfeed.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ program dmfeed
character(len=FILE_PATH_LEN) :: database = ' ' !! Path to log database.
character(len=FILE_PATH_LEN) :: output = ' ' !! Output path of Atom file (stdout if empty).
character(len=NODE_ID_LEN) :: node = ' ' !! Optional node id.
integer :: entries = 50 !! Max. number of entries in feed.
integer :: min_level = LVL_DEBUG !! Minimum log level
integer :: max_level = LVL_CRITICAL !! Maximum log level.
integer :: entries = 50 !! Max. number of entries in feed.
logical :: force = .false. !! Force writing of output file.
type(atom_type) :: atom !! Atom type.
end type app_type
Expand Down Expand Up @@ -83,9 +83,9 @@ integer function read_args(app) result(rc)
arg_type('database', short='d', type=ARG_TYPE_DB), & ! -d, --database <path>
arg_type('output', short='o', type=ARG_TYPE_CHAR), & ! -o, --output <path>
arg_type('node', short='N', type=ARG_TYPE_ID), & ! -N, --node <string>
arg_type('entries', short='E', type=ARG_TYPE_INTEGER), & ! -E, --entries <n>
arg_type('minlevel', short='L', type=ARG_TYPE_INTEGER), & ! -L, --minlevel <n>
arg_type('maxlevel', short='K', type=ARG_TYPE_INTEGER), & ! -K, --maxlevel <n>
arg_type('entries', short='E', type=ARG_TYPE_INTEGER), & ! -E, --entries <n>
arg_type('force', short='F', type=ARG_TYPE_BOOL), & ! -F, --force
arg_type('author', short='A', type=ARG_TYPE_CHAR), & ! -A, --author <string>
arg_type('email', short='M', type=ARG_TYPE_CHAR), & ! -M, --email <string>
Expand All @@ -111,9 +111,9 @@ integer function read_args(app) result(rc)
rc = dm_arg_get(args( 3), app%database)
rc = dm_arg_get(args( 4), app%output)
rc = dm_arg_get(args( 5), app%node)
rc = dm_arg_get(args( 6), app%min_level)
rc = dm_arg_get(args( 7), app%max_level)
rc = dm_arg_get(args( 8), app%entries)
rc = dm_arg_get(args( 6), app%entries)
rc = dm_arg_get(args( 7), app%min_level)
rc = dm_arg_get(args( 8), app%max_level)
rc = dm_arg_get(args( 9), app%force)
rc = dm_arg_get(args(10), app%atom%author)
rc = dm_arg_get(args(11), app%atom%email)
Expand Down Expand Up @@ -178,9 +178,9 @@ integer function read_config(app) result(rc)
rc = dm_config_get(config, 'database', app%database)
rc = dm_config_get(config, 'output', app%output)
rc = dm_config_get(config, 'node', app%node)
rc = dm_config_get(config, 'entries', app%entries)
rc = dm_config_get(config, 'minlevel', app%min_level)
rc = dm_config_get(config, 'maxlevel', app%max_level)
rc = dm_config_get(config, 'entries', app%entries)
rc = dm_config_get(config, 'force', app%force)
rc = dm_config_get(config, 'author', app%atom%author)
rc = dm_config_get(config, 'email', app%atom%email)
Expand Down
4 changes: 2 additions & 2 deletions config/dmfeed.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
-- author - Name of feed author or organisation (optional).
-- database - Path to DMPACK log database.
-- email - E-mail of feed author (optional).
-- entries - Maximum number of entries is feed (default 50, optional).
-- force - Force writing of output file even if no new logs are available.
-- id - 36 characters long UUID (with hyphens) of the Atom feed.
-- maxlevel - Maximum log level (0 to 5, optional).
-- minlevel - Minimum log level (0 to 5, optional).
-- nentries - Maximum number of entries is feed (default 50, optional).
-- node - Sensor node id, selects only related logs (optional).
-- output - Path to output file (if empty, feed is printed to standard output).
-- subtitle - Subtitle of the feed (optional).
Expand All @@ -43,9 +43,9 @@ dmfeed = {
url = "https://example.com/feed.xml",
database = "/var/dmpack/log.sqlite",
node = "dummy-node",
entries = 100,
minlevel = LVL_WARNING,
maxlevel = LVL_CRITICAL,
nentries = 100,
xsl = "feed.xsl",
output = "/var/www/feed.xml",
force = false
Expand Down
38 changes: 21 additions & 17 deletions guide/guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -848,18 +848,19 @@ $ dmexport --database observ.sqlite --type observ --format csv --node dummy-node

=== dmfeed [[dmfeed]]

This program creates a web feed from log messages in Atom Syndication Format.
The log messages are read from database and written as XML to standard output
or file.
The *dmfeed* program creates a web feed from log messages in Atom Syndication
Format. The log messages are read from database and written as XML to standard
output or file.

The feed id has to be a 36 characters long UUID with hyphens. News aggregators
use the id to identify the feed. Therefore, the id should not be reused among
different feeds. Run <<dmuuid>> to generate a valid UUID4.

The time stamp of the feed in the updated element is set to the date and time of
The time stamp of the feed in element _updated_ is set to the date and time of
the last log message. If no logs have been added to the database since the last
file modification of the feed, the output file is not updated, unless argument
`--force` is passed.
`--force` is passed. To update the feed periodically, add *dmfeed* to
<<Cron,crontab>>.

If an XSLT style sheet is given, web browsers may be able to display the Atom
feed in HTML format. Set the option to the (relative) path of the public XSL on
Expand All @@ -876,13 +877,13 @@ the web server. An example style sheet `feed.xsl` is located in
| `--config _file_` | `-c` | – | Path to configuration file.
| `--database _file_` | `-d` | – | Path to SQLite log database.
| `--email _address_` | `-M` | – | E-mail address of feed author.
| `--entries _count_` | `-E` | 50 | Maximum number of entries in feed (max. 500).
| `--force` | `-F` | – | Force file output even if no new log records are available.
| `--help` | `-h` | – | Output available command-line arguments and quit.
| `--id _uuid_` | `-I` | – | UUID of the feed, 36 characters long with hyphens.
| `--maxlevel _level_` | `-K` | 5 | Select log messages of the given maximum <<data-log-level,log level>> (between 1 and 5). Must be greater or equal the minimum level.
| `--minlevel _level_` | `-L` | 1 | Select log messages of the given minimum <<data-log-level,log level>> (between 1 and 5).
| `--name _name_` | `-n` | `dmfeed` | Name of instance and table in given configuration file.
| `--entries _count_` | `-E` | 50 | Maximum number of entries in feed (max. 500).
| `--node _id_` | `-N` | – | Select log messages of the given node id.
| `--output _file_` | `-o` | _stdout_ | Path of the output file. If empty or `-`, the Atom feed will be printed to standard output.
| `--subtitle _string_` | `-G` | – | Sub-title of feed.
Expand Down Expand Up @@ -916,9 +917,8 @@ $ cp /usr/local/share/dmpack/feed.xsl /var/www/
....

If `/var/www/` is served by a web server, feed readers can subscribe to the
feed. To update the feed periodically, add *dmfeed* to <<Cron,crontab>>.
Furthermore, we may translate feed and style sheet into a single HTML document
`feed.html`, using an arbitrary XSLT processor, for instance:
feed. Additionally, we may translate feed and style sheet into a single HTML
document `feed.html`, using an arbitrary XSLT processor, for instance:

....
$ xsltproc --output feed.html /var/www/feed.xsl /var/www/feed.xml
Expand Down Expand Up @@ -4557,17 +4557,18 @@ The maximum message size has to be at least 16384 bytes.
=== Cron

On Unix-like operating system, link:https://en.wikipedia.org/wiki/Cron[cron] is
usually used to run jobs periodically. For example, in order to update an XML
usually used to run jobs periodically. For instance, in order to update an XML
feed, or to generate HTML reports, add a schedule of the task to perform to the
local _crontab(5)_ file.
_crontab(5)_ file of a local user.

For example, we can edit the cron jobs of user `www` with _crontab(1)_:
Edit the cron jobs of user `www` with _crontab(1)_:

....
# crontab -u www -e
....

The following _crontab(5)_ file adds a task to generate reports every hour:
The following _crontab(5)_ entry adds a task to generate reports every hour,
using utility script `mkreport.sh`:

[source,crontab]
....
Expand All @@ -4577,16 +4578,19 @@ MAILTO=/dev/null
@hourly -q /usr/local/share/dmpack/mkreport.sh
....

The shell script `mkreport.sh` must have the execution bits set. Update the
script to your configuration. Furthermore, we can update an Atom XML feed of
logs with <<dmfeed>>:
Status mails and logging are disabled. The shell script `mkreport.sh` must have
the execution bits set. Modify the script according to your set-up.

Additionally, we may update an Atom XML feed of logs by running <<dmfeed>> every
five minutes:

[source,crontab]
....
*/5 * * * * -q /usr/local/bin/dmfeed --config /usr/local/etc/dmpack/dmfeed.conf
....

The feed is updated every five minutes if new logs have arrived.
The feed is updated only if new logs have arrived in the meantime, unless option
_force_ is enabled.

== GeoCOM API

Expand Down
14 changes: 7 additions & 7 deletions man/dmfeed.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: dmfeed
.\" Author: Philipp Engel
.\" Generator: Asciidoctor 2.0.20
.\" Date: 2024-03-05
.\" Date: 2024-03-06
.\" Manual: User Commands
.\" Source: DMFEED
.\" Language: English
.\"
.TH "DMFEED" "1" "2024-03-05" "DMFEED" "User Commands"
.TH "DMFEED" "1" "2024-03-06" "DMFEED" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -78,6 +78,11 @@ Path to SQLite log database.
E\-mail address of feed author.
.RE
.sp
\fB\-\-entries\fP, \fB\-E\fP \fIcount\fP
.RS 4
Maximum number of entries in feed (default is 50).
.RE
.sp
\fB\-\-force\fP, \fB\-F\fP
.RS 4
Force writing of output file. If not set, the output file will be updated
Expand Down Expand Up @@ -110,11 +115,6 @@ Select log messages of the given minimum log level (from 1 to 5).
Name of instance and table in given configuration file (default is \f(CRdmfeed\fP).
.RE
.sp
\fB\-\-entries\fP, \fB\-E\fP \fIcount\fP
.RS 4
Maximum number of entries in feed (default is 50).
.RE
.sp
\fB\-\-node\fP, \fB\-N\fP \fIid\fP
.RS 4
Select log messages of the given node id.
Expand Down
21 changes: 14 additions & 7 deletions src/dm_geocom.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module dm_geocom
!! integer :: rc ! DMPACK return code.
!! type(geocom_class) :: geocom ! GeoCOM object.
!!
!! call geocom%open('/dev/ttyUSB0', GEOCOM_COM_BAUD_115200, retries=1, error=rc)
!! call geocom%open('/dev/ttyUSB0', GEOCOM_COM_BAUD_115200, retries=1, verbose=.true. error=rc)
!!
!! if (dm_is_error(rc)) then
!! dm_error_out(rc)
Expand Down Expand Up @@ -46,8 +46,8 @@ module dm_geocom
integer :: rc = E_NONE !! Last DMPACK return code.
integer :: grc = GRC_OK !! Last GeoCOM return code.
logical :: verbose = .true. !! Print error messages to stderr.
type(request_type) :: request !! Last request.
type(tty_type) :: tty !! TTY type for serial connection to sensor.
type(request_type) :: request !! Last request sent to sensor.
type(tty_type) :: tty !! TTY type for serial connection.
contains
! Public class methods.
procedure, public :: close => geocom_close
Expand Down Expand Up @@ -258,8 +258,8 @@ end subroutine geocom_open

subroutine geocom_send(this, request, error)
!! Sends request to configured TTY.
use :: dm_regex
use :: dm_time
use :: dm_regex, only: dm_regex_request
use :: dm_time, only: dm_time_now

class(geocom_class), intent(inout) :: this !! GeoCOM object.
type(request_type), intent(inout) :: request !! Request to send.
Expand Down Expand Up @@ -489,6 +489,9 @@ subroutine geocom_do_measure(this, tmc_prog, inc_mode)
!! If a distance measurement is performed in measurement program
!! `GEOCOM_TMC_DEF_DIST`, the distance sensor will work with the set
!! EDM mode.
!!
!! This function sets measurement program `GEOCOM_TMC_DEF_DIST` and
!! inclination mode `GEOCOM_TMC_MEA_INC` by default.
class(geocom_class), intent(inout) :: this !! GeoCOM object.
integer, intent(in) :: tmc_prog !! TMC measurement program (`GEOCOM_TMC_MEASURE_PRG`).
integer, intent(in), optional :: inc_mode !! Inclination measurement mode (`GEOCOM_TMC_INCLINE_PRG`).
Expand Down Expand Up @@ -522,7 +525,6 @@ subroutine geocom_download(this, block_number, block_value, block_length)
integer, intent(out) :: block_length !! Block length.

integer :: block_number_
integer :: rc
type(request_type) :: request

block_value = achar(0)
Expand Down Expand Up @@ -569,7 +571,8 @@ end subroutine geocom_fine_adjust

subroutine geocom_get_angle(this, hz, v, inc_mode)
!! Sends *TMC_GetAngle5* request to sensor. Starts an angle measurement
!! and returns the results.
!! and returns the results. This function sets inclination mode
!! `GEOCOM_TMC_MEA_INC` by default.
class(geocom_class), intent(inout) :: this !! GeoCOM object.
real(kind=r8), intent(out) :: hz !! Horizontal angle [rad].
real(kind=r8), intent(out) :: v !! Vertical angle [rad].
Expand All @@ -583,13 +586,17 @@ subroutine geocom_get_angle(this, hz, v, inc_mode)

call dm_geocom_api_request_get_angle(request, inc_mode)
call this%send(request)

call dm_request_get(this%request, 'hz', hz)
call dm_request_get(this%request, 'v', v)
end subroutine geocom_get_angle

subroutine geocom_get_angle_complete(this, hz, v, angle_accuracy, angle_time, trans_inc, long_inc, &
inc_accuracy, inc_time, face, inc_mode)
!! Sends *TMC_GetAngle1* request to sensor. Performs a complete angle
!! measurement. The function starts an angle and, depending on the
!! configuration, an inclination measurement, and returns the results.
!! This function sets inclination mode `GEOCOM_TMC_MEA_INC` by default.
class(geocom_class), intent(inout) :: this !! GeoCOM object.
real(kind=r8), intent(out) :: hz !! Horizontal angle [rad].
real(kind=r8), intent(out) :: v !! Vertical angle [rad].
Expand Down
Loading

0 comments on commit be5f08d

Please sign in to comment.