title: UBLOX NEO6M checksum checking?
body: <p>I am reading the serial input from my serial connections and am receiving data input like this.  These are NMEA strings from a UBLOX NEO6M GPS receiver.</p>
  
  <pre><code>$GPRMC,202325.00,A,4008.94847,N,11135.48840,W,0.011,,241017,,,D*6F
  $GPVTG,,T,,M,0.011,N,0.020,K,D*24
  $GPGSA,A,3,18,24,32,51,08,10,15,27,20,14,21,,1.60,0.86,1.35*0A
  $GPGSV,4,1,15,04,44,270,32,08,15,319,30,10,57,284,42,13,04,036,*74
  $GPGSV,4,2,15,14,08,205,21,15,30,049,43,16,04,259,,18,74,010,41*7C
  $GPGSV,4,3,15,20,18,072,28,21,65,114,36,24,22,100,24,27,41,292,41*72
  $GPGSV,4,4,15,32,25,204,28,46,39,160,27,51,43,173,42*4D
  $GPGLL,4008.94847,N,11135.48840,W,202325.00,A,D*77
  </code></pre>
  
  <p>The last two digits of each line are its checksum.  Starting at the dollar sign and ending before the asterisk is the payload.  The checksum is supposed to be calculated from the payload using this algorithm from the manual:</p>
  
  <pre><code>The checksum algorithm used is the 8-Bit Fletcher Algorithm, which is used in the 
  TCP standard (RFC 1145).  This algorithm works as follows:
  Buffer[N] contains the data over which the checksum is to be calculated.
  The two CK_ values are 8-Bit unsigned integers, only! 
  If implementing with larger-sized integer values, make sure to 
  mask both CK_A and CK_B with 0xFF after both operations in the loop.
  After the loop, the two U1 values contain the checksum, 
  transmitted at the end of the packet.
  </code></pre>
  
  <p>Here is the code from the manual on how do to it.  I'm not sure what language the code is written in, but it is not python.  </p>
  
  <pre><code>CK_A = 0, CK_B = 0
  For(I=0;I&lt;N;I++)
      {
      CK_A = CK_A + Buffer[I]
      CK_B = CK_B + CK_A
      }
  </code></pre>
  
  <p>Here is my flawed python version of the same thing:</p>
  
  <pre><code>                x=0
                  ck_a=0
                  ck_b=0
                  lentemp=len(payloadstr)
                  while x &lt; lentemp:
                          ck_a = ck_a + payloadstr[x]
                          ck_b = ck_b + ck_a
                          x+=1
                  print('ck_a='+str(ck_a))
                  print('ck_b='+str(ck_b))
  </code></pre>
  
  <p>I am getting this error (not surprisingly):</p>
  
  <pre><code>ck_a = ck_a + payloadstr[x]
  TypeError: unsupported operand type(s) for +: 'int' and 'str'
  </code></pre>
  
  <p>Having said all of that, I know that I have a data type mismatch.  I'm not sure how to make ck_a and ck_b into an 8-bit integer.  Also, I'm not sure how to convert payload[str] into a number.  Are they talking about ASCII values?  Or are they talking about hex someway?</p>
  
  <p>Here's a link to the <a href="https://www.u-blox.com/sites/default/files/products/documents/u-blox6_ReceiverDescrProtSpec_%28GPS.G6-SW-10018%29_Public.pdf" rel="nofollow noreferrer">manual</a></p>
  
  <p>Page 85 is the bit about checksums.</p>