// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: decode_dog_enviro(unsigned int, int)
void decode_dog_enviro(unsigned port, int i)
{
   // decode dogtaian.com values then poll for the next reading

   if(i) {
      if(last_enviro == ENV_ID) {  // device ID
         goto poll_next_dog_enviro;
      }
      else if(last_enviro == ENV_SN) {
         enviro_field[UNIT_LEN] = 0;
         have_info |= MFG_INFO;
         strcpy(enviro_sn, enviro_field);
      }
      else if(last_enviro == ENV_HUMID) {
         parse_humidity();
if(humidity > 110.0) {
   last_enviro = 0;
   drain_port(port);
}
      }
      else if(last_enviro == ENV_PRESS) {
         parse_pressure();
         pressure /= 100.0;    // convert to millibars
if(pressure < 200.0) {
   last_enviro = 0;
   drain_port(port);
}
      }
      else if(last_enviro == ENV_TEMP1) {
         parse_temp1();
if(tc1 > 100.0) {
   last_enviro = 0;
   drain_port(port);
}
         save_temp1();
      }
      else {  // unknown reading type
         last_enviro = 0;
      }
   }
   else last_enviro = 0;

   poll_next_dog_enviro: // get the next reading
   next_enviro_poll();   // get what reading type to request

   if(next_enviro & ENV_HUMID) {
      send_enviro_cmd("GH\r", port);
      last_enviro = ENV_HUMID;
   }
   else if(next_enviro & ENV_PRESS) {
      send_enviro_cmd("GP\r", port);
      last_enviro = ENV_PRESS;
   }
   else if(next_enviro & ENV_TEMP1) {
      send_enviro_cmd("GT\r", port);
      last_enviro = ENV_TEMP1;
   }
   else if(next_enviro & ENV_SN) {
      send_enviro_cmd("GN\r", port);
      last_enviro = ENV_SN;
   }
   else {  // should never happen
      send_enviro_cmd("GT\r", port);
      last_enviro = ENV_TEMP1;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %edi, %ebx
testl %esi, %esi
je 0x9bf3c
leaq 0x166a3b(%rip), %r14    # 0x202924
movl (%r14), %eax
cmpl $0x1, %eax
je 0x9bfa4
cmpl $0x4, %eax
je 0x9bf4b
cmpl $0x8, %eax
je 0x9bf67
cmpl $0x8000, %eax           # imm = 0x8000
je 0x9bfce
cmpl $0x10, %eax
jne 0x9bf9e
movb $0x0, 0x2ba548(%rip)    # 0x356462
leaq 0x2ba52f(%rip), %rsi    # 0x356450
leaq 0x25ba4c(%rip), %rax    # 0x2f7974
orb $0x8, (%rax)
leaq 0x28b34e(%rip), %rdi    # 0x327280
callq 0x9330
jmp 0x9bfce
leaq 0x1669e1(%rip), %rax    # 0x202924
andl $0x0, (%rax)
jmp 0x9bfce
callq 0x9b823
leaq 0x25ac41(%rip), %rax    # 0x2f6b98
movsd (%rax), %xmm0
ucomisd 0x6c815(%rip), %xmm0    # 0x108778
ja 0x9bf91
jmp 0x9bfce
callq 0x9b864
leaq 0x25ac2d(%rip), %rax    # 0x2f6ba0
movsd (%rax), %xmm0
divsd 0x570e1(%rip), %xmm0    # 0xf3060
movsd %xmm0, (%rax)
movsd 0x59bed(%rip), %xmm1    # 0xf5b78
ucomisd %xmm0, %xmm1
jbe 0x9bfce
andl $0x0, (%r14)
movl %ebx, %edi
callq 0x5142f
jmp 0x9bfce
andl $0x0, (%r14)
jmp 0x9bfce
callq 0x9b8e6
leaq 0x25ac00(%rip), %rax    # 0x2f6bb0
movsd (%rax), %xmm0
ucomisd 0x570a4(%rip), %xmm0    # 0xf3060
jbe 0x9bfc9
andl $0x0, (%r14)
movl %ebx, %edi
callq 0x5142f
callq 0x9bbf2
callq 0x9bc4f
leaq 0x16694e(%rip), %rax    # 0x202928
movl (%rax), %eax
testb $0x4, %al
jne 0x9c009
testb $0x8, %al
jne 0x9c016
testb $0x1, %al
jne 0x9c023
testb $0x10, %al
leaq 0x7427b(%rip), %rax     # 0x11026c
leaq 0x74278(%rip), %rdi     # 0x110270
cmoveq %rax, %rdi
pushq $0x1
popq %rax
pushq $0x10
popq %r14
cmovel %eax, %r14d
jmp 0x9c02e
pushq $0x4
popq %r14
leaq 0x74250(%rip), %rdi     # 0x110264
jmp 0x9c02e
pushq $0x8
popq %r14
leaq 0x74247(%rip), %rdi     # 0x110268
jmp 0x9c02e
pushq $0x1
popq %r14
leaq 0x7423e(%rip), %rdi     # 0x11026c
movl %ebx, %esi
callq 0x593cc
leaq 0x1668e8(%rip), %rax    # 0x202924
movl %r14d, (%rax)
popq %rbx
popq %r14
popq %rbp
retq