// File: 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
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
je 0xe918c
leaq 0x18eac5(%rip), %rax    # 0x277b04
cmpl $0x8000, (%rax)         # imm = 0x8000
jne 0xe904c
jmp 0xe919b
leaq 0x18eab1(%rip), %rax    # 0x277b04
cmpl $0x10, (%rax)
jne 0xe908c
movb $0x0, 0x2e25e3(%rip)    # 0x3cb642
leaq 0x283aee(%rip), %rax    # 0x36cb54
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x283ae2(%rip), %rax    # 0x36cb54
movl %ecx, (%rax)
leaq 0x2b33e5(%rip), %rdi    # 0x39c460
leaq 0x2e25ae(%rip), %rsi    # 0x3cb630
callq 0x9350
jmp 0xe9188
leaq 0x18ea71(%rip), %rax    # 0x277b04
cmpl $0x4, (%rax)
jne 0xe90d0
callq 0xe85f0
leaq 0x282cd4(%rip), %rax    # 0x36bd78
movsd (%rax), %xmm0
movsd 0x9a020(%rip), %xmm1    # 0x1830d0
ucomisd %xmm1, %xmm0
jbe 0xe90cb
leaq 0x18ea47(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x79900
jmp 0xe9186
leaq 0x18ea2d(%rip), %rax    # 0x277b04
cmpl $0x8, (%rax)
jne 0xe912f
callq 0xe8650
leaq 0x282c98(%rip), %rax    # 0x36bd80
movsd (%rax), %xmm0
movsd 0x85f5c(%rip), %xmm1    # 0x16f050
divsd %xmm1, %xmm0
leaq 0x282c81(%rip), %rax    # 0x36bd80
movsd %xmm0, (%rax)
movsd 0x8608d(%rip), %xmm0    # 0x16f198
leaq 0x282c6e(%rip), %rax    # 0x36bd80
ucomisd (%rax), %xmm0
jbe 0xe912d
leaq 0x18e9e5(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x79900
jmp 0xe9184
leaq 0x18e9ce(%rip), %rax    # 0x277b04
cmpl $0x1, (%rax)
jne 0xe9175
callq 0xe8710
leaq 0x282c49(%rip), %rax    # 0x36bd90
movsd (%rax), %xmm0
movsd 0x85efd(%rip), %xmm1    # 0x16f050
ucomisd %xmm1, %xmm0
jbe 0xe916e
leaq 0x18e9a4(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x79900
callq 0xe8b90
jmp 0xe9182
leaq 0x18e988(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
jmp 0xe9184
jmp 0xe9186
jmp 0xe9188
jmp 0xe918a
jmp 0xe9199
leaq 0x18e971(%rip), %rax    # 0x277b04
movl $0x0, (%rax)
jmp 0xe919b
callq 0xe8bf0
leaq 0x18e961(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xe91d2
movl -0x4(%rbp), %esi
leaq 0xa04e3(%rip), %rdi     # 0x18969e
callq 0x855b0
leaq 0x18e93d(%rip), %rax    # 0x277b04
movl $0x4, (%rax)
jmp 0xe9281
leaq 0x18e92f(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xe9201
movl -0x4(%rbp), %esi
leaq 0xa04b5(%rip), %rdi     # 0x1896a2
callq 0x855b0
leaq 0x18e90b(%rip), %rax    # 0x277b04
movl $0x8, (%rax)
jmp 0xe927f
leaq 0x18e900(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xe9230
movl -0x4(%rbp), %esi
leaq 0xa048a(%rip), %rdi     # 0x1896a6
callq 0x855b0
leaq 0x18e8dc(%rip), %rax    # 0x277b04
movl $0x1, (%rax)
jmp 0xe927d
leaq 0x18e8d1(%rip), %rax    # 0x277b08
movl (%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0xe925f
movl -0x4(%rbp), %esi
leaq 0xa045f(%rip), %rdi     # 0x1896aa
callq 0x855b0
leaq 0x18e8ad(%rip), %rax    # 0x277b04
movl $0x10, (%rax)
jmp 0xe927b
movl -0x4(%rbp), %esi
leaq 0xa043d(%rip), %rdi     # 0x1896a6
callq 0x855b0
leaq 0x18e88f(%rip), %rax    # 0x277b04
movl $0x1, (%rax)
jmp 0xe927d
jmp 0xe927f
jmp 0xe9281
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)