// File: jkingan[P]ladyheather/heathgps.cpp
// Function: wakeup_nortel()
void wakeup_nortel()
{
int row, col;
unsigned c;

   // try to wake up the Nortel NTGS/NTPX/NTBW units

   if(sim_file) return;
   try_nortel = 0;
   saw_nortel = 0;
   if(PALISADE) return;
   if(SV6_FAMILY) return;
   if(nortel != 1) return;  

   try_nortel = 0xFF;
   wakeup_tsip_msg = 0;
   waking = 1;

   col = 0;
   row = 1;
   while(wakeup_tsip_msg == 0) {
      vidstr(row,col, RED, "*");
      refresh_page();
      ++col;

      SetDtrLine(RCVR_PORT, 1);
      if(NO_SCPI_BREAK && (rcvr_type == SCPI_RCVR)) ; 
      else SendBreak(RCVR_PORT);

      request_sig_levels();           // 0x27
      request_rcvr_health();          // 0x26
      request_sat_list();             // 0x24
      request_sat_status(0x00);       // 0x3C
      request_gps_time();             // 0x21
      request_io_options();           // 0x35
//    request_hw_ver();               // 1C 03
//    request_unk_ver();              // 1C 02
      request_version();              // 1F
      request_rcvr_config(4);         // BB 00
      request_filter_config();        // 70
      set_health_config(0x03, 0x00);  // 39 03 00
      request_c2();                   // C2
      request_7A_00();                // 7A 00
      request_datum();                // 8E 15
      Sleep(500);

      if(1 && com[RCVR_PORT].process_com) {
         loopy:
         abort_wakeup();
         if(SERIAL_DATA_AVAILABLE(RCVR_PORT)) {
            while(SERIAL_DATA_AVAILABLE(RCVR_PORT)) {
               c = get_com_char();
               while(c == DLE) {
                  if(SERIAL_DATA_AVAILABLE(RCVR_PORT) == 0) {
                     Sleep(100);
                  }
                  if(SERIAL_DATA_AVAILABLE(RCVR_PORT) == 0) {
                     goto loopy;
                  }
                  c = get_com_char();
                  if(c == ETX) goto etx_seen;
                  abort_wakeup();
               }
               abort_wakeup();
            }
            Sleep(100);
            goto loopy;
         }
         abort_wakeup();
         continue;
      }

      etx_seen:
      get_pending_gps(2);
      abort_wakeup();
   }

   waking = 0;
// set_pps_mode(RATE_1PPS);  // 1pps mode
// request_pps_mode();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0x1ef411(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
je 0xae19a
jmp 0xae3b8
movb $0x0, 0x31ce5b(%rip)    # 0x3caffc
leaq 0x1eff72(%rip), %rax    # 0x29e11a
movb $0x0, (%rax)
leaq 0x1c98fe(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xae1c9
leaq 0x1cbff5(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
jne 0xae1c9
jmp 0xae3b8
leaq 0x1c98e0(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xae20b
leaq 0x1cbfd7(%rip), %rax    # 0x27a1b4
cmpl $0x36, (%rax)
je 0xae206
leaq 0x1cbfcb(%rip), %rax    # 0x27a1b4
cmpl $0x33, (%rax)
je 0xae206
leaq 0x1cbfbf(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
je 0xae206
leaq 0x1cbfb3(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0xae20b
jmp 0xae3b8
leaq 0x1eff07(%rip), %rax    # 0x29e119
movzbl (%rax), %eax
cmpl $0x1, %eax
je 0xae21f
jmp 0xae3b8
movb $-0x1, 0x31cdd6(%rip)   # 0x3caffc
leaq 0x1eff4b(%rip), %rax    # 0x29e178
movq $0x0, (%rax)
movb $0x1, 0x31cdc2(%rip)    # 0x3caffd
movl $0x0, -0x8(%rbp)
movl $0x1, -0x4(%rbp)
leaq 0x1eff28(%rip), %rax    # 0x29e178
cmpq $0x0, (%rax)
jne 0xae3b1
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl $0xc, %edx
leaq 0xd1f3d(%rip), %rcx     # 0x1801a9
callq 0x10ee0
callq 0xb0d0
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
movl $0xa, %edi
movl $0x1, %esi
callq 0xb660
movl $0xa, %edi
callq 0xb840
callq 0x8bfa0
callq 0x85ac0
callq 0x8bdd0
xorl %edi, %edi
callq 0x8ff50
callq 0x8bf60
callq 0x8e670
callq 0x8b430
movl $0x4, %edi
callq 0x8c270
callq 0x902f0
movl $0x3, %edi
xorl %esi, %esi
callq 0x8e990
callq 0x85910
callq 0x85990
callq 0x91420
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xb8b0
leaq 0x2bf1c8(%rip), %rax    # 0x36d4c0
cmpl $0x0, 0x179f4(%rax)
je 0xae39b
jmp 0xae307
callq 0x29330
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
je 0xae391
jmp 0xae31d
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
je 0xae382
callq 0x79fc0
movl %eax, -0xc(%rbp)
cmpl $0x10, -0xc(%rbp)
jne 0xae37b
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xae353
movl $0x64, %edi
callq 0xb8b0
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xae364
jmp 0xae307
callq 0x79fc0
movl %eax, -0xc(%rbp)
cmpl $0x3, -0xc(%rbp)
jne 0xae374
jmp 0xae39d
callq 0x29330
jmp 0xae334
callq 0x29330
jmp 0xae31d
movl $0x64, %edi
callq 0xb8b0
jmp 0xae307
callq 0x29330
jmp 0xae249
jmp 0xae39d
movl $0x2, %edi
callq 0x29240
callq 0x29330
jmp 0xae249
movb $0x0, 0x31cc45(%rip)    # 0x3caffd
addq $0x10, %rsp
popq %rbp
retq
nop