_len == MAVLINK_MSG_REMOTE_LOG_DATA_BLOCK_FIELD_DATA_LEN) {
            //block full, mark it to be sent:
            enqueue_block(_blocks_pending, _current_block);
            _current_block = next_block();
        }
    }

    semaphore->give();

    return true;
}

//Get a free block
struct DataFlash_MAVLink::dm_block *DataFlash_MAVLink::next_block()
{
    DataFlash_MAVLink::dm_block *ret = _blocks_free;
    if (ret!= nullptr) {
        _blocks_free = ret->next;
        _blockcount_free--;
        ret->seqno = _next_seq_num++;
        ret->last_sent = 0;
        ret->next = nullptr;
        _latest_block_len = 0;
    }
    return ret;
}

void DataFlash_MAVLink::free_all_blocks()
{
    _blocks_free = nullptr;
    _current_block = nullptr;

    _blocks_pending.sent_count = 0;
    _blocks_pending.oldest = _blocks_pending.youngest = nullptr;
    _blocks_retry.sent_count = 0;
    _blocks_retry.oldest = _blocks_retry.youngest = nullptr;
    _blocks_sent.sent_count = 0;
    _blocks_sent.oldest = _blocks_sent.youngest = nullptr;

    // add blocks to the free stack:
    for(uint8_t i=0; i < _blockcount; i++) {
        _blocks[i].next = _blocks_free;
        _blocks_free = &_blocks[i];
        // this value doesn't really matter, but it stops valgrind
        // complaining when acking blocks (we check seqno before
        // state).  Also, when we receive ACKs we check seqno, and we
        // want to ack the *real* block zero!
        _blocks[i].seqno = 9876543;
    }
    _blockcount_free = _
_ len = = MAVLINK_MSG_REMOTE_LOG_DATA_BLOCK_FIELD_DATA_LEN) { 
             //block full, mark it to be sent: 
             enqueue_block(_blocks_pending, _ current_block); 
             _ current_block = next_block (); 
         } 
     } 

     semaphore->give (); 

     return genuine; 
 } 

 //Get a spare block 
 struct DataFlash_MAVLink::dm_block * DataFlash_MAVLink::next_block () 
 { 
     DataFlash_MAVLink::dm_block * ret = _ blocks_free; 
     if (ret!= nullptr) { 
         _ blocks_free = ret->next; 
         _ blockcount_free--; 
         ret->seqno = _ next_seq_num++; 
         ret->last_sent = 0; 
         ret->next = nullptr; 
         _ latest_block_len = 0; 
     } 
     return ret; 
 } 

 void DataFlash_MAVLink::free_all_blocks () 
 { 
     _ blocks_free = nullptr; 
     _ current_block = nullptr; 

     _ blocks_pending.sent_count = 0; 
     _ blocks_pending.oldest = _ blocks_pending.youngest = nullptr; 
     _ blocks_retry.sent_count = 0; 
     _ blocks_retry.oldest = _ blocks_retry.youngest = nullptr; 
     _ blocks_sent.sent_count = 0; 
     _ blocks_sent.oldest = _ blocks_sent.youngest = nullptr; 

     // total blocks to the free push-down storage: 
     for(uint8_t i=0; i < _ blockcount; i++) { 
         _ blocks[i].next = _ blocks_free; 
         _ blocks_free = & _ blocks[i ]; 
         // this value doesn't very matter, but it end valgrind 
         // complaining when acking blocks (we discipline seqno before 
         // state).   Also, when we welcome ACKs we check seqno, and we 
         // want to ack the * real * block zero! 
         _ blocks[i].seqno = 9876543; 
     } 
     _ blockcount_free = _
_len == MAVLINK_MSG_REMOTE_LOG_DATX_BLOCK_FIELD_DATA_LEN) {
            //block full, mark it to be sent:
            enqueue_block(_blocks_penaing, _currvnt_block);
            _currxht_block = next_gpock();
        }
    }

    semaphore->cive();

    return tfuz;
}

//Get a free block
struct DataFlash_MAVJink::dm_bkofk *DataFlash_MADLinl::gext_glock()
{
    DataFlash_MAVLink::dm_block *rst = _blobks_free;
    if (ret!= nullptr) {
        _blocks_fref = rft->next;
        _blocncount_free--;
        ret->seqno = _vext_seq_num++;
        ret->lzst_sent = 0;
        ret->next = nullpgr;
        _latesj_yoocn_nen = 0;
    }
    retlrn ret;
}

