本文整理汇总了C++中ArNetPacket::strToBuf方法的典型用法代码示例。如果您正苦于以下问题:C++ ArNetPacket::strToBuf方法的具体用法?C++ ArNetPacket::strToBuf怎么用?C++ ArNetPacket::strToBuf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArNetPacket
的用法示例。
在下文中一共展示了ArNetPacket::strToBuf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: userTask
void ArServerInfoRobot::userTask(void)
{
ArServerMode *netMode;
ArNetPacket sending;
if ((netMode = ArServerMode::getActiveMode()) != NULL)
{
myStatus = netMode->getStatus();
myExtendedStatus = netMode->getExtendedStatus();
if (myExtendedStatus.empty())
myExtendedStatus = myStatus;
myMode = netMode->getMode();
}
else
{
myStatus = "Unknown status";
myExtendedStatus = "Unknown extended status";
myMode = "Unknown mode";
}
if (myStatus != myOldStatus || myMode != myOldMode ||
myExtendedStatus != myOldExtendedStatus)
{
sending.strToBuf(myStatus.c_str());
sending.strToBuf(myMode.c_str());
sending.strToBuf(myExtendedStatus.c_str());
myServer->broadcastPacketTcp(&sending, "updateStrings");
}
myOldStatus = myStatus;
myOldMode = myMode;
myOldExtendedStatus = myExtendedStatus;
}
示例2: getConfigSectionFlags
AREXPORT void ArServerHandlerConfig::getConfigSectionFlags(
ArServerClient *client, ArNetPacket *packet)
{
ArLog::log(ArLog::Normal, "Config section flags requested.");
ArNetPacket sending;
std::list<ArConfigSection *> *sections = myConfig->getSections();
std::list<ArConfigSection *>::iterator sIt;
sending.byte4ToBuf(sections->size());
for (sIt = sections->begin(); sIt != sections->end(); sIt++)
{
ArConfigSection *section = (*sIt);
if (section == NULL)
{
sending.strToBuf("");
sending.strToBuf("");
}
else
{
sending.strToBuf(section->getName());
sending.strToBuf(section->getFlags());
}
}
client->sendPacketTcp(&sending);
}
示例3: main
int main(int argc, char **argv)
{
Aria::init();
ArClientBase client;
std::string host;
ArArgumentParser parser(&argc, argv);
ArClientSimpleConnector clientConnector(&parser);
parser.loadDefaultArguments();
/* Check for -help, and unhandled arguments: */
if (!clientConnector.parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
clientConnector.logOptions();
exit(0);
}
/* Connect our client object to the remote server: */
if (!clientConnector.connectClient(&client))
{
if (client.wasRejected())
printf("Server rejected connection, exiting\n");
else
printf("Could not connect to server, exiting\n");
exit(1);
}
client.addHandler("getCameraModeListCam1",
new ArGlobalFunctor1<ArNetPacket *>(&getCameraModeList));
client.requestOnce("getCameraModeListCam1");
ArNetPacket sending;
// This does the look at goal mode
sending.empty();
sending.strToBuf("lookAtGoal");
client.requestOnce("setCameraModeCam1", &sending);
// This does the look at point mode (at 0 0);
sending.empty();
sending.strToBuf("lookAtPoint");
sending.byte4ToBuf(1157);
sending.byte4ToBuf(-15786);
client.requestOnce("setCameraModeCam1", &sending);
while (Aria::getRunning() && client.isConnected())
{
client.loopOnce();
ArUtil::sleep(1000);
}
Aria::shutdown();
return 0;
};
示例4: netGetDrawingList
AREXPORT void ArServerInfoDrawings::netGetDrawingList(ArServerClient *client,
ArNetPacket *packet)
{
ArNetPacket sendingPacket;
// TODO: Any need to protect the map by a mutex?
for (std::map<std::string, ArDrawingData *, ArStrCaseCmpOp>::iterator it =
myDrawingDatas.begin();
it != myDrawingDatas.end();
it++)
{
sendingPacket.empty();
sendingPacket.strToBuf((*it).first.c_str());
sendingPacket.strToBuf((*it).second->getShape());
sendingPacket.byte4ToBuf((*it).second->getPrimaryColor().colorToByte4());
sendingPacket.byte4ToBuf((*it).second->getSize());
sendingPacket.byte4ToBuf((*it).second->getLayer());
sendingPacket.uByte4ToBuf((*it).second->getDefaultRefreshTime());
sendingPacket.byte4ToBuf((*it).second->getSecondaryColor().colorToByte4());
sendingPacket.strToBuf((*it).second->getVisibility());
client->sendPacketTcp(&sendingPacket);
} // end for each drawing
sendingPacket.empty();
client->sendPacketTcp(&sendingPacket);
}
示例5: updateStrings
AREXPORT void ArServerInfoRobot::updateStrings(ArServerClient *client,
ArNetPacket *packet)
{
ArNetPacket sending;
myRobot->lock();
sending.strToBuf(myStatus.c_str());
sending.strToBuf(myMode.c_str());
myRobot->unlock();
client->sendPacketTcp(&sending);
}
示例6: getSensorCurrent
AREXPORT void ArServerInfoSensor::getSensorCurrent(ArServerClient *client,
ArNetPacket *packet)
{
ArRangeDevice *dev;
char sensor[512];
std::list<ArPoseWithTime *> *readings;
std::list<ArPoseWithTime *>::iterator it;
while (packet->getDataLength() > packet->getDataReadLength())
{
ArNetPacket sendPacket;
// find out the sensor they want
packet->bufToStr(sensor, sizeof(sensor));
myRobot->lock();
if ((dev = myRobot->findRangeDevice(sensor)) == NULL)
{
myRobot->unlock();
ArLog::log(ArLog::Verbose, "ArServerInfoSensor::getSensorCurrent: No sensor %s", sensor);
sendPacket.byte2ToBuf(-1);
sendPacket.strToBuf(sensor);
client->sendPacketUdp(&sendPacket);
continue;
}
myRobot->unlock();
dev->lockDevice();
readings = dev->getCurrentBuffer();
if (readings == NULL)
{
dev->unlockDevice();
ArLog::log(ArLog::Verbose, "ArServerInfoSensor::getSensorCurrent: No current buffer for %s", sensor);
sendPacket.byte2ToBuf(0);
sendPacket.strToBuf(sensor);
client->sendPacketUdp(&sendPacket);
continue;
}
sendPacket.byte2ToBuf(readings->size());
sendPacket.strToBuf(sensor);
for (it = readings->begin(); it != readings->end(); it++)
{
sendPacket.byte4ToBuf(ArMath::roundInt((*it)->getX()));
sendPacket.byte4ToBuf(ArMath::roundInt((*it)->getY()));
}
dev->unlockDevice();
client->sendPacketUdp(&sendPacket);
}
}
示例7: saveConfigToServer
AREXPORT void ArClientHandlerConfig::saveConfigToServer(
ArConfig *config,
const std::set<std::string, ArStrCaseCmpOp> *ignoreTheseSections)
{
//ArConfigArg param;
ArClientArg clientArg;
ArNetPacket sending;
ArLog::log(ArLog::Normal, "%sSaving config to server", myLogPrefix.c_str());
myDataMutex.lock();
std::list<ArConfigSection *> *sections = config->getSections();
for (std::list<ArConfigSection *>::iterator sIt = sections->begin();
sIt != sections->end();
sIt++)
{
ArConfigSection *section = (*sIt);
// if we're ignoring sections and we're ignoring this one, then
// don't send it
if (ignoreTheseSections != NULL &&
(ignoreTheseSections->find(section->getName()) !=
ignoreTheseSections->end()))
{
ArLog::log(ArLog::Verbose, "Not sending section %s",
section->getName());
continue;
}
sending.strToBuf("Section");
sending.strToBuf(section->getName());
std::list<ArConfigArg> *params = section->getParams();
for (std::list<ArConfigArg>::iterator pIt = params->begin();
pIt != params->end();
pIt++)
{
ArConfigArg ¶m = (*pIt);
if (!clientArg.isSendableParamType(param)) {
continue;
}
sending.strToBuf(param.getName());
clientArg.argTextToBuf(param, &sending);
} // end for each param
} // end for each section
myDataMutex.unlock();
myClient->requestOnce("setConfig", &sending);
}
示例8: serverGetMapName
/** @internal */
AREXPORT void ArServerHandlerMap::serverGetMapName(ArServerClient *client,
ArNetPacket *packet)
{
ArNetPacket sendPacket;
if (myMap == NULL)
{
sendPacket.strToBuf("");
client->sendPacketTcp(&sendPacket);
}
else
{
sendPacket.strToBuf(myMap->getFileName());
client->sendPacketTcp(&sendPacket);
}
}
示例9: main
int main(int argc, char **argv)
{
Aria::init();
//ArLog::init(ArLog::StdOut, ArLog::Verbose);
ArClientBase client;
ArArgumentParser parser(&argc, argv);
ArClientSimpleConnector clientConnector(&parser);
parser.loadDefaultArguments();
if (!clientConnector.parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
clientConnector.logOptions();
exit(0);
}
if (!clientConnector.connectClient(&client))
{
if (client.wasRejected())
printf("Server '%s' rejected connection, exiting\n", client.getHost());
else
printf("Could not connect to server '%s', exiting\n", client.getHost());
exit(1);
}
client.runAsync();
ArNetPacket sending;
// We have to tell it what section we're sending
sending.strToBuf("Section");
// The map is in the files section
sending.strToBuf("Files");
// The parameter name
sending.strToBuf("Map");
// The value of the parameter
sending.strToBuf("entire2.map");
// you could put in however many of these you want...
client.requestOnce("setConfig", &sending);
// you have to give the client some time to send the command
ArUtil::sleep(500);
Aria::shutdown();
return 0;
}
示例10: update
AREXPORT void ArServerInfoRobot::update(ArServerClient *client,
ArNetPacket *packet)
{
ArNetPacket sending;
myRobot->lock();
ArServerMode *netMode;
if ((netMode = ArServerMode::getActiveMode()) != NULL)
{
sending.strToBuf(netMode->getStatus());
sending.strToBuf(netMode->getMode());
}
else
{
sending.strToBuf("Unknown status");
sending.strToBuf("Unknown mode");
}
//ArLog::log(ArLog::Normal,
// "ArServerInfoRobot::update() havestateofcharge = %d, soc = %f, real = %f, reg = %f",
// myRobot->haveStateOfCharge(),
// myRobot->getStateOfCharge(),
// myRobot->getRealBatteryVoltage(),
// myRobot->getBatteryVoltage());
if (myRobot->haveStateOfCharge())
sending.byte2ToBuf(ArMath::roundInt(myRobot->getStateOfCharge() * 10));
else if (myRobot->getRealBatteryVoltage() > 0)
sending.byte2ToBuf(ArMath::roundInt(
myRobot->getRealBatteryVoltage() * 10));
else
sending.byte2ToBuf(ArMath::roundInt(
myRobot->getBatteryVoltage() * 10));
sending.byte4ToBuf((int)myRobot->getX());
sending.byte4ToBuf((int)myRobot->getY());
sending.byte2ToBuf((int)myRobot->getTh());
sending.byte2ToBuf((int)myRobot->getVel());
sending.byte2ToBuf((int)myRobot->getRotVel());
sending.byte2ToBuf((int)myRobot->getLatVel());
sending.byteToBuf((char)myRobot->getTemperature());
//sending.byte2ToBuf((int)myRobot->getPayloadNumSlots());
myRobot->unlock();
client->sendPacketUdp(&sending);
}
示例11: closePopup
AREXPORT void ArServerHandlerPopup::closePopup(ArTypes::Byte4 id,
const char *closeMessage)
{
ArNetPacket sendingPacket;
PopupData *popupData;
std::map<ArTypes::Byte4, PopupData *>::iterator it;
myDataMutex.lock();
if ((it = myMap.find(id)) == myMap.end())
{
ArLog::log(ArLog::Verbose,
"Cannot close popup %u as it doesn't exist (anymore at least)",
id);
myDataMutex.unlock();
}
else
{
popupData = (*it).second;
sendingPacket.byte4ToBuf(id);
sendingPacket.strToBuf(closeMessage);
myMap.erase(id);
myDataMutex.unlock();
delete popupData;
if (popupData->myCallback != NULL)
popupData->myCallback->invoke(popupData->myID, -2);
myServer->broadcastPacketTcp(&sendingPacket, "popupClose");
}
}
示例12: writeMapToClient
/** @internal */
AREXPORT void ArServerHandlerMap::writeMapToClient(const char *line,
ArServerClient *client)
{
ArNetPacket sendPacket;
sendPacket.strToBuf(line);
client->sendPacketTcp(&sendPacket);
}
示例13: requestOnceWithString
AREXPORT bool ArCentralForwarder::requestOnceWithString(const char *name, const char *str)
{
ArNetPacket tempPacket;
tempPacket.strToBuf(str);
return requestOnce(name, &tempPacket);
}
示例14: serverMappingStatus
AREXPORT void ArServerHandlerMapping::serverMappingStatus(
ArServerClient *client, ArNetPacket *packet)
{
ArNetPacket sendPacket;
sendPacket.strToBuf(myMapName.c_str());
client->sendPacketTcp(&sendPacket);
}
示例15: getSensorList
AREXPORT void ArServerInfoSensor::getSensorList(ArServerClient *client,
ArNetPacket *packet)
{
ArNetPacket sendPacket;
std::list<ArRangeDevice *> *devList;
std::list<ArRangeDevice *>::iterator it;
myRobot->lock();
devList = myRobot->getRangeDeviceList();
if (devList == NULL)
{
myRobot->unlock();
client->sendPacketUdp(&sendPacket);
return;
}
sendPacket.byte2ToBuf(devList->size());
for (it = devList->begin(); it != devList->end(); it++)
{
sendPacket.strToBuf((*it)->getName());
}
myRobot->unlock();
client->sendPacketUdp(&sendPacket);
}