Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Doing NMEA command sequences with zsh ... ??!!



On Oct 13, 11:27pm, Vasiliy Ivanov wrote:
} Subject: Re: Doing NMEA command sequences with zsh ... ??!!
}
} > An NMEA command sequence consist of
} > $<commandname><parameter,nextparameter,....><*><checksum>
} > 
} > The checksum is the binary XOR of all characters between '$' and '*'.
} > This checksum is given a an hexadecimal number.
} 
} Not digging deep into NMEA stuff, only some related hints:
} 
} % integer a b; a=16#e7; b=16#3c; print $(([#16]a^b));
} 16#DB
} 
} % c='abcABC'; for i in ${(s..)c}; do print $((#i)); done
} 97
} 98
} 99
} 65
} 66
} 67

Zsh does support bitwise math ops, so

--- 8< --- snip --- 8< ---
print_nmea () {
  setopt localoptions C_BASES
  integer -i 16 checksum
  local i

  local commandname=$1
  shift
  local parameters=${(j:,:)*}

  local NMEA="$commandname$parameters"

  for i in ${(s..)NMEA}; do
    (( checksum ^= #i ))
  done

  print \$$NMEA\*$checksum
}
--- 8< --- snip --- 8< ---


-- 
Barton E. Schaefer



Messages sorted by: Reverse Date, Date, Thread, Author