// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: parse_gpsd_pps(char*, int)
void parse_gpsd_pps(char *s, int type)
{
double clock_sec, clock_nsec;
double real_sec, real_nsec;
double precision;

   // decode the PPS message - used to get info for the PPS plot

   saw_gpsd_pps |= type;
   if((saw_gpsd_pps & 0x01) && (type & 0x02)) { // pps takes priority over toff
      return;
   }
   pps_enabled = 1;
   have_pps_enable = 11;

   precision = 0;  // NTP precision
   clock_sec = real_sec = 0.0;
   clock_nsec = real_nsec = 0.0;

   while(s) {
      s = get_json_field(s);
      strcpy(gpsd_cmd, msg_field);
      if(gpsd_cmd[0] == 0) continue; 

      s = get_json_field(s);
log_gpsd_cmd();

      if(!strcmp(gpsd_cmd, "\"CLOCK_SEC\"")) {
         clock_sec = atof(msg_field);
      }
      else if(!strcmp(gpsd_cmd, "\"CLOCK_NSEC\"")) { 
         clock_nsec = atof(msg_field)*1.0E-9;
      }
      else if(!strcmp(gpsd_cmd, "\"REAL_SEC\"")) { 
         real_sec = atof(msg_field);
      }
      else if(!strcmp(gpsd_cmd, "\"REAL_NSEC\"")) { 
         real_nsec = atof(msg_field)*1.0E-9;
      }
      else if(!strcmp(gpsd_cmd, "\"PRECISION\"")) { // ntp style power of two seconds
         saw_gpsd_pre = 1;
         precision = atof(msg_field);
         precision = pow(2.0, precision);
      }
   }

   pps_offset = (clock_sec - real_sec);
   have_pps_offset = 8;
   have_rcvr_pps = 8;
   pps_offset += (clock_nsec - real_nsec);
   pps_offset *= 1.0E9;
//adadad   if(jitter_adev == 0) do_pps_adev(pps_offset);
if(debug_file) fprintf(debug_file, "pps offset:%.10f", pps_offset);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x173e10(%rip), %rax    # 0x21b0ac
movl (%rax), %ecx
orl %esi, %ecx
movl %ecx, (%rax)
andl $0x2, %esi
shrl %esi
testl %ecx, %esi
jne 0xa74f7
movq %rdi, %rbx
leaq 0x266a67(%rip), %rax    # 0x30dd20
movb $0x1, (%rax)
leaq 0x266019(%rip), %rax    # 0x30d2dc
movl $0xb, (%rax)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x2cad37(%rip), %r14    # 0x372010
leaq 0x294760(%rip), %r15    # 0x33ba40
movabsq $0x224345534e5f4b, %r13 # imm = 0x224345534E5F4B
leaq 0x10ecf6(%r13), %r12
xorps %xmm1, %xmm1
movsd %xmm1, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movsd %xmm0, -0x30(%rbp)
testq %rbx, %rbx
je 0xa748f
movq %rbx, %rdi
callq 0xa6568
movq %rax, %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0x9340
movsd -0x30(%rbp), %xmm0
cmpb $0x0, 0x2cace2(%rip)    # 0x372010
je 0xa7303
movq %rbx, %rdi
callq 0xa6568
movq %rax, %rbx
callq 0xa6663
movq 0x2cacc9(%rip), %rax    # 0x372010
movabsq $0x535f4b434f4c4322, %rcx # imm = 0x535F4B434F4C4322
xorq %rcx, %rax
movl 0x2cacbe(%rip), %ecx    # 0x372018
xorq $0x224345, %rcx         # imm = 0x224345
orq %rax, %rcx
je 0xa7463
movq 0x2cac9f(%rip), %rax    # 0x372010
movabsq $0x4e5f4b434f4c4322, %rcx # imm = 0x4E5F4B434F4C4322
xorq %rcx, %rax
movq 0x2cac90(%rip), %rcx    # 0x372015
xorq %r13, %rcx
orq %rax, %rcx
je 0xa747a
movq 0x2cac78(%rip), %rax    # 0x372010
movabsq $0x45535f4c41455222, %rcx # imm = 0x45535F4C41455222
xorq %rcx, %rax
movq 0x2cac67(%rip), %rcx    # 0x372013
xorq %r12, %rcx
orq %rax, %rcx
je 0xa742d
movq 0x2cac55(%rip), %rax    # 0x372010
movabsq $0x534e5f4c41455222, %rcx # imm = 0x534E5F4C41455222
xorq %rcx, %rax
movl 0x2cac4a(%rip), %ecx    # 0x372018
xorq $0x224345, %rcx         # imm = 0x224345
orq %rax, %rcx
je 0xa7444
movq 0x2cac2f(%rip), %rax    # 0x372010
movabsq $0x4953494345525022, %rcx # imm = 0x4953494345525022
xorq %rcx, %rax
movl 0x2cac24(%rip), %ecx    # 0x372018
xorq $0x224e4f, %rcx         # imm = 0x224E4F
orq %rax, %rcx
movsd -0x30(%rbp), %xmm0
jne 0xa7303
leaq 0x173ca0(%rip), %rax    # 0x21b0b0
movl $0x1, (%rax)
movq %r15, %rdi
callq 0x9470
callq 0x9320
movsd -0x30(%rbp), %xmm0
jmp 0xa7303
movq %r15, %rdi
callq 0x9470
movsd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
jmp 0xa7303
movq %r15, %rdi
callq 0x9470
mulsd 0x61cf4(%rip), %xmm0    # 0x109148
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
jmp 0xa7303
movq %r15, %rdi
callq 0x9470
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
jmp 0xa72fe
movq %r15, %rdi
callq 0x9470
mulsd 0x61cbe(%rip), %xmm0    # 0x109148
jmp 0xa72fe
movsd -0x48(%rbp), %xmm1
subsd -0x40(%rbp), %xmm1
leaq 0x265d98(%rip), %rax    # 0x30d238
movl $0x8, %ecx
movl %ecx, (%rax)
leaq 0x265d96(%rip), %rax    # 0x30d244
movl %ecx, (%rax)
subsd -0x38(%rbp), %xmm0
addsd %xmm1, %xmm0
mulsd 0x61b67(%rip), %xmm0    # 0x109028
leaq 0x2652f0(%rip), %rax    # 0x30c7b8
movsd %xmm0, (%rax)
leaq 0x196ebd(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0xa74f7
leaq 0x7e989(%rip), %rsi     # 0x125e6b
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9560
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq