{"id":4554,"date":"2014-10-16T09:57:44","date_gmt":"2014-10-16T14:57:44","guid":{"rendered":"http:\/\/w0ep.us\/OM\/?p=4554"},"modified":"2014-10-16T21:56:12","modified_gmt":"2014-10-17T02:56:12","slug":"little-endian","status":"publish","type":"post","link":"http:\/\/w0ep.us\/OM\/?p=4554","title":{"rendered":"Little Endian"},"content":{"rendered":"<p>[Yesterday run: 3.4 miles]<\/p>\n<p>I&#8217;ve been all projecty and working on various stuff recently.\u00a0 One of the things I&#8217;ve been playing with is trying to get some software to read the output of the GPS in my GPS disciplined oscillator.<\/p>\n<p>I have a Windows program from Trimble which works fine.\u00a0 But I was thinking about putting a BeagleBone or Arduino into the GPSDO and have it show interesting information on a little LCD, like the current GPS time and date.\u00a0 I could even have it act as an NTP server to tell all of my other computers what the correct time\/date is.<\/p>\n<p>To do that, I need to now how to read the TSIP protocol coming from the GPS in that box.<\/p>\n<p>I have the TSIP line routed to the front of the box, and I&#8217;ve been playing with this BeagleBone (white) running Debian Linux.\u00a0 I can get to the data, so far so good.<\/p>\n<p>I have two software packages that claim to be able to talk TSIP: gpsd, a GPS daemon program and ntpd, the NTP time server program.\u00a0 Neither of them is successful in translating the TSIP coming from this thing.<\/p>\n<p>So I dug around into the TSIP protocol information a bit.\u00a0 And I was able to get some binary data from the serial port on the BBW\u00a0 (beaglebone white) and put it in a file.\u00a0 Using the &#8216;od&#8217; command I can show the hexadecimal values of the data.\u00a0 It was looking oh so close to the patterns I would expect, but something was not quite right.<\/p>\n<p>Then I discovered that every pair of bytes is swapped.\u00a0 !\u00a0\u00a0 This is a known thing in the computer world called &#8220;endian&#8221;.\u00a0 You have your Big Endian computers and your Little Endian computers.\u00a0 It has to do with the way the CPU fetches bytes from memory.\u00a0 If it does one byte at a time, no problem.\u00a0 But if it does multiple bytes at a time, some CPUs fetch the &#8220;high&#8221; byte first and some the &#8220;low&#8221; byte first.\u00a0 As an example, pretend you have a number like\u00a0 23,456 and your computer can put 3 digits in each memory hole.\u00a0 So it puts 023 in one hole and 456 in another.\u00a0 Some computers put 023 in hole number 5 and 456 in hole number 6.\u00a0 Others put 023 in 6 and 456 in 5.\u00a0 When these computers swap data they have to know which thing to send first.\u00a0 I know that isn&#8217;t a very useful example.\u00a0 Anyway&#8230;<\/p>\n<p>I used this command:<\/p>\n<p>dd if=\/dev\/ttyO2 of=gps.data conv=swab<\/p>\n<p>which swaps the bytes around.\u00a0 Now the gps data in the file gps.data actually looks pretty good.\u00a0 I don&#8217;t know if the numbers are right, but the packet begin and end points make sense.<\/p>\n<p>Ok, so where is this going wrong?\u00a0 Is the GPS sending stuff to me in swapped order\u00a0 (I think so), or is the serial port on the BBW doing this (seems unlikely)?\u00a0 A mystery.\u00a0 I may have to get another computer running linux and hook it up and see if I get the same effect.<\/p>\n<p>I think I may be able to set up a named pipe (a file that passes data through) and have the dd command read from the serial port, swap the bytes and send it to the named pipe, kind of an inline translator.\u00a0 Then I can point the ntpd program at the other end of the translator and see if it works.\u00a0 Unfortunately that would be a one-way\/read-only thing.\u00a0 If it tries to write to the gps it will fail.<\/p>\n<p>&#8212;<\/p>\n<p>Later&#8230;<\/p>\n<p>I tried the named pipe thing, that didn&#8217;t work.\u00a0 But I was able to whip together a small program to parse the data from the GPS and it is working fine.\u00a0 So, no endian problem after all.\u00a0 Very strange.\u00a0 I think maybe my &#8220;od&#8221; command was fooling me somehow.\u00a0 The parser is working fine and I can see the data from the GPS just great.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Yesterday run: 3.4 miles] I&#8217;ve been all projecty and working on various stuff recently.\u00a0 One of the things I&#8217;ve been playing with is trying to get some software to read the output of the GPS in my GPS disciplined oscillator. I have a Windows program from Trimble which works fine.\u00a0 But I was thinking about [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-4554","post","type-post","status-publish","format-standard","hentry","category-other-thoughts"],"_links":{"self":[{"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=\/wp\/v2\/posts\/4554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4554"}],"version-history":[{"count":3,"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=\/wp\/v2\/posts\/4554\/revisions"}],"predecessor-version":[{"id":4557,"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=\/wp\/v2\/posts\/4554\/revisions\/4557"}],"wp:attachment":[{"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4554"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/w0ep.us\/OM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}