本文整理汇总了C++中Port::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ Port::Write方法的具体用法?C++ Port::Write怎么用?C++ Port::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Port
的用法示例。
在下文中一共展示了Port::Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sprintf
static void
WriteWithChecksum(Port &port, const char *String)
{
port.Write(String);
char sTmp[8];
sprintf(sTmp, "%02X\r\n", ::NMEAChecksum(String));
port.Write(sTmp);
}
示例2:
void
LX::CommandModeQuick(Port &port, OperationEnvironment &env)
{
port.Write(SYN);
env.Sleep(500);
port.Write(SYN);
env.Sleep(500);
port.Write(SYN);
env.Sleep(500);
}
示例3: EWMicroRecorderPrintf
bool
EWMicroRecorderDevice::Declare(const Declaration *decl)
{
// Must have at least two, max 12 waypoints
if (decl->size() < 2 || decl->size() > 12)
return false;
port->StopRxThread();
port->SetRxTimeout(500); // set RX timeout to 500[ms]
if (!TryConnect())
return false;
port->Write('\x18'); // start to upload file
port->Write(user_data);
EWMicroRecorderPrintf(port, _T("%-15s %s\r\n"),
_T("Pilot Name:"), decl->PilotName);
EWMicroRecorderPrintf(port, _T("%-15s %s\r\n"),
_T("Competition ID:"), decl->AircraftRego);
EWMicroRecorderPrintf(port, _T("%-15s %s\r\n"),
_T("Aircraft Type:"), decl->AircraftType);
port->Write("Description: Declaration\r\n");
for (unsigned i = 0; i < 11; i++) {
if (i+1>= decl->size()) {
EWMicroRecorderPrintf(port, _T("%-17s %s\r\n"),
_T("TP LatLon:"), _T("0000000N00000000E TURN POINT\r\n"));
} else {
const Waypoint &wp = decl->waypoints[i];
if (i == 0) {
EWMicroRecorderWriteWayPoint(port, wp, _T("Take Off LatLong:"));
EWMicroRecorderWriteWayPoint(port, wp, _T("Start LatLon:"));
} else if (i + 1 < decl->size()) {
EWMicroRecorderWriteWayPoint(port, wp, _T("TP LatLon:"));
}
}
}
const Waypoint &wp = decl->waypoints[decl->size() - 1];
EWMicroRecorderWriteWayPoint(port, wp, _T("Finish LatLon:"));
EWMicroRecorderWriteWayPoint(port, wp, _T("Land LatLon:"));
port->Write('\x03'); // finish sending user file
bool success = ExpectStringWait(port, "uploaded successfully");
port->Write("!!\r\n"); // go back to NMEA mode
port->SetRxTimeout(0); // clear timeout
port->StartRxThread(); // restart RX thread
return success;
}
示例4:
void
DeviceDescriptor::ForwardLine(const char *line)
{
/* XXX make this method thread-safe; this method can be called from
any thread, and if the Port gets closed, bad things happen */
if (IsNMEAOut() && port != nullptr) {
Port *p = port;
p->Write(line);
p->Write("\r\n");
}
}
示例5:
bool
CaiGpsNavDevice::Open(OperationEnvironment &env)
{
port->Write(CtrlC);
env.Sleep(50);
port->Write("NMEA\r");
// This is for a slightly different mode, that
// apparently outputs pressure info too...
//port->Write("PNP\r\n");
//port->Write("LOG 0\r\n");
return true;
}
示例6:
bool
Volkslogger::SendCommand(Port &port, OperationEnvironment &env,
Command cmd, uint8_t param1, uint8_t param2)
{
static constexpr unsigned delay = 2;
/* flush buffers */
if (!port.FullFlush(env, 20, 100))
return false;
/* reset command interpreter */
if (!Reset(port, env, 6))
return false;
/* send command packet */
const uint8_t cmdarray[8] = {
(uint8_t)cmd, param1, param2,
0, 0, 0, 0, 0,
};
if (!port.Write(ENQ))
return false;
env.Sleep(delay);
if (!SendWithCRC(port, cmdarray, sizeof(cmdarray), env))
return false;
/* wait for confirmation */
return port.WaitRead(env, 4000) == Port::WaitResult::READY &&
port.GetChar() == 0;
}
示例7: while
bool
Volkslogger::WriteBulk(Port &port, OperationEnvironment &env,
const void *buffer, unsigned length)
{
const unsigned delay = 1;
env.SetProgressRange(length);
uint16_t crc16 = 0;
const uint8_t *p = (const uint8_t *)buffer, *end = p + length;
while (p < end) {
unsigned n = end - p;
if (n > 400)
n = 400;
n = port.Write(p, n);
if (n == 0)
return false;
crc16 = UpdateCRC16CCITT(p, n, crc16);
p += n;
env.SetProgressPosition(p - (const uint8_t *)buffer);
/* throttle sending a bit, or the Volkslogger's receive buffer
will overrun */
env.Sleep(delay * 100);
}
return port.Write(crc16 >> 8) && port.Write(crc16 & 0xff);
}
示例8: strchr
static void
EWMicroRecorderPrintf(Port &port, const TCHAR *fmt, ...)
{
TCHAR EWStr[128];
va_list ap;
va_start(ap, fmt);
_vstprintf(EWStr, fmt, ap);
va_end(ap);
#ifdef _UNICODE
char buffer[256];
if (::WideCharToMultiByte(CP_ACP, 0, EWStr, -1, buffer, sizeof(buffer),
NULL, NULL) <= 0)
return;
#else
char *buffer = EWStr;
#endif
char *p = strchr(buffer, ':');
if (p != NULL)
++p;
else
p = buffer;
for (; *p != 0; ++p)
if (!IsValidEWChar(*p))
*p = ' ';
port.Write(buffer);
}
示例9: timeout
static bool
TryConnect(Port &port, char *user_data, size_t max_user_data,
OperationEnvironment &env)
{
port.Flush();
port.Write('\x02'); // send IO Mode command
unsigned user_size = 0;
TimeoutClock timeout(8000);
while (true) {
int remaining = timeout.GetRemainingSigned();
if (remaining < 0)
return false;
if (port.WaitRead(env, remaining) != Port::WaitResult::READY)
return false;
int nbytes = port.Read(user_data + user_size, max_user_data - user_size);
if (nbytes < 0)
return false;
if (user_size == 0) {
const char *minus = (const char *)memchr(user_data, '-', nbytes);
if (minus == NULL)
continue;
user_size = user_data + nbytes - minus;
memmove(user_data, minus, user_size);
} else
user_size += nbytes;
char *end = (char *)memchr(user_data, '\x13', user_size);
if (end != NULL) {
*end = 0;
port.Write('\x16');
return true;
}
if (user_size >= max_user_data)
/* response too large */
return false;
}
return false;
}
示例10: sprintf
bool
XCOM760Device::PutVolume(int Volume)
{
char szTmp[32];
sprintf(szTmp, "$RVOL=%d\r\n", Volume);
port->Write(szTmp);
return true;
}
示例11: timeout
bool
FLARM::SendEscaped(Port &port, const void *buffer, size_t length,
OperationEnvironment &env, unsigned timeout_ms)
{
assert(buffer != nullptr);
assert(length > 0);
const TimeoutClock timeout(timeout_ms);
// Send data byte-by-byte including escaping
const uint8_t *p = (const uint8_t *)buffer, *end = p + length;
while (true) {
const uint8_t *special = FindSpecial(p, end);
if (special > p) {
/* bulk write of "harmless" characters */
if (!port.FullWrite(p, special - p, env, timeout.GetRemainingOrZero()))
return false;
p = special;
}
if (p == end)
break;
// Check for bytes that need to be escaped and send
// the appropriate replacements
bool result;
if (*p == START_FRAME)
result = port.Write(ESCAPE) && port.Write(ESCAPE_START);
else if (*p == ESCAPE)
result = port.Write(ESCAPE) && port.Write(ESCAPE_ESCAPE);
else
// Otherwise just send the original byte
result = port.Write(*p);
if (!result)
return false;
p++;
}
return true;
}
示例12: SendCommand
bool
LX::SendPacket(Port &port, Command command,
const void *data, size_t length,
OperationEnvironment &env, unsigned timeout_ms)
{
return SendCommand(port, command) &&
port.FullWrite(data, length, env, timeout_ms) &&
port.Write(calc_crc(data, length, 0xff));
}
示例13: SendCommand
bool
LX::SendPacket(Port &port, Command command,
const void *data, size_t length,
OperationEnvironment &env,
std::chrono::steady_clock::duration timeout)
{
return SendCommand(port, command) &&
port.FullWrite(data, length, env, timeout) &&
port.Write(calc_crc(data, length, 0xff));
}
示例14: WriteLabel
static bool
EWMicroRecorderWriteWaypoint(Port &port, const char *type,
const Waypoint &way_point)
{
return WriteLabel(port, type) &&
WriteGeoPoint(port, way_point.location) &&
port.Write(' ') &&
WriteCleanString(port, way_point.name.c_str(), 1000) &&
port.FullWrite("\r\n", 2, 500);
}
示例15: while
static bool
TryConnect(Port &port, char *user_data)
{
int retries=10;
while (--retries){
port.Write('\x02'); // send IO Mode command
unsigned user_size = 0;
bool started = false;
PeriodClock clock;
clock.update();
int i;
while ((i = port.GetChar()) != EOF && !clock.check(8000)) {
char ch = (char)i;
if (!started && ch == '-')
started = true;
if (started) {
if (ch == 0x13) {
port.Write('\x16');
user_data[user_size] = 0;
// found end of file
return true;
} else {
if (user_size < sizeof(user_data) - 1) {
user_data[user_size] = ch;
user_size++;
}
}
}
}
}
return false;
}