// File: 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
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
leaq 0x18e0ae(%rip), %rax    # 0x277ab0
cmpq $0x80000, (%rax)        # imm = 0x80000
jne 0xe9a2c
movl $0x1, %edi
callq 0xae4a0
leaq 0x1b4744(%rip), %rax    # 0x29e160
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x1b4738(%rip), %rax    # 0x29e160
movl %ecx, (%rax)
jmp 0xe9a56
leaq 0x1b4721(%rip), %rax    # 0x29e154
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x1b4715(%rip), %rax    # 0x29e154
movl %ecx, (%rax)
leaq 0x1b4718(%rip), %rax    # 0x29e160
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x1b470c(%rip), %rax    # 0x29e160
movl %ecx, (%rax)
leaq 0x1b4703(%rip), %rax    # 0x29e160
cmpl $0x14, (%rax)
jne 0xe9b35
leaq 0x2829cf(%rip), %rax    # 0x36c43c
cmpl $0x0, (%rax)
jne 0xe9a83
leaq 0xd32a7(%rip), %rax     # 0x1bcd20
movl $0x0, 0xdb0(%rax)
leaq 0x2829b6(%rip), %rax    # 0x36c440
cmpl $0x0, (%rax)
jne 0xe9aa0
leaq 0xd328a(%rip), %rax     # 0x1bcd20
movl $0x0, 0xe98(%rax)
leaq 0x28298d(%rip), %rax    # 0x36c434
cmpl $0x0, (%rax)
jne 0xe9abd
leaq 0xd326d(%rip), %rax     # 0x1bcd20
movl $0x0, 0xf80(%rax)
leaq 0x282974(%rip), %rax    # 0x36c438
cmpl $0x0, (%rax)
jne 0xe9ada
leaq 0xd3250(%rip), %rax     # 0x1bcd20
movl $0x0, 0x1068(%rax)
leaq 0x18dfcf(%rip), %rax    # 0x277ab0
cmpq $0x80000, (%rax)        # imm = 0x80000
je 0xe9afa
leaq 0x18dfbf(%rip), %rax    # 0x277ab0
cmpq $0x800000, (%rax)       # imm = 0x800000
jne 0xe9b33
leaq 0x28294b(%rip), %rax    # 0x36c44c
cmpl $0x0, (%rax)
jne 0xe9b14
leaq 0xd3213(%rip), %rax     # 0x1bcd20
movl $0x0, 0x18(%rax)
leaq 0x282935(%rip), %rax    # 0x36c450
cmpl $0x0, (%rax)
jne 0xe9b31
leaq 0xd31f9(%rip), %rax     # 0x1bcd20
movl $0x0, 0x100(%rax)
jmp 0xe9b33
jmp 0xe9b35
leaq 0x1b4624(%rip), %rax    # 0x29e160
cmpl $0x14, (%rax)
jne 0xe9b77
leaq 0x1908cc(%rip), %rax    # 0x27a414
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xe9b77
leaq 0x1b4609(%rip), %rax    # 0x29e160
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movl $0x7, %edi
movl $0x67, %esi
callq 0x14df0
movl -0x10(%rbp), %ecx
leaq 0x1b45eb(%rip), %rax    # 0x29e160
movl %ecx, (%rax)
movb $0x0, 0x2e18a2(%rip)    # 0x3cb420
cmpl $0xf, -0x4(%rbp)
jne 0xe9bdc
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x2af8bf(%rip), %rcx    # 0x399454
cmpl (%rcx), %eax
jge 0xe9bda
movslq -0x8(%rbp), %rcx
leaq 0x2ae8ac(%rip), %rax    # 0x398450
movb (%rax,%rcx), %al
movb %al, -0x9(%rbp)
movb -0x9(%rbp), %dl
movslq -0x8(%rbp), %rcx
leaq 0x2e1868(%rip), %rax    # 0x3cb420
movb %dl, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2e1855(%rip), %rax    # 0x3cb420
movb $0x0, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xe9b8b
jmp 0xe9c37
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x2ad845(%rip), %rcx    # 0x397432
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xe9c35
movslq -0x8(%rbp), %rcx
leaq 0x2ac831(%rip), %rax    # 0x396430
movb (%rax,%rcx), %al
movb %al, -0x9(%rbp)
movb -0x9(%rbp), %dl
movslq -0x8(%rbp), %rcx
leaq 0x2e180d(%rip), %rax    # 0x3cb420
movb %dl, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2e17fa(%rip), %rax    # 0x3cb420
movb $0x0, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xe9be3
jmp 0xe9c37
leaq 0x2e17e2(%rip), %rdi    # 0x3cb420
callq 0x9890
movl $0x0, 0x2e1be7(%rip)    # 0x3cb834
callq 0xe84c0
movl %eax, -0x8(%rbp)
leaq 0x18dea8(%rip), %rax    # 0x277b04
cmpl $0x8000, (%rax)         # imm = 0x8000
jne 0xe9c69
callq 0xe8eb0
leaq 0x2e19c0(%rip), %rdi    # 0x3cb630
leaq 0x9fa21(%rip), %rsi     # 0x189698
callq 0x9090
cmpq $0x0, %rax
je 0xe9ce3
callq 0xe8cd0
leaq 0x18de76(%rip), %rax    # 0x277b04
movl (%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
jne 0xe9cd6
leaq 0x18de63(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
leaq 0x1b38c2(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xe9ccc
leaq 0x1b38b5(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x9fa2f(%rip), %rsi     # 0x1896f4
movb $0x0, %al
callq 0x9550
movl $0x200, %edi            # imm = 0x200
callq 0x9ec0
leaq 0x18de27(%rip), %rax    # 0x277b04
movl $0x8000, (%rax)         # imm = 0x8000
leaq 0x2e1946(%rip), %rdi    # 0x3cb630
leaq 0x9f98f(%rip), %rsi     # 0x189680
callq 0x9090
cmpq $0x0, %rax
je 0xe9d09
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
callq 0xe9960
jmp 0xe9d47
leaq 0x18dde4(%rip), %rax    # 0x277af4
cmpl $0x1, (%rax)
jne 0xe9d22
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
callq 0xe9020
jmp 0xe9d45
leaq 0x18ddcb(%rip), %rax    # 0x277af4
cmpl $0x3, (%rax)
jne 0xe9d3b
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
callq 0xe9290
jmp 0xe9d43
movl -0x4(%rbp), %edi
callq 0x961a0
jmp 0xe9d45
jmp 0xe9d47
movl $0x1, -0x8(%rbp)
leaq 0x18ddab(%rip), %rax    # 0x277b00
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xe9d74
leaq 0x2826ce(%rip), %rax    # 0x36c434
cmpl $0x0, (%rax)
jne 0xe9d74
movl $0x0, -0x8(%rbp)
jmp 0xe9dea
leaq 0x18dd85(%rip), %rax    # 0x277b00
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xe9d9a
leaq 0x2826ac(%rip), %rax    # 0x36c438
cmpl $0x0, (%rax)
jne 0xe9d9a
movl $0x0, -0x8(%rbp)
jmp 0xe9de8
leaq 0x18dd5f(%rip), %rax    # 0x277b00
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xe9dc0
leaq 0x28268e(%rip), %rax    # 0x36c440
cmpl $0x0, (%rax)
jne 0xe9dc0
movl $0x0, -0x8(%rbp)
jmp 0xe9de6
leaq 0x18dd39(%rip), %rax    # 0x277b00
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xe9de4
leaq 0x282664(%rip), %rax    # 0x36c43c
cmpl $0x0, (%rax)
jne 0xe9de4
movl $0x0, -0x8(%rbp)
jmp 0xe9de6
jmp 0xe9de8
jmp 0xe9dea
cmpl $0x0, -0x8(%rbp)
je 0xe9e1d
leaq 0x18dcb9(%rip), %rax    # 0x277ab0
cmpq $0x80000, (%rax)        # imm = 0x80000
jne 0xe9e1b
leaq 0x1b3799(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
je 0xe9e14
callq 0xb2630
jmp 0xe9e19
callq 0xb2630
jmp 0xe9e1b
jmp 0xe9e1d
leaq 0x1b377c(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
je 0xe9e48
leaq 0x1989af(%rip), %rax    # 0x2827e0
cmpq $0x0, (%rax)
je 0xe9e48
leaq 0x1989a2(%rip), %rax    # 0x2827e0
movq (%rax), %rax
movl %eax, %edi
callq 0xb8b0
leaq 0x1b4331(%rip), %rax    # 0x29e180
movl $0x1, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)