// File: /workspace/github_cpp_makefile_star2_O2/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:
leaq 0x16d532(%rip), %rax    # 0x2050ac
movl (%rax), %ecx
orl %esi, %ecx
movl %ecx, (%rax)
andl $0x2, %esi
shrl %esi
testl %ecx, %esi
jne 0x97d81
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x260178(%rip), %rax    # 0x2f7d20
movb $0x1, (%rax)
leaq 0x25f72a(%rip), %rax    # 0x2f72dc
movl $0xb, (%rax)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x2c4448(%rip), %r14    # 0x35c010
leaq 0x28de71(%rip), %r15    # 0x325a40
leaq 0x7819e(%rip), %r12     # 0x10fd74
pushq $0xc
popq %r13
xorps %xmm1, %xmm1
movsd %xmm1, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movsd %xmm0, -0x30(%rbp)
testq %rbx, %rbx
je 0x97d11
movq %rbx, %rdi
callq 0x96fd1
movq %rax, %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0x9330
cmpb $0x0, 0x2c43fe(%rip)    # 0x35c010
je 0x97bec
movq %rbx, %rdi
callq 0x96fd1
movq %rax, %rbx
callq 0x970c3
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x9380
testl %eax, %eax
je 0x97ce5
movq %r14, %rdi
leaq 0x7813c(%rip), %rsi     # 0x10fd80
pushq $0xd
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x97cfc
movq %r14, %rdi
leaq 0x7812f(%rip), %rsi     # 0x10fd8d
pushq $0xb
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x97cb9
movq %r14, %rdi
leaq 0x78124(%rip), %rsi     # 0x10fd98
movq %r13, %rdx
callq 0x9380
testl %eax, %eax
je 0x97ccb
movq %r14, %rdi
leaq 0x7811a(%rip), %rsi     # 0x10fda4
movq %r13, %rdx
callq 0x9380
testl %eax, %eax
jne 0x97bec
leaq 0x16d40f(%rip), %rax    # 0x2050b0
movl $0x1, (%rax)
movq %r15, %rdi
callq 0x9470
callq 0x9310
jmp 0x97bec
movq %r15, %rdi
callq 0x9470
movsd %xmm0, -0x40(%rbp)
jmp 0x97bec
movq %r15, %rdi
callq 0x9470
mulsd 0x5b46d(%rip), %xmm0    # 0xf3148
movsd %xmm0, -0x38(%rbp)
jmp 0x97bec
movq %r15, %rdi
callq 0x9470
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
jmp 0x97be7
movq %r15, %rdi
callq 0x9470
mulsd 0x5b43c(%rip), %xmm0    # 0xf3148
jmp 0x97be7
movsd -0x48(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
leaq 0x25f516(%rip), %rax    # 0x2f7238
pushq $0x8
popq %rcx
movl %ecx, (%rax)
leaq 0x25f516(%rip), %rax    # 0x2f7244
movl %ecx, (%rax)
movsd -0x30(%rbp), %xmm1
subsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulsd 0x5b2de(%rip), %xmm0    # 0xf3028
leaq 0x25ea67(%rip), %rax    # 0x2f67b8
movsd %xmm0, (%rax)
leaq 0x190634(%rip), %rax    # 0x228390
movq (%rax), %rdi
testq %rdi, %rdi
leaq 0x28(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
je 0x97d81
leaq 0x78036(%rip), %rsi     # 0x10fdb0
movb $0x1, %al
jmp 0x9560
retq