#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#define DEBUG_FILE1 "/tmp/dbg_param.txt"
#define DEBUG_FILE2 "/tmp/mnt/sdcard/dbg_param.txt"
typedef enum {
DBG_VALUE_TYPE_INT,
DBG_VALUE_TYPE_BOOL,
DBG_VALUE_TYPE_STRING,
DBG_VALUE_TYPE_FLOAT,
}DBG_VALUE_TYPE;
int debug_getinfo(char* key, char** value, DBG_VALUE_TYPE type)
{
if (!key || !value)
{
printf ("para is null\n");
return -1;
}
if (type > DBG_VALUE_TYPE_FLOAT || type < DBG_VALUE_TYPE_INT)
{
printf ("value type error\n");
return -1;
}
FILE * fp1;
FILE * fp2;
bool check1 = false;
bool check2 = false;
int ret = access(DEBUG_FILE1, F_OK);
if (ret == 0 && (fp1 = fopen(DEBUG_FILE1, "r")))
{
check1 = true;
}
ret = access(DEBUG_FILE2, F_OK);
if (ret == 0 && (fp2 = fopen(DEBUG_FILE2, "r")))
{
check2 = true;
}
char *line = NULL;
char* p = NULL;
char* goal = NULL;
size_t len = 0;
ssize_t read;
if (check1)
{
while ((read = getline(&line, &len, fp1)) != -1)
{
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
p = strstr(line, key);
if (p)
{
p += strlen(key);
printf ("find the %s\n", key);
for ( ; *p == ' ' || *p == '\t';p++);
if (*p++ == '=')
{
goal = (char*)calloc(1, strlen(p)+1);
strcpy(goal, p);
*value = goal;
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
break;
}
}
}
free(line);
fclose(fp1);
if (goal)
{
printf ("find the key:%s value:%s at %s\n",key, *value, DEBUG_FILE1);
return 0;
}
}
line = NULL;
p = NULL;
goal = NULL;
len = 0;
if (check2)
{
while ((read = getline(&line, &len, fp2)) != -1)
{
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
p = strstr(line, key);
if (p)
{
p += strlen(key);
for ( ; *p == ' ' || *p == '\t';p++);
if (*p++ == '=')
{
goal = (char*)calloc(1, strlen(p)+1);
strcpy(goal, p);
*value = goal;
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
break;
}
}
}
free(line);
fclose(fp2);
if (goal)
{
printf ("find the key:%s value:%s at %s\n",key, *value, DEBUG_FILE1);
return 0;
}
}
printf ("not find the the %s\n", key);
return -1;
}
这就是读一个指定路径下的指定配置文件,来获取配置参数。
例如:
ret = debug_getinfo("cameraAngle", &vstr, DBG_VALUE_TYPE_FLOAT);
if (ret == 0 && vstr)
{
f_ca = atof(vstr);
free (vstr);
vstr = NULL;
}
配置文件:
cameraAngle=44.4 标定餐数
cameraHeight=111.1 标定参数
fl=222.2 标定参数
debug=1 是否获取图灵后台上传的原始图和调整后的图
takepicture=1 是否使能抓图放在本地
这个还是比较方便的,你可以在程序的任何地方可以设置控制点,后改变参数。