// File: jkingan[P]ladyheather/heathgps.cpp
// Function: parse_nvs_raw()
void parse_nvs_raw()
{
double tow;
int week;
double gps_shift;
double glonass_shift;
int corr;
u08 type;
int prn;
u08 glonass_carrier;
u08 snr;
double phase;
double range;
double doppler;
u08 flags;
u08 rsvd;
int lli;
int xtow;
double meas_tow;

   // 0xF5 packet
   log_packet_id("nvs_raw");

   tow = tsip_double() / 1000.0;   // in seconds
   week = tsip_word();
   week = fix_nvs_week(week); 

   meas_tow = ((double) tow);         // this is in UTC... bastards!!!
   meas_tow += (double) utc_offset;   // convert to GPS time
   xtow = (int) (meas_tow*nav_rate+0.01);  // raw Hz //rtk3   raw Hz

   if(1) {  // this might cause time stamp faults in CSRS-PPP  rnx3
      if(xtow % (int) ((double)raw_msg_rate*nav_rate)) return;

      obs_tow = meas_tow;
      jd_obs = GPS_EPOCH + ((double) week * 7.0) + jtime(0,0,0,meas_tow);
   }
   else {
      obs_tow = meas_tow;
      jd_obs = GPS_EPOCH + ((double) week * 7.0) + jtime(0,0,0,meas_tow);
   }

   gps_shift = tsip_double();
   glonass_shift = tsip_double();
   corr = (int) (s08) tsip_byte();

   while(tsip_rptr < tsip_wptr) {
      type = tsip_byte();
      prn = tsip_byte();
      glonass_carrier = tsip_byte();
      snr = tsip_byte();
      phase = tsip_double();
      range = tsip_double();    // msecs
      doppler = tsip_double();
      flags = tsip_byte();
      rsvd = tsip_byte();

      if(type == 0x01) prn += NVS_GLONASS_PRN;
      else if(type == 0x02) prn += 0;
      else {
         continue;
      }
      if(prn < 0) continue;
      if(prn > MAX_PRN) continue;

      range /= 1000.0;  // pseudorange now in seconds
      range *= (LIGHTSPEED*1000.0);  // now in meters

      sat[prn].code_phase = phase;
      sat[prn].doppler = doppler;
      sat[prn].range = range;

      lli = 0x00;
      if((flags & 0x01) == 0) lli |= 0x80;  // no gignal
      if((flags & 0x02) == 0) lli |= 0x80;  // no doppler/pseudorange
      if((flags & 0x08) == 0) lli |= 0x80;  // no carrier phase

      sat[prn].ca_lli = lli;
      sat[prn].l1_lli = 0;
      sat[prn].l2_lli = 0;

      if(doppler) {
         have_doppler |= rinex_gnss(prn);
      }
      if(phase) {
         have_phase |= rinex_gnss(prn); 
      }
      if(range) {
         have_range |= rinex_gnss(prn); 
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
leaq 0xa424f(%rip), %rdi     # 0x18939e
callq 0x7add0
callq 0x7a9d0
movsd 0x89ecf(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
callq 0x7a560
movzwl %ax, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0xe4bd0
movl %eax, -0xc(%rbp)
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x287777(%rip), %rax    # 0x36c908
cvtsi2sdl (%rax), %xmm0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
leaq 0x19538d(%rip), %rax    # 0x27a538
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x89f65(%rip), %xmm1    # 0x16f120
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
leaq 0x195388(%rip), %rcx    # 0x27a558
cvtsi2sdl (%rcx), %xmm0
leaq 0x19535d(%rip), %rcx    # 0x27a538
mulsd (%rcx), %xmm0
cvttsd2si %xmm0, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xe51f0
jmp 0xe54d6
movsd -0x60(%rbp), %xmm0
leaq 0x28755c(%rip), %rax    # 0x36c758
movsd %xmm0, (%rax)
cvtsi2sdl -0xc(%rbp), %xmm0
movsd 0x8c47b(%rip), %xmm1    # 0x171688
mulsd %xmm1, %xmm0
movsd 0x8c3ff(%rip), %xmm1    # 0x171618
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x60(%rbp), %xmm0
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x28750b(%rip), %rax    # 0x36c750
movsd %xmm0, (%rax)
callq 0x7a9d0
movsd %xmm0, -0x18(%rbp)
callq 0x7a9d0
movsd %xmm0, -0x20(%rbp)
callq 0x7a510
movsbl %al, %eax
movl %eax, -0x24(%rbp)
leaq 0x2b21c5(%rip), %rax    # 0x397434
movzwl (%rax), %eax
leaq 0x2b21b9(%rip), %rcx    # 0x397432
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xe54d6
callq 0x7a510
movb %al, -0x25(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
callq 0x7a510
movb %al, -0x2d(%rbp)
callq 0x7a510
movb %al, -0x2e(%rbp)
callq 0x7a9d0
movsd %xmm0, -0x38(%rbp)
callq 0x7a9d0
movsd %xmm0, -0x40(%rbp)
callq 0x7a9d0
movsd %xmm0, -0x48(%rbp)
callq 0x7a510
movb %al, -0x49(%rbp)
callq 0x7a510
movb %al, -0x4a(%rbp)
movzbl -0x25(%rbp), %eax
cmpl $0x1, %eax
jne 0xe52e9
movl -0x2c(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x2c(%rbp)
jmp 0xe5304
movzbl -0x25(%rbp), %eax
cmpl $0x2, %eax
jne 0xe52fd
movl -0x2c(%rbp), %eax
addl $0x0, %eax
movl %eax, -0x2c(%rbp)
jmp 0xe5302
jmp 0xe5268
jmp 0xe5304
cmpl $0x0, -0x2c(%rbp)
jge 0xe530f
jmp 0xe5268
cmpl $0x3e7, -0x2c(%rbp)     # imm = 0x3E7
jle 0xe531d
jmp 0xe5268
movsd -0x40(%rbp), %xmm0
movsd 0x89d06(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x8c2ad(%rip), %xmm0    # 0x1715e8
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rcx
leaq 0x1b8e3b(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x28(%rax)
movsd -0x48(%rbp), %xmm0
movslq -0x2c(%rbp), %rcx
leaq 0x1b8e1c(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x30(%rax)
movsd -0x40(%rbp), %xmm0
movslq -0x2c(%rbp), %rcx
leaq 0x1b8dfd(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x38(%rax)
movl $0x0, -0x50(%rbp)
movzbl -0x49(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xe53c0
movl -0x50(%rbp), %eax
orl $0x80, %eax
movl %eax, -0x50(%rbp)
movzbl -0x49(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xe53d7
movl -0x50(%rbp), %eax
orl $0x80, %eax
movl %eax, -0x50(%rbp)
movzbl -0x49(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0xe53ee
movl -0x50(%rbp), %eax
orl $0x80, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %ecx
movslq -0x2c(%rbp), %rdx
leaq 0x1b8d94(%rip), %rax    # 0x29e190
imulq $0x348, %rdx, %rdx      # imm = 0x348
addq %rdx, %rax
movl %ecx, 0x68(%rax)
movslq -0x2c(%rbp), %rcx
leaq 0x1b8d7c(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0x0, 0xa8(%rax)
movslq -0x2c(%rbp), %rcx
leaq 0x1b8d5d(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0x0, 0xe8(%rax)
movsd -0x48(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xe5459
jp 0xe5459
jmp 0xe5475
movl -0x2c(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x2870b6(%rip), %rax    # 0x36c520
orl (%rax), %ecx
leaq 0x2870ad(%rip), %rax    # 0x36c520
movl %ecx, (%rax)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xe5487
jp 0xe5487
jmp 0xe54a3
movl -0x2c(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x28708c(%rip), %rax    # 0x36c524
orl (%rax), %ecx
leaq 0x287083(%rip), %rax    # 0x36c524
movl %ecx, (%rax)
movsd -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xe54b5
jp 0xe54b5
jmp 0xe54d1
movl -0x2c(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x287062(%rip), %rax    # 0x36c528
orl (%rax), %ecx
leaq 0x287059(%rip), %rax    # 0x36c528
movl %ecx, (%rax)
jmp 0xe5268
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)