// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x16c286(%rip), %rax    # 0x218914
cmpl $0x2, (%rax)
je 0xac6aa
callq 0xae92
movsd 0x2c5ba8(%rip), %xmm1   # 0x372248
ucomisd %xmm0, %xmm1
ja 0xac876
callq 0xae92
addsd 0x5c9f1(%rip), %xmm0    # 0x1090a8
movsd %xmm0, 0x2c5b89(%rip)   # 0x372248
movl %ebx, %edi
callq 0xb9ad
movl %ebx, %edi
testl %eax, %eax
je 0xac701
callq 0x1ea0b
cmpl $0xa, %ebx
jne 0xac76e
callq 0x584bd
movl %eax, %r14d
leaq 0x261bf7(%rip), %rax    # 0x30e2e0
cmpb $0x0, 0x17a12(%rax)
je 0xac78f
addq $0x17a12, %rax          # imm = 0x17A12
jmp 0xac78c
callq 0x1e66a
testl %eax, %eax
je 0xac876
movl %ebx, %eax
imulq $0x2260, %rax, %r15     # imm = 0x2260
leaq 0x261bc2(%rip), %r14    # 0x30e2e0
movb $0x2, 0x2250(%r14,%r15)
movl %ebx, %edi
callq 0x1ea0b
movl %ebx, %edi
movl $0x6b, %esi
callq 0xb49e
cmpl $0x0, 0x2230(%r14,%r15)
jle 0xac753
addq %r15, %r14
movl $0x4, 0x2234(%r14)
movl $0x201, %edi            # imm = 0x201
callq 0x9d78
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6e19a
callq 0x58584
movl %eax, %r14d
leaq 0x261b63(%rip), %rax    # 0x30e2e0
cmpb $0x0, 0x225f2(%rax)
je 0xac78f
addq $0x225f2, %rax          # imm = 0x225F2
movb $0x0, (%rax)
leaq 0x28dae6(%rip), %r15    # 0x33a27c
movl (%r15), %eax
cmpl $0x1, %eax
je 0xac7db
testl %eax, %eax
jne 0xac7fd
cmpb $0xd, %r14b
ja 0xac7c2
movzbl %r14b, %eax
movl $0x2401, %ecx           # imm = 0x2401
btl %eax, %ecx
jae 0xac7c2
movl $0x1, (%r15)
callq 0x58672
leaq 0x28daab(%rip), %rax    # 0x33a274
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0x28daa4(%rip), %rax    # 0x33a278
movl %ecx, (%rax)
jmp 0xac876
cmpb $0xd, %r14b
ja 0xac854
movzbl %r14b, %eax
movl $0x2401, %ecx           # imm = 0x2401
btl %eax, %ecx
jae 0xac854
leaq 0x28da7e(%rip), %rax    # 0x33a274
cmpl $0x0, (%rax)
jne 0xac809
jmp 0xac876
leaq 0x28da70(%rip), %rax    # 0x33a274
cmpl $0x0, (%rax)
je 0xac81a
movl %ebx, %edi
callq 0xac349
movl $0x1, 0x2bf47a(%rip)    # 0x36bc94
leaq 0x28da53(%rip), %rax    # 0x33a274
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0x28da4c(%rip), %rax    # 0x33a278
movl %ecx, (%rax)
cmpb $0xd, %r14b
ja 0xac84b
movzbl %r14b, %eax
movl $0x2401, %ecx           # imm = 0x2401
btl %eax, %ecx
jae 0xac84b
movl $0x1, (%r15)
jmp 0xac876
movl $0x0, (%r15)
jmp 0xac876
leaq 0x28da19(%rip), %rcx    # 0x33a274
movslq (%rcx), %rax
cmpq $0xfff, %rax            # imm = 0xFFF
jg 0xac81a
leal 0x1(%rax), %edx
movl %edx, (%rcx)
leaq 0x28c9fe(%rip), %rcx    # 0x339270
movb %r14b, (%rcx,%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq