|  |  |  | @ -15,6 +15,7 @@ | 
		
	
		
			
				|  |  |  |  | #include <netinet/in.h> | 
		
	
		
			
				|  |  |  |  | #include <arpa/inet.h> | 
		
	
		
			
				|  |  |  |  | #include <pthread.h> | 
		
	
		
			
				|  |  |  |  | #include <time.h> | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* 用户代码头文件. */ | 
		
	
		
			
				|  |  |  |  | #include "cmd.h" | 
		
	
	
		
			
				
					|  |  |  | @ -379,6 +380,49 @@ int _csg_response_realtime_data(int sendtype) | 
		
	
		
			
				|  |  |  |  |     return 0; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | void _csg_set_system_time(unsigned int time) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     struct tm *p =localtime((time_t *)&time);  | 
		
	
		
			
				|  |  |  |  |     char buf[128] = {0};           | 
		
	
		
			
				|  |  |  |  |     sprintf(buf,"date -s \"%d-%d-%d %d:%d:%d\"",1900+p->tm_year,1+p->tm_mon,p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec); | 
		
	
		
			
				|  |  |  |  |     LOG("%s U32:0x%08x",buf,time); | 
		
	
		
			
				|  |  |  |  |     system(buf); | 
		
	
		
			
				|  |  |  |  |     system("hwclock -w"); | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | int _csg_set_utc_time(char *databuf, int datalen) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     if (datalen != sizeof(csg_utc_t)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         int result = 0; | 
		
	
		
			
				|  |  |  |  |         DBG(DBG_M_CA_CSG_ERR, "msg reallen:%d,expect len:%d\n", datalen, sizeof(csg_utc_t)); | 
		
	
		
			
				|  |  |  |  |         return  _csg_send_packet(Res_SetUTC, (char *)&result, sizeof(result)); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     csg_utc_t *msg = (csg_utc_t *)databuf; | 
		
	
		
			
				|  |  |  |  |     unsigned int stime = msg->utc + SHIQUCHA; | 
		
	
		
			
				|  |  |  |  |      | 
		
	
		
			
				|  |  |  |  |     if (abs(stime - time(NULL)) > 60) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         unsigned int tmp = time(NULL) - sysctrl.start_time; | 
		
	
		
			
				|  |  |  |  |         _csg_set_system_time(stime); | 
		
	
		
			
				|  |  |  |  |         sysctrl.start_time = time(NULL) - tmp; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     csg_utc_t ack = {0}; | 
		
	
		
			
				|  |  |  |  |     ack.utc = time(NULL) - SHIQUCHA; | 
		
	
		
			
				|  |  |  |  |     _csg_send_packet(Res_SetUTC, (char *)&ack, sizeof(csg_utc_t)); | 
		
	
		
			
				|  |  |  |  |     return 0; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | void _csg_reboot_system() | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     unsigned int ack[9] = {0}; | 
		
	
		
			
				|  |  |  |  |     _csg_send_packet(Res_Reboot, (char *)&ack, sizeof(ack)); | 
		
	
		
			
				|  |  |  |  |     reboot_system(LOG_CSG, BOOT_REMOTE_RESET); | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | int _csg_get_system_config() | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     struct in_addr addr; | 
		
	
	
		
			
				
					|  |  |  | @ -568,6 +612,12 @@ int _csg_recv_process(char *buf) | 
		
	
		
			
				|  |  |  |  |     case Cmd_ReqRTD2: | 
		
	
		
			
				|  |  |  |  |         _csg_response_realtime_data(1); | 
		
	
		
			
				|  |  |  |  |         break; | 
		
	
		
			
				|  |  |  |  |     case Cmd_SetUTC: | 
		
	
		
			
				|  |  |  |  |         _csg_set_utc_time(pdata, dataLen); | 
		
	
		
			
				|  |  |  |  |         break; | 
		
	
		
			
				|  |  |  |  |     case Cmd_Reboot: | 
		
	
		
			
				|  |  |  |  |         _csg_reboot_system(); | 
		
	
		
			
				|  |  |  |  |         break; | 
		
	
		
			
				|  |  |  |  |     case Cmd_ReqSysCfg: | 
		
	
		
			
				|  |  |  |  |         _csg_get_system_config(); | 
		
	
		
			
				|  |  |  |  |         break; | 
		
	
	
		
			
				
					|  |  |  | 
 |