Esempio n. 1
0
bool MHZ14::Updata()
{	
	//向模块发送获取数据
	   CO2.SendData(Command_getvalue,9);
	
	//判断是否有数据返回
	  if(CO2.ReceiveBufferSize()<9)
	  {
		  CO2.ClearReceiveBuffer(); //清空接收缓存
		  return false;
	  }
	  else
	  {
		  CO2.GetReceivedData(rev_buffer,9); //取出一帧数据
		   CO2.ClearReceiveBuffer(); //清空接收缓存
		  
		  if(SumCheck(rev_buffer)==false)  //校验和
			  return false;
		  else
		  {
			  DATA_H=rev_buffer[2];
			  DATA_L=rev_buffer[3];
			  CO2_Concentration=rev_buffer[2]*256+rev_buffer[3];  //计算浓度
			  return true;
		  }
	  }
}
Esempio n. 2
0
int main(int argc, char **argv) {	
	while (true) {
		out.print("Enter some text: ");
		char buf[20];
		out.getline(buf, sizeof(buf));
		out.printf("You typed: %s\n", buf);
		Task::sleep(1000);
	}
}
static void docalibrate(const char *type, PID::Config *conf) {
	out.printf("Old %s: %f %f %f\n", type, conf->p, conf->i, conf->d);
	out.printf("New %s PID values:\n", type);
	
	static char buf[100];
	out.getline(buf, sizeof(buf));
	
	sscanf(buf, "%f %f %f", &conf->p, &conf->i, &conf->d);
	out.printf("Got: %f %f %f\n", conf->p, conf->i, conf->d);
}
Esempio n. 4
0
void AppInit(void) {
	TouchPanelTask.Run();
	GUITask.Run();
	BlinkTask.Run();
	
	printf("Gib was ein:\r\n");
	Serial.ReadLn(buf, 10);
	printf("Du hast eingegeben: %s", buf);
}	
/* ----------------------------------------------------------------------------
 * メイン処理
 * ---------------------------------------------------------------------------- */
