Esempio n. 1
0
int main()
{
		u8 State=REMOTECONTROL_LOCK;
		u8 OldState=REMOTECONTROL_LOCK;
		double Receive_data=0;  //接收数据  10ms
		double RcUpdata=0;      //遥控器状态更新时间  20ms
		ledBlueGPIO.SetLevel(0);
	while(1)
	{	
		if(tskmgr.TimeSlice(Receive_data,0.01) ) //0.01
		{
			Hi.DataListening_SendPC();//监听飞机发送来的数据转发给PC
			Hi.DataListening_SendCopter();//监听PC发送来的数据转发给飞机
		}
		
		if(tskmgr.TimeSlice(RcUpdata,0.08) )
		{
			State=RC.Updata(80,2000);	
			Hi.SendData2Copter(RC.GetYawVal(),RC.GetThrottleVal(),RC.GetRollVal(),RC.GetPitchVal(),false);	
			
			if(State == REMOTECONTROL_LOCK &&  OldState ==REMOTECONTROL_UNLOCK )
			{
					OldState = REMOTECONTROL_LOCK;
					Hi.SendOrder(0XA0);
					ledBlueGPIO.SetLevel(1);//上锁状态为亮
			}
			else if(State ==REMOTECONTROL_UNLOCK && OldState ==REMOTECONTROL_LOCK)//解锁
			{	
					Hi.SendOrder(0XA1);
					OldState = REMOTECONTROL_UNLOCK;
					ledBlueGPIO.SetLevel(0);//解锁状态为灭
					//tskmgr.DelayS(1);
			}		
			if(State == REMOTECONTROL_UNLOCK) //如果解锁了才向上位机发送
					Hi.SendData2Copter(RC.GetYawVal(),RC.GetThrottleVal(),RC.GetRollVal(),RC.GetPitchVal(),true);			
			
			
		}	
		
	}
}
Esempio n. 2
0
int main(){
	u8 order=0;
	double record_updataSensor=0;
	double record_alive=0;
	double record_getwifi=0;
	bool network=false ; //网络连接标识位 
	char *ip = (char*)calloc(15, sizeof(char*) ); 
	char *WifiName = (char*)calloc(20, sizeof(char*) ); 
	char *WifiPassword = (char*)calloc(20, sizeof(char*) ); 
	
/*开机WIFI模式选择*****************************************************************/
	if(wifimemory.getWifiSum()!=0)//判断表中是否已经保存wifi信息
	{
		while( wifimemory.Load(WifiName,WifiPassword) )
		 {
			  if(wifi.ConnectNetwork_client(WifiName,WifiPassword,SERVER_IP,1111)) //每次连接历时20秒
				{network=true;   break;}
		 }
		 if(network ==false) {
			  wifi.ConnectNetwork_server(MODULE_COM,0);
			 	WIFI.ClearReceiveBuffer();
		 }
	}
  else
	{
		 wifi.ConnectNetwork_server(MODULE_COM,0);
			WIFI.ClearReceiveBuffer();
	}
	
	Led.SetLevel(1);//将指示灯熄灭(模式切换结束)
/*END*********************************************************************************/	

while(1)
	{		
		order=CMCT_Tool.GetStateOrder(WIFI);
		switch(order)
		{
			case DELAY:{}break;
	/*启动********************************************************************************************/
			case START:{//启动
				while(1){
							if(tskmgr.ClockTool(record_updataSensor,3)) //每三秒执行一次更新
							{
								co2.Updata();
								if(network)
									wifi.Send(20,CMCT_Tool.ToServerPack(CO2Number,co2.DATA_H,co2.DATA_L,0));	
								else
									wifi.Send(0,20,CMCT_Tool.ToClientPack(CO2Number,co2.DATA_H,co2.DATA_L,0));	
							}
							if(CMCT_Tool.GetStateOrder(WIFI)==DELAY)
							break;					
				}
			}break;
	/*END********************************************************************************************/			
			
	/*复位******************************************************************************************/
			case RESET:{//复位
					wifimemory.ClearAllData(); //清空所有保存信息
					*((u32 *)0xE000ED0C) = 0x05fa0004;
			}break;
	/*END******************************************************************************************/
			
	/*获取WIFI信息*********************************************************************************/		
			case GETWIFI:{//得到wifi账号密码
				record_getwifi=tskmgr.Time();
					while(1)
					{
						if(CMCT_Tool.GetWifiNameAndPassword(WifiName,WifiPassword,WIFI) )
						{
								//保存WIFI账号密码
								com<<WifiName<<"\t"<<WifiPassword<<"\n";
								break;
						}
						if(tskmgr.ClockTool(record_getwifi,30)) //超时10秒退出
						   break;
					}
			}break;
	/*END******************************************************************************************/
			
	/*模式切换*************************************************************************************/
			case MODEL:{//模式切换
					wifi.ConnectNetwork_server(MODULE_COM,0);
					WIFI.ClearReceiveBuffer();
					network=false;
			}break;
	/*END******************************************************************************************/

	/*存活确认*************************************************************************************/			
			case ALIVE:{//存活确认
				if(network)
					CMCT_Tool.SendAlive(wifi,CO2Number,1); //存活确认,数据位全为0xff
				else
					CMCT_Tool.SendAlive(wifi,CO2Number,0);
			}break;			
	/*END******************************************************************************************/		
			
	/*常态******************************************************************************************/		
			default:		
			{  
					if(tskmgr.ClockTool(record_updataSensor,3)) //每三秒执行一次更新
						 co2.Updata();//当没有命令时更新传感器
						if(tskmgr.ClockTool(record_alive,60)) //每60秒发送一次存活确认
					{
						if(network)
							CMCT_Tool.SendAlive(wifi,CO2Number,1);
						else
							CMCT_Tool.SendAlive(wifi,CO2Number,0);
					}
			}
		}		
	}
}
Esempio n. 3
0
int main()
{
	double record_UI_Updata=0; //UI更新时间片
	double record_UI_power=0;//电量更新
	double record_UI_time_hight=0;//时间更新
	double record_UI_YRPT_CLOCK=0;//时间更新
	double record_JoystickUpdata=0;
	double test=0;
	


	
	ledRedGPIO.SetLevel(1);
	ledGREGPIO.SetLevel(1);
	
	
	
	while(1)
	{
		Rc2Copter.DataListening();
		
		
		if(tskmgr.TimeSlice(record_UI_Updata,0.1))  //0.1秒更新一次UI
		{
				//MessageShow.setTextBox("t21",num);
			if(tskmgr.TimeSlice(record_UI_power,5))//每5秒更新一次电量值
			{
				MessageShow.setTextBox(UI_RcPower,pressure.Voltage_I(1,1,2,4.2),1);
				MessageShow.setTextBox(UI_CopterPower,Rc2Copter.RcvPower,1);
				
			}
			if(tskmgr.TimeSlice(record_UI_time_hight,1))//每秒更新一次高度和时间
			{
				MessageShow.setTextBox(UI_Hight,Rc2Copter.RcvHight,0);
				MessageShow.setTextBox(UI_AliveTime,Rc2Copter.RcvTime,0);
			}
			if(tskmgr.TimeSlice(record_UI_YRPT_CLOCK,0.5)) //没0.5秒更新一次显示
			{
				MessageShow.setTextBox(UI_YAW,Rc2Copter.RcvYaw,0);
				MessageShow.setTextBox(UI_ROOL,Rc2Copter.RcvRoll,0);
				MessageShow.setTextBox(UI_PITCH,Rc2Copter.RcvPitch,0);
				MessageShow.setTextBox(UI_THR,Rc2Copter.RcvThr,0);	
				
				if(Rc2Copter.ClockState == 1)
					MessageShow.vis(UI_FlyClock,1);//显示  为橙色
				else
					MessageShow.vis(UI_FlyClock,0);//隐藏  为蓝色
				
			}
			
			//更新摇杆状态显示
			MessageShow.outputDirection(UI_DirectionL,RC.getLeftState());
			MessageShow.outputDirection(UI_DirectionR,RC.getNightState());
			
		}
		
		if(tskmgr.TimeSlice(record_JoystickUpdata,0.1))  //0.1秒更新一次摇杆状态
		{
  				if(RC.Updata())
					{
					//遥控器状态判断  外八解锁,内八上锁
						if(RC.getLeftState() == 7 && RC.getNightState() == 9) //解
						{
								Rc2Copter.FlightLockControl(false);
						}
						else if(RC.getLeftState() == 9 && RC.getNightState() == 7)
						{
								Rc2Copter.FlightLockControl(true);
						}
						else if(RC.getLeftState() == 1 && RC.getNightState() == 3 && Rc2Copter.ClockState == 1) //外八且上锁
						{
								
						}
						else//如果处于解锁状态则发送数据
						{
								if(Rc2Copter.ClockState == 0)
								{
									//发送数据
									Rc2Copter.SendData2Copter(1000,1000,1000,1000);
								}
						}
															
					}			
		}
		if(tskmgr.TimeSlice(test,0.1))  
			com1<<pressure[5]<<"\t"<<pressure[6]<<"\t"<<pressure[8]<<"\t"<<pressure[9]<<"\n";
		
		
	}
}