Improvement

This commit is contained in:
2021-07-13 15:38:13 +03:00
parent e17a82acf2
commit 31ec56fb25
9 changed files with 123 additions and 55 deletions

23
.idea/workspace.xml generated
View File

@@ -5,6 +5,7 @@
<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" />
<change beforePath="$PROJECT_DIR$/protocol_kx.py" beforeDir="false" afterPath="$PROJECT_DIR$/protocol_kx.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -83,7 +84,7 @@
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="SpellCheckerSettings" BundledDictionaries="0" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" Dictionaries="0" CorrectionsLimit="5" DefaultDictionary="application-level" UseSingleDictionary="true" />
<component name="SvnConfiguration">
<configuration />
</component>
@@ -102,31 +103,35 @@
<screen x="0" y="0" width="1920" height="1050" />
</state>
<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">
<state width="1899" height="285" key="GridCell.Tab.0.bottom" timestamp="1626178105375">
<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="1625231013474" />
<state width="1899" height="285" key="GridCell.Tab.0.bottom/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1626178105375" />
<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">
<state width="1899" height="285" key="GridCell.Tab.0.center" timestamp="1626178105375">
<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="1625231013474" />
<state width="1899" height="285" key="GridCell.Tab.0.center/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1626178105375" />
<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">
<state width="1899" height="285" key="GridCell.Tab.0.left" timestamp="1626178105375">
<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="1625231013474" />
<state width="1899" height="285" key="GridCell.Tab.0.left/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1626178105375" />
<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">
<state width="1899" height="285" key="GridCell.Tab.0.right" timestamp="1626178105375">
<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@0.0.1920.1050" timestamp="1626178105375" />
<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="718" y="246" width="737" height="804" key="find.popup" timestamp="1626177094089">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="718" y="246" width="737" height="804" key="find.popup/0.0.1920.1050/1920.0.1920.1050@0.0.1920.1050" timestamp="1626177094089" />
<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>

Binary file not shown.

Binary file not shown.

Binary file not shown.

71
kx.py
View File

