// File: 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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %ecx
leaq 0x1977e3(%rip), %rax    # 0x27a28c
orl (%rax), %ecx
leaq 0x1977da(%rip), %rax    # 0x27a28c
movl %ecx, (%rax)
leaq 0x1977d1(%rip), %rax    # 0x27a28c
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xe2ad5
movl -0xc(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xe2ad5
jmp 0xe2d23
leaq 0x28a424(%rip), %rax    # 0x36cf00
movb $0x1, (%rax)
leaq 0x2899d6(%rip), %rax    # 0x36c4bc
movl $0xb, (%rax)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xe2c86
movq -0x8(%rbp), %rdi
callq 0xe1c20
movq %rax, -0x8(%rbp)
leaq 0x2ee6dd(%rip), %rdi    # 0x3d1210
leaq 0x2b80e6(%rip), %rsi    # 0x39ac20
callq 0x9350
movsbl 0x2ee6ca(%rip), %eax    # 0x3d1210
cmpl $0x0, %eax
jne 0xe2b4d
jmp 0xe2b14
movq -0x8(%rbp), %rdi
callq 0xe1c20
movq %rax, -0x8(%rbp)
callq 0xe1e70
leaq 0x2ee6aa(%rip), %rdi    # 0x3d1210
leaq 0xa65fd(%rip), %rsi     # 0x18916a
callq 0x9510
cmpl $0x0, %eax
jne 0xe2b8d
leaq 0x2b80a2(%rip), %rdi    # 0x39ac20
callq 0x9480
movsd %xmm0, -0x18(%rbp)
jmp 0xe2c81
leaq 0x2ee67c(%rip), %rdi    # 0x3d1210
leaq 0xa65db(%rip), %rsi     # 0x189176
callq 0x9510
cmpl $0x0, %eax
jne 0xe2bc7
leaq 0x2b8074(%rip), %rdi    # 0x39ac20
callq 0x9480
movsd 0x8c5af(%rip), %xmm1    # 0x16f168
mulsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0xe2c7f
leaq 0x2ee642(%rip), %rdi    # 0x3d1210
leaq 0xa65ae(%rip), %rsi     # 0x189183
callq 0x9510
cmpl $0x0, %eax
jne 0xe2bf5
leaq 0x2b803a(%rip), %rdi    # 0x39ac20
callq 0x9480
movsd %xmm0, -0x28(%rbp)
jmp 0xe2c7d
leaq 0x2ee614(%rip), %rdi    # 0x3d1210
leaq 0xa658b(%rip), %rsi     # 0x18918e
callq 0x9510
cmpl $0x0, %eax
jne 0xe2c2c
leaq 0x2b800c(%rip), %rdi    # 0x39ac20
callq 0x9480
movsd 0x8c547(%rip), %xmm1    # 0x16f168
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0xe2c7b
leaq 0x2ee5dd(%rip), %rdi    # 0x3d1210
leaq 0xa6560(%rip), %rsi     # 0x18919a
callq 0x9510
cmpl $0x0, %eax
jne 0xe2c79
leaq 0x197645(%rip), %rax    # 0x27a290
movl $0x1, (%rax)
leaq 0x2b7fc8(%rip), %rdi    # 0x39ac20
callq 0x9480
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm1
movsd 0x8c4e1(%rip), %xmm0    # 0x16f150
callq 0x9690
movsd %xmm0, -0x38(%rbp)
jmp 0xe2c7b
jmp 0xe2c7d
jmp 0xe2c7f
jmp 0xe2c81
jmp 0xe2b14
movsd -0x18(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
leaq 0x288d01(%rip), %rax    # 0x36b998
movsd %xmm0, (%rax)
leaq 0x289776(%rip), %rax    # 0x36c418
movl $0x8, (%rax)
leaq 0x289775(%rip), %rax    # 0x36c424
movl $0x8, (%rax)
movsd -0x20(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
leaq 0x288cd2(%rip), %rax    # 0x36b998
addsd (%rax), %xmm0
leaq 0x288cc7(%rip), %rax    # 0x36b998
movsd %xmm0, (%rax)
movsd 0x8c34b(%rip), %xmm0    # 0x16f028
leaq 0x288cb4(%rip), %rax    # 0x36b998
mulsd (%rax), %xmm0
leaq 0x288ca9(%rip), %rax    # 0x36b998
movsd %xmm0, (%rax)
leaq 0x1ba876(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xe2d23
leaq 0x1ba869(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x288c87(%rip), %rax    # 0x36b998
movsd (%rax), %xmm0
leaq 0xa648a(%rip), %rsi     # 0x1891a6
movb $0x1, %al
callq 0x9550
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)