void dis_rtc(void) { uint8_t dis_buf[100]; time_now = Time_GetCalendarTime(); sprintf((void*)dis_buf,"%02d-%02d %02d:%02d:%02d\r\n", time_now.tm_mon, time_now.tm_mday,time_now.tm_hour, time_now.tm_min, time_now.tm_sec); display_GB2312_string(1,1,0,dis_buf); }
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ DWORD get_fattime (void) { struct tm t; DWORD date; t = Time_GetCalendarTime(); t.tm_year -= 1980; //年份改为1980年起 t.tm_mon++; //0-11月改为1-12月 t.tm_sec /= 2; //将秒数改为0-29 date = 0; date = (t.tm_year << 25)|(t.tm_mon<<21)|(t.tm_mday<<16)| (t.tm_hour<<11)|(t.tm_min<<5)|(t.tm_sec); return date; }
/*-----------------------------------------------------------------------*/ DWORD get_fattime (void) { #if 0 struct tm t; DWORD date; t = Time_GetCalendarTime(); t.tm_year -= 1980; t.tm_mon++; t.tm_sec /= 2; date = 0; date = (t.tm_year << 25) | (t.tm_mon<<21) | (t.tm_mday<<16)|\ (t.tm_hour<<11) | (t.tm_min<<5) | (t.tm_sec); return date; #else return 0; #endif }
void GetRTCTime(T_STRUCT* time) { struct tm Rtime; // int ttime[30]; RTC_ITConfig(RTC_IT_SEC, DISABLE); //关闭秒中断 RTC_WaitForLastTask(); Rtime = Time_GetCalendarTime(); time->year = Rtime.tm_year%100; time->month = Rtime.tm_mon+1; time->day = Rtime.tm_mday; time->hour = Rtime.tm_hour; time->minute = Rtime.tm_min; time->sec = Rtime.tm_sec; time->date = Rtime.tm_wday; RTC_WaitForLastTask(); RTC_ITConfig(RTC_IT_SEC, ENABLE); //打开秒中断 #ifdef DEBUG // printf("%d年%d月%d日%d:%d:%d \r\n",time->year,time->month,time->day,time->hour,time->minute,time->sec); #endif }
void Time_Display(void) { struct tm time; time = Time_GetCalendarTime(); printf("Time: %d-%d-%d %02d:%02d:%02d \r\n", time.tm_year, \ time.tm_mon+1, time.tm_mday,\ time.tm_hour, time.tm_min, time.tm_sec); OLED_DisDigital(10, 25,time.tm_year, &tFont12);//显示年 if((time.tm_mon+1)==1 && time.tm_mday==1 && time.tm_hour == 0 && time.tm_min == 0 && time.tm_sec == 0) { OLED_DispStr(55, 25," ", &tFont12); } OLED_DisDigital(55, 25,(time.tm_mon+1), &tFont12);//显示月 if(time.tm_mday==1 && time.tm_hour == 0 && time.tm_min == 0 && time.tm_sec == 0) { OLED_DispStr(78, 25," ", &tFont12); } OLED_DisDigital(78, 25,time.tm_mday, &tFont12);//显示日 if(time.tm_hour == 0 && time.tm_min == 0 && time.tm_sec == 0) { OLED_DispStr(10, 40," ", &tFont12); } OLED_DisDigital(10, 40,time.tm_hour, &tFont12);//显示时 if(time.tm_min == 0 && time.tm_sec == 0) { OLED_DispStr(37, 40," ", &tFont12); } OLED_DisDigital(37, 40,time.tm_min, &tFont12);//显示分 if(time.tm_sec == 0) { OLED_DispStr(63, 40," ", &tFont12); } OLED_DisDigital(63, 40,time.tm_sec, &tFont12);//显示秒 }
// 设定闹钟时间 void SetAlarmTime(void) { // 23:59:59 struct tm time_current; uint32_t DayTotalSeconds; // 一天累积总秒数 uint32_t CurrentTotalSeconds; // 当前时间累积总秒数 uint32_t AlarmValue; // 秒差 DayTotalSeconds = 23*3600 + 59*60 +59; time_current = Time_GetCalendarTime(); CurrentTotalSeconds = time_current.tm_hour*3600 + time_current.tm_min*60 + time_current.tm_sec; AlarmValue = DayTotalSeconds - CurrentTotalSeconds; /* Wait till RTC Second event occurs */ RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Set the RTC Alarm after 3s */ RTC_SetAlarm(RTC_GetCounter()+AlarmValue); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
uint32_t CmdShowData(char *outputstr,T_MESSAGE *message) { uint8_t i; uint8_t status=0; char *p; struct tm time_now; time_t old_time; static float MeaRecordTab[MEANUM]; static uint8_t DiRecording[16]; old_time = 0; memset (outputstr,0,1314); p=outputstr; switch(message->m_type) { case CMD_AI: #if MEAUPDATE_METHOD==MEMBLKCP status = AiQuerry(); if(status) { I2C_MeasureTab[23]=GetTemperature(); #endif #if LINGUA==EN sprintf(p, "╔════════╦═════total meas:%3d═════╦════════╗\r\n",MEANUM); p+=strlen("╔════════╦═════total meas:%3d═════╦════════╗\r\n"); #endif #if LINGUA==CH sprintf(p, "╔════════╦═════遥测量总数:%3d═════╦════════╗\r\n",MEANUM); p+=strlen("╔════════╦═════遥测量总数:%3d═════╦════════╗\r\n"); #endif for(i=0;i<MEANUM;i++) { if ((i+1) % 4) { if((16==i)||(17==i)||(21==i)||(22==i)) { // if((I2C_MeasureTab[i]-MeaRecordTab[i])>Compress_Factor*MeaPropTab[i].scale) // { // sprintf(p, "║%-4s:%s%6.1f%s %4s",MeaPropTab[i].Title,rouge_mutation,\ // I2C_MeasureTab[i],normale,MeaPropTab[i].Unit); // p+=strlen(rouge_mutation); // p+=strlen(normale); // } // else sprintf(p, "║%-4s:%6.1f %-4s",MeaPropTab[i].Title,I2C_MeasureTab[i],MeaPropTab[i].Unit); p+=strlen("║XXXX:01234.5XXXX"); } else if(18==i) { // if((I2C_MeasureTab[i]-MeaRecordTab[i])>Compress_Factor*MeaPropTab[i].scale) // { // sprintf(p, "║%-4s:%s%6.1f %s%4s",MeaPropTab[i].Title,rouge_mutation,\ // I2C_MeasureTab[i],normale,MeaPropTab[i].Unit); // p+=strlen(rouge_mutation); // p+=strlen(normale); // } // else sprintf(p, "║%-4s:%6.4f %-4s",MeaPropTab[i].Title,I2C_MeasureTab[i],MeaPropTab[i].Unit); p+=strlen("║XXXX:01.2345XXXX"); } else { // if((I2C_MeasureTab[i]-MeaRecordTab[i])>Compress_Factor*MeaPropTab[i].scale) // { // sprintf(p, "║%-4s:%s%6.1f%s %4s",MeaPropTab[i].Title,rouge_mutation,\ // I2C_MeasureTab[i],normale,MeaPropTab[i].Unit); // p+=strlen(rouge_mutation); // p+=strlen(normale); // } // else sprintf(p, "║%-4s:%6.2f %-4s",MeaPropTab[i].Title,I2C_MeasureTab[i],MeaPropTab[i].Unit); p+=strlen("║XXXX:0123.45XXXX"); } } else { // if((I2C_MeasureTab[i]-MeaRecordTab[i])>Compress_Factor*MeaPropTab[i].scale) // { // sprintf(p, "║%-4s:%s%6.1f %s%4s",MeaPropTab[i].Title,rouge_mutation,\ // I2C_MeasureTab[i],normale,MeaPropTab[i].Unit); // p+=strlen(rouge_mutation); // p+=strlen(normale); // } // else sprintf(p, "║%-4s:%6.2f %-4s║\r\n",MeaPropTab[i].Title,I2C_MeasureTab[i],MeaPropTab[i].Unit); p+=strlen("║XXXX:0123.45XXXX║\r\n"); //sprintf(p, "╠════════╬════════╬════════╬════════╣\r\n"); if((MEANUM-1)==i) sprintf(p, "╚════════╩════════╩════════╩════════╝\r\n"); p+=strlen("╠════════╬════════╬════════╬════════╣\r\n"); } MeaRecordTab[i]=I2C_MeasureTab[i]; } #if MEAUPDATE_METHOD==MEMBLKCP } else { #if LINGUA== EN sprintf(outputstr,"can't read data from AI board \r\n"); p+=strlen("can't read data from AI board \r\n"); #endif #if LINGUA== CH sprintf(outputstr,"无法读取AI数据 \r\n"); p+=strlen("无法读取AI数据 \r\n"); #endif } #endif break; case CMD_DI: #if LINGUA== EN sprintf(p, "╔══totaldis%2d══╗\r\n",16); p+=strlen("╔══totaldis%2d══╗\r\n"); #endif #if LINGUA ==CH sprintf(p, "╔══遥信总数%2d══╗\r\n",16); p+=strlen("╔══遥信总数%2d══╗\r\n"); #endif for(i=0;i<8;i++) { if(1==DiStatus_DI[i].Value) { sprintf(p, "║ %-3d %s◆%s ",i+1,rouge,normale); if(DiRecording[i]!=DiStatus_DI[i].Value) sprintf(p, "║ %-3d %s◆%s ",i+1,rouge_mutation,normale); p+=strlen("║ %-3d ◆ "); p+=strlen(rouge); p+=strlen(normale); } else { sprintf(p, "║ %-3d %s◇%s ",i+1,vert,normale); if(DiRecording[i]!=DiStatus_DI[i].Value) sprintf(p, "║ %-3d %s◇%s ",i+1,vert_mutation,normale); p+=strlen("║ %-3d ◇ "); p+=strlen(vert); p+=strlen(normale); } DiRecording[i]=DiStatus_DI[i].Value; if(1==DiStatus_DI[i+8].Value) { sprintf(p, "║ %-3d %s◆%s ║\r\n",i+9,rouge,normale); if(DiRecording[i+8]!=DiStatus_DI[i+8].Value) sprintf(p, "║ %-3d %s◆%s ║\r\n",i+9,rouge_mutation,normale); p+=strlen("%║ -3d ◆ ║\r\n"); p+=strlen(rouge); p+=strlen(normale); } else { sprintf(p, "║ %-3d %s◇%s ║\r\n",i+9,vert,normale); if(DiRecording[i+8]!=DiStatus_DI[i+8].Value) sprintf(p, "║ %-3d %s◇%s ║\r\n",i+9,vert_mutation,normale); p+=strlen("║ %-3d ◇ ║\r\n"); p+=strlen(vert); p+=strlen(normale); } if(7==i) { sprintf(p, "╚════╩════╝\r\n"); p+=strlen("╚════╩════╝\r\n"); } else { sprintf(p, "╠════╬════╣\r\n"); p+=strlen("╚════╩════╝\r\n"); } DiRecording[i+8]=DiStatus_DI[i+8].Value; } break; case CMD_TI: if(Can_Online) { for(i=0;i<4;i++) { if(CAN_MeasureTab[i]>6000) sprintf(p, "%s\r\n","OffSccope"); sprintf(p, "%s:%5d %s\r\n",MeaPropTab[24+i].Title,CAN_MeasureTab[i],MeaPropTab[24+i].Unit); p+=strlen("XXXXX:01234XX\r\n"); } #if LINGUA ==EN sprintf(p,"enter the number of 4~20mA channel\r\n"); p=p+strlen("enter the number of 4~20mA channel\r\n")+strlen(DevNameStr); #endif #if LINGUA ==CH sprintf(p,"输入4~20mA通道序号查看电流显示\r\n"); p=p+strlen("输入4~20mA通道序号查看电流显示\r\n")+strlen(DevNameStr); #endif Shell_State=TI_mA; } else { #if LINGUA== EN sprintf(outputstr,"can't read data from TI board \r\n"); p+=strlen("can't read data from TI board \r\n"); #endif #if LINGUA== CH sprintf(outputstr,"无法读取TI数据\r\n"); p+=strlen("无法读取TI数据\r\n"); #endif } break; case CMD_COEF: break; case CMD_DATE: time_now = Time_GetCalendarTime(); sprintf(p, "%d-%02d-%02d %02d:%02d:%02d %s\r\n",time_now.tm_year,time_now.tm_mon/*+1*/,time_now.tm_mday,\ time_now.tm_hour,time_now.tm_min,time_now.tm_sec,Weekchar[time_now.tm_wday]); p+=strlen("1982-05-24 21:13:14 Tue\r\n"); break; case CMD_NAME: #if LINGUA ==EN sprintf(p,"device name now:%s,enter your new name\r\n",DevNameStr); p=p+strlen("device name now:,enter your new name\r\n")+strlen(DevNameStr); #endif #if LINGUA ==CH sprintf(p,"当前装置名称为%s,请输入新名称\r\n",DevNameStr); p=p+strlen("当前装置名称为,请输入新名称\r\n")+strlen(DevNameStr); #endif Shell_State=MODIFY_NAME; break; case CMD_NET: i=netstat(p); p+=i; break; case CMD_SOE: sprintf(p,"***************SOE事件记录***************\r\n"); p+=strlen("***************SOE事件记录***************\r\n"); if(0==SetCurrent.TrigSoeQueue.total) { sprintf(p,"无SOE事件记录 *_*||\r\n"); p+=strlen("无SOE事件记录 *_*||\r\n"); } else { for(i=0;i<SetCurrent.TrigSoeQueue.total;i++) { //tyh:20130312 判断当前显示的是否是最新记录,如果不是画线区分 if(old_time > SetCurrent.TrigSoeQueue.SOE_Queue_Flash[i].timetamp) { sprintf(p, "~~~~~~~~~~"); p+=10; sprintf(p, "~~~~~~~~~~"); p+=10; sprintf(p, "~~~~~~~~~~"); p+=10; sprintf(p, "~~~~~~~~~~"); p+=10; sprintf(p, "~\r\n"); p+=3; } time_now = Time_ConvUnixToCalendar(SetCurrent.TrigSoeQueue.SOE_Queue_Flash[i].timetamp); sprintf(p, "%4d-%02d-%02d %02d:%02d:%02d %4dms DI%02d非电量%4s\r\n",time_now.tm_year,time_now.tm_mon,time_now.tm_mday,\ time_now.tm_hour,time_now.tm_min,time_now.tm_sec,SetCurrent.TrigSoeQueue.SOE_Queue_Flash[i].mscd,\ SetCurrent.TrigSoeQueue.SOE_Queue_Flash[i].diseq+1,(SetCurrent.TrigSoeQueue.SOE_Queue_Flash[i].state?"动作":"返回")); p+=43; old_time = SetCurrent.TrigSoeQueue.SOE_Queue_Flash[i].timetamp; } old_time = 0; } break; case CMD_REC: sprintf(p,"***************ERROR LIST***************\r\n"); p+=strlen("***************ERROR LIST***************\r\n"); if(0==SetCurrent.ErrorQueue.total) { sprintf(p,"no error recorded *_*||\r\n"); p+=strlen("no error recorded *_*||\r\n"); } else { for(i=0;i<SetCurrent.ErrorQueue.total;i++) { //tyh:20130312 判断当前显示的是否是最新记录,如果不是画线区分 if(old_time > SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].timetamp) { sprintf(p, "~~~~~~~~~~~~~~~~~~~~"); p+=20; sprintf(p, "~~~~~~~~~~~~~~~~~~~~"); p+=20; sprintf(p, "~~~~~~~~~~~~~~~~~~~~"); p+=20; sprintf(p, "~~~~~~~~~~~~~~~~~~~~"); p+=20; sprintf(p, "\r\n"); p+=2; } time_now = Time_ConvUnixToCalendar(SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].timetamp); sprintf(p, "%4d-%02d-%02d %02d:%02d:%02d %4dms %08x's Reg=|%08x|%08x|%08x|%08x|\r\n",time_now.tm_year,time_now.tm_mon/*+1*/,time_now.tm_mday,\ time_now.tm_hour,time_now.tm_min,time_now.tm_sec,SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].mscd,\ SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].Perirh_baseaddr,\ SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].Register_1,\ SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].Register_2,\ SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].Register_3,\ SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].Register_4); p+=strlen("1982-05-24 13:14:10 1234ms 12345678's Reg=|00000400|00000003|00000401|00000124|\r\n"); old_time = SetCurrent.ErrorQueue.ERROR_Queue_Flash[i].timetamp; } old_time = 0; } break; case CMD_SHOWIP://20130312 TYH:添加IP显示命令处理 break; case CMD_AI_RESET_COUNT: //tyh:20130730 sprintf(p,"AI RESET COUNT = %7.0f\r\n", AI_Reset_Count); p+=strlen("AI RESET COUNT = 1234567\r\n"); break; default: break; } *(p++)=0x0A; *(p++)=0x0D; return (p-outputstr); }