Esempio n. 1
0
def unpackParameter(paramId, dataLength, msg, nodeParams):
    for case in switch(paramId):
        if case(ParamId.nodeId):
            if (dataLength == 1):
                value = unpackBytes('=B', msg)[0][0]
                return nodeParams.config.updateParameter(paramId, value)
            break
        if case(ParamId.parseMsgMax):
            if (dataLength == 2):
                value = unpackBytes('=H', msg)[0][0]
                return nodeParams.config.updateParameter(paramId, value)
            break
        else:
            return False
    def test_unpackBytes(self):
        """Test unpackBytes method."""
        # Test processing of equal size message
        msg = b'12345'
        fmt = '=BBBBB'
        out = unpackBytes(fmt, msg)
        assert (len(out) == calcsize(fmt))
        #assert(len(out[1]) == 0) # no excess bytes

        # Test processing of short message
        fmt = '=BBBBBB'
        with pytest.raises(InsufficientMsgBytes) as e:
            out = unpackBytes(fmt, msg)

        # Test processing of long message
        fmt = '=BBBB'
        out = unpackBytes(fmt, msg)
        assert (len(out) == calcsize(fmt))
Esempio n. 3
0
 def test_parseBody(self):
     """Test parsing body from serial message bytes."""
     bodyEntries = unpackBytes(self.bodyFormat, self.msgBytes[len(self.headerBytes):])
     body = parseBody(bodyEntries, self.cmdId)
     self.checkBodyEntries(body)
Esempio n. 4
0
 def test_parseHeader(self):
     """Test parsing header from serial message bytes."""
     headerEntries = unpackBytes(self.headerFormat, self.msgBytes[0:len(self.headerBytes)])
     #header = parseHeader([self.msgBytes[0:len(self.headerBytes)],[]], self.cmdId)
     header = parseHeader(headerEntries, self.cmdId)
     self.checkHeaderEntries(header)