Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanMessage.py
More file actions
Latest commit
37 lines (28 loc) · 982 Bytes
/
Copy pathCanMessage.py
File metadata and controls
37 lines (28 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
importjson
importlogging
log=logging.getLogger(__name__)
classCanMessage(object):
def__init__(self):
self.last_revid=0
self.memory_file='last_revid.json'
try:
withopen(self.memory_file) asfile_handle:
self.last_revid=json.load(file_handle)
exceptExceptionasex:
# TODO: empty file or no file at all, get the proper error
pass
log.debug("initialized with %s as the last revid", self.last_revid)
defcan_send(self, revid):
returnrevid>self.last_revid
defset_last_revid(self, revid):
self.last_revid=revid
defsave(self):
log.debug("saving")
withopen(self.memory_file, 'w') asfile_handle:
json.dump(self.last_revid, file_handle)
if__name__=='__main__':
can_message=CanMessage()
ifcan_message.can_send(124):
print('OK')
can_message.set_last_revid(124)
can_message.save()