36 lines
957 B
Python
36 lines
957 B
Python
import socket
|
|
import sys
|
|
import os
|
|
import CompLib_pb2
|
|
|
|
|
|
SOCKET_PATH = "/tmp/compLib"
|
|
|
|
|
|
def send(data, size):
|
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
|
sock.connect(SOCKET_PATH)
|
|
sock.sendall(size.to_bytes(1, byteorder='big'))
|
|
sock.sendall(data)
|
|
|
|
responseSizeBytes = sock.recv(1)
|
|
responseSize = int.from_bytes(responseSizeBytes, byteorder="big")
|
|
print(responseSize)
|
|
|
|
responseBytes = sock.recv(responseSize)
|
|
genericResponse = CompLib_pb2.GenericResponse()
|
|
|
|
genericResponse.ParseFromString(responseBytes)
|
|
print(genericResponse)
|
|
|
|
# reponseBytes =
|
|
|
|
|
|
def main():
|
|
readSensorsRequest = CompLib_pb2.ReadSensorsRequest()
|
|
# readSensorsRequest.header = CompLib_pb2.Header()
|
|
readSensorsRequest.header.message_type = readSensorsRequest.DESCRIPTOR.full_name
|
|
send(readSensorsRequest.SerializeToString(), readSensorsRequest.ByteSize())
|
|
|
|
|
|
main()
|