Ejemplo n.º 1
0
int Hex2Bin(const char* hex, int len, uint8* bin)
{
	int i;
	if (len & 1) {
		printf("invalid hex number (odd length): '%s'\n", hex);
		return ERR_INVALID;
	}
	for (i = 0; i < len; i += 2) {
		int hi = hex[i + 0];
		int lo = hex[i + 1];
#define HEX(ch) (\
		'0' <= ch && ch <= '9' \
		? ch - '0' \
		: 'A' <= ch && ch <= 'F' \
			? 10 + ch - 'A' \
			: 'a' <= ch && ch <= 'f' \
				? 10 + ch - 'a' \
				: -1)
		int b = HEX(hi) << 4 | HEX(lo);
#undef HEX
		if (b < 0) {
			printf("invalid hex number (non hex digit): '%s'\n", hex);
			return ERR_INVALID;
		}
		bin[i / 2] = b;
	}
	return 0;
}
char *camera_get_msr_filename(char *buf, int buf_size, char *sensor, int cam)
{
	snprintf(buf, buf_size, "%02d%s-%s%x-%s%x-%s%x.drvb",
		 cam, sensor, HEX(spid.vendor_id),
		 HEX(spid.platform_family_id), HEX(spid.product_line_id));
	return buf;
}
Ejemplo n.º 3
0
int
set_reminder ( reminder_t *reminder, S710_Packet_Index which, S710_Driver *d )
{
  packet_t  *p;
  int        lower = S710_SET_REMINDER_1;
  int        upper = S710_SET_REMINDER_7;

  if ( which < lower || which > upper ) {
    fprintf(stderr,"set_reminder: index %d outside of [%d,%d]\n",
	    which,lower,upper);
    return 0;
  }
  
  p = make_set_packet(which);
  if ( p == NULL ) return 0;

  p->data[0] = reminder->which - 1;
  p->data[1] = HEX(reminder->date.tm_min);
  p->data[2] = HEX(reminder->date.tm_hour);
  p->data[3] = HEX(reminder->date.tm_mday);
  p->data[4] = HEX(reminder->date.tm_year - 100);
  p->data[5] = BINU(reminder->on) | BINL(reminder->date.tm_mon + 1);

  encode_label(reminder->label,&p->data[6],7);

  p->data[13] = BINU(reminder->repeat) | BINL(reminder->exercise);

  return send_set_packet(p,d);
}
Ejemplo n.º 4
0
static void
fromhex(const char input[], char output[], int n) {
	int i;
	for (i=0;i<n;i++) {
		char hi,low;
		HEX(hi, input[i*2]);
		HEX(low, input[i*2+1]);
		output[i] = hi<<4 | low;
	}
}
Ejemplo n.º 5
0
    // does not return
    void Binary::runBasic(int argc, char* argv[]){
        long res;

        pid_t pid = fork();
        if (pid == 0){
            // child that runs bin
            PTRACE_AND_CHECK(PTRACE_TRACEME, 0, NULL, NULL);

            EPAXOut << "child (" << getName();
            for (int i = 1; i < argc; i++){
                std::cout << " " << argv[i];
            }
            std::cout << ") will start at " << HEX(getStartAddr()) << ENDL;

            int ret = execve(argv[0], argv, NULL);
            EPAXAssert(false, "exec returned with an error: " << DEC(ret));
        }

        // parent/epax process
        siginfo_t s;
        struct user_regs bregs;

	// wait, then be sure the signal caught is a SIGTRAP from child's execve
        wait(NULL);
        PTRACE_AND_CHECK(PTRACE_GETSIGINFO, pid, NULL, &s);
        EPAXAssert(s.si_signo == SIGTRAP, "unexpected signal caught (expect SIGTRAP resulting from execve)");

	// grab the PC of the child process
        PTRACE_AND_CHECK(PTRACE_GETREGS, pid, NULL, &bregs);
        EPAXOut << getName() << " PC: " << HEX(bregs.uregs[15]) << ENDL; // TODO: get magic num 15 from armd

        long b = ptrace(PTRACE_PEEKTEXT, pid, bregs.uregs[15], NULL);
        EPAXOut << getName() << " instruction bytes: " << HEX(b) << ENDL; // TODO: get magic num 15 from armd

        // plan: here we need to inject code that copies the contents of the parent process (epax) into the child.
        // this code can then shepherd the child process, taking control back at every BB, for example.
        PTRACE_AND_CHECK(PTRACE_POKETEXT, pid, bregs.uregs[15], b);

        // prints out the instruction stream, 1 PC at a time
//#define SINGLE_STEP_THROUGH
#ifdef SINGLE_STEP_THROUGH
        while (1){
            PTRACE_AND_CHECK(PTRACE_SINGLESTEP, pid, NULL, NULL);
            wait(NULL);
            PTRACE_AND_CHECK(PTRACE_GETREGS, pid, NULL, &bregs);
            EPAXOut << getName() << " PC: " << HEX(bregs.rip) << ENDL;
        }
#else
        PTRACE_AND_CHECK(PTRACE_CONT, pid, NULL, NULL);
#endif
        wait(NULL);
        exit(0);        
    }
