*/
#define REPORT_TIME_SECS (2*60*60) //2hours
-#define ANGLE_CHANGE_MIN (100) //0.100 ¡æ
+#define ANGLE_CHANGE_MIN (2000) //2.000 ¡æ
+
+static uint32_t last_sent_rtc_secs; //ÉÏ´ÎÉϱ¨rtcʱ¼ä£¬µ¥Î»Ã룬 ÓÃÓÚ¼ÆË㶨ʱÉϱ¨Ê±¼ä, ½Ç¶È²»±ä»¯2Сʱ·¢ËÍÒ»´Î
-static uint32_t to_send_time_secs; //ÐÞ¸ÄΪ2Сʱ·¢ËÍÒ»´Î£¬ 2025/4/23
static int last_x_angle;
static int last_y_angle;
static int last_z_angle;
return 1;
}
-#define STOP_MODE (0) //ֹͣģʽ
-#define SOFTWARE_VERSION "app_version = 2.4"
+#define STOP_MODE (1) //ֹͣģʽ
+#define SOFTWARE_VERSION "app_version = 2.5"
u8 uid[32];
//²âÊÔ-µÚ¶þ¸ö°å×Ó
void func_test(void)
{
+ int send_err = 0;
+ uint32_t now_rtc_secs;
+
uint32_t to_report = 0;
- to_send_time_secs = REPORT_TIME_SECS; //µÚÒ»´ÎÁ¢¼´Éϱ¨£¬ºóÃæµÈ´ýÉϱ¨×î´óÖÜÆÚ
+
+ now_rtc_secs = 0;
+ last_sent_rtc_secs = now_rtc_secs;
while(1)
{
Request_Temp_And_Humidity(); //Ö÷¶¯»ñȡһ´ÎÎÂʪ¶È´«¸ÐÆ÷µÄÊý¾Ý
Cmd_11(); //Ö÷¶¯»ñȡһ´Î½Ç¶ÈÊý¾Ý
Delay_s(1);
- to_send_time_secs++;
Process_Temp_And_Hum_Data(); //´¦ÀíÎÂʪ¶ÈÊý¾Ý
Process_IM600_Data(); //´¦Àí½Ç¶È´«¸ÐÆ÷Êý¾Ý
}else{
im600_receive_ok = 0; //¼Ó²»¼Óelse¶¼ÐÐ
}
-
- if( to_send_time_secs >= REPORT_TIME_SECS ){
+
+ now_rtc_secs = RTC_GetCounter();
+ if( now_rtc_secs - last_sent_rtc_secs > REPORT_TIME_SECS ){
+ //¹Ì¶¨2¸öСʱÉϱ¨Ò»´Î
to_report = 1;
}else if( is_angle_changed(x_angle, y_angle, z_angle) ){
+ //½Ç¶È±ä»¯´óÓÚ2¶È ÐèÒªÉϱ¨
to_report = 1;
}else{
to_report = 0;
}
if( to_report ){
- last_x_angle = x_angle;
- last_y_angle = y_angle;
- last_z_angle = z_angle;
WH_GM5_Config(); //ÅäÖÃ4GÄ£¿é
sprintf((char*)net.TxBuff,data_format1,uid,temp_value,hum_value,x_angle/(fp32)1000,(fp32)(y_angle/(fp32)1000),
(fp32)(z_angle/(fp32)1000),(fp32)(raw_x/(fp32)10000),direction,Get_Battery_Power(),Bat_AdcGetValue(),Get_Sun_Adc_value());
encrypt(); //rc4¼ÓÃÜ
- if( WH_GM5_Send_Data() ) //4GÄ£¿é·¢ËÍÊý¾Ý
- to_send_time_secs = 0;
+ if( WH_GM5_Send_Data() ){ //4GÄ£¿é·¢ËÍÊý¾Ý
+ last_sent_rtc_secs = now_rtc_secs;
+ last_x_angle = x_angle;
+ last_y_angle = y_angle;
+ last_z_angle = z_angle;
+ send_success = 1;
+ send_err = 0;
+ }else{
+ send_success =0;
+ send_err ++;
+ Delay_s(4);
+ }
}
- Delay_s(1);
- to_send_time_secs++;
+// Delay_s(1);
MCU_LED_TOGGLES;
#if STOP_MODE
- if(send_success == 1){
+ if(send_success == 1 || send_err > 5 || to_report==0 ){
+
ADC_Cmd(ADC1, DISABLE);
MCU_LED_OFF; //¹Ø±ÕLEDµÆ
CTL_4G_PWR_OFF;
//RTC_WaitForLastTask(); //µÈ´ýÉÏÒ»´Î²Ù×÷Íê³É
RTC_EnterConfigMode();
RTC_WaitForLastTask();
- RTC_SetAlarm((10 )+RTC_GetCounter()); //ÅäÖÃÏ´ÎÄÖÖÓΪ10sºó
+ RTC_SetAlarm((30)+RTC_GetCounter()); //ÅäÖÃÏ´ÎÄÖÖÓΪ60sºó
RTC_WaitForLastTask();
RTC_ExitConfigMode();
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); //½øÈëֹͣģʽµÍ¹¦ºÄ
SysTickEnableOrDisable(ENABLE); //´ò¿ªsystick
send_success = 0;
+ send_err = 0;
+ ConnectFlag = 0;
CTL_4G_PWR_ON;
}
#endif