Exemplo n.º 1
0
/*
Service call when we want information
*/
bool getInfo(supervisor_msgs::GetInfo::Request  &req, supervisor_msgs::GetInfo::Response &res){

    if(req.info == "ALL_FACTS"){
        res.facts = ms->db_.getFactsAgent(req.agent);
    }else if(req.info == "FACTS_IN"){
        res.answer = ms->db_.factsAreIn(req.agent, req.facts);
    }else if(req.info == "AGENTS"){
        res.agents =  ms->db_.getAgents();
    }else if(req.info == "ACTIONS_TODO"){
        pair<supervisor_msgs::Action, string> answer = getActionTodo(req.agent, req.actor);
        res.action = answer.first;
        res.state = answer.second;
    }else if(req.info == "ACTION_STATE"){
        res.state = getActionState(req.agent, req.action);
    }else if(req.info == "ACTIONS"){
        res.actions = ms->getActionList();
    }

    return true; 

}
Exemplo n.º 2
0
void __fastcall TKeyControlForm::LineTimerTimer( TObject */*Sender*/ )
{
   syncSetLines();
   bool PTT = getPTT();
   if ( recordWait && PTT )
   {
      recind->Caption = "Release PTT to stop Recording";
      recordWait = false;
      recording = true;
   }
   else
      if ( recording && !PTT )
      {
         recind->Caption = "";
         recordWait = false;
         recording = false;
      }
	KeyerServer::publishCommand( recind->Caption.t_str() );
   eMixerSets m = GetCurrentMixerSet();

   std::string astate;
   getActionState( astate );

   // This isn't quite what we want - needs to be better english and slower changing

   std::string kstatus;
   if ( getKeyerStatus( kstatus ) )
      Caption = String( msets[ m ] ) + " : " + astate.c_str() + " : " + kstatus.c_str();
   else
      Caption = String( msets[ m ] ) + " : " + astate.c_str();

   static String old;

   if ( Caption != old )
   {
      old = Caption;
      CaptionTimer->Enabled = true;
   }

}
Exemplo n.º 3
0
void WeatherStation::run()
{
    uint8_t dataType;
    int16_t data;
    boolean ret;

    /*event*/

    if (g_RTCIntFlag)  //it must be at the front of      processRTCAlarm()
    {
        g_RTCIntFlag = false;
        RTCObj.clearINTStatus();
    }

    if ( EVENT_STATE_SET == eventRTCState )
    {
        processRTCAlarm();
        eventRTCState = EVENT_STATE_DOING;
    }

    if ( EVENT_STATE_SET == eventButtonState )
    {
        processButton();
        eventButtonState = EVENT_STATE_DOING;
    }


    if ( SYS_STATE_WAITING == systemState )
    {
        if ( STATE_DOING == getActionState())  //high priority
        {
            systemState = SYS_STATE_ACTION;
        }
        else if ( (uint8_t)((millis()/1000) - startTime) >= overTime )
        {
            systemState = SYS_STATE_GOTOSLEEP;

            DBG_PRINTLN("goto sleep");

            /**to minimize the time to sleep state, so there is not sleep state case **/
            if ( (SW_RUN == digitalRead(PALETTE_PIN_SW)) && (SW_MAKE == switchState) )
            {
#if !_DEBUG
                dettachUSB();
#endif
                switchState = SW_RUN;
            }


            disableBeforeSleep();

            wakeFlag = false;

            sleep();

            enableAfterSleep();
            systemState = SYS_STATE_WAITING;

            DBG_PRINTLN_VAR(systemState,DEC);

        }
        else
        {
            //nothing
        }
    }
    else if ( SYS_STATE_ACTION == systemState )
    {

        /*action*/

        if ( STATE_DOING == a_actionList[ACTION_SAMPLE_DATA].state )
        {
            DBG_PRINTLN("**Sample");
            ret = sensorMgt.run();

            if ( ret )
            {
                a_actionList[ACTION_SAMPLE_DATA].state = STATE_DONE;
            }
            else
            {
                delay(10);
            }
        }

        if ( STATE_DOING == a_actionList[ACTION_SAVE_DATA].state )
        {
            if ( STATE_DONE == a_actionList[ACTION_SAMPLE_DATA].state )
            {
                DBG_PRINTLN("**Save");
                for ( uint8_t i = 0; i < DATA_TYPE_MAXNUM; i++ )
                {
                    if ( false == a_measureData[i].valid )
                    {
                        break;
                    }

                    dataType = a_measureData[i].dataType;
                    data = a_measureData[i].p_sensor->getValue( dataType );

                    dataHouse.putData( data, dataType, currentHour );
                }

                a_actionList[ACTION_SAVE_DATA].state = STATE_DONE;

            }

        }

        if ( STATE_DOING == a_actionList[ACTION_DISPLAY].state )
        {
            if (STATE_DONE == a_actionList[ACTION_SAMPLE_DATA].state)
            {
                displayMgt.state = DISPLAY_STATE_NEXT;
            }

            if ( DISPLAY_STATE_NEXT == displayMgt.state )
            {
                DBG_PRINTLN("**Display");

                displayNext();

                a_actionList[ACTION_DISPLAY].state = STATE_DONE;
            }

        }


        if ( STATE_DONE == getActionState() )
        {
            startTime = millis()/1000;

            if( (END_HOURTIME_ONEDAY == currentHour) && (EVENT_STATE_DOING == eventRTCState) )
            {   //todo:  muti thread
                DBG_PRINTLN_VAR(currentHour,DEC);
                dataHouse.updateDate( currentYear, currentMonth, currentDate );
            }

            eventRTCState = EVENT_STATE_DONE;
            eventButtonState = EVENT_STATE_DONE;

            for ( uint8_t i = 0; i < ACTION_NUMBER; i++ )  //todo
            {
                a_actionList[i].state = STATE_INIT;
            }

            systemState = SYS_STATE_WAITING;

            DBG_PRINTLN_VAR(systemState,DEC);

        }

    }



#if 0
DateTime now = RTCObj.now();
Serial.println(now.minute(), DEC);
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println(' ');
Serial.println(RTCObj.getTemperature());


#endif

}
Exemplo n.º 4
0
void YYEnemy::processAI(){
    if(targetSprite){
        //攻击间隔计算
        if (attackIntervalCounter < attackInterval) {
            attackIntervalCounter ++;
        }else{
            attackIntervalCounter = 0;
            isAttackable = true;
        }
        if (getActionState() != kActionAttack) {//不中断已经进行的攻击
            //视距范围内发现目标
            if (targetSprite->getPosition().x > getPosition().x - rangeOfVisibility.width
                && targetSprite->getPosition().x < getPosition().x + rangeOfVisibility.width
                && targetSprite->getPosition().y > getPosition().y - rangeOfVisibility.height
                && targetSprite->getPosition().y < getPosition().y + rangeOfVisibility.height)
            {
                setFaceToRight(targetSprite->getPosition().x > getPosition().x);//根据目标位置设置朝向
                
                if (getPosition().y >= targetSprite->getPosition().y + VERTICAL_SPEED) {
                    setOffsetPerFrame(ccp(0,-VERTICAL_SPEED));
                    setAnimation(ACTION_WALK, true, isFaceToRight());
                }else if(getPosition().y <= targetSprite->getPosition().y - VERTICAL_SPEED){
                    setOffsetPerFrame(ccp(0,VERTICAL_SPEED));
                    setAnimation(ACTION_WALK, true, isFaceToRight());
                }else{
                    int8_t offsetX = 0;
                    int8_t offsetY = targetSprite->getPosition().y - getPosition().y;
                    if (isFaceToRight()) {
                        if (targetSprite->getPosition().x > getPosition().x + rangeOfAttack.width){//攻击范围外
                            if(targetSprite->getPosition().x >= getPosition().x + rangeOfAttack.width + HORIZONTAL_SPEED){
                                setOffsetPerFrame(ccp(HORIZONTAL_SPEED,offsetY));
                            }else{
                                offsetX = targetSprite->getPosition().x - getPosition().x - rangeOfAttack.width;
                                setOffsetPerFrame(ccp(offsetX,offsetY));
                            }
                            setAnimation(ACTION_WALK, true, isFaceToRight());
                        }else{
                            setOffsetPerFrame(ccp(0,0));
                            if(isAttackable){
                                setAnimation(ACTION_ATTACK_0, false, isFaceToRight());
                                setActionState(kActionAttack);
                                isAttackable = false;
                            }else{
                                setAnimation(ACTION_STAND, true, isFaceToRight());
                            }
                        }
                        
                    }else{
                        if(targetSprite->getPosition().x < getPosition().x - rangeOfAttack.width){//攻击范围外
                            if(targetSprite->getPosition().x <= getPosition().x - rangeOfAttack.width - HORIZONTAL_SPEED){
                                setOffsetPerFrame(ccp(-HORIZONTAL_SPEED,offsetY));
                            }else{
                                offsetX = targetSprite->getPosition().x - (getPosition().x - rangeOfAttack.width);
                                setOffsetPerFrame(ccp(offsetX,offsetY));
                            }
                            setAnimation(ACTION_WALK, true, isFaceToRight());
                        }else{
                            setOffsetPerFrame(ccp(0,0));
                            if(isAttackable){
                                setAnimation(ACTION_ATTACK_0, false, isFaceToRight());
                                setActionState(kActionAttack);
                                isAttackable = false;
                            }else{
                                setAnimation(ACTION_STAND, true, isFaceToRight());
                            }
                        }
                    }
                }
            }else{
                setOffsetPerFrame(ccp(0,0));
                setAnimation(ACTION_STAND, true, isFaceToRight());
            }
        }
    }
}