Ejemplo n.º 1
0
void GizWits_DevStatusUpgrade(uint8_t * P0_Buff, uint32_t Time, uint8_t flag, uint8_t ConfigFlag)
{
	uint8_t i = 0;
	uint8_t Report_Flag = 0;
	Pro_HeadPartP0CmdTypeDef *Pro_D2W_ReportStatusStruct = (Pro_HeadPartP0CmdTypeDef *)g_DevStatus;
	
    //等待上一次主动上报后判断ACK的状态,flg = 1:放弃主动上报 flg = 0:可以主动上报
  	if( ConfigFlag == 1 || Wait_AckStruct.Flag == 1)
	{
        return; 
	}
    if(flag == 1) 
    {
        Report_Flag = 1;
        goto Report; 
    }
	
    //设备的状态的变化是由于用户触发或环境变化所产生的, 其发送的频率不能快于2秒每次
    if((2 * 1000) < (SystemTimeCount - Last_ReportTime)) 
    {
        if(memcmp(g_DevStatus + sizeof(Pro_HeadPartP0CmdTypeDef), P0_Buff, g_P0DataLen) != 0)
        {
            Report_Flag = 1;
        }
    }

    //每隔十分钟定时主动上报
    if((Time * 6 * 10) < (SystemTimeCount - Last_Report_10_Time)) 
	{
        Serial.println("%%%%%%%%%%%%%%%10 minutes regular reporting%%%%%%%%%%%%%%%"); 
		Report_Flag = 1;
        Last_Report_10_Time = SystemTimeCount; 
	}
	
Report:
	if(Report_Flag == 1)
	{
        memcpy(g_DevStatus + sizeof(Pro_HeadPartP0CmdTypeDef), P0_Buff, g_P0DataLen);

        Pro_D2W_ReportStatusStruct->Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_HeadPartP0CmdTypeDef) + 1 + g_P0DataLen - 4);
        Pro_D2W_ReportStatusStruct->Pro_HeadPart.Cmd = Pro_D2W_P0_Cmd;
        Pro_D2W_ReportStatusStruct->Pro_HeadPart.SN = SN++;
        Pro_D2W_ReportStatusStruct->Action = P0_D2W_ReportDevStatus_Action;
        g_DevStatus[sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen] = CheckSum(g_DevStatus, sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen + 1);
        Pro_UART_SendBuf((uint8_t *)Pro_D2W_ReportStatusStruct, sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen + 1, 1);//最后一位为 4.3/4.4/4.9 的重发机制开关

        Last_ReportTime = SystemTimeCount;

#if(DEBUG==1)
		Serial.print("[");Serial.print(SystemTimeCount,DEC);Serial.print("]");Serial.print(" MCU 8 :");
		for(i = 0; i < (sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen + 1); i++)
		{
		  Serial.print(" "); Serial.print(g_DevStatus[i],HEX);
		}
		Serial.println("");
#endif

	}
	return;
}
Ejemplo n.º 2
0
/*******************************************************************************
* Function Name  : Pro_GetMcuInfo
* Description    : WiFi模组请求设备信息
* Input          : None
* Output         : None
* Return         : None
* Attention		   : None
*******************************************************************************/
void Pro_W2D_GetMcuInfo(void)
{
	Pro_CommonCmdTypeDef Pro_CommonCmdStruct;
	uint8_t i = 0;
	memcpy(&Pro_CommonCmdStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_CommonCmdStruct));

	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.SN = Pro_CommonCmdStruct.Pro_HeadPart.SN;
	Pro_M2W_ReturnInfoStruct.Sum = CheckSum((uint8_t *)&Pro_M2W_ReturnInfoStruct, sizeof(Pro_M2W_ReturnInfoStruct));
	Pro_UART_SendBuf((uint8_t *)&Pro_M2W_ReturnInfoStruct,sizeof(Pro_M2W_ReturnInfoStruct), 0);

#if(DEBUG==1)
	Serial.print("[");Serial.print(SystemTimeCount,DEC);Serial.print("]");Serial.print(" MCU 2 :");
	for(i = 0; i < sizeof(Pro_M2W_ReturnInfoStruct); i++)
	{
	  Serial.print(" "); Serial.print(*((uint8_t *)&Pro_M2W_ReturnInfoStruct + i),HEX);
	}
	Serial.println("");
