Skip to content

Commit

Permalink
fix: fix timestamp inconsistencies between Windows and Linux (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
TedRio committed Mar 4, 2024
1 parent a42daaf commit 013cbe9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/pykiso/lib/connectors/cc_pcan_can/cc_pcan_can.py
Expand Up @@ -34,6 +34,16 @@
except ImportError as e:
raise ImportError(f"{e.name} dependency missing, consider installing pykiso with 'pip install pykiso[can]'")

try:
# use to avoid timestamp inconsistances between pykiso and python can
import uptime

if uptime.boottime() is None:
boottime_epoch = 0
else:
boottime_epoch = uptime.boottime().timestamp()
except ImportError:
boottime_epoch = 0

from pykiso import CChannel

Expand Down Expand Up @@ -152,6 +162,7 @@ def __init__(
# In case of a multi-threading system, all tasks will be called one after the other.
self.timeout = 1e-6
self.trc_count = 0
self.boottime_epoch = boottime_epoch
self._initialize_trace()

if bus_error_warning_filter:
Expand Down Expand Up @@ -358,7 +369,7 @@ def _cc_receive(self, timeout: float = 0.0001) -> Dict[str, Union[bytes, int, No
if received_msg is not None:
frame_id = received_msg.arbitration_id
payload = received_msg.data
timestamp = received_msg.timestamp
timestamp = received_msg.timestamp - self.boottime_epoch

log.internal_debug(
"received CAN Message: %s, %s, %s",
Expand Down
19 changes: 8 additions & 11 deletions tests/test_cc_pcan_can.py
Expand Up @@ -22,18 +22,9 @@

from pykiso import Message
from pykiso.lib.connectors.cc_pcan_can import cc_pcan_can
from pykiso.lib.connectors.cc_pcan_can.cc_pcan_can import (
CCPCanCan,
PCANBasic,
can,
)
from pykiso.lib.connectors.cc_pcan_can.cc_pcan_can import CCPCanCan, PCANBasic, can
from pykiso.lib.connectors.cc_pcan_can.trc_handler import TRCReaderCanFD
from pykiso.message import (
MessageAckType,
MessageCommandType,
MessageType,
TlvKnownTags,
)
from pykiso.message import MessageAckType, MessageCommandType, MessageType, TlvKnownTags

tlv_dict_to_send = {
TlvKnownTags.TEST_REPORT: "OK",
Expand Down Expand Up @@ -274,6 +265,12 @@ def test_import():
importlib.reload(cc_pcan_can)


def test_import_uptime():
sys.modules["uptime"] = None
importlib.reload(cc_pcan_can)
assert cc_pcan_can.boottime_epoch == 0


@pytest.mark.parametrize(
"constructor_params, expected_config",
[
Expand Down

0 comments on commit 013cbe9

Please sign in to comment.