本文整理汇总了C++中Command::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ Command::GetType方法的具体用法?C++ Command::GetType怎么用?C++ Command::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command::GetType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddTicket
int TransactionQueue::AddTicket(Command &cmd) {
string target = cmd.GetTargetsid();
int type = cmd.GetType();
int ticket = GetNextTicketID();
string targetsid = cmd.GetTargetsid();
vector<Transaction>::iterator it;
/* if the command object is register command */
if(type == FX_REGISTER) {
/* first find the register transaction */
for( it = _transq.begin(); it < _transq.end(); it++) {
if((*it).GetType() == 0 ) {
/* We have found the register transaction
* Update the command object and do the transaction
*/
(*it).SetCommand(cmd);
(*it).SetTicketid(ticket);
DoTransaction((*it).GetID());
return ticket;
}
}
/* not existing a register transaction
* add a new transaction and do it
*/
Transaction tmp(cmd);
tmp.SetTicketid(ticket);
DoTransaction(Add(Transaction(cmd)));
return ticket;
} else {
/* not a register command */
/* find if there exists a transaction
* whose targetid and type is the same
* as the command.
*/
for( it = _transq.begin(); it < _transq.end(); it++) {
if( ((*it).GetTargetsid().compare(targetsid) == 0) && \
((*it).GetType() == cmd.GetType()) ) {
/* We have found the specific transaction
* Update the command object and do the transaction
*/
(*it).SetCommand(cmd);
(*it).SetTicketid(ticket);
DoTransaction((*it).GetID());
return ticket;
}
}
Transaction tmp(cmd);
tmp.SetTicketid(ticket);
DoTransaction(Add(Transaction(cmd)));
return ticket;
}
}
示例2: ExecCommand
bool LoopModule::ExecCommand(const Command& command, bool wantAnswer)
{
if(command.GetType() == ctGET) // получить состояние связанного модуля
{
return AddLink(command,wantAnswer) ? true : false;
} // if
else
if(command.GetType() == ctSET) // установить состояние связанного модуля
{
return AddLink(command,wantAnswer) ? true : false;
} // if
return true;
}
示例3: main
//.........这里部分代码省略.........
}
if( c == 'a' )
{
Command c;
c.SetType(Command::LEFT);
connection.SendCommand(c);
}
if( c == 'd' )
{
Command c;
c.SetType(Command::RIGHT);
connection.SendCommand(c);
}
if( c == 'e' )
{
Command c;
c.SetType(Command::TAKE);
connection.SendCommand(c);
}
if( c == 'q' )
{
Command c;
c.SetType(Command::OPEN);
connection.SendCommand(c);
}
}
if ( connection.Ready() ) ///< reakcia na packet, ktory prave dorazil
{
connection.ReadPacket();
if( connection.GetHeaderType() == packetHeader::COMMAND )
{
Command c = connection.GetPacketContent<Command>();
if( c.GetType() == Command::TEXT ) ///< ak mi sietou neprisiel novy obsah mapy tak prisla textova sprava, ktoru vypisem
{
cout << c.GetText() << endl;
}
else
{
cout << "Received packet different than text or gameupdate";
}
}
else if ( connection.GetHeaderType() == packetHeader::GAME_UPDATE ) ///< server zaslal game update
{
MapUpdate updatepacket = connection.GetPacketContent<MapUpdate>();
Map::MapMatrix screenbuffer = background;
screenbuffer[updatepacket.treasure.x][updatepacket.treasure.y] = Map::FINISH; ///< vlozenie pokladu
for ( auto item: updatepacket.gates ) ///< vlozenie bran
{
if ( item.optionFlag == true )
{
screenbuffer[item.x][item.y] = Map::GATE;
}
else
{
screenbuffer[item.x][item.y] = Map::GATE_OPEN;
}
}
for ( auto item: updatepacket.keys ) ///< vlozenie klucov
{
if ( item.optionFlag == true )
{
screenbuffer[item.x][item.y] = Map::KEY;
}
}
for ( auto item: updatepacket.guards ) ///< vlozenie strazcov
示例4: ExecCommand
bool CompositeCommandsModule::ExecCommand(const Command& command, bool wantAnswer)
{
if(wantAnswer)
PublishSingleton = UNKNOWN_COMMAND;
size_t argsCount = command.GetArgsCount();
if(command.GetType() == ctGET)
{
if(wantAnswer)
PublishSingleton = NOT_SUPPORTED;
}
else
if(command.GetType() == ctSET)
{
if(argsCount < 1)
{
PublishSingleton = PARAMS_MISSED;
}
else
{
// есть параметры
String which = command.GetArg(0);
if(which == CC_DELETE_COMMAND) // очистить все команды
{
Clear();
if(wantAnswer)
PublishSingleton = REG_DEL; // говорим, что удалили всё
PublishSingleton.Status = true;
} // CC_DELETE_COMMAND
else
if(which == CC_SAVE_COMMAND) // сохранить команды в EEPROM
{
SaveCommands();
if(wantAnswer)
PublishSingleton = REG_SUCC; // говорим, что сохранили
PublishSingleton.Status = true;
} // CC_SAVE_COMMAND
else
if(which == CC_PROCESS_COMMAND) // выполнить команду
{
if(argsCount > 1)
{
// хватает аргументов
uint8_t cmd = abs(atoi(command.GetArg(1)));
ProcessCommand(cmd); // выполняем составную команду
if(wantAnswer)
PublishSingleton = REG_SUCC; // говорим, что выполнили
PublishSingleton.Status = true;
}
else
{
// не хватает аргументов
if(wantAnswer)
PublishSingleton = PARAMS_MISSED;
}
} // CC_PROCESS_COMMAND
else
if(which == CC_ADD_COMMAND) // добавить параметр в список составной команды
{
if(argsCount > 3)
{
uint8_t listIdx = abs(atoi(command.GetArg(1)));
uint8_t action = abs(atoi(command.GetArg(2)));
uint8_t param = abs(atoi(command.GetArg(3)));
AddCommand(listIdx,action,param); // добавляем команду
if(wantAnswer)
PublishSingleton = REG_SUCC; // говорим, что добавили
PublishSingleton.Status = true;
}
else
{
// не хватает аргументов
if(wantAnswer)
PublishSingleton = PARAMS_MISSED;
}
} // CC_ADD_COMMAND
} // else
} // ctSET
// отвечаем на команду
MainController->Publish(this,command);
return PublishSingleton.Status;
}
示例5: ExecCommand
bool SoilMoistureModule::ExecCommand(const Command& command, bool wantAnswer)
{
if(wantAnswer)
PublishSingleton = NOT_SUPPORTED;
if(command.GetType() == ctSET) // установка свойств
{
} // ctSET
else
if(command.GetType() == ctGET) // запрос свойств
{
uint8_t argsCnt = command.GetArgsCount();
if(argsCnt < 1)
{
if(wantAnswer)
PublishSingleton = PARAMS_MISSED; // не хватает параметров
} // argsCnt < 1
else
{
String param = command.GetArg(0);
if(param == ALL) // запросили показания со всех датчиков: CTGET=SOIL|ALL
{
PublishSingleton.Status = true;
uint8_t _cnt = State.GetStateCount(StateSoilMoisture);
if(wantAnswer)
PublishSingleton = _cnt;
for(uint8_t i=0;i<_cnt;i++)
{
OneState* stateHumidity = State.GetStateByOrder(StateSoilMoisture,i);
if(stateHumidity)
{
HumidityPair hp = *stateHumidity;
if(wantAnswer)
{
PublishSingleton << PARAM_DELIMITER << (hp.Current);
}
} // if
} // for
} // param == ALL
else
if(param == PROP_CNT) // запросили данные о кол-ве датчиков: CTGET=SOIL|CNT
{
PublishSingleton.Status = true;
if(wantAnswer)
{
PublishSingleton = PROP_CNT;
uint8_t _cnt = State.GetStateCount(StateSoilMoisture);
PublishSingleton << PARAM_DELIMITER << _cnt;
}
} // PROP_CNT
else
if(param != GetID()) // если только не запросили без параметров
{
// запросили показания с датчика по индексу
uint8_t idx = param.toInt();
uint8_t _cnt = State.GetStateCount(StateSoilMoisture);
if(idx >= _cnt)
{
// плохой индекс
if(wantAnswer)
PublishSingleton = NOT_SUPPORTED;
} // плохой индекс
else
{
if(wantAnswer)
PublishSingleton = param;
OneState* stateHumidity = State.GetStateByOrder(StateSoilMoisture,idx);
if(stateHumidity)
{
PublishSingleton.Status = true;
HumidityPair hp = *stateHumidity;
if(wantAnswer)
{
PublishSingleton << PARAM_DELIMITER << (hp.Current);
}
} // if
} // else нормальный индекс
} // if param != GetID()
} // else
}
MainController->Publish(this,command);
return true;
}
示例6: ExecCommand
bool ZeroStreamListener::ExecCommand(const Command& command, bool wantAnswer)
{
if(wantAnswer) PublishSingleton = UNKNOWN_COMMAND;
bool canPublish = true; // флаг, что можем публиковать
size_t argsCnt = command.GetArgsCount();
if(command.GetType() == ctGET)
{
PublishSingleton = NOT_SUPPORTED;
if(!argsCnt) // нет аргументов
{
PublishSingleton = PARAMS_MISSED;
}
else
{
if(argsCnt < 1)
{
// мало параметров
PublishSingleton = PARAMS_MISSED;
} // if
else
{
String t = command.GetArg(0); // получили команду
t.toUpperCase();
if(t == PING_COMMAND) // пинг
{
PublishSingleton.Status = true;
PublishSingleton = PONG;
PublishSingleton.AddModuleIDToAnswer = false;
} // if
else
if(t == UNI_RF_CHANNEL_COMMAND)
{
PublishSingleton.Status = true;
PublishSingleton = UNI_RF_CHANNEL_COMMAND;
PublishSingleton << PARAM_DELIMITER;
PublishSingleton << UniDispatcher.GetRFChannel();
PublishSingleton.AddModuleIDToAnswer = false;
}
#if defined(USE_UNIVERSAL_SENSORS) && defined(UNI_USE_REGISTRATION_LINE)
else
if(t == UNI_SEARCH) // поиск универсального модуля на линии регистрации
{
PublishSingleton.AddModuleIDToAnswer = false;
if(uniRegistrator.IsModulePresent())
{
// датчик найден, отправляем его внутреннее состояние
PublishSingleton.Status = true;
UniRawScratchpad scratch;
uniRegistrator.CopyScratchpad(&scratch);
byte* raw = (byte*) &scratch;
PublishSingleton = "";
// теперь пишем весь скратчпад вызывающему, пущай сам разбирается, как с ним быть
for(byte i=0;i<sizeof(UniRawScratchpad);i++)
{
PublishSingleton << WorkStatus::ToHex(raw[i]);
} // for
} // if
else
{
// датчика нету
PublishSingleton = UNI_NOT_FOUND;
} // else
}
#endif // UNI_USE_REGISTRATION_LINE
else
if(t == ID_COMMAND)
{
PublishSingleton.Status = true;
PublishSingleton.AddModuleIDToAnswer = false;
PublishSingleton = ID_COMMAND;
PublishSingleton << PARAM_DELIMITER << MainController->GetSettings()->GetControllerID();
}
else
if(t == WIRED_COMMAND) // получить количество жёстко указанных в прошивке обычных датчиков
{
PublishSingleton.Status = true;
PublishSingleton.AddModuleIDToAnswer = false;
PublishSingleton = WIRED_COMMAND;
PublishSingleton << PARAM_DELIMITER << UniDispatcher.GetHardCodedSensorsCount(uniTemp);
PublishSingleton << PARAM_DELIMITER << UniDispatcher.GetHardCodedSensorsCount(uniHumidity);
PublishSingleton << PARAM_DELIMITER << UniDispatcher.GetHardCodedSensorsCount(uniLuminosity);
PublishSingleton << PARAM_DELIMITER << UniDispatcher.GetHardCodedSensorsCount(uniSoilMoisture);
PublishSingleton << PARAM_DELIMITER << UniDispatcher.GetHardCodedSensorsCount(uniPH);
//TODO: Тут остальные типы датчиков указывать !!!
}
else
if(t == UNI_COUNT_COMMAND) // получить количество зарегистрированных универсальных датчиков
{
PublishSingleton.Status = true;
//.........这里部分代码省略.........
示例7: ExecCommand
//-------------------------------------------------------------------------------------------------------------------------------------------------------
bool PhModule::ExecCommand(const Command& command, bool wantAnswer)
{
if(wantAnswer)
PublishSingleton = NOT_SUPPORTED;
uint8_t argsCnt = command.GetArgsCount();
if(command.GetType() == ctSET) // установка свойств
{
if(argsCnt < 1)
{
if(wantAnswer)
PublishSingleton = PARAMS_MISSED;
}
else
{
String param = command.GetArg(0);
if(param == PH_SETTINGS_COMMAND) // установить настройки: CTSET=PH|T_SETT|calibration_factor|ph4Voltage|ph7Voltage|ph10Voltage|temp_sensor_index|samples_temp|ph_target|ph_histeresis|mix_time|reagent_time
{
if(argsCnt < 11)
{
if(wantAnswer)
PublishSingleton = PARAMS_MISSED;
}
else
{
// аргументов хватает
calibration = atoi(command.GetArg(1));
ph4Voltage = atoi(command.GetArg(2));
ph7Voltage = atoi(command.GetArg(3));
ph10Voltage = atoi(command.GetArg(4));
phTemperatureSensorIndex = atoi(command.GetArg(5));
int samplesTemp = atoi(command.GetArg(6));
phSamplesTemperature.Value = samplesTemp/100;
phSamplesTemperature.Fract = samplesTemp%100;
phTarget = atoi(command.GetArg(7));
phHisteresis = atoi(command.GetArg(8));
phMixPumpTime = atoi(command.GetArg(9));
phReagentPumpTime = atoi(command.GetArg(10));
SaveSettings();
PublishSingleton.Status = true;
PublishSingleton = REG_SUCC;
}
} // PH_SETTINGS_COMMAND
} // else argsCount >= 1
} // ctSET
else
if(command.GetType() == ctGET) // запрос свойств
{
if(argsCnt < 1)
{
if(wantAnswer)
PublishSingleton = PARAMS_MISSED; // не хватает параметров
} // argsCnt < 1
else
{
String param = command.GetArg(0);
if(param == ALL) // запросили показания со всех датчиков: CTGET=PH|ALL
{
PublishSingleton.Status = true;
uint8_t _cnt = State.GetStateCount(StatePH);
if(wantAnswer)
PublishSingleton = _cnt;
for(uint8_t i=0;i<_cnt;i++)
{
OneState* stateHumidity = State.GetStateByOrder(StatePH,i);
if(stateHumidity)
{
HumidityPair hp = *stateHumidity;
if(wantAnswer)
{
PublishSingleton << PARAM_DELIMITER << (hp.Current);
}
} // if
} // for
} // param == ALL
else
if(param == PH_SETTINGS_COMMAND) // получить/установить настройки: CTGET=PH|T_SETT, CTSET=PH|T_SETT|calibration_factor|ph4Voltage|ph7Voltage|ph10Voltage|temp_sensor_index|samples_temp|ph_target|ph_histeresis|mix_time|reagent_time
{
PublishSingleton.Status = true;
if(wantAnswer)
{
PublishSingleton = PH_SETTINGS_COMMAND;
PublishSingleton << PARAM_DELIMITER << calibration;
//.........这里部分代码省略.........