Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drv flow #81

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions code/drv_flow/src/wattrex_driver_flow/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/python3
'''
This module manages the constants variables.
Those variables are used in the scripts inside the module and can be modified
in a config yaml file specified in the environment variable with name declared
in system_config_tool.
'''

####################### MANDATORY IMPORTS #######################
from __future__ import annotations
####################### GENERIC IMPORTS #######################

####################### SYSTEM ABSTRACTION IMPORTS #######################
from system_logger_tool import Logger, sys_log_logger_get_module_logger
log: Logger = sys_log_logger_get_module_logger(__name__)

####################### THIRD PARTY IMPORTS #######################

####################### PROJECT IMPORTS #######################
from system_config_tool import sys_conf_update_config_params

####################### MODULE IMPORTS #######################

###################### CONSTANTS ######################
# For further information check out README.md
DEFAULT_MAX_WAIT_TIME : int = 3
DEFAULT_TIME_BETWEEN_ATTEMPTS : float = 0.1
DEFAULT_TIMEOUT_REC : float = 0.1
DEFAULT_MAX_MSG : int = 100 # Max number of allowed message per chan
DEFAULT_MAX_MESSAGE_SIZE : int = 300 # Size of message sent through IPC message queue
DEFAULT_TX_CHAN : str = 'TX_SCPI' # Name of the TX channel in CAN
DEFAULT_RX_CHAN : str = 'RX_SCPI_FLOW' #Name of the RX channel for epc



CONSTANTS_NAMES = ('DEFAULT_MAX_WAIT_TIME', 'DEFAULT_TIME_BETWEEN_ATTEMPTS',
'DEFAULT_MAX_MSG', 'DEFAULT_MAX_MESSAGE_SIZE',
'DEFAULT_TX_CHAN', 'DEFAULT_RX_CHAN',
'DEFAULT_TIMEOUT_REC')
sys_conf_update_config_params(context=globals(),
constants_names=CONSTANTS_NAMES)
25 changes: 11 additions & 14 deletions code/drv_flow/src/wattrex_driver_flow/drv_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
from wattrex_driver_base import DrvBaseStatusE, DrvBaseStatusC

####################### MODULE IMPORTS #######################

###################### CONSTANTS ######################
from .context import (DEFAULT_MAX_WAIT_TIME, DEFAULT_TIME_BETWEEN_ATTEMPTS, DEFAULT_TIMEOUT_REC,
DEFAULT_MAX_MSG, DEFAULT_MAX_MESSAGE_SIZE, DEFAULT_RX_CHAN, DEFAULT_TX_CHAN)
####################### ENUMS #######################
_MAX_WAIT_TIME = 3
_TIME_BETWEEN_ATTEMPTS = 0.1
_TIMEOUT_REC = 0.1
_MAX_MSG = 100
_MAX_MESSAGE_SIZE = 300

class _ScpiCmds(Enum):
"Modes of the device"
Expand Down Expand Up @@ -70,7 +67,7 @@ def __str__(self) -> str:

class DrvFlowDeviceC():
"Principal class of flowmeter"
def __init__(self, config: DrvScpiSerialConfC, rx_chan_name: str) -> None:
def __init__(self, config: DrvScpiSerialConfC, rx_chan_name: str= DEFAULT_RX_CHAN) -> None:
'''
Args:
- config (DrvScpiSerialConfC): Configuration of the serial port.
Expand All @@ -79,10 +76,10 @@ def __init__(self, config: DrvScpiSerialConfC, rx_chan_name: str) -> None:
'''
self.__device_id: int = 0
self.__firmware_version: int = 0
self.__tx_chan = SysShdIpcChanC(name = 'tx_scpi')
self.__rx_chan = SysShdIpcChanC(name = rx_chan_name,
max_msg = _MAX_MSG,
max_message_size= _MAX_MESSAGE_SIZE)
self.__tx_chan = SysShdIpcChanC(name = DEFAULT_TX_CHAN)
self.__rx_chan = SysShdIpcChanC(name = rx_chan_name+'_'+config.port,
max_msg = DEFAULT_MAX_MSG,
max_message_size= DEFAULT_MAX_MESSAGE_SIZE)
self.__port = config.port

add_msg = DrvScpiCmdDataC(data_type = DrvScpiCmdTypeE.ADD_DEV,
Expand Down Expand Up @@ -124,8 +121,8 @@ def __read_device_properties(self) -> None:

# Wait until receive the message
time_init = time()
while (time() - time_init) < _MAX_WAIT_TIME:
sleep(_TIME_BETWEEN_ATTEMPTS)
while (time() - time_init) < DEFAULT_MAX_WAIT_TIME:
sleep(DEFAULT_TIME_BETWEEN_ATTEMPTS)
if not self.__rx_chan.is_empty():
command_rec : DrvScpiCmdDataC = self.__rx_chan.receive_data()
msg = command_rec.payload[0]
Expand Down Expand Up @@ -160,7 +157,7 @@ def get_data(self) -> DrvFlowDataC:
self.__wait_4_response = True
else:
if not self.__rx_chan.is_empty():
data : DrvScpiCmdDataC = self.__rx_chan.receive_data(timeout = _TIMEOUT_REC)
data : DrvScpiCmdDataC = self.__rx_chan.receive_data(timeout = DEFAULT_TIMEOUT_REC)
msg_received = data.payload[0]
self.__wait_4_response = False
if len(msg_received) > 0 and ('ERROR' not in msg_received) and \
Expand Down