本文整理汇总了C++中Serial::getc方法的典型用法代码示例。如果您正苦于以下问题:C++ Serial::getc方法的具体用法?C++ Serial::getc怎么用?C++ Serial::getc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serial
的用法示例。
在下文中一共展示了Serial::getc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
Serial *pc = new Serial(USBTX, USBRX);
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(serial_nc_tx_auto);
MBED_HOSTTEST_DESCRIPTION(Serial NC TX);
MBED_HOSTTEST_START("MBED_38");
// Wait until we receive start signal from host test
char c = pc->getc();
delete pc;
// If signal is correct, start the test
if (c == 'S') {
Serial *pc = new Serial(USBTX, NC);
pc->printf("TX OK - Expected\r\n");
wait(0.5); // wait for characters to finish transmitting
delete pc;
pc = new Serial(NC, USBRX);
pc->printf("TX OK - Unexpected\r\n");
wait(0.5); // wait for characters to finish transmitting
delete pc;
}
while (1) {
}
}
示例2: main
int main() {
Serial *pc = new Serial(USBTX, USBRX);
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(serial_nc_rx_auto);
MBED_HOSTTEST_DESCRIPTION(Serial NC RX);
MBED_HOSTTEST_START("MBED_37");
char c = pc->getc();
// This should be true, sync the start of test
if (c == 'S') {
pc->printf("RX OK - Start NC test\r\n");
// disconnect TX and get char
delete pc;
pc = new Serial(NC, USBRX);
c = pc->getc();
if (c == 'E') {
// ok disconnect Rx and answer to host
delete pc;
pc = new Serial(USBTX, NC);
pc->printf("RX OK - Expected\r\n");
c = pc->getc();
// This should be false/not get here
if (c == 'U') {
pc->printf("RX OK - Unexpected\r\n");
}
}
delete pc;
}
while (1) {
}
}
示例3: rxInterruptLoop
/* This function is invoked whenever new data is received. Such new data
includes both the actual message sent from as well as all control messages,
such as "CSQ:"
Currently, this is the function in which you may read out the actual (SBDRB)
message and perform appropriate tasks.
*/
void rxInterruptLoop(const void *_serial, const void *_sbd) {
Serial *serial = (Serial *)_serial;
IridiumSBD2 *sbd = (IridiumSBD2 *)_sbd;
if (millis_time() - sbd->getStartTime() > 1000UL * sbd->getDuration()) {
// Last message received timeout, and need to reset state
// drop message
return;
}
bool terminated = false; /* This is used to check if the current set of recvd
bytes is the end of a full control message, which
will trigger subsequent control actions.
*/
while (serial->readable()) { // serial == nss (main.cpp)
char c = (char) serial->getc();
sbd->console(c);
char *prompt = sbd->getPrompt();
char *terminator = sbd->getTerminator();
if (prompt) {
int matchPromptPos = sbd->getMatchPromptPos();
switch(sbd->getPromptState()) {
case 0: // matching prompt
if (c == prompt[matchPromptPos]) {
matchPromptPos++;
sbd->setMatchPromptPos(matchPromptPos);
if (prompt[matchPromptPos] == '\0') {
sbd->setPromptState(1);
}
} else {
matchPromptPos = c == prompt[0] ? 1 : 0; /* try to match prompt,
if current char matches,
then move on to next char
to match
*/
sbd->setMatchPromptPos(matchPromptPos);
}
break;
case 1: // gathering reponse from end of prompt to first
int responseSize = sbd->getResponseSize();
if (responseSize > 0) {
if (c == '\r' || responseSize < 2) {
sbd->setPromptState(2);
} else {
(sbd->getRxBuffer())->insert(c);
// rxBuffer (only put in actual response,
// no prompt/terminator in buffer
responseSize--;
sbd->setResponseSize(responseSize);
}
}
break;
}
}
if (sbd->getCompletionNum() == processSBDRBResponsNum) {
(sbd->getRxBuffer())->insert(c);
messageBuffer.insert(c);
}
// If there is no prompt, then just keep trying to match the terminator
// until either all terminator characters are
// matched (return true), or no more serial to read (return false)
int matchTerminatorPos = sbd->getMatchTerminatorPos();
if (terminator) {
if (c == terminator[matchTerminatorPos]) {
matchTerminatorPos++;
sbd->setMatchTerminatorPos(matchTerminatorPos);
if (terminator[matchTerminatorPos] == '\0') {
terminated = true;
}
} else {
matchTerminatorPos = c == terminator[0] ? 1 : 0;
sbd->setMatchTerminatorPos(matchTerminatorPos);
}
}
} // while (serial.available())
if (sbd->checkCompletion(terminated) && sbd->getCompletionNum() == processSBDRBResponsNum) {
char c;
int nBytes = sbd->getResponseSize() - 4; /* -4 because we are currently
seeing the four bytes missing
on most cases, though not always
consistent.
*/
/* NOTE: THIS IS WHERE YOU MAY DECIDE WHAT ACTIONS/TASKS TO ENQUE FOR
RECEIVING DIFFERENT TYPES OF MESSAGES FROM SBDRB */
if (nBytes > 0) {
printf("I RECEIVED A MESSAGE :) \n");
}
for (int i = 0; i < nBytes; i++) {
//.........这里部分代码省略.........