Beispiel #1
0
def createSetValuesPDU(header, parameter=[], references=[]):
    if not isinstance(header, Header):
        raise TypeError('Parameter "header" must be of type "Header".')

    length = 2
    pdu = []

    if parameter:
        parameterAPDU = createSetParametersAPDU(parameter)
        length += len(parameterAPDU)

    if references:
        referencesAPDU = createSetReferencesAPDU(references)
        length += len(referencesAPDU)

    pdu.extend(
        [header.startDelimiter, length, header.destAddr, header.sourceAddr])

    if parameter:
        pdu.extend(parameterAPDU)

    if references:
        pdu.extend(referencesAPDU)

    crc = wordToBytes(calcuteCrc(pdu))
    pdu.extend(crc)

    #arr = array.array('B', pdu)
    # TODO: arr.tostring() for I/O!
    return array('B', pdu)
Beispiel #2
0
def createGetValuesPDU(klass,
                       header,
                       protocolData=[],
                       measurements=[],
                       parameter=[],
                       references=[],
                       strings=[]):
    if not isinstance(header, Header):
        raise TypeError('Parameter "header" must be of type "Header".')

    length = 2
    pdu = []

    if protocolData:
        protocolAPDU = createGetProtocolDataAPDU(protocolData)
        length += len(protocolAPDU)

    if measurements:
        measurementAPDU = createGetMeasuredDataAPDU(klass, measurements)
        length += len(measurementAPDU)

    if parameter:
        parameterAPDU = createGetParametersAPDU(parameter)
        length += len(parameterAPDU)

    if references:
        referencesAPDU = createGetReferencesAPDU(references)
        length += len(referencesAPDU)

    if strings:
        stringsAPDU = createGetStringsAPDU(strings)
        length += len(stringsAPDU)

    pdu.extend(
        [header.startDelimiter, length, header.destAddr, header.sourceAddr])

    if protocolData:
        pdu.extend(protocolAPDU)

    if parameter:
        pdu.extend(parameterAPDU)

    if measurements:
        pdu.extend(measurementAPDU)

    if references:
        pdu.extend(referencesAPDU)

    if strings:
        pdu.extend(stringsAPDU)

    crc = wordToBytes(calcuteCrc(pdu))
    pdu.extend(crc)

    return array('B', pdu)
Beispiel #3
0
def createGetInfoPDU(klass,
                     header,
                     measurements=[],
                     parameter=[],
                     references=[]):
    ## To be defensive, at most 15 datapoints should be requested at once (min.frame length = 70 bytes).
    if not isinstance(header, Header):
        raise TypeError('Parameter "header" must be of type "Header".')

    length = 2
    pdu = []
    if measurements:
        if klass == defs.APDUClass.MEASURED_DATA:
            measurementsAPDU = createGetInfoAPDU(defs.APDUClass.MEASURED_DATA,
                                                 measurements)
        if klass == defs.APDUClass.SIXTEENBIT_MEASURED_DATA:
            measurementsAPDU = createGetInfoAPDU(
                defs.APDUClass.SIXTEENBIT_MEASURED_DATA, measurements)
        length += len(measurementsAPDU)

    if parameter:
        parameterAPDU = createGetInfoAPDU(
            defs.APDUClass.CONFIGURATION_PARAMETERS, parameter)
        length += len(parameterAPDU)

    if references:
        referencesAPDU = createGetInfoAPDU(defs.APDUClass.REFERENCE_VALUES,
                                           references)
        length += len(referencesAPDU)

    pdu.extend(
        [header.startDelimiter, length, header.destAddr, header.sourceAddr])

    if measurements:
        pdu.extend(measurementsAPDU)

    if parameter:
        pdu.extend(parameterAPDU)

    if references:
        pdu.extend(referencesAPDU)

    crc = wordToBytes(calcuteCrc(pdu))
    pdu.extend(crc)

    return array('B', pdu)
Beispiel #4
0
def createSetCommandsPDU(header, commands):
    if not isinstance(header, Header):
        raise TypeError('Parameter "header" must be of type "Header".')

    length = 2
    pdu = []

    commandsAPDU = createSetCommandsAPDU(commands)
    length += len(commandsAPDU)

    pdu.extend(
        [header.startDelimiter, length, header.destAddr, header.sourceAddr])

    pdu.extend(commandsAPDU)

    crc = wordToBytes(calcuteCrc(pdu))
    pdu.extend(crc)

    return array('B', pdu)
Beispiel #5
0
 def test06(self):
     self.assertEqual(calcuteCrc(TEST_VECTORS[5]), RESULTS[5])