⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 为了满足每个项目终端的需求
💻 C
📖 第 1 页 / 共 3 页
字号:
	{		MAIN_DPRINTF("APP_ReadCfg,Device Type err\n");		if(cfg_read_fd != NULL)		{			fclose(cfg_read_fd);			cfg_read_fd = NULL;		}		return -1;	}	if(cfg_read_fd != NULL)	{		fclose(cfg_read_fd);		cfg_read_fd = NULL;	}	return 0;}/************************************************************************* APP_WriteCfg*************************************************************************FUNCTION: write the configure msg which received from client into deviceINPUTS:   pktOUTPUTS:  noneRETURN:   0 is OK, otherwise error**/int APP_WriteCfg(PKT* pkt){	int ret,nwrite;	long date,time;	U8 tempbuffer[MAX_CFG_LENGTH+1];	U8 datebuff[DATE_LENGTH+1];	U8 timebuff[TIME_LENGTH+1];	U16 dev_type,pkt_Len;	struct tm change_tm;	time_t  tval;#ifdef TIME_DEBUG	U32 ReceiveTimeYear, ReceiveTimeMonth, ReceiveTimeDay, ReceiveTimeHour, ReceiveTimeMin, ReceiveTimeSec;#endif	FILE_DATA return_temp;	FILE_DATA *receive_temp;	FILE *cfg_write_fd =NULL;	receive_temp = &(pkt->Msg);	return_temp.Index = 0;	return_temp.Sum = 0;	return_temp.DataLen = MAX_FILE_DATA_LEN;	memset(return_temp.Data,'\0',MAX_FILE_DATA_LEN+1);	memset(return_temp.Data,'0',MAX_FILE_DATA_LEN);	return_temp.BCC = PktCalcCRC(return_temp.Data,return_temp.DataLen);	/*debug*/	MAIN_DPRINTF("pkt->Msg.Index is %d\n",pkt->Msg.Index);#ifdef NTOHS_DEBUG	receive_temp->Index = ntohs(pkt->Msg.Index);	receive_temp->Sum = ntohs(pkt->Msg.Sum);	receive_temp->DataLen = ntohs(pkt->Msg.DataLen);	receive_temp->BCC = ntohs(pkt->Msg.BCC);#else	receive_temp->Index = pkt->Msg.Index;	receive_temp->Sum = pkt->Msg.Sum;	receive_temp->DataLen = pkt->Msg.DataLen;	receive_temp->BCC = pkt->Msg.BCC;#endif	dev_type = receive_temp->Index;	pkt_Len = receive_temp->DataLen;	MAIN_DPRINTF("receive_temp->DataLen is %d\n",receive_temp->DataLen);	//MAIN_DPRINTF("receive_temp->Data is %c %c %c %c\n",receive_temp->Data[0],receive_temp->Data[1],receive_temp->Data[1],receive_temp->Data[1]);	memset(tempbuffer,'\0',sizeof(tempbuffer));	//memcpy(tempbuffer,receive_temp->Data,pkt_Len);	memcpy(tempbuffer,receive_temp->Data,MAX_CFG_LENGTH);	memset(datebuff,'\0', DATE_LENGTH + 1);	memcpy(datebuff,tempbuffer,DATE_LENGTH);	//MAIN_DPRINTF("datebuff is %s\n",datebuff);	date = atoi(datebuff);	MAIN_DPRINTF("date is %ld\n",date);	memset(timebuff,'\0', TIME_LENGTH + 1);	memcpy(timebuff,&tempbuffer[8],TIME_LENGTH);	//MAIN_DPRINTF("timebuff is %s\n",timebuff);	time = atoi(timebuff);	MAIN_DPRINTF("time is %ld\n",time);	/*have a test ,maybe strptime is unable to achieve */	ReceiveTimeYear = date/10000;	ReceiveTimeMonth = date%10000/100;	ReceiveTimeDay = date%100;	ReceiveTimeHour = time/10000;	ReceiveTimeMin = time%10000/100;	ReceiveTimeSec = time%100;	change_tm.tm_year = ReceiveTimeYear - 1900;	change_tm.tm_mon = ReceiveTimeMonth - 1;	change_tm.tm_mday = ReceiveTimeDay;	change_tm.tm_hour = ReceiveTimeHour;	change_tm.tm_min = ReceiveTimeMin;	change_tm.tm_sec = ReceiveTimeSec;	tval = mktime(&change_tm);	stime(&tval);	system("hwclock - w");	//MAIN_DPRINTF("change_tm.tm_year is %d\n",change_tm.tm_year);	if(dev_type == DEV_CZT_CFG)	{	/*operate configure in the CZT device*/		if((cfg_write_fd = fopen(ADDR_CZT, "r+"))== NULL)		{			MAIN_DPRINTF("APP_WriteCfg,OpenCfg err\n");			ret = SendPkt(gChannelHandle, STA_REVCFG_ERR, &return_temp, sizeof(FILE_DATA) -1);			if(ret == -1)			{				MAIN_DPRINTF("APP_WriteCfg,SendPkt err\n");			}			return -1;		}		MAIN_DPRINTF("APP_WriteCfg,OpenCfg OK\n");		if(gKEY_FLAG == 1)		{			/*have right to change the password */			if((nwrite = fwrite(&tempbuffer[14], sizeof(char), 32, cfg_write_fd))!= 32)			{				MAIN_DPRINTF("APP_WriteCfg,WriteCfg err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}			fseek(cfg_write_fd, 40, SEEK_SET);			if((nwrite = fwrite(&tempbuffer[54], sizeof(char), 8, cfg_write_fd))!= 8)			{				MAIN_DPRINTF("APP_WriteCfg,WriteCfg err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}			MAIN_DPRINTF("APP_WriteCfg,if key fwrite cztcfg OK\n");			if((ret = SendPkt(gChannelHandle, STA_REVCFG_OK, &return_temp, sizeof(FILE_DATA) -1)) == -1)			{				MAIN_DPRINTF("APP_WriteCfg,SendPkt err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}		}		else if(gKEY_FLAG == 0)		{			/*have no right to change the password */			if((nwrite = fwrite(&tempbuffer[14], sizeof(char), 32, cfg_write_fd))!= 32)			{				MAIN_DPRINTF("APP_WriteCfg,WriteCfg err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}			MAIN_DPRINTF("APP_WriteCfg,if no key fwrite cztcfg OK\n");			if((ret = SendPkt(gChannelHandle, STA_REVCFG_OK, &return_temp, sizeof(FILE_DATA) -1)) == -1)			{				MAIN_DPRINTF("APP_WriteCfg,SendPkt err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}		}		if(cfg_write_fd != NULL)		{			fclose(cfg_write_fd);			cfg_write_fd = NULL;		}		gKEY_FLAG = 0;	}	else if(dev_type == DEV_GDT_CFG)	{		/*operate configure in the GDT device*/		if((cfg_write_fd = fopen(ADDR_GDT, "r+"))== NULL)		{			MAIN_DPRINTF("APP_WriteCfg,OpenCfg err\n");			ret = SendPkt( gChannelHandle, STA_REVCFG_ERR, &return_temp, sizeof(FILE_DATA) -1);			if(ret == -1)			{				MAIN_DPRINTF("APP_WriteCfg,SendPkt err\n");			}			return -1;		}		if(gKEY_FLAG == 1)		{			/*have right to change the password */			if((nwrite = fwrite(&tempbuffer[14], sizeof(char), 40, cfg_write_fd))!= 40)			{				MAIN_DPRINTF("APP_WriteCfg,WriteCfg err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}			fseek(cfg_write_fd, 48, SEEK_SET);			if((nwrite = fwrite(&tempbuffer[62], sizeof(char), 8, cfg_write_fd))!= 8)			{				MAIN_DPRINTF("APP_WriteCfg,WriteCfg err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}			MAIN_DPRINTF("APP_WriteCfg,if key fwrite cztcfg OK\n");			if((ret = SendPkt(gChannelHandle, STA_REVCFG_OK, &return_temp, sizeof(FILE_DATA) -1)) == -1)			{				MAIN_DPRINTF("APP_WriteCfg,SendPkt err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}		}		else if(gKEY_FLAG == 0)		{			/*have no right to change the password */			if((nwrite = fwrite(&tempbuffer[14], sizeof(char), 40, cfg_write_fd))!= 40)			{				MAIN_DPRINTF("APP_WriteCfg,WriteCfg err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}			MAIN_DPRINTF("APP_WriteCfg,if no key fwrite cztcfg OK\n");			if((ret = SendPkt(gChannelHandle, STA_REVCFG_OK, &return_temp, sizeof(FILE_DATA) -1)) == -1)			{				MAIN_DPRINTF("APP_WriteCfg,SendPkt err\n");				if(cfg_write_fd != NULL)				{					fclose(cfg_write_fd);					cfg_write_fd = NULL;				}				return -1;			}		}		else		{			return -1;		}		if(cfg_write_fd != NULL)		{			fclose(cfg_write_fd);			cfg_write_fd = NULL;		}		gKEY_FLAG = 0;	}	else	{		MAIN_DPRINTF("APP_WriteCfg,Device Type err\n");		return -1;	}	return 0;}/************************************************************************* APP_CutLink*************************************************************************FUNCTION: clear file buffer and delete connectionINPUTS:   pkt pointerOUTPUTS:  noneRETURN:   0 is OK, otherwise error**/int APP_CutLink(PKT* pkt){	int ret;	FILE_DATA *CutLink_return_pkt;	CutLink_return_pkt = &(pkt->Msg);	CutLink_return_pkt->Index = 0;	CutLink_return_pkt->Sum = 0;	CutLink_return_pkt->DataLen = MAX_FILE_DATA_LEN;	memset(CutLink_return_pkt->Data,'\0',MAX_FILE_DATA_LEN+1);	memset(CutLink_return_pkt->Data,'0',MAX_FILE_DATA_LEN);	CutLink_return_pkt->BCC = PktCalcCRC(CutLink_return_pkt->Data,CutLink_return_pkt->DataLen);	gHELLO_FLAG = 0;	gERASE_FLAG = 0;	gKEY_FLAG = 0;	gSTORAGE_FLAG = 0;	//CHN_Close(gChannelHandle);	if(gFileRAM.BufferBak != NULL)	{		free(gFileRAM.BufferBak);		gFileRAM.Buffer = NULL;		gFileRAM.BufferBak = NULL;	}	if((ret = SendPkt(gChannelHandle, STA_CUTLINK_OK, CutLink_return_pkt, sizeof(FILE_DATA) -1)) == -1)	{		MAIN_DPRINTF("APP_CutLink, SendPkt err\n");		return -1;	}	return 0;}/************************************************************************* Mbox_boot_check_yafdir*************************************************************************FUNCTION: check if the cfg resist or notINPUTS:   noneOUTPUTS:  noneRETURN:   none**/void Mbox_boot_check_yafdir(void){	struct stat buff ;	int ret ;	ret = stat("/yaf/cfgdata/mboxcztsys.cfg",&buff);	if(ret != 0)	{		system("cp -rf /mbox_appsrc/mboxcztsys.cfg /yaf/cfgdata/");	}	ret = stat("/yaf/cfgdata/mboxgdtsys.cfg",&buff);	if(ret != 0)	{		system("cp -rf /mbox_appsrc/mboxgdtsys.cfg /yaf/cfgdata/");	}}/************************************************************************* VersionInfo*************************************************************************FUNCTION: display program infoINPUTS:   noneOUTPUTS:  noneRETURN:   none**/void VersionInfo(void){	printf("\n***********************************************");	printf("\n	Online update program for ARM");	printf("\n***********************************************");	printf("\n	Owned by:     %s",COMPANY);	printf("\n	Programed by: %s",AUTHOR);	printf("\n	Version:      %s",SRC_VERSION);	printf("\n	Build at:     %s",BUILD_TIME);	printf("\n	Modify at:    %s",MODIFY_TIME);	printf("\n	For:          %s",USER);	printf("\n***********************************************\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -