unsigned int HexFileParser::parseHexWord(const std::string& line, int idx) { unsigned char b1, b2; b1 = parseHexByte(line, idx); b2 = parseHexByte(line, idx + 2); return (b1 << 8) | b2; }
void parseMacOUI(char *str, unsigned char *addr) { addr[0] = parseHexByte(str[0], str[1]); addr[1] = parseHexByte(str[3], str[4]); addr[2] = parseHexByte(str[6], str[7]); printMsg("read mac OUI: %02x:%02x:%02x\n", addr[0], addr[1], addr[2]); }
static void parseMacAddress(const char *str, mac_addr addr) { addr[0] = parseHexByte(str); addr[1] = parseHexByte(str); addr[2] = parseHexByte(str); addr[3] = parseHexByte(str); addr[4] = parseHexByte(str); addr[5] = parseHexByte(str); }
bool HexFileParser::processLine(const std::string& line) { if (line[0] != ':') { std::cerr << "Line does not start with ':'" << std::endl << line << std::endl; return false; } unsigned char lineSize = parseHexByte(line, 1); unsigned int addr = parseHexWord(line, 3); unsigned char recordType = parseHexByte(line, 7); if (recordType == 4) { baseAddress_ = parseHexWord(line, 9) << 16; } else if (recordType == 0) { Record r; r.adress_ = baseAddress_ + addr; r.size_ = lineSize; r.data_ = new unsigned char[lineSize]; for(int idx = 0; idx < lineSize; idx++) { r.data_[idx] = parseHexByte(line, 9 + idx*2); } content_.push_back(r); } else if (recordType == 1) { // Ignore EOF record. } else { std::cerr << "Unknown record type" << recordType << std::endl << line << std::endl; return false; } return true; }
void parseMacAddress(const char *str, mac_addr addr) { addr[0] = parseHexByte(str[0], str[1]); addr[1] = parseHexByte(str[3], str[4]); addr[2] = parseHexByte(str[6], str[7]); addr[3] = parseHexByte(str[9], str[10]); addr[4] = parseHexByte(str[12], str[13]); addr[5] = parseHexByte(str[15], str[16]); // printMsg("read mac addr: %02x:%02x:%02x:%02x:%02x:%02x\n", addr[0], // addr[1], addr[2], addr[3], addr[4], addr[5]); }
// process one parsed CAN bus command static void processCanCmd (void) { uint32_t addr = parseHexNum(); char sep = canCmdBuf[canCmdFill++]; chprintf(chp1, "CAN: 0x%x %d\r\n", addr, sep); if (sep == '#') { CANTxFrame txMsg; txMsg.IDE = addr < 0x800 ? CAN_IDE_STD : CAN_IDE_EXT; txMsg.EID = addr; txMsg.DLC = 0; if (canCmdBuf[canCmdFill] == 'R') txMsg.RTR = CAN_RTR_REMOTE; else { txMsg.RTR = CAN_RTR_DATA; while (canCmdBuf[canCmdFill] > ' ' && txMsg.DLC < 8) txMsg.data8[txMsg.DLC++] = parseHexByte(); } canTransmit(&CAND1, 1, &txMsg, 100); } }
int drawString( int x , const char *s , chartype *font ) { int strech =1; int padding = DEFAULT_CHAR_PADDING; int xoffset=0; while (*s) { if ( *s == '*' ) { s++; switch (*s) { case '*': { // Two *'s just means escape out a single * s++; xoffset += draw5x7(x+xoffset, '*' , strech , font ); xoffset += padding; } break; case 'X': { // Hex code s++; if (*s && isxdigit(*s) && isxdigit( *(s+1) )) { unsigned char hexcode = parseHexByte( s ); s+=2; xoffset+=draw5x7( x+xoffset , hexcode , strech , font ); xoffset += padding; } else { xoffset += drawString( x+xoffset , " [ERR:**X bad hex byte] " , font ); // Dont put a * in the error message or you get an infinate loop } } break; case 'O': { // Overstrike - Dont forget padding s++; if (*s && isdigit(*s)) { int backtrack = *s - '0'; s++; xoffset -= backtrack; } else { drawString( x+xoffset , " [ERR:**B without digit] " , font ); // Dont put a * in the error message or you get an infinate loop } } break; case 'S': { // Set strech s++; if (*s && isdigit(*s)) { strech = *s - '0'; s++; } else { xoffset += drawString( x+xoffset , " [ERR:**S without strech amount] " , font ); // Dont put a * in the error message or you get an infinate loop } } break; case 'T': { // Insert time s++; if (*s && isalpha(*s)) { xoffset += drawString( x+xoffset , timestring( *s ) , font ); xoffset += padding; s++; } else { xoffset += drawString( x+xoffset , " [ERR:**T without format value] " , font ); } } break; case 'L': { // Scroll lag s++; if (*s && isdigit(*s)) { lag = *s - '0'; s++; } else { xoffset += drawString( x+xoffset , " [ERR:**L without lag digit] " , font ); } } break; case 'P': { // Interchar padding s++; if (*s && isdigit(*s)) { padding = *s - '0'; s++; } else { xoffset += drawString( x+xoffset , " [ERR:**P without padding digit] " , font ); } } break; case 'D': { // Insert device name s++; xoffset += drawString( x+xoffset , devArg , font ); xoffset += padding; } break; case 'G': { // Ping Google... s++; const char *p = ping(); // Get the ping message xoffset += drawString( x+xoffset , p , font ); xoffset += padding; } break; case 'W': { // Wait s++; if ( isdigit(*s) && isdigit(*(s+1)) ) { if (x+xoffset==0) { // Only actually do the Wait one time, when this col is leftmost const unsigned int secs= (( *s - '0' ) * 10 ) + ( *(s+1) - '0' ); wait = secs; } else { wait=0; } s+=2; // Skip the digits } else { xoffset += drawString( x+xoffset , " [ERR:**W without 2 digit seconds count] " , font ); } } break; } } else { xoffset+=draw5x7(x+xoffset, *s , strech , font ); xoffset += padding; s++; } } return(xoffset); }