diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 0618d4b..1757f4d 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,12 @@
-
+
+
+
+
+
+
@@ -14,7 +19,11 @@
+
+
+
+
@@ -22,6 +31,8 @@
+
+
@@ -87,29 +98,38 @@
-
+
-
-
-
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/__pycache__/kx.cpython-37.pyc b/__pycache__/kx.cpython-37.pyc
index 4ed85f9..7ec21d3 100644
Binary files a/__pycache__/kx.cpython-37.pyc and b/__pycache__/kx.cpython-37.pyc differ
diff --git a/__pycache__/kx.cpython-38.pyc b/__pycache__/kx.cpython-38.pyc
new file mode 100644
index 0000000..538e4e6
Binary files /dev/null and b/__pycache__/kx.cpython-38.pyc differ
diff --git a/__pycache__/main.cpython-38.pyc b/__pycache__/main.cpython-38.pyc
new file mode 100644
index 0000000..f533435
Binary files /dev/null and b/__pycache__/main.cpython-38.pyc differ
diff --git a/__pycache__/protocol_kx.cpython-38.pyc b/__pycache__/protocol_kx.cpython-38.pyc
new file mode 100644
index 0000000..417f23c
Binary files /dev/null and b/__pycache__/protocol_kx.cpython-38.pyc differ
diff --git a/kx.py b/kx.py
index a05b40c..f38f70d 100644
--- a/kx.py
+++ b/kx.py
@@ -3,6 +3,8 @@ import can
import cantools
import os
import numpy as np
+import struct
+import time
K = np.zeros(protocol_kx.KX_K_COUNT)
@@ -21,21 +23,55 @@ class KX:
def reset(self):
resetMsg = can.Message(arbitration_id=0xA, data=[99, self.sbl_id], is_extended_id=False)
- self.can0.send(resetMsg)
+ try:
+ self.can0.send(resetMsg)
+ print(f"Message sent on{self.can0.channel_info}")
+ except self.can0.CanError:
+ print("Message NOT sent")
+
def sendK(self):
- msg = protocol_kx.CANMsgK(self.sbl_id, 0, protocol_kx.KX_FLAG_SEND, K[0])
i = 0
for element in K:
- msg.k = element
- msg.index = i
+ ba = bytearray(struct.pack("f", element))
+ messageK = can.Message(arbitration_id=0x2BB, data=[self.sbl_id, i, 0,
+ protocol_kx.KX_FLAG_SEND, ba[0], ba[1], ba[2], ba[3]], is_extended_id=False)
+ try:
+ self.can0.send(messageK)
+ time.sleep(0.01)
+ print(f"Message sent on{self.can0.channel_info}")
+ except self.can0.CanError:
+ print("Message NOT sent")
i = i + 1
- messageK = can.Message(protocol_kx.KX_FLAG_SEND, data=msg, is_extended_id=False)
- self.can0.send(messageK)
+
def writeToFlashK(self):
msg = protocol_kx.CANMsgK(self.sbl_id, 0, protocol_kx.KX_FLAG_WRITE_REQ, K)
- messageK = can.Message(protocol_kx.KX_FLAG_READ, data=msg, is_extended_id=False)
- self.can0.send(messageK)
\ No newline at end of file
+ messageK = can.Message(arbitration_id=0x2BB, data=[self.sbl_id, 0, 0,
+ protocol_kx.KX_FLAG_WRITE_REQ], is_extended_id=False)
+ try:
+ self.can0.send(messageK)
+ time.sleep(0.01)
+ print(f"Flash sent on{self.can0.channel_info}")
+ except self.can0.CanError:
+ print("Flash NOT sent")
+
+
+ def send_test_source_enable(self, x, y, xVel, yVel):
+ resetMsg = can.Message(
+ arbitration_id=0xA,
+ data=[
+ 0x53,
+ 0xFF,
+ struct.pack('b', int(x))[0],
+ struct.pack('B', int(y))[0],
+ struct.pack('b', int(xVel))[0],
+ struct.pack('b', int(yVel))[0],
+ 0x68,
+ 0xA4
+ ],
+ is_extended_id=False
+ )
+ self.can0.send(resetMsg)
\ No newline at end of file
diff --git a/main.py b/main.py
index 7babafe..cbf17c1 100644
--- a/main.py
+++ b/main.py
@@ -1,13 +1,15 @@
import kx
import can
import protocol_kx
+import struct
import os
+import time
can0 = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=500000)
-
KXLOX = kx.KX(protocol_kx.KDescription.K_TEST_SOURCE_2_SIGLVL.value, 950, 255, can0)
+KXLOX.KXInit(protocol_kx.KDescription.K_SBL_ID.value, 43)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_X_MAX.value, 21)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Y_MAX.value, 21)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_X_MIN.value, 1)
@@ -18,5 +20,6 @@ KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_SIGLVL.value, 450)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCES_ENABLED.value, 1)
KXLOX.sendK()
KXLOX.writeToFlashK()
-os.wait(100)
+time.sleep(0.1)
KXLOX.reset()
+