int main(void)
{
	setup();
	while(1)
	{
		loop();
		Serial1.getrxd();
	}
}
Esempio n. 6
0
int main(int argc, char **argv) {	
	out.print("Begin log test!\n");
	
	const uint8_t writedata[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	unsigned int i;
	for (i=0;i<20;i++)
		logger.write(writedata, sizeof(writedata));
		
	logger.flush();
	out.print("Done!\n");
	
	uint8_t data[128];
	eeprom.read(EEPROM::pageAddress(0), data, sizeof(data));
	out.printf("EEPROM page 0:\n", data);
	for (i=0; i<sizeof(data); i++) {
		out.printf("%u ", (unsigned int)data[i]);
	}
	out.print("\n");
}
Esempio n. 7
0
int main(int argc, char **argv) {
	bool prevsynced=true;
		
	while (true) {
		Task::sleep(5);
		
		if (vex.getSynced()) {
			VexRC::Channels chans = vex.getChannels();
		
			out.printf("%d %d %d %d ", chans.analogs[0], chans.analogs[1], chans.analogs[2], chans.analogs[3]);
			out.printf("%s %s\n", digitalToString(chans.left), digitalToString(chans.right));
			prevsynced = true;
		} else {
			if (prevsynced) {
				buzzer.buzz(100);
				out.print("Not synced\n");
			}
			prevsynced = false;
		}
	}
}
Esempio n. 8
0
int main(void)
{
  char buffer[15];
  setup();
  
  
  
  for(;;){
     ADCSRA |= 1 << ADSC;
     loop_until_bit_is_clear(ADCSRA, ADSC);
     adch = ADC;
     
     //uart.printstr(str);
     itoa(adch, buffer, 10);
     uart.printstr( (const char *)buffer );
     uart.printstr( "\n" );
     _delay_ms(100);
  }

  return 0;
}
Esempio n. 9
0
//监听一个端口,返回一个命令
u8 Transmission::GetStateOrder(USART &ListeningCOM)
{
		u8 comand[8]={0};
		u8 ch=0;
		u8 num = ListeningCOM.ReceiveBufferSize();
		if(num>7)   //一帧命令包含8个字节
		{
				ListeningCOM.GetReceivedData(&ch,1);
			if(ch == 0xFF)
			{
				ListeningCOM.GetReceivedData(&ch,1);
				if(ch == 0xDD)
				{
					while(ListeningCOM.ReceiveBufferSize()<6);//等待数据
					comand[0]=0xff;
					comand[1]=0xDD;
					ListeningCOM.GetReceivedData(comand+2,6);
					ListeningCOM.ClearReceiveBuffer();
					return CommandParsing(comand);  //解包
				}
				else return 0;
			}
			else
				return 0;
		}
		else 
			return 0;
}
Esempio n. 10
0
bool Transmission::GetWifiNameAndPassword(char *name,char *password,USART &ListeningCOM)
{
	u8 ch=0;
	u8 i =0;
	ListeningCOM.GetReceivedData(&ch,1);
		if(ch == 0xFF)
		{
			tskmgr.DelayMs(100);
			ListeningCOM.GetReceivedData(&ch,1);
			if(ch == 0x03)
			{
				ListeningCOM.GetReceivedData(&ch,1);
				while(ch!=0xff){
					*(name+i)=ch;
					i++;
					ListeningCOM.GetReceivedData(&ch,1);
				}
					*(name+i)='\0';
					ListeningCOM.GetReceivedData(&ch,1);
					i=0;
				while(ch!=0xff){
					*(password+i)=ch;
					i++;
					ListeningCOM.GetReceivedData(&ch,1);
				}
					*(password+i)='\0';	
				return 1;
			}
			else return 0;
		}
		else
			return 0;
}
/* ----------------------------------------------------------------------------
 * メインループ
 * ---------------------------------------------------------------------------- */
void loop() {
	int i;
	int j;
	
	// 1秒毎の処理
	if(interruptCount > 999) {
		// 時計モード
		if(userDataTimerCount == 0) {
			rtc.get();
			// 年月日表示か時刻表示かの判定
			if(displayDateIntervalCount <= displayDateIntervalValue) {
				// 時分秒表示
				// カンマをクリア
				for(int i = 0; i < 8; i++) {
					IN12Com[i] = 0;
				}
				// 6桁フォーマット 999999
				if(dispTimeFormat == 0) {
					IN12Num[0] = 0x0F;
					if(hour12_24format == 1) {
						IN12Num[1] = rtc.hourHigh;
						IN12Num[2] = rtc.hourLow;
					} else {
						IN12Num[1] = rtc.hourHigh12;
						IN12Num[2] = rtc.hourLow12;
					}
					IN12Num[3] = rtc.minutesHigh;
					IN12Num[4] = rtc.minutesLow;
					IN12Num[5] = rtc.secondsHigh;
					IN12Num[6] = rtc.secondsLow;
					IN12Num[7] = 0x0F;
				}
				// 8桁フォーマット 99, 99, 99
				if(dispTimeFormat == 1) {
					if(hour12_24format == 1) {
						IN12Num[0] = rtc.hourHigh;
						IN12Num[1] = rtc.hourLow;
					} else {
						IN12Num[0] = rtc.hourHigh12;
						IN12Num[1] = rtc.hourLow12;
					}
					IN12Num[2] = 0x0F;
					IN12Num[3] = rtc.minutesHigh;
					IN12Num[4] = rtc.minutesLow;
					IN12Num[5] = 0x0F;
					IN12Num[6] = rtc.secondsHigh;
					IN12Num[7] = rtc.secondsLow;
					IN12Com[2] = 1;
					IN12Com[5] = 1;
				}
			} else {
				// 年月日表示
				// カンマクリア
				for(int i = 0; i < 8; i++) {
					IN12Com[i] = 0;
				}
				IN12Num[0] = 2;
				IN12Num[1] = 0;
				IN12Num[2] = rtc.yearHigh;
				IN12Num[3] = rtc.yearLow;
				IN12Num[4] = rtc.monthHigh;
				IN12Num[5] = rtc.monthLow;
				IN12Num[6] = rtc.dayHigh;
				IN12Num[7] = rtc.dayLow;
				if(displayDateIntervalCount >= ( displayDateIntervalValue + displayDateSecondsValue)) {
					displayDateIntervalCount = 0;
				}
			}
			displayDateIntervalCount++;
		}
		// ユーザーデータ表示中
		if(userDataTimerCount > 0) {
			userDataTimerCount--;
		}
		// LED 点滅
		if(led == false) {
			led = true;
			PORTC |= (1<<LED);
		} else {
			led = false;
			PORTC &= ~(1<<LED);
		}
		interruptCount = 0;
	}
	
	// シリアル1 受信処理
	while(Serial1.available()) {
		char ch = Serial1.getch();
		serial0String[serial0StringIdx] = ch;
		Serial1.putch(ch);
		if(serial0String[serial0StringIdx] == '\r') {
			Serial1.putch('\n');
			serial0String[serial0StringIdx] = 0;
			serial0StringComplete = true;
		}
		serial0StringIdx++;
		if(serial0StringIdx >= SERIALBUF_LEN) {
			serial0StringIdx = SERIALBUF_LEN - 1;
		}
		// CR コードだけの入力は無視
		if(serial0StringComplete == true && serial0StringIdx == 1) {
			serial0StringIdx = 0;
			serial0StringComplete = false;
		}
	}
	
	// 受信データ処理
	if(serial0StringComplete == true) {
		// ニキシー表示データチェック
		int isUserData = true;
		for(i = 0; i < (serial0StringIdx - 1); i++) {
			if(serial0String[i] == ' ') continue;
			if(serial0String[i] == '.') continue;
			if((serial0String[i] >= '0') && (serial0String[i] <= '9')) continue;
			isUserData = false;
		}
		// ユーザーデータを表示
		if(isUserData == true) {
			for(i = 0; i < 8; i++) {
				IN12Num[i] = 0x0F;
				IN12Com[i] = 0;
			}
			j = 7;
			for(i = (serial0StringIdx - 1); i >= 0; i--) {
				if(serial0String[i] >= '0' && serial0String[i] <= '9') {
					if(j >= 0) {
						IN12Num[j--] = serial0String[i] - 0x30;
					}
				} else if(serial0String[i] == ' ') {
					if(j >= 0) {
						IN12Num[j--] = 0x0F;
					}
				}
			}
			j = 8;
			int previusCharValid = false;
			for(i = (serial0StringIdx - 1); i >= 0; i--) {
				if((serial0String[i] >= '0' && serial0String[i] <= '9') || serial0String[i] == ' ') {
					previusCharValid = true;
					if(j > 0) {
						j--;
					}
					continue;
				}
				if(serial0String[i] == '.' && previusCharValid == true) {
					IN12Com[j] = 1;
					previusCharValid = false;
				}
			}
			userDataTimerCount = userDataTimerValue;
		}
		if(isUserData == false) {
			// コマンド処理
			if(strncmp(serial0String, "help", 4) == 0) {
				Serial1.putstr("set time YYMMDD hhmmss\r\n");
				Serial1.putstr("set timeformat [0 or 1]\r\n");
				Serial1.putstr("set dateinterval 99999\r\n");
				Serial1.putstr("set datesec 99999\r\n");
				Serial1.putstr("set udatasec 99999\r\n");
				Serial1.putstr("set bright daytime [1 to 9]\r\n");
				Serial1.putstr("set bright night [1 to 9]\r\n");
				Serial1.putstr("set hour daytime [0 to 23]\r\n");
				Serial1.putstr("set hour night [0 to 23]\r\n");
				Serial1.putstr("set 12/24 format [0 or 1]\r\n");
				Serial1.putstr("cathod -> Cathod poisoning\r\n");
				Serial1.putstr("sekai  -> STEINS;GATE like effect\r\n");
				Serial1.putstr("save   -> write EEPROM\r\n");
				Serial1.putstr("show   -> show all setting\r\n");
				Serial1.putstr("time   -> change to clock mode\r\n");
				Serial1.putstr("\r\n");
				Serial1.putstr("99999: numeric number 0 to 65535\r\n");
				Serial1.putstr("---\r\n");
			}
			if(strncmp(serial0String, "set timeformat ", 15) == 0) {
				unsigned int i = atoi(&serial0String[15]);
				if(i == 0 || i == 1) {
					dispTimeFormat = i;
					sprintf(msg, "value = %d\r\n", dispTimeFormat);
					Serial1.putstr(msg);
				}
			}
			if(strncmp(serial0String, "set time ", 9) == 0) {
				unsigned char year = ((serial0String[9] & 0x0F)<<4);
				year |= serial0String[10] & 0x0F;
				unsigned char month = ((serial0String[11] & 0x0F)<<4);
				month |= serial0String[12] & 0x0F;
				unsigned char days = ((serial0String[13] & 0x0F)<<4);
				days |= serial0String[14] & 0x0F;
				unsigned char hour = ((serial0String[16] & 0x0F)<<4);
				hour |= serial0String[17] & 0x0F;
				unsigned char minutes = ((serial0String[18] & 0x0F)<<4);
				minutes |= serial0String[19] & 0x0F;
				unsigned char seconds = ((serial0String[20] & 0x0F)<<4);
				seconds |= serial0String[21] & 0x0F;
				rtc.set(year, month, 1, days, hour, minutes, seconds);
			}
			if(strncmp(serial0String, "set dateinterval ", 17) == 0) {
				displayDateIntervalValue = atoi(&serial0String[17]);
				sprintf(msg, "value = %d\r\n", displayDateIntervalValue);
				Serial1.putstr(msg);
			}
			if(strncmp(serial0String, "set datesec ", 12) == 0) {
				displayDateSecondsValue = atoi(&serial0String[12]);
				sprintf(msg, "value = %d\r\n", displayDateSecondsValue);
				Serial1.putstr(msg);
			}
			if(strncmp(serial0String, "set udatasec ", 13) == 0) {
				userDataTimerValue = atoi(&serial0String[13]);
				sprintf(msg, "value = %d\r\n", userDataTimerValue);
				Serial1.putstr(msg);
			}
			if(strncmp(serial0String, "cathod", 6) == 0) {
				cathodePoisoning();
				Serial1.putstr("Done.");
			}
			if(strncmp(serial0String, "sekai", 5) == 0) {
				steins();
				//serialPrintln("Done.");
			}
			if(strncmp(serial0String, "set bright daytime ", 19) == 0) {
				unsigned int i = atoi(&serial0String[19]);
				if(i > 0 && i < 10) {
					IN12BrightDaytime = i;
					sprintf(msg, "value = %d\r\n", IN12BrightDaytime);
					Serial1.putstr(msg);
				}
			}
			if(strncmp(serial0String, "set bright night ", 17) == 0) {
				unsigned int i = atoi(&serial0String[17]);
				if(i > 0 && i < 10) {
					IN12BrightNight = i;
					sprintf(msg, "value = %d\r\n",IN12BrightNight);
					Serial1.putstr(msg);
				}
			}
			if(strncmp(serial0String, "set hour daytime ", 17) == 0) {
				unsigned int i = atoi(&serial0String[17]);
				if(i >= 0 && i < 24) {
					hourDaytime = i;
					sprintf(msg, "value = %d\r\n", hourDaytime);
					Serial1.putstr(msg);
				}
			}
			if(strncmp(serial0String, "set hour night ", 15) == 0) {
				unsigned int i = atoi(&serial0String[15]);
				if(i >= 0 && i < 24) {
					hourNight = i;
					sprintf(msg, "value = %d\r\n", hourNight);
					Serial1.putstr(msg);
				}
			}
			if(strncmp(serial0String, "set 12/24 format ", 17) == 0) {
				unsigned int i = atoi(&serial0String[17]);
				if(i == 0 || i == 1) {
					hour12_24format = i;
					sprintf(msg, "value = %d\r\n", hour12_24format);
					Serial1.putstr(msg);
				}
			}
			if(strncmp(serial0String, "save", 4) == 0) {
				// EEPROM 書き込み
				eeprom_busy_wait();
				eeprom_write_word(&E_displayDateIntervalValue, displayDateIntervalValue);
				eeprom_busy_wait();
				eeprom_write_word(&E_displayDateSecondsValue, displayDateSecondsValue);
				eeprom_busy_wait();
				eeprom_write_word(&E_userDataTimerValue, userDataTimerValue);
				eeprom_busy_wait();
				eeprom_write_byte(&E_dispTimeFormat, dispTimeFormat);
				eeprom_busy_wait();
				eeprom_write_byte(&E_IN12BrightDaytime, IN12BrightDaytime);
				eeprom_busy_wait();
				eeprom_write_byte(&E_IN12BrightNight, IN12BrightNight);
				eeprom_busy_wait();
				eeprom_write_byte(&E_hourDaytime, hourDaytime);
				eeprom_busy_wait();
				eeprom_write_byte(&E_hourNight, hourNight);
				eeprom_busy_wait();
				eeprom_write_byte(&E_hour12_24format, hour12_24format);
				Serial1.putstr("EEPROM write complete\r\n");
			}
			if(strncmp(serial0String, "time", 4) == 0) {
				userDataTimerCount = 0;
			}
			if(strncmp(serial0String, "show", 4) == 0) {
				sprintf(msg, "set timeformat %d\r\n",dispTimeFormat);
				Serial1.putstr(msg);
				sprintf(msg, "set dateinterval: %d\r\n",displayDateIntervalValue);
				Serial1.putstr(msg);
				sprintf(msg, "set datesec: %d\r\n", displayDateSecondsValue);
				Serial1.putstr(msg);
				sprintf(msg, "set udatasec: %d\r\n", userDataTimerValue);
				Serial1.putstr(msg);
				sprintf(msg, "set bright daytime: %d\r\n", IN12BrightDaytime);
				Serial1.putstr(msg);
				sprintf(msg, "set bright night: %d\r\n", IN12BrightNight);
				Serial1.putstr(msg);
				sprintf(msg, "set hour daytime: %d\r\n", hourDaytime);
				Serial1.putstr(msg);
				sprintf(msg, "set hour night: %d\r\n", hourNight);
				Serial1.putstr(msg);
				sprintf(msg, "set 12/24 format: %d\r\n", hour12_24format);
				Serial1.putstr(msg);
				Serial1.putstr("Release 2013/11/03 Ver 1.0\r\n");
				Serial1.putstr("---\r\n");
			}
		}
		serial0StringIdx = 0;
		serial0StringComplete = false;
	}
	wdt_reset();
}
Esempio n. 12
0
int main()
{
	u8 command[6];
	u8 datatemp[18];//数据暂存
	u8 tagInfo[18];
	u8 sensor[16];//保存传感器型号
	u8 basic_information[6];//基础信息
	u8 version[16];//版本
	
	tskmgr.DelayMs(1000);
	tskmgr.DelayMs(1000);
	
	
	//设置模式
	//设置名字密码
	//设置IP地址
	//复位
	WIFI.SendData(CLOSS,6);  //关闭回显
	tskmgr.DelayMs(1000);
	WIFI.SendData(Command1,13);  //开启多路连接
	tskmgr.DelayMs(1000);
	WIFI.SendData(Command2,21); //开启服务器模式
	tskmgr.DelayMs(1000);
	
	
	  equipment[0]=2;//测试用 将设备二加入
//	  DATA_COM.SendData(c,8);  //连续发送命令
	
	
    while(1)
	{
	  //接收从模块数据
	 if(DATA_COM.ReceiveBufferSize()>=40) //如果接收到了一帧数据
	 {
		 u32 check=10,moduleNo;
		 u8 sum=0;
		 u8 FFAA=0;
		 DATA_COM.GetReceivedData(&FFAA,1); //找包头
		 if(FFAA==0xff)
		{
		  DATA_COM.GetReceivedData(&FFAA,1); //找包头
		  if(FFAA==0xcc)
		{
		 DATA_COM.GetReceivedData(datatemp,18);
		 moduleNo=datatemp[0]+datatemp[1]+datatemp[2]+datatemp[3];
		 for(u8 i=0;i<10;i++) //查询是否有这个设备
		  {
			if(moduleNo==equipment[i])
				check=0;//有这个设备
		  }
		  for(u8 i=0;i<16;i++)
		  {
			sum+=datatemp[i];  //j校验和
		  }
		  sum=sum+0XCB;  //加上包头
		  if(sum==datatemp[17])
			  check=check+1;
		  
		  //使用WIFI发送数据给上位机
		  if(check==1)
		  {
		    WIFI.SendData(Command3,17);
	        tskmgr.DelayMs(100);
			WIFI.ClearSendBuffer();
			WIFI.SendData(packgroup.MAINToUser(datatemp[5],datatemp[6],datatemp[7],moduleNo,datatemp[4]),20);
			tskmgr.DelayMs(100); 
			  
			WIFI.ClearReceiveBuffer();//清除接收缓存
			WIFI.ClearSendBuffer();  //清除发送缓存
		  }
	  }
	  }
	 }
	
//从上位机得到命令()
		if(WIFI.ReceiveBufferSize()>40)
		{
			u8 ch=0;
			u8 temp_cmd;
			 u32 temp;
			//test
		
			while(WIFI.ReceiveBufferSize()>8)
			{
				WIFI.GetReceivedData(&ch,1);
				if(ch==0xff)//判断包头
				{
					WIFI.GetReceivedData(&ch,1);
					if(ch==0xdd)//判断包头
					{
					  //得到指令
					   WIFI.GetReceivedData(command,6);
					   WIFI.ClearReceiveBuffer();
						
					   temp_cmd=command[4];  //得到命令位				
					   temp=command[0]+command[1]+command[2]+command[3];//得到设备号
						//命令处理
						if(temp_cmd==0XAA)//如果命令是注册
						{
							//读取RFID 将结果给上位机*********************************************
							double in_time;
							in_time=tskmgr.Time();
							rfid.PCDInit();
							while(1)
							{							
								tskmgr.DelayMs(500);
								if(tskmgr.Time()-in_time>=20)  //60秒读取等待
								{
									//返回结束
									break;
								}
								if(rfid.FindCard(MFRC522_PICC_REQALL,tagInfo))//寻到卡
								{
									if(rfid.PcdAntiColl(tagInfo))
									{																																
										if(rfid.PcdSelect(tagInfo))//选卡,卡号为前一步找到的卡号
										{																											
											if(rfid.PcdAuthState(MFRC522_PICC_AUTHENT1A,5,(unsigned char*)DefaultKey,tagInfo))//校验A密匙
											{
												rfid.PcdRead(5,basic_information);//第五块																		
												rfid.PcdRead(6,sensor);//第六块
													
											}
											
											if(rfid.PcdAuthState(MFRC522_PICC_AUTHENT1A,9,(unsigned char*)DefaultKey,tagInfo))//校验A密匙
											{
												rfid.PcdRead(9,version);//第9块
											}
								    		equipment_confirm(basic_information);//设备号存在判断,没有就存入
										    WIFI.SendData(Command3,17);
											tskmgr.DelayMs(100);
											WIFI.ClearSendBuffer();
											WIFI.SendData(packgroup.registered(basic_information,sensor,version),20);//打包发送	WIFI.SendData(a,6);												
											tskmgr.DelayMs(500);//这里必须保证充足的延时才能发送下一半
											
										}
											
									}
									
								}
								
							}
						}
						else if(temp_cmd==0XDD)//如果命令是删除
						{
							for(int n=0;n<10;n++)
							{
								if(temp==equipment[n])
									equipment[n]=0;  //删除这个设备
							}
						}
						else
						{
							DATA_COM.SendData(packgroup.CmmandTomodule(temp_cmd,temp),8); 	
						}

						
					}
				}
			}
			WIFI.ClearReceiveBuffer();
		}

	}
	
}
Esempio n. 13
0
    void Run(uint32_t i2cClockSpeed)
    {
        bool dmpReady = false; // set true if DMP init was successful
        uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
        uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
        uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
        uint16_t fifoCount; // count of all bytes currently in FIFO
        uint8_t fifoBuffer[64]; // FIFO storage buffer

        Quaternion q; // [w, x, y, z] quaternion container
        VectorInt16 aa; // [x, y, z] accel sensor measurements
        VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
        VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
        VectorFloat gravity; // [x, y, z] gravity vector
        float eu[3]; // [psi, theta, phi] Euler angle container
        float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
        uint16_t y, p, r;
        float yaw_offset;

        I2C1* i2c = GPIO_Helper::SetupI2C1_PB_6_9(i2cClockSpeed);
        i2c->SetErrorHandler(this);
        MPU6050 mpu(i2c);

        //Initialized with highest sensitivities
        mpu.reset();
        RCC_Delay_ms(50);
        mpu.initialize();

#ifdef USE_USART
        uint32_t clockSpeed = 1200000;
        USART* usart = GPIO_Helper::SetupUSART2_PA_2_3(clockSpeed);
#endif        

        devStatus = mpu.dmpInitialize();

        if (devStatus != 0)
        {
            while (1)
                ;
        }

        mpu.setDMPEnabled(true);
        packetSize = mpu.dmpGetFIFOPacketSize();

        while (1)
        {
            // wait for MPU interrupt or extra packet(s) available
            //while (!mpuInterrupt && fifoCount < packetSize) {
            //}

            // reset interrupt flag and get INT_STATUS byte
            mpuIntStatus = mpu.getIntStatus();
            // get current FIFO count
            fifoCount = mpu.getFIFOCount();
            // check for overflow (this should never happen unless our code is too inefficient)
            if (mpuIntStatus & 0x02)
            {
                // wait for correct available data length, should be a VERY short wait
                while (fifoCount < packetSize)
                    fifoCount = mpu.getFIFOCount();
                // read a packet from FIFO
                mpu.getFIFOBytes(fifoBuffer, packetSize);
                // track FIFO count here in case there is > 1 packet available
                // (this lets us immediately read more without waiting for an interrupt)
                fifoCount -= packetSize;

                // display quaternion values in easy matrix form: w x y z
                mpu.dmpGetQuaternion(&q, fifoBuffer);

                mpu.dmpGetEuler(eu, &q);
                eu[0] *= 180. / M_PI;
                eu[1] *= 180. / M_PI;
                eu[2] *= 180. / M_PI;
                mpu.dmpGetGravity(&gravity, &q);

                mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

                //rad to degrees
                ypr[0] *= 180. / M_PI;
                ypr[1] *= 180. / M_PI;
                ypr[2] *= 180. / M_PI;

                // display real acceleration, adjusted to remove gravity
                mpu.dmpGetAccel(&aa, fifoBuffer);
                mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);

                // display initial world-frame acceleration, adjusted to remove gravity
                // and rotated based on known orientation from quaternion
                mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);

#ifdef USE_USART
                if (usart->IsRXNE())
                {
                    if (usart->Receive() == 23)
                    {
                        usart->SendWord((int16_t)(ypr[0]));
                        usart->SendWord((int16_t) ypr[1]);
                        usart->SendWord((int16_t) ypr[2]);
                    }
                }

#endif                
            }
            else if ((mpuIntStatus & 0x10) || fifoCount == 1024)
            {
                // reset so we can continue cleanly
                mpu.resetFIFO();
            }
        }
    }
