添加4G模组复位功能
This commit is contained in:
parent
23d0d8d80e
commit
efcb2bc04c
@ -238,6 +238,8 @@ void SqliteDB::SqliteInit(const char *pDbName, bool isDB2)
|
||||
T_DATANODE_TIME(STATICSTARTTIME));
|
||||
CreateTable(sql_exec, isDB2);*/
|
||||
|
||||
execute_sql_file("/opt/configenv/reboot_record.sql");
|
||||
|
||||
}
|
||||
void SqliteDB::Createtable(const char *ptableName)
|
||||
{
|
||||
@ -1556,6 +1558,47 @@ int SqliteDB::CalculateData()
|
||||
}
|
||||
|
||||
}
|
||||
int callback(void *data, int argc, char **argv, char **azColName) {
|
||||
// 如果需要处理查询结果,可以在此回调函数中进行操作
|
||||
for (int i = 0; i < argc; i++) {
|
||||
LOG_ERROR("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int SqliteDB::execute_sql_file(const char *filename) {
|
||||
FILE *file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 获取文件大小
|
||||
fseek(file, 0, SEEK_END);
|
||||
long file_size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
// 为文件内容分配内存
|
||||
char *sql = (char *)malloc(file_size + 1);
|
||||
if (sql == NULL) {
|
||||
fclose(file);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// 读取文件内容到内存
|
||||
fread(sql, 1, file_size, file);
|
||||
sql[file_size] = '\0'; // 确保字符串结尾
|
||||
|
||||
fclose(file);
|
||||
|
||||
// 执行 SQL 文件中的语句
|
||||
char *err_msg = NULL;
|
||||
if (sqlite3_exec(GetDbHandle(false), sql, callback, 0, &err_msg) != SQLITE_OK) {
|
||||
sqlite3_free(err_msg);
|
||||
free(sql);
|
||||
return 3;
|
||||
}
|
||||
free(sql);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SqliteDB::TransBegin()
|
||||
{
|
||||
|
@ -62,6 +62,7 @@ public:
|
||||
int QueryofflineData();
|
||||
int CalculateData();
|
||||
int CalculateWaveRate();
|
||||
int execute_sql_file(const char *filename);
|
||||
std::string GetNodeConfigureInfor(const char* whereCon);
|
||||
int CloseDB();
|
||||
|
||||
|
@ -610,7 +610,18 @@ void JsonData::DataNodeStatusCheck()
|
||||
if (count == nSize && nodeOnline && count != 0)
|
||||
{
|
||||
LOG_ERROR("ALL Node offline,count = %d\n",count);
|
||||
exit(0);
|
||||
char whereCon[100]={0};
|
||||
sprintf(whereCon,"DATE(timestamp, 'unixepoch') = DATE('now') ORDER BY timeStamp DESC limit 0,1");
|
||||
std::string strCount = sql_ctl->GetData(" reboot_record ", "count", whereCon);
|
||||
if (atoi(strCount.c_str()) < 3)//当天大于三次不再重启进程
|
||||
{
|
||||
char insertSql[64] = {0};
|
||||
sprintf(insertSql, "'%s',%d,'%s'",localtimestamp,atoi(strCount.c_str())+1,"ALL Node offline");
|
||||
sql_ctl->InsertData(" reboot_record ", insertSql);
|
||||
exit(0);
|
||||
}else{
|
||||
LOG_ERROR("reboot now count = %d\n",atoi(strCount.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ void CheckThread()
|
||||
GlobalConfig::net0Status = iStatus;
|
||||
}
|
||||
#endif
|
||||
if (7200 == time_check) {//2h
|
||||
if (180 == time_check) {//2h 7200
|
||||
char buf[256] = {0};
|
||||
char buf2[256] = {0};
|
||||
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}",
|
||||
@ -129,11 +129,35 @@ void CheckThread()
|
||||
{
|
||||
LOG_ERROR("MQTT connect failed ,time check\n");
|
||||
#ifdef Q4G_MODULE
|
||||
if(fd){
|
||||
LOG_ERROR("MQTT connect failed ,4G Module\n");
|
||||
write_data(fd,"AT+CFUN=1,1\r\n",15);
|
||||
// if(fd){
|
||||
// LOG_ERROR("MQTT connect failed ,4G Module\n");
|
||||
// write_data(fd,"AT+CFUN=1,1\r\n",15);
|
||||
// system("reboot");
|
||||
// }
|
||||
#ifdef G2UL_GATEWAY
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
char whereCon[100]={0};
|
||||
sprintf(whereCon,"DATE(timestamp, 'unixepoch') = DATE('now') ORDER BY timeStamp DESC limit 0,1");
|
||||
std::string strCount = sql_ctl->GetData(" reboot_record ", "count", whereCon);
|
||||
if (atoi(strCount.c_str()) < 3)//当天大于三次不再重启进程
|
||||
{
|
||||
char insertSql[64] = {0};
|
||||
sprintf(insertSql, "'%s',%d,'%s'",localtimestamp,atoi(strCount.c_str())+1,"4G connect failed ");
|
||||
sql_ctl->InsertData(" reboot_record ", insertSql);
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower,0);
|
||||
LOG_DEBUG("commPower start\n");
|
||||
sleep(2);
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower,1);
|
||||
LOG_DEBUG("commPower End\n");
|
||||
sleep(2);
|
||||
system("reboot");
|
||||
}else{
|
||||
LOG_ERROR("Q4G_MODULE error\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
|
Loading…
x
Reference in New Issue
Block a user