// File: /workspace/github_cpp_makefile_star2_O2/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 0x16649c(%rip), %r15    # 0x2028d0
cmpq $0x80000, (%r15)        # imm = 0x80000
jne 0x9c447
pushq $0x1
popq %rdi
callq 0x73dcb
jmp 0x9c450
leaq 0x18cb26(%rip), %rax    # 0x228f74
incl (%rax)
leaq 0x18cb29(%rip), %r14    # 0x228f80
movl (%r14), %eax
incl %eax
movl %eax, (%r14)
cmpl $0x14, %eax
jne 0x9c532
leaq 0x25aded(%rip), %rax    # 0x2f725c
cmpl $0x0, (%rax)
jne 0x9c482
leaq 0xab8b5(%rip), %rax     # 0x147d30
andl $0x0, 0xdb0(%rax)
leaq 0x25add7(%rip), %rax    # 0x2f7260
cmpl $0x0, (%rax)
jne 0x9c49c
leaq 0xab89b(%rip), %rax     # 0x147d30
andl $0x0, 0xe98(%rax)
leaq 0x25adb1(%rip), %rax    # 0x2f7254
cmpl $0x0, (%rax)
jne 0x9c4b6
leaq 0xab881(%rip), %rax     # 0x147d30
andl $0x0, 0xf80(%rax)
leaq 0x25ad9b(%rip), %rax    # 0x2f7258
cmpl $0x0, (%rax)
jne 0x9c4d0
leaq 0xab867(%rip), %rax     # 0x147d30
andl $0x0, 0x1068(%rax)
movq (%r15), %rax
cmpq $0x800000, %rax         # imm = 0x800000
je 0x9c4e3
cmpq $0x80000, %rax          # imm = 0x80000
jne 0x9c514
leaq 0x25ad82(%rip), %rax    # 0x2f726c
cmpl $0x0, (%rax)
jne 0x9c4fa
leaq 0xab83a(%rip), %rax     # 0x147d30
andl $0x0, 0x18(%rax)
leaq 0x25ad6f(%rip), %rax    # 0x2f7270
cmpl $0x0, (%rax)
jne 0x9c514
leaq 0xab823(%rip), %rax     # 0x147d30
andl $0x0, 0x100(%rax)
leaq 0x168d19(%rip), %rax    # 0x205234
cmpb $0x0, (%rax)
jne 0x9c532
pushq $0x7
popq %rdi
pushq $0x67
popq %rsi
callq 0x10a99
movl $0x14, (%r14)
movb $0x0, 0x2b9d07(%rip)    # 0x356240
cmpl $0xf, %ebx
jne 0x9c573
leaq 0x287d2f(%rip), %rax    # 0x324274
movl (%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
leaq 0x286d1b(%rip), %rdx    # 0x323270
leaq 0x2b9ce4(%rip), %rsi    # 0x356240
cmpq %rcx, %rax
je 0x9c5a4
movb (%rdx,%rcx), %dil
movb %dil, (%rcx,%rsi)
movb $0x0, 0x1(%rcx,%rsi)
incq %rcx
jmp 0x9c55c
leaq 0x285cd8(%rip), %rax    # 0x322252
movzwl (%rax), %eax
xorl %ecx, %ecx
leaq 0x284cca(%rip), %rdx    # 0x321250
leaq 0x2b9cb3(%rip), %rsi    # 0x356240
cmpq %rcx, %rax
je 0x9c5a4
movb (%rdx,%rcx), %dil
movb %dil, (%rcx,%rsi)
movb $0x0, 0x1(%rcx,%rsi)
incq %rcx
jmp 0x9c58d
leaq 0x2b9c95(%rip), %rdi    # 0x356240
callq 0x988f
andl $0x0, 0x2ba09d(%rip)    # 0x356654
callq 0x9b7a1
movl %eax, %r14d
leaq 0x16635e(%rip), %r12    # 0x202924
cmpl $0x8000, (%r12)         # imm = 0x8000
jne 0x9c5d5
callq 0x9bdb8
leaq 0x2b9e74(%rip), %rdi    # 0x356450
leaq 0x73c7b(%rip), %rsi     # 0x11025e
callq 0x9090
testq %rax, %rax
je 0x9c632
callq 0x9bcaa
testb $-0x80, 0x1(%r12)
jne 0x9c62a
andl $0x0, (%r12)
leaq 0x18bd8a(%rip), %rax    # 0x228390
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9c620
leaq 0x73ca5(%rip), %rdi     # 0x1102ba
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
movl $0x200, %edi            # imm = 0x200
callq 0x9d23
movl $0x8000, (%r12)         # imm = 0x8000
leaq 0x2b9e17(%rip), %rdi    # 0x356450
leaq 0x73c06(%rip), %rsi     # 0x110246
callq 0x9090
testq %rax, %rax
je 0x9c6f3
callq 0x9c3b9
leaq 0x1662c6(%rip), %rax    # 0x202920
movl (%rax), %eax
testb $0x1, %al
je 0x9c66c
leaq 0x25abed(%rip), %rcx    # 0x2f7254
cmpl $0x0, (%rcx)
je 0x9c6b3
testb $0x2, %al
je 0x9c67c
leaq 0x25abe1(%rip), %rcx    # 0x2f7258
cmpl $0x0, (%rcx)
je 0x9c6b3
testb $0x8, %al
je 0x9c68c
leaq 0x25abd9(%rip), %rcx    # 0x2f7260
cmpl $0x0, (%rcx)
je 0x9c6b3
testb $0x4, %al
sete %al
leaq 0x25abc4(%rip), %rcx    # 0x2f725c
cmpl $0x0, (%rcx)
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x9c6b3
cmpq $0x80000, (%r15)        # imm = 0x80000
jne 0x9c6b3
callq 0x76a3e
leaq 0x18bd06(%rip), %rax    # 0x2283c0
cmpq $0x0, (%rax)
setne %al
leaq 0x170f38(%rip), %rcx    # 0x20d600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9c6dd
callq 0xae83
leaq 0x18c8bc(%rip), %rax    # 0x228fa0
movl $0x1, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16621a(%rip), %rax    # 0x202914
movl (%rax), %eax
movl %ebx, %edi
cmpl $0x3, %eax
je 0x9c715
cmpl $0x1, %eax
jne 0x9c722
movl %r14d, %esi
callq 0x9bed5
jmp 0x9c653
movl %r14d, %esi
callq 0x9c044
jmp 0x9c653
callq 0x64dce
jmp 0x9c653