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

   // This routine is used when the environmental sensor is an "extra" 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

   i = SERIAL_DATA_AVAILABLE(port);
   if(i == 0) {  // no characters available, check for com timeout
      i = check_com_timer(port);
      
      if(i || (i == DATA_LOSS_REINIT)) {
         com[port].com_data_lost = DATA_LOSS_NO_INIT;  // prevents futile re-init attempts
         reset_com_timer(port);
         init_com(port, 107);
////com[port].com_running = 4;
if(com[port].com_running > 0) com[port].process_com = 4;
//lfs com[port].process_com = 4;
BEEP(513);  //lfs
         init_enviro(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[THERMO_PORT].rcv_error) {      // parity/framing/overrun errors
         com[THERMO_PORT].rcv_error = 0;
         //!!!!!qqqq    goto rst_msg;
      }
   }

   last_c = c;

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

      if(enviro_wptr < MAX_TSIP) {   // add char to the message buffer
         enviro_buf[enviro_wptr++] = c;
      }
      else {  // buffer overflow, ignore the message
//         enviro_error |= 0x8000;  // aaattt
         goto rst_msg;
      }
   }
   else {  // end of message
      enviro_end:
      if(enviro_wptr) {           // we have a message
         decode_enviro_msg(port); // process the message
         packet_end = 1;
      }

      rst_msg:
      enviro_wptr = 0;     // prepare for next message
      enviro_rptr = 0;
      if((c == 0x0D) || (c == 0x0A) || (c == 0x00)) enviro_sync = 1;
      else enviro_sync = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
leaq 0x18dc82(%rip), %rax    # 0x277af4
cmpl $0x2, (%rax)
jne 0xe9e79
jmp 0xe9e96
callq 0xb630
movaps %xmm0, %xmm1
movsd 0x2e75cf(%rip), %xmm0   # 0x3d1458
ucomisd %xmm1, %xmm0
jbe 0xe9e94
jmp 0xea113
jmp 0xe9e96
callq 0xb630
movsd 0x8521d(%rip), %xmm1    # 0x16f0c0
addsd %xmm1, %xmm0
movsd %xmm0, 0x2e75a9(%rip)   # 0x3d1458
movl -0x4(%rbp), %edi
callq 0xcad0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xe9f67
movl -0x4(%rbp), %edi
callq 0x2b610
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xe9edf
cmpl $0x1, -0xc(%rbp)
jne 0xe9f62
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2835d5(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movb $0x2, 0x2250(%rax)
movl -0x4(%rbp), %edi
callq 0x2bd30
movl -0x4(%rbp), %edi
movl $0x6b, %esi
callq 0xc0e0
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2835a3(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
cmpl $0x0, 0x2230(%rax)
jle 0xe9f50
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x283584(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl $0x4, 0x2234(%rax)
movl $0x201, %edi            # imm = 0x201
callq 0x9ec0
movl -0x4(%rbp), %edi
callq 0x961a0
jmp 0xea113
movl -0x4(%rbp), %edi
callq 0x2bd30
cmpl $0xa, -0x4(%rbp)
jne 0xe9f9d
callq 0x79fc0
movb %al, -0x5(%rbp)
leaq 0x28353c(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xe9f9b
leaq 0x28352c(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
jmp 0xe9fc5
callq 0x7a0b0
movb %al, -0x5(%rbp)
leaq 0x283514(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x225f2(%rax)
je 0xe9fc3
leaq 0x283504(%rip), %rax    # 0x36d4c0
movb $0x0, 0x225f2(%rax)
jmp 0xe9fc5
movb -0x5(%rbp), %al
movb %al, 0x2e7486(%rip)     # 0x3d1454
leaq 0x2af487(%rip), %rax    # 0x39945c
cmpl $0x0, (%rax)
jne 0xea026
movzbl -0x5(%rbp), %eax
cmpl $0xd, %eax
je 0xe9ff5
movzbl -0x5(%rbp), %eax
cmpl $0xa, %eax
je 0xe9ff5
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
jne 0xea007
leaq 0x2af460(%rip), %rax    # 0x39945c
movl $0x1, (%rax)
callq 0x7a1d0
leaq 0x2af446(%rip), %rax    # 0x399454
movl $0x0, (%rax)
leaq 0x2af43d(%rip), %rax    # 0x399458
movl $0x0, (%rax)
jmp 0xea113
leaq 0x2af42f(%rip), %rax    # 0x39945c
cmpl $0x1, (%rax)
jne 0xea09c
movzbl -0x5(%rbp), %eax
cmpl $0xd, %eax
je 0xea04d
movzbl -0x5(%rbp), %eax
cmpl $0xa, %eax
je 0xea04d
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
jne 0xea060
leaq 0x2af400(%rip), %rax    # 0x399454
cmpl $0x0, (%rax)
jne 0xea05e
jmp 0xea113
jmp 0xea09e
leaq 0x2af3ed(%rip), %rax    # 0x399454
cmpl $0x1000, (%rax)         # imm = 0x1000
jge 0xea098
movb -0x5(%rbp), %dl
leaq 0x2af3db(%rip), %rax    # 0x399454
movl (%rax), %eax
movl %eax, %esi
addl $0x1, %esi
leaq 0x2af3cd(%rip), %rcx    # 0x399454
movl %esi, (%rcx)
movslq %eax, %rcx
leaq 0x2ae3bd(%rip), %rax    # 0x398450
movb %dl, (%rax,%rcx)
jmp 0xea09a
jmp 0xea0be
jmp 0xea111
jmp 0xea09e
leaq 0x2af3af(%rip), %rax    # 0x399454
cmpl $0x0, (%rax)
je 0xea0bc
movl -0x4(%rbp), %edi
callq 0xe99f0
movl $0x1, 0x2e0db8(%rip)    # 0x3cae74
jmp 0xea0be
leaq 0x2af38f(%rip), %rax    # 0x399454
movl $0x0, (%rax)
leaq 0x2af386(%rip), %rax    # 0x399458
movl $0x0, (%rax)
movzbl -0x5(%rbp), %eax
cmpl $0xd, %eax
je 0xea0f3
movzbl -0x5(%rbp), %eax
cmpl $0xa, %eax
je 0xea0f3
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
jne 0xea102
leaq 0x2af362(%rip), %rax    # 0x39945c
movl $0x1, (%rax)
jmp 0xea10f
leaq 0x2af353(%rip), %rax    # 0x39945c
movl $0x0, (%rax)
jmp 0xea111
jmp 0xea113
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)