コード例 #1
0
ファイル: usb_prop.c プロジェクト: supermk2/Deviation
/*******************************************************************************
* Function Name  : MASS_init
* Description    : Mass Storage init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void MASS_init()
{
  /* Update the serial number string descriptor with the data from the unique
  ID*/
  Get_SerialNum();

  pInformation->Current_Configuration = 0;

  /* Connect the device */
  PowerOn();

  /* Perform basic device initialization operations */
  USB_SIL_Init();

  bDeviceState = UNCONNECTED;
}
コード例 #2
0
ファイル: usb_prop.c プロジェクト: kuling729/USB_JKJ
/*******************************************************************************
* Function Name  : CustomHID_init.
* Description    : Custom HID init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void CustomHID_init(void)
{
  /* Update the serial number string descriptor with the data from the unique 
  ID*/
  Get_SerialNum();
    
  pInformation->Current_Configuration = 0;
  /* Connect the device */
  PowerOn();
  /* USB interrupts initialization */
  _SetISTR(0);               /* clear pending interrupts */
  wInterrupt_Mask = IMR_MSK;
  _SetCNTR(wInterrupt_Mask); /* set interrupts mask */

  bDeviceState = UNCONNECTED;
}
コード例 #3
0
ファイル: _usb_prop.c プロジェクト: norayn/serv_controller
// Инициализация USB-девайса
void SomeDev_init()
{
	// Получаем серийный номер
	Get_SerialNum();
	
	// Задаем текущую конфигурацию
	pInformation->Current_Configuration = 0;
	
	// Подключение 
	PowerOn();
	
	// Основные инициализации
	USB_SIL_Init();
	
	bDeviceState = UNCONNECTED;
}
コード例 #4
0
void CDialogWritePublishInfo::OnBtnWrite()
{
    //上电
    char ATR[100]= {0};
    int re=PowerOn(hDev,0x01,ATR);
    if(re!=0)
    {
        this->MessageBox("健康卡上电失败!");
        return;
    }
    CHealthCardReaderDlg *dlg=(CHealthCardReaderDlg*)pDlg;
    CString KLB;          //卡类别代码
    CString  GFBB;            //规范版本
    CString  FKJGMC;          //发卡机构名称
    CString  FKJGDM;          //发卡机构代码
    CString  FKJGZS;			//发卡机构证书
    CString  FKSJ;          //发卡时间,YYYYMMDD格式
    CString  KH;            //卡号,与居民身份证号或者证件号码一致
    CString  AQM;             //安全码
    CString  XPXLH;           //芯片序列号
    CString  YYCSDM;          //应用城市代码
    this->GetDlgItemText(IDC_EDIT_KLB,KLB);
    this->GetDlgItemText(IDC_EDIT_GFBB,GFBB);
    this->GetDlgItemText(IDC_EDIT_FKJGMC,FKJGMC);
    this->GetDlgItemText(IDC_EDIT_FKJGDM,FKJGDM);
    this->GetDlgItemText(IDC_EDIT_FKJGZS,FKJGZS);
    this->GetDlgItemText(IDC_EDIT_FKSJ,FKSJ);
    this->GetDlgItemText(IDC_EDIT_KH,KH);
    this->GetDlgItemText(IDC_EDIT_AQM,AQM);
    this->GetDlgItemText(IDC_EDIT_XPXLH,XPXLH);
    this->GetDlgItemText(IDC_EDIT_YYCSDM,YYCSDM);
    re=iW_DDF1EF05Info(hDev,KLB.GetBuffer(0),GFBB.GetBuffer(0),FKJGMC.GetBuffer(0),FKJGDM.GetBuffer(0),FKJGZS.GetBuffer(0),FKSJ.GetBuffer(0),KH.GetBuffer(0),AQM.GetBuffer(0),XPXLH.GetBuffer(0),YYCSDM.GetBuffer(0));
    if(re!=0)
    {
        CString temp;
        temp.Format("写入失败,错误代码:%d\r\n",re);
        dlg->UpdateData();
        dlg->m_sData=temp;
        dlg->UpdateData(FALSE);
        CDialog::OnOK();
        return;
    }
    dlg->UpdateData();
    dlg->m_sData="写入成功\r\n";
    dlg->UpdateData(FALSE);
    CDialog::OnOK();
}
コード例 #5
0
ファイル: usb_prop.c プロジェクト: ozwin/desenet
/*******************************************************************************
* Function Name  : Virtual_Com_Port_init.
* Description    : Virtual COM Port Mouse init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Virtual_Com_Port_Init(void)
{
  pInformation->Current_Configuration = 0;
  /* Connect the device */
  PowerOn();
  /* USB interrupts initialization */
  /* clear pending interrupts */
  _SetISTR(0);
  wInterrupt_Mask = IMR_MSK;
  /* set interrupts mask */
  _SetCNTR(wInterrupt_Mask);
  pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];
  LineCoding_Reset();
  /* Wait until device is configured */
  while (((volatile DEVICE_INFO*) pInformation)->Current_Configuration == 0);	// WARNING
  bDeviceState = CONFIGURED;
}
コード例 #6
0
ファイル: main.c プロジェクト: BulbLi/crazepony-firmware-none
/********************************************
              飞控主函数入口
功能:
1.初始化各个硬件
2.初始化系统参数
3.开定时器4等待数据中断到来
4.开定时器3串口广播实时姿态以及相关信息
********************************************/
int main(void)
{
    SystemClock(9);               //系统时钟初始化
    UART1_init(SysClock,115200); 	//串口1初始化
    NVIC_INIT();	                //中断初始化
    STMFLASH_Unlock();            //内部flash解锁
    LedInit();		                //IO初始化 
    delay_init(SysClock);         //滴答延时初始化
    BT_PowerInit();               //蓝牙电源初始化完成,默认关闭
    MotorInit();	                //马达初始化
    BatteryCheckInit();           //电池电压监测初始化
    IIC_Init();                   //IIC初始化
    MPU6050_DMP_Initialize();     //初始化DMP引擎
    PID_INIT();                   //PID参数初始化 
    ParameterRead();              //Flash参数读取
    NRF24L01_INIT();              //NRF24L01初始化
    SetRX_Mode();                 //设无线模块为接收模式
    PowerOn();                    //开机等待
    BT_on();                      //蓝牙开
    TIM3_Init(36,2000);	          //定时器3初始化,调试串口输出
    TIM4_Init(36,1000);	          //定时器4初始化,定时采样传感器数据,更新PID输出
    while (1)                     //等待数据更新中断到来
    {

      
//    switch(UART1_Get_Char())//检测串口发送数据,做相应处理
//       {
//         case 'w':
//                  LedA_on;LedB_on;LedC_on;LedD_on;
//                  //TxBuf[0]++;
//                  //UART1_Put_Package(TxBuf);
//                   LedA_on;LedB_on;LedC_on;LedD_on;
//                   MotoPWM+=10;
//                   UART1_Put_Char(0x5a);
//                  break;
//         case 's':
//                  LedA_off;LedB_off;LedC_off;LedD_off;
//                  UART1_Put_Char(0xaa);
//                  MotoPWM-=10;
//                  break;
//         default :break;
//       } 
//        MotorPwmFlash(MotoPWM,MotoPWM,MotoPWM,MotoPWM);    
//       
    }
}
コード例 #7
0
ファイル: usb_prop.c プロジェクト: vortex314/projects
/*******************************************************************************
 * Function Name  : Virtual_Com_Port_init.
 * Description    : Virtual COM Port Mouse init routine.
 * Input          : None.
 * Output         : None.
 * Return         : None.
 *******************************************************************************/
