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


C++ AP_GPS::lock_port方法代码示例

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


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

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