示例#1
0
    def sessionPlayback(self, pbSessionID, dump=False):
        """
            Playback a recorded session.

            :param pbSessionID: Recorded session identifier.
            :param dump: True, to dump recorded data to file. False, to skip.
            :return: Number of data retrieved.
        """
        self.core.sendCommand(SubSystem.Storage, Commands.Storage.Playback, True, sessionID=pbSessionID)
        logging.debug('Sent the start playback command, waiting for response...')
        # wait for confirmation
        self.core.waitForAck(SubSystem.Storage, Commands.Storage.Playback)
        packet = self.core.waitForPacket(PacketType.RegularResponse, SubSystem.Storage, Commands.Storage.Playback)
        if packet.header.packetType == PacketType.ErrorLogResp:
            logging.error('Playback failed due to an invalid session number request!')
            return 0
        else:
            pbSessionID = packet.data.sessionID
            logging.info('Playback routine started from session number {0}'.format(pbSessionID))
            packetList = self.core.storePacketsUntil(PacketType.RegularResponse, SubSystem.Storage,
                                                     Commands.Storage.Playback)
            logging.info('Finished playback from session number {0}!'.format(pbSessionID))
            if dump:
                logging.info('Saving dump file. Waiting for completion...')
                NebUtilities.saveFlashPlayback(pbSessionID, packetList)
                logging.info('Dump file saving completed.')
            return len(packetList)
 def __init__(self, subSystem, commandType, enable=True, **kwargs):
     # Logic for determining which type of command packet it is based on the header
     if subSystem == SubSystem.Debug and commandType == Commands.Debug.UnitTestMotionData:
         self.data = NebUnitTestMotionDataCommandData(kwargs['timestamp'], kwargs['accel'],\
                                                      kwargs['gyro'], kwargs['mag'])
     elif subSystem == SubSystem.Debug and commandType == Commands.Debug.InterfaceState:
         self.data = NebDataPortState(enable, kwargs['interface'])
     elif subSystem == SubSystem.Motion and commandType == Commands.Motion.Downsample:
         self.data = NebDownsampleCommandData(enable)
     elif subSystem == SubSystem.Motion and commandType == Commands.Motion.AccRange:
         self.data = NebAccRangeCommandData(enable)
     elif subSystem == SubSystem.Storage and commandType == Commands.Storage.Playback :
         self.data = NebFlashPlaybackCommandData(enable, kwargs['sessionID'])
     elif subSystem == SubSystem.Storage and commandType == Commands.Storage.SessionInfo:
         self.data = NebFlashSessionInfoCommandData(kwargs['sessionID'])
     elif subSystem == SubSystem.EEPROM:
         if commandType == Commands.EEPROM.Read:
             self.data = NebEEPROMCommandData(False, kwargs['pageNumber'])
         elif commandType == Commands.EEPROM.Write :
             self.data = NebEEPROMCommandData(True, kwargs['pageNumber'], kwargs['dataBytes'])
     elif subSystem == SubSystem.LED and commandType == Commands.LED.SetVal:
         self.data = NebSetLEDCommandData(kwargs['ledValueTupleList'])
     elif subSystem == SubSystem.LED and commandType == Commands.LED.GetVal:
         self.data = NebGetLEDCommandData(kwargs['ledIndices'])
     else:
         self.data = NebCommandData(enable)
     self.header = NebHeader(subSystem, PacketType.Command, commandType, length=len(self.data.encode()))
     # Perform CRC calculation
     self.header.crc = nebUtilities.crc8(bytearray(self.header.encode() + self.data.encode()))
示例#3
0
    def __init__(self, packetString=None, header=None, data=None, checkCRC=True):
        if (packetString != None):
            # Sanity check
            packetStringLength = len(packetString)
            if (packetStringLength < 4):
                raise InvalidPacketFormatError( \
                    'Impossible packet, must have a packet of at least 4 bytes but got {0}' \
                        .format(packetStringLength))

            # The string can either be bytes or an actual string
            # Force it to a string if that is the case.
            if (type(packetString) == str):
                packetString = packetString.encode('iso-8859-1')

            # Extract the header information
            self.headerLength = 4
            headerString = packetString[:self.headerLength]
            ctrlByte, packetLength, crc, command \
                = struct.unpack(Formatting.CommandData.Header, headerString)

            # Extract the value from the subsystem byte
            subSystem = ctrlByte & BitMask.SubSystem

            # Check if the response byte is an acknowledge
            packetTypeCode = ctrlByte & BitMask.PacketType
            packetType = packetTypeCode >> BitPosition.PacketType

            # See if the packet is a response or a command packet
            if (packetType == PacketType.Command):
                raise InvalidPacketFormatError('Cannot create a response packet with the string of a command packet.')

            self.header = NebHeader(subSystem, packetType, command, crc, packetLength)

            # Extract the data substring
            dataString = packetString[self.headerLength:self.headerLength + packetLength]

            # Perform CRC of data bytes
            if (checkCRC):
                calculatedCRC = nebUtilities.genNebCRC8(bytearray(packetString))
                if calculatedCRC != self.header.crc:
                    raise CRCError(calculatedCRC, self.header.crc)

            if packetType == PacketType.Ack:
                self.data = AckData()
            else:
                # Build the data object based on the subsystem and command.
                self.data = ResponsePacketDataConstructors[subSystem][self.header.command](dataString)

        elif (header != None and data != None):
            self.header = header
            self.data = data
示例#4
0
    def sessionPlayback(self, pbSessionID, dump=False):
        """
            Playback a recorded session.

            :param pbSessionID: Recorded session identifier.
            :param dump: True, to dump recorded data to file. False, to skip.
            :return: Number of data retrieved.
        """
        self.core.sendCommand(SubSystem.Storage,
                              Commands.Storage.Playback,
                              True,
                              sessionID=pbSessionID)
        logging.debug(
            'Sent the start playback command, waiting for response...')
        # wait for confirmation
        self.core.waitForAck(SubSystem.Storage, Commands.Storage.Playback)
        packet = self.core.waitForPacket(PacketType.RegularResponse,
                                         SubSystem.Storage,
                                         Commands.Storage.Playback)
        if packet.header.packetType == PacketType.ErrorLogResp:
            logging.error(
                'Playback failed due to an invalid session number request!')
            return 0
        else:
            pbSessionID = packet.data.sessionID
            logging.info(
                'Playback routine started from session number {0}'.format(
                    pbSessionID))
            packetList = self.core.storePacketsUntil(
                PacketType.RegularResponse, SubSystem.Storage,
                Commands.Storage.Playback)
            logging.info('Finished playback from session number {0}!'.format(
                pbSessionID))
            if dump:
                logging.info('Saving dump file. Waiting for completion...')
                NebUtilities.saveFlashPlayback(pbSessionID, packetList)
                logging.info('Dump file saving completed.')
            return len(packetList)
示例#5
0
 def createResponsePacket(self, subSystem, commands, data, dataString):
     crc = nebUtilities.crc8(bytearray(dataString))
     header = NebHeader(subSystem, False, commands, crc, len(dataString))
     responsePacket = NebResponsePacket(packetString=None, header=header, data=data, checkCRC=False)
     responsePacket.header.crc = nebUtilities.genNebCRC8(bytearray(responsePacket.stringEncode()))
     return responsePacket