You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
4.3 KiB
160 lines
4.3 KiB
1 week ago
|
--�ִ���־����
|
||
|
WIN_0 = 0x0001
|
||
|
WIN_1 = 0x0002
|
||
|
WIN_2 = 0x0004
|
||
|
WIN_3 = 0x0008
|
||
|
WIN_4 = 0x0010
|
||
|
WIN_5 = 0x0020
|
||
|
WIN_6 = 0x0040
|
||
|
WIN_7 = 0x0080
|
||
|
WIN_8 = 0x0100
|
||
|
WIN_9 = 0x0200
|
||
|
WIN_10 = 0x0400
|
||
|
WIN_11 = 0x0800
|
||
|
WIN_12 = 0x1000
|
||
|
WIN_13 = 0x2000
|
||
|
WIN_14 = 0x4000
|
||
|
WIN_15 = 0x8000
|
||
|
|
||
|
|
||
|
--GV�����ַ���
|
||
|
local GVstr = {
|
||
|
"State_Index_U",
|
||
|
"State_Index_U_Elapse",
|
||
|
"State_Index_N",
|
||
|
"State_Index_N_Elapse",
|
||
|
"NC_ARRAY_u8_0",
|
||
|
"NC_ARRAY_u8_01",
|
||
|
"NC_ARRAY_u8_1",
|
||
|
"NC_ARRAY_u8_11",
|
||
|
"NC_ARRAY_u8_2",
|
||
|
"MK32_Key.RxIndex",
|
||
|
"MK32_Key.CH0_RY_H",
|
||
|
"MK32_Key.CH1_RY_V",
|
||
|
"MK32_Key.CH2_LY_V",
|
||
|
"MK32_Key.CH3_LY_H",
|
||
|
"MK32_Key.CH4_SA",
|
||
|
"MK32_Key.CH5_SB",
|
||
|
"MK32_Key.CH6_SC",
|
||
|
"MK32_Key.CH7_SD",
|
||
|
"MK32_Key.CH8_SE",
|
||
|
"MK32_Key.CH9_SF",
|
||
|
"MK32_Key.CH10_LD1",
|
||
|
"MK32_Key.CH11_RD1",
|
||
|
"MK32_Key.CH12_S1",
|
||
|
"MK32_Key.CH13_S2",
|
||
|
"MK32_Key.CH14_LT",
|
||
|
"MK32_Key.CH15_RT",
|
||
|
"MK32_Key.IsOnline",
|
||
|
"Motor_P[0]MotorID",
|
||
|
"Motor_P[0]RxIndex",
|
||
|
"Motor_P[0]Run_Mode",
|
||
|
"Motor_P[0]Current",
|
||
|
"Motor_P[0]Target_Current",
|
||
|
"Motor_P[0]Velcity",
|
||
|
"Motor_P[0]Target_Velcity",
|
||
|
"Motor_P[0]Position",
|
||
|
"Motor_P[0]Target_Position",
|
||
|
"Motor_P[0]ERROR_Flag",
|
||
|
"Motor_P[0]Temperature_Motor",
|
||
|
"Motor_P[0]Temperature_PCB",
|
||
|
"Motor_P[1]MotorID",
|
||
|
"Motor_P[1]RxIndex",
|
||
|
"Motor_P[1]Run_Mode",
|
||
|
"Motor_P[1]Current",
|
||
|
"Motor_P[1]Target_Current",
|
||
|
"Motor_P[1]Velcity",
|
||
|
"Motor_P[1]Target_Velcity",
|
||
|
"Motor_P[1]Position",
|
||
|
"Motor_P[1]Target_Position",
|
||
|
"Motor_P[1]ERROR_Flag",
|
||
|
"Motor_P[1]Temperature_Motor",
|
||
|
"Motor_P[1]Temperature_PCB",
|
||
|
"Motor_P[2]MotorID",
|
||
|
"Motor_P[2]RxIndex",
|
||
|
"Motor_P[2]Run_Mode",
|
||
|
"Motor_P[2]Current",
|
||
|
"Motor_P[2]Target_Current",
|
||
|
"Motor_P[2]Velcity",
|
||
|
"Motor_P[2]Target_Velcity",
|
||
|
"Motor_P[2]Position",
|
||
|
"Motor_P[2]Target_Position",
|
||
|
"Motor_P[2]ERROR_Flag",
|
||
|
"Motor_P[2]Temperature_Motor",
|
||
|
"Motor_P[2]Temperature_PCB"
|
||
|
}
|
||
|
|
||
|
--CAN ���뺯�������ص��ַ�����չʾ�����ݴ���
|
||
|
--id ֡ID
|
||
|
--std_ext 0��ʾ��֡, 1��ʾ��չ֡
|
||
|
--data_remote 0��ʾ����֡, 1��ʾԶ��֡
|
||
|
--datalen ���ݳ��ȣ��ֽ�
|
||
|
--data_bin ����������
|
||
|
--��������: ret1�����ַ��� , ret2�ִ�������, ���������ַ���
|
||
|
function can_decoder(id, std_ext, data_remote, datalen, data_bin)
|
||
|
local ret1 = "" --����ֵ1 ������ʾ����
|
||
|
local ret2 = 0 --����ֵ2 �ִ���־
|
||
|
local bin = {}
|
||
|
local i
|
||
|
local str_wave = ""
|
||
|
|
||
|
local _index = 0
|
||
|
local _value = 0
|
||
|
--local a_string = string.pack(">i2", your_integer)
|
||
|
--local an_integer = string.unpack(">i2", a_string, start) ���������ַ���ת��Ϊ�������ͣ��ӵ�start���ַ���ʼ��<С�� >���ˣ�����i2������2
|
||
|
|
||
|
--#���ַ���ת����������������
|
||
|
for i = 1,#data_bin,1 do
|
||
|
bin[i] = tonumber(string.byte(data_bin, i,i))
|
||
|
end
|
||
|
|
||
|
--������������,����ʾ�����ݰ�����
|
||
|
if (id == 0x120) then
|
||
|
_index = string.unpack("<i2", data_bin, 1)
|
||
|
_value = string.unpack("<i4", data_bin, 3)
|
||
|
ret1 = string.format("����CV��Index %d = %d", _index, _value)
|
||
|
elseif (id == 0x121) then
|
||
|
_index = string.unpack("<i2", data_bin, 1)
|
||
|
ret1 = string.format("����CV��Index %d", _index, _value)
|
||
|
elseif (id == 0x122) then
|
||
|
_index = string.unpack("<i2", data_bin, 1)
|
||
|
_value = string.unpack("<i4", data_bin, 3)
|
||
|
ret1 = string.format("��ȡCV��Index %d = %d", _index, _value)
|
||
|
elseif (id == 0x1FF) then
|
||
|
if(datalen == 1) then
|
||
|
ret1 = string.format("## Boot��������")
|
||
|
elseif (datalen == 3) then
|
||
|
ret1 = string.format("## Boot����APP")
|
||
|
elseif (datalen == 2) then
|
||
|
ret1 = string.format("## ����ˢдģʽ")
|
||
|
elseif (datalen == 4) then
|
||
|
ret1 = string.format("## ˢд����")
|
||
|
elseif (datalen == 5) then
|
||
|
ret1 = string.format("## APP��������")
|
||
|
end
|
||
|
elseif (id == 0x110) then
|
||
|
if(data_bin[1]==0x55) then
|
||
|
ret1 = string.format("## ��������ϵͳ")
|
||
|
end
|
||
|
elseif (id == 0x130) then
|
||
|
_index = string.unpack("<i2", data_bin, 1)
|
||
|
_value = string.unpack("<i2", data_bin, 3)
|
||
|
ret1 = string.format("����GV.%d,%s, Length = %d", _index, GVstr[_index+1],_value)
|
||
|
elseif (id == 0x132) then
|
||
|
_index = string.unpack("<i2", data_bin, 1)
|
||
|
_value = string.unpack("<i4", data_bin, 3)
|
||
|
ret1 = string.format("______��ȡGV.%d,%s = %d", _index, GVstr[_index+1],_value)
|
||
|
end
|
||
|
|
||
|
--�����ִ���־, �������ݰ�ͬ����ʾ����Щ�Ӵ���
|
||
|
if (id == 0x120 or id == 0x121 or id == 0x122) then
|
||
|
ret2 = ret2 | WIN_0
|
||
|
elseif (id == 0x1FF or id == 0x110) then
|
||
|
ret2 = ret2 | WIN_1
|
||
|
elseif (id == 0x130 or id == 0x132) then
|
||
|
ret2 = ret2 | WIN_2
|
||
|
end
|
||
|
|
||
|
return ret1, ret2, str_wave
|
||
|
end
|