anchor.diff:  txpk(Time, RF, DevAddr, FPort, Data) ->
       {atomic, L} = mnesia:transaction(fun() ->
           [D] = mnesia:read(links, DevAddr, write),
  -        FCnt =  case D#link.fcntdown of
  -                    N when N < 16#FFFF -> N+1;
  -                    _Else -> 0
  -                end,
  +        FCnt =  (D#link.fcntdown + 1) band 16#FFFFFFFF,
           NewD = D#link{fcntdown=FCnt},
           mnesia:write(links, NewD, write),
           NewD
  
positive.code:     end.
  
  fcnt_gap(A, B) ->
      if
          A =< B -> B - A;
          A > B -> 16#FFFF - A + B
      end.
  
  store_rxpk(MAC, RxQ, RF, DevAddr, FCnt, Data) ->
  
negative.code:         [L] ->
              case fcnt_gap(L#link.fcntup, FCnt) of
                  N when N < ?MAX_FCNT_GAP ->
                      NewFCnt = (L#link.fcntup + N) band 16#FFFFFFFF,
                      mnesia:dirty_write(links, L#link{fcntup = NewFCnt}),
                      {ok, L};
                  BigN ->
                      {error, {fcnt_gap_too_large, BigN}}
  