本文整理汇总了C++中Port::WaitConnected方法的典型用法代码示例。如果您正苦于以下问题:C++ Port::WaitConnected方法的具体用法?C++ Port::WaitConnected怎么用?C++ Port::WaitConnected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Port
的用法示例。
在下文中一共展示了Port::WaitConnected方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: args
int
main(int argc, char **argv)
{
Args args(argc, argv, "PORT BAUD");
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
Port *port = OpenPort(config, nullptr, *(DataHandler *)nullptr);
if (port == NULL) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
FlarmDevice flarm(*port);
RunUI(flarm, env);
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例2: args
int
main(int argc, char **argv)
{
Args args(argc, argv, "PORT BAUD");
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
MyHandler handler;
Port *port = OpenPort(config, handler);
if (port == NULL) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
if (!port->StartRxThread()) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to start the port thread\n");
return EXIT_FAILURE;
}
char stamp[6] = "";
char line[1024];
while (fgets(line, sizeof(line), stdin) != NULL) {
if (memcmp(line, "$GP", 3) == 0 &&
(memcmp(line + 3, "GGA", 3) == 0 ||
memcmp(line + 3, "RMC", 3) == 0) &&
line[6] == ',' &&
strncmp(stamp, line + 7, sizeof(stamp)) != 0) {
/* the time stamp has changed - sleep for one second */
Sleep(1000);
strncpy(stamp, line + 7, sizeof(stamp));
}
if (!port->FullWriteString(line, env, 1000)) {
fprintf(stderr, "Failed to write to port\n");
delete port;
return EXIT_FAILURE;
}
}
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例3: main
int main(int argc, char **argv)
{
Args args(argc, argv, "PORT BAUD");
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
Port *port = OpenPort(config, nullptr, *(DataHandler *)nullptr);
if (port == NULL) {
delete port;
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
char buffer[4096];
while (true) {
switch (port->WaitRead(env, 60000)) {
case Port::WaitResult::READY:
break;
case Port::WaitResult::TIMEOUT:
continue;
case Port::WaitResult::FAILED:
delete port;
return EXIT_FAILURE;
case Port::WaitResult::CANCELLED:
delete port;
return EXIT_SUCCESS;
}
int nbytes = port->Read(buffer, sizeof(buffer));
if (nbytes < 0)
break;
fwrite((const void *)buffer, 1, nbytes, stdout);
}
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例4: OpenInternalSensors
bool
DeviceDescriptor::DoOpen(OperationEnvironment &env)
{
assert(config.IsAvailable());
if (config.port_type == DeviceConfig::PortType::INTERNAL)
return OpenInternalSensors();
if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2)
return OpenDroidSoarV2();
if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR)
return OpenI2Cbaro();
if (config.port_type == DeviceConfig::PortType::NUNCHUCK)
return OpenNunchuck();
if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE)
return OpenVoltage();
reopen_clock.Update();
Port *port = OpenPort(config, port_listener, *this);
if (port == nullptr) {
TCHAR name_buffer[64];
const TCHAR *name = config.GetPortName(name_buffer, 64);
StaticString<256> msg;
msg.Format(_T("%s: %s."), _("Unable to open port"), name);
env.SetErrorMessage(msg);
return false;
}
DumpPort *dump_port = new DumpPort(port);
dump_port->Disable();
if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) {
if (!env.IsCancelled())
++n_failures;
delete dump_port;
return false;
}
ResetFailureCounter();
return true;
}
示例5: args
int
main(int argc, char **argv)
{
Args args(argc, argv, "DRIVER PORT BAUD");
Emulator *emulator = LoadEmulator(args);
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
Port *port = OpenPort(config, *emulator->handler);
if (port == NULL) {
delete emulator;
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
emulator->port = port;
ConsoleOperationEnvironment env;
emulator->env = &env;
if (!port->WaitConnected(env)) {
delete port;
delete emulator;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
if (!port->StartRxThread()) {
delete port;
delete emulator;
DeinitialiseIOThread();
fprintf(stderr, "Failed to start the port thread\n");
return EXIT_FAILURE;
}
while (port->GetState() != PortState::FAILED)
Sleep(1000);
delete port;
delete emulator;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例6: main
int main(int argc, char **argv)
{
const char *const usage = "PORT BAUD COMMAND\n\n"
"Where COMMAND is one of:"
"\n\tinfo"
"\n\treboot"
"\n\tpoweroff"
"\n\tstartlogger"
"\n\tstoplogger"
"\n\tpilots"
"\n\tnavpoints"
;
Args args(argc, argv, usage);
const DeviceConfig config = ParsePortArgs(args);
const char *command = args.ExpectNext();
args.ExpectEnd();
InitialiseIOThread();
Port *port = OpenPort(config, nullptr, *(DataHandler *)nullptr);
if (port == NULL) {
fprintf(stderr, "Failed to open port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
CAI302Device device(config, *port);
if (!RunCommand(device, command, env)) {
fprintf(stderr, "error\n");
return EXIT_FAILURE;
}
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例7: main
int main(int argc, char **argv)
{
Args args(argc, argv, "DRIVER PORT BAUD");
tstring _driver_name = args.ExpectNextT();
const TCHAR *driver_name = _driver_name.c_str();
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
Port *port = OpenPort(config, *(DataHandler *)NULL);
if (port == NULL) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
const struct DeviceRegister *driver = FindDriverByName(driver_name);
if (driver == NULL) {
_ftprintf(stderr, _T("No such driver: %s\n"), driver_name);
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
assert(driver->CreateOnPort != NULL);
Device *device = driver->CreateOnPort(config, *port);
assert(device != NULL);
device->EnableNMEA(env);
delete device;
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例8: main
int main(int argc, char **argv)
{
Args args(argc, argv, "PORT BAUD [NAME=VALUE] [NAME] ...");
const DeviceConfig config = ParsePortArgs(args);
InitialiseIOThread();
Port *port = OpenPort(config, nullptr, *(DataHandler *)nullptr);
if (port == NULL) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
VegaDevice device(*port);
while (!args.IsEmpty()) {
const char *p = args.GetNext();
char *q = strdup(p);
char *v = strchr(q, '=');
if (v == NULL) {
if (!device.RequestSetting(q, env))
printf("Error\n");
} else {
*v++ = 0;
if (!device.SendSetting(q, atoi(v), env))
printf("Error\n");
}
free(q);
}
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例9: main
int main(int argc, char **argv)
{
Args args(argc, argv, "PORT BAUD");
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
MyHandler handler;
Port *port = OpenPort(config, handler);
if (port == NULL) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
/* turn off output buffering */
setvbuf(stdout, NULL, _IONBF, 0);
if (!port->StartRxThread()) {
delete port;
fprintf(stderr, "Failed to start the port thread\n");
return EXIT_FAILURE;
}
while (true)
Sleep(10000);
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}
示例10: main
int main(int argc, char **argv)
{
Args args(argc, argv, "PORT");
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
Port *port = OpenPort(config, nullptr, *(DataHandler *)nullptr);
if (port == nullptr) {
DeinitialiseIOThread();
fprintf(stderr, "Failed to open port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
PeriodClock start_clock;
start_clock.Update();
PeriodClock pressure_clock;
PeriodClock battery_clock;
fixed pressure = fixed(101300);
unsigned battery_level = 11;
while (true) {
if (pressure_clock.CheckUpdate(48)) {
NarrowString<16> sentence;
int elapsed_ms = start_clock.Elapsed();
auto elapsed = fixed(elapsed_ms) / 1000;
auto vario = sin(elapsed / 3) * cos(elapsed / 10) *
cos(elapsed / 20 + fixed(2)) * 3;
auto pressure_vario = -vario * fixed(12.5);
auto delta_pressure = pressure_vario * 48 / 1000;
pressure += delta_pressure;
sentence = "_PRS ";
sentence.AppendFormat("%08X", uround(pressure));
sentence += "\n";
port->Write(sentence.c_str(), sentence.length());
}
if (battery_clock.CheckUpdate(11000)) {
NarrowString<16> sentence;
sentence = "_BAT ";
if (battery_level <= 10)
sentence.AppendFormat("%X", battery_level);
else
sentence += "*";
sentence += "\n";
port->Write(sentence.c_str(), sentence.length());
if (battery_level == 0)
battery_level = 11;
else
battery_level--;
}
}
}
示例11: main
int main(int argc, char **argv)
{
Args args(argc, argv, "[--through DRIVER0] DRIVER PORT BAUD");
tstring _through_name;
const TCHAR *through_name = NULL;
const char *a;
while ((a = args.PeekNext()) != NULL && *a == '-') {
a = args.ExpectNext();
if (strcmp(a, "--through") == 0) {
_through_name = args.ExpectNextT();
through_name = _through_name.c_str();
} else
args.UsageError();
}
tstring _driver_name = args.ExpectNextT();
const TCHAR *driver_name = _driver_name.c_str();
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
Port *port = OpenPort(config, *(DataHandler *)NULL);
if (port == NULL) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
LoggerSettings logger_settings;
logger_settings.pilot_name = _T("Foo Bar");
Plane plane;
plane.registration = _T("D-3003");
plane.competition_id = _T("33");
plane.type = _T("Cirrus");
Declaration declaration(logger_settings, plane, NULL);
declaration.Append(MakeWaypoint(_T("Bergneustadt"), 488,
7.7061111111111114, 51.051944444444445));
declaration.Append(MakeWaypoint(_T("Foo"), 488, 8, 52));
declaration.Append(MakeWaypoint(_T("Bar"), 488, 7.5, 50));
declaration.Append(MakeWaypoint(_T("Bergneustadt"), 488,
7.7061111111111114, 51.051944444444445));
Device *through_device = NULL;
if (through_name != NULL) {
const struct DeviceRegister *through_driver =
FindDriverByName(through_name);
if (through_driver == NULL) {
_ftprintf(stderr, _T("No such driver: %s\n"), through_name);
return EXIT_FAILURE;
}
if (!through_driver->HasPassThrough()) {
_ftprintf(stderr, _T("Not a pass-through driver: %s\n"), through_name);
return EXIT_FAILURE;
}
assert(through_driver->CreateOnPort != NULL);
through_device = through_driver->CreateOnPort(config, *port);
assert(through_device != NULL);
}
const struct DeviceRegister *driver = FindDriverByName(driver_name);
if (driver == NULL) {
_ftprintf(stderr, _T("No such driver: %s\n"), driver_name);
return EXIT_FAILURE;
}
if (!driver->CanDeclare()) {
_ftprintf(stderr, _T("Not a logger driver: %s\n"), driver_name);
return EXIT_FAILURE;
}
assert(driver->CreateOnPort != NULL);
Device *device = driver->CreateOnPort(config, *port);
assert(device != NULL);
if (through_device != NULL && !through_device->EnablePassThrough(env)) {
_ftprintf(stderr, _T("Failed to enable pass-through mode: %s\n"),
through_name);
return EXIT_FAILURE;
}
if (device->Declare(declaration, NULL, env))
fprintf(stderr, "Declaration ok\n");
else
fprintf(stderr, "Declaration failed\n");
//.........这里部分代码省略.........
示例12: protect
bool
DeviceDescriptor::DoOpen(OperationEnvironment &env)
{
assert(config.IsAvailable());
{
ScopeLock protect(mutex);
error_message.clear();
}
if (config.port_type == DeviceConfig::PortType::INTERNAL)
return OpenInternalSensors();
if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2)
return OpenDroidSoarV2();
if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR)
return OpenI2Cbaro();
if (config.port_type == DeviceConfig::PortType::NUNCHUCK)
return OpenNunchuck();
if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE)
return OpenVoltage();
reopen_clock.Update();
Port *port;
try {
port = OpenPort(io_service, config, this, *this);
} catch (const std::runtime_error &e) {
TCHAR name_buffer[64];
const TCHAR *name = config.GetPortName(name_buffer, 64);
LogError(WideToUTF8Converter(name), e);
StaticString<256> msg;
const UTF8ToWideConverter what(e.what());
if (what.IsValid()) {
ScopeLock protect(mutex);
error_message = what;
}
msg.Format(_T("%s: %s (%s)"), _("Unable to open port"), name,
(const TCHAR *)what);
env.SetErrorMessage(msg);
return false;
}
if (port == nullptr) {
TCHAR name_buffer[64];
const TCHAR *name = config.GetPortName(name_buffer, 64);
StaticString<256> msg;
msg.Format(_T("%s: %s."), _("Unable to open port"), name);
env.SetErrorMessage(msg);
return false;
}
DumpPort *dump_port = new DumpPort(port);
dump_port->Disable();
if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) {
if (!env.IsCancelled())
++n_failures;
delete dump_port;
return false;
}
ResetFailureCounter();
return true;
}
示例13: args
int
main(int argc, char **argv)
{
Args args(argc, argv, "PORT BAUD");
const DeviceConfig config = ParsePortArgs(args);
args.ExpectEnd();
InitialiseIOThread();
MyHandler handler;
Port *port = OpenPort(config, handler);
if (port == NULL) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
if (!port->WaitConnected(env)) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to connect the port\n");
return EXIT_FAILURE;
}
if (!port->StartRxThread()) {
delete port;
DeinitialiseIOThread();
fprintf(stderr, "Failed to start the port thread\n");
return EXIT_FAILURE;
}
unsigned long last_stamp = -1;
char line[1024];
while (fgets(line, sizeof(line), stdin) != NULL) {
char *endptr;
unsigned long current_stamp = strtoul(line, &endptr, 10);
if (endptr == line || *endptr != ' ' || endptr[1] != '<')
continue;
char *start = endptr + 2;
char *end = strchr(start, '>');
if (end == NULL)
continue;
*end++ = '\n';
*end = 0;
if (current_stamp > last_stamp) {
unsigned long delta_t = std::min(current_stamp - last_stamp, 1000ul);
Sleep(delta_t);
}
last_stamp = current_stamp;
if (!port->FullWrite(start, end - start, env, 1000)) {
fprintf(stderr, "Failed to write to port\n");
delete port;
return EXIT_FAILURE;
}
}
delete port;
DeinitialiseIOThread();
return EXIT_SUCCESS;
}