SHARE
TWEET

Sean Brewer

a guest Jan 27th, 2010 3,677 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #synctime - synchronize your chronos watch to your computer
  2. #
  3. #
  4. # Copyright (c) 2010 Sean Brewer
  5. #
  6. # Permission is hereby granted, free of charge, to any person
  7. # obtaining a copy of this software and associated documentation
  8. # files (the "Software"), to deal in the Software without
  9. # restriction, including without limitation the rights to use,
  10. #
  11. # copies of the Software, and to permit persons to whom the
  12. # Software is furnished to do so, subject to the following
  13. # conditions:
  14. #
  15. # The above copyright notice and this permission notice shall be
  16. # included in all copies or substantial portions of the Software.
  17. #
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  20. # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. # OTHER DEALINGS IN THE SOFTWARE.
  26. #
  27. #
  28. #You can contact me at seabre986@gmail.com or on reddit (seabre) if you want.
  29. #
  30. #****TONS**** of mistakes in the last version. Sorry about that everybody.
  31.  
  32. import serial
  33. import datetime
  34. import array
  35. from time import sleep
  36. def splitIntoNPieces(s,n):
  37.     return [s[i:i+n] for i in range(0, len(s), n)]
  38.  
  39. def makeByteString(arr):
  40.     return array.array('B', arr).tostring()
  41.  
  42. def startAccessPoint():
  43.     return makeByteString([0xFF, 0x07, 0x03])
  44.    
  45.  
  46. def stopAccessPoint():
  47.     return makeByteString([0xFF, 0x09, 0x03])
  48.  
  49.  
  50. """
  51. kinda messy
  52.  
  53. Here's how this works.
  54. A packet for the watch sync looks like this:
  55. FF 31 16 03 94 34 01 07 DA 01 17 06 1E 00 00 00 00 00 00 00 00 00
  56. You have the first four bytes which we're just going to ignore.
  57. The 5th byte represents the hour you want to sync to.
  58. The 6th byte represents the minute you want to sync to.
  59. The 7th byte represents the second you want to sync to.
  60. The 9th byte represents the year you want to sync to.
  61. The 10th byte represents the month you want to sync to.
  62. The 11th byte represents the day you want to sync to.
  63. THe 14th and 15th bytes represent the temperature in celcius.
  64. The 16th and 17th bytes represent the altitude in meters.
  65.  
  66. It also stores some of these values in some unusual (to me) ways.
  67.  
  68. For hour, the value 0x80 needs to be added to the 24hr representation of the desired
  69. hour to sync to.
  70.  
  71. For year the value 0x700 needs to be subtracted from the desired year to sync to.
  72.  
  73. For temperature, the temperature (in celcius) needs to be multiplied by 0x0A.
  74.  
  75. Caveat emptor: There is no error checking implemented to check for valid ranges.
  76. """
  77. def syncTimeDateTempAlt(hour,minute,second,month,day,year,tempCelcius,altMeters):
  78.     adjHour = hour + 0x80 #assumes 24h based time entry
  79.     adjYear = year - 0x700
  80.     adjTempCelcius = tempCelcius * 0x0A
  81.  
  82.     cmd = [0xFF, 0x31, 0x16, 0x03,adjHour,minute,second,0x07,adjYear,month,day,0x06,0x1E]
  83.  
  84.     hexCelcius = hex(adjTempCelcius)[2:].zfill(4)
  85.     hexMeters = hex(altMeters)[2:].zfill(4)
  86.  
  87.     for i in splitIntoNPieces(hexCelcius,2):
  88.         cmd.append(int(i,16))
  89.     for i in splitIntoNPieces(hexMeters,2):
  90.         cmd.append(int(i,16))
  91.    
  92.     for i in xrange(0,5):
  93.         cmd.append(0)
  94.    
  95.     return makeByteString(cmd)
  96.  
  97.  
  98. #Open COM port 6 (check your system info to see which port
  99. #yours is actually on.)
  100. #argments are 5 (COM6), 115200 (bit rate), and timeout is set so
  101. #the serial read function won't loop forever.
  102. ser = serial.Serial(5,115200,timeout=1)
  103.  
  104. #Start access point
  105. ser.write(startAccessPoint())
  106.  
  107. raw_input("Please turn your watch to sync mode and turn on the transceiver (though if the transciever is already on you may have to turn it off then on again), then press enter...")
  108.  
  109. time = datetime.datetime.now()
  110.  
  111. ser.write(syncTimeDateTempAlt(time.hour,time.minute,time.second,time.month,time.day,time.year,0,0))
  112.  
  113. #Need to pause to make sure the watch actually gets the sync packet
  114. print "OK. Your watch should have been sync'd. Pausing for two seconds.."
  115.  
  116. sleep(2)
  117.  
  118. #The start access point command needs to come before the stop access point command
  119. #in order for the access point to turn off.
  120. ser.write(startAccessPoint())
  121. ser.write(stopAccessPoint())
  122.    
  123. ser.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top