Index: dialin/dg/calibration.py =================================================================== diff -u -r6154b064dd181c32b09982c04ca9ddbca41bf509 -r4da359d875e41ceea5ed164a20636256da74e886 --- dialin/dg/calibration.py (.../calibration.py) (revision 6154b064dd181c32b09982c04ca9ddbca41bf509) +++ dialin/dg/calibration.py (.../calibration.py) (revision 4da359d875e41ceea5ed164a20636256da74e886) @@ -1,7 +1,10 @@ import struct +import datetime +import time +import math from collections import OrderedDict -from ..utils.conversions import integer_to_bytearray +from ..ui.crc import crc_16 from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import _AbstractSubSystem, _publish @@ -16,6 +19,7 @@ CALIBRATION_RECORD_START_INDEX = 6 CALIBRATION_RECORD_SPECS_BYTES = 12 + CALIBRATION_RECORDS_SPECS_BYTE_ARRAY = 3 DEFAULT_GAIN_VALUE = 1 DEFAULT_OFFSET_VALUE = 0 DEFAULT_RATIO_VALUE = 1 @@ -28,6 +32,13 @@ PAYLOAD_LENGTH_INDEX = 8 PAYLOAD_START_INDEX = 12 + CALIBRATION_DATA_TYPE_INDEX = 0 + CALIBRATION_VALUE_INDEX = 1 + + TARGET_BYTES_TO_SEND_TO_FW = 150 + + EEPROM_MAX_BYTES_TO_WRITE = 16 + # DG calibration main record DG_CALIBRATION_RECORD = OrderedDict() @@ -58,7 +69,7 @@ def get_dg_calibration_data(self): """ - Handles getting dg calibration data from firmware. + Handles getting DG calibration data from firmware. @return: None """ @@ -137,22 +148,22 @@ # Convert the concatenated raw data into a byte array since the struct library requires byte arrays. self.raw_cal_record = bytearray(self.raw_cal_record) - # Loop though the keys for the main calibration dictionary + # Loop through the keys for the main calibration dictionary # DG_Calibration : {pressure_sensors : { ppi : { gain: [' 4: + + current_payload_length += data_type_bytes + temp_buffer[1] = struct.pack(' 0: + # Make the sure variables are 16-bit integers + left = (crc << 8) & 0x0000FFFF + right = (crc >> 8) & 0x0000FFFF + crc = left ^ crc_16_table[data[i] ^ (right & 0x00FF)] + l -= 1 + i += 1 + return crc Index: tests/test_dg_calibration.py =================================================================== diff -u -r6154b064dd181c32b09982c04ca9ddbca41bf509 -r4da359d875e41ceea5ed164a20636256da74e886 --- tests/test_dg_calibration.py (.../test_dg_calibration.py) (revision 6154b064dd181c32b09982c04ca9ddbca41bf509) +++ tests/test_dg_calibration.py (.../test_dg_calibration.py) (revision 4da359d875e41ceea5ed164a20636256da74e886) @@ -1,6 +1,7 @@ from ctypes import * from collections import OrderedDict from dialin.dg.dialysate_generator import DG +from dialin.ui import crc from time import sleep import struct @@ -10,7 +11,7 @@ if dg.cmd_log_in_to_dg() == 0: exit(1) - + sleep(2) cal = dg.calibration """" @@ -37,11 +38,12 @@ f = open("DG_Calibration.log", "w") - dara = [] + print(cal.DG_CALIBRATION_RECORD) + #dara = [] + #cal.get_dg_calibration_data() - cal.get_dg_calibration_data() - try: + """ while True: sleep(0.2) #print(cal.current_message, cal.total_messages, cal.cal_data) @@ -53,17 +55,8 @@ if cal.current_message == cal.total_messages: f.close() break - #[print(i) for i in dara] - #value = struct.unpack('f', bytearray(dara[0][18:(18+4)]))[0] - #print(cal.DG_CALIBRATION_RECORD.keys()) + """ + cal.set_dg_calibration_data() - #load_cells = OrderedDict({'group_name': OrderedDict()}) - #individual_sensor = OrderedDict() - #list1 = ['load_1', 'load_2', 'load_3'] - #for i in list1: - # individual_sensor[i] = {'gain': ['