Can msg send

This commit is contained in:
2021-07-02 16:13:59 +03:00
parent f9368c434b
commit 88c6b06061
8 changed files with 90 additions and 25 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

50
.idea/workspace.xml generated
View File

@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="72cc40b1-c3bf-43e3-bbc5-daa6555ea73d" name="Default Changelist" comment="" />
<list default="true" id="72cc40b1-c3bf-43e3-bbc5-daa6555ea73d" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/kx.py" beforeDir="false" afterPath="$PROJECT_DIR$/kx.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -14,7 +19,11 @@
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="1tfF9PwSNSXsgpWLjjHxA5A61PP" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
@@ -22,6 +31,8 @@
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../texas_test" />
</component>
<component name="RunManager" selected="Python.main">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
@@ -87,29 +98,38 @@
<servers />
</component>
<component name="WindowStateProjectService">
<state width="1899" height="285" key="GridCell.Tab.0.bottom" timestamp="1623333108256">
<state x="740" y="280" key="FileChooserDialogImpl" timestamp="1625210370146">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1899" height="285" key="GridCell.Tab.0.bottom/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1623333108256" />
<state width="1882" height="285" key="GridCell.Tab.0.bottom/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1623328090440" />
<state width="1899" height="285" key="GridCell.Tab.0.center" timestamp="1623333108256">
<state x="740" y="280" key="FileChooserDialogImpl/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1625210370146" />
<state width="1899" height="285" key="GridCell.Tab.0.bottom" timestamp="1625231013474">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1899" height="285" key="GridCell.Tab.0.center/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1623333108256" />
<state width="1882" height="285" key="GridCell.Tab.0.center/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1623328090440" />
<state width="1899" height="285" key="GridCell.Tab.0.left" timestamp="1623333108256">
<state width="1899" height="285" key="GridCell.Tab.0.bottom/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1625231013474" />
<state width="1899" height="285" key="GridCell.Tab.0.bottom/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1625226001969" />
<state width="1899" height="285" key="GridCell.Tab.0.center" timestamp="1625231013474">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1899" height="285" key="GridCell.Tab.0.left/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1623333108256" />
<state width="1882" height="285" key="GridCell.Tab.0.left/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1623328090440" />
<state width="1899" height="285" key="GridCell.Tab.0.right" timestamp="1623333108256">
<state width="1899" height="285" key="GridCell.Tab.0.center/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1625231013474" />
<state width="1899" height="285" key="GridCell.Tab.0.center/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1625226001969" />
<state width="1899" height="285" key="GridCell.Tab.0.left" timestamp="1625231013474">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1899" height="285" key="GridCell.Tab.0.right/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1623333108256" />
<state width="1882" height="285" key="GridCell.Tab.0.right/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1623328090440" />
<state x="2576" y="349" key="com.intellij.ide.util.TipDialog" timestamp="1623318929088">
<state width="1899" height="285" key="GridCell.Tab.0.left/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1625231013474" />
<state width="1899" height="285" key="GridCell.Tab.0.left/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1625226001969" />
<state width="1899" height="285" key="GridCell.Tab.0.right" timestamp="1625231013474">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1899" height="285" key="GridCell.Tab.0.right/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1625231013474" />
<state width="1899" height="285" key="GridCell.Tab.0.right/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1625226001969" />
<state x="656" y="349" key="com.intellij.ide.util.TipDialog" timestamp="1625209374327">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="656" y="349" key="com.intellij.ide.util.TipDialog/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1625209374327" />
<state x="2576" y="349" key="com.intellij.ide.util.TipDialog/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1623318929088" />
<state x="2543" y="227" width="672" height="678" key="search.everywhere.popup" timestamp="1625214536301">
<screen x="1920" y="0" width="1920" height="1050" />
</state>
<state x="2576" y="349" key="com.intellij.ide.util.TipDialog/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1623318929088" />
<state x="2543" y="227" width="672" height="678" key="search.everywhere.popup/0.0.1920.1050/1920.0.1920.1050@1920.0.1920.1050" timestamp="1625214536301" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

52
kx.py
View File

@@ -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)
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)

View File

@@ -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()