Python - Leer datos de entrada en formato binario y enviado a través del protocolo TCP

 
Vista:

Leer datos de entrada en formato binario y enviado a través del protocolo TCP

Publicado por Gabriel (4 intervenciones) el 08/04/2015 15:21:26
Saludos !!

Amigos estoy recibiendo datos en formato binario y enviado través del protocolo TCP, en el servidor con SUse habilite un puerto y recibo cantidad de datos que son ilegibles.
Mi pregunta es como leer dichos datos sabiendo la estructura de lo que se envía por ej:

Size (in bytes) Field type Field description
4 Integer Packet size
- Char Controller ID. This field has variable size. Null byte
(00) is the end of the string.
4 Integer Time in seconds (UTC)

esto es parte del formato del paquete

gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 2.239
Plata
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

Leer datos de entrada en formato binario y enviado a través del protocolo TCP

Publicado por xve (1646 intervenciones) el 08/04/2015 21:54:54
Hola Gabriel, estaria bien visualizar lo que te llega y el contenido del mismo para poder hacer pruebas...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Leer datos de entrada en formato binario y enviado a través del protocolo TCP

Publicado por Gabriel (4 intervenciones) el 09/04/2015 04:52:38
Amigo, gracias por responder, esto es una parte de lo que recibo

///*** parte del código
data = conn.recv(65536)
reply = 'Message Received at the server!\n'
print data


Socket created
Socket bind complete
Socket now listening
Connected with 77.74.50.76:57976

///**** parte de lo que recibo tal cual sale por pantalla así indentado
3356612022821377U%▒▒
▒ecu_battery_flagU
▒ecu_cool_lvl_flagT
▒ecu_cool_psi_flagU
▒ecu_cool_tmp_flagT
▒ecu_distance_flagT
▒ecu_error_flagU
▒ecu_fan_state_flagU
▒ecu_fuel_level_flagU
▒ecu_hours_flagT
▒ecu_hours_idle_flagU
▒ecu_idle_fuel_flagU
▒ecu_oxygen_flagU
▒ecu_rpm_flagT
▒ecu_throttle_flagT
▒ecu_tires_tmp_flagU
▒ecu_torque_flagT
▒ecu_total_fuel_flagT
▒ecu_trans_lvl_flagU
▒ecu_trans_psi_flagU
▒ecu_trans_tmp_flagU
▒ecu_weights_flagT
▒ecu_brake_pedal
▒ecu_cool_lvl
▒ecu_cool_tmpY
▒ecu_distance

▒ecu_eng_oil_psi>
▒ecu_fuel_level_real▒
▒ecu_hours
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Leer datos de entrada en formato binario y enviado a través del protocolo TCP

Publicado por Gabriel (4 intervenciones) el 09/04/2015 05:41:27
Supuesta mente tengo que recibir algo así

Original packet:
74000000333533393736303133343435343835004B0BFB70000000030BBB0000002701027
06F73696E666F00A027AFDF5D9848403AC7253383DD4B400000000000805A400036014
60B0BBB0000001200047077725F657874002B8716D9CE973B400BBB0000001101036176
6C5F696E707574730000000001
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 2.239
Plata
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

Leer datos de entrada en formato binario y enviado a través del protocolo TCP

Publicado por xve (1646 intervenciones) el 09/04/2015 08:42:55
No entiendo muy bien, pero hay unos caracteres extraños en tu código¿?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Leer datos de entrada en formato binario y enviado a través del protocolo TCP

Publicado por Gabriel (4 intervenciones) el 12/04/2015 01:43:48
Te cuento
desde un sevidor me envian al mio, me llega informacion pero aun no logro decodificar la misma o el modo de lograr identificar cada campo de informacion

"data has binary format and is sent via TCP protocol. The packet has the following format: "

Size (in bytes) Field type Field description
4 Integer Packet size
- Char Controller ID. This field has variable size. Null byte
(00) is the end of the string.
4 Integer Time in seconds (UTC)
4 Integer Message bit flags.
0×1 – Position information
0×2 – digital inputs information
0×4 -
digital outputs information
0×10 – Alarm bit
0×20 – Driver's ID infomation
All other bits are reserved or used only by Wialon.
- - Data blocks inside the packet, blocks follow one after
another
Data block has the following format:
Size (in bytes) Field type Field description
2 Integer Block type
4 Integer Block size
1 Integer Visibility attribute (1 – parameter
is invisible, 0 - visible)
1 Integer Block data type
0x1 — text
0x2 — binary
0x3 — Integer(int, 4 bytes)
0x4 — floating (double)
0x5 — Long int(long, 8 bytes)
- Char Block name
posinfo - coordinates
pwr_ext – power voltage
avl_inputs – digital inputs
avl_outputs – digital outputs
adc1,adc2 – analog sensors
gsm – gsm signal level
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Leer datos de entrada en formato binario y enviado a través del protocolo TCP

Publicado por anon (1 intervención) el 18/04/2015 20:37:09
Hola amigo para leer la estructura prueba esto y cuéntanos la salida que produce.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import struct
 
 
class Read():
    def __init__(self, pack):
        self.index = 0
        self.pack = pack
 
    def next(self, size):
        aux = self.pack[self.index:self.index+size]
        self.index += size
        return aux
 
    def get_int(self):
        aux = self.next(4)
        return struct.unpack("I", aux)[0]
 
    def get_short(self):
        aux = self.next(2)
        return struct.unpack("H", aux)[0]
 
    def get_char(self):
        aux = self.next(1)
        return struct.unpack("B", aux)[0]
 
 
# Paquete de ejemplo.
# data = conn.recv(65536) # Descomentar esta linea y comentar el de abajo.
data = "\1\0\0\0\2\0\0\0\3\0\0\0\4\0\5\0\0\0\6\7"
print (data, ) # Como tupla es mas util la salida.
 
 
read = Read(data)
 
# 4 Integer Packet size
pack_size = read.get_int()
 
# 4 Integer Time in seconds (UTC)
time_secconds = read.get_int()
 
# 4 Integer Message bit flags.
msg_flags = read.get_int()
 
# 2 Integer Block type
block_type = read.get_short()
 
# 4 Integer Block size
block_size = read.get_int()
 
# 1 Integer Visibility attribute
visibility = read.get_char()
 
# 1 Integer Block data type
block_data_type = read.get_char()
 
# Salida.
print ("pack_size:", pack_size)
print ("time_secconds:", time_secconds)
print ("msg_flags:", msg_flags)
print ("block_type:", block_type)
print ("block_size:", block_size)
print ("visibility:", visibility)
print ("block_data_type:", block_data_type)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar