Skip to content

Commit

Permalink
feat: Pass status event as a parameter to start servers. Reduce check…
Browse files Browse the repository at this point in the history
… status delay to 10 mS
  • Loading branch information
santiagosalamandri committed Oct 17, 2022
1 parent 8d260e2 commit d596370
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions iso15118/secc/comm_session_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
from asyncio.streams import StreamReader, StreamWriter
from typing import Dict, List, Optional, Tuple, Union

from iso15118.secc.controller.interface import (
EVSEControllerInterface,
EVSEServiceStatus,
)
from iso15118.secc.controller.interface import EVSEControllerInterface, ServiceStatus
from iso15118.secc.failed_responses import (
init_failed_responses_din_spec_70121,
init_failed_responses_iso_v2,
Expand Down Expand Up @@ -195,21 +192,24 @@ async def __init__.
"""

self.udp_server = UDPServer(self._rcv_queue, self.config.iface)
self.status_event_list.append(self.udp_server.ready_event)
udp_ready_event: asyncio.Event = asyncio.Event()
self.status_event_list.append(udp_ready_event)

self.tcp_server = TCPServer(self._rcv_queue, self.config.iface)
self.status_event_list.append(self.tcp_server.tls_ready_event)
tls_ready_event: asyncio.Event = asyncio.Event()
self.status_event_list.append(tls_ready_event)

self.list_of_tasks = [
self.get_from_rcv_queue(self._rcv_queue),
self.udp_server.start(),
self.tcp_server.start_tls(),
self.udp_server.start(udp_ready_event),
self.tcp_server.start_tls(tls_ready_event),
self.check_status_task(),
]

if not self.config.enforce_tls:
self.list_of_tasks.append(self.tcp_server.start_no_tls())
self.status_event_list.append(self.tcp_server.tcp_ready_event)
tcp_ready_event: asyncio.Event = asyncio.Event()
self.status_event_list.append(tcp_ready_event)
self.list_of_tasks.append(self.tcp_server.start_no_tls(tcp_ready_event))

logger.info("Communication session handler started")

Expand All @@ -226,15 +226,15 @@ def check_events(self) -> bool:
async def check_ready_status(self) -> None:
# Wait until all flags are set
while self.check_events() is False:
await asyncio.sleep(0.1)
await asyncio.sleep(0.01)

async def check_status_task(self) -> None:
try:
await asyncio.wait_for(self.check_ready_status(), timeout=10)
await self.evse_controller.set_status(EVSEServiceStatus.READY)
await self.evse_controller.set_status(ServiceStatus.READY)
except asyncio.TimeoutError:
logger.error("Timeout: Servers failed to startup")
await self.evse_controller.set_status(EVSEServiceStatus.ERROR)
await self.evse_controller.set_status(ServiceStatus.ERROR)

async def get_from_rcv_queue(self, queue: asyncio.Queue):
"""
Expand Down

0 comments on commit d596370

Please sign in to comment.