// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_ae_packet()
void get_ae_packet()
{
u08 subcode;      // packet subcode
u16 zero;         // ???
u08 leds;         // led status
u08 hold;         // holdover state
u08 pll;          // pll state
u08 dis;          // disciplining mode
u08 flash;        // firmware code
u08 b1,b2;        // ???
u08 log_count;    // number of events in the log
u16 op_status;    // operation status
u16 hw_status;    // hardware status
float pps_val;    // related to pps error (in ns)
float osc_val;    // related to osc error (in ppb)
int i;
unsigned char buf[32];


   log_packet_id("Packet 0x8F.AE (Nortel packet)");

   // Unknown packet sent by Nortel receiver.  Also mentioned as being
   // sent by the Palisade,  but in a different format.

// for(i=0; i<9+8; i++) tsip_byte();
   subcode = tsip_byte();
   if(subcode == 0x01) {
      zero  = tsip_word();
      leds  = tsip_byte();
      ffom  = tsip_byte();
      have_ffom = 1;
      tfom  = tsip_byte();
      have_tfom = 1;
      hold  = tsip_byte();

      if(try_ntpx == 0) {
         pll   = tsip_byte();
         dis   = tsip_byte();
         flash = tsip_byte();

         b1 = tsip_byte();    // 0
         b2 = tsip_byte();    // 1
         log_count = tsip_byte();  // error count
         op_status = tsip_word(); 
         hw_status = tsip_word(); 

         pps_val = tsip_single();  // PPS val (ns)
         osc_val = tsip_single();  // OSC val (ppb)
      }
//    sprintf(plot_title, "led:%02X  ffom:%02X tfom:%02X  ho:%02X  pll:%02X  dis:%02X  flash:%02X  b:%02X,%02X  log:%02X  op:%04X hw:%04X  %12g %12g", 
//      leds, ffom,tfom,  hold,pll,dis,flash, b1,b2, log_count, op_status,hw_status, pps_val,osc_val);
   }
   else if(1) {
//    plot_title[0] = 0;
      for(i=0; i<9+8+8; i++) {
         buf[i] = tsip_byte();
//       sprintf(out, "%02X ", (unsigned) buf[i]);
//       strcat(plot_title, out);
      }
   }

   check_tsip_end(1);
   if(STARLOC) ;
   else if(try_ntpx && (tsip_error == 0) && (zero == 0x0001)) {
      saw_ntpx = 1;
      strcpy(unit_name, "Nortel NTPX"); 
      saw_gpsdo = 3;
      if(user_set_temp_filter == 0) undo_fw_temp_filter = 0;
   }

   if(STARLOC) ;
   else if(tsip_error && (zero == 0x0001)) { // error seen, maybe it's an NTPX gpsdo?
      try_ntpx ^= 1;
      if(try_ntpx == 0) {
         saw_ntpx = 0;
         saw_gpsdo = 0;
      }
   }
//sprintf(plot_title, "ntpx: %d  zero:%04X  saw_ntpx=%d  notel=%d  oscp=%04X", 
//try_ntpx, zero, saw_ntpx, saw_nortel, have_osc_params);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq 0xdddb0(%rip), %rdi     # 0x18557f
callq 0x7add0
callq 0x7a510
movb %al, -0x1(%rbp)
movzbl -0x1(%rbp), %eax
cmpl $0x1, %eax
jne 0xa78a5
callq 0x7a560
movw %ax, -0x4(%rbp)
callq 0x7a510
movb %al, -0x5(%rbp)
callq 0x7a510
movzbl %al, %ecx
leaq 0x2c462f(%rip), %rax    # 0x36be38
movl %ecx, (%rax)
leaq 0x2c462a(%rip), %rax    # 0x36be3c
movl $0x1, (%rax)
callq 0x7a510
movzbl %al, %ecx
leaq 0x2c4609(%rip), %rax    # 0x36be30
movl %ecx, (%rax)
leaq 0x2c4604(%rip), %rax    # 0x36be34
movl $0x1, (%rax)
callq 0x7a510
movb %al, -0x6(%rbp)
leaq 0x1f68d6(%rip), %rax    # 0x29e11b
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xa78a3
callq 0x7a510
movb %al, -0x7(%rbp)
callq 0x7a510
movb %al, -0x8(%rbp)
callq 0x7a510
movb %al, -0x9(%rbp)
callq 0x7a510
movb %al, -0xa(%rbp)
callq 0x7a510
movb %al, -0xb(%rbp)
callq 0x7a510
movb %al, -0xc(%rbp)
callq 0x7a560
movw %ax, -0xe(%rbp)
callq 0x7a560
movw %ax, -0x10(%rbp)
callq 0x7a860
movss %xmm0, -0x14(%rbp)
callq 0x7a860
movss %xmm0, -0x18(%rbp)
jmp 0xa78ce
movl $0x0, -0x1c(%rbp)
cmpl $0x19, -0x1c(%rbp)
jge 0xa78cc
callq 0x7a510
movb %al, %cl
movslq -0x1c(%rbp), %rax
movb %cl, -0x40(%rbp,%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa78ac
jmp 0xa78ce
movl $0x1, %edi
callq 0x7aee0
leaq 0x1d01d1(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa78f3
leaq 0x1d28c8(%rip), %rax    # 0x27a1b4
cmpl $0x53, (%rax)
jne 0xa78f3
jmp 0xa795b
leaq 0x1f6821(%rip), %rax    # 0x29e11b
cmpb $0x0, (%rax)
je 0xa7959
leaq 0x1f684a(%rip), %rax    # 0x29e150
cmpl $0x0, (%rax)
jne 0xa7959
movzwl -0x4(%rbp), %eax
cmpl $0x1, %eax
jne 0xa7959
leaq 0x1f6801(%rip), %rax    # 0x29e11c
movb $0x1, (%rax)
leaq 0x2f3efb(%rip), %rdi    # 0x39b820
leaq 0xe9e54(%rip), %rsi     # 0x191780
callq 0x9350
leaq 0x1d28e0(%rip), %rax    # 0x27a218
movl $0x3, (%rax)
leaq 0x1d2ba8(%rip), %rax    # 0x27a4ed
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xa7957
leaq 0x1d2b98(%rip), %rax    # 0x27a4ec
movb $0x0, (%rax)
jmp 0xa7959
jmp 0xa795b
leaq 0x1d014e(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa7976
leaq 0x1d2845(%rip), %rax    # 0x27a1b4
cmpl $0x53, (%rax)
jne 0xa7976
jmp 0xa79cd
leaq 0x1f67d3(%rip), %rax    # 0x29e150
cmpl $0x0, (%rax)
je 0xa79cb
movzwl -0x4(%rbp), %eax
cmpl $0x1, %eax
jne 0xa79cb
leaq 0x1f6789(%rip), %rax    # 0x29e11b
movzbl (%rax), %eax
xorl $0x1, %eax
movb %al, %cl
leaq 0x1f677a(%rip), %rax    # 0x29e11b
movb %cl, (%rax)
leaq 0x1f6771(%rip), %rax    # 0x29e11b
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xa79c9
leaq 0x1f6763(%rip), %rax    # 0x29e11c
movb $0x0, (%rax)
leaq 0x1d2855(%rip), %rax    # 0x27a218
movl $0x0, (%rax)
jmp 0xa79cb
jmp 0xa79cd
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)