当前位置: 首页>>代码示例>>C++>>正文


C++ DataBuffer::fillInt16方法代码示例

本文整理汇总了C++中DataBuffer::fillInt16方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBuffer::fillInt16方法的具体用法?C++ DataBuffer::fillInt16怎么用?C++ DataBuffer::fillInt16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataBuffer的用法示例。


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

示例1: SendTransparentMsg

/*发送透明传输数据*/
bool CVechileMgr::SendTransparentMsg(_stVechile *p , int ncount,unsigned short wType)
{
	if( ncount <= 0 ) {
		return false ;
	}

	DataBuffer transport_buf;
	TransHeader  header;

	int nLen = _logistics->BuildTransportData(wType,transport_buf);

	OUT_HEX(NULL, 0, "Transport", transport_buf.getBuffer(),transport_buf.getLength());

	BuildHeader(header.header, 0x900,nLen, p);

	DataBuffer sendbuf;

	sendbuf.writeBlock(&header, sizeof(header));
	sendbuf.writeBlock(transport_buf.getBuffer(), transport_buf.getLength());

	unsigned short  mlen = (sendbuf.getLength()-sizeof(GBheader)) & 0x03FF ;
	sendbuf.fillInt16( mlen, 3 ) ;

	GBFooter footer ;
	sendbuf.writeBlock(&footer, sizeof(footer) ) ;

	if ( ! Send5BData( p->fd_, sendbuf.getBuffer(), sendbuf.getLength() ) ) {
		p->car_state_ = OFF_LINE ;
		return false ;
	}
	p->lgs_time_ = share::Util::currentTimeUsec() ;

    return true ;
}
开发者ID:caocf,项目名称:workspace-kepler,代码行数:35,代码来源:vechilemgr.cpp

示例2: SendLocationPos


//.........这里部分代码省略.........
		header.gpsinfo.state.bit6 = 1;
		header.gpsinfo.state.bit7 = 1;
		header.gpsinfo.longitude = htonl( pt.lon ) ;
		header.gpsinfo.latitude  = htonl( pt.lat ) ;
	}

	buf.writeBlock( &header, sizeof(header) ) ;

	// 需要上传CAN的数据
	if ( now - p->last_candata_ > _candata_time && _candata_time > 0 ) {

		p->last_candata_ = now ;

		int index = nrand % 5;

		write_dword( buf, 0x01, 2000 ) ;
		write_word(  buf, 0x02, 100 ) ;
		write_word(  buf, 0x03, 800 ) ;
		if ( index != 0 ) {
			struct _B1{
				unsigned char cmd ;
				unsigned int  val ;
			};
			_B1 b1 ;
			b1.cmd = ( index - 1 ) ;
			b1.val = htonl( nrand ) ;

			write_block( buf, 0x11, (unsigned char*)&b1 , sizeof(_B1) ) ;
		} else {
			write_byte( buf, 0x11, 0 ) ;
		}

		if ( nrand % 2 == 0 ) {
			struct _B2{
				unsigned char type;
				unsigned int  val ;
				unsigned char dir ;
			};
			_B2 b2 ;
			b2.type = (( index + 1 ) % 5 ) ;
			b2.val  = htonl( index ) ;
			b2.dir  = ( index%2 == 0 ) ;

			write_block( buf, 0x12, (unsigned char*)&b2, sizeof(_B2) ) ;
		}
		if ( nrand % 3 == 0 ) {
			struct _B3{
				unsigned int   id ;
				unsigned short time ;
				unsigned char  result ;
			};
			_B3 b3 ;
			b3.id     = htonl( index ) ;
			b3.time   = htons( nrand % 100 ) ;
			b3.result = ( index % 2 == 0 ) ;

			write_block( buf , 0x13, (unsigned char*)&b3, sizeof(_B3) ) ;
		}

		switch( index ) {
		case 0:
			write_word(  buf, 0x20, nrand ) ;
			write_word(  buf, 0x21, nrand % 100 ) ;
			write_word(  buf, 0x22, nrand % 1000 ) ;
			write_word(  buf, 0x23, nrand % 80 ) ;
		case 1:
			write_dword( buf, 0x24, nrand % 157887 ) ;
			write_dword( buf, 0x25, nrand % 233555 ) ;
			write_dword( buf, 0x26, nrand % 200 ) ;
			write_dword( buf, 0x40, nrand % 3000 ) ;
		case 2:
			write_word(  buf, 0x41, nrand % 130 ) ;
			write_word(  buf, 0x42, nrand % 120 ) ;
			write_word(  buf, 0x43, nrand % 200 ) ;
			write_word(  buf, 0x44, nrand % 300 ) ;
		case 3:
			write_word(  buf, 0x45, nrand % 150 ) ;
			write_word(  buf, 0x46, nrand % 100 ) ;
		case 4:
			write_word(  buf, 0x47, nrand % 150 ) ;
			write_word(  buf, 0x48, nrand % 200 ) ;
			break ;
		}
	}

	// 长度为消息内容的长度去掉头和尾
	unsigned short  mlen = (buf.getLength()-sizeof(GBheader)) & 0x03FF ;
	buf.fillInt16( mlen, 3 ) ;

	GBFooter footer ;
	buf.writeBlock( &footer, sizeof(footer) ) ;

	if ( Send5BData( p->fd_, buf.getBuffer(), buf.getLength() ) ) {
		p->gps_pos_ = pos ;
		return true ;
	}
	p->car_state_ = OFF_LINE ;
	// 发送位置包
	return false ;
}
开发者ID:caocf,项目名称:workspace-kepler,代码行数:101,代码来源:vechilemgr.cpp


注:本文中的DataBuffer::fillInt16方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。