add zlog.
This commit is contained in:
parent
9b7ce05eb4
commit
ea5dbf1313
@ -77,8 +77,6 @@
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="minilzo-2.10|wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="minilzo-2.10"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="wifi"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
@ -117,6 +115,7 @@
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/WLG"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/zlog/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include"/>
|
||||
@ -129,6 +128,7 @@
|
||||
<option id="gnu.cpp.link.option.paths.1792108116" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" useByScannerDiscovery="false" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/ssl/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/zlog/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/mqtt1410/lib"/>
|
||||
@ -137,6 +137,7 @@
|
||||
</option>
|
||||
<option id="gnu.cpp.link.option.libs.2006599708" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
|
||||
<listOptionValue builtIn="false" value="sqlite3"/>
|
||||
<listOptionValue builtIn="false" value="zlog"/>
|
||||
<listOptionValue builtIn="false" value="boost_system"/>
|
||||
<listOptionValue builtIn="false" value="pthread"/>
|
||||
<listOptionValue builtIn="false" value="boost_thread"/>
|
||||
@ -161,8 +162,6 @@
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="minilzo-2.10|wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="minilzo-2.10"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="wifi"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <linux/rtc.h>
|
||||
#include <linux/rtc.h>
|
||||
#include <boost/xpressive/xpressive_dynamic.hpp>
|
||||
#include <zlog.h>
|
||||
#include "global.hpp"
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
|
||||
@ -33,7 +34,10 @@ char sendpacket[PACKET_SIZE];
|
||||
char recvpacket[PACKET_SIZE];
|
||||
|
||||
static boost::mutex s_config_mu;
|
||||
Mutex g_tDbMutex;
|
||||
|
||||
zlog_category_t *zct;
|
||||
zlog_category_t *zbt;
|
||||
|
||||
string GetLocalTimeWithMs(void) {
|
||||
string defaultTime = "19700101000000000";
|
||||
try {
|
||||
@ -56,6 +60,7 @@ string GetLocalTimeWithMs(void) {
|
||||
return defaultTime;
|
||||
}
|
||||
}
|
||||
|
||||
int code_convert(const char *from_charset, const char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen) {
|
||||
iconv_t cd;
|
||||
char **pin = &inbuf;
|
||||
@ -112,6 +117,7 @@ std::string UTFtoGBK(const char *utf8) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string convertEncoding(const std::string &input, const char *fromEncoding, const char *toEncoding) {
|
||||
iconv_t conv = iconv_open(toEncoding, fromEncoding);
|
||||
if (conv == (iconv_t)-1) {
|
||||
|
||||
73
main.cpp
73
main.cpp
@ -8,44 +8,48 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <boost/thread.hpp>
|
||||
#include "platform/SH_PlatformInit.hpp"
|
||||
#include "common/SH_CommonFunc.hpp"
|
||||
#include "API_log/SH_log.h"
|
||||
#include "common/SH_global.h"
|
||||
#include "threadfunc/SH_ThreadFunc.hpp"
|
||||
#include "secure/SH_Secure.hpp"
|
||||
#include "aes/aes.h"
|
||||
#include "dbaccess/SH_SqlDB.hpp"
|
||||
#include "uart/SH_Uart.hpp"
|
||||
#include <zlog.h>
|
||||
#include "platform/platform_init.hpp"
|
||||
#include "common/common_func.hpp"
|
||||
#include "common/global.hpp"
|
||||
#include "threadfunc/thread_func.hpp"
|
||||
#include "utility/secure.hpp"
|
||||
#include "utility/aes.h"
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
#include "uart/uart.hpp"
|
||||
|
||||
namespace{
|
||||
PlatformInit *platform = PlatformInit::instance();
|
||||
Uart *pUart = Uart::instance();
|
||||
}
|
||||
extern std::vector<RecvData> g_VecWaveDataX;
|
||||
extern std::vector<RecvData> g_VecWaveDataY;
|
||||
extern std::vector<RecvData> g_VecWaveDataZ;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
|
||||
// 初始化日志记录,日志缓存区,记录数,未使用,后期,命令启动
|
||||
log_init(SOFTWARE_RUN_LOG, 1380, 1000 * 1024);
|
||||
LOG_INFO("####CIDNSOFT start####\n");
|
||||
LOG_INFO(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
|
||||
// 查看版本信息
|
||||
if (CheckFileVersion(argc, argv)) {
|
||||
return 0;
|
||||
|
||||
zlog_category_t *zct = NULL;
|
||||
zlog_category_t *zbt = NULL;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int rc = zlog_init("/opt/wlg.conf");
|
||||
if (rc) {
|
||||
printf("init failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
zct = zlog_get_category("wlg");
|
||||
zbt = zlog_get_category("cfg");
|
||||
if (!zct || !zbt) {
|
||||
printf("get category fail\n");
|
||||
zlog_fini();
|
||||
return -2;
|
||||
}
|
||||
|
||||
zlog_info(zbt, " Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__, GlobalConfig::Version.c_str());
|
||||
zlog_info(zbt, "####CIDNSOFT start####\n");
|
||||
|
||||
g_VecWaveDataX.reserve(1000);
|
||||
g_VecWaveDataY.reserve(1000);
|
||||
g_VecWaveDataZ.reserve(1500);
|
||||
// 设置线程属性之栈空间大小
|
||||
boost::thread::attributes attrs;
|
||||
attrs.set_stack_size(1024*1024);//2M
|
||||
attrs.set_stack_size(1024 * 1024);
|
||||
|
||||
// 初始化平台配置文件
|
||||
platform->PlatFormInit();
|
||||
PlatformInit::Init();
|
||||
|
||||
sqlite_db_ctrl::instance().InintGateway();
|
||||
|
||||
@ -64,7 +68,6 @@ int main(int argc, char *argv[])
|
||||
boost::thread InitModuleReadTh(InitModule);
|
||||
InitModuleReadTh.detach();
|
||||
|
||||
|
||||
// 休眠2秒,等待串口线程初始化完毕
|
||||
sleep(2);
|
||||
|
||||
@ -72,7 +75,6 @@ int main(int argc, char *argv[])
|
||||
boost::thread uartWaveReadTh(UartStartWave);
|
||||
uartWaveReadTh.detach();
|
||||
|
||||
|
||||
#ifdef G2UL_GATEWAY
|
||||
//启动 RUN LED
|
||||
boost::thread startRunLED(RunLED);
|
||||
@ -116,7 +118,6 @@ int main(int argc, char *argv[])
|
||||
boost::thread startTcpCgi(attrs, StartCgiServer);
|
||||
startTcpCgi.detach();
|
||||
|
||||
|
||||
sleep(5);
|
||||
uart_inst::instance().ZigbeeInit();
|
||||
sleep(1);
|
||||
@ -130,10 +131,9 @@ int main(int argc, char *argv[])
|
||||
boost::thread startHeart(HeartRep);
|
||||
startHeart.detach();
|
||||
|
||||
if (lzo_init() != LZO_E_OK)
|
||||
{
|
||||
printf("internal error - lzo_init() failed !!!\n");
|
||||
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
|
||||
if (lzo_init() != LZO_E_OK) {
|
||||
zlog_error(zbt, "internal error - lzo_init() failed !!!");
|
||||
zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)");
|
||||
}
|
||||
|
||||
int fd = OpenWatchDog();
|
||||
@ -153,12 +153,9 @@ int main(int argc, char *argv[])
|
||||
count = 0;
|
||||
}
|
||||
if (count >= 30) {
|
||||
LOG_ERROR("===========threadStatus ========failed \n");
|
||||
zlog_error(zbt, "===========threadStatus ========failed");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include "common/global.hpp"
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
|
||||
|
||||
/*********************全局变量声明***********************/
|
||||
int GlobalConfig::RUN_MODE = 0;
|
||||
int GlobalConfig::QuitFlag_G = 1;
|
||||
@ -12,7 +11,6 @@ int GlobalConfig::LinkStatus_G = 0;
|
||||
int GlobalConfig::LinkCount = 0;
|
||||
int GlobalConfig::net0Status = 1;
|
||||
|
||||
|
||||
std::string GlobalConfig::Version = "3.2.5";
|
||||
std::string GlobalConfig::MacAddr_G = "";
|
||||
std::string GlobalConfig::MacAddr_G2 = "";
|
||||
@ -41,17 +39,11 @@ std::string GlobalConfig::UartName_G = "/dev/ttymxc4";
|
||||
enumZigBeeTransmitStatus GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||
int GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
|
||||
PlatformInit::PlatformInit()
|
||||
{
|
||||
PlatformInit::PlatformInit() {}
|
||||
|
||||
}
|
||||
PlatformInit::~PlatformInit() {}
|
||||
|
||||
PlatformInit::~PlatformInit()
|
||||
{
|
||||
}
|
||||
|
||||
void PlatformInit::PlatFormInit()
|
||||
{
|
||||
void PlatformInit::Init() {
|
||||
try {
|
||||
GlobalConfig::MacAddr_G = GetLocalMac("eth0");
|
||||
GlobalConfig::MacAddr_G2 = GetLocalMac("eth1");
|
||||
@ -74,8 +66,7 @@ try{
|
||||
char szUpdateSql[100] = {0x00};
|
||||
sprintf(szUpdateSql, "gatewayMAC = '%s'", GlobalConfig::MacAddr_G.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info", szUpdateSql, NULL);
|
||||
}
|
||||
else if(strMac != GlobalConfig::MacAddr_G ){
|
||||
} else if (strMac != GlobalConfig::MacAddr_G) {
|
||||
LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n", strMac.c_str(), GlobalConfig::MacAddr_G.c_str());
|
||||
strMac.insert(2, ":");
|
||||
strMac.insert(5, ":");
|
||||
@ -91,8 +82,7 @@ try{
|
||||
char szUpdateSql[100] = {0x00};
|
||||
sprintf(szUpdateSql, "MAC2 = '%s'", GlobalConfig::MacAddr_G2.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info", szUpdateSql, NULL);
|
||||
}
|
||||
else if(strMac2 != GlobalConfig::MacAddr_G2 ){
|
||||
} else if (strMac2 != GlobalConfig::MacAddr_G2) {
|
||||
LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n", strMac2.c_str(), GlobalConfig::MacAddr_G2.c_str());
|
||||
strMac2.insert(2, ":");
|
||||
strMac2.insert(5, ":");
|
||||
@ -110,16 +100,13 @@ try{
|
||||
std::string errorinfo = "系统初始化异常";
|
||||
}
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", NULL);
|
||||
for (size_t i = 0; i < vecResult.size(); i++)
|
||||
{
|
||||
for (size_t i = 0; i < vecResult.size(); i++) {
|
||||
compressWaveChannel tempchannel;
|
||||
g_mapCompress.insert(std::make_pair(vecResult[0], tempchannel));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlatformInit::TopicInit()
|
||||
{
|
||||
void PlatformInit::TopicInit() {
|
||||
GlobalConfig::Topic_G.mPubData = "wireless/statisticData/" + GlobalConfig::MacAddr_G;
|
||||
|
||||
GlobalConfig::Topic_G.mPubStatus = "wireless/status/" + GlobalConfig::MacAddr_G;
|
||||
@ -140,7 +127,6 @@ void PlatformInit::TopicInit()
|
||||
|
||||
GlobalConfig::Topic_G.mPubTiming = "equipment/cmd/" + GlobalConfig::MacAddr_G;
|
||||
|
||||
|
||||
GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi";
|
||||
|
||||
GlobalConfig::Topic_G.mPubLocalWaveServer = "up/" + GlobalConfig::MacAddr_G + "/recive/waveserver";
|
||||
@ -154,9 +140,7 @@ void PlatformInit::TopicInit()
|
||||
GlobalConfig::Topic_G.mPubLocalCmd = "up/" + GlobalConfig::MacAddr_G + "/recive/cmd";
|
||||
}
|
||||
|
||||
|
||||
void PlatformInit::ConfigFileCheck()
|
||||
{
|
||||
void PlatformInit::ConfigFileCheck() {
|
||||
if (access(SYSTEMINFOFILE, 0) < 0) {
|
||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName", "");
|
||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId", "");
|
||||
@ -168,7 +152,6 @@ void PlatformInit::ConfigFileCheck()
|
||||
WriteStr2Config(SYSTEMINFOFILE, "Area", "provincesId", "");
|
||||
WriteStr2Config(SYSTEMINFOFILE, "Area", "cityListId", "");
|
||||
WriteStr2Config(SYSTEMINFOFILE, "Uint", "uint", "ST");
|
||||
|
||||
}
|
||||
|
||||
if (access(NETWORKCONFIG, 0) < 0) {
|
||||
@ -186,17 +169,14 @@ void PlatformInit::ConfigFileCheck()
|
||||
}
|
||||
}
|
||||
|
||||
int PlatformInit::ServerIpInit()
|
||||
{
|
||||
int PlatformInit::ServerIpInit() {
|
||||
if (access(SERVERCONFIG, 0) >= 0) {
|
||||
GlobalConfig::ServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||
GlobalConfig::ServerPort = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlatformInit::Sqlite3Init()
|
||||
{
|
||||
void PlatformInit::Sqlite3Init() {
|
||||
sqlite_db_ctrl::instance().OpenDB(GlobalConfig::DbName_G.c_str());
|
||||
char szValue[10] = {0x00};
|
||||
int nType = readIntValue("Update", "type", (char*)GlobalConfig::Config_G.c_str());
|
||||
@ -209,8 +189,7 @@ void PlatformInit::Sqlite3Init()
|
||||
print_info("Sqlite3Init \n");
|
||||
}
|
||||
|
||||
void PlatformInit::GPIOInit()
|
||||
{
|
||||
void PlatformInit::GPIOInit() {
|
||||
#ifdef G2UL_GATEWAY
|
||||
GlobalConfig::GPIO_G.zigAckrep = 507;
|
||||
GlobalConfig::GPIO_G.zigAckreset = 499;
|
||||
@ -235,8 +214,7 @@ void PlatformInit::GPIOInit()
|
||||
GlobalConfig::GPIO_G.errorLed = 130;
|
||||
#endif
|
||||
}
|
||||
void PlatformInit::SystemInfoInit()
|
||||
{
|
||||
void PlatformInit::SystemInfoInit() {
|
||||
std::ifstream ifileOut(SYSTEMINFOFILE);
|
||||
Json::Reader recvReader;
|
||||
Json::Value Systeminfo;
|
||||
@ -266,9 +244,7 @@ void PlatformInit::SystemInfoInit()
|
||||
os.close();
|
||||
}
|
||||
|
||||
|
||||
void PlatformInit::UserInit()
|
||||
{
|
||||
void PlatformInit::UserInit() {
|
||||
std::string userName = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "UserName");
|
||||
if (userName.length() == 0) {
|
||||
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "UserName", "Admin");
|
||||
@ -277,8 +253,7 @@ void PlatformInit::UserInit()
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformInit::EquipIpInit(std::string eth)
|
||||
{
|
||||
void PlatformInit::EquipIpInit(std::string eth) {
|
||||
// eth0 初始化
|
||||
int flag = 0;
|
||||
std::string networkPortStatus = ReadStrByOpt(NETWORKCONFIG, eth, "networkPortStatus");
|
||||
@ -288,8 +263,7 @@ void PlatformInit::EquipIpInit(std::string eth)
|
||||
std::string strStatus = GetFileContent(NETWORK, 18);
|
||||
print_red("strStatus:%s\n networkPortStatus:%s dataWatchIpAddress:%s subnetMask:%s gateway:%s\n", strStatus.c_str(), networkPortStatus.c_str(), dataWatchIpAddress.c_str(), subnetMask.c_str(), gateway.c_str());
|
||||
|
||||
if(0 == networkPortStatus.compare("DHCP"))
|
||||
{
|
||||
if (0 == networkPortStatus.compare("DHCP")) {
|
||||
print_white("dhcp config\n");
|
||||
std::string cmd = "";
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
@ -312,14 +286,12 @@ void PlatformInit::EquipIpInit(std::string eth)
|
||||
#endif
|
||||
flag = 0;
|
||||
}
|
||||
if(0 == networkPortStatus.compare("STATIC"))
|
||||
{
|
||||
if (0 == networkPortStatus.compare("STATIC")) {
|
||||
std::string cmd = "";
|
||||
print_red("static config\n");
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
system("sed -i '18c iface eth0 inet static' /etc/network/interfaces");
|
||||
if(dataWatchIpAddress.length() > 0)
|
||||
{
|
||||
if (dataWatchIpAddress.length() > 0) {
|
||||
cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces";
|
||||
} else {
|
||||
cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces";
|
||||
@ -327,8 +299,7 @@ void PlatformInit::EquipIpInit(std::string eth)
|
||||
system(cmd.c_str());
|
||||
cmd.clear();
|
||||
|
||||
if(subnetMask.length() > 0)
|
||||
{
|
||||
if (subnetMask.length() > 0) {
|
||||
cmd = "sed -i '21c netmask " + subnetMask + "' /etc/network/interfaces";
|
||||
} else {
|
||||
cmd = "sed -i '21c netmask 255.255.255.0' /etc/network/interfaces";
|
||||
@ -336,8 +307,7 @@ void PlatformInit::EquipIpInit(std::string eth)
|
||||
system(cmd.c_str());
|
||||
cmd.clear();
|
||||
|
||||
if(gateway.length() > 0)
|
||||
{
|
||||
if (gateway.length() > 0) {
|
||||
cmd = "sed -i '22c gateway " + gateway + "' /etc/network/interfaces";
|
||||
} else {
|
||||
cmd = "sed -i '22c gateway 0.0.0.0' /etc/network/interfaces";
|
||||
@ -366,7 +336,6 @@ void PlatformInit::EquipIpInit(std::string eth)
|
||||
}
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
|
||||
|
||||
system("reboot");
|
||||
|
||||
#endif
|
||||
@ -374,4 +343,3 @@ void PlatformInit::EquipIpInit(std::string eth)
|
||||
system("systemctl restart systemd-networkd.service");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ public :
|
||||
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||
* @return void
|
||||
*/
|
||||
static void PlatFormInit();
|
||||
static void Init();
|
||||
|
||||
/**
|
||||
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user