Browse Source

部分日志信息

master
忱 沈 3 weeks ago
parent
commit
0a20e23704
  1. 57
      applications/INI/config.c
  2. 2
      applications/data/Variable.c
  3. 2
      applications/data/Variable.h
  4. 9
      applications/drv/drv_ads111x.c
  5. 2
      applications/drv/drv_aht20.c

57
applications/INI/config.c

@ -14,11 +14,46 @@
#define INI_config "/sys/828config.ini"
int read_write_sample(void)
#define DBG_TAG "INI.config"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
void write_sample(void)
{
//检查文件
if (access(INI_config, F_OK) != 0)
{
LOG_E("NOT 828config");
int fd = open(INI_config, O_WRONLY | O_CREAT);//创建文件
close(fd);
}
// 初始化INI解析器
INI_File *ini = ini_init();
if (!ini) {
return;
}
// 解析INI文件
if (ini_parse(ini, INI_config) != 0)
{
LOG_E("Analysis failed");
ini_free(ini);
return;
}
LOG_I("write config");
// 写入各种类型的值
ini_set_value(ini,"CONFIG", "ID",machine_ID);
ini_set_value(ini,"CONFIG", "NAME",machine_name);
ini_save(ini,INI_config);
// 清理资源
ini_free(ini);
}
int read_sample(void)
{
//检查文件
if (access(INI_config, F_OK) != 0)
{
LOG_E("NOT 828config");
int fd = open(INI_config, O_WRONLY | O_CREAT);//创建文件
close(fd);
}
@ -28,22 +63,24 @@ int read_write_sample(void)
return -1;
}
// 解析INI文件
if (ini_parse(ini, INI_config) != 0) {
rt_kprintf("2\n");
if (ini_parse(ini, INI_config) != 0)
{
LOG_E("Retry");
rt_thread_mdelay(100);
if (ini_parse(ini, INI_config) != 0)
{
LOG_E("Analysis failed");
ini_free(ini);
return -1;
}
}
LOG_I("read config");
// 读取各种类型的值
strncpy(machine_ID, ini_get_value(ini, "CONFIG", "ID","99"),sizeof(machine_ID));
machine_name = ini_get_value(ini, "CONFIG", "NAME","SC828");
//// ini_set_value(ini,"database", "host","192.168.9.1");
// ini_save(ini,INI_config);
strncpy(machine_name, ini_get_value(ini, "CONFIG", "NAME","SC828"),sizeof(machine_name));
// 清理资源
ini_free(ini);
return 0;
}
INIT_APP_EXPORT(read_write_sample);
INIT_APP_EXPORT(read_sample);

2
applications/data/Variable.c

@ -17,7 +17,7 @@ int pow_dev2;//设备电压,其它
char *DATA_dat;
char DATA_machins[3];
char DATA_api[5];
char *machine_name;
char machine_name[16];
char machine_ID[3];
// 状态标志

2
applications/data/Variable.h

@ -18,7 +18,7 @@ extern int pow_dev2;//设备电压,其它
extern char *DATA_dat;
extern char DATA_machins[3];
extern char DATA_api[5];
extern char *machine_name;
extern char machine_name[16];
extern char machine_ID[3];
// ===== 布尔变量 =====

9
applications/drv/drv_ads111x.c

@ -136,11 +136,11 @@ static rt_int32_t ads1115_raw_to_mv(rt_int16_t raw)
*/
static void ads1115_thread_entry(void *parameter)
{
rt_int16_t raw = 0 ,mt = 3600;
rt_int16_t raw = 0 ,mt = 900;
while (1)
{
if(mt>3600)
if(mt>900)
{
if (ads1115_read_channel(0, &raw) == RT_EOK)
{
@ -155,6 +155,7 @@ static void ads1115_thread_entry(void *parameter)
{
mt = 0;
}
rt_thread_mdelay(1000);
if (ads1115_read_channel(1, &raw) == RT_EOK)
{
@ -164,6 +165,7 @@ static void ads1115_thread_entry(void *parameter)
{
LOG_E("Failed to read ADS1115 P_CODE");
}
rt_thread_mdelay(1000);
if (ads1115_read_channel(2, &raw) == RT_EOK)
{
@ -173,6 +175,7 @@ static void ads1115_thread_entry(void *parameter)
{
LOG_E("Failed to read ADS1115 P_DEV1");
}
rt_thread_mdelay(1000);
if (ads1115_read_channel(3, &raw) == RT_EOK)
{
@ -182,8 +185,6 @@ static void ads1115_thread_entry(void *parameter)
{
LOG_E("Failed to read ADS1115 P_DEV2");
}
rt_thread_mdelay(1000); // 每 秒读取一次
}
}

2
applications/drv/drv_aht20.c

@ -93,7 +93,7 @@ static rt_err_t aht20_init_sensor(void)
/* 读取状态字节(可选) */
if (aht20_read_data(&status, 1) == RT_EOK)
{
LOG_D("AHT20 status: 0x%02X", status);
LOG_I("AHT20 status: 0x%02X", status);
}
return RT_EOK;

Loading…
Cancel
Save