#endif

// 	Log_UART_SendBuf((uint8_t *)&Pro_M2W_ReturnInfoStruct,sizeof(Pro_M2W_ReturnInfoStruct));
// 	
//  /******************************????*********************************************/	
// 	printf("W2D_GetMcuInfo...\r\n");
// 	printf("PRO_VER:"); 		printf(PRO_VER); 			printf("\r\n");
// 	printf("P0_VER:");			printf(P0_VER);				printf("\r\n");
// 	printf("P0_VER:");      printf(HARD_VER);			printf("\r\n");
// 	printf("SOFT_VER:");    printf(SOFT_VER);			printf("\r\n");
// 	printf("PRODUCT_KEY:"); printf(PRODUCT_KEY);  printf("\r\n");
// /***********************************************************************************/	   
}
Ejemplo n.º 3
0
void GizWits_D2WConfigCmd(uint8_t WiFi_Mode)
{
	uint8_t i = 0;
	Pro_D2W_ConfigWifiTypeDef Pro_D2WConfigWiFiMode;
	
	Pro_D2WConfigWiFiMode.Pro_HeadPart.Head[0] = 0xFF;
	Pro_D2WConfigWiFiMode.Pro_HeadPart.Head[1] = 0xFF;
	Pro_D2WConfigWiFiMode.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_D2W_ConfigWifiTypeDef) - 4);
	Pro_D2WConfigWiFiMode.Pro_HeadPart.Cmd = Pro_D2W_ControlWifi_Config_Cmd;
    Pro_D2WConfigWiFiMode.Pro_HeadPart.SN = SN++;
	Pro_D2WConfigWiFiMode.Pro_HeadPart.Flags[0] = 0x00;
	Pro_D2WConfigWiFiMode.Pro_HeadPart.Flags[1] = 0x00;
	Pro_D2WConfigWiFiMode.Config_Method = WiFi_Mode;
	Pro_D2WConfigWiFiMode.Sum = CheckSum((uint8_t *)&Pro_D2WConfigWiFiMode, sizeof(Pro_D2W_ConfigWifiTypeDef));
	Pro_UART_SendBuf((uint8_t *)&Pro_D2WConfigWiFiMode, sizeof(Pro_D2W_ConfigWifiTypeDef), 1); //最后一位为 4.3/4.4/4.9 的重发机制开关
	
#if(DEBUG==1)
	Serial.print("[");Serial.print(SystemTimeCount,DEC);Serial.print("]");Serial.print(" MCU 7 :");
	for(i = 0; i < (sizeof(Pro_D2W_ConfigWifiTypeDef)); i++)
	{
	  Serial.print(" "); Serial.print(*((uint8_t *)&Pro_D2WConfigWiFiMode + i),HEX);
	}
	Serial.println("");
