Add complib client and TCP communication
This commit is contained in:
parent
1a033c8b03
commit
a484bc2137
35 changed files with 815 additions and 232 deletions
|
@ -1,36 +1,48 @@
|
|||
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 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)
|
||||
#
|
||||
# response_size_bytes = sock.recv(1)
|
||||
# response_size = int.from_bytes(response_size_bytes, byteorder="big")
|
||||
# # print(f"Response size: {response_size}")
|
||||
#
|
||||
# response_bytes = sock.recv(response_size)
|
||||
# generic_response = CompLib_pb2.GenericResponse()
|
||||
#
|
||||
# generic_response.ParseFromString(response_bytes)
|
||||
# # print(f"Response: {generic_response}")
|
||||
#
|
||||
# # 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())
|
||||
# encoder_read_positions_request = CompLib_pb2.EncoderReadPositionsRequest()
|
||||
# # readSensorsRequest.header = CompLib_pb2.Header()
|
||||
# encoder_read_positions_request.header.message_type = encoder_read_positions_request.DESCRIPTOR.full_name
|
||||
#
|
||||
# start_time = time.time()
|
||||
# for i in range(100000):
|
||||
# send(encoder_read_positions_request.SerializeToString(), encoder_read_positions_request.ByteSize())
|
||||
# print("--- %s seconds ---" % (time.time() - start_time))
|
||||
|
||||
# from compLib.IRSensor import IRSensor
|
||||
# IRSensor.read_all()
|
||||
#
|
||||
from compLib.Encoder import Encoder
|
||||
Encoder.read_all_positions()
|
||||
Encoder.read_all_velocities()
|
||||
|
||||
# from compLib.Motor import Motor
|
||||
# Motor.speed(0, 50)
|
||||
# Motor.speed(3, -50)
|
||||
|
||||
# time.sleep(10)
|
||||
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Reference in a new issue