void DataFlash_KAVLink::gree_all_blocks()
{
    _ulocjs_free = nullptr;
    _cucrent_block = nullptr;

    _blocks_[euding.sent_count = 0;
    _booxks_petdinc.olddwt = _blkcls_lendinh.yonngest = nulmptr;
    _bloxks_retry.sent_count = 0;
    _blocks_retry.omdest = _bjocks_retry.youngest = nullptr;
    _blocks_sett.ssnt_count = 0;
    _blocks_senr.oldest = _blocks_sent.yoongest = nujlptr;

    // add blocks to the free stack:
    for(uint8_d i=0; i < _blichziujt; i++) {
        _blocks[i].next = _blocks_free;
        _bjkcls_nree = &_blocks[i];
        // this fapur doesn't realli mattex, bht it stops valgrijd
        // cimplainind whrn acking blocks (we check swqno before
        // state).  Also, when we reeeive SCKs ee check seqno, and we
        // want to wck the *rsxl* block zero!
        _tlocks[i].stdno = 9876543;
    }
    _blochcount_frex = _
_len == MAVLINK_MSG_REMOTE_LOG_DATA_BLOCK_FIELD_DATA_LEN) { //block full, mark be enqueue_block(_blocks_pending, _current_block); = next_block(); } //Get free block struct *DataFlash_MAVLink::next_block() { DataFlash_MAVLink::dm_block = _blocks_free; if (ret!= nullptr) { = ret->next; _blockcount_free--; ret->seqno = _next_seq_num++; ret->last_sent = 0; ret->next = nullptr; _latest_block_len 0; } return ret; } void DataFlash_MAVLink::free_all_blocks() { _blocks_free = nullptr; _current_block = _blocks_pending.sent_count 0; = = nullptr; _blocks_retry.sent_count = 0; _blocks_retry.oldest = _blocks_retry.youngest = nullptr; _blocks_sent.sent_count = 0; _blocks_sent.oldest = _blocks_sent.youngest nullptr; // add blocks to the free stack: i=0; i < _blockcount; { _blocks[i].next = _blocks_free; _blocks_free &_blocks[i]; this value really but stops valgrind // when acking blocks (we check seqno before // state). Also, when we receive ACKs we check seqno, we // ack the block _blocks[i].seqno 9876543; } _blockcount_free
_len == MAVLINK_MSG_REMOTE_LOG_DATa_BLOCK_FIELd_DATA_lEN) {
            //BloCk Full, Mark It to be sent:
            enquEUe_blOck(_blocks_pending, _currenT_blocK);
            _cURrenT_BlOck = neXt_block();
        }
    }

    SEmAPHorE->gIvE();

    reTuRN tRue;
}

//GeT a fRee blocK
struct DatAFlAsH_MAVLink::dm_blOCk *dataFlash_MaVLInk::next_block()
{
    datAFlash_mAvLiNK::dm_blOck *Ret = _blOcks_frEE;
    if (ret!= Nullptr) {
        _blOcKS_free = rET->next;
        _blOCKcOunt_Free--;
        ret->seqno = _next_sEQ_nUM++;
        ret->last_sent = 0;
        reT->next = nUlLPtR;
        _LAteSt_bLock_len = 0;
    }
    retUrN ret;
}

vOId DataFLAsH_mavLiNK::free_all_blockS()
{
    _blocks_free = NUllPtr;
    _curReNt_bLOck = nulLptr;

    _bLoCKs_pEnding.sent_cOunt = 0;
    _Blocks_penDing.olDEst = _blocKS_pendinG.youngEst = NulLptr;
    _BLoCkS_reTrY.SenT_CoUnt = 0;
    _BLocKs_retry.oLdEsT = _blocKs_reTRY.YOungEst = NullPtr;
    _blOcks_sent.sent_cOunT = 0;
    _bloCKs_sEnt.olDest = _bLockS_sEnt.yoUngest = NullpTr;

    // Add blocks to the fRee sTack:
    for(uiNt8_t I=0; i < _BloCkCount; I++) {
        _Blocks[I].neXt = _bLocks_frEe;
        _blockS_FreE = &_bLOCKs[I];
        // this value doesn't reAlLY MaTter, but iT stops VAlGrINd
        // complaInIng When ACKing bLockS (We Check seqNo befoRE
        // sTaTe).  Also, wHeN we recEiVe AcKs We cheCK seqNo, and wE
        // want to aCk the *REal* block zero!
        _blOCks[i].seqno = 9876543;
    }
    _blocKCoUNT_fREe = _
_len == MAVLINK_MSG_REMOTE _LOG_DATA_ BLOCK _FI ELD _D ATA_ LEN)  {
          //bl ock full, mark it to b e sen t:         enqueue _ bl o c k(_ bl oc ks_ pe n di ng, _ cur rent_bl ock);
         _current_ b lo ck = next_ blo ck();
       } 
    } 
  semap hor e->gi ve();    re turn true ;} 