void Virtual_Com_Port_init(void) {

	/* Update the serial number string descriptor with the data from the unique
	 ID*/
	Get_SerialNum();

	pInformation->Current_Configuration = 0;

	/* Connect the device */
	PowerOn();

	/* Perform basic device initialization operations */
	USB_SIL_Init();

	/* configure the USART to the default settings */
	//USART_Config_Default();
	bDeviceState = UNCONNECTED;
}
コード例 #8
0
ファイル: usb_prop.c プロジェクト: WillJason/cortex-M-Serise
/*******************************************************************************
* Function Name  : Joystick_init.
* Description    : Joystick Mouse init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Joystick_init(void)
{
  pInformation->Current_Configuration = 0;
  /* Connect the device */
  PowerOn();
  /* USB interrupts initialization */
  _SetISTR(0);               /* clear pending interrupts */
  wInterrupt_Mask = IMR_MSK;
  _SetCNTR(wInterrupt_Mask); /* set interrupts mask */
  pInformation->Current_Feature = Joystick_ConfigDescriptor[7];
  /* Wait until device is configured */
  while (pInformation->Current_Configuration == 0)
  {
    NOP_Process();
  }

  bDeviceState = CONFIGURED;
}
コード例 #9
0
ファイル: System.cpp プロジェクト: Banbury/starshatter-open
void
System::DoEMCON(int index)
{
    int e = GetEMCONPower(index);

    if (power_level * 100 > e || emcon != index) {
        if (e == 0) {
            PowerOff();
        }
        else {
            if (emcon != index)
            PowerOn();

            SetPowerLevel(e);
        }
    }

    emcon = index;
}
コード例 #10
0
boolean ModemGSM::Initialize(HardwareSerial *pSerial, byte pNetworkLedPin, byte pPowerOnPin)
{
	pinMode(pNetworkLedPin, OUTPUT);
	pinMode(pPowerOnPin, OUTPUT);

	FSerial = pSerial;
	FNetworkLedPin = pNetworkLedPin;
	FPowerOnPin = pPowerOnPin;

	FLastKeepAliveTS.Set(KEEPALIVE_INTERVAL_MS);
	FLastBlinkTS.Set(NETWORK_LED_UPDATE_INTERVAL_MS);
#ifdef REGISTRATION_DELAYED
	FNetworkRegDelayTS.Set(NETWORK_REGISTRAION_DELAY_MS);
#endif
	FSMSResendTS.Set(SMS_RETRY_DELAY_MS);

	PowerOn();

	return InnerSetup();
}
コード例 #11
0
ファイル: usb_prop.c プロジェクト: tianxq/fly_controller
/*******************************************************************************
* Function Name  : DFU_init.
* Description    : DFU init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DFU_init(void)
{
  DEVICE_INFO *pInfo = &Device_Info;

  /* Update the serial number string descriptor with the data from the unique ID*/
  Get_SerialNum();

  pInfo->Current_Configuration = 0;

  /* Connect the device */
  PowerOn();

  /* Perform basic device initialization operations */
  USB_SIL_Init();

  /* Enable USB interrupts */
  USB_Interrupts_Config();

  bDeviceState = UNCONNECTED;
}
コード例 #12
0
ファイル: main.c プロジェクト: ytai/PixieGuitar
int main(int argc, char** argv) {
  PowerOn();

  ClockInit();

  ANSELA = 0;
  ANSELB = 0;
  SPLIM = 0xFFFF;  // TODO: implement proper handling of SPLIM.

  ModuleInit();
  I2cInit();
  ShellTaskInit();

  App * first = MainMenuAppInit(&main_menu_app);
  // Comment out the next line to skip splash.
  first = SplashAppInit(&splash_app, first);

  AppTaskInit(first);

  vTaskStartScheduler();
}
コード例 #13
0
ファイル: usb_prop.c プロジェクト: mambrus/bitfire
/*******************************************************************************
* Function Name  : DFU_init
* Description    :
* Input          :None
* Output         :None
* Return         :None
*******************************************************************************/
void DFU_init(void)
{
 DEVICE_INFO *pInfo = &Device_Info;

	pInfo->Current_Configuration = 0;
        pInfo->Current_Feature = DFU_ConfigDescriptor[7];

	/* Connect the device */
	PowerOn();
        /* USB interrupts initialization */
        _SetISTR(0);               /* clear pending interrupts */
        wInterrupt_Mask = IMR_MSK;
        _SetCNTR(wInterrupt_Mask); /* set interrupts mask */

        /* Enable USB interrupts */
        USB_Interrupts_Config();

        /* Wait until device is configured */
	while (pInfo->Current_Configuration == 0) NOP_Process();


	bDeviceState = CONFIGURED;
} /* DFU_init() */
コード例 #14
0
void ProcessPacket( const char *in, char *out )
{
    /* Assume valid packet */
    strcpy( out, "K" );

    if( strncmp( in, "WG", 2 ) == 0 )
    {
        /* Ping request I think, no action needed.
         * Characters 3+ are ascii digits for some parameter.
         */
    }
    else if( strcmp( in, "RE" ) == 0 )
    {
        /* Reset? */
        verbose_printf( "Reset request received.\n" );
        PowerOn();
    }
    else if( strcmp( in, "CL" ) == 0 )
    {
        /* Clear? */
        verbose_printf( "Clear request received.\n" );
        PowerOn();
    }
    else if( strncmp( in, "KL", 2 ) == 0 )
    {
        /* Unknown packet, Characters 3+ are ascii digits. */
    }
    else if( strncmp( in, "VM", 2 ) == 0 )
    {
        /* Unknown packet, Characters 3+ are ascii digits.
         * Observed values are '0' before loading chapter,
         * '1' after loading chapter when playback should
         * start.
         */
    }
    else if( strncmp( in, "RP", 2 ) == 0 )
    {
        /* Repeat count */
        int rpCnt = atoi( &in[2] );
        verbose_printf( "Repeat request for %d times received.\n", rpCnt );

        /* TODO: Implement multiple repeats */
    }
    else if( strcmp( in, "PL" ) == 0 )
    {
        /* Play */
        verbose_printf( "Play request received.\n" );
        Play();
    }
    else if( strcmp( in, "PU" ) == 0 )
    {
        /* Play */
        verbose_printf( "Pause request received.\n" );
        Pause();
    }
    else if( strncmp( in, "CS", 2 ) == 0 )
    {
        /* Chapter select */
        int title = 0;
        int chapter = 0;
        sscanf( &in[2], "%d,%d", &title, &chapter );
        verbose_printf( "Chapter select request for title %d, chapter %d.\n", title, chapter );

        /* TODO: Something with titles? */
        SeekToChapter( chapter );
    }
    else
    {
        /* Unknown packet? */
        verbose_printf( "Unknown packet '%s' received!", in );
        strcpy( out, "E" );
    }
}
コード例 #15
0
ファイル: dwhcidevice.cpp プロジェクト: aniket-deole/circle
boolean CDWHCIDevice::Initialize (void)
{
	DataMemBarrier ();

	assert (m_pInterruptSystem != 0);
	assert (m_pTimer != 0);

	CDWHCIRegister VendorId (DWHCI_CORE_VENDOR_ID);
	if (VendorId.Read () != 0x4F54280A)
	{
		CLogger::Get ()->Write (FromDWHCI, LogError, "Unknown vendor 0x%0X", VendorId.Get ());
		return FALSE;
	}

	if (!PowerOn ())
	{
		CLogger::Get ()->Write (FromDWHCI, LogError, "Cannot power on");
		return FALSE;
	}
	
	// Disable all interrupts
	CDWHCIRegister AHBConfig (DWHCI_CORE_AHB_CFG);
	AHBConfig.Read ();
	AHBConfig.And (~DWHCI_CORE_AHB_CFG_GLOBALINT_MASK);
	AHBConfig.Write ();
	
	assert (m_pInterruptSystem != 0);
	m_pInterruptSystem->ConnectIRQ (ARM_IRQ_USB, InterruptStub, this);

	if (!InitCore ())
	{
		CLogger::Get ()->Write (FromDWHCI, LogError, "Cannot initialize core");
		return FALSE;
	}
	
	EnableGlobalInterrupts ();
	
	if (!InitHost ())
	{
		CLogger::Get ()->Write (FromDWHCI, LogError, "Cannot initialize host");
		return FALSE;
	}

	// The following calls will fail if there is no device or no supported device connected
	// to root port. This is not an error because the system may run without an USB device.

	if (!EnableRootPort ())
	{
		CLogger::Get ()->Write (FromDWHCI, LogWarning, "No device connected to root port");
		return TRUE;
	}

	if (!m_RootPort.Initialize ())
	{
		CLogger::Get ()->Write (FromDWHCI, LogWarning, "Cannot initialize root port");
		return TRUE;
	}
	
	DataMemBarrier ();

	return TRUE;
}
コード例 #16
0
ファイル: irman.cpp プロジェクト: mikemakuch/muzikbrowzer
BOOL Irman::Open( ) {
    if (ready())
        return TRUE;

    if (!m_sComPort.GetLength()) {
        return false;
    }
    const TCHAR * error = _T( "Error opening device" );

    CSerialMFC::EPort e = CSerialMFC::CheckPort(m_sComPort);
    if (e != CSerialMFC::EPortAvailable) {
        CString msg;
        msg << m_sComPort << " " << m_serial.EPortError(e);
        MBMessageBox("serial i/o error", msg);
        return false;
    }

    LONG o = m_serial.Open(m_sComPort, m_wndMsgHndlr, m_wmsg);
    if (o != ERROR_SUCCESS) {
        CString msg;
        msg << "unable to open " << m_sComPort << " error ["
            << o << "] " << MBFormatError(o);
        MBMessageBox("serial i/o error", msg);
        return false;
    }

    o = m_serial.Setup(CSerial::EBaud9600,CSerial::EData8,
                       CSerial::EParNone,CSerial::EStop1);
    if (o != ERROR_SUCCESS) {
        CString msg;
        msg << "unable to Setup " << m_sComPort << " error ["
            << o << "] " << MBFormatError(o);
        MBMessageBox("serial i/o error", msg);
        return false;
    }

    o = m_serial.SetupHandshaking(CSerial::EHandshakeOff);
    if (o != ERROR_SUCCESS) {
        CString msg;
        msg << "unable to Setup HandshakeOff " << m_sComPort << " error ["
            << o << "] " << MBFormatError(o);
        MBMessageBox("serial i/o error", msg);
        return false;
    }
    o = m_serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);
    if (o != ERROR_SUCCESS) {
        CString msg;
        msg << "unable to Setup TimeoutNonblocking" << m_sComPort << " error ["
            << o << "] " << MBFormatError(o);
        MBMessageBox("serial i/o error", msg);
        return false;
    }

    if (PowerOff( ) == FALSE)
        return FALSE;
    Sleep( 200 );
    if (PowerOn( ) == FALSE)
        return FALSE;

    Sleep( 100 );	// Time for the output to settle
    Flush( );		// Remove power up garbage

    m_serial.Write("I"); // These strings must be ASCII, not Unicode
    Sleep( 2 );			 // Need to have >500us between the 'I' & the 'R'
    m_serial.Write("R");
    m_OKreceived = 0;

    // Need to check that we receive "OK" back from Irman

    return RemoteReceiver::Open();
}
コード例 #17
0
ファイル: main.c プロジェクト: PolyakovV/Unit213
int32_t main()
{

/***************************************************************************
*       ClkInit()
****************************************************************************/
	ClkInit();

/***************************************************************************
*       GPIOInit();
****************************************************************************/
//	DrvGPIO_InitFunction(E_FUNC_GPIO);
	outpw(&SYS->P0_MFP, 0);
	outpw(&SYS->P1_MFP, 0);
	outpw(&SYS->P2_MFP, 0);
	outpw(&SYS->P3_MFP, 0);
	outpw(&SYS->P4_MFP, 0);

	_GPIO_SET_PIN_MODE(MODEM_ON_PORT, MODEM_ON_PIN, GPIO_PMD_OUTPUT);
	ModuleOn(TRUE);

	_GPIO_SET_PIN_MODE(MODEM_POWER_PORT, MODEM_POWER_PIN, GPIO_PMD_OUTPUT);
	ModulePowerOn(FALSE);

	_GPIO_SET_PIN_MODE(LOCK_POWER_PORT, LOCK_POWER_PIN, GPIO_PMD_OUTPUT);
	LockPower(FALSE);

	_GPIO_SET_PIN_MODE(KEY_HELP_PORT, KEY_HELP_PIN, GPIO_PMD_QUASI);
	_GPIO_SET_PIN_MODE(KEY_BAT_PORT, KEY_BAT_PIN, GPIO_PMD_QUASI);

	_GPIO_SET_PIN_MODE(SLEEP_PORT, SLEEP_PIN, GPIO_PMD_OUTPUT);
	ModemSleep(FALSE);

	_GPIO_SET_PIN_MODE(LED_PORT, LED_PIN, GPIO_PMD_OUTPUT);
	
	LedDark();
	
	_GPIO_SET_PIN_MODE(INT_PORT, INT_PIN, GPIO_PMD_INPUT);

/***************************************************************************
*       TimerInit();
****************************************************************************/
	SysTick_Config(SYS_TICK);
//	SYS_LockReg();

/***************************************************************************
*       UartInit();
****************************************************************************/
	UartInit();
//	debug(VERSION);
//	DrvSYS_GetPLLClockFreq();

/***************************************************************************
*       WatchdogInit();
****************************************************************************/	
	WatchdogInit();

//	udpTest();
	NvInit();



 	WhatToDo();
	AdcInit();
	
	
	
	WaitLockPower();

  LockPower(!custermParam.param.lockState);


	InitMsgDebug();	
	
	if( Communication(10) == FALSE )
		SoftReset();

	if( isCheckingBattery )
	{
		delay_50ms(40);
		MeasurePower(4);
	}
	else
	{
		MeasurePower(2);
	}
					
	Flag_ModuleOn = TRUE;
	//Flag_ModuleOn = TRUE;
	ModemVolumeInit();

	///--------------------24.11.2015----------------------------------------------
	////////////////////////////////////////////////////////////////////////////////////////
while(PressHelp()&&(tmp_my<200)&&(PressBatter())){
	tmp_my++;
		
	delay_50ms(1);
if (tmp_my>=150) {
	  LedLight(144);
	    if (custermParam.param.lockState) {
														LockPower(TRUE);
														custermParam.param.lockState = FALSE;
												    WriteToNv( &custermParam ); //- save to eeprom
  													PlayVoice("\"unitUnlock.wav\",2\r");
														delay_ms(2000);
			                      LockPower(FALSE);
			
			} else {
	                          //  debug("ins");
															while(PressBatter()){};
														 tmp_my=0;
												while (tmp_my<25){               
																											tmp_my++;
																											delay_ms(150);
																											if (PressBatter()){counterPress++;
																																				while(!PressBatter()){};
																																					}
																										  if (counterPress>2){ 
																																					PlayVoice("\"unitLock.wav\",2\r");
																																					delay_ms(2000);
																																					custermParam.param.lockState = TRUE;
																																					WriteToNv( &custermParam ); //- save to eeprom
																																		      tmp_my=0;
																																					delay_ms(2000);
																																					LockPower(DISABLE);

																																				}
																											}
													LedBlink();
										} 
					///////				
			tmp_my=0;
			}

}

while(custermParam.param.lockState){}
 
///////////////////////////////////////////////////////////////////////////////////////////////													
#ifdef DELAY_TEST
	DelayTest();
#endif
	PowerOn();
	
	

	
	if(state==STATE_POWERING_DOWN || Flag_Power_Down)
	{
		Flag_Power_Down = FALSE;
		EnterPowerDown();
		while( TimerWait )
			FeedWatchdog();
		PowerDown();
		//不会返回
	}
	
	InitVariables();
	  
	if(state == STATE_NULL)
	{
		state = STATE_1ST_CALL;
		TimerWait = 100;	// 5 s
	}
	
	TimerTestMode = 6000;
	//debug("ent main loop");
	while(1)
	{  
			
		///--------------------
				if (!TimerTestMode && state==STATE_TEST)
										{ 
										PlayMusic(MUSIC_PD);
										EnterPowerDown();
										}
		
		///--------------------
		
		if( Flag_Incomming )
		{
	#if 1
			TimerWait = 200;
			Flag_Incomming = FALSE;
			TimerStandby = custermParam.param.delay;
			//if(state != STATE_ACTIVE)
			{
				ModemSleep(FALSE);
				state = STATE_INCOMMING;
			}
	#else
			Flag_Incomming = FALSE;
			if(state != STATE_INCOMMING)
			{
				state = STATE_INCOMMING;
				ModemSleep(FALSE);
				EnterAnswer();
			}
	#endif
		}
		
		if(TimerWait == 0)
		{
			switch(state)
			{
									
			case STATE_POWERING_DOWN:
				PowerDown();
				break;

			case STATE_1ST_CALL:
				RegisterWait();
				break;

			case STATE_REGISTER_OK:	
				GetCpsiInfo();
				if( Flag_ObtainCpsi==TRUE)
				{
					state = STATE_GSM_STEADY;
					if( Flag_SimExist )
					{
						//delay_50ms(200);
						SockOpen();
						TimerWait = 400;
					}
					else
					{
						TimerWait = 60;
					}
				}
				else
				{
					TimerWait = 70;
				}
				break;

			case STATE_GSM_STEADY:	
				if( gPhoneNumOk==PHONE_NUM_READY || Flag_SimExist==FALSE)
					EnterCall();
				else
					TimerWait = 40;
				break;
				
			case STATE_CALL_PROMPT:
				Call();
				break;

			case STATE_ALERT:
				EnterCallFail();
				break;
			
			case STATE_NEXT_CALL:
				Redial();
				break;				

			case STATE_BATT_DISPLAY:
				EnterPowerDown();
				break;

			case STATE_INCOMMING:
				TimerStandby = custermParam.param.delay;
				EnterStandby();
				break;
			}
		}

		if( TimerSock==0 && Flag_SimExist
			&& ( (state>=STATE_GSM_STEADY && state<STATE_STANDBY) || progress>=TEST_GPS ) )
		{
			switch(sockState)
			{
			//case SOCKSTATE_NULL:
			case SOCKSTATE_CONFIG:				
			case SOCKSTATE_OPENNING:
				SockOpen();	// 打开失败,从新打开
				break;

			case SOCKSTATE_OPENED:
				SendAtWaitRsq(50, 1, FALSE, "AT+CIPOPEN=0,\"UDP\",,,%s\r\n", custermParam.param.local_port);
				TimerSock = 80;
				break;
	#if 0
			case SOCKSTATE_CONNECTING:
				SockConnect();	// 连接失败,从新连接
				break;
	#endif
			case SOCKSTATE_CONNECT_OK:		
				if( witchApn == 1)
					ClientInit();
				break;

			default:
				break;
			}
		}

		KeyHandle();

		SecondHandle();
		//SignalCheck();
		BatterCheck();
		PowerDownHandle();
		MsgHandle();
											
		if( Flag_SimExist )
		{
			UdpHandle();
			SmsHandle();
			PowerDownHandle();
		}
		
		FeedWatchdog();
	}
}	
コード例 #18
0
ファイル: rotorstate.c プロジェクト: thjm/RotorControl
/** The state machine of the rotor control engine ...
 *
 * This is the transition diagram after the command kRotateCW has been issued:
 *
 * kRotateCW -> kIdle
 *                |
 *                | ==> PowerOn()
 *               \/
 *              kReleaseBrake
 *                |
 *       kStop -> | -------- >>> -------+
 *                | ==> ReleaseBrake()  |
 *                |                     |
 *               \/                     |
 *              kRotorRampup            |
 *                |                     |
 *       kStop -> | -------- >>> -------|--+
 *                | ==> RotateCW()      |  |
 *                |                     |  |
 *               \/                     |  |
 *              kTurningCW              |  |
 *                |                     |  |
 *                * <-------------------+  |
 *       kStop -> |                        |
 *                | ==> RotorOff()         |
 *                |                        |
 *               \/                        |
 *              kLockBrake                 |
 *                |                        |
 *                * <----------------------+
 *                |
 *                | ==> LockBrake()
 *                |
 *               \/
 *              kRotorRampdown
 *                |
 *                | ==> PowerOff()
 *                |
 *               \/
 *              kIdle
 *
 * It will be handled in a similar way for the command kRotateCCW.
 *
 * As the trasitions will take some time, it is not unlikely, that the kStop 
 * event is issued before the state kTurningCW is reached. In that case the 
 * rotor relays etc. must be switched off in a proper order.
 */
