本文整理汇总了C++中NarrowString::AppendFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ NarrowString::AppendFormat方法的具体用法?C++ NarrowString::AppendFormat怎么用?C++ NarrowString::AppendFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NarrowString
的用法示例。
在下文中一共展示了NarrowString::AppendFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsPrintable
static inline void
HexDumpLine(const char *prefix, unsigned offset,
const uint8_t *data, size_t length)
{
NarrowString<128> line;
line.clear();
for (size_t i = 0; i < length; ++i) {
if ((i & 0x7) == 0)
line += " ";
line.AppendFormat(" %02x", data[i]);
}
for (size_t i = length; i < 0x10; ++i) {
if ((i & 0x7) == 0)
line += " ";
line += " ";
}
line += " ";
for (size_t i = 0; i < length; ++i) {
if ((i & 0x7) == 0)
line += " ";
char byte[2];
byte[0] = IsPrintable(data[i]) ? (char)data[i] : '.';
byte[1] = '\0';
line += byte;
}
LogFormat("%s%04x%s", prefix, offset, line.c_str());
}
示例2: main
int main(int argc, char **argv)
{
NarrowString<1024> usage;
usage = "DRIVER\n\n"
"Where DRIVER is one of:";
{
const DeviceRegister *driver;
for (unsigned i = 0; (driver = GetDriverByIndex(i)) != nullptr; ++i) {
WideToUTF8Converter driver_name(driver->name);
usage.AppendFormat("\n\t%s", (const char *)driver_name);
}
}
Args args(argc, argv, usage);
tstring driver_name = args.ExpectNextT();
args.ExpectEnd();
driver = FindDriverByName(driver_name.c_str());
if (driver == nullptr) {
_ftprintf(stderr, _T("No such driver: %s\n"), driver_name.c_str());
return 1;
}
DeviceConfig config;
config.Clear();
NullPort port;
Device *device = driver->CreateOnPort != nullptr
? driver->CreateOnPort(config, port)
: nullptr;
NMEAParser parser;
NMEAInfo data;
data.Reset();
char buffer[1024];
while (fgets(buffer, sizeof(buffer), stdin) != nullptr) {
StripRight(buffer);
if (device == nullptr || !device->ParseNMEA(buffer, data))
parser.ParseLine(buffer, data);
}
Dump(data);
return EXIT_SUCCESS;
}
示例3: 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--;
}
}
}
示例4: main
int main(int argc, char **argv)
{
// Determine on which TCP port to connect to the server
const char *tcp_port;
if (argc < 2) {
fprintf(stderr, "This program opens a TCP connection to a server which is assumed ");
fprintf(stderr, "to be at 127.0.0.1, and sends artificial FlyNet vario data.\n\n");
fprintf(stderr, "Usage: %s PORT\n", argv[0]);
fprintf(stderr, "Defaulting to port 4353\n");
tcp_port = "4353";
} else {
tcp_port = argv[1];
}
// Convert IP address to binary form
SocketAddress server_address;
if (!server_address.Lookup("127.0.0.1", tcp_port, AF_INET)) {
fprintf(stderr, "Failed to look up address\n");
exit(EXIT_FAILURE);
}
// Create socket for the outgoing connection
SocketDescriptor sock;
if (!sock.CreateTCP()) {
perror("Socket");
exit(EXIT_FAILURE);
}
// Connect to the specified server
if (!sock.Connect(server_address))
{
perror("Connect");
exit(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();
fixed elapsed = fixed(elapsed_ms) / 1000;
fixed vario = sin(elapsed / 3) * cos(elapsed / 10) *
cos(elapsed / 20 + fixed(2)) * fixed(3);
fixed pressure_vario = -vario * fixed(12.5);
fixed delta_pressure = pressure_vario * 48 / 1000;
pressure += delta_pressure;
sentence = "_PRS ";
sentence.AppendFormat("%08X", uround(pressure));
sentence += "\n";
sock.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";
sock.Write(sentence.c_str(), sentence.length());
if (battery_level == 0)
battery_level = 11;
else
battery_level--;
}
}
return EXIT_SUCCESS;
}
示例5: main
int main(int argc, char **argv)
{
NarrowString<1024> usage;
usage = "DRIVER PORT BAUD FILE.igc [FLIGHT NR]\n\n"
"Where DRIVER is one of:";
{
const DeviceRegister *driver;
for (unsigned i = 0; (driver = GetDriverByIndex(i)) != NULL; ++i) {
if (driver->IsLogger()) {
NarrowPathName driver_name(driver->name);
usage.AppendFormat("\n\t%s", (const char *)driver_name);
}
}
}
Args args(argc, argv, usage);
PathName driver_name(args.ExpectNext());
PathName port_name(args.ExpectNext());
DeviceConfig config;
config.Clear();
config.baud_rate = atoi(args.ExpectNext());
PathName path(args.ExpectNext());
unsigned flight_id = args.IsEmpty() ? 0 : atoi(args.GetNext());
args.ExpectEnd();
#ifdef HAVE_POSIX
TTYPort port(port_name, config.baud_rate, *(Port::Handler *)NULL);
#else
SerialPort port(port_name, config.baud_rate, *(Port::Handler *)NULL);
#endif
if (!port.Open()) {
fprintf(stderr, "Failed to open COM port\n");
return EXIT_FAILURE;
}
ConsoleOperationEnvironment env;
const struct DeviceRegister *driver = FindDriverByName(driver_name);
if (driver == NULL) {
fprintf(stderr, "No such driver: %s\n", argv[1]);
args.UsageError();
}
if (!driver->IsLogger()) {
fprintf(stderr, "Not a logger driver: %s\n", argv[1]);
args.UsageError();
}
assert(driver->CreateOnPort != NULL);
Device *device = driver->CreateOnPort(config, port);
assert(device != NULL);
if (!device->Open(env)) {
delete device;
fprintf(stderr, "Failed to open driver: %s\n", argv[1]);
return EXIT_FAILURE;
}
if (!device->EnableDownloadMode()) {
delete device;
fprintf(stderr, "Failed to enable download mode\n");
return EXIT_FAILURE;
}
RecordedFlightList flight_list;
if (!device->ReadFlightList(flight_list, env)) {
device->DisableDownloadMode();
delete device;
fprintf(stderr, "Failed to download flight list\n");
return EXIT_FAILURE;
}
if (flight_list.empty()) {
device->DisableDownloadMode();
delete device;
fprintf(stderr, "Logger is empty\n");
return EXIT_FAILURE;
}
PrintFlightList(flight_list);
if (flight_id >= flight_list.size()) {
device->DisableDownloadMode();
delete device;
fprintf(stderr, "Flight id not found\n");
return EXIT_FAILURE;
}
if (!device->DownloadFlight(flight_list[flight_id], path, env)) {
device->DisableDownloadMode();
delete device;
fprintf(stderr, "Failed to download flight\n");
return EXIT_FAILURE;
}
device->DisableDownloadMode();
delete device;
//.........这里部分代码省略.........
示例6: main
int main(int argc, char **argv)
{
NarrowString<1024> usage;
usage = "DRIVER PORT BAUD FILE.igc [FLIGHT NR]\n\n"
"Where DRIVER is one of:";
{
const DeviceRegister *driver;
for (unsigned i = 0; (driver = GetDriverByIndex(i)) != NULL; ++i) {
if (driver->IsLogger()) {
WideToUTF8Converter driver_name(driver->name);
usage.AppendFormat("\n\t%s", (const char *)driver_name);
}
}
}
Args args(argc, argv, usage);
tstring driver_name = args.ExpectNextT();
const DeviceConfig config = ParsePortArgs(args);
PathName path(args.ExpectNext());
unsigned flight_id = args.IsEmpty() ? 0 : atoi(args.GetNext());
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;
const struct DeviceRegister *driver = FindDriverByName(driver_name.c_str());
if (driver == NULL) {
fprintf(stderr, "No such driver: %s\n", argv[1]);
args.UsageError();
}
if (!driver->IsLogger()) {
fprintf(stderr, "Not a logger driver: %s\n", argv[1]);
args.UsageError();
}
assert(driver->CreateOnPort != NULL);
Device *device = driver->CreateOnPort(config, *port);
assert(device != NULL);
RecordedFlightList flight_list;
if (!device->ReadFlightList(flight_list, env)) {
delete device;
delete port;
fprintf(stderr, "Failed to download flight list\n");
return EXIT_FAILURE;
}
if (flight_list.empty()) {
delete device;
delete port;
fprintf(stderr, "Logger is empty\n");
return EXIT_FAILURE;
}
PrintFlightList(flight_list);
if (flight_id >= flight_list.size()) {
delete device;
delete port;
fprintf(stderr, "Flight id not found\n");
return EXIT_FAILURE;
}
if (!device->DownloadFlight(flight_list[flight_id], path, env)) {
delete device;
delete port;
fprintf(stderr, "Failed to download flight\n");
return EXIT_FAILURE;
}
delete device;
delete port;
DeinitialiseIOThread();
printf("Flight downloaded successfully\n");
return EXIT_SUCCESS;
}