/** * Dispatches attached callbacks based on command */ void CmdMessenger::handleMessage() { lastCommandId = readIntArg(); // if command attached, we will call it if (lastCommandId >= 0 && lastCommandId < MAXCALLBACKS && ArgOk && callbackList[lastCommandId] != NULL) (*callbackList[lastCommandId])(); else // If command not attached, call default callback (if attached) if (default_callback!=NULL) (*default_callback)(); }
/** * Processes a byte and determines if an acknowlegde has come in */ bool CmdMessenger::processAndWaitForAck(int serialByte, int AckCommand) { //*comms << "1, processAndWaitForAck,"; int messageState = processLine(serialByte); if ( messageState == kEndOfMessage ) { int id = readIntArg(); if (AckCommand==id && ArgOk) { //*comms << " matched! ;" << endl; return true; } else { //*comms << " unmatched;" << endl; return false; } } //*comms << "No command;" << endl; return false; }
/** * Loops as long data is available to determine if acknowledge has come in */ bool CmdMessenger::CheckForAck(int AckCommand) { while ( comms->available() ) { //Processes a byte and determines if an acknowlegde has come in int messageState = processLine(comms->read()); if ( messageState == kEndOfMessage ) { int id = readIntArg(); if (AckCommand==id && ArgOk) { return true; } else { return false; } } return false; } return false; }
/** * Read the next argument as bool */ bool CmdMessenger::readBoolArg() { return (readIntArg()!=0)?true:false; }