fork(1) download
  1. #python code
  2. SV = {
  3. 1: [2,6],2: [3,7],3: [4,8],4: [5,9],5: [1,9],6: [2,10],7: [1,8],
  4. 8: [2,9],9: [3,10],10: [2,3],11: [3,4],12: [5,6],13: [6,7],14: [7,8],15: [8,9],
  5. 16: [9,10],17: [1,4],18: [2,5],19: [3,6],20: [4,7],21: [5,8],22: [6,9],23: [1,3],
  6. 24: [4,6],25: [5,7],26: [6,8], 27: [7,9],28: [8,10],29: [1,6],30: [2,7],31: [3,8],32: [4,9],
  7. }
  8.  
  9. def shift(register, feedback, output):
  10. """GPS Shift Register
  11.  
  12. :param list feedback: which positions to use as feedback (1 indexed)
  13. :param list output: which positions are output (1 indexed)
  14. :returns output of shift register:
  15.  
  16. """
  17.  
  18. # calculate output
  19. out = [register[i-1] for i in output]
  20. if len(out) > 1:
  21. out = sum(out) % 2
  22. else:
  23. out = out[0]
  24.  
  25. # modulo 2 add feedback
  26. fb = sum([register[i-1] for i in feedback]) % 2
  27.  
  28. # shift to the right
  29. for i in reversed(range(len(register[1:]))):
  30. register[i+1] = register[i]
  31.  
  32. # put feedback in position 1
  33. register[0] = fb
  34.  
  35. return out
  36.  
  37.  
  38.  
  39. def PRN(sv):
  40. """Build the CA code (PRN) for a given satellite ID
  41.  
  42. :param int sv: satellite code (1-32)
  43. :returns list: ca code for chosen satellite
  44.  
  45. """
  46.  
  47. # init registers
  48. G1 = [1 for i in range(10)]
  49. G2 = [1 for i in range(10)]
  50.  
  51. ca = [] # stuff output in here
  52.  
  53. # create sequence
  54. for i in xrange(1023):
  55. g1 = shift(G1, [3,10], [10])
  56. g2 = shift(G2, [2,3,6,8,9,10], SV[sv]) # <- sat chosen here from table
  57.  
  58. # modulo 2 add and append to the code
  59. ca.append((g1 + g2) % 2)
  60.  
  61. # return C/A code!
  62. return ca
  63.  
  64. #get PRN 24
  65. prn_code = PRN(24)
  66.  
  67. print prn_code;
Success #stdin #stdout 0.08s 45944KB
stdin
Standard input is empty
stdout
[1, 1, 1,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