bool
xpcc::CanLawicelFormatter::convertToString(const can::Message& in, char* out)
{
	if(in.flags.extended){
		if(in.flags.rtr){
			out[0]='R';
		}
		else{
			out[0]='T';
		}
	}
	else{
		if(in.flags.rtr){
			out[0]='r';
		}
		else{
			out[0]='t';
		}
	}

	const uint8_t* ptr=reinterpret_cast<const uint8_t*>(&in.identifier);
	uint8_t dataBegin;
	if(in.flags.extended)
	{
		for(int i=3; i>=0; i--){
			out[2*i+1] = byteToHex((*ptr)>>4);
			out[2*i+2] = byteToHex(*ptr);
			++ptr;
		}
		out[9] = byteToHex(in.length);
		out[10] = '\0';
		dataBegin=10;
	}
	else
	{
void ICACHE_FLASH_ATTR dhdebug_dump(const char *data, unsigned int len) {
	if(len == 0)
		return;
	const unsigned char byte_per_line = 16;
	char textbuf[byte_per_line + 1];
	char hexbuf[byte_per_line * 3 + 1];
	char address[9] = "00000000";
	int pos = 0;
	dhdebug("Dump at 0x%X, length %u", (unsigned int)data, len);
	do {
		byteToHex((pos / 0x1000000) & 0xFF, &address[0]);
		byteToHex((pos / 0x10000) & 0xFF, &address[2]);
		byteToHex((pos / 0x100) & 0xFF, &address[4]);
		byteToHex(pos & 0xFF, &address[6]);
		unsigned int i;
		for(i = 0; i < byte_per_line; i++) {
			if(pos < len) {
				char c = data[pos++];
				byteToHex(c, &hexbuf[i * 3]);
				hexbuf[i * 3 + 2] = ' ';
				if(c < 0x20 || c >= 0x7F)
					textbuf[i] = '.';
				else
					textbuf[i] = c;
				textbuf[i + 1] = 0;
			} else {
				hexbuf[i * 3] = ' ';
				hexbuf[i * 3 + 1] = ' ';
				hexbuf[i * 3 + 2] = ' ';
			}
			hexbuf[i * 3 + 3] = 0;
		}
		dhdebug("%s:  %s  %s", address, hexbuf, textbuf);
	} while (pos < len);
}
Beispiel #3
0
QString
Util::toARgbString(const QColor& color)
{
  return
      byteToHex(color.alpha()) +
      byteToHex(color.red()) +
      byteToHex(color.green()) +
      byteToHex(color.blue())
      ;
}
char sendByte( char byte )
{
    char echo[7] = "W:    ";
    byteToHex( &echo[3], byte );
    write( port, &byte, 1 );
    write( STDOUT_FILENO, echo, 6 );
}
Beispiel #5
0
void createTestFiles(void)
{
    Dsetdrv(drive);             // switch to selected drive
    Dsetpath("\\");
    (void) Dcreate("TESTDIR");
    Dsetpath("\\TESTDIR");

    int i, f;
    char numString[8];
    char fileName[16];
    for(i=0; i<25; i++) {
        byteToHex(i + 1, numString);
        
        strcpy(fileName, "FILE_");
        strcat(fileName, numString);
        f = Fcreate(fileName, 0);
        Fwrite(f, 7, fileName);
        Fclose(f);
        
        strcpy(fileName, "FILENAME.X");
        strcat(fileName, numString);
        f = Fcreate(fileName, 0);
        Fwrite(f, 12, fileName);
        Fclose(f);
        
        strcpy(fileName, "DIR_");
        strcat(fileName, numString);
        (void) Dcreate(fileName);
    }
}
char readByte()
{
    char byte = 0;
    char echo[7] = "R:   \n";
    read( port, &byte, 1 );
    byteToHex( &echo[3], byte );
    write( STDOUT_FILENO, echo, 6 );
    return byte;
}
Beispiel #7
0
char *bytesToString( const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s )
{
    bool truncate = (numBytes > maxBytes);
    if ( truncate )
        numBytes = maxBytes;

    s = copyString( s, "{ " );
    for ( unsigned i = 0; i < numBytes; ++ i, ++ bytes )
        s = copyString( copyString( s, byteToHex( *bytes ) ), " " );
    if ( truncate )
        s = copyString( s, "..." );
    return copyString( s, " }" );
}
Beispiel #8
0
			static bool	preCheckAsc(const void* start, size_t size, ParseStatus& parseStatus)
			{
				char sync[2];
				byteToHex((unsigned char)kRs232SyncUp, sync);

				const unsigned char* ptr = (const unsigned char*)start;
				static const size_t	MIN_SIZE = kMinSizeOfResponse * 2;

				if (size < MIN_SIZE) {
					parseStatus.bytes = MIN_SIZE - size;
					parseStatus.status = ParseStatus::kParseMoreData;
					return false;
				}
				if ((sync[0] != ((const  char*)start)[0]) || (sync[1] != ((const char*)start)[1])) {
					parseStatus.bytes = 2;
					parseStatus.status = ParseStatus::kParseBadHeader;
					return false;
				}
				return true;

			}
	const uint8_t* ptr=reinterpret_cast<const uint8_t*>(&in.identifier);
	uint8_t dataBegin;
	if(in.flags.extended)
	{
		for(int i=3; i>=0; i--){
			out[2*i+1] = byteToHex((*ptr)>>4);
			out[2*i+2] = byteToHex(*ptr);
			++ptr;
		}
		out[9] = byteToHex(in.length);
		out[10] = '\0';
		dataBegin=10;
	}
	else
	{
		out[1] = byteToHex(*(ptr+1));
		out[2] = byteToHex((*(ptr))>>4);
		out[3] = byteToHex((*(ptr)));
		out[4] = byteToHex(in.length);
		out[5] = '\0';	// terminate if no data is appended.
		dataBegin=5;

	}

	if (!in.flags.rtr)
	{
		uint_fast8_t i = 0;
		for( ; i < in.length ; i++)
		{
			out[dataBegin+2*i] = byteToHex(in.data[i]>>4);
			out[dataBegin+2*i+1] = byteToHex(in.data[i]);