更新电池电量算法

其它更改(待测试)
This commit is contained in:
CSSC-WORK\murmur 2023-09-02 19:33:16 +08:00
parent 1153f750cf
commit 736bf46d2f
6 changed files with 50 additions and 38 deletions

View File

@ -91,33 +91,34 @@ static void timer485_cb()
{
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)
{
LOG_HEX("batt",16,din,len);
// LOG_HEX("batt",16,din,len);
uint8_t head[]={0x01,0x03,0x3a};
if (rt_memcmp(din, head, sizeof(head)) != 0) {
LOG_W("answer from battery is error.");
}
rt_memcpy(&batt, din+sizeof(head), sizeof(batt));
LOG_D("batt=%X,%X,%d\%",batt.level[0],batt.level[1]);
}
static uint16_t b2v(uint8_t *din)
{
return din[0] << 8 + din[1];
// LOG_D("batt=%X,%X,%d\%",batt.level[0],batt.level[1],b2v(batt.level));
}
static void dumpBattInfo()
{
rt_kprintf("标称电压 %s\n",b2v(batt.norVol));
rt_kprintf("电芯数量 %s\n",b2v(batt.cnt));
rt_kprintf("电量 %s\n",b2v(batt.level));
rt_kprintf("容量 %s\n",b2v(batt.Ah));
rt_kprintf("输出电流 %s\n",b2v(batt.current));
rt_kprintf("充电电流 %s\n",b2v(batt.incu));
rt_kprintf("温度1 %s\n",b2v(batt.temp1));
rt_kprintf("温度2 %s\n",b2v(batt.temp2));
rt_kprintf("温度3 %s\n",b2v(batt.temp3));
rt_kprintf("电芯 1电压 %s\n",b2v(batt.vol1));
rt_kprintf("标称电压 %d\n",b2v(batt.norVol));
rt_kprintf("电芯数量 %d\n",b2v(batt.cnt));
rt_kprintf("电量 %d\n",b2v(batt.level));
rt_kprintf("容量 %d\n",b2v(batt.Ah));
rt_kprintf("输出电流 %d\n",b2v(batt.current));
rt_kprintf("充电电流 %d\n",b2v(batt.incu));
rt_kprintf("温度1 %d\n",b2v(batt.temp1));
rt_kprintf("温度2 %d\n",b2v(batt.temp2));
rt_kprintf("温度3 %d\n",b2v(batt.temp3));
rt_kprintf("电芯 1电压 %d\n",b2v(batt.vol1));
}
/**
*
@ -125,7 +126,7 @@ static void dumpBattInfo()
*/
uint8_t getPowerLevel(void)
{
return batt.level[1];
return b2v(batt.level);
}
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_pin_write(TR485_RE, PIN_LOW);
}
rt_thread_mdelay(10*1000);
rt_memset(&msg, 0, sizeof(msg));
/* 从消息队列中读取消息*/
@ -167,6 +167,8 @@ static void serial485_thread_entry(void *parameter)
parseBattInfo(rx_buffer, rx_length);
}
rt_thread_mdelay(30*1000);
}

View File

@ -25,16 +25,16 @@
volatile static uint8_t islock=0;
static rt_mutex_t isCfgOk=RT_NULL;
static rt_mutex_t isTosendOk=RT_NULL;
void initCfg()
void initCfgMutex()
{
isCfgOk = rt_mutex_create("cfg", RT_IPC_FLAG_FIFO);
isTosendOk = rt_mutex_create("tosend", RT_IPC_FLAG_FIFO);
}
INIT_APP_EXPORT(initCfg);
//INIT_APP_EXPORT(initCfg);
static void setLock()
{
rt_mutex_take(isCfgOk, RT_WAITING_FOREVER);
// rt_mutex_take(isCfgOk, RT_WAITING_FOREVER);
return;
while(islock)
{
@ -45,9 +45,10 @@ static void setLock()
}
static void clearLock()
{
rt_mutex_release(isCfgOk);
return;
// rt_mutex_release(isCfgOk);
// return;
islock=0;
LOG_W("------file unlocked");
}
extern rt_sem_t cfgUpdate;
int get_cfg(const char *k);
@ -306,8 +307,8 @@ MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, 重置系统统计数据)
volatile size_t nislock=0;
static void nsetLock()
{
rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
return;
// rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
// return;
// LOG_D("--%d--",nislock);
size_t cnt=10;
while(nislock)
@ -323,8 +324,8 @@ static void nsetLock()
}
static void nclearLock()
{
rt_mutex_release(isTosendOk);
return;
// rt_mutex_release(isTosendOk);
// return;
nislock=0;
LOG_W("file is unlocked.");
}

View File

@ -212,7 +212,7 @@ void sysSemInit()
// rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_FIFO);//检查天通状态
// rt_sem_release(cfgUpdate); //上电更新值
initCfg();
initCfgMutex();
// void reportINFO();
reportINFO();
/* 创建 serial 线程 */
@ -252,7 +252,7 @@ void sysEventInit(void)
void sysInit(void)
{
sysSemInit();
// sysEventInit();
initCfg();
if (isInWindowZone() || isManualWindow()) {//开机检查是否在开窗区间内是则给TT开机
initTT();
setWindowMode();
@ -671,6 +671,7 @@ void deInitTT_thread_entry()
pwTT_thread_entry("0");
// startAlarm();//alarm 引起崩溃
clearWindowMode();
setManualWindow(-1);
LOG_W("shunt down TT DONE");
}
// initThread = RT_NULL;
@ -689,7 +690,7 @@ void initTT()
LOG_W("TT is already running.");
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)
{
@ -705,7 +706,7 @@ void initTT()
if (deinitThread != RT_NULL) {
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)
{

View File

@ -593,10 +593,10 @@ void updateAllSysCfg(uint8_t *cfg, size_t len)
if (rst) {
LOG_I("set value success.");
}
if ((uint16_t)getFileSize("cfg.ini") != (uint16_t)getFileSize("sd/cfg.ini")) {
LOG_D("backup cfg file to sd");
copy("cfg.ini", "sd/cfg.ini");
}
// if ((uint16_t)getFileSize("cfg.ini") != (uint16_t)getFileSize("sd/cfg.ini")) {
// LOG_D("backup cfg file to sd");
// copy("cfg.ini", "sd/cfg.ini");
// }
}
/**
*
@ -1109,6 +1109,14 @@ void parse3SData(uint8_t *din, size_t count)
}
else {
LOG_W("无法解析的目标地址");
// cacheDataToFile(din, count);
if (isTTjh())
{//如果TT为开机状态具备通信状态待商榷则不缓存直接发
upSend(din, count);
}
else {
cacheDataToFile(din, count);
}
}
}

View File

@ -474,7 +474,7 @@ void repGetTT(void)
{}
rt_memset(rstInfo,0x3f,RST_LEN);//初始化
/* 创建 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)
{

View File

@ -86,7 +86,7 @@ void show_version(void)
char str[30];
uint8_t t[10];
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,);