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

C++ ap_hal::UARTDriver类代码示例

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

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



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

示例1: _printf

void AP_AccelCal::_printf(const char* fmt, ...)
{
    if (!_gcs) {
        return;
    }
    char msg[50];
    va_list ap;
    va_start(ap, fmt);
    hal.util->vsnprintf(msg, sizeof(msg), fmt, ap);
    va_end(ap);
    if (msg[strlen(msg)-1] == '\n') {
        // STATUSTEXT messages should not add linefeed
        msg[strlen(msg)-1] = 0;
    }
    AP_HAL::UARTDriver *uart = _gcs->get_uart();
    /*
     *     to ensure these messages get to the user we need to wait for the
     *     port send buffer to have enough room
     */
    while (uart->txspace() < MAVLINK_NUM_NON_PAYLOAD_BYTES+MAVLINK_MSG_ID_STATUSTEXT_LEN) {
        hal.scheduler->delay(1);
    }

#if !APM_BUILD_TYPE(APM_BUILD_Replay)
    _gcs->send_text(MAV_SEVERITY_CRITICAL, msg);
#endif
}
开发者ID:Benbenbeni,项目名称:ardupilot-1,代码行数:27,代码来源:AP_AccelCal.cpp


示例2: send_blob_update

/*
  send some more initialisation string bytes if there is room in the
  UART transmit buffer
 */
void AP_GPS::send_blob_update(uint8_t instance)
{
    // see if we can write some more of the initialisation blob
    if (initblob_state[instance].remaining > 0) {
        AP_HAL::UARTDriver *port = instance==0?hal.uartB:hal.uartE;
        int16_t space = port->txspace();
        if (space > (int16_t)initblob_state[instance].remaining) {
            space = initblob_state[instance].remaining;
        }
        while (space > 0) {
            port->write(pgm_read_byte(initblob_state[instance].blob));
            initblob_state[instance].blob++;
            space--;
            initblob_state[instance].remaining--;
        }
    }
}
开发者ID:AdiKulkarni,项目名称:ardupilot,代码行数:21,代码来源:AP_GPS.cpp


示例3: printf

void AP_InertialSensor_UserInteract_MAVLink::printf(const char* fmt, ...)
{
    char msg[50];
    va_list ap;
    va_start(ap, fmt);
    hal.util->vsnprintf(msg, sizeof(msg), fmt, ap);
    va_end(ap);
    if (msg[strlen(msg)-1] == '\n') {
        // STATUSTEXT messages should not add linefeed
        msg[strlen(msg)-1] = 0;
    }
    AP_HAL::UARTDriver *uart = _gcs->get_uart();
    /*
      to ensure these messages get to the user we need to wait for the
      port send buffer to have enough room
     */
    while (uart->txspace() < MAVLINK_NUM_NON_PAYLOAD_BYTES+MAVLINK_MSG_ID_STATUSTEXT_LEN) {
        hal.scheduler->delay(1);
    }
    _gcs->send_text(MAV_SEVERITY_CRITICAL, msg);
}
开发者ID:08shwang,项目名称:ardupilot,代码行数:21,代码来源:AP_InertialSensor_UserInteract_MAVLink.cpp


示例4: begin

/*
  setup a UART, handling begin() and init()
 */
void
GCS_MAVLINK::setup_uart(const AP_SerialManager& serial_manager, AP_SerialManager::SerialProtocol protocol, uint8_t instance)
{
    // search for serial port

    AP_HAL::UARTDriver *uart;
    uart = serial_manager.find_serial(protocol, instance);
    if (uart == NULL) {
        // return immediately if not found
        return;
    }

    // get associated mavlink channel
    mavlink_channel_t mav_chan;
    if (!serial_manager.get_mavlink_channel(protocol, instance, mav_chan)) {
        // return immediately in unlikely case mavlink channel cannot be found
        return;
    }

    /*
      Now try to cope with SiK radios that may be stuck in bootloader
      mode because CTS was held while powering on. This tells the
      bootloader to wait for a firmware. It affects any SiK radio with
      CTS connected that is externally powered. To cope we send 0x30
      0x20 at 115200 on startup, which tells the bootloader to reset
      and boot normally
     */
    uart->begin(115200);
    AP_HAL::UARTDriver::flow_control old_flow_control = uart->get_flow_control();
    uart->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE);
    for (uint8_t i=0; i<3; i++) {
        hal.scheduler->delay(1);
        uart->write(0x30);
        uart->write(0x20);
    }
    // since tcdrain() and TCSADRAIN may not be implemented...
    hal.scheduler->delay(1);
    
    uart->set_flow_control(old_flow_control);

    // now change back to desired baudrate
    uart->begin(serial_manager.find_baudrate(protocol, instance));

    // and init the gcs instance
    init(uart, mav_chan);
}
开发者ID:radiohail,项目名称:ardupilot,代码行数:49,代码来源:GCS_Common.cpp