Ejemplo n.º 6
0
string pCFGIterator::genRandColor(unsigned int curPSet)
{
    stringstream color;
    boost::mt19937 seed(static_cast<unsigned int> (time(0) + curPSet));
    boost::uniform_smallint<> color_component(0, 255);
    boost::variate_generator< boost::mt19937, boost::uniform_smallint<> > 
        hex(seed, color_component);
    int r = hex();
    int g = hex();
    int b = hex();
    color << "\"# " << HEX(r) << HEX(g) << HEX(b) << "\"";
    //cout << std::hex << r << endl;
    return color.str();
}
Ejemplo n.º 7
0
    void Binary::construct(std::string n, BinaryFormat f){
        if (f == BinaryFormat_undefined){
            f = detectFormat(n);
        }

        format = f;
        EPAXOut << "File " << n << " is a " << getFormatName() << " file" << ENDL;

        EPAXAssert(format != BinaryFormat_undefined, "Cannot determine format of " << n << ". Try specifying it manually.");

        switch (format){
        case BinaryFormat_Elf32:
            binary = new Elf::ElfBinary32(n);
            break;
        case BinaryFormat_Elf64:
            binary = new Elf::ElfBinary64(n);
            break;
        case BinaryFormat_MachO32:
            binary = new MachO::MachOBinary32(n);
            break;
        case BinaryFormat_MachO64:
            binary = new MachO::MachOBinary64(n);
            break;
        default:
            EPAXDie("Unimplemented binary format " << getFormatName() << " given.");
        }

        EPAXOut << "Program entry point at vaddr " << HEX(binary->getStartAddr()) << ENDL;

        lineinfo = new LineInformation(binary);

        binary->describe();
        //EPAXAssert(binary->isARM(), "This binary contains non-ARM code... bailing");
    }
  void PostIncTestInt64()
  {
    size_t i;

    for( i = 0; i < COUNTOF(inc_int64); ++i )
      {
        bool fSuccess = true;
        try
          {
            SafeInt< __int64 > si(inc_int64[i].x);
            SafeInt< __int64 > vv = si++;

            if(vv != inc_int64[i].x)
              {
                fSuccess = false;
              }
          }
        catch(SafeIntException&)
          {
            fSuccess = false;
          }

        if( fSuccess != inc_int64[i].fExpected )
          {
            cerr << "Error in case inc_int64 throw (2): ";
            cerr << HEX(8) << inc_int64[i].x << ", ";
            cerr << "expected = " << inc_int64[i].fExpected << endl;
          }
      }
  }
