/*发送透明传输数据*/ 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 ; }
bool CVechileMgr::SendLocationPos( _stVechile *p , int ncount ) { if( ncount <= 0 || p == NULL ) { return false ; } time_t now = share::Util::currentTimeUsec() ; srand( now ) ; int nrand = rand() ; // 产生随机报警 DataBuffer buf ; TermLocationHeader header ; BuildHeader( header.header, 0x200 , sizeof(GpsInfo), p ) ; unsigned int alarm = 0 ; if ( now - p->last_alam_ > _alam_time && _alam_time > 0 ) { alarm = htonl( nrand ) ; p->last_alam_ = now ; } memcpy( &header.gpsinfo.alarm, &alarm, sizeof(unsigned int) ) ; unsigned int state = 0 ; memcpy( &header.gpsinfo.state , &state, sizeof(unsigned int) ) ; int pos = p->gps_pos_ ; pos = pos + 1 ; pos = pos % ncount ; Point &pt = _gps_vec[pos] ; header.gpsinfo.heigth = htons(nrand%100) ; header.gpsinfo.speed = htons(get_car_speed());//htons(nrand%1000) ; header.gpsinfo.direction = htons(nrand%360) ; // 取得当前BCD的时间 get_bcd_time( header.gpsinfo.date_time ) ; if(header.gpsinfo.speed == 0) { header.gpsinfo.state.bit6 = 0; header.gpsinfo.state.bit7 = 0; header.gpsinfo.longitude = 0 ; header.gpsinfo.latitude = 0 ; } else { 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 ; }