// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebx
cmpl $0x0, 0x2c6621(%rip)    # 0x372244
je 0xabccd
callq 0xab798
movl $0x0, 0x2c660c(%rip)    # 0x372244
leaq 0x16cce9(%rip), %rax    # 0x218928
movl (%rax), %eax
testb $0x1, %al
jne 0xabcbb
testb $0x4, %al
jne 0xabd88
testb $0x2, %al
jne 0xabdac
testb $0x8, %al
jne 0xabdf1
btl $0x9, %eax
jb 0xabe89
testb $0x20, %al
jne 0xabf86
btl $0xa, %eax
jb 0xabfb3
testb %al, %al
js 0xabfc2
btl $0x8, %eax
jb 0xabfd1
testb $0x40, %al
jne 0xabfe0
testb $0x10, %al
leaq 0x7a5b3(%rip), %rax     # 0x12624f
leaq 0x7a5eb(%rip), %rdi     # 0x12628e
cmoveq %rax, %rdi
movl $0x1, %eax
movl $0x10, %r14d
cmovel %eax, %r14d
jmp 0xabfed
movl $0x1, %r14d
leaq 0x7a587(%rip), %rdi     # 0x12624f
jmp 0xabfed
testl %esi, %esi
je 0xabd9a
leaq 0x16cc48(%rip), %r14    # 0x218924
movl (%r14), %eax
cmpl $0x3f, %eax
jg 0xabdbe
leal -0x1(%rax), %ecx
cmpl $0x7, %ecx
ja 0xabe26
leaq 0x73e4d(%rip), %rax     # 0x11fb48
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
callq 0xab417
leaq 0x260ea0(%rip), %r15    # 0x30cbb0
movsd (%r15), %xmm0
divsd 0x5d38b(%rip), %xmm0    # 0x1090a8
addsd 0x5fb7b(%rip), %xmm0    # 0x10b8a0
mulsd 0x5d40b(%rip), %xmm0    # 0x109138
divsd 0x72a23(%rip), %xmm0    # 0x11e758
movsd %xmm0, (%r15)
ucomisd 0x5d31e(%rip), %xmm0    # 0x109060
jbe 0xabd52
movl $0x0, (%r14)
movl %ebx, %edi
callq 0x5804f
leaq 0x16cb77(%rip), %rax    # 0x2188d0
cmpq $0x80000, (%rax)        # imm = 0x80000
jne 0xabf95
movsd (%r15), %xmm0
leaq 0x260ca6(%rip), %rax    # 0x30ca18
movsd %xmm0, (%rax)
leaq 0x2614cf(%rip), %rax    # 0x30d24c
movl $0x384, (%rax)          # imm = 0x384
jmp 0xabc29
movl $0x4, %r14d
leaq 0x7a4c0(%rip), %rdi     # 0x126255
jmp 0xabfed
leaq 0x16cb83(%rip), %rax    # 0x218924
movl $0x0, (%rax)
jmp 0xabc29
movl $0x2, %r14d
leaq 0x7a4a2(%rip), %rdi     # 0x12625b
jmp 0xabfed
cmpl $0x1ff, %eax            # imm = 0x1FF
jg 0xabe03
cmpl $0x40, %eax
je 0xabe45
cmpl $0x80, %eax
je 0xabf22
cmpl $0x100, %eax            # imm = 0x100
jne 0xabe9b
callq 0xab672
leaq 0x260e1c(%rip), %rax    # 0x30cc08
jmp 0xabf2e
movl $0x8, %r14d
leaq 0x7a463(%rip), %rdi     # 0x126261
jmp 0xabfed
cmpl $0x200, %eax            # imm = 0x200
je 0xabf14
cmpl $0x400, %eax            # imm = 0x400
je 0xabf3c
cmpl $0x8000, %eax           # imm = 0x8000
je 0xabc29
jmp 0xabe9b
cmpl $0x10, %eax
je 0xabf5d
cmpl $0x20, %eax
jne 0xabe9b
callq 0xab5a9
leaq 0x260db0(%rip), %rax    # 0x30cbf0
jmp 0xabf2e
callq 0xab45a
leaq 0x260d67(%rip), %rax    # 0x30cbb8
movsd (%rax), %xmm0
divsd 0x5d24b(%rip), %xmm0    # 0x1090a8
addsd 0x5fa3b(%rip), %xmm0    # 0x10b8a0
mulsd 0x5d2cb(%rip), %xmm0    # 0x109138
divsd 0x728e3(%rip), %xmm0    # 0x11e758
movsd %xmm0, (%rax)
ucomisd 0x5d1df(%rip), %xmm0    # 0x109060
jbe 0xabc29
jmp 0xabf01
movl $0x200, %r14d           # imm = 0x200
leaq 0x7a3d1(%rip), %rdi     # 0x126267
jmp 0xabfed
movl $0x0, (%r14)
jmp 0xabc29
callq 0xab391
leaq 0x260ced(%rip), %rax    # 0x30cba0
movsd (%rax), %xmm0
divsd 0x5d1e9(%rip), %xmm0    # 0x1090a8
movsd %xmm0, (%rax)
movsd 0x5fc35(%rip), %xmm1    # 0x10bb00
ucomisd %xmm0, %xmm1
jbe 0xabc29
jmp 0xabf01
callq 0xab34e
leaq 0x260cb5(%rip), %rax    # 0x30cb98
movsd (%rax), %xmm0
divsd 0x5d1b9(%rip), %xmm0    # 0x1090a8
movsd %xmm0, (%rax)
ucomisd 0x72855(%rip), %xmm0    # 0x11e750
jbe 0xabc29
movl $0x0, (%r14)
movl %ebx, %edi
callq 0x5804f
jmp 0xabc29
callq 0xab6b5
leaq 0x260cf0(%rip), %rax    # 0x30cc10
jmp 0xabf2e
callq 0xab62f
leaq 0x260cd2(%rip), %rax    # 0x30cc00
movsd (%rax), %xmm0
divsd 0x5d16e(%rip), %xmm0    # 0x1090a8
jmp 0xabf54
callq 0xab6f8
leaq 0x260e98(%rip), %rax    # 0x30cde0
movsd (%rax), %xmm0
divsd 0x5d10c(%rip), %xmm0    # 0x109060
movsd %xmm0, (%rax)
jmp 0xabc29
movb $0x0, 0x2c04fe(%rip)    # 0x36c462
leaq 0x2c04e5(%rip), %rsi    # 0x36c450
leaq 0x29130e(%rip), %rdi    # 0x33d280
callq 0x9340
leaq 0x2619f6(%rip), %rax    # 0x30d974
orb $0x8, (%rax)
jmp 0xabc29
movl $0x20, %r14d
leaq 0x7a2da(%rip), %rdi     # 0x12626d
jmp 0xabfed
leaq 0x2612b0(%rip), %rax    # 0x30d24c
cmpl $0x0, (%rax)
jne 0xabc29
movsd (%r15), %xmm0
leaq 0x260a67(%rip), %rax    # 0x30ca18
jmp 0xabf54
movl $0x400, %r14d           # imm = 0x400
leaq 0x7a2b3(%rip), %rdi     # 0x126273
jmp 0xabfed
movl $0x80, %r14d
leaq 0x7a2ab(%rip), %rdi     # 0x12627a
jmp 0xabfed
movl $0x100, %r14d           # imm = 0x100
leaq 0x7a2a2(%rip), %rdi     # 0x126280
jmp 0xabfed
movl $0x40, %r14d
leaq 0x7a29a(%rip), %rdi     # 0x126287
movl %ebx, %esi
callq 0x60ef6
leaq 0x16c929(%rip), %rax    # 0x218924
movl %r14d, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq