更新电池电量算法
其它更改(待测试)
This commit is contained in:
parent
1153f750cf
commit
736bf46d2f
@ -91,33 +91,34 @@ static void timer485_cb()
|
|||||||
{
|
{
|
||||||
rt_sem_release(sendcmd);
|
rt_sem_release(sendcmd);
|
||||||
}
|
}
|
||||||
|
static int b2v(uint8_t *din)
|
||||||
|
{
|
||||||
|
int rst = (din[0] << 8) + din[1];
|
||||||
|
return rst;
|
||||||
|
}
|
||||||
void parseBattInfo(uint8_t *din, size_t len)
|
void parseBattInfo(uint8_t *din, size_t len)
|
||||||
{
|
{
|
||||||
LOG_HEX("batt",16,din,len);
|
// LOG_HEX("batt",16,din,len);
|
||||||
uint8_t head[]={0x01,0x03,0x3a};
|
uint8_t head[]={0x01,0x03,0x3a};
|
||||||
if (rt_memcmp(din, head, sizeof(head)) != 0) {
|
if (rt_memcmp(din, head, sizeof(head)) != 0) {
|
||||||
LOG_W("answer from battery is error.");
|
LOG_W("answer from battery is error.");
|
||||||
}
|
}
|
||||||
rt_memcpy(&batt, din+sizeof(head), sizeof(batt));
|
rt_memcpy(&batt, din+sizeof(head), sizeof(batt));
|
||||||
LOG_D("batt=%X,%X,%d\%",batt.level[0],batt.level[1]);
|
// LOG_D("batt=%X,%X,%d\%",batt.level[0],batt.level[1],b2v(batt.level));
|
||||||
}
|
|
||||||
static uint16_t b2v(uint8_t *din)
|
|
||||||
{
|
|
||||||
return din[0] << 8 + din[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dumpBattInfo()
|
static void dumpBattInfo()
|
||||||
{
|
{
|
||||||
rt_kprintf("标称电压 %s\n",b2v(batt.norVol));
|
rt_kprintf("标称电压 %d\n",b2v(batt.norVol));
|
||||||
rt_kprintf("电芯数量 %s\n",b2v(batt.cnt));
|
rt_kprintf("电芯数量 %d\n",b2v(batt.cnt));
|
||||||
rt_kprintf("电量 %s\n",b2v(batt.level));
|
rt_kprintf("电量 %d\n",b2v(batt.level));
|
||||||
rt_kprintf("容量 %s\n",b2v(batt.Ah));
|
rt_kprintf("容量 %d\n",b2v(batt.Ah));
|
||||||
rt_kprintf("输出电流 %s\n",b2v(batt.current));
|
rt_kprintf("输出电流 %d\n",b2v(batt.current));
|
||||||
rt_kprintf("充电电流 %s\n",b2v(batt.incu));
|
rt_kprintf("充电电流 %d\n",b2v(batt.incu));
|
||||||
rt_kprintf("温度1 %s\n",b2v(batt.temp1));
|
rt_kprintf("温度1 %d\n",b2v(batt.temp1));
|
||||||
rt_kprintf("温度2 %s\n",b2v(batt.temp2));
|
rt_kprintf("温度2 %d\n",b2v(batt.temp2));
|
||||||
rt_kprintf("温度3 %s\n",b2v(batt.temp3));
|
rt_kprintf("温度3 %d\n",b2v(batt.temp3));
|
||||||
rt_kprintf("电芯 1电压 %s\n",b2v(batt.vol1));
|
rt_kprintf("电芯 1电压 %d\n",b2v(batt.vol1));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 获取电池电量
|
* 获取电池电量
|
||||||
@ -125,7 +126,7 @@ static void dumpBattInfo()
|
|||||||
*/
|
*/
|
||||||
uint8_t getPowerLevel(void)
|
uint8_t getPowerLevel(void)
|
||||||
{
|
{
|
||||||
return batt.level[1];
|
return b2v(batt.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void serial485_thread_entry(void *parameter)
|
static void serial485_thread_entry(void *parameter)
|
||||||
@ -147,7 +148,6 @@ static void serial485_thread_entry(void *parameter)
|
|||||||
rt_device_write(serial485, 0, cmd, sizeof(cmd));
|
rt_device_write(serial485, 0, cmd, sizeof(cmd));
|
||||||
rt_pin_write(TR485_RE, PIN_LOW);
|
rt_pin_write(TR485_RE, PIN_LOW);
|
||||||
}
|
}
|
||||||
rt_thread_mdelay(10*1000);
|
|
||||||
|
|
||||||
rt_memset(&msg, 0, sizeof(msg));
|
rt_memset(&msg, 0, sizeof(msg));
|
||||||
/* 从消息队列中读取消息*/
|
/* 从消息队列中读取消息*/
|
||||||
@ -167,6 +167,8 @@ static void serial485_thread_entry(void *parameter)
|
|||||||
parseBattInfo(rx_buffer, rx_length);
|
parseBattInfo(rx_buffer, rx_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rt_thread_mdelay(30*1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,16 +25,16 @@
|
|||||||
volatile static uint8_t islock=0;
|
volatile static uint8_t islock=0;
|
||||||
static rt_mutex_t isCfgOk=RT_NULL;
|
static rt_mutex_t isCfgOk=RT_NULL;
|
||||||
static rt_mutex_t isTosendOk=RT_NULL;
|
static rt_mutex_t isTosendOk=RT_NULL;
|
||||||
void initCfg()
|
void initCfgMutex()
|
||||||
{
|
{
|
||||||
isCfgOk = rt_mutex_create("cfg", RT_IPC_FLAG_FIFO);
|
isCfgOk = rt_mutex_create("cfg", RT_IPC_FLAG_FIFO);
|
||||||
isTosendOk = rt_mutex_create("tosend", RT_IPC_FLAG_FIFO);
|
isTosendOk = rt_mutex_create("tosend", RT_IPC_FLAG_FIFO);
|
||||||
}
|
}
|
||||||
INIT_APP_EXPORT(initCfg);
|
//INIT_APP_EXPORT(initCfg);
|
||||||
|
|
||||||
static void setLock()
|
static void setLock()
|
||||||
{
|
{
|
||||||
rt_mutex_take(isCfgOk, RT_WAITING_FOREVER);
|
// rt_mutex_take(isCfgOk, RT_WAITING_FOREVER);
|
||||||
return;
|
return;
|
||||||
while(islock)
|
while(islock)
|
||||||
{
|
{
|
||||||
@ -45,9 +45,10 @@ static void setLock()
|
|||||||
}
|
}
|
||||||
static void clearLock()
|
static void clearLock()
|
||||||
{
|
{
|
||||||
rt_mutex_release(isCfgOk);
|
// rt_mutex_release(isCfgOk);
|
||||||
return;
|
// return;
|
||||||
islock=0;
|
islock=0;
|
||||||
|
LOG_W("------file unlocked");
|
||||||
}
|
}
|
||||||
extern rt_sem_t cfgUpdate;
|
extern rt_sem_t cfgUpdate;
|
||||||
int get_cfg(const char *k);
|
int get_cfg(const char *k);
|
||||||
@ -306,8 +307,8 @@ MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, 重置系统统计数据)
|
|||||||
volatile size_t nislock=0;
|
volatile size_t nislock=0;
|
||||||
static void nsetLock()
|
static void nsetLock()
|
||||||
{
|
{
|
||||||
rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
|
// rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
|
||||||
return;
|
// return;
|
||||||
// LOG_D("--%d--",nislock);
|
// LOG_D("--%d--",nislock);
|
||||||
size_t cnt=10;
|
size_t cnt=10;
|
||||||
while(nislock)
|
while(nislock)
|
||||||
@ -323,8 +324,8 @@ static void nsetLock()
|
|||||||
}
|
}
|
||||||
static void nclearLock()
|
static void nclearLock()
|
||||||
{
|
{
|
||||||
rt_mutex_release(isTosendOk);
|
// rt_mutex_release(isTosendOk);
|
||||||
return;
|
// return;
|
||||||
nislock=0;
|
nislock=0;
|
||||||
LOG_W("file is unlocked.");
|
LOG_W("file is unlocked.");
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ void sysSemInit()
|
|||||||
// rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_FIFO);//检查天通状态
|
// rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_FIFO);//检查天通状态
|
||||||
// rt_sem_release(cfgUpdate); //上电更新值
|
// rt_sem_release(cfgUpdate); //上电更新值
|
||||||
|
|
||||||
initCfg();
|
initCfgMutex();
|
||||||
// void reportINFO();
|
// void reportINFO();
|
||||||
reportINFO();
|
reportINFO();
|
||||||
/* 创建 serial 线程 */
|
/* 创建 serial 线程 */
|
||||||
@ -252,7 +252,7 @@ void sysEventInit(void)
|
|||||||
void sysInit(void)
|
void sysInit(void)
|
||||||
{
|
{
|
||||||
sysSemInit();
|
sysSemInit();
|
||||||
// sysEventInit();
|
initCfg();
|
||||||
if (isInWindowZone() || isManualWindow()) {//开机检查是否在开窗区间内,是则给TT开机
|
if (isInWindowZone() || isManualWindow()) {//开机检查是否在开窗区间内,是则给TT开机
|
||||||
initTT();
|
initTT();
|
||||||
setWindowMode();
|
setWindowMode();
|
||||||
@ -671,6 +671,7 @@ void deInitTT_thread_entry()
|
|||||||
pwTT_thread_entry("0");
|
pwTT_thread_entry("0");
|
||||||
// startAlarm();//alarm 引起崩溃
|
// startAlarm();//alarm 引起崩溃
|
||||||
clearWindowMode();
|
clearWindowMode();
|
||||||
|
setManualWindow(-1);
|
||||||
LOG_W("shunt down TT DONE");
|
LOG_W("shunt down TT DONE");
|
||||||
}
|
}
|
||||||
// initThread = RT_NULL;
|
// initThread = RT_NULL;
|
||||||
@ -689,7 +690,7 @@ void initTT()
|
|||||||
LOG_W("TT is already running.");
|
LOG_W("TT is already running.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
initThread = rt_thread_create("initTT", initTT_thread_entry, RT_NULL, 1024 * 5, 20, 10);
|
initThread = rt_thread_create("initTT", initTT_thread_entry, RT_NULL, 1024 * 5, 25, 10);
|
||||||
/* 创建成功则启动线程 */
|
/* 创建成功则启动线程 */
|
||||||
if (initThread != RT_NULL)
|
if (initThread != RT_NULL)
|
||||||
{
|
{
|
||||||
@ -705,7 +706,7 @@ void initTT()
|
|||||||
if (deinitThread != RT_NULL) {
|
if (deinitThread != RT_NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
deinitThread = rt_thread_create("deInitTT", deInitTT_thread_entry, RT_NULL, 1024 * 5, 19, 10);
|
deinitThread = rt_thread_create("deInitTT", deInitTT_thread_entry, RT_NULL, 1024 * 5, 25, 10);
|
||||||
/* 创建成功则启动线程 */
|
/* 创建成功则启动线程 */
|
||||||
if (deinitThread != RT_NULL)
|
if (deinitThread != RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -593,10 +593,10 @@ void updateAllSysCfg(uint8_t *cfg, size_t len)
|
|||||||
if (rst) {
|
if (rst) {
|
||||||
LOG_I("set value success.");
|
LOG_I("set value success.");
|
||||||
}
|
}
|
||||||
if ((uint16_t)getFileSize("cfg.ini") != (uint16_t)getFileSize("sd/cfg.ini")) {
|
// if ((uint16_t)getFileSize("cfg.ini") != (uint16_t)getFileSize("sd/cfg.ini")) {
|
||||||
LOG_D("backup cfg file to sd");
|
// LOG_D("backup cfg file to sd");
|
||||||
copy("cfg.ini", "sd/cfg.ini");
|
// copy("cfg.ini", "sd/cfg.ini");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 上报系统各项工作参数
|
* 上报系统各项工作参数
|
||||||
@ -1109,6 +1109,14 @@ void parse3SData(uint8_t *din, size_t count)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG_W("无法解析的目标地址");
|
LOG_W("无法解析的目标地址");
|
||||||
|
// cacheDataToFile(din, count);
|
||||||
|
if (isTTjh())
|
||||||
|
{//如果TT为开机状态(具备通信状态?待商榷)则不缓存直接发
|
||||||
|
upSend(din, count);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cacheDataToFile(din, count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ void repGetTT(void)
|
|||||||
{}
|
{}
|
||||||
rt_memset(rstInfo,0x3f,RST_LEN);//初始化
|
rt_memset(rstInfo,0x3f,RST_LEN);//初始化
|
||||||
/* 创建 serial 线程 */
|
/* 创建 serial 线程 */
|
||||||
rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 10, 27+2, 10);
|
rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 30, 27+2, 10);
|
||||||
/* 创建成功则启动线程 */
|
/* 创建成功则启动线程 */
|
||||||
if (thread != RT_NULL)
|
if (thread != RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -86,7 +86,7 @@ void show_version(void)
|
|||||||
char str[30];
|
char str[30];
|
||||||
uint8_t t[10];
|
uint8_t t[10];
|
||||||
size_t len=time2Byte(t);
|
size_t len=time2Byte(t);
|
||||||
rt_kprintf("SW Version: %s, build-%s\n","1.6d",bytes2str(t, 3, 10, "", str));
|
rt_kprintf("SW Version: %s, build-%s\n","1.7d",bytes2str(t, 3, 10, "", str));
|
||||||
}
|
}
|
||||||
|
|
||||||
MSH_CMD_EXPORT(show_version,显示版本号);
|
MSH_CMD_EXPORT(show_version,显示版本号);
|
||||||
|
Loading…
Reference in New Issue
Block a user