Esempio n. 14
0
int main(int argc, char **argv) {
	imu.start();

	out.printf("Battery: %f cell\n", batmon.getCellVoltage());
	out.print("Waiting for remote signal\n");
	while (!vex.getSynced()) { Task::sleep(100); }

	out.print("Arming\n");
	motors.arm();

	float heading = imu.getYaw();
	buzzer.buzz(300);

	while (true) {
		control.start();
		Logger logger(eeprom, 0);
		bool logging = false;
		
		while (true) {
			bool up = false;
			if (!vex.getSynced()) {
				control.stop();
				motors.off();
				while (!vex.getSynced()) { Task::sleep(100); }
				control.start();
				sensors.centerGyros();
				heading = imu.getYaw();
				buzzer.buzz(300);
			}
		
			VexRC::Channels chans = vex.getChannels();
	
			if (chans.right != VexRC::NONE)
				break;
			if (chans.left == VexRC::UP)
				logging = true;
			else if (chans.left == VexRC::DOWN)
				logging = false;
	
			float throttle = chans.analogs[1] / 50.0;
			if (throttle < 0)
				throttle = 0;
			float rollsetpoint = (-chans.analogs[3] / 50.0) * 0.3;
			float pitchsetpoint = (-chans.analogs[2] / 50.0) * 0.3;
			heading += (chans.analogs[0] / 50.0) * (M_PI / 4) * .005;
			
			control.setControlPoints(throttle, rollsetpoint, pitchsetpoint, heading);
			if (!up) {
				if (throttle > 0.4)
					up = true;
				else
					control.clearIntegrals();
			}
			
			if (logging) {
				LogEntry entry = { sensors.getReadings(), imu.getState(), throttle };
				logger.write((uint8_t *)&entry, sizeof(entry));
			}
			
			IMU::State state = imu.getState();
			IMU::State velstate = imu.getVelocityState();
			out.printf("%f %f\n", control.getRollCorrection(), control.getPitchCorrection());
			Task::sleep(25);
		}
		
		control.stop();
		motors.off();
		out.print("Push enter\n");
		while (out.getch() != '\r') { }
		
		out.print("Press y to dump log");
		if (out.getch() == 'y') {
			out.print("\nLog dump:");
			LogReader reader(eeprom, 0);
			struct LogEntry entry;
			while (reader.read((uint8_t *)&entry, sizeof(entry)) == sizeof(entry)) {
				int i;
				for (i=0;i<6;i++) {
					out.printf("%.3f ", entry.analogs.array[i]);
				}
				out.printf("%.3f %.3f %.3f ", entry.state.roll, entry.state.pitch, entry.state.yaw);
				out.printf("%.3f\n", entry.throttle);
			}
		}
		docalibrate("Roll", &controlconfig.roll_config);
		docalibrate("Pitch", &controlconfig.pitch_config);
		docalibrate("Yaw", &controlconfig.yaw_config);
		
		out.printf("Current stick values: %f %f\n", controlconfig.rollpitch_stickfactor, controlconfig.yaw_stickfactor);
		out.printf("Stick: ");
		static char buf[50];
		out.getline(buf, sizeof(buf));
		sscanf(buf, "%f %f", &controlconfig.rollpitch_stickfactor, &controlconfig.yaw_stickfactor);
	}
}
Esempio n. 15
0
int main(int argc, char **argv) {	
	out.print("Hello World!\n");
}
Esempio n. 16
0
		void spiMaster() {
			// TXEPT is 1 after reset
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0TCTL(), 1));

			m->setByte(v->getP1SEL(), 0x31);
			m->setByte(v->getU0CTL(), 0); // UCSWRST
			// UCTL0 = CHAR + SYNC + MM + SWRST;
			m->setByte(v->getU0CTL(), 23);
			// UTCTL0 = SSEL1 + SSEL0 + STC;
			m->setByte(v->getU0TCTL(), 51);
			m->setByte(v->getUC0IE(), 255);
 			// ME1 |= USPIE0;                            // Enable USART0 SPI mode
 			// UCTL0 &= ~SWRST;                          // Initialize USART state machine
			m->setByte(v->getU0ME(), 255);
			m->setByte(v->getU0CTL(), 22);
			// Set BR
			m->setByte(v->getU0BR0(), 2);

			// nothing should happen until we send character
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
			usart->tickRising(); usart->tickFalling();
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
			// No transmission, TXEPT is 1
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0TCTL(), 1));

			// Set TX IFG just to test it gets cleared by write to TXBUF later
			m->setBit(v->getU0IFG(), 128, true);
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0IFG(), 128));

			// start transmitting - we will transfer 8 bits
			m->setByte(v->getU0TXBUF(), 55); // 00110111
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);

			// Write to TXBUF should clear TX IFG
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0IFG(), 128));
			// We are transmitting now, so TXEPT should be 0
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0TCTL(), 1));

			// Disable SWRST
			m->setBit(v->getU0CTL(), 1, false);

		/// BIT 1
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

			// prepare '1' to be captured
			pinManager->handlePinInput(0, 3.0);

			//  bit captured from SOMI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 2
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 3
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 3.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 4
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 5
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 3.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 6
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 7
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 3.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(false, intManager->hasQueuedInterrupts());

		/// BIT 8
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			CPPUNIT_ASSERT_EQUAL(true, intManager->hasQueuedInterrupts());
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0IFG(), 1 << 6));
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0IFG(), 1 << 7));

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

			// Transmission stopped, UCBUSY is 0 again
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0TCTL(), 1));

			// Check RX IFG flag now, because after reading the value, it should be cleared
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0IFG(), 1 << 6));
			CPPUNIT_ASSERT_EQUAL(170, (int) m->getByte(v->getU0RXBUF()));

		/// INTERRUPT
			// RX IFG is cleared by reading RX BUF
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0IFG(), 1 << 6));
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0IFG(), 1 << 7));
			CPPUNIT_ASSERT_EQUAL(true, intManager->hasQueuedInterrupts());
		}
