// File: jkingan[P]ladyheather/heathgps.cpp
// Function: decode_lfs_enviro(unsigned int, int)
void decode_lfs_enviro(unsigned port, int i)
{
   // decode LFS sensor values then poll for the next reading

// if(debug_file) fprintf(debug_file, "decoding enviro:%d  last:%04X  fault:%d\n", i,last_enviro, lfs_fault); //lfs
   if(lfs_fault) {
   }
   else if(i) {
      if(last_enviro == ENV_ID) {  // device ID
         goto poll_next_lfs_enviro; 
      }
      else if(last_enviro == ENV_SN) {
         enviro_field[UNIT_LEN] = 0;
         strcpy(enviro_sn, enviro_field);
         have_info |= MFG_INFO;
      }
      else if(last_enviro == ENV_TEMP1) {  // themrometer
         parse_temp1();
         tc1 /= 10.0;
         tc1 = (DATA_SIZE) (((double) tc1 - 32.0) * 5.0 / 9.0);
if(tc1 > 100.0) {
   last_enviro = 0;
   drain_port(port);
}
         save_temp1();
      }
      else if(last_enviro == ENV_HUMID) {  // humidity
         parse_humidity();
         humidity /= 10.0;
if(humidity > 110.0) {
   last_enviro = 0;
   drain_port(port);
}
      }
      else if((last_enviro == ENV_TEMP2) || (last_enviro == ENV_RTEMP)) {  // IR or remote thermometer
         parse_temp2();
         tc2 /= 10.0;
         tc2 = (DATA_SIZE) (((double) tc2 - 32.0) * 5.0 / 9.0);
if(tc2 > 100.0) {
   last_enviro = 0;
   drain_port(port);
}
      }
      else if(last_enviro == ENV_PRESS) {  // pressure
         parse_pressure();
         pressure /= 10.0;
if(pressure < 200.0) {
   last_enviro = 0;
   drain_port(port);
}
      }
      else if(last_enviro == ENV_DP) {     // dew point
         parse_dp();
         dew_pt /= 10.0;
      }
      else if(last_enviro == ENV_RTEMP) {  // remote temperature - !!!! handled above as temp2
         parse_rtemp();
         rem_temp /= 10.0;
         rem_temp = (DATA_SIZE) (((double) rem_temp - 32.0) * 5.0 / 9.0);
      }
      else if(last_enviro == ENV_LUX) {    // light sensor
         parse_lux();
         lux /= 10.0;
      }
      else if(last_enviro == ENV_REFALT) { // reference altitude
         parse_ref_baro_alt();
         ref_baro_alt /= 10.0;
      }
      else if(last_enviro == ENV_COUNT) {  // counter / freq
         parse_lfs_counter();
         lfs_counter /= 10.0;
      }
      else if(last_enviro == ENV_EMIS) {   // IR sensor emissivity
         parse_lfs_emis();
         emis1 /= 100.0;
      }
      else {
         last_enviro = 0;
      }
   }
   else last_enviro = 0;

   poll_next_lfs_enviro: // get the next reading 
// if(debug_file) fprintf(debug_file, "polling next enviro:%d  last:%04X  next:%04X\n", i,last_enviro,next_enviro); //lfs
   next_enviro_poll();   // get the reading type to poll for
   lfs_fault = 0;
// if(debug_file) fprintf(debug_file, "polling next enviro::%d  last:%04X  next:%04X\n", i,last_enviro, next_enviro); //lfs

   if(next_enviro & ENV_TEMP1) {  // get temp1
      send_enviro_cmd("GET1\r", port);
      last_enviro = ENV_TEMP1;
   }
   else if(next_enviro & ENV_HUMID) { // get humidity
      send_enviro_cmd("GET2\r", port);
      last_enviro = ENV_HUMID;
   }
   else if(next_enviro & ENV_TEMP2) {  // get temp2 - IR
      send_enviro_cmd("GET3\r", port); 
      last_enviro = ENV_TEMP2;
   }
   else if(next_enviro & ENV_PRESS) {  // get baro 
      send_enviro_cmd("GET4\r", port);
      last_enviro = ENV_PRESS;
   }
   else if(next_enviro & ENV_COUNT) {  // get count/freq
      send_enviro_cmd("GET6\r", port);
      last_enviro = ENV_COUNT;
   }
   else if(next_enviro & ENV_DP) {  // get dew point
      send_enviro_cmd("GET7\r", port);
      last_enviro = ENV_DP;
   }
   else if(next_enviro & ENV_EMIS) {  // get emissivity setting
      send_enviro_cmd("GEMIS\r", port);
      last_enviro = ENV_EMIS;
   }
   else if(next_enviro & ENV_LUX) {  // get lux level
      send_enviro_cmd("GET9\r", port);
      last_enviro = ENV_LUX;
   }
   else if(next_enviro & ENV_REFALT) {  // get reference altitude
      send_enviro_cmd("GETA1\r", port);
      last_enviro = ENV_REFALT;
   }
   else if(next_enviro & ENV_RTEMP) {  // get remote temp
      send_enviro_cmd("GETr1\r", port);
      last_enviro = ENV_RTEMP;
   }
   else if(next_enviro & ENV_SN) {  // get serial number
      send_enviro_cmd("GETSN\r", port);
      last_enviro = ENV_SN;
   }
   else {  // unknown last request
      send_enviro_cmd("GET1\r", port);  // should never happen - get temp1
      last_enviro = ENV_TEMP1;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
cmpl $0x0, 0x2e81ab(%rip)    # 0x3d1450
je 0xe92ac
jmp 0xe96ef
cmpl $0x0, -0x8(%rbp)
je 0xe96e0
leaq 0x18e847(%rip), %rax    # 0x277b04
cmpl $0x8000, (%rax)         # imm = 0x8000
jne 0xe92ca
jmp 0xe96f1
leaq 0x18e833(%rip), %rax    # 0x277b04
cmpl $0x10, (%rax)
jne 0xe930a
movb $0x0, 0x2e2365(%rip)    # 0x3cb642
leaq 0x2b317c(%rip), %rdi    # 0x39c460
leaq 0x2e2345(%rip), %rsi    # 0x3cb630
callq 0x9350
leaq 0x28385d(%rip), %rax    # 0x36cb54
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x283851(%rip), %rax    # 0x36cb54
movl %ecx, (%rax)
jmp 0xe96dc
leaq 0x18e7f3(%rip), %rax    # 0x277b04
cmpl $0x1, (%rax)
jne 0xe93b3
callq 0xe8710
leaq 0x282a6a(%rip), %rax    # 0x36bd90
movsd (%rax), %xmm0
movsd 0x85d8e(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x282a53(%rip), %rax    # 0x36bd90
movsd %xmm0, (%rax)
leaq 0x282a48(%rip), %rax    # 0x36bd90
movsd (%rax), %xmm0
movsd 0x85d7c(%rip), %xmm1    # 0x16f0d0
subsd %xmm1, %xmm0
movsd 0x85e00(%rip), %xmm1    # 0x16f160
mulsd %xmm1, %xmm0
movsd 0x998e4(%rip), %xmm1    # 0x182c50
divsd %xmm1, %xmm0
leaq 0x282a19(%rip), %rax    # 0x36bd90
movsd %xmm0, (%rax)
leaq 0x282a0e(%rip), %rax    # 0x36bd90
movsd (%rax), %xmm0
movsd 0x85cc2(%rip), %xmm1    # 0x16f050
ucomisd %xmm1, %xmm0
jbe 0xe93a9
leaq 0x18e769(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x79900
callq 0xe8b90
jmp 0xe96da
leaq 0x18e74a(%rip), %rax    # 0x277b04
cmpl $0x4, (%rax)
jne 0xe9419
callq 0xe85f0
leaq 0x2829ad(%rip), %rax    # 0x36bd78
movsd (%rax), %xmm0
movsd 0x85ce9(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x282996(%rip), %rax    # 0x36bd78
movsd %xmm0, (%rax)
leaq 0x28298b(%rip), %rax    # 0x36bd78
movsd (%rax), %xmm0
movsd 0x99cd7(%rip), %xmm1    # 0x1830d0
ucomisd %xmm1, %xmm0
jbe 0xe9414
leaq 0x18e6fe(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x79900
jmp 0xe96d8
leaq 0x18e6e4(%rip), %rax    # 0x277b04
cmpl $0x2, (%rax)
je 0xe9435
leaq 0x18e6d8(%rip), %rax    # 0x277b04
cmpl $0x40, (%rax)
jne 0xe94c9
callq 0xe8770
leaq 0x282957(%rip), %rax    # 0x36bd98
movsd (%rax), %xmm0
movsd 0x85c73(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x282940(%rip), %rax    # 0x36bd98
movsd %xmm0, (%rax)
leaq 0x282935(%rip), %rax    # 0x36bd98
movsd (%rax), %xmm0
movsd 0x85c61(%rip), %xmm1    # 0x16f0d0
subsd %xmm1, %xmm0
movsd 0x85ce5(%rip), %xmm1    # 0x16f160
mulsd %xmm1, %xmm0
movsd 0x997c9(%rip), %xmm1    # 0x182c50
divsd %xmm1, %xmm0
leaq 0x282906(%rip), %rax    # 0x36bd98
movsd %xmm0, (%rax)
leaq 0x2828fb(%rip), %rax    # 0x36bd98
movsd (%rax), %xmm0
movsd 0x85ba7(%rip), %xmm1    # 0x16f050
ucomisd %xmm1, %xmm0
jbe 0xe94c4
leaq 0x18e64e(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x79900
jmp 0xe96d6
leaq 0x18e634(%rip), %rax    # 0x277b04
cmpl $0x8, (%rax)
jne 0xe952b
callq 0xe8650
leaq 0x28289f(%rip), %rax    # 0x36bd80
movsd (%rax), %xmm0
movsd 0x85bd3(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x282888(%rip), %rax    # 0x36bd80
movsd %xmm0, (%rax)
movsd 0x85c94(%rip), %xmm0    # 0x16f198
leaq 0x282875(%rip), %rax    # 0x36bd80
ucomisd (%rax), %xmm0
jbe 0xe9526
leaq 0x18e5ec(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x79900
jmp 0xe96d4
leaq 0x18e5d2(%rip), %rax    # 0x277b04
cmpl $0x20, (%rax)
jne 0xe9563
callq 0xe8950
leaq 0x28288d(%rip), %rax    # 0x36bdd0
movsd (%rax), %xmm0
movsd 0x85b71(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x282876(%rip), %rax    # 0x36bdd0
movsd %xmm0, (%rax)
jmp 0xe96d2
leaq 0x18e59a(%rip), %rax    # 0x277b04
cmpl $0x40, (%rax)
jne 0xe95d5
callq 0xe89b0
leaq 0x28285d(%rip), %rax    # 0x36bdd8
movsd (%rax), %xmm0
movsd 0x85b39(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x282846(%rip), %rax    # 0x36bdd8
movsd %xmm0, (%rax)
leaq 0x28283b(%rip), %rax    # 0x36bdd8
movsd (%rax), %xmm0
movsd 0x85b27(%rip), %xmm1    # 0x16f0d0
subsd %xmm1, %xmm0
movsd 0x85bab(%rip), %xmm1    # 0x16f160
mulsd %xmm1, %xmm0
movsd 0x9968f(%rip), %xmm1    # 0x182c50
divsd %xmm1, %xmm0
leaq 0x28280c(%rip), %rax    # 0x36bdd8
movsd %xmm0, (%rax)
jmp 0xe96d0
leaq 0x18e528(%rip), %rax    # 0x277b04
cmpl $0x80, (%rax)
jne 0xe9610
callq 0xe8a10
leaq 0x2827f0(%rip), %rax    # 0x36bde0
movsd (%rax), %xmm0
movsd 0x85ac4(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x2827d9(%rip), %rax    # 0x36bde0
movsd %xmm0, (%rax)
jmp 0xe96ce
leaq 0x18e4ed(%rip), %rax    # 0x277b04
cmpl $0x100, (%rax)          # imm = 0x100
jne 0xe964b
callq 0xe8a70
leaq 0x2827bd(%rip), %rax    # 0x36bde8
movsd (%rax), %xmm0
movsd 0x85a89(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x2827a6(%rip), %rax    # 0x36bde8
movsd %xmm0, (%rax)
jmp 0xe96cc
leaq 0x18e4b2(%rip), %rax    # 0x277b04
cmpl $0x200, (%rax)          # imm = 0x200
jne 0xe9683
callq 0xe8ad0
leaq 0x28278a(%rip), %rax    # 0x36bdf0
movsd (%rax), %xmm0
movsd 0x85a4e(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x282773(%rip), %rax    # 0x36bdf0
movsd %xmm0, (%rax)
jmp 0xe96ca
leaq 0x18e47a(%rip), %rax    # 0x277b04
cmpl $0x400, (%rax)          # imm = 0x400
jne 0xe96bb
callq 0xe8b30
leaq 0x282922(%rip), %rax    # 0x36bfc0
movsd (%rax), %xmm0
movsd 0x859a6(%rip), %xmm1    # 0x16f050
divsd %xmm1, %xmm0
leaq 0x28290b(%rip), %rax    # 0x36bfc0
movsd %xmm0, (%rax)
jmp 0xe96c8
leaq 0x18e442(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
jmp 0xe96ca
jmp 0xe96cc
jmp 0xe96ce
jmp 0xe96d0
jmp 0xe96d2
jmp 0xe96d4
jmp 0xe96d6
jmp 0xe96d8
jmp 0xe96da
jmp 0xe96dc
jmp 0xe96de
jmp 0xe96ed
leaq 0x18e41d(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
jmp 0xe96ef
jmp 0xe96f1
callq 0xe8bf0
movl $0x0, 0x2e7d50(%rip)    # 0x3d1450
leaq 0x18e401(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xe9732
movl -0x4(%rbp), %esi
leaq 0x9ff93(%rip), %rdi     # 0x1896ae
callq 0x855b0
leaq 0x18e3dd(%rip), %rax    # 0x277b04
movl $0x1, (%rax)
jmp 0xe9955
leaq 0x18e3cf(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xe9764
movl -0x4(%rbp), %esi
leaq 0x9ff67(%rip), %rdi     # 0x1896b4
callq 0x855b0
leaq 0x18e3ab(%rip), %rax    # 0x277b04
movl $0x4, (%rax)
jmp 0xe9953
leaq 0x18e39d(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xe9796
movl -0x4(%rbp), %esi
leaq 0x9ff3b(%rip), %rdi     # 0x1896ba
callq 0x855b0
leaq 0x18e379(%rip), %rax    # 0x277b04
movl $0x2, (%rax)
jmp 0xe9951
leaq 0x18e36b(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xe97c8
movl -0x4(%rbp), %esi
leaq 0x9ff0f(%rip), %rdi     # 0x1896c0
callq 0x855b0
leaq 0x18e347(%rip), %rax    # 0x277b04
movl $0x8, (%rax)
jmp 0xe994f
leaq 0x18e339(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0xe97fc
movl -0x4(%rbp), %esi
leaq 0x9fee1(%rip), %rdi     # 0x1896c6
callq 0x855b0
leaq 0x18e313(%rip), %rax    # 0x277b04
movl $0x200, (%rax)          # imm = 0x200
jmp 0xe994d
leaq 0x18e305(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xe982e
movl -0x4(%rbp), %esi
leaq 0x9feb5(%rip), %rdi     # 0x1896cc
callq 0x855b0
leaq 0x18e2e1(%rip), %rax    # 0x277b04
movl $0x20, (%rax)
jmp 0xe994b
leaq 0x18e2d3(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0xe9862
movl -0x4(%rbp), %esi
leaq 0x9fe87(%rip), %rdi     # 0x1896d2
callq 0x855b0
leaq 0x18e2ad(%rip), %rax    # 0x277b04
movl $0x400, (%rax)          # imm = 0x400
jmp 0xe9949
leaq 0x18e29f(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xe9896
movl -0x4(%rbp), %esi
leaq 0x9fe5a(%rip), %rdi     # 0x1896d9
callq 0x855b0
leaq 0x18e279(%rip), %rax    # 0x277b04
movl $0x80, (%rax)
jmp 0xe9947
leaq 0x18e26b(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0xe98c7
movl -0x4(%rbp), %esi
leaq 0x9fe2c(%rip), %rdi     # 0x1896df
callq 0x855b0
leaq 0x18e245(%rip), %rax    # 0x277b04
movl $0x100, (%rax)          # imm = 0x100
jmp 0xe9945
leaq 0x18e23a(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0xe98f6
movl -0x4(%rbp), %esi
leaq 0x9fe04(%rip), %rdi     # 0x1896e6
callq 0x855b0
leaq 0x18e216(%rip), %rax    # 0x277b04
movl $0x40, (%rax)
jmp 0xe9943
leaq 0x18e20b(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0xe9925
movl -0x4(%rbp), %esi
leaq 0x9fddc(%rip), %rdi     # 0x1896ed
callq 0x855b0
leaq 0x18e1e7(%rip), %rax    # 0x277b04
movl $0x10, (%rax)
jmp 0xe9941
movl -0x4(%rbp), %esi
leaq 0x9fd7f(%rip), %rdi     # 0x1896ae
callq 0x855b0
leaq 0x18e1c9(%rip), %rax    # 0x277b04
movl $0x1, (%rax)
jmp 0xe9943
jmp 0xe9945
jmp 0xe9947
jmp 0xe9949
jmp 0xe994b
jmp 0xe994d
jmp 0xe994f
jmp 0xe9951
jmp 0xe9953
jmp 0xe9955
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)