Ejemplo n.º 9
0
int main() {
    char ch = 0;
    printf("请输入一个十六进制数位字符:"); 
    scanf("%c", &ch);
    printf("转换结果是%d\n", HEX(ch));
    return 0;
}
  void PostDecTestInt8()
  {
    size_t i;

    for( i = 0; i < COUNTOF(dec_int8); ++i )
      {
        bool fSuccess = true;
        try
          {
            SafeInt< __int8 > si(dec_int8[i].x);
            SafeInt< __int8 > vv = si--;

            if(vv != dec_int8[i].x)
              {
                fSuccess = false;
              }
          }
        catch(SafeIntException&)
          {
            fSuccess = false;
          }

        if( fSuccess != dec_int8[i].fExpected )
          {
            cerr << "Error in case dec_int8 throw (2): ";
            cerr << HEX(2) << (0xFF & (int)dec_int8[i].x) << ", ";
            cerr << "expected = " << dec_int8[i].fExpected << endl;
          }
      }
  }
  void PreIncTestInt32()
  {
    size_t i;

    for( i = 0; i < COUNTOF(inc_int32); ++i )
      {
        bool fSuccess = true;
        try
          {
            SafeInt< __int32 > si(inc_int32[i].x);
            SafeInt< __int32 > vv = ++si;

            if(vv != inc_int32[i].y)
              {
                fSuccess = false;
              }
          }
        catch(SafeIntException&)
          {
            fSuccess = false;
          }

        if( fSuccess != inc_int32[i].fExpected )
          {
            cerr << "Error in case inc_int32 throw (1): ";
            cerr << HEX(8) << inc_int32[i].x << ", ";
            cerr << "expected = " << inc_int32[i].fExpected << endl;
          }
      }
  }
  void PostDecTestUint64()
  {
    size_t i;

    for( i = 0; i < COUNTOF(dec_uint64); ++i )
      {
        bool fSuccess = true;
        try
          {
            SafeInt<unsigned __int64> si(dec_uint64[i].x);
            SafeInt<unsigned __int64> vv = si--;

            if(vv != dec_uint64[i].x)
              {
                fSuccess = false;
              }
          }
        catch(SafeIntException&)
          {
            fSuccess = false;
          }

        if( fSuccess != dec_uint64[i].fExpected )
          {
            cerr << "Error in case dec_uint64 throw (2): ";
            cerr << HEX(16) << dec_uint64[i].x << ", ";
            cerr << "expected = " << dec_uint64[i].fExpected << endl;
          }
      }
  }
  void PreDecTestUint32()
  {
    size_t i;

    for( i = 0; i < COUNTOF(dec_uint32); ++i )
      {
        bool fSuccess = true;
        try
          {
            SafeInt<unsigned __int32> si(dec_uint32[i].x);
            SafeInt<unsigned __int32> vv = --si;

            if(vv != dec_uint32[i].y)
              {
                fSuccess = false;
              }
          }
        catch(SafeIntException&)
          {
            fSuccess = false;
          }

        if( fSuccess != dec_uint32[i].fExpected )
          {
            cerr << "Error in case dec_uint32 throw (1): ";
            cerr << HEX(8) << dec_uint32[i].x << ", ";
            cerr << "expected = " << dec_uint32[i].fExpected << endl;
          }
      }
  }
  void PreIncTestUint8()
  {
    size_t i;

    for( i = 0; i < COUNTOF(inc_uint8); ++i )
      {
        bool fSuccess = true;
        try
          {
            SafeInt<unsigned __int8> si(inc_uint8[i].x);
            SafeInt<unsigned __int8> vv = ++si;

            if(vv != inc_uint8[i].y)
              {
                fSuccess = false;
              }
          }
        catch(SafeIntException&)
          {
            fSuccess = false;
          }

        if( fSuccess != inc_uint8[i].fExpected )
          {
            cerr << "Error in case inc_uint8 throw (1): ";
            cerr << HEX(2) << (0xFF & (int)inc_uint8[i].x) << ", ";
            cerr << "expected = " << inc_uint8[i].fExpected << endl;
          }
      }
  }
