• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ read_bytes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中read_bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ read_bytes函数的具体用法?C++ read_bytes怎么用?C++ read_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了read_bytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: execute_get_load_threshold_handle

int execute_get_load_threshold_handle(struct data_buffer *dbuf, int socket_fd, MEM_POOL_PTR mem_pool)
{
	struct data_buffer rbuf;
	
	//发数据包
	if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0)
		return -1;

	//接受命名
	memset(&rbuf,0,sizeof(struct data_buffer));
	rbuf.data_len = sizeof(uint32_t);
	rbuf.size = rbuf.data_len;
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t));
	
	if(socket_read(socket_fd,rbuf.data,sizeof(uint32_t)) <= 0)
		return -1;

	rbuf.data_len = read_int32(&rbuf);
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len);
	rbuf.rpos = 0;
	rbuf.size = rbuf.data_len;

	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0)
		return -1;
	rbuf.rpos += MESSAGE_HEAD_LEN;

	uint16_t type = message_type(&rbuf);
	if (type != MT_DC_EXE_RS)
		return -1;

	double load = 0;
	read_bytes(&rbuf, (uint8_t *)&load, sizeof(load));

	fprintf(stderr, "%g\n", load);
	return 0;
}
开发者ID:Alibaba-boonya,项目名称:mile,代码行数:36,代码来源:client.c


示例2: read_version

    int read_version()
    {
        int sum = 0;
        int bytes_read = 0;

        uint16_t header = read_bytes(2, &bytes_read, &sum); // Always 0x210 (0x10-0x02)
        uint16_t command = read_bytes(2, &bytes_read, &sum);

        if (header == START && command == UNIT_VERSION)
        {
            read_bytes(2, &bytes_read, &sum); // length

            int major_version = read_bytes(1, &bytes_read, &sum);
            int minor_version = read_bytes(2, &bytes_read, &sum);
            int data_version = read_bytes(2, &bytes_read, &sum);

            QString version = QString(minor_version<100?"%1.0%2 (%3)":"%1.%2 (%3)").arg(major_version).arg(minor_version).arg(data_version);
            deviceInfo += rideFile->deviceType()+QString(" Version %1\n").arg(version);

            read_bytes(1, &bytes_read, &sum); // checksum
        }
        return bytes_read;
    }
开发者ID:BryanF1947,项目名称:GoldenCheetah,代码行数:23,代码来源:Bin2RideFile.cpp


示例3: read_system_info

    int read_system_info()
    {
        int sum = 0;
        int bytes_read = 0;

        uint16_t header = read_bytes(2, &bytes_read, &sum); // Always (0x10-0x02)
        uint16_t command = read_bytes(2, &bytes_read, &sum);


        if (header == START && command == SYSTEM_INFO)
        {
            read_bytes(2, &bytes_read, &sum); // length

            read_bytes(52, &bytes_read, &sum);
            uint16_t odometer = read_bytes(8, &bytes_read, &sum);
            deviceInfo += QString("Odometer %1km\n").arg(odometer/1000.0);

            read_bytes(1, &bytes_read, &sum); // checksum
        }
        return bytes_read;
    }
开发者ID:BryanF1947,项目名称:GoldenCheetah,代码行数:21,代码来源:Bin2RideFile.cpp


示例4: read_ride_summary

    void read_ride_summary(int *bytes_read = NULL, int *sum = NULL)
    {
        data_version = read_bytes(1, bytes_read, sum); // data_version
        read_bytes(1, bytes_read, sum); // firmware_minor_version

        QDateTime t = read_date(bytes_read, sum);

        rideFile->setStartTime(t);

        if (jouleGPS)
        {
            read_bytes(148, bytes_read, sum);

            if (data_version >= 4)
                read_bytes(8, bytes_read, sum);

            if (data_version >= 6)
                read_bytes(8, bytes_read, sum);
       } else
       {
            read_bytes(84, bytes_read, sum);
       }
    }
开发者ID:cernst72,项目名称:GoldenCheetah,代码行数:23,代码来源:Bin2RideFile.cpp


示例5: read_block

