Skip to content
Snippets Groups Projects
Commit ebbb9a64 authored by JuanPi Carbajal's avatar JuanPi Carbajal
Browse files

serial and html: get logger configuration as serial command, adapt html ui to use it.

parent 30fe2759
No related branches found
No related tags found
No related merge requests found
Pipeline #238411 passed
......@@ -22,20 +22,14 @@ import pandas as pd
try:
from . import serialui as sui
from .logger import channel_idx
except ImportError:
import serialui as sui
from logger import channel_idx
datetime_fmt = '%a %b %d %H:%M:%S.%f %Y %Z'
""" Date and Time format on the UI """
channel_idx = dict(
adc_in8_name=0,
adc_in9_name=1,
adc_in10_name=2,
adc_in11_name=3
)
""" Mapping from internal channel name to channel index """
defaults = dict(
sampling_interval=10,
interval_units='T',
......@@ -177,27 +171,10 @@ def get_config_logger():
if not sui.wbsLogger.is_open:
sui.wbsLogger.open()
# get data
volt, count = sui.get_battery_configuration()
interval, units = sui.get_sampling_interval()
config_dict = dict(
device_name=sui.get_device_name(),
sampling_interval=str(interval),
interval_units=units,
auto_sampleStatus=sui.get_auto_sampling(),
samples_count=sui.get_sample_count(),
battery_cell_voltage=volt,
battery_cell_count=count,
firmware_version=sui.get_firmware_version(),
unique_id=sui.get_unique_id(),
rtc_now=sui.get_datetime().strftime(datetime_fmt), # print time in LOCALE
serial_port=sui.wbsLogger.port,
)
# channel names
ch_name = sui.get_analog_channel_name()
for ch, idx in channel_idx.items():
config_dict[ch] = ch_name[idx]
# get configuration
config_dict = sui.get_configuration()
config_dict['sampling_interval'] = str(config_dict['sampling_interval'])
config_dict['rtc_now'] = config_dict['rtc_now'].strftime(datetime_fmt)
return config_dict
......
"""
Logger basic configuration and other miscellaneous definitions
"""
import datetime
import re
import string
from pathlib import Path
from collections import namedtuple
import yaml
from flask import Flask, flash, render_template, request, url_for, redirect
from werkzeug.utils import secure_filename
channel_idx = dict(
adc_in8_name=0,
adc_in9_name=1,
adc_in10_name=2,
adc_in11_name=3
)
""" Mapping from internal channel name to channel index """
datetime_fmt_rtc_set = '%Y.%m.%d %u %H:%M:%S'
datetime_fmt_rtc_get = '%Y.%m.%d %u %H:%M:%S.%f'
""" RTC datetime format string
See https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
for information about the format string.
"""
datetime_fmt_sample = '%Y.%m.%d %H:%M:%S.%f'
""" Datetime format of logger sample """
......@@ -46,14 +46,17 @@ import datetime
import re
from pkg_resources import packaging
from string import Template
from time import sleep
from itertools import chain
from collections import namedtuple
try:
from .commands import ActionDict, SetterDict, GetterDict
from .logger import (datetime_fmt_rtc_set, datetime_fmt_rtc_get,
datetime_fmt_sample, channel_idx)
except ImportError:
from commands import ActionDict, SetterDict, GetterDict
from logger import (datetime_fmt_rtc_set, datetime_fmt_rtc_get,
datetime_fmt_sample, channel_idx)
import serial
import serial.tools.list_ports as slp
......@@ -318,8 +321,9 @@ def get_analog_channel_name(*, channel=None):
Parameters
----------
channel: :class:`int` or :class:`str`
channel: :class:`int` or :class:`str` or None
Channel number to read. Valid values: 0-3
If None (default) then all channel names are retrieved.
Returns
-------
......@@ -351,15 +355,6 @@ def get_analog_channel_name(*, channel=None):
return ch_name
datetime_fmt_rtc_set = '%Y.%m.%d %u %H:%M:%S'
datetime_fmt_rtc_get = '%Y.%m.%d %u %H:%M:%S.%f'
""" RTC datetime format string
See https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
for information about the format string.
"""
def parse_datetime(dt_str, *, fmt):
""" Parse datetime string into datetime.
......@@ -387,8 +382,6 @@ LoggerSample = namedtuple('LoggerSample', ['datetime',
'adc_in9'])
""" Inmutable logger sample container. """
datetime_fmt_sample = '%Y.%m.%d %H:%M:%S.%f'
""" Datetime format of looger sample """
sample_typecast = LoggerSample(*([lambda u: parse_datetime(u, fmt=datetime_fmt_sample),
lambda u: u == '1'] + [float]*6))
......@@ -458,6 +451,46 @@ def get_datetime():
fmt=datetime_fmt_rtc_get)
def get_configuration():
""" Get current logger configuration.
The current configuration might not be stored to the non-volatile
memory of the logger.
Returns
-------
:class:`dict`
Current logger configurationDate and time
See also
--------
:func:`~.store_configuration()`
Make current configuration permanent (non-volatile).
"""
volt, count = get_battery_configuration()
interval, units = get_sampling_interval()
config_dict = dict(
device_name=get_device_name(),
sampling_interval=interval,
interval_units=units,
auto_sampleStatus=get_auto_sampling(),
samples_count=get_sample_count(),
battery_cell_voltage=volt,
battery_cell_count=count,
firmware_version=get_firmware_version(),
unique_id=get_unique_id(),
rtc_now=get_datetime(), # print time in LOCALE
serial_port=wbsLogger.port,
)
# channel names
ch_name = get_analog_channel_name()
for ch, idx in channel_idx.items():
config_dict[ch] = ch_name[idx]
return config_dict
# -------------
# Setters
# -------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment