修复各类问题 --V2.5 zsxfly20241226
This commit is contained in:
parent
a584b681eb
commit
967e983df7
|
@ -142,5 +142,5 @@ void uart_send(uint8_t port, uint16_t len, const uint8_t *data)
|
|||
}
|
||||
|
||||
while (!(uart->SR.TBEM)); // wait tx finish
|
||||
//while (uart->SR.BUSY); // wait idle state
|
||||
//while (uart->SR.BUSY); // wait idle state /*BUG:修复概率性死锁,修复方法:注释改行 zsxfly 20240615*/
|
||||
}
|
||||
|
|
|
@ -0,0 +1,383 @@
|
|||
import serial
|
||||
import serial.tools.list_ports
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
import fnmatch
|
||||
|
||||
def crc16(data):
|
||||
crc = 0xFFFF
|
||||
for byte in data:
|
||||
crc ^= byte
|
||||
for _ in range(8):
|
||||
if (crc & 0x0001) != 0:
|
||||
crc >>= 1
|
||||
crc ^= 0xA001
|
||||
else:
|
||||
crc >>= 1
|
||||
return crc
|
||||
|
||||
def create_frame(index, data):
|
||||
crc = crc16(struct.pack('>H', index) + data)
|
||||
frame = struct.pack('>H', index) + data + struct.pack('>H', crc)
|
||||
return frame
|
||||
|
||||
def list_serial_ports():
|
||||
ports = serial.tools.list_ports.comports()
|
||||
return [port.device for port in ports]
|
||||
|
||||
def list_bin_files(directory):
|
||||
bin_files = []
|
||||
for dirpath, dirnames, filenames in os.walk(directory):
|
||||
for filename in fnmatch.filter(filenames, '*.bin'):
|
||||
# 使用 os.path.relpath 将路径转换为相对路径
|
||||
relative_path = os.path.relpath(os.path.join(dirpath, filename), start=os.getcwd())
|
||||
bin_files.append(relative_path)
|
||||
return bin_files
|
||||
|
||||
# def list_bin_files(directory):
|
||||
# bin_files = []
|
||||
# for dirpath, dirnames, filenames in os.walk(directory):
|
||||
# for filename in fnmatch.filter(filenames, '*.bin'):
|
||||
# bin_files.append(os.path.join(dirpath, filename))
|
||||
# return bin_files
|
||||
|
||||
def select_option(options, prompt):
|
||||
for index, option in enumerate(options):
|
||||
print(f"{index + 1}: {option}")
|
||||
selected_index = int(input(prompt)) - 1
|
||||
if selected_index < 0 or selected_index >= len(options):
|
||||
print("无效的选择。")
|
||||
sys.exit(1)
|
||||
return options[selected_index]
|
||||
|
||||
def main():
|
||||
# 列出可用串口
|
||||
serial_ports = list_serial_ports()
|
||||
if not serial_ports:
|
||||
print("没有找到可用的串口。")
|
||||
sys.exit(1)
|
||||
|
||||
print("可用串口:")
|
||||
selected_port = select_option(serial_ports, "请选择串口序号: ")
|
||||
|
||||
# 列出当前目录及子目录下所有的bin文件
|
||||
bin_files = list_bin_files(os.path.dirname(os.path.abspath(__file__)))
|
||||
if not bin_files:
|
||||
print("没有找到任何 .bin 文件。")
|
||||
sys.exit(1)
|
||||
|
||||
print("找到以下 .bin 文件:")
|
||||
selected_file = select_option(bin_files, "请选择文件序号: ")
|
||||
|
||||
baudrate = 9600 # 这里可以根据需要设置波特率
|
||||
init_delay = 0.04 # 这里也可以根据需要设置延迟
|
||||
|
||||
COM_serial = serial.Serial(selected_port, baudrate, timeout=0)
|
||||
|
||||
with open(selected_file, 'rb') as f:
|
||||
file_data = f.read()
|
||||
|
||||
time.sleep(2) # 等待串口稳定
|
||||
|
||||
# 发送初始化帧
|
||||
chunk = file_data[8:11]
|
||||
chunk = chunk.ljust(16, b'\x00')
|
||||
init_frame = create_frame(0xFF01, chunk)
|
||||
|
||||
count = 0
|
||||
ACK_OK = False
|
||||
while True:
|
||||
print(f"Sent start frame: {init_frame.hex().upper()}")
|
||||
COM_serial.write(init_frame)
|
||||
time_count = 0
|
||||
while True:
|
||||
response = COM_serial.read(2)
|
||||
if len(response) == 2:
|
||||
error_code = int.from_bytes(response, byteorder='big')
|
||||
if 0xFF01 == error_code:
|
||||
ACK_OK = True
|
||||
print("Initialization response received: 0xFF01")
|
||||
break
|
||||
elif 0x5501 == error_code:
|
||||
print("Firmware partition verification fails. Please check whether the selected firmware is correct.")
|
||||
sys.exit(1)
|
||||
elif 0x5502 <= error_code <= 0x5514:
|
||||
print(f"Received error code: {error_code:04X}. Stopping file transmission.")
|
||||
sys.exit(1)
|
||||
time.sleep(0.001)
|
||||
time_count += 1
|
||||
if time_count > 1000:
|
||||
count += 1
|
||||
print("Initialization response not received. Retrying...")
|
||||
break
|
||||
if ACK_OK:
|
||||
break
|
||||
if count >= 3:
|
||||
sys.exit(1)
|
||||
|
||||
index = 0
|
||||
frame_size = 16
|
||||
num_frames = (len(file_data) + frame_size - 1) // frame_size
|
||||
|
||||
# 发送数据帧
|
||||
for i in range(num_frames):
|
||||
start = i * frame_size
|
||||
end = start + frame_size
|
||||
chunk = file_data[start:end]
|
||||
|
||||
if len(chunk) < frame_size:
|
||||
chunk = chunk.ljust(frame_size, b'\x00')
|
||||
|
||||
frame = create_frame(index, chunk)
|
||||
COM_serial.write(frame)
|
||||
if (index % 16 == 0): # 每16个数据帧delay一下
|
||||
time.sleep(0.02)
|
||||
|
||||
# 尝试接收响应和错误码
|
||||
time_count = 0
|
||||
while True:
|
||||
response = COM_serial.read(2)
|
||||
if len(response) == 2:
|
||||
error_code = int.from_bytes(response, byteorder='big')
|
||||
if 0x5501 <= error_code <= 0x5514:
|
||||
print(f"Received error code: {error_code:04X}. Stopping file transmission.")
|
||||
sys.exit(1)
|
||||
time.sleep(0.001)
|
||||
time_count += 1
|
||||
if time_count > (1000 * init_delay):
|
||||
break
|
||||
|
||||
frame_crc = struct.pack('>H', crc16(struct.pack('>H', index) + chunk))
|
||||
print(f"IDX:{struct.pack('>H', index).hex().upper()}|DATA:{chunk.hex().upper()}|CRC:{frame_crc.hex().upper()}")
|
||||
index += 1
|
||||
|
||||
# 发送尾帧
|
||||
end_frame_index = index - 1
|
||||
end_frame_index_bytes = struct.pack('>H', end_frame_index)
|
||||
end_frame_index_inverted = struct.pack('>H', ~end_frame_index & 0xFFFF)
|
||||
end_frame_data = end_frame_index_bytes + end_frame_index_inverted + b'\x00' * 12
|
||||
end_frame = create_frame(0xFF02, end_frame_data)
|
||||
|
||||
print(f"Sent end frame: {end_frame.hex().upper()}")
|
||||
COM_serial.write(end_frame)
|
||||
|
||||
# 尝试接收尾帧响应和错误码
|
||||
time_count = 0
|
||||
while True:
|
||||
response = COM_serial.read(2)
|
||||
if len(response) == 2:
|
||||
error_code = int.from_bytes(response, byteorder='big')
|
||||
if 0xFF02 == error_code:
|
||||
print("OTA update successfully.")
|
||||
break
|
||||
elif 0x5501 <= error_code <= 0x5514:
|
||||
print(f"OTA update failed: error code:{error_code:04X}")
|
||||
sys.exit(1)
|
||||
time.sleep(0.001)
|
||||
time_count += 1
|
||||
if time_count > 1500:
|
||||
print("OTA update failed: timeout...")
|
||||
break
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# import serial
|
||||
# import struct
|
||||
# import sys
|
||||
# import time
|
||||
|
||||
# def crc16(data):
|
||||
# crc = 0xFFFF
|
||||
# for byte in data:
|
||||
# crc ^= byte
|
||||
# for _ in range(8):
|
||||
# if (crc & 0x0001) != 0:
|
||||
# crc >>= 1
|
||||
# crc ^= 0xA001
|
||||
# else:
|
||||
# crc >>= 1
|
||||
# return crc
|
||||
|
||||
# def create_frame(index, data):
|
||||
# crc = crc16(struct.pack('>H', index) + data)
|
||||
# frame = struct.pack('>H', index) + data + struct.pack('>H', crc)
|
||||
# return frame
|
||||
|
||||
# def save_frame_to_file(frame, index):
|
||||
# with open('frames.txt', 'a') as f:
|
||||
# f.write(f"Frame {index}: {frame.hex().upper()}\n")
|
||||
|
||||
# def main():
|
||||
# if len(sys.argv) != 5:
|
||||
# print("Usage: python serial_sender.py <port> <baudrate> <file> <float_delay>")
|
||||
# sys.exit(1)
|
||||
|
||||
# port = sys.argv[1]
|
||||
# baudrate = int(sys.argv[2])
|
||||
# file_path = sys.argv[3]
|
||||
# init_delay = float(sys.argv[4])
|
||||
|
||||
# COM_serial = serial.Serial(port, baudrate, timeout=0)
|
||||
|
||||
# with open(file_path, 'rb') as f:
|
||||
# file_data = f.read()
|
||||
|
||||
# time.sleep(2) #等待串口稳定
|
||||
|
||||
|
||||
# # 发送初始化帧
|
||||
# chunk = file_data[8:11]
|
||||
# chunk = chunk.ljust(16, b'\x00')
|
||||
# init_frame = create_frame(0xFF01, chunk)
|
||||
|
||||
# # init_frame = create_frame(0xFF01, b'\x00' * 16)
|
||||
|
||||
# # response = COM_serial.read(2)
|
||||
# # print(f"Received response: {response.hex().upper()}")
|
||||
# count =0
|
||||
# ACK_OK = False
|
||||
# while True:
|
||||
# print(f"Sent satrt frame: {init_frame.hex().upper()}")
|
||||
# COM_serial.write(init_frame)
|
||||
# time_count = 0
|
||||
# while True:
|
||||
# response = COM_serial.read(2)
|
||||
# error_code = int.from_bytes(response, byteorder='big')
|
||||
# if 0xFF01 == error_code:
|
||||
# ACK_OK = True
|
||||
# print("Initialization response received: 0xFF01")
|
||||
# break
|
||||
# elif 0x5501 == error_code:
|
||||
# print("Firmware partition verification fails. Please check whether the selected firmware is correct.")
|
||||
# sys.exit(1)
|
||||
# # break
|
||||
# elif 0x5502 <= error_code <= 0x5514:
|
||||
# print(f"Received error code: {error_code:04X}. Stopping file transmission.")
|
||||
# # sys.exit(1)
|
||||
# break
|
||||
# else:
|
||||
# time.sleep(0.001)
|
||||
# time_count += 1
|
||||
# if time_count > 1000:
|
||||
# count += 1
|
||||
# print("Initialization response not received. Retrying...")
|
||||
# break
|
||||
# if ACK_OK:
|
||||
# break
|
||||
# if count >= 3:
|
||||
# sys.exit(1)
|
||||
|
||||
# # save_frame_to_file(init_frame, 0)
|
||||
|
||||
# index = 0
|
||||
# frame_size = 16
|
||||
# num_frames = (len(file_data) + frame_size - 1) // frame_size
|
||||
|
||||
# # 发送数据帧
|
||||
# for i in range(num_frames):
|
||||
# start = i * frame_size
|
||||
# end = start + frame_size
|
||||
# chunk = file_data[start:end]
|
||||
|
||||
# if len(chunk) < frame_size:
|
||||
# chunk = chunk.ljust(frame_size, b'\x00')
|
||||
|
||||
# frame = create_frame(index, chunk) # 发送数据帧
|
||||
# COM_serial.write(frame)
|
||||
# if (index % 16 == 0): # 每16个数据帧delay一下
|
||||
# # print("delay...")
|
||||
# time.sleep(0.02)
|
||||
# # 尝试接收响应和错误码
|
||||
# time_count = 0
|
||||
# while True:
|
||||
# response = COM_serial.read(2)
|
||||
# error_code = int.from_bytes(response, byteorder='big')
|
||||
# if 0x5501 <= error_code <= 0x5514:
|
||||
# print(f"Received error code: {error_code:04X}. Stopping file transmission.")
|
||||
# sys.exit(1)
|
||||
# else:
|
||||
# time.sleep(0.001)
|
||||
# time_count += 1
|
||||
# if time_count > (1000 * init_delay):
|
||||
# # print("timeout...")
|
||||
# break
|
||||
|
||||
# # response = COM_serial.read(2)
|
||||
# # if response:
|
||||
# # error_code = int.from_bytes(response, byteorder='big')
|
||||
# # if 0x5501 <= error_code <= 0x5514:
|
||||
# # print(f"Received error code: {error_code:04X}. Stopping file transmission.")
|
||||
# # sys.exit(1)
|
||||
# # # save_frame_to_file(frame, index)
|
||||
# # time.sleep(init_delay)
|
||||
|
||||
# frame_crc = struct.pack('>H',crc16(struct.pack('>H', index) + chunk))
|
||||
# frame_index = struct.pack('>H', index)
|
||||
# print(f"IDX:{frame_index.hex().upper()}|DATA:{chunk.hex().upper()}|CRC:{frame_crc.hex().upper()}")
|
||||
# index += 1
|
||||
|
||||
|
||||
|
||||
# # 发送尾帧
|
||||
# end_frame_index = index - 1
|
||||
# end_frame_index_bytes = struct.pack('>H', end_frame_index)
|
||||
# end_frame_index_inverted = struct.pack('>H', ~end_frame_index & 0xFFFF)
|
||||
# end_frame_data = end_frame_index_bytes + end_frame_index_inverted + b'\x00' * 12
|
||||
# end_frame = create_frame(0xFF02, end_frame_data)
|
||||
|
||||
# print(f"Sent end frame: {end_frame.hex().upper()}")
|
||||
# COM_serial.write(end_frame)
|
||||
# # 尝试接收尾帧响应和错误码
|
||||
# time_count = 0
|
||||
# while True:
|
||||
# response = COM_serial.read(2)
|
||||
# error_code = int.from_bytes(response, byteorder='big')
|
||||
# if 0xFF02 == error_code:
|
||||
# print("OTA update successfully.")
|
||||
# break
|
||||
# elif 0x5501 <= error_code <= 0x5514:
|
||||
# print(f"OTA update failed: error code:{error_code:04X}")
|
||||
# sys.exit(1)
|
||||
# else:
|
||||
# time.sleep(0.001)
|
||||
# time_count += 1
|
||||
# if time_count > 1500:
|
||||
# print("OTA update failed: timeout...")
|
||||
# break
|
||||
# # save_frame_to_file(end_frame, index)
|
||||
|
||||
|
||||
# # end_frame_count = 0
|
||||
# # while True:
|
||||
# # # if COM_serial.in_waiting > 0: # 检查是否有数据可读
|
||||
# # response = COM_serial.read(2)
|
||||
# # if response:
|
||||
# # print(f"Received response: {response.hex().upper()}")
|
||||
# # error_code = int.from_bytes(response, byteorder='big')
|
||||
# # if 0x5501 <= error_code <= 0x5514:
|
||||
# # print(f"Received error code: {error_code:04X}. Stopping file transmission.")
|
||||
# # sys.exit(1)
|
||||
# # elif error_code == 0xFF02:
|
||||
# # print("OTA update successfully.")
|
||||
# # break
|
||||
# # else:
|
||||
# # end_frame_count +=1
|
||||
# # if end_frame_count > 10:
|
||||
# # print("End frame response not received. Stopping file transmission.")
|
||||
# # sys.exit(1)
|
||||
# # print("End frame response not received. Retrying...")
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# main()
|
|
@ -8,7 +8,7 @@ $Ext_asm = '.asm'
|
|||
$Path_lnp = '.\output\'
|
||||
|
||||
# user defined
|
||||
$Path_cmd = 'C:\APP\KeilMDK\ARM\ARMCC\bin'
|
||||
$Path_cmd = 'C:\app\keil_MDK\Keil_v5\ARM\ARMCC\bin'
|
||||
$env:path+=";$Path_cmd;"
|
||||
|
||||
# 获取最新的lnp文件(eg:\projects\bleOTA\mdk\output\bleOTA.lnp)
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
<InvalidFlash>1</InvalidFlash>
|
||||
</TargetStatus>
|
||||
<OutputDirectory>.\output\</OutputDirectory>
|
||||
<OutputName>OTA_V2_1</OutputName>
|
||||
<OutputName>OTA_V2_5</OutputName>
|
||||
<CreateExecutable>1</CreateExecutable>
|
||||
<CreateLib>0</CreateLib>
|
||||
<CreateHexFile>1</CreateHexFile>
|
||||
|
@ -184,6 +184,8 @@
|
|||
<uocXRam>0</uocXRam>
|
||||
<RvdsVP>0</RvdsVP>
|
||||
<RvdsMve>0</RvdsMve>
|
||||
<RvdsCdeCp>0</RvdsCdeCp>
|
||||
<nBranchProt>0</nBranchProt>
|
||||
<hadIRAM2>0</hadIRAM2>
|
||||
<hadIROM2>0</hadIROM2>
|
||||
<StupSel>0</StupSel>
|
||||
|
@ -350,7 +352,7 @@
|
|||
<NoWarn>0</NoWarn>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<useXO>0</useXO>
|
||||
<uClangAs>0</uClangAs>
|
||||
<ClangAsOpt>4</ClangAsOpt>
|
||||
<VariousControls>
|
||||
<MiscControls>--thumb</MiscControls>
|
||||
<Define></Define>
|
||||
|
|
|
@ -4,6 +4,16 @@
|
|||
|
||||
#include "sys_config.h"
|
||||
|
||||
#define DBG_TIME_ENEVT 0
|
||||
|
||||
#if (DBG_TIME_ENEVT)
|
||||
#include "dbg.h"
|
||||
#define DEBUG(format, ...) debug("[TR_ET]" format "\r\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG(format, ...)
|
||||
#define debugHex(dat, len)
|
||||
#endif
|
||||
|
||||
static Time_Events_t Time_Events[Time_Event_MAX];
|
||||
tmr_tk_t Time_Event_tmr_id;
|
||||
|
||||
|
@ -19,11 +29,16 @@ void Event_Handle(uint16_t Event_List ,bool isOn,void *Parameter){
|
|||
break;
|
||||
case Pmode_Timeout_Event:
|
||||
if(!isOn){
|
||||
sys_sta.Pmode =0;
|
||||
DEBUG("Pmode_Timeout_Event\n\nERROR\n\n");
|
||||
// sys_sta.Pmode =0;
|
||||
}
|
||||
break;
|
||||
case GRB_WS2812_Event:
|
||||
if(0x01 == (sys_sta.Pmode | sys_sta.Smode)){
|
||||
GRB_WS2812_Write_color(WS2812_GRBs.len, isOn ? WS2812_GRBs.GRBs : 0x0);
|
||||
}else{
|
||||
GRB_WS2812_Write_color(WS2812_GRBs.len, isOn ? GRB_ORANGE : 0x0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
|
@ -47,6 +62,7 @@ static tmr_tk_t Time_Event_Handle(tmr_id_t id) {
|
|||
// 打开
|
||||
Events->isOn = true;
|
||||
if(Events->Ms_delayoff){
|
||||
DEBUG("OffDelay:%d,delay:%d\n",i,Events->Ms_delayoff);
|
||||
Events->mode = Time_MODE_OFF;
|
||||
Events->delay =1 + Events->Ms_delayoff;
|
||||
Events->Ms_delayoff =0;
|
||||
|
@ -72,7 +88,7 @@ static tmr_tk_t Time_Event_Handle(tmr_id_t id) {
|
|||
}
|
||||
|
||||
}
|
||||
return (Time_delay_interval / 10);
|
||||
return (Time_delay_interval / 10);//1;
|
||||
}
|
||||
|
||||
void Time_Event_Init(void) {
|
||||
|
@ -84,23 +100,31 @@ void Time_Event_Init(void) {
|
|||
Time_Events[i].blinkCount = 0;
|
||||
Time_Events[i].isOn = false;
|
||||
Time_Events[i].Parameter=NULL;
|
||||
Time_Events[i].Ms_delayoff =0;
|
||||
DEBUG("Delay:%d,%dms",i, Time_Events[i].Ms_delayoff);
|
||||
}
|
||||
Time_Event_tmr_id = sftmr_start(10, Time_Event_Handle);
|
||||
}
|
||||
|
||||
void Time_Event_On(uint16_t ledIndex,void *Parameter) {
|
||||
DEBUG("On:%d",ledIndex);
|
||||
Time_Events[ledIndex].mode = Time_MODE_ON;
|
||||
Time_Events[ledIndex].delay = 1;
|
||||
// Time_Events[ledIndex].Ms_delayoff =0;
|
||||
Time_Events[ledIndex].Parameter=Parameter;
|
||||
}
|
||||
|
||||
void Time_Event_Off(uint16_t ledIndex,void *Parameter) {
|
||||
DEBUG("Off:%d",ledIndex);
|
||||
Time_Events[ledIndex].mode = Time_MODE_OFF;
|
||||
Time_Events[ledIndex].delay = 1;
|
||||
// Time_Events[ledIndex].Ms_delayoff =0;
|
||||
Time_Events[ledIndex].Parameter=Parameter;
|
||||
}
|
||||
|
||||
void Time_Event_DelayOff(uint16_t ledIndex ,uint16_t Ms_delayoff,void *Parameter) {
|
||||
DEBUG("Delay:%d,%dms",ledIndex, Ms_delayoff);
|
||||
if(0 == Ms_delayoff/Time_delay_interval){return;}
|
||||
Time_Events[ledIndex].mode = Time_MODE_ON;
|
||||
Time_Events[ledIndex].delay = 1;
|
||||
Time_Events[ledIndex].Ms_delayoff =Ms_delayoff / Time_delay_interval;
|
||||
|
@ -108,12 +132,16 @@ void Time_Event_DelayOff(uint16_t ledIndex ,uint16_t Ms_delayoff,void *Parameter
|
|||
}
|
||||
|
||||
void Time_Event_Cancel_DelayOff(uint16_t ledIndex) {
|
||||
DEBUG("Cancel:%d",ledIndex);
|
||||
Time_Events[ledIndex].mode = Time_MODE_OFF;
|
||||
Time_Events[ledIndex].delay = 0;
|
||||
Time_Events[ledIndex].Ms_delayoff =0;
|
||||
Time_Events[ledIndex].Parameter =NULL;
|
||||
}
|
||||
|
||||
void Time_Event_Blink(uint16_t ledIndex, uint16_t Ms_on, uint16_t Ms_off, uint16_t blinkCount,void *Parameter) {
|
||||
DEBUG("Blink:%d,on%dms,off%dms,count%d",ledIndex, Ms_on, Ms_off, blinkCount);
|
||||
|
||||
Time_Events[ledIndex].mode = Time_MODE_BLINK;
|
||||
Time_Events[ledIndex].Ms_on = Ms_on / Time_delay_interval;
|
||||
Time_Events[ledIndex].Ms_off = Ms_off / Time_delay_interval;
|
||||
|
|
|
@ -33,10 +33,10 @@ static tmr_tk_t BAT_Message_Handle(tmr_id_t id) {
|
|||
WS2812_GRBs.GRBs=GRB_BLUE;
|
||||
}else if(Bat_Percent_100 > Bat_Voltage){
|
||||
BAT_Message.Bat_STA =(BAT_Message.Bat_STA & 0x03)|Bat_100_STA;
|
||||
WS2812_GRBs.GRBs=GRB_GREEN;
|
||||
WS2812_GRBs.GRBs=GRB_WHITE;
|
||||
}else{
|
||||
BAT_Message.Bat_STA =(BAT_Message.Bat_STA & 0xF3)|Bat_Full_STA;
|
||||
WS2812_GRBs.GRBs=GRB_GREEN;
|
||||
WS2812_GRBs.GRBs=GRB_WHITE;
|
||||
}
|
||||
if(0==(BAT_Message.Bat_STA & Bat_Charge_STA)){
|
||||
Bat_Voltage_Last =Bat_Voltage;
|
||||
|
@ -74,7 +74,8 @@ static tmr_tk_t BAT_Message_Handle(tmr_id_t id) {
|
|||
Bat_STA_Last =BAT_Message.Bat_STA;
|
||||
if( Get_Status(OUT_Door_lock)){
|
||||
if(BAT_Message.Bat_STA & Bat_Charge_STA){
|
||||
Time_Event_On(GRB_WS2812_Event,NULL);
|
||||
// Time_Event_On(GRB_WS2812_Event,NULL);
|
||||
Time_Event_Blink(GRB_WS2812_Event,500,500,0xffff,NULL);
|
||||
}else if(BAT_Message.Bat_STA & Bat_Low_STA){
|
||||
Time_Event_Blink(GRB_WS2812_Event,150,150,0xffff,NULL);
|
||||
}else{
|
||||
|
|
|
@ -96,13 +96,14 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
}
|
||||
case 0x0002: // 设备的软件版本号
|
||||
if(CMDCode == 0x03){
|
||||
MODBUS_Sent_BUF[len_count++] =sys_conf.VERSION >> 8;
|
||||
MODBUS_Sent_BUF[len_count++] =sys_conf.VERSION & 0xff;
|
||||
MODBUS_Sent_BUF[len_count++] =(sys_conf.VERSION | VER_TYPE) >> 8;
|
||||
MODBUS_Sent_BUF[len_count++] =(sys_conf.VERSION | VER_TYPE) & 0xff;
|
||||
MODBUS_Sent_BUF[2] +=2;
|
||||
if(0 == --reg_val_num){
|
||||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
len_count =0;
|
||||
// sys_conf.VERSION =reg_val_num;
|
||||
// MODBUS_Sent_BUF[len_count++] =sys_conf.VERSION >> 8;
|
||||
// MODBUS_Sent_BUF[len_count++] =sys_conf.VERSION & 0xff;
|
||||
|
@ -118,6 +119,7 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
len_count =0;
|
||||
// sys_conf.VERSION =reg_val_num;
|
||||
// MODBUS_Sent_BUF[len_count++] =sys_conf.VERSION >> 8;
|
||||
// MODBUS_Sent_BUF[len_count++] =sys_conf.VERSION & 0xff;
|
||||
|
@ -126,10 +128,12 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
{ // 0x0101-0x0002
|
||||
case 0x0101: // // 写系统配置
|
||||
if(CMDCode == 0x03){ // # 读 - 保持寄存器
|
||||
|
||||
len_count =0;
|
||||
break;
|
||||
}else if(CMDCode == 0x06){ // # 写 - 单个寄存器
|
||||
write_cfg(&sys_conf); //保存写入配置
|
||||
MODBUS_Sent_BUF[len_count++] =reg_val_num >> 8;
|
||||
MODBUS_Sent_BUF[len_count++] =reg_val_num & 0xff;
|
||||
break;
|
||||
}
|
||||
case 0x0102: // 管理员模式油门极限寄存器(Unit:%)
|
||||
|
@ -242,11 +246,14 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
uint8_t Pmode_Timeout =((reg_val_num >> 8) & 0xff);
|
||||
if(0 == Pmode_Timeout){
|
||||
Time_Event_Cancel_DelayOff(Pmode_Timeout_Event);
|
||||
}else{
|
||||
Time_Event_DelayOff(Pmode_Timeout_Event ,1000 * Pmode_Timeout ,NULL);
|
||||
}
|
||||
// if(0 == Pmode_Timeout){
|
||||
// Time_Event_Cancel_DelayOff(Pmode_Timeout_Event);
|
||||
// }else{
|
||||
// if(Pmode_Timeout > 65){
|
||||
// Pmode_Timeout =65;
|
||||
// }
|
||||
// Time_Event_DelayOff(Pmode_Timeout_Event ,1000 * Pmode_Timeout ,NULL);
|
||||
// }
|
||||
sys_sta.Pmode =reg_val_num & 0x03;
|
||||
MODBUS_Sent_BUF[len_count++] =reg_val_num >> 8;
|
||||
MODBUS_Sent_BUF[len_count++] =sys_sta.Pmode & 0xff;
|
||||
|
@ -261,6 +268,7 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
len_count =0;
|
||||
// sys_sta.Smode =reg_val_num & 0xff;
|
||||
// MODBUS_Sent_BUF[len_count++] =sys_sta.Smode >> 8;
|
||||
// MODBUS_Sent_BUF[len_count++] =sys_sta.Smode & 0xff;
|
||||
|
@ -334,7 +342,7 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
|
||||
len_count =0;
|
||||
break;
|
||||
}
|
||||
case 0x0302: // 电池电压
|
||||
|
@ -346,7 +354,7 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
|
||||
len_count =0;
|
||||
break;
|
||||
}
|
||||
case 0x0303: // 电池电量
|
||||
|
@ -358,7 +366,7 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
|
||||
len_count =0;
|
||||
break;
|
||||
}
|
||||
case 0x0304: // 剩余充电时间
|
||||
|
@ -370,7 +378,7 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
|
||||
len_count =0;
|
||||
break;
|
||||
}
|
||||
case 0x0305: // 雷达距离信息
|
||||
|
@ -382,7 +390,7 @@ void FunctionalCode_03_06(uint8_t CMDCode, uint16_t reg_addr , uint16_t reg_val_
|
|||
break;
|
||||
}
|
||||
}else if(CMDCode == 0x06){
|
||||
|
||||
len_count =0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,41 @@ typedef struct BLE_GRB_Data{
|
|||
uint32_t GRBs;
|
||||
} BLE_GRB_Data_t;
|
||||
|
||||
#define GRB_RED 0x00ff00;
|
||||
#define GRB_GREEN 0xff0000;
|
||||
#define GRB_BLUE 0x0000ff;
|
||||
#define GRB_RED 0x00ff00
|
||||
#define GRB_GREEN 0xff0000
|
||||
#define GRB_BLUE 0x0000ff
|
||||
#define GRB_WHITE 0xffffff
|
||||
#define GRB_BLACK 0x000000
|
||||
#define GRB_YELLOW 0xffff00
|
||||
#define GRB_CYAN 0x00ffff
|
||||
#define GRB_MAGENTA 0xff00ff
|
||||
#define GRB_ORANGE 0x2B73F5//0xa5ff00
|
||||
#define GRB_PURPLE 0x800080
|
||||
#define GRB_PINK 0xffc0cb
|
||||
#define GRB_BROWN 0xa52a2a
|
||||
#define GRB_GRAY 0x808080
|
||||
#define GRB_LIGHT_BLUE 0xadd8e6
|
||||
#define GRB_DARK_BLUE 0x00008b
|
||||
#define GRB_LIGHT_GREEN 0x90ee90
|
||||
#define GRB_DARK_GREEN 0x006400
|
||||
#define GRB_LIGHT_RED 0xffc0cb
|
||||
#define GRB_DARK_RED 0x8b0000
|
||||
#define GRB_LIGHT_YELLOW 0xffffe0
|
||||
#define GRB_DARK_YELLOW 0xffa500
|
||||
#define GRB_LIGHT_CYAN 0xe0ffff
|
||||
#define GRB_DARK_CYAN 0x008b8b
|
||||
#define GRB_LIGHT_MAGENTA 0xffa07a
|
||||
#define GRB_DARK_MAGENTA 0x8b008b
|
||||
#define GRB_LIGHT_ORANGE 0xffa500
|
||||
#define GRB_DARK_ORANGE 0xff8c00
|
||||
#define GRB_LIGHT_PURPLE 0x800080
|
||||
#define GRB_DARK_PURPLE 0x663399
|
||||
#define GRB_LIGHT_PINK 0xffc0cb
|
||||
#define GRB_DARK_PINK 0xff1493
|
||||
#define GRB_LIGHT_BROWN 0xa52a2a
|
||||
#define GRB_DARK_BROWN 0x663300
|
||||
#define GRB_LIGHT_GRAY 0xd3d3d3
|
||||
#define GRB_DARK_GRAY 0x808080
|
||||
|
||||
|
||||
extern BLE_GRB_Data_t WS2812_GRBs;
|
||||
|
|
|
@ -58,8 +58,6 @@ uint8_t read_cfg(SYS_CONF_t *sys_config_info_t){
|
|||
return ((sys_config_info_t->CRC16 == crc16) ? 0 : 1);
|
||||
}
|
||||
|
||||
#define BANK_A_BASE (0x18004000)
|
||||
#define BANK_B_BASE (0x18020000)
|
||||
void conf_init(void){
|
||||
// read config
|
||||
if( read_cfg(&sys_conf) || (sys_conf.VERSION != SOFTWARE_ID)){
|
||||
|
@ -76,13 +74,6 @@ void conf_init(void){
|
|||
DEBUG("write Default Config!!!");// 写入默认配置
|
||||
write_cfg(&sys_conf);
|
||||
}
|
||||
uint32_t curr_code_addr = RD_32(0x18000008);
|
||||
DEBUG("Curr Addr:0x%x", curr_code_addr);
|
||||
if(curr_code_addr == BANK_A_BASE){
|
||||
sys_conf.VER_type =0;
|
||||
}else if(curr_code_addr == BANK_B_BASE){
|
||||
sys_conf.VER_type =1;
|
||||
}
|
||||
DEBUG("\nsys_conf:lenght=%d",sizeof(sys_conf));
|
||||
DEBUG("VERSION:%#04X",sys_conf.VERSION);
|
||||
DEBUG("Modbus_addr:%#04X",sys_conf.Modbus_addr);
|
||||
|
|
|
@ -57,11 +57,11 @@ void conf_init(void);
|
|||
|
||||
/**************************系统版本**************************/
|
||||
// 软件本号
|
||||
#define SW_VERSION (1)
|
||||
#define SW_VERSION (5)
|
||||
// 硬件本号
|
||||
#define HW_VERSION (2)
|
||||
// 版本类型:0:0x04000;1:0x20000//不可修改
|
||||
#define VER_TYPE (sys_conf.VER_type)
|
||||
#define VER_TYPE ((0x18004000 ==RD_32(0x18000008))?0x0000:0x8000)
|
||||
|
||||
#define SOFTWARE_ID (((SW_VERSION & 0x07FF) | ((HW_VERSION & 0x0F)<<11)) & 0x7fff)
|
||||
|
||||
|
|
Loading…
Reference in New Issue