示例5: if

/*
  run detection step for one GPS instance. If this finds a GPS then it
  will fill in drivers[instance] and change state[instance].status
  from NO_GPS to NO_FIX.
 */
void
AP_GPS::detect_instance(uint8_t instance)
{
    AP_GPS_Backend *new_gps = NULL;
    AP_HAL::UARTDriver *port = instance==0?hal.uartB:hal.uartE;
    struct detect_state *dstate = &detect_state[instance];

    if (port == NULL) {
        // UART not available
        return;
    }

    uint32_t now = hal.scheduler->millis();

    state[instance].instance = instance;
    state[instance].status = NO_GPS;

    // record the time when we started detection. This is used to try
    // to avoid initialising a uBlox as a NMEA GPS
    if (dstate->detect_started_ms == 0) {
        dstate->detect_started_ms = now;
    }

    if (now - dstate->last_baud_change_ms > 1200) {
        // try the next baud rate
		dstate->last_baud++;
		if (dstate->last_baud == sizeof(_baudrates) / sizeof(_baudrates[0])) {
			dstate->last_baud = 0;
		}
		uint32_t baudrate = pgm_read_dword(&_baudrates[dstate->last_baud]);
		port->begin(baudrate, 256, 16);		
		dstate->last_baud_change_ms = now;
        send_blob_start(instance, _initialisation_blob, sizeof(_initialisation_blob));
    }

    send_blob_update(instance);

    while (port->available() > 0 && new_gps == NULL) {
        uint8_t data = port->read();
        /*
          running a uBlox at less than 38400 will lead to packet
          corruption, as we can't receive the packets in the 200ms
          window for 5Hz fixes. The NMEA startup message should force
          the uBlox into 38400 no matter what rate it is configured
          for.
        */
        if ((_type[instance] == GPS_TYPE_AUTO || _type[instance] == GPS_TYPE_UBLOX) &&
            pgm_read_dword(&_baudrates[dstate->last_baud]) >= 38400 && 
            AP_GPS_UBLOX::_detect(dstate->ublox_detect_state, data)) {
            hal.console->print_P(PSTR(" ublox "));
            new_gps = new AP_GPS_UBLOX(*this, state[instance], port);
        } 
		else if ((_type[instance] == GPS_TYPE_AUTO || _type[instance] == GPS_TYPE_MTK19) &&
                 AP_GPS_MTK19::_detect(dstate->mtk19_detect_state, data)) {
			hal.console->print_P(PSTR(" MTK19 "));
			new_gps = new AP_GPS_MTK19(*this, state[instance], port);
		} 
		else if ((_type[instance] == GPS_TYPE_AUTO || _type[instance] == GPS_TYPE_MTK) &&
                 AP_GPS_MTK::_detect(dstate->mtk_detect_state, data)) {
			hal.console->print_P(PSTR(" MTK "));
			new_gps = new AP_GPS_MTK(*this, state[instance], port);
		}
#if GPS_RTK_AVAILABLE
        else if ((_type[instance] == GPS_TYPE_AUTO || _type[instance] == GPS_TYPE_SBP) &&
                 AP_GPS_SBP::_detect(dstate->sbp_detect_state, data)) {
            hal.console->print_P(PSTR(" SBP "));
            new_gps = new AP_GPS_SBP(*this, state[instance], port);
        }
#endif // HAL_CPU_CLASS
#if !defined( __AVR_ATmega1280__ )
		// save a bit of code space on a 1280
		else if ((_type[instance] == GPS_TYPE_AUTO || _type[instance] == GPS_TYPE_SIRF) &&
                 AP_GPS_SIRF::_detect(dstate->sirf_detect_state, data)) {
			hal.console->print_P(PSTR(" SIRF "));
			new_gps = new AP_GPS_SIRF(*this, state[instance], port);
		}
		else if (now - dstate->detect_started_ms > 5000) {
			// prevent false detection of NMEA mode in
			// a MTK or UBLOX which has booted in NMEA mode
			if ((_type[instance] == GPS_TYPE_AUTO || _type[instance] == GPS_TYPE_NMEA) &&
                AP_GPS_NMEA::_detect(dstate->nmea_detect_state, data)) {
				hal.console->print_P(PSTR(" NMEA "));
				new_gps = new AP_GPS_NMEA(*this, state[instance], port);
			}
		}
#endif
	}

	if (new_gps != NULL) {
        state[instance].status = NO_FIX;
        drivers[instance] = new_gps;
        timing[instance].last_message_time_ms = now;
	}
}
开发者ID:AdiKulkarni,项目名称:ardupilot,代码行数:99,代码来源:AP_GPS.cpp


