Skip to content

Commit 47b6fa6

Browse files
committed
Refactoring and smaller updates.
1 parent b0ab3cc commit 47b6fa6

File tree

11 files changed

+296
-193
lines changed

11 files changed

+296
-193
lines changed

app/dmved.f90

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,14 @@ integer function run(app, tty) result(rc)
246246
type(tty_type), intent(inout) :: tty !! TTY type.
247247

248248
character(len=VE_PRODUCT_NAME_LEN) :: product
249-
character(len=VE_VALUE_LEN) :: serial
250249

251250
character :: byte
252251
integer :: errors(VE_NFIELDS)
253252
integer :: code, field_type, pid
254253
integer(kind=i8) :: epoch_last, epoch_now
255254
logical :: eor, finished, valid
256255
logical :: debug
257-
logical :: has_product, has_receiver, has_serial
256+
logical :: has_product, has_receiver
258257

259258
type(observ_type) :: observ
260259
type(ve_frame_type) :: frame
@@ -267,7 +266,6 @@ integer function run(app, tty) result(rc)
267266
epoch_last = 0_i8
268267
has_product = .false.
269268
has_receiver = (len_trim(app%receiver) > 0)
270-
has_serial = .false.
271269

272270
! Set serial port parameters.
273271
tty%path = app%path
@@ -322,7 +320,7 @@ integer function run(app, tty) result(rc)
322320

323321
! Convert all frames to responses.
324322
call dm_ve_frame_read(frames, responses, error=errors)
325-
if (any(dm_is_error(errors))) call logger%error('failed to convert VE.Direct frame', error=maxval(errors))
323+
if (any(dm_is_error(errors))) call logger%error('failed to convert frame to response', error=maxval(errors))
326324

327325
! Create and forward observation.
328326
call create_observ(observ, app, responses)
@@ -335,31 +333,24 @@ integer function run(app, tty) result(rc)
335333

336334
! VE.Direct frame finished.
337335
if (eor) then
338-
if (frame%label == 'BMV') cycle tty_loop ! Ignore deprecated model description.
339-
if (frame%label == 'ERR') code = dm_atoi(frame%value) ! Save device error.
340-
341-
! Save serial number of device.
342-
if (frame%label == 'SER#' .and. .not. has_serial) then
343-
serial = frame%value
344-
has_serial = .true.
345-
cycle tty_loop
346-
end if
336+
if (frame%label == 'BMV') cycle tty_loop ! Ignore deprecated model description.
337+
if (frame%label == 'SER#') cycle tty_loop ! Ignore serial number string.
338+
if (frame%label == 'ERR') code = dm_atoi(frame%value) ! Save device error.
347339

348340
! Log VE.Direct device error.
349341
if (dm_ve_is_error(code)) then
350342
call logger%warning(dm_ve_error_message(code), error=E_SENSOR)
351343
end if
352344

353-
! Output product name and serial number of connected VE device.
345+
! Output product name of connected VE device.
354346
if (frame%label == 'PID' .and. .not. has_product) then
355347
call dm_hex_to_int(frame%value, pid)
356348
rc = dm_ve_product_name(pid, product)
357349

