// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_rcvr_enviro_message(unsigned int)
void get_rcvr_enviro_message(unsigned port)
{
u08 c;
static u08 last_c = 0;
static double last_enviro_time = 0.0;

   // This routine is used when the environmental sensor the main "receiver" device.
   // This routine buffers up an incoming environmental message.  When the 
   // end of the message is seen, the message is parsed and decoded with 
   // decode_enviro_msg().  Messages can end with 0x0D, 0x0A, or both.

   if(enviro_type == HEATHER_ENVIRO) ;
   else if(GetMsecs() < last_enviro_time) return;  // rate limits requests to minimize useless traffic
   last_enviro_time = GetMsecs() + ENVIRO_RATE;    // 100 cps max input rate

   // This routine buffers up an incoming sensor message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_enviro_msg()
   // Messages can end with 0x0D, 0x0A, or both.

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

   if(port == RCVR_PORT) {  // sensor is main input decice
      c = get_com_char();
      if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
         com[RCVR_PORT].rcv_error = 0;
         //!!!!!qqqq    goto rst_msg;
      }
   }
   else {  // sensor is auxiliary input device (/et=)
      c = get_enviro_char();  // aaattt
      if(com[port].rcv_error) {      // parity/framing/overrun errors
         com[port].rcv_error = 0;
         //!!!!!qqqq    goto rst_msg;
      }
   }

   last_c = c;

   if(tsip_sync == 0) {    // syncing to start of message, search for a line feed
      if((c == 0x0D) || (c == 0x0A) || (c == 0x00)) {
         tsip_sync = 1;
         get_sync_time();
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) { // 0x0A has been seen, now build the message
      if((c == 0x0D) || (c == 0x0A) || (c == 0x00)) {
         if(tsip_wptr == 0) return; // end-of-line with no data in the message buffer
         goto tsip_end;  // end of message
      }

      if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         tsip_buf[tsip_wptr++] = c;
      }
      else {  // buffer overflow, ignore the message
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else {  // end of message
      tsip_end:
      if(tsip_wptr) {           // we have a message
         decode_enviro_msg(port); // process the message
         packet_end = 1;
      }

      rst_msg:
      tsip_wptr = 0;     // prepare for next message
      tsip_rptr = 0;
      if((c == 0x0D) || (c == 0x0A) || (c == 0x00)) tsip_sync = 1;
      else tsip_sync = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
leaq 0x18d9c2(%rip), %rax    # 0x277af4
cmpl $0x2, (%rax)
jne 0xea139
jmp 0xea156
callq 0xb630
movaps %xmm0, %xmm1
movsd 0x2e731f(%rip), %xmm0   # 0x3d1468
ucomisd %xmm1, %xmm0
jbe 0xea154
jmp 0xea37a
jmp 0xea156
callq 0xb630
movsd 0x84f5d(%rip), %xmm1    # 0x16f0c0
addsd %xmm1, %xmm0
movsd %xmm0, 0x2e72f9(%rip)   # 0x3d1468
movl -0x4(%rbp), %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xea189
movl -0x4(%rbp), %edi
callq 0x2b610
jmp 0xea37a
movl -0x4(%rbp), %edi
callq 0x2bd30
cmpl $0xa, -0x4(%rbp)
jne 0xea1bf
callq 0x79fc0
movb %al, -0x5(%rbp)
leaq 0x28331a(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xea1bd
leaq 0x28330a(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
jmp 0xea205
callq 0x7a0b0
movb %al, -0x5(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2832ed(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
cmpb $0x0, 0x2252(%rax)
je 0xea203
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2832ce(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movb $0x0, 0x2252(%rax)
jmp 0xea205
movb -0x5(%rbp), %al
movb %al, 0x2e7252(%rip)     # 0x3d1460
leaq 0x2ad221(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xea266
movzbl -0x5(%rbp), %eax
cmpl $0xd, %eax
je 0xea238
movzbl -0x5(%rbp), %eax
cmpl $0xa, %eax
je 0xea238
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
jne 0xea249
leaq 0x2ad1f7(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
leaq 0x2ad1e2(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2ad1d8(%rip), %rax    # 0x397434
movw $0x0, (%rax)
jmp 0xea37a
leaq 0x2ad1c9(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xea306
movzbl -0x5(%rbp), %eax
cmpl $0xd, %eax
je 0xea294
movzbl -0x5(%rbp), %eax
cmpl $0xa, %eax
je 0xea294
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
jne 0xea2aa
leaq 0x2ad197(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xea2a8
jmp 0xea37a
jmp 0xea308
leaq 0x2ad181(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xea2ea
movb -0x5(%rbp), %dl
leaq 0x2ad16d(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2ad15c(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2ac14b(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
jmp 0xea304
leaq 0x1b3e5f(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1b3e50(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xea329
jmp 0xea378
jmp 0xea308
leaq 0x2ad123(%rip), %rax    # 0x397432
cmpw $0x0, (%rax)
je 0xea327
movl -0x4(%rbp), %edi
callq 0xe99f0
movl $0x1, 0x2e0b4d(%rip)    # 0x3cae74
jmp 0xea329
leaq 0x2ad102(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2ad0f8(%rip), %rax    # 0x397434
movw $0x0, (%rax)
movzbl -0x5(%rbp), %eax
cmpl $0xd, %eax
je 0xea35c
movzbl -0x5(%rbp), %eax
cmpl $0xa, %eax
je 0xea35c
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
jne 0xea36a
leaq 0x2ad0d3(%rip), %rax    # 0x397436
movw $0x1, (%rax)
jmp 0xea376
leaq 0x2ad0c5(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xea378
jmp 0xea37a
addq $0x10, %rsp
popq %rbp
retq