function [ok,smessage]=nmeachecksum(str)
%NMEACHECKSUM Check NMEA checksum
%   OK=NMEACHECKSUM(STR) checks the checksum of the NMEA string STR and returns
%   the boolean OK to indicate success (OK=1) or failure (OK=0).
%
%   [OK,MESS]=NMEACHECKSUM(STR) also returns a string MESS with the message part 
%   of STR, i.e. the with the checksum "*FF" removed.
%
%   See also NMEAREAD, NMEAGPGGA, ...
%
%   Copyright 2010, TU Delft, DEOS.

%   Created:    4 March 2010 by Hans van der Marel
%   Modified:   

[smessage,hexcheck] = strtok(str,'*');
dmessage=double(smessage); 
dcheck=hex2dec(hexcheck(2:end));

checksum=0;
for k=2:length(dmessage) 
  checksum=bitxor(checksum,dmessage(k));
end

ok = ( dcheck == checksum );

return  