Exemple #1
0
    def sendpbcommand(self, request, responseclass):
        self.setmode(self.MODEBREW)
        buffer = prototypes.buffer()
        request.writetobuffer(buffer,
                              logtitle="audiovox cdm8900 phonebook request")
        data = buffer.getvalue()
        data = common.pppescape(data +
                                common.crcs(data)) + common.pppterminator
        first = data[0]
        try:
            data = self.comm.writethenreaduntil(data,
                                                False,
                                                common.pppterminator,
                                                logreaduntilsuccess=False)
        except com_phone.modeignoreerrortypes:
            self.mode = self.MODENONE
            self.raisecommsdnaexception("manipulating the phonebook")
        self.comm.success = True

        origdata = data
        # sometimes there is junk at the begining, eg if the user
        # turned off the phone and back on again.  So if there is more
        # than one 7e in the escaped data we should start after the
        # second to last one
        d = data.rfind(common.pppterminator, 0, -1)
        if d >= 0:
            self.log(
                "Multiple PB packets in data - taking last one starting at " +
                ` d + 1 `)
            self.logdata("Original pb data", origdata, None)
            data = data[d + 1:]

        # turn it back to normal
        data = common.pppunescape(data)

        # sometimes there is other crap at the begining
        d = data.find(first)
        if d > 0:
            self.log("Junk at begining of pb packet, data at " + ` d `)
            self.logdata("Original pb data", origdata, None)
            self.logdata("Working on pb data", data, None)
            data = data[d:]
        # take off crc and terminator
        crc = data[-3:-1]
        data = data[:-3]
        if common.crcs(data) != crc:
            self.logdata("Original pb data", origdata, None)
            self.logdata("Working on pb data", data, None)
            raise common.CommsDataCorruption(
                "Audiovox phonebook packet failed CRC check", self.desc)

        # parse data
        buffer = prototypes.buffer(data)
        res = responseclass()
        res.readfrombuffer(buffer, logtitle="Audiovox phonebook response")
        return res
Exemple #2
0
    def sendpbcommand(self, request, responseclass, callsetmode=True, writemode=False, numsendretry=0, returnerror=False):
        if writemode:
            numretry=3
        else:
            numretry=0
            
        if callsetmode:
            self.setmode(self.MODEPHONEBOOK)
        buffer=prototypes.buffer()

        request.writetobuffer(buffer, logtitle="Samsung phonebook request")
        data=buffer.getvalue()
        firsttwo=data[:2]
        data=common.pppescape(data+common.crcs(data))+common.pppterminator
        isendretry=numsendretry
        while isendretry>=0:
            try:
                rdata=self.comm.writethenreaduntil(data, False, common.pppterminator, logreaduntilsuccess=False, numfailures=numretry)
                break
            except com_phone.modeignoreerrortypes:
                if isendretry>0:
                    self.log("Resending request packet...")
                    time.sleep(0.3)
                else:
                    self.comm.success=False
                    self.mode=self.MODENONE
                    self.raisecommsdnaexception("manipulating the phonebook")
                isendretry-=1

        self.comm.success=True

        origdata=rdata
        # sometimes there is junk at the beginning, eg if the user
        # turned off the phone and back on again.  So if there is more
        # than one 7e in the escaped data we should start after the
        # second to last one
        d=rdata.rfind(common.pppterminator,0,-1)
        if d>=0:
            self.log("Multiple Samsung packets in data - taking last one starting at "+`d+1`)
            self.logdata("Original Samsung data", origdata, None)
            rdata=rdata[d+1:]

        # turn it back to normal
        data=common.pppunescape(rdata)

        # Sometimes there is other crap at the beginning.  But it might
        # be a Sanyo error byte.  So strip off bytes from the beginning
        # until the crc agrees, or we get to the first two bytes of the
        # request packet.
        d=data.find(firsttwo)
        crc=data[-3:-1]
        crcok=False
        for i in range(0,d+1):
            trydata=data[i:-3]
            if common.crcs(trydata)==crc:
                crcok=True
                break

        if not crcok:
            self.logdata("first two",firsttwo, None)
            self.logdata("Original Sanyo data", origdata, None)
            self.logdata("Working on Sanyo data", data, None)
            raise common.CommsDataCorruption("Sanyo packet failed CRC check", self.desc)

        res=responseclass()
        if d>0:
            if d==i:
                self.log("Junk at beginning of Sanyo packet, data at "+`d`)
                self.logdata("Original Sanyo data", origdata, None)
                self.logdata("Working on Sanyo data", data, None)
            else:
                if returnerror:
                    res=self.protocolclass.sanyoerror()
                else:
                    self.log("Sanyo Error code "+`ord(data[0])`)
                    self.logdata("sanyo phonebook response", data, None)
                    raise SanyoCommandException(ord(data[0]))
            
        data=trydata

        # parse data
        buffer=prototypes.buffer(data)
        res.readfrombuffer(buffer, logtitle="sanyo phonebook response")
        return res