示例6: handle_serial_control

/**
   handle a SERIAL_CONTROL message
 */
void GCS_MAVLINK::handle_serial_control(mavlink_message_t *msg, AP_GPS &gps)
{
    mavlink_serial_control_t packet;
    mavlink_msg_serial_control_decode(msg, &packet);

    AP_HAL::UARTDriver *port = NULL;

    if (packet.flags & SERIAL_CONTROL_FLAG_REPLY) {
        // how did this packet get to us?
        return;
    }

    bool exclusive = (packet.flags & SERIAL_CONTROL_FLAG_EXCLUSIVE) != 0;

    switch (packet.device) {
    case SERIAL_CONTROL_DEV_TELEM1:
        port = hal.uartC;
        lock_channel(MAVLINK_COMM_1, exclusive);
        break;
    case SERIAL_CONTROL_DEV_TELEM2:
        port = hal.uartD;
        lock_channel(MAVLINK_COMM_2, exclusive);
        break;
    case SERIAL_CONTROL_DEV_GPS1:
        port = hal.uartB;
        gps.lock_port(0, exclusive);
        break;
    case SERIAL_CONTROL_DEV_GPS2:
        port = hal.uartE;
        gps.lock_port(1, exclusive);
        break;
    default:
        // not supported yet
        return;
    }

    if (exclusive) {
        // force flow control off for exclusive access. This protocol
        // is used to talk to bootloaders which may not have flow
        // control support
        port->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE);
    }

    // optionally change the baudrate
    if (packet.baudrate != 0) {
        port->begin(packet.baudrate);
    }

    // write the data
    if (packet.count != 0) {
        if ((packet.flags & SERIAL_CONTROL_FLAG_BLOCKING) == 0) {
            port->write(packet.data, packet.count);
        } else {
            const uint8_t *data = &packet.data[0];
            uint8_t count = packet.count;
            while (count > 0) {
                while (port->txspace() <= 0) {
                    hal.scheduler->delay(5);
                }
                uint16_t n = port->txspace();
                if (n > packet.count) {
                    n = packet.count;
                }
                port->write(data, n);
                data += n;
                count -= n;
            }
        }
    }

    if ((packet.flags & SERIAL_CONTROL_FLAG_RESPOND) == 0) {
        // no response expected
        return;
    }

    uint8_t flags = packet.flags;

more_data:
    // sleep for the timeout
    while (packet.timeout != 0 &&
            port->available() < (int16_t)sizeof(packet.data)) {
        hal.scheduler->delay(1);
        packet.timeout--;
    }

    packet.flags = SERIAL_CONTROL_FLAG_REPLY;

    // work out how many bytes are available
    int16_t available = port->available();
    if (available < 0) {
        available = 0;
    }
    if (available > (int16_t)sizeof(packet.data)) {
        available = sizeof(packet.data);
    }

    // read any reply data
//.........这里部分代码省略.........
开发者ID:bluerobotics,项目名称:ardupilot-bluerov-apm,代码行数:101,代码来源:GCS_serial_control.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ thrift::ClientReceiveState类代码示例发布时间:2022-05-31
下一篇:
C++ ap::real_2d_array类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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