Esempio n. 17
0
		void spiSlave() {
			m->setByte(v->getP1SEL(), 0x31);
			m->setByte(v->getUCA0CTL1(), 0); // UCSWRST
			// UCA0CTL0 |= UCSYNC+UCMSB;
			m->setByte(v->getUCA0CTL0(), 33);
			// UCA0CTL1 &= ~UCSWRST;
			m->setByte(v->getUCA0CTL1(), 0);
			// UCA0IE |= UCRXIE | UCTXIE;
			m->setByte(v->getUC0IE(), 255);

			m->setByte(v->getUCA0TXBUF(), 55); // 00110111

			// nothing should happen, because we are slave
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
			usart->tickRising();
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);

			// Transfer byte
			for (int i = 0; i < 8; ++i) {
				pinManager->handlePinInput(1, 3.0);
				pinManager->handlePinInput(2, 3.0);
				pinManager->handlePinInput(2, 0.0);
				CPPUNIT_ASSERT_EQUAL((bool)(55 & (1 << (7 - i))), (bool)watcher->sdo); break;
			}

/*
		/// BIT 2
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 3
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 3.0);

			// cnt--, bit captured from SDI
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 4
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 5
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 3.0);

			// cnt--, bit captured from SDI
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 6
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 7
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 3.0);

			// cnt--, bit captured from SDI
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(false, intManager->hasQueuedInterrupts());

		/// BIT 8
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			CPPUNIT_ASSERT_EQUAL(true, intManager->hasQueuedInterrupts());
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getUC0IFG(), 1));
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getUC0IFG(), 2));

			// cnt--, bit captured from SDI
			usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

			// Transmission stopped, UCBUSY is 0 again
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getUCA0STAT(), 1));

			// Check RX IFG flag now, because after reading the value, it should be cleared
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getUC0IFG(), 1));
			CPPUNIT_ASSERT_EQUAL(170, (int) m->getByte(v->getUCA0RXBUF()));

		/// INTERRUPT
			// RX IFG is cleared by reading RX BUF
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getUC0IFG(), 1));
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getUC0IFG(), 2));
			CPPUNIT_ASSERT_EQUAL(true, intManager->hasQueuedInterrupts());*/
		}
