void loop() { while(!triggerFlag) { if(debug) Serial << "Trigger flag is false, driving" << endl; drive(); } if(triggerFlag) { if(debug) Serial << "Trigger flag is set, sending outgoing interrupt" << endl; // Send the flag to receive the message digitalWrite(interruptOutgoing, HIGH); // Check if it's getting the message if(nextByte() == 'E') { // Show that we received the message if(debug) Serial << "Received the message" << endl; digitalWrite(LED, HIGH); delay(2000); digitalWrite(LED, LOW); triggerFlag = false; } delay(50); digitalWrite(interruptOutgoing, LOW); } }
addressType evaluateUnop(void) { int op; addressType arg; nextByte(op); arg = evaluateExpression(); switch(intOp(op)) { case UNARY_MINUS: return(-arg); case LOGICAL_NOT: return(!arg); case BITWISE_NOT: return(~arg); case HI_BYTE: return((arg & 0xFF00) >> 8); case LO_BYTE: return(arg & 0xFF); } }
addressType evaluateFunctionCall(void) { expressionPCType savePoint; functionType *theFunction; int argCount; bindingListType *saveBindings; theFunction = getFunction(); nextByte(argCount); saveBindings = localBindings; localBindings = NULL; bindFunctionArguments(theFunction, argCount); savePoint = pc; pc = theFunction->functionBody; evaluateExpression(); undoBindings(); localBindings = saveBindings; pc = savePoint; if (hitFreturn) { hitFreturn = FALSE; return(functionResult); } else return(0); }
void putSymbolPointersIntoFunctionCall(void) { int argCount; instantiateFunction(); nextByte(argCount); while (argCount-- > 0) putSymbolPointersIntoExpression(); }
void putSymbolPointersIntoBuiltinFunctionCall(void) { int argCount; overNumber(); nextByte(argCount); while (argCount-- > 0) putSymbolPointersIntoExpression(); }
void skipFunctionCall(void) { int argCount; overFunction(); nextByte(argCount); while (argCount-- > 0) skipExpression(); }
int readByte(FILE* file) { int value = -1; if (fscanf(file, "%i", &value) == 1) { nextByte(value); } return value; }
int readInt(FILE* file) { int value = -1; if (fscanf(file, "%i", &value) == 1) { int tmp = value; for (int i = 0; i < 4; i++) { nextByte(tmp); tmp >>= 8; } }
addressType evaluateBuiltinFunctionCall(void) { int theFunction; int argCount; theFunction = getNumber(); nextByte(argCount); if (theFunction<0 || MAX_FUNCTIONS<=theFunction) { printf("illegal built-in function #%d\n", theFunction); chokePukeAndDie(); } return((*builtInFunctionTable[theFunction].functionEntry)(argCount)); }
addressType evaluatePreop(void) { int op; symbolType *target; nextByte(op); target = getSymbol(); switch (intOp(op)) { case INCREMENT: return(++target->symbolValue); case DECREMENT: return(--target->symbolValue); } }
void LexBase::nextChar() throw(ConfigurationException) { char ch; int status; wchar_t wChar; m_ch.reset(); status = -1; while (status == -1) { ch = nextByte(); if (m_atEOF && !m_ch.isEmpty()) { StringBuffer msg; msg << "Invalid multi-byte character on line " << m_lineNum; throw ConfigurationException(msg.c_str()); } if (m_atEOF) { //-------- // At EOF. Our work is done. //-------- break; } if (!m_ch.add(ch)) { StringBuffer msg; msg << "Invalid multi-byte character on line " << m_lineNum; throw ConfigurationException(msg.c_str()); } status = mbrtowc(&wChar, m_ch.c_str(), m_ch.length(), &m_mbtowcState); if (status == -1 && m_ch.isFull()) { StringBuffer msg; msg << "Invalid multi-byte character on line " << m_lineNum; throw ConfigurationException(msg.c_str()); } m_ch.setWChar(wChar); } if (m_ch == '\n') { m_lineNum ++; } }
bool ControlSeqParser::nextChar() { unsigned char c; while (0 != (c = nextByte())) { switch (m_mode) { case MODE_UTF8: if (0 == m_utf8_remlen) { m_currentChar = 0; m_utf8_seqlen = 1; /* new char */ if (0 == (c & 0x80)) { m_currentChar = c; } else if (0xC0 == (c & 0xFE)) { continue; /* 0xCO / 0xC1 overlong */ } else if (0xC0 == (c & 0xE0)) { m_utf8_seqlen = 2; m_currentChar = c & 0x1f; } else if (0xE0 == (c & 0xF0)) { m_utf8_seqlen = 3; m_currentChar = c & 0x0f; } /* only 16-bit, seqlen 4 not supported */ /* else if (0xF0 == (c & 0xF8)) { m_utf8_seqlen = 4; code = c & 0x07; } */ else continue; /* skip invalid byte */ m_utf8_remlen = m_utf8_seqlen - 1; } else { if (0x80 != (c & 0xC0)) { m_utf8_remlen = 0; /* skip invalid bytes */ continue; } m_currentChar = (m_currentChar << 6) | (c & 0x3f); --m_utf8_remlen; } if (0 == m_utf8_remlen) { /* char complete */ if ((3 == m_utf8_seqlen) && (m_currentChar < 0x800)) return false; /* overlong */ return true; } break; case MODE_7BIT: case MODE_8BIT: default: m_currentChar = c; return true; } } return false; }
int srecLoad(FILE *fp, char *buf, int bufLen, int *entry) { static unsigned char addrLens[] = { 2, 2, 3, 4, 0, 2, 0, 4, 3, 2 }; char line[1 + 1 + 2 + 255*2 + 1]; char dataBytes[255], *p; int dataLen, dataRecs; char *s; int type, x, addrLen, byteCount, byteTotal; int addr; unsigned char chkSum; memset(buf, 0, bufLen); *entry = 0; dataRecs = 0; byteTotal = 0; while (fgets(line, sizeof (line), fp) != 0) { s = line; chkSum = 0; if (*s++ != 'S') continue; type = *s++; if (type < '0' || type > '9') return SREC_ERROR_FORMAT; addrLen = addrLens[type - '0']; if ((byteCount = nextByte(&s)) < 0) return SREC_ERROR_FORMAT; chkSum = (unsigned char) byteCount; byteCount -= addrLen; if (byteCount < 1) return SREC_ERROR_FORMAT; /* Need at least addr and checksum */ addr = 0; while (addrLen--) { if ((x = nextByte(&s)) < 0) return SREC_ERROR_TRUNC; addr = addr << 8 | x; chkSum += (unsigned char) x; } p = dataBytes; dataLen = byteCount - 1; while (byteCount-- > 1) { if ((x = nextByte(&s)) < 0) return SREC_ERROR_TRUNC; *p++ = (char) x; chkSum += (unsigned char) x; } if ((x = nextByte(&s)) < 0) return SREC_ERROR_TRUNC; chkSum += (unsigned char) x; if (chkSum != (unsigned char) 0xff) return SREC_ERROR_CHECKSUM; switch (type) { case '0': /* Header record */ dataRecs = 0; break; case '5': /* Record count */ if (addr != dataRecs) return SREC_ERROR_NRECORDS; break; /* Ignore */ case '1': /* 2-byte address with data */ case '2': /* 3-byte address with data */ case '3': /* 4-byte address with data */ if (addr < 0 || addr + dataLen > bufLen){ printf("addr=0x%x, addr+dataLen=0x%x, bufLen=%d\n", addr, addr + dataLen, bufLen); return SREC_ERROR_ADDR; } memcpy(buf + addr, dataBytes, dataLen); byteTotal += dataLen; dataRecs++; break; case '7': /* Termination with 4-byte address */ case '8': /* Termination with 3-byte address */ case '9': /* Termination with 2-byte address */ *entry = addr; dataRecs = 0; break; default: return SREC_ERROR_FORMAT; } } return byteTotal; }
addressType evaluateBinop(void) { int op; symbolType *leftSymbol; addressType left; addressType right; nextByte(op); if (intOp(op) == ASSIGN) { leftSymbol = getSymbol(); } else { left = evaluateExpression(); } right = evaluateExpression(); switch (intOp(op)) { case ASSIGN: leftSymbol->symbolValue = right; return(right); case LOGICAL_OR: return(left || right); case LOGICAL_XOR: return((left && !right) || (!left && right)); case LOGICAL_AND: return(left && right); case BITWISE_OR: return(left | right); case BITWISE_XOR: return(left ^ right); case BITWISE_AND: return(left & right); case EQUAL_TO: return(left == right); case NOT_EQUAL_TO: return(left != right); case LESS_THAN: return(left < right); case LESS_THAN_OR_EQUAL_TO: return(left <= right); case GREATER_THAN: return(left > right); case GREATER_THAN_OR_EQUAL_TO: return(left >= right); case LEFT_SHIFT: return(left << right); case RIGHT_SHIFT: return(left >> right); case ADD: return(left + right); case SUB: return(left - right); case MUL: return(left * right); case DIV: return(left / right); case MOD: return(left % right); } }