// File: rellla[P]E3DC-Rscp/RscpMain.cpp
// Function: handleResponseBatData(RscpProtocol*, SRscpValue*)
int
handleResponseBatData(RscpProtocol * protocol,
		      SRscpValue * batteryData)
{
    uint8_t ucBatteryIndex = 0;
    // check each battery sub tag
    switch (batteryData->tag) {
    case TAG_BAT_INDEX:{
	ucBatteryIndex = protocol->getValueAsUChar8(batteryData);
	printf("Battery Index is %i\n", ucBatteryIndex);
	break;
    }
    case TAG_BAT_RSOC:{
	// response for TAG_BAT_REQ_RSOC
	float fSOC = protocol->getValueAsFloat32(batteryData);
	printf("Battery SOC is %0.1f %%\n", fSOC);
	break;
    }
    case TAG_BAT_MODULE_VOLTAGE:{
	// response for TAG_BAT_REQ_MODULE_VOLTAGE
	float fVoltage = protocol->getValueAsFloat32(batteryData);
	printf("Battery total voltage is %0.1f V\n",
	       fVoltage);
	break;
    }
    case TAG_BAT_CURRENT:{
	// response for TAG_BAT_REQ_CURRENT
	float fVoltage =
	    protocol->getValueAsFloat32(batteryData);
	printf("Battery current is %0.1f A\n", fVoltage);
	break;
    }
    case TAG_BAT_STATUS_CODE:{
	// response for TAG_BAT_REQ_STATUS_CODE
	uint32_t uiErrorCode =
	    protocol->getValueAsUInt32(batteryData);
	printf("Battery status code is 0x%08X\n",
	       uiErrorCode);
	break;
    }
    case TAG_BAT_ERROR_CODE:{
	// response for TAG_BAT_REQ_ERROR_CODE
	uint32_t uiErrorCode =
	    protocol->getValueAsUInt32(batteryData);
	printf("Battery error code is 0x%08X\n",
	       uiErrorCode);
	break;
    }
    default:
	uint8_t unknown =
    protocol->getValueAsUChar8(batteryData);
    printf("Unknown battery tag %08X -> %i\n", batteryData->tag, unknown);
    break;
    }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movb $0x0, 0x27(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x8(%rsp)
subl $0x3040001, %eax        # imm = 0x3040001
je 0x385b
jmp 0x3807
movl 0x8(%rsp), %eax
subl $0x3800001, %eax        # imm = 0x3800001
je 0x3886
jmp 0x3814
movl 0x8(%rsp), %eax
subl $0x3800002, %eax        # imm = 0x3800002
je 0x38b8
jmp 0x3825
movl 0x8(%rsp), %eax
subl $0x3800003, %eax        # imm = 0x3800003
je 0x38ea
jmp 0x3836
movl 0x8(%rsp), %eax
subl $0x380000a, %eax        # imm = 0x380000A
je 0x3919
jmp 0x3847
movl 0x8(%rsp), %eax
subl $0x380000b, %eax        # imm = 0x380000B
je 0x3940
jmp 0x3967
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x5ef0
movb %al, 0x27(%rsp)
movzbl 0x27(%rsp), %esi
leaq 0x1c990(%rip), %rdi     # 0x2020a
movb $0x0, %al
callq 0x2040
jmp 0x3994
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x5f80
movss %xmm0, 0x20(%rsp)
movss 0x20(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1c973(%rip), %rdi     # 0x2021f
movb $0x1, %al
callq 0x2040
jmp 0x3994
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x5f80
movss %xmm0, 0x1c(%rsp)
movss 0x1c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1c95a(%rip), %rdi     # 0x20238
movb $0x1, %al
callq 0x2040
jmp 0x3994
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x5f80
movss %xmm0, 0x18(%rsp)
movss 0x18(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1c94a(%rip), %rdi     # 0x2025a
movb $0x1, %al
callq 0x2040
jmp 0x3994
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x5ec0
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %esi
leaq 0x1c93f(%rip), %rdi     # 0x20276
movb $0x0, %al
callq 0x2040
jmp 0x3994
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x5ec0
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %esi
leaq 0x1c937(%rip), %rdi     # 0x20295
movb $0x0, %al
callq 0x2040
jmp 0x3994
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x5ef0
movb %al, 0xf(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %esi
movzbl 0xf(%rsp), %edx
leaq 0x1c926(%rip), %rdi     # 0x202b3
movb $0x0, %al
callq 0x2040
ud2
nopw %cs:(%rax,%rax)