function [tms] = parseNSTBtms(fid);
%---------------------------------------------------------
% parse NSTB message type 40 (tms)
% Ju-Yong Do,  Jan 22, 2009
%---------------------------------------------------------
% input  : NSTB file indicator
% output : tms message in "tms"
%=========================================================
%=========================================================
global rx option

%read header
tms.id          = fread(fid, 1, '*uint16');      %tms identification number
gpsweek         = fread(fid, 1, 'uint16');
tms.tow         = fread(fid, 1, 'uint32')*1e-3; %time of validity in time of week (ms->sec)

%=========================================================
%read tms message
tms.msgcnt      = fread(fid, 1, '*uint8');      %message sequence counter (0,1, or 2)
tms.geoprn      = fread(fid, 1, '*uint8');      %GEO prn
tms.status      = fread(fid, 1, '*uint16');     %TMS status flags
tms.waasmsg     = fread(fid, 32, '*uint8');     %WAAS message

%stack up what's collected
rx.aiding.tms        = [rx.aiding.tms tms];

%=========================================================
% CRC test for sanity check
crcTestNSTB(fid, 9, 26, 2); %(fid,headLen,bodyLen,tailLen)

if option.plot,             
    disp('=======MESSAGE 40 TMS=======================================');
    disp(['tow= ',num2str(tms.tow),' sec']); 
end

return
%=========================================================
%=========================================================
