Subversion Repositories HomeAutomation

Rev

Rev 746 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 746 Rev 752
Line 2... Line 2...
2
#
2
#
3
# This class represents a can packet which should be
3
# This class represents a can packet which should be
4
# identifiable by its type and contents
4
# identifiable by its type and contents
5
#
5
#
6
###########################################################
6
###########################################################
-
 
7
import logging as log
7
 
8
 
8
class CanPkt:
9
class CanPkt:
9
   
10
   
10
    STANDARD_ID_MASK = 0x1FF
11
    STANDARD_ID_MASK = 0x1FF
11
    EXTENDED_ID_MASK = 0x1FFFFFFF
12
    EXTENDED_ID_MASK = 0x1FFFFFFF
Line 42... Line 43...
42
        return (strpkt + bytestrings)
43
        return (strpkt + bytestrings)
43
   
44
   
44
    @staticmethod
45
    @staticmethod
45
    def stringToCanPkt(self, str):
46
    def stringToCanPkt(self, str):
46
        """ Converts can message string to CanPkt class """
47
        """ Converts can message string to CanPkt class """
-
 
48
        if len(str) > 40:
-
 
49
            str = str[:40]
-
 
50
            log.debug('WARNING: Oversized string packet truncated to: ' + str)
-
 
51
 
47
        strbyteslist = str.split(' ')
52
        strbyteslist = str.split(' ')
48
        nodeid = int('0x'+strbyteslist[1], 16)
53
        nodeid = int('0x'+strbyteslist[1], 16)
49
        intvalues = [int(val, 16) for val in strbyteslist[2:]]
54
        intvalues = [int(val, 16) for val in strbyteslist[2:]]
50
        extended = (intvalues[0] == 1)
55
        extended = (intvalues[0] == 1)
51
        remote = (intvalues[1] == 1)
56
        remote = (intvalues[1] == 1)
52
        pkt = CanPkt(nodeid, intvalues[2:], extended, remote)
57
        pkt = CanPkt(nodeid, intvalues[2:], extended, remote)
53
        return pkt
58
        return pkt
54
 
-
 
55
   
59