Ejemplo n.º 15
0
static PyObject * add_to_pointerlist(struct pointerlist *n, struct key_thing *other)
{
    HEX(n);
    HEX(other);
    INT(other->key);
    HEX(other->self);
    XX(print_pointerlist(n));
    if (n == NULL) {
	PyErr_SetString(PyExc_RuntimeError,
			"add_to_pointerlist: null list??");
	return NULL;
    }
    if (other == NULL) {
	PyErr_SetString(PyExc_RuntimeError,
			"add_to_pointerlist: second arg is NULL");
	return NULL;
    }
    if (other->key == 0) {
	printf("BADNESS: ");
	PyObject_Print(other->self, stdout, 0);
	printf("\n");

	PyErr_SetString(PyExc_RuntimeError,
			"add_to_pointerlist: key is zero");
	return NULL;
    }
    /* we already have somebody with the same key, so remove it */
    if (has_key(n, other->key) != NULL) {
	if (remove_from_pointerlist(n, other->key) == NULL)
	    return NULL;
    }
	n->size++;
    if (n->size > n->arraysize) {
	printf("GROW LIST FROM %d to %d\n", n->arraysize, 2 * n->arraysize);
	n->arraysize *= 2;
	n->lst = (struct key_thing **)
	    realloc(n->lst, n->arraysize * sizeof(struct key_thing *));
    }
	n->lst[n->size-1] = other;
	Py_INCREF(other->self);

    MARK();
    XX(print_pointerlist(n));
    Py_INCREF(Py_None);
    return Py_None;
}
Ejemplo n.º 16
0
std::string coloritcolor(float val,
                         float perfect,
                         float a,
                         float b,
                         float c,
                         float d) {
  
  if (val < 0.00001) return "ffffff";
  else if (val > perfect) return "aa88ff";
  else {
  float red,green,blue;

  if (val >= a) { // blue -> green
    red = 200;
    green = 200 + 55*(perfect-val)/(float(perfect-a));
    blue = 255 - 55*(perfect-val)/(float(perfect-a));
  } 

  else if (val >= b) {  // green -> yellow
    red = 200 + 55*(a-val)/(float(a-b));
    green = 255;
    blue = 200;
  } 

  else if (val >= c) { // yellow -> pink
    red = 255; 
    green = 255 - 55*(b-val)/(float(b-c));
    blue = 200;
  } 

  else if (val >= d) {  // pink -> red;
    red = 255;
    green = 200 - 200*(c-val)/(float(c-d));
    blue = 200 - 200*(c-val)/(float(c-d));
  } 

  else { // dark red
    red = 200;
    green = 0;
    blue = 0;
  }

  return HEX(red) + HEX(green) + HEX(blue);

  }
}
Ejemplo n.º 17
0
int
ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
    UINT8* ptr;
    int a, b;

    ptr = buf;

    for (;;) {

	if (bytes < 2)
	    return ptr - buf;

	a = HEX(ptr[0]);
	b = HEX(ptr[1]);

	if (a < 0 || b < 0) {

	    ptr++;
	    bytes--;

	} else {

	    ptr += 2;
	    bytes -= 2;

	    state->buffer[state->x] = (a<<4) + b;

	    if (++state->x >= state->bytes) {

		/* Got a full line, unpack it */
		state->shuffle((UINT8*) im->image[state->y], state->buffer,
			       state->xsize);

		state->x = 0;

		if (++state->y >= state->ysize) {
		    /* End of file (errcode = 0) */
		    return -1;
		}
	    }

	}
    }
}
// Encodes and prints string using Percent-encoding specified
// in RFC 1738, Section 2.2
static int print_encoded_string(Print* print, const char* str) {
  int bytes = 0;
  for (int i = 0; str[i] != 0; i++) {
    if (((str[i] >= 'A') && (str[i] <= 'Z')) ||
        ((str[i] >= 'a') && (str[i] <= 'z')) ||
        ((str[i] >= '0') && (str[i] <= '9')) ||
        (str[i] == '-') || (str[i] == '_') ||
        (str[i] == '.') || (str[i] == '~')) {
      bytes += print->print(str[i]);
    } else {
      // Encode all other characters
      bytes += print->print('%');
      bytes += print->print(HEX(str[i] / 16));
      bytes += print->print(HEX(str[i] % 16));
    }
  }
  return bytes;
}
Ejemplo n.º 19
0
/*
 * This function should vanish when 2.5 comes around and
 * we have pnpbios_module_init()
 */
