// File: /workspace/github_cpp_makefile_star2_O3/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, 0x2c639a(%rip)    # 0x372244
je 0xabf54
callq 0xaba1b
movl $0x0, 0x2c6385(%rip)    # 0x372244
leaq 0x16ca62(%rip), %rax    # 0x218928
movl (%rax), %eax
testb $0x1, %al
jne 0xabf42
testb $0x4, %al
jne 0xac00f
testb $0x2, %al
jne 0xac033
testb $0x8, %al
jne 0xac078
btl $0x9, %eax
jb 0xac110
testb $0x20, %al
jne 0xac20d
btl $0xa, %eax
jb 0xac23a
testb %al, %al
js 0xac249
btl $0x8, %eax
jb 0xac258
testb $0x40, %al
jne 0xac267
testb $0x10, %al
leaq 0x7a40c(%rip), %rax     # 0x12632f
leaq 0x7a444(%rip), %rdi     # 0x12636e
cmoveq %rax, %rdi
movl $0x1, %eax
movl $0x10, %r14d
cmovel %eax, %r14d
jmp 0xac274
movl $0x1, %r14d
leaq 0x7a3e0(%rip), %rdi     # 0x12632f
jmp 0xac274
testl %esi, %esi
je 0xac021
leaq 0x16c9c1(%rip), %r14    # 0x218924
movl (%r14), %eax
cmpl $0x3f, %eax
jg 0xac045
leal -0x1(%rax), %ecx
cmpl $0x7, %ecx
ja 0xac0ad
leaq 0x73c9e(%rip), %rax     # 0x11fc20
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
callq 0xab69a
leaq 0x260c19(%rip), %r15    # 0x30cbb0
movsd (%r15), %xmm0
divsd 0x5d104(%rip), %xmm0    # 0x1090a8
addsd 0x5f904(%rip), %xmm0    # 0x10b8b0
mulsd 0x5d184(%rip), %xmm0    # 0x109138
divsd 0x7284c(%rip), %xmm0    # 0x11e808
movsd %xmm0, (%r15)
ucomisd 0x5d097(%rip), %xmm0    # 0x109060
jbe 0xabfd9
movl $0x0, (%r14)
movl %ebx, %edi
callq 0x5802f
leaq 0x16c8f0(%rip), %rax    # 0x2188d0
cmpq $0x80000, (%rax)        # imm = 0x80000
jne 0xac21c
movsd (%r15), %xmm0
leaq 0x260a1f(%rip), %rax    # 0x30ca18
movsd %xmm0, (%rax)
leaq 0x261248(%rip), %rax    # 0x30d24c
movl $0x384, (%rax)          # imm = 0x384
jmp 0xabeb0
movl $0x4, %r14d
leaq 0x7a319(%rip), %rdi     # 0x126335
jmp 0xac274
leaq 0x16c8fc(%rip), %rax    # 0x218924
movl $0x0, (%rax)
jmp 0xabeb0
movl $0x2, %r14d
leaq 0x7a2fb(%rip), %rdi     # 0x12633b
jmp 0xac274
cmpl $0x1ff, %eax            # imm = 0x1FF
jg 0xac08a
cmpl $0x40, %eax
je 0xac0cc
cmpl $0x80, %eax
je 0xac1a9
cmpl $0x100, %eax            # imm = 0x100
jne 0xac122
callq 0xab8f5
leaq 0x260b95(%rip), %rax    # 0x30cc08
jmp 0xac1b5
movl $0x8, %r14d
leaq 0x7a2bc(%rip), %rdi     # 0x126341
jmp 0xac274
cmpl $0x200, %eax            # imm = 0x200
je 0xac19b
cmpl $0x400, %eax            # imm = 0x400
je 0xac1c3
cmpl $0x8000, %eax           # imm = 0x8000
je 0xabeb0
jmp 0xac122
cmpl $0x10, %eax
je 0xac1e4
cmpl $0x20, %eax
jne 0xac122
callq 0xab82c
leaq 0x260b29(%rip), %rax    # 0x30cbf0
jmp 0xac1b5
callq 0xab6dd
leaq 0x260ae0(%rip), %rax    # 0x30cbb8
movsd (%rax), %xmm0
divsd 0x5cfc4(%rip), %xmm0    # 0x1090a8
addsd 0x5f7c4(%rip), %xmm0    # 0x10b8b0
mulsd 0x5d044(%rip), %xmm0    # 0x109138
divsd 0x7270c(%rip), %xmm0    # 0x11e808
movsd %xmm0, (%rax)
ucomisd 0x5cf58(%rip), %xmm0    # 0x109060
jbe 0xabeb0
jmp 0xac188
movl $0x200, %r14d           # imm = 0x200
leaq 0x7a22a(%rip), %rdi     # 0x126347
jmp 0xac274
movl $0x0, (%r14)
jmp 0xabeb0
callq 0xab614
leaq 0x260a66(%rip), %rax    # 0x30cba0
movsd (%rax), %xmm0
divsd 0x5cf62(%rip), %xmm0    # 0x1090a8
movsd %xmm0, (%rax)
movsd 0x5f98e(%rip), %xmm1    # 0x10bae0
ucomisd %xmm0, %xmm1
jbe 0xabeb0
jmp 0xac188
callq 0xab5d1
leaq 0x260a2e(%rip), %rax    # 0x30cb98
movsd (%rax), %xmm0
divsd 0x5cf32(%rip), %xmm0    # 0x1090a8
movsd %xmm0, (%rax)
ucomisd 0x7267e(%rip), %xmm0    # 0x11e800
jbe 0xabeb0
movl $0x0, (%r14)
movl %ebx, %edi
callq 0x5802f
jmp 0xabeb0
callq 0xab938
leaq 0x260a69(%rip), %rax    # 0x30cc10
jmp 0xac1b5
callq 0xab8b2
leaq 0x260a4b(%rip), %rax    # 0x30cc00
movsd (%rax), %xmm0
divsd 0x5cee7(%rip), %xmm0    # 0x1090a8
jmp 0xac1db
callq 0xab97b
leaq 0x260c11(%rip), %rax    # 0x30cde0
movsd (%rax), %xmm0
divsd 0x5ce85(%rip), %xmm0    # 0x109060
movsd %xmm0, (%rax)
jmp 0xabeb0
movb $0x0, 0x2c0277(%rip)    # 0x36c462
leaq 0x2c025e(%rip), %rsi    # 0x36c450
leaq 0x291087(%rip), %rdi    # 0x33d280
callq 0x9340
leaq 0x26176f(%rip), %rax    # 0x30d974
orb $0x8, (%rax)
jmp 0xabeb0
movl $0x20, %r14d
leaq 0x7a133(%rip), %rdi     # 0x12634d
jmp 0xac274
leaq 0x261029(%rip), %rax    # 0x30d24c
cmpl $0x0, (%rax)
jne 0xabeb0
movsd (%r15), %xmm0
leaq 0x2607e0(%rip), %rax    # 0x30ca18
jmp 0xac1db
movl $0x400, %r14d           # imm = 0x400
leaq 0x7a10c(%rip), %rdi     # 0x126353
jmp 0xac274
movl $0x80, %r14d
leaq 0x7a104(%rip), %rdi     # 0x12635a
jmp 0xac274
movl $0x100, %r14d           # imm = 0x100
leaq 0x7a0fb(%rip), %rdi     # 0x126360
jmp 0xac274
movl $0x40, %r14d
leaq 0x7a0f3(%rip), %rdi     # 0x126367
movl %ebx, %esi
callq 0x60f7b
leaq 0x16c6a2(%rip), %rax    # 0x218924
movl %r14d, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq