function print_acars_packet(cb)
%
% print_acars_packet(cb)
%
%    Input:
%        cb -- ascii character array as bytes
%

if length(cb) < 44
    fprintf("Packet too short, only %d characters\n",length(cb))
    return
end

disp(" ")

fprintf("Mode: %c\n", cb(6));
fprintf("Address: %s\n",cb(7:13));
ack = '   ';
if cb(14) == 0x06
    ack = 'ACK';
elseif cb(14) == 0x15
    ack = 'NAK';
end
fprintf("Ack: %s\n",ack);
fprintf("Msg Type: %s\n",cb(15:16));
fprintf("Block: %c\n", cb(17))
stx = '   ';
if cb(18) == 0x02
    stx = 'STX';
elseif cb(18) == 0x03
    stx = 'ETX';
end
fprintf("STX: %s\n", stx);
fprintf("Flight #: %s\n",cb(19:24));
disp(" ")

disp("Message:")
cc = 25; 
mb = zeros(1,220);
mbc = 1;
while ((cb(cc) ~= 0x03) && (cb(cc) ~= 0x17))
    mb(mbc) = cb(cc);
    if cb(cc) == '/'
        fprintf("%s\n",mb(1:mbc))
        mbc = 0;
    end
    cc = cc + 1;
    mbc = mbc + 1;
end
fprintf("%s\n",mb(1:mbc))

disp(' ');

fprintf("Mesage Length: %d\n", cc-24);
etx = '   ';
if cb(cc) == 0x03
    etx = 'ETX';
elseif cb(cc) == 0x17
    etx = 'ETB';
end
fprintf("ETX: %s\n", etx);

if cc+3 > length(cb)
    return;
end
fprintf("BCS: %x %x\n", cb(cc+2), cb(cc+3))
etb = '   ';
if cb(cc+3) == 0x17
    etb = 'ETB';
elseif cb(cc+3) == 0x7F
    etb = 'DEL';
end
fprintf("BCS Suffix: %s\n", etb);
fprintf("Total bytes: %d\n", cc+3)
end

