Exemplo n.º 1
0
int	McuStatusInit()
{
	SN = 0;
	cmd_flag1 = 0;
	cmd_flag2 = 0;
	get_one_package = 0;
	uart_Count = 0;
	cmd_flag = 0;
	cmd_len = 0 ;	
	wait_wifi_status = 0;
	
	memset(uart_buf, 0, 256);
	
	//初始化通用命令帧,命令字和sn需要传入,校验和发送前计算,其他信息相同;
	memset(&m_pro_commonCmd, 0, sizeof(pro_commonCmd));
	m_pro_commonCmd.head_part.head[0] = 0xFF;
	m_pro_commonCmd.head_part.head[1] = 0xFF;
	m_pro_commonCmd.head_part.len = exchangeBytes(sizeof(pro_commonCmd) - 4);

	//初始化返回mcu信息帧,sn和校验和需要根据实际填写;
	memset(&m_m2w_returnMcuInfo, 0, sizeof(m2w_returnMcuInfo));
	m_m2w_returnMcuInfo.head_part.head[0] = 0xFF;
	m_m2w_returnMcuInfo.head_part.head[1] = 0xFF;
	//长度值不包含包头和长度字段,所以要减去4个字节;
	m_m2w_returnMcuInfo.head_part.len = exchangeBytes(sizeof(m2w_returnMcuInfo) - 4);			
	m_m2w_returnMcuInfo.head_part.cmd = CMD_GET_MCU_INFO_ACK;
	memcpy(m_m2w_returnMcuInfo.pro_ver, PRO_VER, 8);
	memcpy(m_m2w_returnMcuInfo.p0_ver, P0_VER, 8);
	memcpy(m_m2w_returnMcuInfo.hard_ver, HARD_VER, 8);
	memcpy(m_m2w_returnMcuInfo.soft_ver, SOFT_VER, 8);
	memcpy(m_m2w_returnMcuInfo.product_key, PRODUCT_KEY, 32);
	//binable_time默认0,可以随时被绑定;
	m_m2w_returnMcuInfo.binable_time = 0;																		
		
	//初始化mcu状态帧,sn和校验和需要根据实际填写;
	memset(&m_m2w_mcuStatus, 0, sizeof(m2w_mcuStatus));
	m_m2w_mcuStatus.head_part.head[0] = 0xFF;
	m_m2w_mcuStatus.head_part.head[1] = 0xFF;
	m_m2w_mcuStatus.head_part.len = exchangeBytes(sizeof(m2w_mcuStatus) - 4);
//	DHT11_Read_Data((uint8_t *)&(m_m2w_mcuStatus.status_r.temputure), (uint8_t *)&(m_m2w_mcuStatus.status_r.humidity));
//	m_m2w_mcuStatus.status_w.motor_speed = 5;
	
	//初始化配置wifi模块帧,sn和校验和需要根据实际填写;
	memset(&m_m2w_setModule, 0, sizeof(m2w_setModule));
	m_m2w_setModule.head_part.head[0] = 0xFF;
	m_m2w_setModule.head_part.head[1] = 0xFF;
	m_m2w_setModule.head_part.cmd = CMD_SET_MODULE_WORKMODE;
	m_m2w_setModule.head_part.len = exchangeBytes(sizeof(m2w_setModule) - 4);

	//初始化错误命令帧,sn和校验和需要根据实际填写;
	memset(&m_pro_errorCmd, 0, sizeof(pro_errorCmd));
	m_pro_errorCmd.head_part.head[0] = 0xFF;
	m_pro_errorCmd.head_part.head[1] = 0xFF;
	m_pro_errorCmd.head_part.cmd = CMD_MODULE_CMD_ERROR_ACK;
	m_pro_errorCmd.head_part.len = exchangeBytes(sizeof(pro_errorCmd) - 4);
	
	return 0;
}
Exemplo n.º 2
0
void GizWits_init(uint8_t P0_Len)
{
	Pro_HeadPartP0CmdTypeDef *Pro_D2W_ReportStatusStruct = (Pro_HeadPartP0CmdTypeDef *)g_DevStatus;
	
	Serial1.begin(9600); 
	#if(GetFrame==1)
	//自定义引脚通信SoftwareSerial初始
	Serial.begin(9600);
	#endif
    
    //定时中断初始
//    MsTimer2::set(1, gokit_timer); // 1ms period
//    MsTimer2::start();
    Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);
    Timer2.setPeriod(1000); // in 1000 microseconds = 1ms
    Timer2.setCompare1(1);  // overflow might be small
    Timer2.attachCompare1Interrupt(gokit_timer); // handler function
    // Timer2.pause();
    // Timer2.resume();

    if(P0_Len > MAX_P0_LEN)
    {
        Serial.println("Warning P0_Len out of range");
        while(1);
    }    
    //RingBuffer
    rb_new(&u_ring_buff);
    
	memset((uint8_t *)&g_DevStatus, 0, 128);
	memset(&Pro_M2W_ReturnInfoStruct, 0, sizeof(Pro_M2W_ReturnInfoStruct));
	
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Head[0] = 0xFF;
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Head[1] = 0xFF;
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_M2W_ReturnInfoStruct) - 4);
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Cmd = Pro_D2W__GetDeviceInfo_Ack_Cmd;
	memcpy(Pro_M2W_ReturnInfoStruct.Pro_ver, PRO_VER, strlen(PRO_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.P0_ver, P0_VER, strlen(P0_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Hard_ver, HARD_VER, strlen(HARD_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Soft_ver, SOFT_VER, strlen(SOFT_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Product_Key, PRODUCT_KEY, strlen(PRODUCT_KEY));
	Pro_M2W_ReturnInfoStruct.Binable_Time = exchangeBytes(0);
	
	
	g_P0DataLen = P0_Len;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Head[0] = 0xFF;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Head[1] = 0xFF;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_HeadPartP0CmdTypeDef) - 4);
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Cmd = 0x0;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.SN = 0;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Flags[0] = 0x0;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Flags[1] = 0x0;
	//Pro_D2W_ReportStatusStruct->Action = 0x0;
}
Exemplo n.º 3
0
void GizWits_init(uint8_t P0_Len)
{
	Pro_HeadPartP0CmdTypeDef *Pro_D2W_ReportStatusStruct = (Pro_HeadPartP0CmdTypeDef *)g_DevStatus;

#ifdef M5_VERSION
	Serial1.begin(9600); 
#else	
	Serial.begin(9600); 
#endif	
	#if(GetFrame==1)
	//自定义引脚通信SoftwareSerial初始
	mySerial.begin(9600);
	#endif
    
    //定时中断初始
    MsTimer2::set(1, gokit_timer); // 1ms period
    MsTimer2::start();

    if(P0_Len > MAX_P0_LEN)
    {
        mySerial.println("Warning P0_Len out of range");
        while(1);
    }    
    //RingBuffer
    rb_new(&u_ring_buff);
    
	memset((uint8_t *)&g_DevStatus, 0, 128);
	memset(&Pro_M2W_ReturnInfoStruct, 0, sizeof(Pro_M2W_ReturnInfoStruct));
	
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Head[0] = 0xFF;
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Head[1] = 0xFF;
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_M2W_ReturnInfoStruct) - 4);
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Cmd = Pro_D2W__GetDeviceInfo_Ack_Cmd;
	memcpy(Pro_M2W_ReturnInfoStruct.Pro_ver, PRO_VER, strlen(PRO_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.P0_ver, P0_VER, strlen(P0_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Hard_ver, HARD_VER, strlen(HARD_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Soft_ver, SOFT_VER, strlen(SOFT_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Product_Key, PRODUCT_KEY, strlen(PRODUCT_KEY));
	Pro_M2W_ReturnInfoStruct.Binable_Time = exchangeBytes(0);
	
	
	g_P0DataLen = P0_Len;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Head[0] = 0xFF;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Head[1] = 0xFF;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_HeadPartP0CmdTypeDef) - 4);
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Cmd = 0x0;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.SN = 0;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Flags[0] = 0x0;
	Pro_D2W_ReportStatusStruct->Pro_HeadPart.Flags[1] = 0x0;
	//Pro_D2W_ReportStatusStruct->Action = 0x0;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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
}
Exemplo n.º 6
0
void Pro_W2D_WifiStatusHandle(void)
{
	Pro_W2D_WifiStatusTypeDef Pro_W2D_WifiStatusStruct;
	
	memcpy(&Pro_W2D_WifiStatusStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_W2D_WifiStatusStruct));	
	Pro_W2D_CommonCmdHandle();
    callBackFunc = GizWits_WiFiStatueHandle;
    (*callBackFunc)(exchangeBytes(Pro_W2D_WifiStatusStruct.Wifi_Status)); 
    
} 
Exemplo n.º 7
0
void printf_DevStatus(void)
{
	Printf_TimeDisplay();
	
	printf("RGB LED R=%d,G=%d,B=%d; Motor=%d; Humidity=%d,Temperature=%d; Infrared=%d\r\n",
	Pro_D2W_ReportStatusStruct.Device_All.Device_Wirte.LED_R,Pro_D2W_ReportStatusStruct.Device_All.Device_Wirte.LED_G,Pro_D2W_ReportStatusStruct.Device_All.Device_Wirte.LED_B,
	exchangeBytes(Pro_D2W_ReportStatusStruct.Device_All.Device_Wirte.Motor),
	Pro_D2W_ReportStatusStruct.Device_All.Device_Read.Humidity,
	Pro_D2W_ReportStatusStruct.Device_All.Device_Read.Temperature,
	Pro_D2W_ReportStatusStruct.Device_All.Device_Read.Infrared);
	printf("------------------------------ReportDevStatus-------------------------------------\r\n");
}
Exemplo n.º 8
0
void McuStatusInit(void)
{
	printf("UART_HandleStruct Init...\r\n");
	memset(&UART_HandleStruct, 0, sizeof(UART_HandleStruct));
	memset(&Pro_CommonCmdStruct, 0, sizeof(Pro_CommonCmdStruct));
	Pro_CommonCmdStruct.Pro_HeadPart.Head[0] = 0XFF;
	Pro_CommonCmdStruct.Pro_HeadPart.Head[1] = 0XFF;	
	
	printf("Pro_CommonCmdStruct Init...\r\n");
	memset(&Pro_CommonCmdStruct, 0, sizeof(Pro_CommonCmdStruct));
	Pro_CommonCmdStruct.Pro_HeadPart.Head[0] = 0XFF;
	Pro_CommonCmdStruct.Pro_HeadPart.Head[1] = 0XFF;	
	
	
	memset(&Pro_M2W_ReturnInfoStruct, 0, sizeof(Pro_M2W_ReturnInfoStruct));
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Head[0] = 0XFF; 
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Head[1] = 0XFF;
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_M2W_ReturnInfoStruct) - 4);
	Pro_M2W_ReturnInfoStruct.Pro_HeadPart.Cmd = Pro_D2W__GetDeviceInfo_Ack_Cmd;
	memcpy(Pro_M2W_ReturnInfoStruct.Pro_ver, PRO_VER, strlen(PRO_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.P0_ver, P0_VER, strlen(P0_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Hard_ver, HARD_VER, strlen(HARD_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Soft_ver, SOFT_VER, strlen(SOFT_VER));
	memcpy(Pro_M2W_ReturnInfoStruct.Product_Key, PRODUCT_KEY, strlen(PRODUCT_KEY));
	Pro_M2W_ReturnInfoStruct.Binable_Time = exchangeBytes(0);;		
	
	printf("Pro_D2W_ReportStatusStruct Init...\r\n");
	memset(&Pro_D2W_ReportStatusStruct, 0, sizeof(Pro_D2W_ReportStatusStruct));
	Pro_D2W_ReportStatusStruct.Pro_HeadPartP0Cmd.Pro_HeadPart.Head[0] = 0XFF;
	Pro_D2W_ReportStatusStruct.Pro_HeadPartP0Cmd.Pro_HeadPart.Head[1] = 0XFF;            
	Pro_D2W_ReportStatusStruct.Pro_HeadPartP0Cmd.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_D2W_ReportStatusStruct) - 4);
	Pro_D2W_ReportStatusStruct.Pro_HeadPartP0Cmd.Pro_HeadPart.Cmd = Pro_D2W_P0_Cmd;
	
	printf("Pro_M2WResetCmdStruct Init...\r\n");
	memset(&Pro_M2WResetCmdStruct, 0, sizeof(Pro_M2WResetCmdStruct));
	Pro_M2WResetCmdStruct.Pro_HeadPart.Head[0] = 0XFF;
	Pro_M2WResetCmdStruct.Pro_HeadPart.Head[1] = 0XFF;
	Pro_M2WResetCmdStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_M2WResetCmdStruct) - 4);
	Pro_M2WResetCmdStruct.Pro_HeadPart.Cmd = Pro_D2W_ResetWifi_Cmd;
	
	printf("Pro_D2WConfigCmdStruct Init...\r\n");
	memset(&Pro_D2WConfigCmdStruct, 0, sizeof(Pro_D2WConfigCmdStruct));
	Pro_D2WConfigCmdStruct.Pro_HeadPart.Head[0] = 0XFF;
	Pro_D2WConfigCmdStruct.Pro_HeadPart.Head[1] = 0XFF;
	Pro_D2WConfigCmdStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_D2WConfigCmdStruct) - 4);
	Pro_D2WConfigCmdStruct.Pro_HeadPart.Cmd = Pro_D2W_ControlWifi_Config_Cmd;	

	printf("Device_WirteStruct Init...\r\n");
	memset(&Device_WirteStruct, 0, sizeof(Device_WirteStruct));
	Device_WirteStruct.Motor = exchangeBytes(0x05);   //关闭电机
	
	printf("Device_ReadStruct Init...\r\n");
	memset(&Device_ReadStruct, 0, sizeof(Device_ReadStruct));
	
	printf("KEY_Status Init...\r\n");
	memset(&KEY_Status, 0, sizeof(KEY_Status));
	
}
Exemplo n.º 9
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
}
Exemplo n.º 10
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

}
Exemplo n.º 11
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
}
Exemplo n.º 12
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;
	}	
}