var CONST =
{
   GPS   : 0,
   GAL   : 1,
   SBAS  : 2,
   GLN   : 3
};

//convert the returned hex ascii value to actually binary
function hex2bin(str)
{
   var buf = new Uint8Array(str.length/2); // 2 bytes for each char
   for (var ii=0, jj=0; ii<str.length-1; ii+=2)
      buf[jj++] = ('0x' + str[ii] + str[ii+1])/1;
   return buf;
}

function str2hex(str)
{
   var retStr = "";
   for(ii=0; ii<str.length; ii++)
      retStr += str.charCodeAt(ii).toString(16);
   return retStr;
}

function alm1b_obj()
{
   var MsgName = "[ALM1B]";
   
   var constIdx = 16;
   this.gpsAlm = null;
   this.glnAlm = null;
   this.sbasAlm = null;
   
   this.update = function(input)
   {
      var start = input.indexOf(MsgName);

      //don't start parsing if this is not the right message
      if(start < 0)
      {
         return false;
      }
      this.name = MsgName;
      
      //whatever you get, spit it back
      msgLine = input.substring(start).split(this.name);
      this.msgList = []; 
      for(i=0; i<msgLine.length; i++)
      {
         //if the length of the alm is long enough
         if(msgLine[i].length > 10)
         {
            msgLine[i] = str2hex(MsgName) + msgLine[i];
            var almBin = hex2bin(msgLine[i]);
            if(almBin.length > constIdx);
            switch(almBin[constIdx])
            {
               case CONST.GPS:  this.gpsAlm = almBin;   break;
               case CONST.GLN:  this.glnAlm = almBin;   break;
               case CONST.SBAS: this.sbasAlm = almBin;  break;
            }
         }
      }
      return true;
   }
}