static void pnp_init(void)
{
	const struct pnpbios_device_id *id;
	struct pci_dev *dev = NULL;

#ifdef SERIAL_DEBUG_PNP
	printk("Entered probe_serial_pnp()\n");
#endif

	isapnp_for_each_dev(dev) {
		char slot_name[8];
		u32 pnpid;

		if (dev->active)
			continue;

		pnpid = dev->vendor << 16 | dev->device;
		pnpid = cpu_to_le32(pnpid);

#define HEX(id,a) hex[((id)>>a) & 15]
#define CHAR(id,a) (0x40 + (((id)>>a) & 31))
		slot_name[0] = CHAR(pnpid, 26);
		slot_name[1] = CHAR(pnpid, 21);
		slot_name[2] = CHAR(pnpid, 16);
		slot_name[3] = HEX(pnpid, 12);
		slot_name[4] = HEX(pnpid, 8);
		slot_name[5] = HEX(pnpid, 4);
		slot_name[6] = HEX(pnpid, 0);
		slot_name[7] = '\0';
		
		for (id = pnp_dev_table; id->id[0]; id++)
			if (memcmp(id->id, slot_name, 7) == 0)
				break;

		if (id->id[0])
			pnp_init_one(dev, id, slot_name);
		else
			pnp_init_one(dev, NULL, slot_name);
	}

#ifdef SERIAL_DEBUG_PNP
	printk("Leaving probe_serial_pnp() (probe finished)\n");
#endif
}
Ejemplo n.º 20
0
BOOL WlanMisc_String2Mac(char *pszString, PBYTE pbMac)
{
	UCHAR i, nargs = 0;
	char *argv[6];

	while (nargs < 6) {
		while ((*pszString == ' ') || (*pszString == '\t')) {
			++ pszString;
		}
		if (*pszString == '\0') {
			argv[nargs] = NULL;
			break;
		}

		argv[nargs ++] = pszString;

		while (*pszString && (*pszString != ':')) {
			++ pszString;
		}

		if (*pszString == '\0') {
			argv[nargs] = NULL;
			break;
		}

		*pszString ++ = '\0';
	}
	
	if (nargs != 6)
		return FALSE;

	for (i = 0; i < 6; i ++) {
		UINT8 val1, val2;

		val1 = HEX(argv[i][0]);
		val2 = HEX(argv[i][1]);

		pbMac[i] = (val1 << 4) + val2;
	}

	return TRUE;
}
Ejemplo n.º 21
0
void SPIDevice::debugDumpRegisters(unsigned int number){
	cout << "SPI Mode: " << this->mode << endl;
	cout << "Bits per word: " << (int)this->bits << endl;
	cout << "Max speed: " << this->speed << endl;
	cout << "Dumping Registers for Debug Purposes:" << endl;
	unsigned char *registers = this->readRegisters(number);
	for(int i=0; i<(int)number; i++){
		cout << HEX(*(registers+i)) << " ";
		if (i%16==15) cout << endl;
	}
	cout << dec;
}
Ejemplo n.º 22
0
void display_planet(struct planet p) {
    glColor3f(HEX(p.color));
    glPushMatrix();
    glTranslatef(p.x, p.y, p.z);
    glRotatef(p.angle, 15, 25, 1);
    int lines = p.radius / 2.5;
    glutWireSphere(p.radius, lines, lines);
    glPopMatrix();
    
    if (p.satellite) {
        display_planet(*p.satellite);
    }
}
Ejemplo n.º 23
0
UCHAR WlanMisc_ASCII2WEPKey(CHAR *pszKeyASCII, UCHAR *pucKeyMaterial)
{
	UCHAR ucSize = (UCHAR)strlen(pszKeyASCII);

	TRACE("+SetWEPKey()\r\n");

	switch (ucSize) {
		case KeySizeValue_40_64bit_ASCII:
		case KeySizeValue_104_128bit_ASCII:
			CopyMemory(pucKeyMaterial, pszKeyASCII, strlen(pszKeyASCII));
			ucSize = (UCHAR)strlen(pszKeyASCII);
			break;
		case KeySizeValue_40_64bit_HEX:
		case KeySizeValue_104_128bit_HEX: {
				UCHAR *psz = (UCHAR*)pszKeyASCII;
				UCHAR *pTarget = pucKeyMaterial;

				while (*psz) {
					UINT8 val1, val2;

					val1 = HEX(*psz);
					psz ++;
					val2 = HEX(*psz);
					psz ++;

					*pTarget = (val1 << 4) + val2;
					pTarget ++;
				}
				ucSize = pTarget - pucKeyMaterial;
				break;
			}
		default:
			return 0;
	}

	TRACE("-SetWEPKey()\r\n");

	return ucSize;
}
Ejemplo n.º 24
0
static ssize_t emv_pk_read_bin(char *buf, unsigned char *bin, size_t size, size_t *read)
{
	size_t left = size;
	char *p = buf;
	while (*p && *p == ' ')
		p++;

	while (left > 0) {
		int c1, c2;
		c1 = HEX(*p);
		if (c1 == -1)
			return -(p - buf);
		p++;
		c2 = HEX(*p);
		if (c2 == -1)
			return -(p - buf);
		p++;
		*bin = (c1 * 16 + c2);
		bin ++;
		left --;
		if (*p == ':')
			p++;
		else if (read) {
			*read = (size - left);
			break;
		} else if (left == 0)
			break;
		else
			return -(p - buf);
	}

	while (*p && *p == ' ')
		p++;

	p--;

	return (p - buf);
}
 string toHex(int num) {
     string HEX("0123456789abcdef");
     if (num == 0) {
         return "0";
     }
     string res;
     int count = 0;
     while (num && count < 8) {
         res += HEX[num & 0xf];
         count++;
         num >>= 4;
     }
     reverse(res.begin(), res.end());
     return res;
 }
