// File: /workspace/github_cpp_makefile_star2_O1/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 0x16c7fa(%rip), %r15    # 0x2188d0
cmpq $0x80000, (%r15)        # imm = 0x80000
jne 0xac0eb
movl $0x1, %edi
callq 0x7f47d
jmp 0xac0f4
leaq 0x192e82(%rip), %rax    # 0x23ef74
incl (%rax)
leaq 0x192e85(%rip), %r14    # 0x23ef80
movl (%r14), %eax
incl %eax
movl %eax, (%r14)
cmpl $0x14, %eax
jne 0xac1cc
leaq 0x261149(%rip), %rcx    # 0x30d25c
cmpl $0x0, (%rcx)
jne 0xac129
leaq 0xb1c11(%rip), %rcx     # 0x15dd30
movl $0x0, 0xdb0(%rcx)
leaq 0x261130(%rip), %rcx    # 0x30d260
cmpl $0x0, (%rcx)
jne 0xac146
leaq 0xb1bf4(%rip), %rcx     # 0x15dd30
movl $0x0, 0xe98(%rcx)
leaq 0x261107(%rip), %rcx    # 0x30d254
cmpl $0x0, (%rcx)
jne 0xac163
leaq 0xb1bd7(%rip), %rcx     # 0x15dd30
movl $0x0, 0xf80(%rcx)
leaq 0x2610ee(%rip), %rcx    # 0x30d258
cmpl $0x0, (%rcx)
jne 0xac180
leaq 0xb1bba(%rip), %rcx     # 0x15dd30
movl $0x0, 0x1068(%rcx)
movq (%r15), %rcx
cmpq $0x800000, %rcx         # imm = 0x800000
je 0xac195
cmpq $0x80000, %rcx          # imm = 0x80000
jne 0xac1cc
leaq 0x2610d0(%rip), %rcx    # 0x30d26c
cmpl $0x0, (%rcx)
jne 0xac1af
leaq 0xb1b88(%rip), %rcx     # 0x15dd30
movl $0x0, 0x18(%rcx)
leaq 0x2610ba(%rip), %rcx    # 0x30d270
cmpl $0x0, (%rcx)
jne 0xac1cc
leaq 0xb1b6e(%rip), %rcx     # 0x15dd30
movl $0x0, 0x100(%rcx)
cmpl $0x14, %eax
jne 0xac1f3
leaq 0x16f05c(%rip), %rax    # 0x21b234
cmpb $0x0, (%rax)
jne 0xac1f3
movl $0x7, %edi
movl $0x67, %esi
callq 0x1120f
movl $0x14, (%r14)
movb $0x0, 0x2c0046(%rip)    # 0x36c240
cmpl $0xf, %ebx
jne 0xac235
leaq 0x28e06e(%rip), %rax    # 0x33a274
movslq (%rax), %rax
testq %rax, %rax
jle 0xac269
xorl %ecx, %ecx
leaq 0x28d059(%rip), %rdx    # 0x339270
leaq 0x2c0022(%rip), %rsi    # 0x36c240
movb (%rdx,%rcx), %dil
movb %dil, (%rcx,%rsi)
movb $0x0, 0x1(%rcx,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0xac21e
jmp 0xac269
leaq 0x28c016(%rip), %rax    # 0x338252
movzwl (%rax), %eax
testq %rax, %rax
je 0xac269
xorl %ecx, %ecx
leaq 0x28b003(%rip), %rdx    # 0x337250
leaq 0x2bffec(%rip), %rsi    # 0x36c240
movb (%rdx,%rcx), %dil
movb %dil, (%rcx,%rsi)
movb $0x0, 0x1(%rcx,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0xac254
leaq 0x2bffd0(%rip), %rdi    # 0x36c240
callq 0x9899
movl $0x0, 0x2c03d5(%rip)    # 0x36c654
callq 0xab2b0
movl %eax, %r14d
leaq 0x16c696(%rip), %r12    # 0x218924
cmpl $0x8000, (%r12)         # imm = 0x8000
jne 0xac29d
callq 0xab90f
leaq 0x2c01ac(%rip), %rdi    # 0x36c450
leaq 0x79f8e(%rip), %rsi     # 0x126239
callq 0x9090
testq %rax, %rax
je 0xac301
callq 0xab7f2
testb $-0x80, 0x1(%r12)
jne 0xac2f9
movl $0x0, (%r12)
leaq 0x1920bf(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xac2ef
leaq 0x79fb5(%rip), %rdi     # 0x126295
movl $0xb, %esi
movl $0x1, %edx
callq 0x9750
movl $0x200, %edi            # imm = 0x200
callq 0x9d80
movl $0x8000, (%r12)         # imm = 0x8000
leaq 0x2c0148(%rip), %rdi    # 0x36c450
leaq 0x79f12(%rip), %rsi     # 0x126221
callq 0x9090
testq %rax, %rax
je 0xac3b3
callq 0xac009
leaq 0x16c5f7(%rip), %rax    # 0x218920
movl (%rax), %eax
testb $0x1, %al
je 0xac33b
leaq 0x260f1e(%rip), %rcx    # 0x30d254
cmpl $0x0, (%rcx)
je 0xac35f
testb $0x2, %al
je 0xac34b
leaq 0x260f12(%rip), %rcx    # 0x30d258
cmpl $0x0, (%rcx)
je 0xac35f
testb $0x8, %al
je 0xac3d5
leaq 0x260f06(%rip), %rcx    # 0x30d260
cmpl $0x0, (%rcx)
jne 0xac3d5
xorl %eax, %eax
testb %al, %al
je 0xac373
cmpq $0x80000, (%r15)        # imm = 0x80000
jne 0xac373
callq 0x82578
leaq 0x192046(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
setne %al
leaq 0x177278(%rip), %rcx    # 0x223600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xac39d
callq 0xaff7
leaq 0x192bfc(%rip), %rax    # 0x23efa0
movl $0x1, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16c55a(%rip), %rax    # 0x218914
movl (%rax), %eax
movl %ebx, %edi
cmpl $0x3, %eax
je 0xac3ee
cmpl $0x1, %eax
jne 0xac3fb
movl %r14d, %esi
callq 0xaba2f
jmp 0xac322
testb $0x4, %al
sete %cl
leaq 0x260e7b(%rip), %rax    # 0x30d25c
cmpl $0x0, (%rax)
setne %al
orb %cl, %al
jmp 0xac361
movl %r14d, %esi
callq 0xabc10
jmp 0xac322
callq 0x6e285
jmp 0xac322