358350
if (dm_is_error(rc)) then
359351
call logger%warning('connected to unknown Victron Energy device', error=rc)
360352
else
361-
call logger%info('connected to Victron Energy ' // trim(product) // &
362-
' (' // trim(serial) // ')')
353+
call logger%info('connected to Victron Energy ' // product)
363354
end if
364355

365356
has_product = .true.
@@ -369,11 +360,11 @@ integer function run(app, tty) result(rc)
369360
field_type = dm_ve_field_type(frame%label)
370361

371362
if (.not. dm_ve_is_valid_field_type(field_type)) then
372-
call logger%warning('received invalid or unsupported VE.Direct field ' // frame%label, error=rc)
363+
call logger%warning('received invalid or unsupported field ' // frame%label, error=rc)
373364
cycle tty_loop
374365
end if
375366

376-
if (debug) call logger%debug('received VE.Direct field ' // trim(frame%label) // ': ' // frame%value)
367+
if (debug) call logger%debug('received field ' // trim(frame%label) // ': ' // frame%value)
377368

378369
! Save VE.Direct frame.
379370
frames(field_type) = frame

config/dmserial.conf.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ observ_meter = {
9797
receivers = { "dmdb" },
9898
requests = {
9999
{
100-
name = "get_values",
100+
name = "get-values",
101101
request = "Meter\\r",
102102
delimiter = "\\n",
103103
pattern = "^\\s*(?<temp>[-0-9.]+)\\s.C\\s+.t\\s+(?<humrel>[-0-9.]+)\\s%\\s+.t\\s+(?<humabs>[-0-9.]+)\\sg.m3.t\\s+(?<dew>[-0-9.]+)\\s.C\\s+.t\\s+(?<wetbulb>[-0-9.]+)",

src/dm_api_status.f90

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module dm_api_status
3535
public :: dm_api_status_equals
3636
public :: dm_api_status_to_string
3737
contains
38-
integer function dm_api_status_from_string(string, api) result(rc)
38+
integer function dm_api_status_from_string(string, status) result(rc)
3939
!! Reads API status type from given string. Only keys found in the
4040
!! string are overwritten in the derived type. No error is returned if
4141
!! the string does not contain any of the keys.
@@ -50,7 +50,7 @@ integer function dm_api_status_from_string(string, api) result(rc)
5050
integer, parameter :: LINE_LEN = 1 + (API_STATUS_LEN * 2)
5151

5252
character(len=*), intent(in) :: string !! String representation of API status.
53-
type(api_status_type), intent(out) :: api !! Result.
53+
type(api_status_type), intent(out) :: status !! Result.
5454

5555
integer :: i, nlines, npairs
5656
character(len=LINE_LEN) :: lines(API_STATUS_NKEYS)
@@ -73,52 +73,52 @@ integer function dm_api_status_from_string(string, api) result(rc)
7373
call dm_lower(key)
7474

7575
select case (key)
76-
case ('version'); api%version = dm_ascii_escape(value)
77-
case ('dmpack'); api%dmpack = dm_ascii_escape(value)
78-
case ('host'); api%host = dm_ascii_escape(value)
79-
case ('server'); api%server = dm_ascii_escape(value)
80-
case ('timestamp'); api%timestamp = dm_ascii_escape(value)
81-
case ('message'); api%message = dm_ascii_escape(value)
82-
case ('error'); api%error = dm_atoi(value)
76+
case ('version'); status%version = dm_ascii_escape(value)
77+
case ('dmpack'); status%dmpack = dm_ascii_escape(value)
78+
case ('host'); status%host = dm_ascii_escape(value)
79+
case ('server'); status%server = dm_ascii_escape(value)
80+
case ('timestamp'); status%timestamp = dm_ascii_escape(value)
81+
case ('message'); status%message = dm_ascii_escape(value)
82+
case ('error'); status%error = dm_atoi(value)
8383
case default; cycle
8484
end select
8585
end do
8686

8787
rc = E_NONE
8888
end function dm_api_status_from_string
8989

90-
pure elemental logical function dm_api_status_equals(api1, api2) result(equals)
90+
pure elemental logical function dm_api_status_equals(status1, status2) result(equals)
9191
!! Returns `.true.` if given API status types are equal.
92-
type(api_status_type), intent(in) :: api1 !! The first status type.
93-
type(api_status_type), intent(in) :: api2 !! The second status type.
92+
type(api_status_type), intent(in) :: status1 !! The first status type.
93+
type(api_status_type), intent(in) :: status2 !! The second status type.
9494

9595
equals = .false.
96-
if (api1%version /= api2%version) return
97-
if (api1%dmpack /= api2%dmpack) return
98-
if (api1%host /= api2%host) return
99-
if (api1%server /= api2%server) return
100-
if (api1%timestamp /= api2%timestamp) return
101-
if (api1%message /= api2%message) return
102-
if (api1%error /= api2%error) return
96+
if (status1%version /= status2%version) return
97+
if (status1%dmpack /= status2%dmpack) return
98+
if (status1%host /= status2%host) return
99+
if (status1%server /= status2%server) return
100+
if (status1%timestamp /= status2%timestamp) return
101+
if (status1%message /= status2%message) return
102+
if (status1%error /= status2%error) return
103103
equals = .true.
104104
end function dm_api_status_equals
105105

106-
function dm_api_status_to_string(api) result(string)
106+
function dm_api_status_to_string(status) result(string)
107107
!! Returns string representation of given API status type. The string
108108
!! contains new-line characters.
109-
type(api_status_type), intent(inout) :: api !! API status type.
109+
type(api_status_type), intent(inout) :: status !! API status type.
110110
character(len=:), allocatable :: string !! String representation.
111111

112-
string = 'version=' // trim(api%version) // NL // &
113-
'dmpack=' // trim(api%dmpack) // NL // &
114-
'host=' // trim(api%host) // NL // &
115-
'server=' // trim(api%server) // NL // &
116-
'timestamp=' // trim(api%timestamp)
112+
string = 'version=' // trim(status%version) // NL // &
113+
'dmpack=' // trim(status%dmpack) // NL // &
114+
'host=' // trim(status%host) // NL // &
115+
'server=' // trim(status%server) // NL // &
116+
'timestamp=' // trim(status%timestamp)
117117

118-
if (len_trim(api%message) > 0) then
119-
string = string // NL // 'message=' // trim(api%message)
118+
if (len_trim(status%message) > 0) then
119+
string = string // NL // 'message=' // trim(status%message)
120120
end if
121121

122-
string = string // NL // 'error=' // dm_itoa(api%error)
122+
string = string // NL // 'error=' // dm_itoa(status%error)
123123
end function dm_api_status_to_string
124124
end module dm_api_status

src/dm_modbus_type.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ pure integer function dm_modbus_float_from_name(name) result(float)
9090
end function dm_modbus_float_from_name
9191

9292
pure elemental logical function dm_modbus_is_float(float) result(valid)
93-
!! Returns `.true.` if argument is valid a float byte order enumerator.
94-
!! `MODBUS_FLOAT_NONE` is invalid.
93+
!! Returns `.true.` if argument is a valid float byte order enumerator.
94+
!! `MODBUS_FLOAT_NONE` is not a float.
9595
integer, intent(in) :: float !! Modbus float enumerator.
9696

9797
valid = (float == MODBUS_FLOAT_ABCD .or. &

0 commit comments

Comments
 (0)