// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_gpsd_message()
void get_gpsd_message()
{
u08 c;
static int paren_level = 0;

   // This routine buffers up an incoming GPSD JSON message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_gpsd_msg()

   if(SERIAL_DATA_AVAILABLE(RCVR_PORT) == 0) {
      check_com_timer(RCVR_PORT);
      return;
   }
   else {
      reset_com_timer(RCVR_PORT);
   }

   c = get_com_char();
   if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
      com[RCVR_PORT].rcv_error = 0;
//!!!!!qqqq    goto rst_msg;
   }

   if(tsip_sync == 0) {    // syncing to start of message, search for a '{'
      tsip_rptr = 0;
      tsip_wptr = 0;
      tsip_buf[tsip_wptr] = 0;
      if(c == '{') {
         get_sync_time();
         ++tsip_sync;
         tsip_buf[tsip_wptr++] = (u08) c;
         tsip_buf[tsip_wptr] = 0;
         paren_level = 1;
      }
      return;
   }
   else if(tsip_sync == 1) { // '"' has been seen
      if(c == '"') ++tsip_sync; 
      else goto rst_msg;
      tsip_buf[tsip_wptr++] = (u08) c;
      tsip_buf[tsip_wptr] = 0;
   }
   else if(tsip_sync == 2) { // 'c' has been seen
      if(c == 'c') ++tsip_sync; 
      else goto rst_msg;
      tsip_buf[tsip_wptr++] = (u08) c;
      tsip_buf[tsip_wptr] = 0;
   }
   else if(tsip_sync == 3) { // 'l' has been seen
      if(c == 'l') ++tsip_sync; 
      else goto rst_msg;
      tsip_buf[tsip_wptr++] = (u08) c;
      tsip_buf[tsip_wptr] = 0;
   }
   else if(tsip_sync == 4) { // 'a' has been seen
      if(c == 'a') ++tsip_sync; 
      else goto rst_msg;
      tsip_buf[tsip_wptr++] = (u08) c;
      tsip_buf[tsip_wptr] = 0;
   }
   else if(tsip_sync == 5) { // 's' has been seen
      if(c == 's') ++tsip_sync; 
      else goto rst_msg;
      tsip_buf[tsip_wptr++] = (u08) c;
      tsip_buf[tsip_wptr] = 0;
   }
   else if(tsip_sync == 6) { // 's' has been seen - time to start building the full message
      if(c == 's') ++tsip_sync; 
      else goto rst_msg;
      tsip_buf[tsip_wptr++] = (u08) c;
      tsip_buf[tsip_wptr] = 0;
   }
   else if(tsip_sync == 7) {  // adding chars to the message
      if(tsip_wptr > MAX_GPSD_LEN) goto rst_msg; // message too long (max JSON is 1536 chars)
      if((c == 0x0D) || (c == 0x0A)) {
         decode_gpsd_msg();
         packet_end = 1;
         tsip_wptr = 0;     // prepare for next message
         tsip_sync = 0;
      }
      else {
         tsip_buf[tsip_wptr++] = (u08) c;
         tsip_buf[tsip_wptr] = 0;
      }
   }
   else {     // should never happen, prepare for next message
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
      paren_level = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xe3796
movl $0xa, %edi
callq 0x2b610
jmp 0xe3c5d
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x289d11(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xe37c6
leaq 0x289d01(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2b3c69(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xe3881
leaq 0x2b3c54(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2b3c46(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2b3c3a(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b2c2c(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
movzbl -0x1(%rbp), %eax
cmpl $0x7b, %eax
jne 0xe387c
callq 0x7a1d0
leaq 0x2b3c19(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2b3c0b(%rip), %rax    # 0x397436
movw %cx, (%rax)
movb -0x1(%rbp), %dl
leaq 0x2b3bfa(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b3be9(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b2bd8(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b3bd0(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b2bc2(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
movl $0x1, 0x2edbc8(%rip)    # 0x3d1444
jmp 0xe3c5d
leaq 0x2b3bae(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xe3901
movzbl -0x1(%rbp), %eax
cmpl $0x22, %eax
jne 0xe38b3
leaq 0x2b3b96(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2b3b88(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xe38b8
jmp 0xe3c2d
movb -0x1(%rbp), %dl
leaq 0x2b3b70(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b3b5f(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b2b4e(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b3b46(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b2b38(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe3c5b
leaq 0x2b3b2e(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xe3981
movzbl -0x1(%rbp), %eax
cmpl $0x63, %eax
jne 0xe3933
leaq 0x2b3b16(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2b3b08(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xe3938
jmp 0xe3c2d
movb -0x1(%rbp), %dl
leaq 0x2b3af0(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b3adf(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b2ace(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b3ac6(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b2ab8(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe3c59
leaq 0x2b3aae(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0xe3a01
movzbl -0x1(%rbp), %eax
cmpl $0x6c, %eax
jne 0xe39b3
leaq 0x2b3a96(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2b3a88(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xe39b8
jmp 0xe3c2d
movb -0x1(%rbp), %dl
leaq 0x2b3a70(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b3a5f(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b2a4e(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b3a46(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b2a38(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe3c57
leaq 0x2b3a2e(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x4, %eax
jne 0xe3a81
movzbl -0x1(%rbp), %eax
cmpl $0x61, %eax
jne 0xe3a33
leaq 0x2b3a16(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2b3a08(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xe3a38
jmp 0xe3c2d
movb -0x1(%rbp), %dl
leaq 0x2b39f0(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b39df(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b29ce(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b39c6(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b29b8(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe3c55
leaq 0x2b39ae(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x5, %eax
jne 0xe3b01
movzbl -0x1(%rbp), %eax
cmpl $0x73, %eax
jne 0xe3ab3
leaq 0x2b3996(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2b3988(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xe3ab8
jmp 0xe3c2d
movb -0x1(%rbp), %dl
leaq 0x2b3970(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b395f(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b294e(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b3946(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b2938(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe3c53
leaq 0x2b392e(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x6, %eax
jne 0xe3b81
movzbl -0x1(%rbp), %eax
cmpl $0x73, %eax
jne 0xe3b33
leaq 0x2b3916(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2b3908(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xe3b38
jmp 0xe3c2d
movb -0x1(%rbp), %dl
leaq 0x2b38f0(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b38df(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b28ce(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b38c6(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b28b8(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe3c51
leaq 0x2b38ae(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x7, %eax
jne 0xe3c2b
leaq 0x2b3897(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x600, %eax            # imm = 0x600
jle 0xe3baa
jmp 0xe3c2d
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
je 0xe3bbc
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0xe3be5
callq 0xe34d0
movl $0x1, 0x2e72a9(%rip)    # 0x3cae74
leaq 0x2b3860(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2b3858(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xe3c29
movb -0x1(%rbp), %dl
leaq 0x2b3843(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b3832(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b2821(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b3819(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b280b(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe3c4f
jmp 0xe3c2d
leaq 0x2b37fe(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2b37f6(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movl $0x0, 0x2ed7f5(%rip)    # 0x3d1444
jmp 0xe3c51
jmp 0xe3c53
jmp 0xe3c55
jmp 0xe3c57
jmp 0xe3c59
jmp 0xe3c5b
jmp 0xe3c5d
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)