static int
read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf)
{
	int status;
	struct block_header bhdr;

	status = read_bytes(fp, &bhdr, sizeof(bhdr), 0, errbuf);
	if (status <= 0)
		return (status);	/* error or EOF */

	if (p->swapped) {
		bhdr.block_type = SWAPLONG(bhdr.block_type);
		bhdr.total_length = SWAPLONG(bhdr.total_length);
	}

	/*
	 * Is this block "too big"?
	 *
	 * We choose 16MB as "too big", for now, so that we handle
	 * "reasonably" large buffers but don't chew up all the
	 * memory if we read a malformed file.
	 */
	if (bhdr.total_length > 16*1024*1024) {
		snprintf(errbuf, PCAP_ERRBUF_SIZE,
		    "pcap-ng block size %u > maximum %u",
		    bhdr.total_length, 16*1024*1024);
		    return (-1);
	}

	/*
	 * Is this block "too small" - i.e., is it shorter than a block
	 * header plus a block trailer?
	 */
	if (bhdr.total_length < sizeof(struct block_header) +
	    sizeof(struct block_trailer)) {
		snprintf(errbuf, PCAP_ERRBUF_SIZE,
		    "block in pcap-ng dump file has a length of %u < %lu",
		    bhdr.total_length,
		    (unsigned long)(sizeof(struct block_header) + sizeof(struct block_trailer)));
		return (-1);
	}

	/*
	 * Is the buffer big enough?
	 */
	if (p->bufsize < (int)bhdr.total_length) {
		/*
		 * No - make it big enough.
		 */
		p->buffer = realloc(p->buffer, bhdr.total_length);
		if (p->buffer == NULL) {
			snprintf(errbuf, PCAP_ERRBUF_SIZE, "out of memory");
			return (-1);
		}
	}

	/*
	 * Copy the stuff we've read to the buffer, and read the rest
	 * of the block.
	 */
	memcpy(p->buffer, &bhdr, sizeof(bhdr));
	if (read_bytes(fp, p->buffer + sizeof(bhdr),
	    bhdr.total_length - sizeof(bhdr), 1, errbuf) == -1)
		return (-1);

	/*
	 * Initialize the cursor.
	 */
	cursor->data = p->buffer + sizeof(bhdr);
	cursor->data_remaining = bhdr.total_length - sizeof(bhdr) -
	    sizeof(struct block_trailer);
	cursor->block_type = bhdr.block_type;
	return (1);
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:74,代码来源:sf-pcap-ng.c


示例6: pmix_usock_recv_handler

void pmix_usock_recv_handler(int sd, short flags, void *cbdata)
{
    pmix_status_t rc;
    pmix_peer_t *peer = (pmix_peer_t*)cbdata;
    pmix_ptl_recv_t *msg = NULL;

    /* acquire the object */
    PMIX_ACQUIRE_OBJECT(peer);

    pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                        "usock:recv:handler called with peer %s:%d",
                        (NULL == peer) ? "NULL" : peer->info->pname.nspace,
                        (NULL == peer) ? PMIX_RANK_UNDEF : peer->info->pname.rank);

    if (NULL == peer) {
        return;
    }
    /* allocate a new message and setup for recv */
    if (NULL == peer->recv_msg) {
        pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                            "usock:recv:handler allocate new recv msg");
        peer->recv_msg = PMIX_NEW(pmix_ptl_recv_t);
        if (NULL == peer->recv_msg) {
            pmix_output(0, "usock_recv_handler: unable to allocate recv message\n");
            goto err_close;
        }
        PMIX_RETAIN(peer);
        peer->recv_msg->peer = peer;  // provide a handle back to the peer object
        /* start by reading the header */
        peer->recv_msg->rdptr = (char*)&peer->recv_msg->hdr;
        peer->recv_msg->rdbytes = sizeof(pmix_usock_hdr_t);
    }
    msg = peer->recv_msg;
    msg->sd = sd;
    /* if the header hasn't been completely read, read it */
    if (!msg->hdr_recvd) {
        pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                            "usock:recv:handler read hdr on socket %d", peer->sd);
        if (PMIX_SUCCESS == (rc = read_bytes(peer->sd, &msg->rdptr, &msg->rdbytes))) {
            /* completed reading the header */
            peer->recv_msg->hdr_recvd = true;
            pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                                "RECVD MSG FOR TAG %d SIZE %d",
                                (int)peer->recv_msg->hdr.tag,
                                (int)peer->recv_msg->hdr.nbytes);
            /* if this is a zero-byte message, then we are done */
            if (0 == peer->recv_msg->hdr.nbytes) {
                pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                                    "RECVD ZERO-BYTE MESSAGE FROM %s:%d for tag %d",
                                    peer->info->pname.nspace, peer->info->pname.rank,
                                    peer->recv_msg->hdr.tag);
                peer->recv_msg->data = NULL;  // make sure
                peer->recv_msg->rdptr = NULL;
                peer->recv_msg->rdbytes = 0;
                /* post it for delivery */
                PMIX_ACTIVATE_POST_MSG(peer->recv_msg);
                peer->recv_msg = NULL;
                PMIX_POST_OBJECT(peer);
                return;
            } else {
                pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                                    "usock:recv:handler allocate data region of size %lu",
                                    (unsigned long)peer->recv_msg->hdr.nbytes);
                /* allocate the data region */
                peer->recv_msg->data = (char*)malloc(peer->recv_msg->hdr.nbytes);
                memset(peer->recv_msg->data, 0, peer->recv_msg->hdr.nbytes);
                /* point to it */
                peer->recv_msg->rdptr = peer->recv_msg->data;
                peer->recv_msg->rdbytes = peer->recv_msg->hdr.nbytes;
            }
            /* fall thru and attempt to read the data */
        } else if (PMIX_ERR_RESOURCE_BUSY == rc ||
                   PMIX_ERR_WOULD_BLOCK == rc) {
            /* exit this event and let the event lib progress */
            return;
        } else {
            /* the remote peer closed the connection - report that condition
             * and let the caller know
             */
            pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                                "pmix_usock_msg_recv: peer closed connection");
            goto err_close;
        }
    }

    if (peer->recv_msg->hdr_recvd) {
        /* continue to read the data block - we start from
         * wherever we left off, which could be at the
         * beginning or somewhere in the message
         */
        if (PMIX_SUCCESS == (rc = read_bytes(peer->sd, &msg->rdptr, &msg->rdbytes))) {
            /* we recvd all of the message */
            pmix_output_verbose(2, pmix_ptl_base_framework.framework_output,
                                "RECVD COMPLETE MESSAGE FROM SERVER OF %d BYTES FOR TAG %d ON PEER SOCKET %d",
                                (int)peer->recv_msg->hdr.nbytes,
                                peer->recv_msg->hdr.tag, peer->sd);
            /* post it for delivery */
            PMIX_ACTIVATE_POST_MSG(peer->recv_msg);
            peer->recv_msg = NULL;
            /* ensure we post the modified peer object before another thread
//.........这里部分代码省略.........
开发者ID:dycz0fx,项目名称:ompi,代码行数:101,代码来源:ptl_usock.c


示例7: main

int main(int argc, char** argv) {
	if( 1 >= argc){
		printf("usage: %s file offset length\n", basename(argv[0]));
		return 0;
	}
	FILE *fh = NULL;
	cmp_ctx_t cmp;
	uint16_t year = 1983;
	uint8_t month = 5;
	uint8_t day = 28;
	int64_t sint = 0;
	uint64_t uint = 0;
	float flt = 0.0f;
	double dbl = 0.0;
	bool boolean = false;
	uint8_t fake_bool = 0;
	uint32_t string_size = 0;
	uint32_t array_size = 0;
	uint32_t binary_size = 0;
	uint32_t map_size = 0;
	int8_t ext_type = 0;
	uint32_t ext_size = 0;
	char sbuf[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

	fh = fopen(argv[1], "rb");
	if (fh == NULL){
		error_and_exit(strerror(errno));
	}

	cmp_init(&cmp, fh, file_reader, file_writer);

	/* Alternately, you can read objects until the stream is empty */
	while (1) {
		cmp_object_t obj;

		if (!cmp_read_object(&cmp, &obj)) {
			if (feof(fh))
				break;

			error_and_exit(cmp_strerror(&cmp));
		}

		switch (obj.type) {
		case CMP_TYPE_POSITIVE_FIXNUM:
		case CMP_TYPE_UINT8:
			//printf("Unsigned Integer: %u\n", obj.as.u8);
			printf("Unsigned Integer: %u\n", obj.as.u8);
			break;
		case CMP_TYPE_FIXMAP:
		case CMP_TYPE_MAP16:
		case CMP_TYPE_MAP32:
			printf("Map: %u\n", obj.as.map_size);
			break;
		case CMP_TYPE_FIXARRAY:
		case CMP_TYPE_ARRAY16:
		case CMP_TYPE_ARRAY32:
			printf("Array: %u\n", obj.as.array_size);
			break;
		case CMP_TYPE_FIXSTR:
		case CMP_TYPE_STR8:
		case CMP_TYPE_STR16:
		case CMP_TYPE_STR32:
			if (!read_bytes(sbuf, obj.as.str_size, fh))
				error_and_exit(strerror(errno));
			sbuf[obj.as.str_size] = 0;
			printf("String: %s\n", sbuf);
			break;
		case CMP_TYPE_BIN8:
		case CMP_TYPE_BIN16:
		case CMP_TYPE_BIN32:
			memset(sbuf, 0, sizeof(sbuf));
			if (!read_bytes(sbuf, obj.as.bin_size, fh))
				error_and_exit(strerror(errno));
			printf("Binary: %s\n", sbuf);
			break;
		case CMP_TYPE_NIL:
			printf("NULL\n");
			break;
		case CMP_TYPE_BOOLEAN:
			if (obj.as.boolean)
				printf("Boolean: true\n");
			else
				printf("Boolean: false\n");
			break;
		case CMP_TYPE_EXT8:
		case CMP_TYPE_EXT16:
		case CMP_TYPE_EXT32:
		case CMP_TYPE_FIXEXT1:
		case CMP_TYPE_FIXEXT2:
		case CMP_TYPE_FIXEXT4:
		case CMP_TYPE_FIXEXT8:
		case CMP_TYPE_FIXEXT16:
			if (obj.as.ext.type == 1) { /* Date object */
				if (!read_bytes(&year, sizeof(uint16_t), fh))
					error_and_exit(strerror(errno));

				if (!read_bytes(&month, sizeof(uint8_t), fh))
					error_and_exit(strerror(errno));

				if (!read_bytes(&day, sizeof(uint8_t), fh))
//.........这里部分代码省略.........
开发者ID:ssfang,项目名称:NDKProjectSample,代码行数:101,代码来源:cmp_unpacker.c


示例8: pmix_usock_recv_handler

void pmix_usock_recv_handler(int sd, short flags, void *cbdata)
{
    int rc;

    opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                        "%s usock:recv:handler called",
                        OPAL_NAME_PRINT(OPAL_PROC_MY_NAME));

    switch (mca_pmix_native_component.state) {
    case PMIX_USOCK_CONNECT_ACK:
        if (OPAL_SUCCESS == (rc = usock_recv_connect_ack())) {
            opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                                "%s usock:recv:handler starting send/recv events",
                                OPAL_NAME_PRINT(OPAL_PROC_MY_NAME));
            /* we connected! Start the send/recv events */
            if (!mca_pmix_native_component.recv_ev_active) {
                opal_event_add(&mca_pmix_native_component.recv_event, 0);
                mca_pmix_native_component.recv_ev_active = true;
            }
            if (mca_pmix_native_component.timer_ev_active) {
                opal_event_del(&mca_pmix_native_component.timer_event);
                mca_pmix_native_component.timer_ev_active = false;
            }
            /* if there is a message waiting to be sent, queue it */
            if (NULL == mca_pmix_native_component.send_msg) {
                mca_pmix_native_component.send_msg = (pmix_usock_send_t*)opal_list_remove_first(&mca_pmix_native_component.send_queue);
            }
            if (NULL != mca_pmix_native_component.send_msg && !mca_pmix_native_component.send_ev_active) {
                opal_event_add(&mca_pmix_native_component.send_event, 0);
                mca_pmix_native_component.send_ev_active = true;
            }
            /* update our state */
            mca_pmix_native_component.state = PMIX_USOCK_CONNECTED;
        } else {
            opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                                "%s UNABLE TO COMPLETE CONNECT ACK WITH SERVER",
                                OPAL_NAME_PRINT(OPAL_PROC_MY_NAME));
            opal_event_del(&mca_pmix_native_component.recv_event);
            mca_pmix_native_component.recv_ev_active = false;
            return;
        }
        break;
    case PMIX_USOCK_CONNECTED:
        opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                            "%s usock:recv:handler CONNECTED",
                            OPAL_NAME_PRINT(OPAL_PROC_MY_NAME));
        /* allocate a new message and setup for recv */
        if (NULL == mca_pmix_native_component.recv_msg) {
            opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                                "%s usock:recv:handler allocate new recv msg",
                                OPAL_NAME_PRINT(OPAL_PROC_MY_NAME));
            mca_pmix_native_component.recv_msg = OBJ_NEW(pmix_usock_recv_t);
            if (NULL == mca_pmix_native_component.recv_msg) {
                opal_output(0, "%s usock_recv_handler: unable to allocate recv message\n",
                            OPAL_NAME_PRINT(OPAL_PROC_MY_NAME));
                return;
            }
            /* start by reading the header */
            mca_pmix_native_component.recv_msg->rdptr = (char*)&mca_pmix_native_component.recv_msg->hdr;
            mca_pmix_native_component.recv_msg->rdbytes = sizeof(pmix_usock_hdr_t);
        }
        /* if the header hasn't been completely read, read it */
        if (!mca_pmix_native_component.recv_msg->hdr_recvd) {
            opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                                "usock:recv:handler read hdr");
            if (OPAL_SUCCESS == (rc = read_bytes(mca_pmix_native_component.recv_msg))) {
                /* completed reading the header */
                mca_pmix_native_component.recv_msg->hdr_recvd = true;
                /* if this is a zero-byte message, then we are done */
                if (0 == mca_pmix_native_component.recv_msg->hdr.nbytes) {
                    opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                                        "%s RECVD ZERO-BYTE MESSAGE FROM SERVER for tag %d",
                                        OPAL_NAME_PRINT(OPAL_PROC_MY_NAME),
                                        mca_pmix_native_component.recv_msg->hdr.tag);
                    mca_pmix_native_component.recv_msg->data = NULL;  // make sure
                    mca_pmix_native_component.recv_msg->rdptr = NULL;
                    mca_pmix_native_component.recv_msg->rdbytes = 0;
                } else {
                    opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                                        "%s usock:recv:handler allocate data region of size %lu",
                                        OPAL_NAME_PRINT(OPAL_PROC_MY_NAME),
                                        (unsigned long)mca_pmix_native_component.recv_msg->hdr.nbytes);
                    /* allocate the data region */
                    mca_pmix_native_component.recv_msg->data = (char*)malloc(mca_pmix_native_component.recv_msg->hdr.nbytes);
                    /* point to it */
                    mca_pmix_native_component.recv_msg->rdptr = mca_pmix_native_component.recv_msg->data;
                    mca_pmix_native_component.recv_msg->rdbytes = mca_pmix_native_component.recv_msg->hdr.nbytes;
                }
                /* fall thru and attempt to read the data */
            } else if (OPAL_ERR_RESOURCE_BUSY == rc ||
                       OPAL_ERR_WOULD_BLOCK == rc) {
                /* exit this event and let the event lib progress */
                return;
            } else {
                /* close the connection */
                opal_output_verbose(2, opal_pmix_base_framework.framework_output,
                                    "%s usock:recv:handler error reading bytes - closing connection",
                                    OPAL_NAME_PRINT(OPAL_PROC_MY_NAME));
                CLOSE_THE_SOCKET(mca_pmix_native_component.sd);
                return;
//.........这里部分代码省略.........
开发者ID:ORNL,项目名称:ompi,代码行数:101,代码来源:usock_sendrecv.c


示例9: user_data

// Parse the user data for captions. The udtype variable denotes
// to which type of data it belongs:
// 0 .. sequence header
// 1 .. GOP header
// 2 .. picture header
// Return TRUE if the data parsing finished, FALSE otherwise.
// estream->pos is advanced. Data is only processed if ustream->error
// is FALSE, parsing can set ustream->error to TRUE.
int user_data(struct lib_cc_decode *ctx, struct bitstream *ustream, int udtype, struct cc_subtitle *sub)
{
	dbg_print(CCX_DMT_VERBOSE, "user_data(%d)\n", udtype);

	// Shall not happen
	if (ustream->error || ustream->bitsleft <= 0)
	{
		// ustream->error=1;
		return 0; // Actually discarded on call.
		// CFS: Seen in a Wobble edited file.
		// fatal(CCX_COMMON_EXIT_BUG_BUG, "user_data: Impossible!");
	}

	// Do something
	ctx->stat_numuserheaders++;
	//header+=4;

	unsigned char *ud_header = next_bytes(ustream, 4);
	if (ustream->error || ustream->bitsleft <= 0)
	{
		return 0;  // Actually discarded on call.
		// CFS: Seen in Stick_VHS.mpg.
		// fatal(CCX_COMMON_EXIT_BUG_BUG, "user_data: Impossible!");
	}

	// DVD CC header, see
	// <http://www.theneitherworld.com/mcpoodle/SCC_TOOLS/DOCS/SCC_FORMAT.HTML>
	if ( !memcmp(ud_header,"\x43\x43", 2 ) )
	{
		ctx->stat_dvdccheaders++;

		// Probably unneeded, but keep looking for extra caption blocks
		int maybeextracb = 1;

		read_bytes(ustream, 4); // "43 43 01 F8"

		unsigned char pattern_flag = (unsigned char) read_bits(ustream,1);
		read_bits(ustream,1);
		int capcount=(int) read_bits(ustream,5);
		int truncate_flag = (int) read_bits(ustream,1); // truncate_flag - one CB extra

		int field1packet = 0; // expect Field 1 first
		if (pattern_flag == 0x00)
			field1packet=1; // expect Field 1 second

		dbg_print(CCX_DMT_VERBOSE, "Reading %d%s DVD CC segments\n",
				capcount, (truncate_flag?"+1":""));

		capcount += truncate_flag;

		// This data comes before the first frame header, so
		// in order to get the correct timing we need to set the
		// current time to one frame after the maximum time of the
		// last GOP.  Only useful when there are frames before
		// the GOP.
		if (ctx->timing->fts_max > 0)
			ctx->timing->fts_now = ctx->timing->fts_max + (LLONG) (1000.0/current_fps);

		int rcbcount = 0;
		for (int i=0; i<capcount; i++)
		{
			for (int j=0;j<2;j++)
			{
				unsigned char data[3];
				data[0]=read_u8(ustream);
				data[1]=read_u8(ustream);
				data[2]=read_u8(ustream);

				// Obey the truncate flag.
				if ( truncate_flag && i == capcount-1 && j == 1 )
				{
					maybeextracb = 0;
					break;
				}
				/* Field 1 and 2 data can be in either order,
				   with marker bytes of \xff and \xfe
				   Since markers can be repeated, use pattern as well */
				if ((data[0]&0xFE) == 0xFE) // Check if valid
				{
					if (data[0]==0xff && j==field1packet)
						data[0]=0x04; // Field 1
					else
						data[0]=0x05; // Field 2
					do_cb(ctx, data, sub);
					rcbcount++;
				}
				else
				{
					dbg_print(CCX_DMT_VERBOSE, "Illegal caption segment - stop here.\n");
					maybeextracb = 0;
					break;
				}
//.........这里部分代码省略.........
开发者ID:CCExtractor,项目名称:ccextractor,代码行数:101,代码来源:es_userdata.c


示例10: read_byte

/* Read single byte and return byte read */
static inline u8 read_byte(u16 port)
{
	u8 byte;
	read_bytes(port, 1, &byte, NULL);
	return byte;
}
开发者ID:AdriDlu,项目名称:coreboot,代码行数:7,代码来源:ec_lpc.c


示例11: spin_read_bytes

static int spin_read_bytes(thread_args *args, char *buf) {
  return read_bytes(args->fds.read_fd, buf, args->msg_size, 1);
}
开发者ID:github188,项目名称:grpc,代码行数:3,代码来源:low_level_ping_pong.c


示例12: blocking_read_bytes

static int blocking_read_bytes(thread_args *args, char *buf) {
  return read_bytes(args->fds.read_fd, buf, args->msg_size, 0);
}
开发者ID:github188,项目名称:grpc,代码行数:3,代码来源:low_level_ping_pong.c


示例13: read_interval_summary

 void read_interval_summary(int *bytes_read = NULL, int *sum = NULL)
 {
     read_bytes(3200, bytes_read, sum);
 }
开发者ID:BryanF1947,项目名称:GoldenCheetah,代码行数:4,代码来源:Bin2RideFile.cpp


示例14: read_header

 void read_header(uint16_t &header, uint16_t &command, uint16_t &length, int *bytes_read = NULL, int *sum = NULL)
 {
     header = read_bytes(2, bytes_read, sum);
     command = read_bytes(2, bytes_read, sum);
     length = read_bytes(2, bytes_read, sum);
 }
开发者ID:BryanF1947,项目名称:GoldenCheetah,代码行数:6,代码来源:Bin2RideFile.cpp


示例15: read_detail_record

    void read_detail_record(double *secs, int *bytes_read = NULL, int *sum = NULL)
    {
        int cad = read_bytes(1, bytes_read, sum);
        read_bytes(1, bytes_read, sum); // pedal_smoothness
        int lrbal = read_bytes(1, bytes_read, sum);
        int hr = read_bytes(1, bytes_read, sum);
        read_bytes(1, bytes_read, sum); // dummy
        int watts = read_bytes(2, bytes_read, sum);
        int nm = read_bytes(2, bytes_read, sum);
        double kph = read_bytes(2, bytes_read, sum);
        int alt = read_bytes(2, bytes_read, sum);
        double temp = read_bytes(2, bytes_read, sum)/10.0;
        double lat = read_bytes(4, bytes_read, sum);
        double lng = read_bytes(4, bytes_read, sum);
        double km = read_bytes(8, bytes_read, sum)/1000.0/1000.0;

        // Validations
        if (lrbal == 0xFF)
            lrbal = 0;
        else if ((lrbal & 0x200) == 0x200)
            lrbal = 100-lrbal;

        if (cad == 0xFF)
            cad = 0;

        if (hr == 0xFF)
            hr = 0;

        if (watts == 0xFFFF) // 65535
            watts = 0;

        if (kph == 0xFFFF) // 65535
            kph = 0;
        else
            kph = kph/10.0;

        if (temp == 0x8000)
            temp = 0;

        if (alt == 0x8000)
            alt = 0;

        if (lat == -2147483648) //2147483648
            lat = 0;
        else
            lat = lat/10000000.0;

        if (lng == -2147483648) //0x80000000
            lng = 0;
        else
            lng = lng/10000000.0;

        rideFile->appendPoint(*secs, cad, hr, km, kph, nm, watts, alt, lng, lat, 0.0, 0, temp, lrbal, interval);
        (*secs)++;
    }
开发者ID:BryanF1947,项目名称:GoldenCheetah,代码行数:55,代码来源:Bin2RideFile.cpp


示例16: google_chromeec_command_v3

static int google_chromeec_command_v3(struct chromeec_command *cec_command)
{
	struct ec_host_request rq;
	struct ec_host_response rs;
	const u8 *d;
	u8 csum = 0;
	int i;

	if (cec_command->cmd_size_in + sizeof(rq) > EC_LPC_HOST_PACKET_SIZE) {
		printk(BIOS_ERR, "EC cannot send %zu bytes\n",
		       cec_command->cmd_size_in + sizeof(rq));
		return -1;
	}

	if (cec_command->cmd_size_out > EC_LPC_HOST_PACKET_SIZE) {
		printk(BIOS_ERR, "EC cannot receive %d bytes\n",
		       cec_command->cmd_size_out);
		return -1;
	}

	if (google_chromeec_wait_ready(EC_LPC_ADDR_HOST_CMD)) {
		printk(BIOS_ERR, "Timeout waiting for EC start command %d!\n",
		       cec_command->cmd_code);
		return -1;
	}

	/* Fill in request packet */
	rq.struct_version = EC_HOST_REQUEST_VERSION;
	rq.checksum = 0;
	rq.command = cec_command->cmd_code |
		EC_CMD_PASSTHRU_OFFSET(cec_command->cmd_dev_index);
	rq.command_version = cec_command->cmd_version;
	rq.reserved = 0;
	rq.data_len = cec_command->cmd_size_in;

	/* Copy data and start checksum */
	write_bytes(EC_LPC_ADDR_HOST_PACKET + sizeof(rq),
		    cec_command->cmd_size_in,
		    (u8*)cec_command->cmd_data_in,
		    &csum);

	/* Finish checksum */
	for (i = 0, d = (const u8 *)&rq; i < sizeof(rq); i++, d++)
		csum += *d;

	/* Write checksum field so the entire packet sums to 0 */
	rq.checksum = -csum;

	/* Copy header */
	write_bytes(EC_LPC_ADDR_HOST_PACKET, sizeof(rq), (u8*)&rq, NULL);

	/* Start the command */
	write_byte(EC_COMMAND_PROTOCOL_3, EC_LPC_ADDR_HOST_CMD);

	if (google_chromeec_wait_ready(EC_LPC_ADDR_HOST_CMD)) {
		printk(BIOS_ERR, "Timeout waiting for EC process command %d!\n",
		       cec_command->cmd_code);
		return -1;
	}

	/* Check result */
	cec_command->cmd_code = read_byte(EC_LPC_ADDR_HOST_DATA);
	if (cec_command->cmd_code) {
		printk(BIOS_ERR, "EC returned error result code %d\n",
			cec_command->cmd_code);
		return -i;
	}

	/* Read back response header and start checksum */
	csum = 0;
	read_bytes(EC_LPC_ADDR_HOST_PACKET, sizeof(rs), (u8*)&rs, &csum);

	if (rs.struct_version != EC_HOST_RESPONSE_VERSION) {
		printk(BIOS_ERR, "EC response version mismatch (%d != %d)\n",
		       rs.struct_version, EC_HOST_RESPONSE_VERSION);
		return -1;
	}

	if (rs.reserved) {
		printk(BIOS_ERR, "EC response reserved is %d, should be 0\n",
			rs.reserved);
		return -1;
	}

	if (rs.data_len > cec_command->cmd_size_out) {
		printk(BIOS_ERR, "EC returned too much data (%d > %d)\n",
		       rs.data_len, cec_command->cmd_size_out);
		return -1;
	}

	/* Read back data and update checksum */
	read_bytes(EC_LPC_ADDR_HOST_PACKET + sizeof(rs),
		   rs.data_len,
		   cec_command->cmd_data_out,
		   &csum);

	/* Verify checksum */
	if (csum) {
		printk(BIOS_ERR, "EC response has invalid checksum\n");
		return -1;
//.........这里部分代码省略.........
开发者ID:AdriDlu,项目名称:coreboot,代码行数:101,代码来源:ec_lpc.c


示例17: google_chromeec_command_v1

static int google_chromeec_command_v1(struct chromeec_command *cec_command)
{
	struct ec_lpc_host_args args;
	u8 cmd_code = cec_command->cmd_code;
	u8 csum;

	/* Fill in args */
	args.flags = EC_HOST_ARGS_FLAG_FROM_HOST;
	args.command_version = cec_command->cmd_version;
	args.data_size = cec_command->cmd_size_in;

	/* Initialize checksum */
	csum = cmd_code + args.flags + args.command_version + args.data_size;

	write_bytes(EC_LPC_ADDR_HOST_PARAM,
		    cec_command->cmd_size_in,
		    (u8*)cec_command->cmd_data_in,
		    &csum);

	/* Finalize checksum and write args */
	args.checksum = csum;
	write_bytes(EC_LPC_ADDR_HOST_ARGS, sizeof(args), (u8*)&args, NULL);


	/* Issue the command */
	write_byte(cmd_code, EC_LPC_ADDR_HOST_CMD);

	if (google_chromeec_wait_ready(EC_LPC_ADDR_HOST_CMD)) {
		printk(BIOS_ERR, "Timeout waiting for EC process command %d!\n",
		       cec_command->cmd_code);
		return 1;
	}

	/* Check result */
	cec_command->cmd_code = read_byte(EC_LPC_ADDR_HOST_DATA);
	if (cec_command->cmd_code)
		return 1;

	/* Read back args */
	read_bytes(EC_LPC_ADDR_HOST_ARGS, sizeof(args), (u8*)&args, NULL);

	/*
	 * If EC didn't modify args flags, then somehow we sent a new-style
	 * command to an old EC, which means it would have read its params
	 * from the wrong place.
	 */
	if (!(args.flags & EC_HOST_ARGS_FLAG_TO_HOST)) {
		printk(BIOS_ERR, "EC protocol mismatch\n");
		return 1;
	}

	if (args.data_size > cec_command->cmd_size_out) {
		printk(BIOS_ERR, "EC returned too much data\n");
		return 1;
	}
	cec_command->cmd_size_out = args.data_size;

	/* Start calculating response checksum */
	csum = cmd_code + args.flags + args.command_version + args.data_size;

	/* Read data, if any */
	read_bytes(EC_LPC_ADDR_HOST_PARAM,
		   args.data_size,
		   cec_command->cmd_data_out,
		   &csum);

	/* Verify checksum */
	if (args.checksum != csum) {
		printk(BIOS_ERR, "EC response has invalid checksum\n");
		return 1;
	}

	return 0;
}
开发者ID:AdriDlu,项目名称:coreboot,代码行数:74,代码来源:ec_lpc.c


示例18: load_game

int load_game(char* s)
{
	int i, ver, vt_entries = MAX_VIEWTABLE;
	UINT8 t;
	SINT16 parm[7];
	char sig[8];
	char id[8];
	char description[256];
	FILE *f = fopen(s, "rb");

	if(!f)
		return err_BadFileOpen;

	read_bytes(f, sig, 8);
	if (strncmp (sig, strSig, 8)) {
		fclose(f);
		return err_BadFileOpen;
	}

	read_string (f, description);

	ver = read_uint8(f);
	if (ver == 0)
		vt_entries = 64;
	game.state = read_uint8(f);
	/* game.name - not saved */
	read_string(f, id);
	if(strcmp(id, game.id)) {
		fclose(f);
		return err_BadFileOpen;
	}
	/* game.crc - not saved */

	for (i = 0; i < MAX_FLAGS; i++)
		game.flags[i] = read_uint8(f);
	for (i = 0; i < MAX_VARS; i++)
		game.vars[i] = read_uint8(f);

	game.horizon = read_sint16(f);
	game.line_status = read_sint16(f);
	game.line_user_input = read_sint16(f);
	game.line_min_print = read_sint16(f);

	/* These are never saved */
	game.cursor_pos = 0;
	game.input_buffer[0] = 0;
	game.echo_buffer[0] = 0;
	game.keypress = 0;

	game.input_mode = read_sint16(f);
	game.lognum = read_sint16(f);

	game.player_control = read_sint16(f);
	game.quit_prog_now = read_sint16(f);
	game.status_line = read_sint16(f);
	game.clock_enabled = read_sint16(f);
	game.exit_all_logics = read_sint16(f);
	game.picture_shown = read_sint16(f);
	game.has_prompt = read_sint16(f);
	game.game_flags = read_sint16(f);
	game.input_enabled = !read_sint16(f);

	for (i = 0; i < _HEIGHT; i++)
		game.pri_table[i] = read_uint8(f);

	if(game.has_window)
		close_window();
	game.msg_box_ticks = 0;
	game.block.active = FALSE;
	/* game.window - fixed by close_window() */
	/* game.has_window - fixed by close_window() */

	game.gfx_mode = read_sint16(f);
	game.cursor_char = read_uint8(f);
	game.color_fg = read_sint16(f);
	game.color_bg = read_sint16(f);

	/* game.hires (#ifdef USE_HIRES) - rebuilt from image stack */
	/* game.sbuf - rebuilt from image stack */

	/* game.ego_words - fixed by clean_input */
	/* game.num_ego_words - fixed by clean_input */

	game.num_objects = read_sint16(f);
	for(i = 0; i < (SINT16)game.num_objects; i++)
		object_set_location(i, read_sint16(f));

	/* Those are not serialized */
	for (i = 0; i < MAX_DIRS; i++) {
		game.ev_keyp[i].occured = FALSE;
	}

	for (i = 0; i < MAX_STRINGS; i++)
		read_string (f, game.strings[i]);

	for (i = 0; i < MAX_DIRS; i++) {
		if(read_uint8(f) & RES_LOADED)
			agi_load_resource (rLOGIC, i);
		else
			agi_unload_resource (rLOGIC, i);
//.........这里部分代码省略.........
开发者ID:UIKit0,项目名称:sarien,代码行数:101,代码来源:savegame.c


示例19: read_page

    int read_page()
    {
        int sum = 0;
        int bytes_read = 0;

        char record_command = read_bytes(1, &bytes_read, &sum); // Always 0x89

        if ((0xff & record_command) == 0x89)
        {
            // 1. page # data
            int page_number = read_bytes(2, &bytes_read, &sum); // Page #
            int data_number = read_bytes(1, &bytes_read, &sum); // # of data in page



            if (page_number == 1 || (page_number == 64010 and secs == 0.0)) {
                // 2. Training Summary data (60 bytes)";
                read_bytes(39, &bytes_read, &sum);

                int record_training_flag = read_bytes(1, &bytes_read, &sum); // Training Flag

                if ((record_training_flag & 0x01) == 0) {
                    // Only new lap
                    rideFile->addInterval(last_interval_secs, secs, QString("%1").arg(interval));
                    last_interval_secs = secs;
                    interval ++;
                }

                read_bytes(20, &bytes_read, &sum); // Don't care
            }

            if (page_number == 1 || (page_number == 64010 and secs == 0.0)) {
                // Section Start time and date data (12 byte)

                int sec = read_bsd_byte(&bytes_read, &sum); // Section start time sec
                int min = read_bsd_byte(&bytes_read, &sum); // Section start time min
                int hour = read_bsd_byte(&bytes_read, &sum); // Section start time hour
                int day = read_bsd_byte(&bytes_read, &sum); // Section start time day
                int month = read_bytes(1, &bytes_read, &sum); // Section start time month
                int year = read_bsd_byte(&bytes_read, &sum); // Section start time year

                QDateTime t = QDateTime(QDate(2000+year,month,day), QTime(hour,min,sec));

                if (secs == 0.0 || rideFile->startTime().toTime_t()<0) {
                    rideFile->setStartTime(t);
                }
                else {
                    int gap = (t.toTime_t() - rideFile->startTime().toTime_t()) - secs;
                    secs += gap;
                }

                read_bytes(5, &bytes_read, &sum); // Don't care

                read_bytes(1, &bytes_read, &sum); // Data Flag
                data_number--;
            }

            for (int i = 0; i < data_number; ++i) {
                read_graph_data(&secs, &bytes_read, &sum);
            }

            int finish = 259-bytes_read;

            for (int i = 0; i < finish; i++) {
                read_bytes(1, &bytes_read, &sum); // to finish
            }

            read_bytes(1, &bytes_read, &sum); // Checksum
        }

        return bytes_read;
    }
开发者ID:jasonwiener,项目名称:GoldenCheetah,代码行数:72,代码来源:SyncRideFile.cpp


示例20: select_slot

static int select_slot (char *path)
{
	int i, key, active = 0;
	int rc = -1;
	int hm = 2, vm = 3;			/* box margins */
	char desc[NUM_SLOTS][40];

	for (i = 0; i < NUM_SLOTS; i++) {
		char name[MAX_PATH];
		FILE *f;
		char sig[8];
		sprintf (name, "%s/%08d.sav", path, i);
		f = fopen (name, "rb");
		if (f == NULL) {
			strcpy (desc[i], "          (empty slot)");
		} else {
			read_bytes (f, sig, 8);
			if (strncmp (sig, strSig, 8)) {
				strcpy (desc[i], "(corrupt file)");
			} else {
				read_string (f, desc[i]);
			}
			fclose(f);
		}
	}

	while (42) {
		char dstr[64];
		for (i = 0; i < NUM_SLOTS; i++) {
			sprintf (dstr, "[%-32.32s]", desc[i]);
			print_text (dstr, 0, hm + 1, vm + 4 + i,
				(40 - 2 * hm) - 1,
				i == active ? MSG_BOX_COLOUR : MSG_BOX_TEXT,
				i == active ? MSG_BOX_TEXT : MSG_BOX_COLOUR);

		}

		poll_timer ();		/* msdos driver -> does nothing */
		key = do_poll_keyboard ();
		if (!console_keyhandler (key)) {
			swi 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ read_c0_cause函数代码示例发布时间:2022-05-30
下一篇:
C++ read_byte函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap