// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
movl %edi, %ebx
cmpl $0x0, 0x2c01f0(%rip)    # 0x35c244
je 0x9c0f5
callq 0x9bc4f
andl $0x0, 0x2c01de(%rip)    # 0x35c244
leaq 0x1668bb(%rip), %rax    # 0x202928
movl (%rax), %eax
testb $0x1, %al
jne 0x9c0e5
testb $0x4, %al
jne 0x9c18e
testb $0x2, %al
jne 0x9c1ad
testb $0x8, %al
jne 0x9c220
btl $0x9, %eax
jb 0x9c274
testb $0x20, %al
jne 0x9c35e
btl $0xa, %eax
jb 0x9c36b
testb %al, %al
js 0x9c37a
btl $0x8, %eax
jb 0x9c389
testb $0x40, %al
jne 0x9c398
testb $0x10, %al
leaq 0x741aa(%rip), %rax     # 0x110274
leaq 0x741e2(%rip), %rdi     # 0x1102b3
cmoveq %rax, %rdi
pushq $0x1
popq %rax
pushq $0x10
popq %r14
cmovel %eax, %r14d
jmp 0x9c3a3
pushq $0x1
popq %r14
leaq 0x74184(%rip), %rdi     # 0x110274
jmp 0x9c3a3
testl %esi, %esi
je 0x9c19e
leaq 0x166820(%rip), %r14    # 0x202924
movl (%r14), %eax
leal -0x1(%rax), %ecx
cmpl $0x7, %ecx
jbe 0x9c1bd
cmpl $0x8000, %eax           # imm = 0x8000
je 0x9c05a
cmpl $0x20, %eax
je 0x9c33d
cmpl $0x40, %eax
je 0x9c230
cmpl $0x80, %eax
je 0x9c32f
cmpl $0x100, %eax            # imm = 0x100
je 0x9c2f9
cmpl $0x200, %eax            # imm = 0x200
je 0x9c307
cmpl $0x400, %eax            # imm = 0x400
je 0x9c315
cmpl $0x10, %eax
jne 0x9c286
movb $0x0, 0x2ba2f6(%rip)    # 0x356462
leaq 0x2ba2dd(%rip), %rsi    # 0x356450
leaq 0x28b106(%rip), %rdi    # 0x327280
callq 0x9330
leaq 0x25b7ee(%rip), %rax    # 0x2f7974
orb $0x8, (%rax)
jmp 0x9c05a
pushq $0x4
popq %r14
leaq 0x740e1(%rip), %rdi     # 0x11027a
jmp 0x9c3a3
leaq 0x16677f(%rip), %rax    # 0x202924
andl $0x0, (%rax)
jmp 0x9c05a
pushq $0x2
popq %r14
leaq 0x740c8(%rip), %rdi     # 0x110280
jmp 0x9c3a3
leaq 0x6d9a0(%rip), %rax     # 0x109b64
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
callq 0x9b8e6
leaq 0x25a9d7(%rip), %rax    # 0x2f6bb0
movsd (%rax), %xmm0
divsd 0x56ec3(%rip), %xmm0    # 0xf30a8
addsd 0x5973b(%rip), %xmm0    # 0xf5928
mulsd 0x56f4b(%rip), %xmm0    # 0xf3140
divsd 0x6c583(%rip), %xmm0    # 0x108780
movsd %xmm0, (%rax)
ucomisd 0x56e57(%rip), %xmm0    # 0xf3060
jbe 0x9c216
andl $0x0, (%r14)
movl %ebx, %edi
callq 0x5142f
callq 0x9bbf2
jmp 0x9c05a
pushq $0x8
popq %r14
leaq 0x7405b(%rip), %rdi     # 0x110286
jmp 0x9c3a3
callq 0x9b927
leaq 0x25a97c(%rip), %rax    # 0x2f6bb8
movsd (%rax), %xmm0
divsd 0x56e60(%rip), %xmm0    # 0xf30a8
addsd 0x596d8(%rip), %xmm0    # 0xf5928
mulsd 0x56ee8(%rip), %xmm0    # 0xf3140
divsd 0x6c520(%rip), %xmm0    # 0x108780
movsd %xmm0, (%rax)
ucomisd 0x56df4(%rip), %xmm0    # 0xf3060
jbe 0x9c05a
jmp 0x9c2e9
movl $0x200, %r14d           # imm = 0x200
leaq 0x7400b(%rip), %rdi     # 0x11028c
jmp 0x9c3a3
andl $0x0, (%r14)
jmp 0x9c05a
callq 0x9b864
leaq 0x25a905(%rip), %rax    # 0x2f6ba0
movsd (%rax), %xmm0
divsd 0x56e01(%rip), %xmm0    # 0xf30a8
movsd %xmm0, (%rax)
movsd 0x598c5(%rip), %xmm1    # 0xf5b78
ucomisd %xmm0, %xmm1
jbe 0x9c05a
jmp 0x9c2e9
callq 0x9b823
leaq 0x25a8cd(%rip), %rax    # 0x2f6b98
movsd (%rax), %xmm0
divsd 0x56dd1(%rip), %xmm0    # 0xf30a8
movsd %xmm0, (%rax)
ucomisd 0x6c495(%rip), %xmm0    # 0x108778
jbe 0x9c05a
andl $0x0, (%r14)
movl %ebx, %edi
callq 0x5142f
jmp 0x9c05a
callq 0x9bb2f
leaq 0x25a903(%rip), %rax    # 0x2f6c08
jmp 0x9c349
callq 0x9bb70
leaq 0x25a8fd(%rip), %rax    # 0x2f6c10
jmp 0x9c349
callq 0x9bbb1
leaq 0x25aabf(%rip), %rax    # 0x2f6de0
movsd (%rax), %xmm0
divsd 0x56d33(%rip), %xmm0    # 0xf3060
jmp 0x9c355
callq 0x9baee
leaq 0x25a8c5(%rip), %rax    # 0x2f6c00
jmp 0x9c349
callq 0x9ba6c
leaq 0x25a8a7(%rip), %rax    # 0x2f6bf0
movsd (%rax), %xmm0
divsd 0x56d53(%rip), %xmm0    # 0xf30a8
movsd %xmm0, (%rax)
jmp 0x9c05a
pushq $0x20
popq %r14
leaq 0x73f29(%rip), %rdi     # 0x110292
jmp 0x9c3a3
movl $0x400, %r14d           # imm = 0x400
leaq 0x73f20(%rip), %rdi     # 0x110298
jmp 0x9c3a3
movl $0x80, %r14d
leaq 0x73f18(%rip), %rdi     # 0x11029f
jmp 0x9c3a3
movl $0x100, %r14d           # imm = 0x100
leaq 0x73f0f(%rip), %rdi     # 0x1102a5
jmp 0x9c3a3
pushq $0x40
popq %r14
leaq 0x73f09(%rip), %rdi     # 0x1102ac
movl %ebx, %esi
callq 0x593cc
leaq 0x166573(%rip), %rax    # 0x202924
movl %r14d, (%rax)
popq %rbx
popq %r14
popq %rbp
retq