// initialisation
void DataFlash_MAVLink::Init(const struct LogStructure *structure, uint8_t num_types)
{
    DataFlash_Backend::Init(structure, num_types);

    _blocks = NULL;
    while (_blockcount >= 8) { // 8 is a *magic* number
        _blocks = (struct dm_block *) malloc(_blockcount * sizeof(_blocks[0]));
        if (_blocks != NULL) {
            break;
        }
        _blockcount /= 2;
    }

    if (_blocks == NULL) {
        return;
    }

    free_all_blocks();
    stats_init();

    _initialised = true;
    _logging_started = true; // in actual fact, we throw away
                             // everything until a client connects.
                             // This stops calls to start_new_log from
                             // the vehicles
}
Пример #2
0
// initialisation
void DataFlash_MAVLink::Init()
{
    semaphore = hal.util->new_semaphore();
    if (semaphore == nullptr) {
        AP_HAL::panic("Failed to create DataFlash_MAVLink semaphore");
        return;
    }

    DataFlash_Backend::Init();

    _blocks = nullptr;
    while (_blockcount >= 8) { // 8 is a *magic* number
        _blocks = (struct dm_block *) malloc(_blockcount * sizeof(_blocks[0]));
        if (_blocks != nullptr) {
            break;
        }
        _blockcount /= 2;
    }

    if (_blocks == nullptr) {
        return;
    }

    free_all_blocks();
    stats_init();

    _initialised = true;
    _logging_started = true; // in actual fact, we throw away
                             // everything until a client connects.
                             // This stops calls to start_new_log from
                             // the vehicles
}
void DataFlash_MAVLink::handle_ack(mavlink_channel_t chan,
                                   mavlink_message_t* msg,
                                   uint32_t seqno)
{
    if (!_initialised) {
        return;
    }
    if(seqno == MAV_REMOTE_LOG_DATA_BLOCK_STOP) {
        Debug("Received stop-logging packet");
        if (_sending_to_client) {
            _sending_to_client = false;
            _last_response_time = hal.scheduler->millis();
        }
        return;
    }
    if(seqno == MAV_REMOTE_LOG_DATA_BLOCK_START) {
        if (!_sending_to_client) {
            Debug("Starting New Log");
            free_all_blocks();
            // _current_block = next_block();
            // if (_current_block == NULL) {
            //     Debug("No free blocks?!!!\n");
            //     return;
            // }
            stats_init();
            _sending_to_client = true;
            _target_system_id = msg->sysid;
            _target_component_id = msg->compid;
            _chan = chan;
            _next_seq_num = 0;
            _startup_messagewriter->reset();
            _last_response_time = hal.scheduler->millis();
            Debug("Target: (%u/%u)", _target_system_id, _target_component_id);
        }
        return;
    }

    // check SENT blocks (VERY likely to be first on the list):
    if (free_seqno_from_queue(seqno, _blocks_sent)) {
        // celebrate
        _last_response_time = hal.scheduler->millis();
    } else if(free_seqno_from_queue(seqno, _blocks_retry)) {
        // party
        _last_response_time = hal.scheduler->millis();
    } else {
        // probably acked already and put on the free list.
    }
}