Ejemplo n.º 26
0
static void list_output(int32_t offset, const void *data,
			enum out_type type, uint64_t size)
{
    char q[20];

    if (!listp || suppress || user_nolist)      /* fbk - 9/2/00 */
        return;

    switch (type) {
    case OUT_RAWDATA:
    {
        uint8_t const *p = data;

	if (size == 0 && !listdata[0])
	    listoffset = offset;
        while (size--) {
            HEX(q, *p);
            q[2] = '\0';
            list_out(offset++, q);
            p++;
        }
	break;
    }
    case OUT_ADDRESS:
      list_address(offset, "[]", *(int64_t *)data, abs((int)size));
	break;
    case OUT_REL1ADR:
	list_address(offset, "()", *(int64_t *)data, 1);
	break;
    case OUT_REL2ADR:
	list_address(offset, "()", *(int64_t *)data, 2);
	break;
    case OUT_REL4ADR:
	list_address(offset, "()", *(int64_t *)data, 4);
	break;
    case OUT_REL8ADR:
	list_address(offset, "()", *(int64_t *)data, 8);
	break;
    case OUT_RESERVE:
    {
        snprintf(q, sizeof(q), "<res %08"PRIX64">", size);
        list_out(offset, q);
	break;
    }
    }
}
Ejemplo n.º 27
0
static void list_address(int32_t offset, const char *brackets,
			 int64_t addr, int size)
{
    char q[20];
    char *r = q;

    nasm_assert(size <= 8);

    *r++ = brackets[0];
    while (size--) {
	HEX(r, addr);
	addr >>= 8;
	r += 2;
    }
    *r++ = brackets[1];
    *r = '\0';
    list_out(offset, q);
}
Ejemplo n.º 28
0
int main()
{
	char		passwd[MAX_LEN], hash[HASH_LENGTH], out[MAX_LEN * 2];
	size_t		passwd_len;


#	ifdef USE_GCRYPT
	gcry_error_t err;

	/* Initialize libgcrypt so it does not put warning messages in the syslog. */
	if (!gcry_check_version(GCRYPT_VERSION))
	{
		printf("libgcrypt version mismatch. %s or higher is required.\n",
				GCRYPT_VERSION);
				exit(1);
	}
	/* Since we will just be hashing, secure memory is not needed. */
	if (!(err = gcry_control(GCRYCTL_DISABLE_SECMEM,0)))
			err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
	if (GPG_ERR_NO_ERROR != err)
	{
		printf("Libgcrypt error: %s\n", gcry_strerror(err));
		exit(1);
	}
#	endif

	passwd_len = -1;
	memset(passwd, 0, MAX_LEN);
	memset(out, 0, MAX_LEN * 2);

	if (get_hash_via_env_var(hash))
		if (get_hash_via_username_and_inode(hash, passwd, &passwd_len))
			exit(1);
	if (-1 == passwd_len)
	{
		prompt_passwd(passwd);
		passwd_len = strlen(passwd);
	}

	maskpass(passwd, passwd_len, hash, HASH_LENGTH);
	HEX(passwd, out, passwd_len * 2);
	printf("%s\n", out);
	return 0;
}
Ejemplo n.º 29
0
gcolor from_hex(char *hex) {
    gcolor c = {0, 0, 0};
    if (!hex || !(*hex == '#')) {
        return c;
    }
    c.r = (16*HEX(hex[1]) + HEX(hex[2]));
    c.g = (16*HEX(hex[3]) + HEX(hex[4]));
    c.b = (16*HEX(hex[5]) + HEX(hex[6]));
    if (c.r<0 || c.g<0 || c.b<0) {
        c = (gcolor){0,0,0};
    }
    return c;
}
Ejemplo n.º 30
0
int ATCommandResponse::setData(std::vector<unsigned char> frame)
{
  // Check frame type
  if (frame[0] != 0x88)
  {
    std::cout << __FILE__ << ":" << __LINE__ 
	      << "ATCommandResponse::setData(): Unknown type (" 
	      << HEX(frame[0]) << ")" << std::endl;
    return -1;
  }
  // Check size
  if (frame.size() < 5)
  {
    std::cout << __FILE__ << ":" << __LINE__ 
	      << "ATCommandResponse::setData(): Frame not large "
	      << "enough!  Expected at least 5 bytes, size " 
	      << frame.size() << std::endl;
    return -1;
  }
    

  // Frame ID is next
  m_frameId = frame[1];
  for (int i = 0; i < 2; i++)
  {
    m_command.push_back(frame[i+2]); // command is bytes 2 and 3
  }
  m_status = frame[4]; // Status is byte 4 (starting from 0)
  // Any remaining bytes are the arg, starting at 15
  m_arg = 0;
  for (unsigned int i = 5; i < frame.size(); i++)
  {
    m_argData.push_back(frame[i]);
    m_arg = m_arg << 8;
    m_arg += frame[i];
  }

  return 0;
}