mystring.c 添加字符串转浮点函数
This commit is contained in:
@@ -299,7 +299,7 @@
|
||||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
@@ -529,7 +529,7 @@
|
||||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
@@ -216,4 +216,6 @@
|
||||
解决自动更新bootloader死机的问题
|
||||
软件版本2.00
|
||||
解决检测任务中重试失败后不会填充返回值的bug
|
||||
2023.10.17
|
||||
mystring.c 添加字符串转浮点函数
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include "debug.h"
|
||||
#include "stdlib.h"
|
||||
#include "dev_flash.h"
|
||||
#include "compiler_info.h"
|
||||
|
||||
#include "elec_det.h"
|
||||
#include "base/delay.h"
|
||||
@@ -138,7 +139,7 @@ array_def *elec_bootinfo(void)
|
||||
Ye_BoardCheck();
|
||||
board_st.hard_v=sys_param()->hard_version;
|
||||
board_st.resistor_diff=sys_param()->resistor_diff;
|
||||
board_st.hard_v=19;
|
||||
board_st.soft_v=(int)(str_atof(SOFT_VERSION)*100);
|
||||
array_def *r=arr_creat();
|
||||
arr_append(r,0);
|
||||
arr_appends(r,&board_st,sizeof(BoartCheck_st));
|
||||
@@ -404,13 +405,11 @@ array_def *elec_check_with_scheme(array_def *uid_psw)
|
||||
checker_runcfg.excue_rtv=1;
|
||||
task_fun();
|
||||
Checker_Excueindex(task_index);
|
||||
checker_runcfg.rtv_index-=checker_runcfg.rtv_count;
|
||||
if(checker_runcfg.excue_rtv==0)
|
||||
break;
|
||||
checker_runcfg.rtv_index-=checker_runcfg.rtv_count;
|
||||
}
|
||||
if(checker_runcfg.excue_rtv){
|
||||
checker_runcfg.rtv_index+=checker_runcfg.rtv_count;
|
||||
}
|
||||
checker_runcfg.rtv_index+=checker_runcfg.rtv_count;
|
||||
DBG_LOG("task_index:%d,taskid:%d,ret=%d,rtv_index=%d.",task_index,taskid,checker_runcfg.excue_rtv,
|
||||
checker_runcfg.rtv_index);
|
||||
|
||||
|
@@ -6,8 +6,8 @@
|
||||
|
||||
|
||||
|
||||
#define BUILD_DATE "2023-10-16 18:50:56"
|
||||
#define SOFT_VERSION "2.00"
|
||||
#define BUILD_DATE "2023-10-17 09:42:57"
|
||||
#define SOFT_VERSION "2.01"
|
||||
|
||||
|
||||
|
||||
|
@@ -90,8 +90,8 @@ static int test(list_def *argv)
|
||||
cmd_print("param num too less.");
|
||||
return -1;
|
||||
}
|
||||
int num=str_atoi(list_get_str(argv,1));
|
||||
cmd_print("test num=%d,hex=%x",num,num);
|
||||
float num=str_atof(list_get_str(argv,1));
|
||||
cmd_print("test num=%f",num);
|
||||
return 0;
|
||||
}
|
||||
//commend_export(test,test,"cmd test")
|
||||
|
@@ -7,7 +7,7 @@ import mycopy
|
||||
|
||||
|
||||
# 定义软件版本号
|
||||
SOFT_VERION = "2.00"
|
||||
SOFT_VERION = "2.01"
|
||||
|
||||
|
||||
|
||||
|
@@ -132,7 +132,7 @@ static int str_ainttoi(const char *s)
|
||||
ret*=10;
|
||||
ret+=*s-'0';
|
||||
}
|
||||
else return ret;
|
||||
else return ret*sig;
|
||||
s++;
|
||||
}
|
||||
return ret*sig;
|
||||
@@ -226,6 +226,52 @@ list_def *str_atod_list(const char *s, char c)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* 计算整数乘方
|
||||
*
|
||||
*/
|
||||
float str_exp(int a,int b)
|
||||
{
|
||||
int n=1;
|
||||
for(int i=0;i<b;i++){
|
||||
n*=a;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* 把带一个小数点的数字字符串转化为浮点数
|
||||
*
|
||||
*/
|
||||
float str_atof(const char *s)
|
||||
{
|
||||
list_def *nums=str_split(s,'.');
|
||||
int a,b,len;
|
||||
char *sa,*sb;
|
||||
float exp;
|
||||
len=list_length(nums);
|
||||
if(len==2){
|
||||
sa=list_get_str(nums,0);
|
||||
sb=list_get_str(nums,1);
|
||||
a=str_atoi(sa);
|
||||
b=str_atoi(sb);
|
||||
if(a<0) b=-b;
|
||||
return a+(b/str_exp(10,str_len(sb)));
|
||||
}else if(len==1){
|
||||
sa=list_get_str(nums,0);
|
||||
a=str_atoi(sa);
|
||||
return a;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
|
@@ -14,6 +14,7 @@ const char *str_find_char_right_p(const char *s,const char *const p, char c);
|
||||
const char *str_find_char_left(const char *const p,const char *s, char c);
|
||||
int str_ahextoi(const char *s);
|
||||
int str_atoi(const char *s);
|
||||
float str_atof(const char *s);
|
||||
int str_len(const char *s);
|
||||
int str_cpystr(char *s1, const char *s2, char c);
|
||||
list_def *str_split(const char *s,char c);/*temp_ptr*/
|
||||
|
Reference in New Issue
Block a user