Index: HemodialysisDevice.py =================================================================== diff -u -ra2784d2e31f8459e49cf94be97be37fc6650f1f9 -rabd93c1d800178a5ee618b9bba83532b853e3c96 --- HemodialysisDevice.py (.../HemodialysisDevice.py) (revision a2784d2e31f8459e49cf94be97be37fc6650f1f9) +++ HemodialysisDevice.py (.../HemodialysisDevice.py) (revision abd93c1d800178a5ee618b9bba83532b853e3c96) @@ -1,25 +1,24 @@ -""" - \file HemodialysisDevice.py - \brief Comprises API interface for the DG board. +########################################################################### +# +# Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. +# +# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +# +# @file HemodialysisDevice.py +# +# @date 16-Oct-2019 +# @author L. Baloa +# +# @brief This class allows sending to and receiving from the HD device. +# +############################################################################ -""" from DialityCoreSerialProtocol import DialitySerialMessenger -from DialityCoreSerialProtocol import START_BYTE +from DialityCoreSerialProtocol import DialityPacket from time import sleep -""" \mainpage Dialin API - - Dialin API is comprised primarily by 3 classes: - - - \ref DG - - \ref HD - - \ref UI - - - -""" - class HD: """ \class HD @@ -49,33 +48,16 @@ def login(self): - # Send fill message - message = bytearray([int.from_bytes(START_BYTE, byteorder="big"), 0, 0, 0, 0, 0, 0, 0]) - self.__messageID = 8000 - #message[1:2] = int.from_bytes(self.__messageID, byteorder='little') + request_id = 8000 + cargo = b'123' - message[1] = int.from_bytes(b'\x40',byteorder='big') - message[2] = int.from_bytes(b'\x1F',byteorder='big') - message[3] = int.from_bytes(b'\x03',byteorder='big') - message[4] = int.from_bytes(b'\x31', byteorder='big') - message[5] = int.from_bytes(b'\x32', byteorder='big') - message[6] = int.from_bytes(b'\x33', byteorder='big') + message = DialityPacket.buildPacket(request_id=request_id, cargo=cargo) print("login") # Send message - send_event = self.__send(message) + received_message = self.__serialPort.send(message) - message_received = send_event.wait(1) - - if(message_received): - - - - print("I have a response") - - received_message = self.__getmessage() - if len(received_message) != 0: print(received_message) @@ -88,40 +70,28 @@ print("Timeout!!!!") return False + + def OffButton(self): - # Send fill message - message = bytearray([int.from_bytes(START_BYTE, byteorder="big"), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - self.__messageID = 8000 - # message[1:2] = int.from_bytes(self.__messageID, byteorder='little') + request_id = 8001 + cargo = b'\x00\x01\x00\x00\x00' - message[1] = int.from_bytes(b'\x42', byteorder='big') - message[2] = int.from_bytes(b'\x1F', byteorder='big') - message[3] = int.from_bytes(b'\x05', byteorder='big') - message[4] = int.from_bytes(b'\x00', byteorder='big') - message[5] = int.from_bytes(b'\x01', byteorder='big') - message[6] = int.from_bytes(b'\x00', byteorder='big') - message[7] = int.from_bytes(b'\x00', byteorder='big') - message[8] = int.from_bytes(b'\x00', byteorder='big') + message = DialityPacket.buildPacket(request_id=request_id, cargo=cargo) print("override off button") # Send message - send_event = self.__send(message) + received_message = self.__serialPort.send(message) - message_received = send_event.wait(1) - - if (message_received): - print("I have a response") - - received_message = self.__getmessage() - + # If there is content... if len(received_message) != 0: print(received_message) print("Logged:" + str(received_message[4])) + # 5th element is OK or not OK return received_message[4] else: @@ -136,22 +106,7 @@ t1 = method t2 = message_id - def __send(self, a_message): - # First calculate CRC - ##a_message[-1] = self.__calculate_crc(a_message) - print('Sending: '+str(a_message)) - # Send command via serial port - return self.__serialPort.write(a_message) - - def __getmessage(self): - return self.__serialPort.getMessage() - - def __calculate_crc(self, a_message): - # a_command includes the last byte for crc - return sum(a_message[0:-1]) % 256 - - if __name__ == "__main__": thehd = HD() # \var thedg