// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: decode_enviro_msg(unsigned int)
void decode_enviro_msg(unsigned port)
{
int i;
u08 c;
u32 packets;

   // decode messages from environmental sensors and poll for the next reading

   if(rcvr_type == THERMO_RCVR) {
      start_msg_decode(1);
      ++enviro_packets;
   }
   else {
      ++packet_count;
      ++enviro_packets;
   }

#define ENVIRO_RESET_THRESH 20

   if(enviro_packets == ENVIRO_RESET_THRESH) {  // time to automatcially kill off unused plots
      if(have_humidity == 0) plot[HUMIDITY].show_plot = 0;
      if(have_pressure == 0) plot[PRESSURE].show_plot = 0;
      if(have_temperature1 == 0) plot[TEMP1].show_plot = 0;
      if(have_temperature2 == 0) plot[TEMP2].show_plot = 0;

      if((rcvr_type == THERMO_RCVR) || (rcvr_type == TIDE_RCVR)) {
         if(have_adc3 == 0) plot[ADC3].show_plot = 0;
         if(have_adc4 == 0) plot[ADC4].show_plot = 0;
      }
   }
   

   // reset the data queues shortly after startup and we have a full set of
   // readings.  This makes sure we have data from all sensor channels and
   // that plots will scale properly.
   if((enviro_packets == ENVIRO_RESET_THRESH) && (pause_data == 0)) {
      packets = enviro_packets;
      new_queue(RESET_ALL_QUEUES, 103);
      enviro_packets = packets;
   }

   enviro_msg[0] = 0;
   if(port == THERMO_PORT) {
      for(i=0; i<enviro_wptr; i++) {  // copy message from sensor buffer to enviro_msg
         c = enviro_buf[i];
         enviro_msg[i] = c;
         enviro_msg[i+1] = 0;
      }
   }
   else {
      for(i=0; i<tsip_wptr; i++) {  // copy message from tsip buffer to enviro_msg
         c = tsip_buf[i];
         enviro_msg[i] = c;
         enviro_msg[i+1] = 0;
      }
   }

// if(debug_file) fprintf(debug_file, "decode enviro:{%s} last:%04X  msec:%.0f\n", enviro_msg, last_enviro, GetMsecs()); //lfs

   strupr(enviro_msg);

   enviro_col = 0;     // index of next char to get from the sensor buffer

   i = get_enviro_field();
   if(last_enviro == ENV_ID) {  // response to the device ID command
      detect_enviro_type();
   }

// if(debug_file) fprintf(debug_file, "field:{%s}  last:%04X i:%d %c\n", enviro_field,last_enviro,i,i);
if(1 && strstr(enviro_field, "LFS10")) {  //lfs
   set_lfs_type();
   if((last_enviro & ENV_ID) == 0) {  // unexpected ID response seen
      last_enviro = 0x0000;
///lfs lfs_fault = 1;
if(debug_file) fprintf(debug_file, "lfs fault!\n");
BEEP(512); //lfs
   }
   last_enviro = ENV_ID;
}

   if(strstr(enviro_field, "$PLHEN")) {  // custom Heather BME280 + two thermistors
      decode_heather_enviro(port, i);
   }
   else if(enviro_type == DOG_ENVIRO) { // default dogratian.com sensors
      decode_dog_enviro(port, i);
   }
   else if(enviro_type == LFS_ENVIRO) { // LFS104BW
// if(debug_file) fprintf(debug_file, "decode lfs:{%s}  last:%04X\n", enviro_msg, last_enviro); //lfs
      decode_lfs_enviro(port, i);
   }
   else {  // unknown sensor device
      init_enviro(port);
   }

   i = 1;
   if     ((enviro_sensors & ENV_TEMP1) && (have_temperature1 == 0)) i = 0;
   else if((enviro_sensors & ENV_TEMP2) && (have_temperature2 == 0)) i = 0;
   else if((enviro_sensors & ENV_PRESS) && (have_pressure == 0)) i = 0;
   else if((enviro_sensors & ENV_HUMID) && (have_humidity == 0)) i = 0;

   if(i) {  // only start logging if all supported readings are available
      if(rcvr_type == THERMO_RCVR) {  // system clock is driving screen updates
         if(sim_file) {
            get_norcvr_message();  // aaattt update screen 
         }
         else {
            get_norcvr_message();  // aaattt update screen 
         }
      }
   }

   if(sim_file && sim_delay) {  // throttle sim file messages
      Sleep(sim_delay);
   }
   saw_rcvr_msg = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edi, %ebx
leaq 0x16c573(%rip), %r15    # 0x2188d0
cmpq $0x80000, (%r15)        # imm = 0x80000
jne 0xac372
movl $0x1, %edi
callq 0x7f2b8
jmp 0xac37b
leaq 0x192bfb(%rip), %rax    # 0x23ef74
incl (%rax)
leaq 0x192bfe(%rip), %r14    # 0x23ef80
movl (%r14), %eax
incl %eax
movl %eax, (%r14)
cmpl $0x14, %eax
jne 0xac473
leaq 0x260ec2(%rip), %rax    # 0x30d25c
cmpl $0x0, (%rax)
jne 0xac3b0
leaq 0xb198a(%rip), %rax     # 0x15dd30
movl $0x0, 0xdb0(%rax)
leaq 0x260ea9(%rip), %rax    # 0x30d260
cmpl $0x0, (%rax)
jne 0xac3cd
leaq 0xb196d(%rip), %rax     # 0x15dd30
movl $0x0, 0xe98(%rax)
leaq 0x260e80(%rip), %rax    # 0x30d254
cmpl $0x0, (%rax)
jne 0xac3ea
leaq 0xb1950(%rip), %rax     # 0x15dd30
movl $0x0, 0xf80(%rax)
leaq 0x260e67(%rip), %rax    # 0x30d258
cmpl $0x0, (%rax)
jne 0xac407
leaq 0xb1933(%rip), %rax     # 0x15dd30
movl $0x0, 0x1068(%rax)
movq (%r15), %rax
cmpq $0x800000, %rax         # imm = 0x800000
je 0xac41a
cmpq $0x80000, %rax          # imm = 0x80000
jne 0xac451
leaq 0x260e4b(%rip), %rax    # 0x30d26c
cmpl $0x0, (%rax)
jne 0xac434
leaq 0xb1903(%rip), %rax     # 0x15dd30
movl $0x0, 0x18(%rax)
leaq 0x260e35(%rip), %rax    # 0x30d270
cmpl $0x0, (%rax)
jne 0xac451
leaq 0xb18e9(%rip), %rax     # 0x15dd30
movl $0x0, 0x100(%rax)
leaq 0x16eddc(%rip), %rax    # 0x21b234
cmpb $0x0, (%rax)
jne 0xac473
movl $0x7, %edi
movl $0x67, %esi
callq 0x1118c
movl $0x14, (%r14)
movb $0x0, 0x2bfdc6(%rip)    # 0x36c240
cmpl $0xf, %ebx
jne 0xac4b5
leaq 0x28ddee(%rip), %rax    # 0x33a274
movslq (%rax), %rax
testq %rax, %rax
jle 0xac4e9
xorl %ecx, %ecx
leaq 0x28cdd9(%rip), %rdx    # 0x339270
leaq 0x2bfda2(%rip), %rsi    # 0x36c240
movb (%rdx,%rcx), %dil
movb %dil, (%rcx,%rsi)
movb $0x0, 0x1(%rcx,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0xac49e
jmp 0xac4e9
leaq 0x28bd96(%rip), %rax    # 0x338252
movzwl (%rax), %eax
testq %rax, %rax
je 0xac4e9
xorl %ecx, %ecx
leaq 0x28ad83(%rip), %rdx    # 0x337250
leaq 0x2bfd6c(%rip), %rsi    # 0x36c240
movb (%rdx,%rcx), %dil
movb %dil, (%rcx,%rsi)
movb $0x0, 0x1(%rcx,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0xac4d4
leaq 0x2bfd50(%rip), %rdi    # 0x36c240
callq 0x9899
movl $0x0, 0x2c0155(%rip)    # 0x36c654
callq 0xab531
movl %eax, %r14d
leaq 0x16c416(%rip), %r12    # 0x218924
cmpl $0x8000, (%r12)         # imm = 0x8000
jne 0xac51d
callq 0xabb96
leaq 0x2bff2c(%rip), %rdi    # 0x36c450
leaq 0x79dee(%rip), %rsi     # 0x126319
callq 0x9090
testq %rax, %rax
je 0xac581
callq 0xaba79
testb $-0x80, 0x1(%r12)
jne 0xac579
movl $0x0, (%r12)
leaq 0x191e3f(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xac56f
leaq 0x79e15(%rip), %rdi     # 0x126375
movl $0xb, %esi
movl $0x1, %edx
callq 0x9750
movl $0x200, %edi            # imm = 0x200
callq 0x9d78
movl $0x8000, (%r12)         # imm = 0x8000
leaq 0x2bfec8(%rip), %rdi    # 0x36c450
leaq 0x79d72(%rip), %rsi     # 0x126301
callq 0x9090
testq %rax, %rax
je 0xac642
callq 0xac290
leaq 0x16c377(%rip), %rax    # 0x218920
movl (%rax), %eax
testb $0x1, %al
je 0xac5bb
leaq 0x260c9e(%rip), %rcx    # 0x30d254
cmpl $0x0, (%rcx)
je 0xac602
testb $0x2, %al
je 0xac5cb
leaq 0x260c92(%rip), %rcx    # 0x30d258
cmpl $0x0, (%rcx)
je 0xac602
testb $0x8, %al
je 0xac5db
leaq 0x260c8a(%rip), %rcx    # 0x30d260
cmpl $0x0, (%rcx)
je 0xac602
testb $0x4, %al
sete %al
leaq 0x260c75(%rip), %rcx    # 0x30d25c
cmpl $0x0, (%rcx)
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xac602
cmpq $0x80000, (%r15)        # imm = 0x80000
jne 0xac602
callq 0x8247a
leaq 0x191db7(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
setne %al
leaq 0x176fe9(%rip), %rcx    # 0x223600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xac62c
callq 0xafe8
leaq 0x19296d(%rip), %rax    # 0x23efa0
movl $0x1, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16c2cb(%rip), %rax    # 0x218914
movl (%rax), %eax
movl %ebx, %edi
cmpl $0x3, %eax
je 0xac664
cmpl $0x1, %eax
jne 0xac671
movl %r14d, %esi
callq 0xabcb6
jmp 0xac5a2
movl %r14d, %esi
callq 0xabe97
jmp 0xac5a2
callq 0x6e19a
jmp 0xac5a2