Esempio n. 1
0
static void aa_touch_event(uint8_t action, int x, int y) {
	struct timespec tp;
	uint8_t *buf;
	int idx;
	int siz_arr = 0;
	int size1_idx, size2_idx, i;
	int axis = 0;
	int coordinates[3] = {x, y, 0};
	int ret;

	buf = (uint8_t *)malloc(TS_MAX_REQ_SZ);
	if(!buf) {
		printf("Failed to allocate touchscreen event buffer\n");
		return;
	}

	/* Fetch the time stamp */
	clock_gettime(CLOCK_REALTIME, &tp);

	/* Copy header */
	memcpy(buf, ts_header, sizeof(ts_header));
//	idx = sizeof(ts_header) +
//	      uleb128_encode(tp.tv_nsec, buf + sizeof(ts_header));

	idx = sizeof(ts_header) +
	      varint_encode(tp.tv_sec * 1000000000 +tp.tv_nsec, buf + sizeof(ts_header),0);

	size1_idx = idx + 1;
	size2_idx = idx + 3;

	/* Copy sizes */
	memcpy(buf+idx, ts_sizes, sizeof(ts_sizes));
	idx += sizeof(ts_sizes);

	/* Set magnitude of each axis */
	for (i=0; i<3; i++) {
		axis += 0x08;
		buf[idx++] = axis;
		/* FIXME The following can be optimzed to update size1/2 at end of loop */
		siz_arr = uleb128_encode(coordinates[i], &buf[idx]);
		idx += siz_arr;
		buf[size1_idx] += siz_arr;
		buf[size2_idx] += siz_arr;
	}

	/* Copy footer */
	memcpy(buf+idx, ts_footer, sizeof(ts_footer));
	idx += sizeof(ts_footer);

	buf[idx++] = action;

	queueSend(0, AA_CH_TOU, buf, idx, TRUE);
	
}
Esempio n. 2
0
ssize_t
RecordSetOutBase::write_header (byte_t* const buf, ssize_t const size)
{
    int const csize(check_size(check_type_));

    assert (header_size_max() + csize <= size);

    ssize_t const hdr_offset(header_size_max() - header_size());

    assert (hdr_offset >= 0);

    size_ -= hdr_offset;

    int off(hdr_offset);

    buf[off] = (static_cast<byte_t>(version_) << 4) | /* upper 4 bytes: ver */
               (static_cast<byte_t>(check_type_) & 0x0f);
    off += 1;

    off += uleb128_encode(size_,  buf + off, size - off);
    off += uleb128_encode(count_, buf + off, size - off);

    /* write header CRC */
    uint32_t const crc(gu_fast_hash32(buf + hdr_offset, off - hdr_offset));
    *(reinterpret_cast<uint32_t*>(buf + off)) = htog(crc);

    off += VER1_CRC_SIZE;

    /* append payload checksum */
    if (check_type_ != CHECK_NONE)
    {
        assert (csize <= size - off);
        check_.append (buf + hdr_offset, off - hdr_offset); /* append header */
        check_.gather (buf + off, csize);
    }

    return hdr_offset;
}
 inline size_t uleb128_encode(UI       value,
                              byte_t*  buf,
                              size_t   buflen)
 {
     return uleb128_encode(value, buf, buflen, 0);
 }