@@ -1,67 +1,86 @@
import protocol_kx
import can
import cantools
import os
import numpy as np
import struct
import time
K = np.zeros(protocol_kx.KX_K_COUNT)
K_received = np.zeros(protocol_kx.KX_K_COUNT)
class KX:
def __init__(self, id, value, sbl_id, can):
K[id] = value
def __init__(self, sbl_id, can, dict):
self.sbl_id = sbl_id
self.can0 = can
def KXInit(self, id, value):
K[id] = value
for element in dict:
K[element] = dict[element]
def reset(self):
resetMsg = can.Message(arbitration_id=0xA, data=[99, self.sbl_id], is_extended_id=False)
try:
self.can0.send(resetMsg)
print(f"Message sent on{self.can0.channel_info}")
except self.can0.CanError:
print("Message NOT sent")
print("Message reset NOT sent")
def sendK(self):
i = 0
for element in K:
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)
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")
print("Message sendK NOT sent")
i = i + 1
def writeToFlashK(self):
messageK = can.Message(arbitration_id=0x2BB, data=[self.sbl_id, 0, 0,
protocol_kx.KX_FLAG_WRITE_REQ, 0, 0, 0, 0], is_extended_id=False)
protocol_kx.KX_FLAG_WRITE_REQ, 0, 0, 0, 0],
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, enabaled):
ba = bytearray(struct.pack("f", enabaled))
messageK = can.Message(arbitration_id=0x2BB, data=[self.sbl_id, protocol_kx.KDescription.K_TEST_SOURCES_ENABLED.value, 0,
protocol_kx.KX_FLAG_SEND, ba[0], ba[1], ba[2], ba[3]], is_extended_id=False)
self.can0.send(messageK)
messageK = can.Message(arbitration_id=0x2BB,
data=[self.sbl_id, protocol_kx.KDescription.K_TEST_SOURCES_ENABLED.value, 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)
except self.can0.CanError:
print("Test source enable NOT sent")
self.sendK()
self.writeToFlashK()
self.writeToFlashK()
def send_receive_cmd(self):
messageK = can.Message(arbitration_id=0x2BB,
data=[self.sbl_id, 0, 0,
protocol_kx.KX_FLAG_RECEIVE_REQ, 0, 0, 0, 0], is_extended_id=False)
try:
self.can0.send(messageK)
time.sleep(0.01)
except self.can0.CanError:
print("Receive command NOT sent")
d = 0
while d < 64:
message = self.can0.recv(10)
if message.arbitration_id == 0x2BB:
frame = bytearray()
frame.append(message.data[4])
frame.append(message.data[5])
frame.append(message.data[6])
frame.append(message.data[7])
data= struct.unpack("f", frame)
K_received[message.data[1]] = data[0]
if(K_received[message.data[1]] != K[message.data[1]]):
print("Error in element ", message.data[1], "Need value = ", K[message.data[1]], "Get value = ", K_received[message.data[1]])
d += 1

76
main.py
View File

@@ -1,23 +1,75 @@
import kx
import can
import protocol_kx
import struct
import os
Init_Struct = dict([
(protocol_kx.KDescription.K_SBL_ID.value, 0.0),
(protocol_kx.KDescription.K_TEST_COMP_RX_CHAIN_DISABLED.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCES_ENABLED.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCES_COUNT.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_X.value, 9.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Y.value, 10.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Z.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_VEL_X.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_VEL_Y.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_VEL_Z.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_SIGLVL.value, 450),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_X_MIN.value, 1.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Y_MIN.value, 1.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Z_MIN.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_X_MAX.value, 11.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Y_MAX.value, 17.0),
(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Z_MAX.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_X.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_Y.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_Z.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_VEL_X.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_VEL_Y.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_VEL_Z.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_SIGLVL.value, 950),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_X_MIN.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_Y_MIN.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_Z_MIN.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_X_MAX.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_Y_MAX.value, 0.0),
(protocol_kx.KDescription.K_TEST_SOURCE_2_POS_Z_MAX.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DT.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DX.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DY.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DVX.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DVY.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DR.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DV.value, 0.0),
(protocol_kx.KDescription.K_JPDA_DA.value, 0.0),
(protocol_kx.KDescription.K_JPDA_ASSOC_DR.value, 0.0),
(protocol_kx.KDescription.K_JPDA_ASSOC_DV.value, 0.0),
(protocol_kx.KDescription.K_JPDA_ASSOC_DA.value, 0.0),
(protocol_kx.KDescription.K_JPDA_CONFIRM_COUNT.value, 0.0),
(protocol_kx.KDescription.K_JPDA_CONFIRM_PERIOD.value, 0.0),
(protocol_kx.KDescription.K_JPDA_MISSED_COUNT.value, 0.0),
(protocol_kx.KDescription.K_JPDA_PK_VAL_THLD.value, 0.0),
(protocol_kx.KDescription.K_JPDA_T_SX.value, 0.0),
(protocol_kx.KDescription.K_JPDA_T_SY.value, 0.0),
(protocol_kx.KDescription.K_JPDA_T_SVX.value, 0.0),
(protocol_kx.KDescription.K_JPDA_T_SVY.value, 0.0),
(protocol_kx.KDescription.K_JPDA_ADV_PK_VAL.value, 0.0),
(protocol_kx.KDescription.K_JPDA_ADV_SY_MULT.value, 0.0),
(protocol_kx.KDescription.K_JPDA_BND_BOX_XL.value, 0.0),
(protocol_kx.KDescription.K_JPDA_BND_BOX_XR.value, 0.0),
(protocol_kx.KDescription.K_JPDA_BND_BOX_YB.value, 0.0),
(protocol_kx.KDescription.K_JPDA_BND_BOX_YT.value, 0.0),
(protocol_kx.KDescription.K_MRR_RX_GAIN.value, 0.0),
(protocol_kx.KDescription.K_USRR_RX_GAIN.value, 0.0),
(protocol_kx.KDescription.K_TO_DSS.value, 0.0),
(protocol_kx.KDescription.K_TO_DSS_2.value, 0.0)
])
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 = kx.KX(255, can0, Init_Struct)
KXLOX.send_test_source_enable(0)
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)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Y_MIN.value, 1)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_Y.value, 7)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_POS_X.value, 7)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCE_1_SIGLVL.value, 450)
KXLOX.KXInit(protocol_kx.KDescription.K_TEST_SOURCES_ENABLED.value, 1)
KXLOX.send_test_source_enable(1)
KXLOX.send_receive_cmd()

View File

@@ -17,14 +17,6 @@ KX_FLAG_WRITE_ERR = 7
KX_FLAG_WRITE_OK = 8
class CANMsgK:
def __init__(self, sblID, index, flag, k):
self.sblID = sblID
self.index = index
self.flag = flag
self.k = k
class KDescription(Enum):
K_SBL_ID = 0
K_TEST_COMP_RX_CHAIN_DISABLED = 1