/* ----------------------------------------------------------------------------
 * セットアップ処理
 * ---------------------------------------------------------------------------- */
void setup() {
	
	// Watchdog タイマ停止
	MCUSR = 0;
	wdt_disable();
	
	// SPI 設定
	DDRB |= (1<<PORTB1);
	DDRB |= (1<<PORTB2);
	// Master 設定
	SPCR |= (1<<MSTR);
	// ClockDivide 000 = 1/4
	SPCR &= ~(1<<SPR1);
	SPCR &= ~(1<<SPR0);
	SPSR &= ~(1<<SPI2X);
	// MODE 0
	SPCR &= ~(1<<CPOL);
	SPCR &= ~(1<<CPHA);
	// MSB First
	SPCR &= ~(1<<DORD);
	// SPI Enable
	SPCR |= (1<<SPE);

	// LED ポート出力
	DDRC |= (1<<LED);
	
	PORTD = 0;
	
	Serial1.begin();
	i2c.begin();

	// リセット直後の時間待ち(1秒)
	for(int i = 0; i < 100; i++) {
		_delay_ms(10);
	}
	rtc.begin();
	
	// 74HC595
	DDRB |= (1<<HC595RCLK);
	PORTB &= ~(1<<HC595RCLK);

	// K155ID1
	DDRB |= (1<<K155ID1_A);
	DDRB |= (1<<K155ID1_B);
	DDRB |= (1<<K155ID1_C);
	DDRB |= (1<<K155ID1_D);

	// IN12 カンマ
	DDRE |= (1<<COMMA);

	// EEPROM 読み出し
	eeprom_busy_wait();
	displayDateIntervalValue = eeprom_read_word(&E_displayDateIntervalValue);
	eeprom_busy_wait();
	displayDateSecondsValue = eeprom_read_word(&E_displayDateSecondsValue);
	eeprom_busy_wait();
	userDataTimerValue = eeprom_read_word(&E_userDataTimerValue);
	eeprom_busy_wait();
	dispTimeFormat = eeprom_read_byte(&E_dispTimeFormat);
	eeprom_busy_wait();
	IN12BrightDaytime = eeprom_read_byte(&E_IN12BrightDaytime);
	eeprom_busy_wait();
	IN12BrightNight = eeprom_read_byte(&E_IN12BrightNight);
	eeprom_busy_wait();
	hourDaytime = eeprom_read_byte(&E_hourDaytime);
	eeprom_busy_wait();
	hourNight = eeprom_read_byte(&E_hourNight);
	eeprom_busy_wait();
	hour12_24format = eeprom_read_byte(&E_hour12_24format);

	// タイマー、カウンタ 0 初期化
	// Disbale interrupt
	TIMSK0 &= ~(1<<OCIE0B);
	TIMSK0 &= ~(1<<OCIE0A);
	TIMSK0 &= ~(1<<TOIE0);
	// 比較一致タイマ/カウンタ解除(CTC)動作
	TCCR0B &= ~(1<<WGM02);
	TCCR0A |= (1<<WGM01);
	TCCR0A &= ~(1<<WGM00);
	// clkI/O/64 (64分周)
	TCCR0B &= ~(1<<CS02);
	TCCR0B |= (1<<CS01);
	TCCR0B |= (1<<CS00);
	TCNT0 = 0;
	// 16MHz / 64 = 4us. 4us * 250 = 1.0ms
	OCR0A =  249;
	// set interrupt mask
	TIFR0 |= (1<<OCF0A);
	// Enable interrupt
	TIMSK0 |= (1<<OCIE0A);

	// Watchdog タイマ設定
	wdt_enable(WDTO_1S);
	
	// 割り込み処理を有効にする
	sei();
}
Esempio n. 19
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);
					}
			}
		}		
	}
}