#endif
}
Ejemplo n.º 4
0
/*******************************************************************************
* Function Name  : KEY_LongHandle
* Description    : Key Long Press processing function
                   
* Input          : KeyAction :
					RESS_KEY1 ->MCU To WIFI Send Reset command
                    PRESS_KEY2 ->MCU To WIFI Send Config command
* Output         : None
* Return         : None
* Attention		 	 : None
*******************************************************************************/	
void KEY_LongHandle(uint8_t KeyAction)
{
	if(KeyAction  == KEY1_Long_Action)
	{
	#if 0
		Device_WirteStruct.LED_R = 50;
		Device_WirteStruct.LED_G = 0;
		Device_WirteStruct.LED_B = 0;
		LED_RGB_Control(Device_WirteStruct.LED_R,Device_WirteStruct.LED_G,Device_WirteStruct.LED_B);
	#endif		
		LED_RGB_Control(50, 0, 0);
		
		Pro_M2WResetCmdStruct.Pro_HeadPart.SN = SN++;
		Pro_M2WResetCmdStruct.Sum = CheckSum((uint8_t *)&Pro_M2WResetCmdStruct, sizeof(Pro_M2WResetCmdStruct));
		Pro_UART_SendBuf((uint8_t *)&Pro_M2WResetCmdStruct,sizeof(Pro_M2WResetCmdStruct), 0);	

			
	}

	if(KeyAction  == KEY2_Long_Action)
	{
	#if 0
		Device_WirteStruct.LED_R = 0;
		Device_WirteStruct.LED_G = 0;
		Device_WirteStruct.LED_B = 50;
		LED_RGB_Control(Device_WirteStruct.LED_R,Device_WirteStruct.LED_G,Device_WirteStruct.LED_B);		
	#endif	
		LED_RGB_Control(0, 0, 50);		

		Pro_D2WConfigCmdStruct.Pro_HeadPart.SN = SN++;
		Pro_D2WConfigCmdStruct.Config_Method = 0x02;
		Pro_D2WConfigCmdStruct.Sum = CheckSum((uint8_t *)&Pro_D2WConfigCmdStruct, sizeof(Pro_D2WConfigCmdStruct));
		Pro_UART_SendBuf((uint8_t *)&Pro_D2WConfigCmdStruct,sizeof(Pro_D2WConfigCmdStruct), 0);	


	}
	
}	
Ejemplo n.º 5
0
/*******************************************************************************

* Function Name  : Pro_Pro_W2D_Heartbeat
* Description    : 
* 1,WiFi模组与设备MCU的心跳(4.2)
* 2,设备MCU通知WiFi模组进入配置模式(4.3)
* 3,设备MCU重置WiFi模组(4.4)
* 4, WiFi模组请求重启MCU(4.6)
* 5, WiFi模组请求重启MCU ( 4.9 WiFi模组主动上报当前的状态)
* 6,设备MCU回复 (WiFi模组控制设备)
* 4.6 	WiFi模组请求重启MCU
* 4.9 	Wifi模组回复
* 4.10  设备MCU回复										
* Input          : None
* Output         : None
* Return         : None
* Attention		   : None
*******************************************************************************/
void Pro_W2D_CommonCmdHandle(void)
{
	Pro_CommonCmdTypeDef Pro_CommonCmdStruct;
	uint8_t i = 0;
	
	memcpy(&Pro_CommonCmdStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_CommonCmdStruct));	
    Pro_CommonCmdStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_CommonCmdTypeDef) - 4); 
	Pro_CommonCmdStruct.Pro_HeadPart.Cmd = Pro_CommonCmdStruct.Pro_HeadPart.Cmd + 1;
	Pro_CommonCmdStruct.Sum = CheckSum((uint8_t *)&Pro_CommonCmdStruct, sizeof(Pro_CommonCmdStruct));	
	Pro_UART_SendBuf((uint8_t *)&Pro_CommonCmdStruct, sizeof(Pro_CommonCmdStruct), 0);	

#if(DEBUG==1)
		Serial.print("[");Serial.print(SystemTimeCount,DEC);Serial.print("]");Serial.print(" MCU 3 :");
		for(i = 0; i < (sizeof(Pro_CommonCmdStruct)); i++)
		{
		  Serial.print(" "); Serial.print(*((uint8_t *)&Pro_CommonCmdStruct + i),HEX);
		}
		Serial.println("");
#endif
}
Ejemplo n.º 6
0
void Pro_D2W_ReportDevStatusHandle(void)
{
	uint8_t i = 0;
	Pro_HeadPartP0CmdTypeDef *Pro_D2W_ReportStatusStruct = (Pro_HeadPartP0CmdTypeDef *)g_DevStatus;
    memcpy(Pro_D2W_ReportStatusStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_HeadPartTypeDef)); 
        Pro_D2W_ReportStatusStruct->Pro_HeadPart.Cmd = Pro_D2W_P0_Ack_Cmd; 
		Pro_D2W_ReportStatusStruct->Pro_HeadPart.Len = exchangeBytes((sizeof(Pro_HeadPartP0CmdTypeDef)+g_P0DataLen+1) - 4);
        Pro_D2W_ReportStatusStruct->Action = P0_D2W_ReadDevStatus_Action_ACK; 
		g_DevStatus[sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen] = CheckSum(g_DevStatus, sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen + 1);
		Pro_UART_SendBuf((uint8_t *)Pro_D2W_ReportStatusStruct, sizeof(Pro_HeadPartP0CmdTypeDef)+g_P0DataLen+1, 0);
		
#if(DEBUG==1)
	Serial.print("[");Serial.print(SystemTimeCount,DEC);Serial.print("]");Serial.print(" MCU 5 :");
	for(i = 0; i < (sizeof(Pro_HeadPartP0CmdTypeDef)+g_P0DataLen+1); i++)
	{
	  Serial.print(" "); Serial.print(*((uint8_t *)Pro_D2W_ReportStatusStruct + i),HEX);
	}
	Serial.println("");
