From a4418487df66908e2a89e67a37f8798ab8dba88a Mon Sep 17 00:00:00 2001 From: rusefillc Date: Tue, 20 Dec 2022 19:31:26 -0500 Subject: [PATCH] GDI progress --- .../lua/examples/gdi4-communication.txt | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/lua/examples/gdi4-communication.txt b/firmware/controllers/lua/examples/gdi4-communication.txt index 351c1501e2..27693a4ce1 100644 --- a/firmware/controllers/lua/examples/gdi4-communication.txt +++ b/firmware/controllers/lua/examples/gdi4-communication.txt @@ -36,6 +36,11 @@ function getTwoBytesLSB(data, offset, factor) return (data[offset + 2] * 256 + data[offset + 1]) * factor end +function setTwoBytesLsb(data, offset, value) + value = math.floor(value) + data[offset + 2] = value >> 8 + data[offset + 1] = value & 0xff +end function onCanConfiguration(bus, id, dlc, data) print('Received configuration ' ..arrayToString(data)) @@ -49,11 +54,26 @@ canRxAdd(GDI4_BASE_ADDRESS, printPacket) canRxAdd(GDI4_BASE_ADDRESS + 1, onCanConfiguration) canRxAdd(GDI4_BASE_ADDRESS + 2, printPacket) -local data_0x1ae0092c = { 0x00, 0x00, 0x22, 0xe0, 0x41, 0x90, 0x00, 0x00 } +local data_set_voltage = { 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } + +FIXED_POINT = 100 function onTick() - txCan(1, 0x200, 1, data_0x1ae0092c) + boostVoltage = getCalibration("mc33_hvolt") + boostCurrent = getCalibration("mc33_i_boost") / 1000.0 + peakCurrent = getCalibration("mc33_i_peak") / 1000.0 + print(boostVoltage .." " ..boostCurrent .." " ..peakCurrent) + + setTwoBytesLsb(data_set_voltage, 1, boostVoltage * FIXED_POINT) + setTwoBytesLsb(data_set_voltage, 3, boostCurrent * FIXED_POINT) + setTwoBytesLsb(data_set_voltage, 5, peakCurrent * FIXED_POINT) + print('Sending ' ..arrayToString(data_set_voltage)) + + holdCurrent = getCalibration("mc33_i_hold") + + + txCan(1, 0x201, 1, data_set_voltage) end