def check_o2_balance(): """Check o2 balance""" ser = serial.Serial(find_device()) code = "*#10#" data="AT+CUSD=1,%s,15" % pdu.pack7bit(code)[1].encode('hex').upper() ser.write(data + "\r") start = int(os.times()[4]) while start + 10 > int(os.times()[4]): line = ser.readline().replace('"',"") if "+CUSD:" in line: response = line.split(",")[1] result = gsm0338().decode(pdu.unpack7bit(response.decode('hex')))[0] result = result[:-1].replace(u'Your balance is \xa3','') logging.debug("Balance is %s" %result) return float(result) return -1
def check_o2_balance(): """Check o2 balance""" ser = serial.Serial(find_device()) code = "*#10#" data = "AT+CUSD=1,%s,15" % pdu.pack7bit(code)[1].encode('hex').upper() ser.write(data + "\r") start = int(os.times()[4]) while start + 10 > int(os.times()[4]): line = ser.readline().replace('"', "") if "+CUSD:" in line: response = line.split(",")[1] result = gsm0338().decode(pdu.unpack7bit( response.decode('hex')))[0] result = result[:-1].replace(u'Your balance is \xa3', '') logging.debug("Balance is %s" % result) return float(result) return -1
def test_decoding_7_bit(self): from smspdu.pdu import unpack7bit input_bytes = [0xE8, 0x32, 0x9B, 0xFD, 0x46, 0x97, 0xD9, 0xEC, 0x37] input = ''.join(chr(x) for x in input_bytes) output = 'hellohello' self.assertEquals(unpack7bit(input), output)
def test_decoding_7_bit(self): from smspdu.pdu import unpack7bit input_bytes = [0xE8, 0x32, 0x9B, 0xFD, 0x46, 0x97, 0xD9, 0xEC, 0x37] input = bytes(input_bytes) output = b'hellohello' self.assertEqual(unpack7bit(input), output)