11from dataclasses import dataclass
22
3+ from datetime import datetime
34import fcntl
45import ctypes
56import errno
@@ -164,14 +165,16 @@ class EventDescriptor:
164165
165166
166167class Event :
168+ timestamp : datetime
167169 target_category : int
168170 target_id : int
169171 command_id : int
170172 instance_id : int
171173 data : bytes
172174
173- def __init__ (self , target_category , target_id , command_id , instance_id ,
174- data = bytes ()):
175+ def __init__ (self , timestamp , target_category , target_id , command_id ,
176+ instance_id , data = bytes ()):
177+ self .timestamp = timestamp
175178 self .target_category = target_category
176179 self .target_id = target_id
177180 self .command_id = command_id
@@ -180,6 +183,7 @@ def __init__(self, target_category, target_id, command_id, instance_id,
180183
181184 def __repr__ (self ):
182185 return f"Event {{ " \
186+ f"time={ self .timestamp .strftime ('%H:%M:%S.%f' )} , " \
183187 f"tc={ self .target_category :02x} , " \
184188 f"tid={ self .target_id :02x} , " \
185189 f"cid={ self .command_id :02x} , " \
@@ -188,6 +192,7 @@ def __repr__(self):
188192
189193 def to_dict (self ):
190194 return {
195+ "time" : self .timestamp .strftime ('%H:%M:%S.%f' ),
191196 "tc" : self .target_category ,
192197 "tid" : self .target_id ,
193198 "cid" : self .command_id ,
@@ -321,8 +326,8 @@ def _event_read_blocking(fd):
321326 while len (data ) < hdr .length :
322327 data += os .read (fd , hdr .length - len (data ))
323328
324- return Event (hdr . target_category , hdr .target_id , hdr .command_id ,
325- hdr .instance_id , data )
329+ return Event (datetime . now () , hdr .target_category , hdr .target_id ,
330+ hdr .command_id , hdr . instance_id , data )
326331
327332
328333class Controller :
0 commit comments