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

Fix stop for cu_manager #84

Merged
merged 2 commits into from
Dec 21, 2023
Merged
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
10 changes: 6 additions & 4 deletions code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
####################### ENUMS #######################

####################### CLASSES #######################
class CuManagerNodeC(SysShdNodeC): # pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-instance-attributes
class CuManagerNodeC(SysShdNodeC):
'''
Cu Manager Class to instanciate a CU Manager Node
'''
Expand Down Expand Up @@ -198,15 +199,16 @@ def process_iteration(self) -> None:
self.process_heartbeat()
self.process_cycler_deploy_processes()


def sync_shd_data(self) -> None:
'''Sync shared data with the sync node.
'''


def stop(self) -> None:
'''Stop the stream .
'''
Stop the stream .
'''
log.critical("Stopping CU_Manager...")
self.client_mqtt.close()
self.detector.close()

####################### FUNCTIONS #######################
17 changes: 13 additions & 4 deletions code/cu_manager/src/wattrex_cycler_cu_manager/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ def process_detection(self) -> List[CommDataDeviceC]:
self.__tx_can.send_data(DrvCanCmdDataC(data_type= DrvCanCmdTypeE.REMOVE_FILTER,
payload= DrvCanFilterC(addr= 0x000, mask= 0x000,
chan_name=DEFAULT_RX_CAN_NAME)))
## Closing conections with queues
self.__tx_can.close()
self.__tx_scpi.close()
self.__rx_can.terminate()
return self.det_bms + self.det_epc + self.det_ea + self.det_rs + self.det_flow

def __reset_detected(self) -> None:
Expand Down Expand Up @@ -271,3 +267,16 @@ def __parse_epc_msg(self, msg: DrvCanMessageC) -> Tuple[int, str, bitarray]:
# The last bits correspond to the serial number
serial_number = str(ba2int(msg_bits[24:32]))
return can_id, serial_number, hw_ver

def close(self) -> None:
'''
Close used ipc channels
'''
## Closing conections with queues
if isinstance(self.__tx_can, SysShdIpcChanC):
self.__tx_can.close()
if isinstance(self.__tx_scpi, SysShdIpcChanC):
self.__tx_scpi.close()
if isinstance(self.__rx_can, SysShdIpcChanC):
self.__rx_can.terminate()
log.critical("Closing channels used by detector")
17 changes: 17 additions & 0 deletions devops/cu_manager/run_cu_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
####################### GENERIC IMPORTS #######################
import sys, os
import threading
from signal import signal, SIGINT

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

Expand All @@ -19,6 +20,8 @@
log: Logger = sys_log_logger_get_module_logger(__name__)

####################### MODULE IMPORTS #######################
# sys.path.append(os.getcwd()+'/code/cu_manager/')
# from src.wattrex_cycler_cu_manager import CuManagerNodeC
from wattrex_cycler_cu_manager import CuManagerNodeC

####################### PROJECT IMPORTS #######################
Expand All @@ -28,11 +31,25 @@
####################### CLASSES #######################

####################### FUNCTIONS #######################
cu_manager_node = None

def signal_handler(sig, frame) -> None: #pylint: disable= unused-argument
"""Called when the user presses Ctrl + C to stop test.

Args:
sig ([type]): [description]
frame ([type]): [description]
"""
if isinstance(cu_manager_node, CuManagerNodeC):
log.critical(msg='You pressed Ctrl+C! Stopping test...')
cu_manager_node.stop()
sys.exit(0)

if __name__ == '__main__':
working_flag_event : threading.Event = threading.Event()
working_flag_event.set()
cu_manager_node = CuManagerNodeC(working_flag=working_flag_event,
cycle_period=1000,
cu_id_file_path='./devops/cu_manager/.cu_id')
signal(SIGINT, signal_handler)
cu_manager_node.run()
5 changes: 3 additions & 2 deletions devops/cycler/run_cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
log.critical(f'CS_ID: {CS_ID}')

####################### MODULE IMPORTS #######################
sys.path.append(os.getcwd()+'/code/cycler/')
from src.wattrex_battery_cycler.app.app_man import AppManNodeC
# sys.path.append(os.getcwd()+'/code/cycler/')
# from src.wattrex_battery_cycler.app.app_man import AppManNodeC
from wattrex_battery_cycler.app.app_man import AppManNodeC

####################### PROJECT IMPORTS #######################

Expand Down
7 changes: 4 additions & 3 deletions devops/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export GROUP_ID=$(id -g)

initial_deploy () {
force_stop
python3 -m pip install can-sniffer
python3 -m pip install SCPI-sniffer
python3 -m pip install --upgrade can-sniffer
python3 -m pip install --upgrade SCPI-sniffer
python3 -m pip install --upgrade wattrex-cycler-cu-manager
mkdir -p "${REPO_ROOT_DIR}/log"

docker compose ${DOCKER_COMPOSE_ARGS} up cache_db db_sync -d
Expand All @@ -33,7 +34,7 @@ instance_new_cycler () {
check_sniffer "scpi"
export CYCLER_TARGET=cycler_prod

docker compose ${DOCKER_COMPOSE_ARGS} build --build-arg UPDATE_REQS=$(date +%s) cycler
#docker compose ${DOCKER_COMPOSE_ARGS} build --build-arg UPDATE_REQS=$(date +%s) cycler
docker compose ${DOCKER_COMPOSE_ARGS} run -d -e CSID=${1} --name wattrex_cycler_node_${1} cycler
}

Expand Down