#endif

}
Ejemplo n.º 7
0
void GizWits_D2WResetCmd(void)
{
	uint8_t i = 0;
	Pro_CommonCmdTypeDef Pro_D2WReset;
	
	Pro_D2WReset.Pro_HeadPart.Head[0] = 0xFF;
	Pro_D2WReset.Pro_HeadPart.Head[1] = 0xFF;
	Pro_D2WReset.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_CommonCmdTypeDef) - 4);
	Pro_D2WReset.Pro_HeadPart.Cmd = Pro_D2W_ResetWifi_Cmd;
	Pro_D2WReset.Pro_HeadPart.SN = SN++;
	Pro_D2WReset.Pro_HeadPart.Flags[0] = 0x00;
	Pro_D2WReset.Pro_HeadPart.Flags[1] = 0x00;
	Pro_D2WReset.Sum = CheckSum((uint8_t *)&Pro_D2WReset, sizeof(Pro_CommonCmdTypeDef));
	Pro_UART_SendBuf((uint8_t *)&Pro_D2WReset, sizeof(Pro_CommonCmdTypeDef), 1); //最后一位为 4.3/4.4/4.9 的重发机制开关
	
#if(DEBUG==1)
	Serial.print("[");Serial.print(SystemTimeCount,DEC);Serial.print("]");Serial.print(" MCU 6 :");
	for(i = 0; i < (sizeof(Pro_CommonCmdTypeDef)); i++)
	{
	  Serial.print(" "); Serial.print(*((uint8_t *)&Pro_D2WReset + i),HEX);
	}
	Serial.println("");
#endif
}
Ejemplo n.º 8
0
void Pro_W2D_ErrorCmdHandle(Error_PacketsTypeDef Error_Type, uint8_t flag)
{
	Pro_ErrorCmdTypeDef           	 Pro_ErrorCmdStruct;       //4.7 ??????

    memcpy(&Pro_ErrorCmdStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_ErrorCmdStruct));
    if(flag == 1)
    {
        goto Print_O;
    }
	
    Pro_ErrorCmdStruct.Pro_HeadPart.Head[0] = 0xFF; 
    Pro_ErrorCmdStruct.Pro_HeadPart.Head[1] = 0xFF; 
    Pro_ErrorCmdStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_ErrorCmdStruct) - 4); 
    Pro_ErrorCmdStruct.Pro_HeadPart.Cmd = Pro_D2W_ErrorPackage_Ack_Cmd; 
    Pro_ErrorCmdStruct.Error_Packets = Error_Type;
    Pro_ErrorCmdStruct.Sum = CheckSum((uint8_t *)&Pro_ErrorCmdStruct, sizeof(Pro_ErrorCmdStruct)); 
    Pro_UART_SendBuf((uint8_t *)&Pro_ErrorCmdStruct, sizeof(Pro_ErrorCmdStruct), 0); 

	#if(DEBUG==1)
    Serial.print(F("Error :")); Serial.println(Error_Type, HEX); 
		Serial.print("[");Serial.print(SystemTimeCount,DEC);Serial.print("]");Serial.print(" MCU 4 :");
		for(uint8_t i = 0; i < (sizeof(Pro_ErrorCmdStruct)); i++)
		{
		  Serial.print(" "); Serial.print(*((uint8_t *)&Pro_ErrorCmdStruct + i),HEX);
		}
		Serial.println("");
	#endif
    
    return;

Print_O:
	/*************************错误类型*****************************/
	
	switch (Pro_ErrorCmdStruct.Error_Packets)
	{
		case Error_AckSum:

			#if(DEBUG==1)
				Serial.println(F("ACK : Error_AckSum OK"));
			#endif
			
			break;
		case Error_Cmd:

			#if(DEBUG==1)
            Serial.println(F("ACK : Error_Cmd OK")); 
			#endif
			
			break;
		case Error_Other:

			#if(DEBUG==1)
            Serial.println(F("ACK : Error_Other OK")); 
			#endif
			break;
		default:
			#if(DEBUG==1)
            Serial.println(F("ACK : Error! ")); 
			#endif
			break;
	}	
}