|
@@ -15,20 +15,21 @@
|
|
|
|
|
|
#include <unistd.h>
|
|
|
#include <stdarg.h>
|
|
|
-#include <stdio.h> /*標準輸入輸出定義*/
|
|
|
-#include <stdlib.h> /*標準函數庫定義*/
|
|
|
-#include <unistd.h> /*Unix 標準函數定義*/
|
|
|
-#include <fcntl.h> /*檔控制定義*/
|
|
|
-#include <termios.h> /*PPSIX 終端控制定義*/
|
|
|
-#include <errno.h> /*錯誤號定義*/
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <fcntl.h>
|
|
|
+#include <termios.h>
|
|
|
+#include <errno.h>
|
|
|
#include <errno.h>
|
|
|
#include <string.h>
|
|
|
#include <time.h>
|
|
|
#include <ctype.h>
|
|
|
#include <ifaddrs.h>
|
|
|
-#include "../Projects/define.h"
|
|
|
+#include <math.h>
|
|
|
+#include "define.h"
|
|
|
+
|
|
|
|
|
|
-#include <math.h>
|
|
|
#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
@@ -46,7 +47,7 @@ int mystrcmp(char *p1, char *p2);
|
|
|
void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
|
|
|
void split(char **arr, char *str, const char *del);
|
|
|
|
|
|
-#ifdef SystemLogMessage
|
|
|
+
|
|
|
int StoreLogMsg(const char *fmt, ...) {
|
|
|
char Buf[4096 + 256];
|
|
|
char buffer[4096];
|
|
@@ -66,7 +67,7 @@ int StoreLogMsg(const char *fmt, ...) {
|
|
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour,
|
|
|
tm->tm_min, tm->tm_sec, buffer, tm->tm_year + 1900, tm->tm_mon + 1);
|
|
|
system(Buf);
|
|
|
-#ifdef Debug
|
|
|
+#ifdef ConsloePrintLog
|
|
|
printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year + 1900,
|
|
|
tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
|
|
|
buffer);
|
|
@@ -74,7 +75,6 @@ int StoreLogMsg(const char *fmt, ...) {
|
|
|
|
|
|
return rc;
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
int DiffTimeb(struct timeb ST, struct timeb ET) {
|
|
|
//return milli-second
|
|
@@ -177,6 +177,7 @@ int isDirectory(const char *path) {
|
|
|
return 0;
|
|
|
return S_ISDIR(statbuf.st_mode);
|
|
|
}
|
|
|
+
|
|
|
//==========================================
|
|
|
// Init all share memory
|
|
|
//==========================================
|
|
@@ -221,39 +222,45 @@ int InitShareMemory() {
|
|
|
//================================================
|
|
|
// Main process
|
|
|
//================================================
|
|
|
-int main(int argc, char *argv[]) {
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
int CCSID=0;
|
|
|
int isCCS=isDirectory("/Storage/root");
|
|
|
- if(isCCS==0){
|
|
|
- if (InitShareMemory() == FAIL) {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR("InitShareMemory NG\n");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL) {
|
|
|
+ if(isCCS==0)
|
|
|
+ {
|
|
|
+ if (InitShareMemory() == FAIL)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("InitShareMemory NG\n");
|
|
|
+
|
|
|
+ if (ShmStatusCodeData != NULL)
|
|
|
+ {
|
|
|
ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
|
|
|
}
|
|
|
sleep(5);
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
- if(strcmp(argv[1], "log") == 0){
|
|
|
- if(isCCS==1){
|
|
|
- //get ip to distinguish main or ccs
|
|
|
+
|
|
|
+ if(strcmp(argv[1], "log") == 0)
|
|
|
+ {
|
|
|
+ if(isCCS==1)
|
|
|
+ {
|
|
|
+ // get ip to distinguish main or ccs
|
|
|
char MyIpBuf[32]={0};
|
|
|
FILE *fpRead;
|
|
|
|
|
|
- //使用shell command來取得ip值
|
|
|
+ // Get IP address by shell command
|
|
|
char* command=(char*)"ifconfig eth0|grep 'inet addr' |awk -F \":\" '{print $2}' |awk '{print $1}'";
|
|
|
char* renewCh;
|
|
|
|
|
|
fpRead = popen(command, "r");
|
|
|
fgets(MyIpBuf, 32 , fpRead);
|
|
|
|
|
|
- //記得作pclose()的動作
|
|
|
+ // Have to pclose()
|
|
|
if(fpRead != NULL)
|
|
|
pclose(fpRead);
|
|
|
-
|
|
|
- //最後檢查取出的字串當中是否有多餘的換行,若有直接取代為'\0'作結尾
|
|
|
+
|
|
|
+ // Replace \n to '0'
|
|
|
renewCh=strstr(MyIpBuf,"\n");
|
|
|
if(renewCh)
|
|
|
*renewCh= '\0';
|
|
@@ -269,62 +276,96 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
unsigned char ModelName[64];;
|
|
|
unsigned char SerialNo[64];;
|
|
|
- if(isCCS==0){
|
|
|
+ if(isCCS==0)
|
|
|
+ {
|
|
|
memcpy(ModelName,ShmSysConfigAndInfo->SysConfig.ModelName,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
|
|
|
printf("%s", ModelName);
|
|
|
memcpy(SerialNo,ShmSysConfigAndInfo->SysConfig.SerialNumber,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
|
|
|
printf("%s", SerialNo);
|
|
|
}
|
|
|
- if(CCSID!=0){
|
|
|
+
|
|
|
+ if(CCSID!=0)
|
|
|
+ {
|
|
|
sprintf((char*)ModelName,"CCS%d",CCSID);
|
|
|
printf("%s", ModelName);
|
|
|
}
|
|
|
+
|
|
|
int year,month,i,ty,tm,cnt;
|
|
|
char pwd[70];
|
|
|
- char cmd[1024];
|
|
|
- time_t tt = time(0); //獲取當前時間
|
|
|
- struct tm *pst = localtime(&tt); //把time_t類型轉換為struct tm類型
|
|
|
+ char cmd[2048];
|
|
|
+ time_t tt = time(0); // Get current time
|
|
|
+ struct tm *pst = localtime(&tt); // Transfer time_t to struct tm
|
|
|
year = pst->tm_year + 1900;
|
|
|
month = pst->tm_mon + 1;
|
|
|
- // sprintf(cmd,"rm -f /mnt/%s-%s-*.zip \n",ModelName,SerialNo);
|
|
|
- // system(cmd);
|
|
|
+
|
|
|
system("rm -f /mnt/*.zip");
|
|
|
- if((argc == 3) && isdigit(*argv[2])){
|
|
|
+ if((argc == 3) && isdigit(*argv[2]))
|
|
|
+ {
|
|
|
cnt=atoi(argv[2]);
|
|
|
}
|
|
|
- else{
|
|
|
+ else
|
|
|
+ {
|
|
|
cnt=6;
|
|
|
}
|
|
|
- if(isCCS==0){
|
|
|
+
|
|
|
+ if(isCCS==0)
|
|
|
+ {
|
|
|
sprintf(pwd," --password %04d%02d%s",year,month,SerialNo);
|
|
|
}
|
|
|
- else{
|
|
|
-// strcpy(pwd,"");
|
|
|
- }
|
|
|
- // sprintf(cmd,"zip -9 %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip",pwd,ModelName,SerialNo,year,month,day,hour,min,sec);
|
|
|
- sprintf(cmd,"zip -9 %s \t /mnt/log.zip",pwd);
|
|
|
- for(i=0;i<cnt;i++){
|
|
|
- if(month-i<1){
|
|
|
+ else
|
|
|
+ {}
|
|
|
+
|
|
|
+ // Pack system log
|
|
|
+ sprintf(cmd,"zip -9 %s \t /mnt/system.zip",pwd);
|
|
|
+ for(i=0;i<cnt;i++)
|
|
|
+ {
|
|
|
+ if(month-i<1)
|
|
|
+ {
|
|
|
tm=month-i+12;
|
|
|
ty=year-1;
|
|
|
}
|
|
|
- else{
|
|
|
+ else
|
|
|
+ {
|
|
|
tm=month-i;
|
|
|
ty=year;
|
|
|
}
|
|
|
-// sprintf(cmd,"%s \t /Storage/ChargeLog/*%04d*%02d*",cmd,ty,tm);
|
|
|
- sprintf(cmd,"%s \t /Storage/EventLog/*%04d*%02d*",cmd,ty,tm);
|
|
|
sprintf(cmd,"%s \t /Storage/SystemLog/*%04d*%02d*",cmd,ty,tm);
|
|
|
sprintf(cmd,"%s \t /Storage/OCPP/*%04d*%02d*",cmd,ty,tm);
|
|
|
}
|
|
|
- sprintf(cmd,"%s \t /Storage/ChargeLog/*.db",cmd);
|
|
|
sprintf(cmd,"%s \t /Storage/OCPP/*.db",cmd);
|
|
|
- sprintf(cmd,"%s \t /Storage/EventLog/*.db",cmd);
|
|
|
+
|
|
|
if(isCCS==0){
|
|
|
sprintf(cmd,"%s \t /Storage/CCS*.zip",cmd);
|
|
|
}
|
|
|
system(cmd);
|
|
|
- if(isCCS==1){
|
|
|
+
|
|
|
+ // Pack Event & Charging Log
|
|
|
+ sprintf(cmd,"zip -9 \t /mnt/charging_event.zip");
|
|
|
+ for(i=0;i<cnt;i++)
|
|
|
+ {
|
|
|
+ if(month-i<1)
|
|
|
+ {
|
|
|
+ tm=month-i+12;
|
|
|
+ ty=year-1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tm=month-i;
|
|
|
+ ty=year;
|
|
|
+ }
|
|
|
+ sprintf(cmd,"%s \t /Storage/EventLog/*%04d*%02d*",cmd,ty,tm);
|
|
|
+ }
|
|
|
+ sprintf(cmd,"%s \t /Storage/ChargeLog/*.db",cmd);
|
|
|
+ sprintf(cmd,"%s \t /Storage/EventLog/*.db",cmd);
|
|
|
+ system(cmd);
|
|
|
+
|
|
|
+ // Combine all zip file to one
|
|
|
+ system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
|
|
|
+ system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
|
|
|
+
|
|
|
+
|
|
|
+ if(isCCS==1)
|
|
|
+ {
|
|
|
const char* server="192.168.0.10";
|
|
|
const char* username="vern";
|
|
|
const char* password="vern@delta";
|
|
@@ -332,6 +373,7 @@ int main(int argc, char *argv[]) {
|
|
|
sprintf(cmd,"/usr/bin/ftpput -u %s -p %s %s /Storage/CCS%d.zip /mnt/log.zip",username,password,server,CCSID);
|
|
|
system(cmd);
|
|
|
}
|
|
|
+
|
|
|
printf("Log packing is done!\n");
|
|
|
}
|
|
|
}
|