void ArNMEAParser::nextField() { currentMessage.push_back(currentField); currentField = ""; if (currentMessage.size() > MaxNumFields) endMessage(); }
void comms_main() { sendMessage(1); sendDataByte('G'); sendDataByte('O'); endMessage(); uartTransmit(0x54); uartTransmit(0xff); }
Bundle& Bundle::endFinal() { endMessage(); if(pCompLengthReplace_) { _endMessage(pCompLengthReplace_,InterfaceElement::s_compIE); pCompLengthReplace_ = NULL; } comp_ = 0; curReplyID_ = 0; return *this; }
void SMessageCoder::feed( const char data ) { if (m_escaping) { feedByte(data); m_escaping = false; } else if (data == m_escaper) { m_escaping = true; } else if (data == m_delimiter) { endMessage(); } else { feedByte(data); } }
void packetNotifyReceive(byte *data, byte length) { int i; printTime(); printf("master %d received packet:", address); for(i = 0; i < length; i++) printf(" %02x", data[i]); printf("\n"); fflush(stdout); if (!strncmp(data, "A", length)) { reply(); sendDataByte('B'); endMessage(); } else releaseReceiveBuffer(); }
void BlockingUDPTransport::enqueueSendRequest(TransportSender::shared_pointer const & sender) { Lock lock(_sendMutex); _sendToEnabled = false; _sendBuffer->clear(); sender->lock(); try { sender->send(_sendBuffer.get(), this); sender->unlock(); endMessage(); if(!_sendToEnabled) send(_sendBuffer.get()); else send(_sendBuffer.get(), _sendTo); } catch(...) { sender->unlock(); } }
int main(void) { /* Welcome Message*/ GWindow window = newGWindow(WIDTH, HEIGHT); // instantiates a window setWindowTitle(window, "Tic-Tac-Toe"); welcome(window); /* Mode Selection */ int mode = selectMode(window); /* Show Rules */ showRules(mode, window); /* Play Game */ play(mode, window); /* End Message */ endMessage(window); waitForClick(); closeGWindow(window); return 0; }
AREXPORT int ArNMEAParser::parse(const char *buf, int n) { int result = 0; if (n < 0) { return result|ParseError; } if (n == 0) { return result|ParseFinished; } #ifdef DEBUG_ARNMEAPARSER std::cerr << "\t[ArNMEAParser: given " << n << " bytes of data.]\n"; std::cerr << "\t[ArNMEAParser: parsing chunk \""; ArNMEAParser_printBuf(stderr, buf, n); std::cerr << "\"]\n"; #endif for (int i = 0; i < n; i++) { // Check for message start if (buf[i] == '$') { beginMessage(); continue; } // Otherwise, we must be in a sentece to do anything if (!inMessage) continue; // Reached the CRLF at the end? if (buf[i] == '\r') { gotCR = true; continue; } if (buf[i] == '\n') { if (gotCR) { Message msg; msg.message = ¤tMessage; msg.timeParseStarted = currentMessageStarted; HandlerMap::iterator h = myHandlers.find(currentMessage[0]); if (h != myHandlers.end()) { #ifdef DEBUG_ARNMEAPARSER fprintf(stderr, "\t[ArNMEAParser: Got complete message, calling handler for %s...]\n", currentMessage[0].c_str()); #endif h->second->invoke(msg); result |= ParseUpdated; } endMessage(); } // a syntax error or no data, abort the message and start looking for the next one. if(currentField != "") ArLog::log(ArLog::Normal, "ArNMEAParser: Warning: NMEA parse error (currentField=\"%s\"), resetting parser.", currentField.c_str()); endMessage(); continue; } // Are we in the final checksum field? if (inChecksum) { checksumBuf[checksumBufOffset++] = buf[i]; if (checksumBufOffset > 1) // two bytes of checksum { int checksumRec = (int) strtol(checksumBuf, NULL, 16); if (checksumRec != currentChecksum) { ArLog::log(ArLog::Normal, "%s: Warning: Skipping message with incorrect checksum.", myName); std::string nmeaText = ""; for(MessageVector::const_iterator i = currentMessage.begin(); i != currentMessage.end(); ++i) { if(i != currentMessage.begin()) nmeaText += ","; nmeaText += *i; } ArLog::log(ArLog::Normal, "%s: Message provided checksum \"%s\" = 0x%x (%d). Calculated checksum is 0x%x (%d). NMEA message ID was: \"%s\"", myName, checksumBuf, checksumRec, checksumRec, currentChecksum, currentChecksum, nmeaText.c_str()); // abort the message and start looking for the next one. endMessage(); } } continue; } // Got to the checksum? if (buf[i] == '*') { nextField(); if (!ignoreChecksum) beginChecksum(); continue; } // Every byte in a message between $ and * XORs to form the // checksum: currentChecksum ^= buf[i]; // Time to start a new field? if (buf[i] == ',') { nextField(); continue; } // Else, we must be in the middle of a field // TODO we could use strchr to look ahead in the buf // for the end of the field (',' or '*') or end of the buf, and copy more // than one byte at a time. currentField += buf[i]; if (currentField.size() > MaxFieldSize) { endMessage(); continue; } } return result; }
void POExtractor::handleLine(const char* data, uint32_t length) { if (state == ERROR) return; if (state == WHITESPACE) { if (length == 0) return; if (data[0] != '#') { state = COMMENT; //this allows PO files w/o comments } else { handleComment(data, length); return; } } if (state == COMMENT) { if (length == 0) { state = WHITESPACE; } else if (data[0] == '#') { handleComment(data, length); } else if (length > 7 && strncmp("msgctxt", data, 7) == 0) { state = MSGCTXT; } else if (length > 7 && strncmp("msgid \"", data, 7) == 0) { state = MSGID; } else { state = ERROR; } return; } else if (length > 1 && data[0] == '"' && data[length-1] == '"' && (state == MSGCTXT || state == MSGID || state == MSGSTR || state == MSGID_PLURAL)) { // continued text field isTranslated = state == MSGSTR && length > 2; } else if (state == MSGCTXT && length > 7 && strncmp("msgid \"", data, 7) == 0) { state = MSGID; } else if (state == MSGID && length > 14 && strncmp("msgid_plural \"", data, 14) == 0) { state = MSGID_PLURAL; } else if ((state == MSGID || state == MSGID_PLURAL || state == MSGSTR) && length > 8 && strncmp("msgstr", data, 6) == 0) { state = MSGSTR; isTranslated = strncmp(data+length-3, " \"\"", 3) != 0; } else if (state == MSGSTR) { if (length == 0) { endMessage(); } else if (data[0]=='#' || data[0]=='m') { //allow PO without empty line between entries endMessage(); state = COMMENT; handleLine(data, length); } else { state = ERROR; } } else { state = ERROR; } #if 0 if (messages > 1 || state != MSGSTR) return; // handle special values in the first messsage // assumption is that value takes up only one line if (strncmp("\"POT-Creation-Date: ", data, 20) == 0) { result->add(Property::TranslationTemplateDate, QByteArray(data + 20, length - 21)); } else if (strncmp("\"PO-Revision-Date: ", data, 19) == 0) { result->add(Property::TranslationLastUpDate, QByteArray(data + 19, length - 20)); } else if (strncmp("\"Last-Translator: ", data, 18) == 0) { result->add(Property::TranslationLastAuthor, QByteArray(data + 18, length - 19)); } #endif }