void RotatorExec(void) {

  switch ( gRotatorCommand ) {
  
    case kStop:
         
	 SetBusy(1);
	 
	 switch ( gRotatorState ) {
	 
	   case kReleaseBrake: // ???
	   case kTurningCW:
	   case kTurningCCW:
	        RotatorOff();
		gRotatorBusyCounter = 5;
		gRotatorState = kLockBrake;
	        break;

	   case kRotorRampup: // ???
	   case kLockBrake:
	        BrakeLock();
		gRotatorBusyCounter = 5;
		gRotatorState = kRotorRampdown;
	        break;

	   case kRotorRampdown:
		PowerOff();
	        gRotatorState = kIdle;
		gRotatorBusyCounter = 10;
	        break;

	   case kIdle:
		gRotatorCommand = kNone;
		SetBusy(0);
	        break;
	 }

         break;

    case kTurnCW:
         
	 SetBusy(1);
	 
	 switch ( gRotatorState ) {
	 
	   case kIdle: 
	        PowerOn();
		gRotatorState = kReleaseBrake;
		gRotatorBusyCounter = 10;
		break;
	 
	   case kReleaseBrake:
	        BrakeRelease();
		gRotatorState = kRotorRampup;
		gRotatorBusyCounter = 5;
		break;
	 
	   case kRotorRampup: 
		gRotatorState = kTurningCW;
         	RotatorCW();
		gRotatorBusyCounter = 5;
		break;
	   
	   case kTurningCW:
		gRotatorState = kTurningCW;
	        gRotatorCommand = kNone;
		break;
	 }
	
         break;

    case kTurnCCW:
         
	 SetBusy(1);
	 
	 switch ( gRotatorState ) {
	 
	   case kIdle: 
	        PowerOn();
		gRotatorState = kReleaseBrake;
		gRotatorBusyCounter = 10;
		break;
	 
	   case kReleaseBrake:
	        BrakeRelease();
		gRotatorState = kRotorRampup;
		gRotatorBusyCounter = 5;
		break;
	 
	   case kRotorRampup: 
		gRotatorState = kTurningCCW;
         	RotatorCCW();
		gRotatorBusyCounter = 5;
		break;
	   
	   case kTurningCCW:
		gRotatorState = kTurningCCW;
	        gRotatorCommand = kNone;
		break;
	 }

         break;

    case kFastStop:
         RotatorOff();
         BrakeLock();
	 PowerOff();
	 
	 // reset state machine and command variable
	 gRotatorState = kIdle;
	 gRotatorCommand = kNone;
         
         // both PRESET LEDs off
         LED_PORT &= ~(LED_LEFT | LED_RIGHT);
	 
	 SetBusy(0);
      
         // clear preset data
         gPresetHeading = gCurrentHeading;
	 gPresetCounter = 0;
	 gPresetCommand = kPresetNone;
         break;

    default:
         break;
  }
}
コード例 #19
0
//---------------------------------------------------------
//---------------------------------------------------------
void CNPC_Roller::StartTask( const Task_t *pTask )
{
	switch( pTask->iTask )
	{
	case TASK_ROLLER_ON:
		PowerOn();
		TaskComplete();
		break;

	case TASK_ROLLER_OFF:
		PowerOff();
		TaskComplete();
		break;

	case TASK_ROLLER_WAIT_FOR_PHYSICS:
		// Stop rolling.
		m_flWaitFinished = gpGlobals->curtime;
		m_RollerController.m_vecAngular = vec3_origin;
		PowerOff();
		break;

	case TASK_ROLLER_FIND_PATROL_NODE:

		m_pHintNode = CAI_Hint::FindHint( this, HINT_ROLLER_PATROL_POINT, 0, 1024 ); 

		if(!m_pHintNode)
		{
			TaskFail("Couldn't find roller patrol node");
		}
		else
		{
			TaskComplete();
		}
		break;

	case TASK_ROLLER_UNSTICK:
		Unstick();

		if( m_vecUnstickDirection == vec3_origin )
		{
			TaskComplete();
		}
		else
		{
			VPhysicsGetObject()->Wake();
			PowerOn();
			
			// Cut back on the fail count, but not all the way.
			// Only a successful opportunity move sets this to 0.
			m_iFail /= 2;

			m_flWaitFinished = gpGlobals->curtime + 2;
		}

		break;

	case TASK_WALK_PATH:
	case TASK_RUN_PATH:
		// Make sure the controller isn't turned off.
		m_iFail = 0; // Successfully starting to move.
		VPhysicsGetObject()->Wake();
		PowerOn();
		break;

	case TASK_ROLLER_ISSUE_CODE:
		m_iCodeProgress = 0;
		m_flWaitFinished = gpGlobals->curtime;
		break;

	default:
		BaseClass::StartTask( pTask );
		break;
	}
}