|
@@ -170,6 +170,13 @@ int ModelType(char* type,char* network){
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+int isDirectory(const char *path) {
|
|
|
+ struct stat statbuf;
|
|
|
+ if (stat(path, &statbuf) != 0)
|
|
|
+ return 0;
|
|
|
+ return S_ISDIR(statbuf.st_mode);
|
|
|
+}
|
|
|
//==========================================
|
|
|
// Init all share memory
|
|
|
//==========================================
|
|
@@ -215,23 +222,63 @@ int InitShareMemory() {
|
|
|
// Main process
|
|
|
//================================================
|
|
|
int main(int argc, char *argv[]) {
|
|
|
- if (InitShareMemory() == FAIL) {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR("InitShareMemory NG\n");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL) {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- return 0;
|
|
|
+ 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) {
|
|
|
+ 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
|
|
|
+ char MyIpBuf[32]={0};
|
|
|
+ FILE *fpRead;
|
|
|
+
|
|
|
+ //使用shell command來取得ip值
|
|
|
+ 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()的動作
|
|
|
+ if(fpRead != NULL)
|
|
|
+ pclose(fpRead);
|
|
|
+
|
|
|
+ //最後檢查取出的字串當中是否有多餘的換行,若有直接取代為'\0'作結尾
|
|
|
+ renewCh=strstr(MyIpBuf,"\n");
|
|
|
+ if(renewCh)
|
|
|
+ *renewCh= '\0';
|
|
|
+
|
|
|
+ printf("===ip: %s ===\n", MyIpBuf);
|
|
|
+ if(strcmp(MyIpBuf, "192.168.0.21") == 0){
|
|
|
+ CCSID=1;
|
|
|
+ }
|
|
|
+ if(strcmp(MyIpBuf, "192.168.0.22") == 0){
|
|
|
+ CCSID=2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
unsigned char ModelName[64];;
|
|
|
unsigned char SerialNo[64];;
|
|
|
- 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(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){
|
|
|
+ sprintf(ModelName,"CCS%d",CCSID);
|
|
|
+ printf("%s", ModelName);
|
|
|
+ }
|
|
|
int year,month,day,hour,min,sec,i,ty,tm,cnt;
|
|
|
char pwd[70];
|
|
|
char cmd[512];
|
|
@@ -251,6 +298,12 @@ int main(int argc, char *argv[]) {
|
|
|
else{
|
|
|
cnt=6;
|
|
|
}
|
|
|
+ if(isCCS==0){
|
|
|
+ sprintf(pwd," --password %04d%02d%s",year,month,SerialNo);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+// strcpy(pwd,"");
|
|
|
+ }
|
|
|
for(i=0;i<cnt;i++){
|
|
|
if(month-i<1){
|
|
|
tm=month-i+12;
|
|
@@ -260,16 +313,27 @@ int main(int argc, char *argv[]) {
|
|
|
tm=month-i;
|
|
|
ty=year;
|
|
|
}
|
|
|
- sprintf(pwd,"%04d%02d%s",year,month,SerialNo);
|
|
|
- sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/ChargeLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
+ sprintf(cmd,"zip %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/ChargeLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
+ system(cmd);
|
|
|
+ sprintf(cmd,"zip %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/EventLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
system(cmd);
|
|
|
- sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/EventLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
+ sprintf(cmd,"zip %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/SystemLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
system(cmd);
|
|
|
- sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/SystemLog/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
+ sprintf(cmd,"zip %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/OCPP/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
system(cmd);
|
|
|
- sprintf(cmd,"zip --password %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/OCPP/*%04d*%02d*\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec,ty,tm);
|
|
|
+ }
|
|
|
+ if(isCCS==0){
|
|
|
+ sprintf(cmd,"zip %s \t /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip \t /Storage/CCS*.zip\n",pwd,ModelName,SerialNo,year,month,day,hour,min,sec);
|
|
|
+ system(cmd);
|
|
|
+ }
|
|
|
+ if(isCCS==1){
|
|
|
+ const char* server="192.168.0.10";
|
|
|
+ const char* username="vern";
|
|
|
+ const char* password="vern@delta";
|
|
|
+ //sprintf(cmd,"/usr/bin/ftpput -u %s -p %s %s /Storage/CCS/CCS%d-%04d%02d%02d%02d%02d%02d.zip /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip",username,password,server,CCSID,year,month,day,hour,min,sec,ModelName,SerialNo,year,month,day,hour,min,sec);
|
|
|
+ sprintf(cmd,"/usr/bin/ftpput -u %s -p %s %s /Storage/CCS%d.zip /mnt/%s-%s-%04d%02d%02d%02d%02d%02d.zip",username,password,server,CCSID,ModelName,SerialNo,year,month,day,hour,min,sec);
|
|
|
system(cmd);
|
|
|
- printf("Log packing is done!\n");
|
|
|
}
|
|
|
+ printf("Log packing is done!\n");
|
|
|
}
|
|
|
}
|