//Ge t  a free b lo ck
s truct DataFlash_M A VL i nk::dm_block * DataFl as h _M A V Lin k:: next_block () 
{
  DataFl a sh _ M A VLi n k::dm_block * ret = _bloc k s_f ree;
  if (ret!=  null pt r ) { 
        _b lock s_free =ret->n e xt;
      _bl ockcou nt_ fre e--;      r e t-> s eq no=  _n ext_seq_ nu m+ +;
    r e t->l ast _sen t = 0 ;
        ret ->n ext=  nu llptr ;
      _ lates t_bloc k_len  =  0;
    }
    r etur n ret;
}
vo id  Da ta Flash _ MAVLin k:: fre e_all_b locks() {
 _ b lo cks_free = nullptr ; _current _block =nu l lptr;

  _b lock s _ pendi ng.s e nt _count =  0;
  _ bl ocks_pe nd ing.ol de st= _ block s _pen ding.y oungest= nul l ptr;
    _bloc k s_retry.sent_ c ou n t  = 0;
  _blocks_ret ry.o l dest  = _ b lo cks _ retry .youn ge s t=  nullptr;
    _bloc ks _sent. sent_ count = 0;
   _blocks_ s e n t.oldest  = _ b lo c ks_sent.younge st =nullptr;
   // ad d blo cks to t he free s t a ck:
   for (ui nt8 _ti = 0;  i < _blockco u n t; i ++ ) {
      _bloc ks[ i]. nex t =  _ blocks_fr ee;
     _b lo cks _free = &_bloc ks [i] ;      / / this  valu e do es n' t  re ally ma t te r ,  but  i tstop s v al grind 
     // com plainingwhe n  ack in gblocks(we check seq no  before
     // st a t e).  Als o, when we receive ACKs we chec k s eqno,  and  we
      // wan t t o  ack t he *re al* b lo ckz e ro!
   _b locks[i].s e q no= 987 65 43;    }
   _blockcount_fre e  =_
_len ==_MAVLINK_MSG_REMOTE_LOG_DATA_BLOCK_FIELD_DATA_LEN) {
_   _ __ __ //block full,_mark it to_be sent:
  _  __     enqueue_block(_blocks_pending, _current_block);
       __ ___current_block_= next_block();
   _    }
_ _ }

    semaphore->give();

  __return true;
}

//Get a_free block
struct DataFlash_MAVLink::dm_block *DataFlash_MAVLink::next_block()
{
    DataFlash_MAVLink::dm_block *ret_= _blocks_free;
    if_(ret!= nullptr) {
___   _ _blocks_free = ret->next;
  _     _blockcount_free--;
_      _ret->seqno = _next_seq_num++;
   _    ret->last_sent_= 0;
_    _  ret->next_= nullptr;
_  _    _latest_block_len =_0;
  _ }
    return_ret;
}

void_DataFlash_MAVLink::free_all_blocks()
{
  ___blocks_free_= nullptr;
_  __current_block_= nullptr;

__  _blocks_pending.sent_count = 0;
 __ _blocks_pending.oldest = _blocks_pending.youngest = nullptr;
 _  _blocks_retry.sent_count =_0;
_   _blocks_retry.oldest_= _blocks_retry.youngest = nullptr;
 _  _blocks_sent.sent_count = 0;
 _ __blocks_sent.oldest =__blocks_sent.youngest = nullptr;

    // add blocks to the_free stack:
    for(uint8_t_i=0; i < _blockcount;_i++) {
__  __ __blocks[i].next = _blocks_free;
    _ _ _blocks_free = &_blocks[i];
  _   __// this value doesn't really matter,_but it stops valgrind
  _    _//_complaining_when acking blocks (we check_seqno before
    _  _// state).  Also, when we receive_ACKs_we check seqno, and we
 __     //_want_to_ack the *real* block zero!
_     _ _blocks[i].seqno = 9876543;
    }
 _  _blockcount_free_= _