// File: /workspace/github_cpp_makefile_star2_O1/rellla[P]E3DC-Rscp/RscpMain.cpp
// Function: handleResponseValue(RscpProtocol*, SRscpValue*, int*)
int handleResponseValue(RscpProtocol * protocol, SRscpValue * response,
			int *isAuthRequest)
{
    // check if any of the response has the error flag set and react accordingly
    if (response->dataType == RSCP::eTypeError) {
	// handle error for example access denied errors
	uint32_t uiErrorCode = protocol->getValueAsUInt32(response);
	printf("Tag 0x%08X received error code %u.\n",
	       response->tag, uiErrorCode);
	return -1;
    }
    // check the SRscpValue TAG to detect which response it is
    switch (response->tag) {
    case TAG_RSCP_AUTHENTICATION:{
	    // It is possible to check the response->dataType value to detect correct data type
	    // and call the correct function. If data type is known,
	    // the correct function can be called directly like in this case.
	    uint8_t ucAccessLevel = protocol->getValueAsUChar8(response);
	    if (ucAccessLevel > 0) {
		iAuthenticated = 1;
		*isAuthRequest = 1;
	    }
	    printf("RSCP authentitication level %i\n", ucAccessLevel);
	    break;
	}
    case TAG_EMS_POWER_PV:{
	    // response for TAG_EMS_REQ_POWER_PV
	    int32_t iPower = protocol->getValueAsInt32(response);
	    printf("EMS PV power is %i W\n", iPower);
	    break;
	}
    case TAG_EMS_POWER_BAT:{
	    // response for TAG_EMS_REQ_POWER_BAT
	    int32_t iPower = protocol->getValueAsInt32(response);
	    printf("EMS BAT power is %i W\n", iPower);
	    break;
	}
    case TAG_EMS_POWER_HOME:{
	    // response for TAG_EMS_REQ_POWER_HOME
	    int32_t iPower = protocol->getValueAsInt32(response);
	    printf("EMS house power is %i W\n", iPower);
	    break;
	}
    case TAG_EMS_POWER_GRID:{
	    // response for TAG_EMS_REQ_POWER_GRID
	    int32_t iPower = protocol->getValueAsInt32(response);
	    printf("EMS grid power is %i W\n", iPower);
	    break;
	}
    case TAG_EMS_POWER_ADD:{
	    // response for TAG_EMS_REQ_POWER_ADD
	    int32_t iPower = protocol->getValueAsInt32(response);
	    printf("EMS add power meter power is %i W\n", iPower);
	    break;
	}
    case TAG_BAT_DATA:{
	    // response for TAG_REQ_BAT_DATA
	    std::vector < SRscpValue > batteryData =
		protocol->getValueAsContainer(response);
	    for (size_t i = 0; i < batteryData.size(); ++i) {
		if (batteryData[i].dataType == RSCP::eTypeError) {
		    // handle error for example access denied errors
		    uint32_t uiErrorCode =
			protocol->getValueAsUInt32(&batteryData[i]);
		    printf("Tag 0x%08X received error code %u.\n",
			   batteryData[i].tag, uiErrorCode);
		    return -1;
		}
		handleResponseBatData(protocol, &batteryData[i]);
	    }
	    protocol->destroyValueData(batteryData);
	    break;
	}
    case TAG_EMS_GET_POWER_SETTINGS:{
	    // response for TAG_EMS_REQ_GET_POWER_SETTINGS
	    std::vector < SRscpValue > emsData =
		protocol->getValueAsContainer(response);
	    for (size_t i = 0; i < emsData.size(); ++i) {
		if (emsData[i].dataType == RSCP::eTypeError) {
		    // handle error for example access denied errors
		    uint32_t uiErrorCode =
			protocol->getValueAsUInt32(&emsData[i]);
		    printf("Tag 0x%08X received error code %u.\n",
			   emsData[i].tag, uiErrorCode);
		    return -1;
		}
		// check each ems power settings sub tag
		switch (emsData[i].tag) {
		case TAG_EMS_POWER_LIMITS_USED:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf("EMS power limits used is %i.\n",
			       weather_en);
			break;
		    }
		case TAG_EMS_MAX_CHARGE_POWER:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf("EMS max charge power is %i.\n",
			       weather_en);
			break;
		    }
		case TAG_EMS_MAX_DISCHARGE_POWER:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf("EMS max discharge power is %i.\n",
			       weather_en);
			break;
		    }
		case TAG_EMS_DISCHARGE_START_POWER:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf("EMS discharge start power is %i.\n",
			       weather_en);
			break;
		    }
		case TAG_EMS_POWERSAVE_ENABLED:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf("EMS powersave enabled is %i.\n",
			       weather_en);
			break;
		    }
		case TAG_EMS_WEATHER_REGULATED_CHARGE_ENABLED:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf
			    ("EMS weather regulated charge enabled is %i.\n",
			     weather_en);
			break;
		    }
		case TAG_EMS_UNKNOWN:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf("EMS unknown is %i.\n", weather_en);
			break;
		    }
		    // ...
		default:
		    // default behaviour
		    printf("Unknown ems tag %08X\n", emsData[i].tag);
		    break;
		}
	    }
	    protocol->destroyValueData(emsData);
	    break;
	}
    case TAG_EMS_SET_POWER_SETTINGS:{
	    // resposne for TAG_EMS_REQ_SET_POWER_SETTINGS
	    std::vector < SRscpValue > emsData =
		protocol->getValueAsContainer(response);
	    for (size_t i = 0; i < emsData.size(); ++i) {
		if (emsData[i].dataType == RSCP::eTypeError) {
		    // handle error for example access denied errors
		    uint32_t uiErrorCode =
			protocol->getValueAsUInt32(&emsData[i]);
		    printf("Tag 0x%08X received error code %u.\n",
			   emsData[i].tag, uiErrorCode);
		    return -1;
		}
		// check each battery sub tag
		switch (emsData[i].tag) {
		case TAG_EMS_RES_WEATHER_REGULATED_CHARGE_ENABLED:{
			int8_t weather_en =
			    protocol->getValueAsInt32(&emsData[i]);
			printf
			    ("Weather regulated charge response: %i\n",
			     weather_en);
			break;
		    }
		default:
		    // default behaviour
		    printf("Unknown ems tag %08X\n", emsData[i].tag);
		    break;
		}
	    }
	    protocol->destroyValueData(emsData);
	    break;
	}
    case TAG_EMS_GET_IDLE_PERIODS:{
	    // resposne for TAG_EMS_REQ_GET_IDLE_PERIODS
	    std::vector < SRscpValue > emsData =
		protocol->getValueAsContainer(response);
	    idle_period_t periods[14];
	    for (size_t i = 0; i < emsData.size(); ++i) {
		if (emsData[i].dataType == RSCP::eTypeError) {
		    // handle error for example access denied errors
		    uint32_t uiErrorCode =
			protocol->getValueAsUInt32(&emsData[i]);
		    printf("Tag 0x%08X received error code %u.\n",
			   emsData[i].tag, uiErrorCode);
		    return -1;
		}
		handleResponseEMSGetIdlePeriods(protocol, &emsData[i], &periods[i]);
	    }
	    break;
	}
    default:
	// default behavior
	uint8_t unknown = protocol->getValueAsUChar8(response);
	printf("Unknown tag %08X -> %i.\n", response->tag, unknown);
	break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r14
cmpb $-0x1, 0x4(%rsi)
je 0x34e9
movq %rdi, %rbx
movl (%r14), %eax
cmpl $0x180008a, %eax        # imm = 0x180008A
jg 0x3517
cmpl $0x1800080, %eax        # imm = 0x1800080
jne 0x3a9e
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4940
movq (%r15), %r14
cmpq %r14, 0x8(%r15)
je 0x3a01
leaq 0x20(%rsp), %r15
xorl %r12d, %r12d
movabsq $-0x1111111111111111, %r13 # imm = 0xEEEEEEEEEEEEEEEF
xorl %ebp, %ebp
cmpb $-0x1, 0x4(%r14,%r12)
je 0x390f
addq %r12, %r14
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2d55
incq %rbp
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %rax
subq %r14, %rax
imulq %r13, %rax
addq $0x7, %r15
addq $0xf, %r12
cmpq %rax, %rbp
jb 0x34a6
jmp 0x3a01
xorl %edx, %edx
testq %r14, %r14
je 0x3954
movq 0x7(%r14), %rsi
testq %rsi, %rsi
je 0x3954
movzwl 0x5(%r14), %edx
cmpq $0x4, %rdx
jb 0x393f
movl (%rsi), %edx
jmp 0x3954
cmpl $0x180008b, %eax        # imm = 0x180008B
je 0x358d
cmpl $0x180008c, %eax        # imm = 0x180008C
je 0x3843
cmpl $0x3840000, %eax        # imm = 0x3840000
jne 0x3aaf
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4940
movq (%r15), %r14
cmpq %r14, 0x8(%r15)
je 0x396a
cmpb $-0x1, 0x4(%r14)
jne 0x3aba
xorl %edx, %edx
testq %r14, %r14
je 0x3a27
movq 0x7(%r14), %rsi
testq %rsi, %rsi
je 0x3a27
movzwl 0x5(%r14), %edx
cmpq $0x4, %rdx
jb 0x3a12
movl (%rsi), %edx
jmp 0x3a27
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4940
movq (%r15), %r12
cmpq %r12, 0x8(%r15)
je 0x3831
movl $0x7, %r14d
movabsq $-0x1111111111111111, %r15 # imm = 0xEEEEEEEEEEEEEEEF
leaq 0xca9c(%rip), %r13      # 0x10060
xorl %ebp, %ebp
cmpb $-0x1, -0x3(%r12,%r14)
je 0x397c
movl -0x7(%r12,%r14), %esi
leal -0x1000100(%rsi), %eax
cmpl $0x6, %eax
ja 0x3680
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x36f8
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x3783
movl (%rsi), %eax
jmp 0x3799
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x36ec
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x3714
movl (%rsi), %eax
jmp 0x372a
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x36f0
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x3739
movl (%rsi), %eax
jmp 0x374f
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x36f4
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x375e
movl (%rsi), %eax
jmp 0x3774
leaq 0xcdbc(%rip), %rdi      # 0x10443
jmp 0x3809
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x36ff
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x37a5
movl (%rsi), %eax
jmp 0x37bb
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x3706
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x37c7
movl (%rsi), %eax
jmp 0x37dd
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x370d
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x37e9
movl (%rsi), %eax
jmp 0x37ff
xorl %eax, %eax
jmp 0x372a
xorl %eax, %eax
jmp 0x374f
xorl %eax, %eax
jmp 0x3774
xorl %eax, %eax
jmp 0x3799
xorl %eax, %eax
jmp 0x37bb
xorl %eax, %eax
jmp 0x37dd
xorl %eax, %eax
jmp 0x37ff
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xccb0(%rip), %rdi      # 0x103e4
jmp 0x3809
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xcc49(%rip), %rdi      # 0x103a2
jmp 0x3809
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xcc44(%rip), %rdi      # 0x103c2
jmp 0x3809
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xcbc4(%rip), %rdi      # 0x10367
jmp 0x3809
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xcbc0(%rip), %rdi      # 0x10385
jmp 0x3809
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xcc1b(%rip), %rdi      # 0x10402
jmp 0x3809
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xcc26(%rip), %rdi      # 0x1042f
xorl %eax, %eax
callq 0x2040
incq %rbp
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %rax
subq %r12, %rax
imulq %r15, %rax
addq $0xf, %r14
cmpq %rax, %rbp
jb 0x35c6
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x554e
jmp 0x3a70
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4940
movq (%r15), %rbp
cmpq %rbp, 0x8(%r15)
je 0x38fd
movl $0x7, %r13d
movabsq $-0x1111111111111111, %r15 # imm = 0xEEEEEEEEEEEEEEEF
leaq 0xcbc9(%rip), %r12      # 0x10443
xorl %r14d, %r14d
cmpb $-0x1, -0x3(%rbp,%r13)
je 0x39ab
movl -0x7(%rbp,%r13), %esi
cmpl $0x1800105, %esi        # imm = 0x1800105
jne 0x38b0
movq (%rbp,%r13), %rsi
testq %rsi, %rsi
je 0x38b5
movzwl -0x2(%rbp,%r13), %edx
cmpq $0x4, %rdx
jb 0x38b9
movl (%rsi), %eax
jmp 0x38cf
movq %r12, %rdi
jmp 0x38d9
xorl %eax, %eax
jmp 0x38cf
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x20f0
movl 0x8(%rsp), %eax
movsbl %al, %esi
leaq 0xcb80(%rip), %rdi      # 0x10459
xorl %eax, %eax
callq 0x2040
incq %r14
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %rax
subq %rbp, %rax
imulq %r15, %rax
addq $0xf, %r13
cmpq %rax, %r14
jb 0x387d
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x554e
jmp 0x3a70
xorl %edx, %edx
testq %r14, %r14
je 0x39ef
movq 0x7(%r14,%r12), %rsi
testq %rsi, %rsi
je 0x39ef
movzwl 0x5(%r14,%r12), %edx
cmpq $0x4, %rdx
jb 0x39d7
movl (%rsi), %edx
jmp 0x39ef
leaq 0x20(%rsp), %rbx
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x20f0
movl (%rbx), %edx
movl (%r14), %esi
leaq 0xc752(%rip), %rdi      # 0x100b0
xorl %eax, %eax
callq 0x2040
jmp 0x3a87
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x554e
jmp 0x3a70
xorl %edx, %edx
testq %r12, %r12
je 0x3a41
movq (%r12,%r14), %rsi
testq %rsi, %rsi
je 0x3a41
movzwl -0x2(%r12,%r14), %edx
cmpq $0x4, %rdx
jb 0x3a2c
movl (%rsi), %edx
jmp 0x3a41
xorl %edx, %edx
testq %rbp, %rbp
je 0x3a5d
movq (%rbp,%r13), %rsi
testq %rsi, %rsi
je 0x3a5d
movzwl -0x2(%rbp,%r13), %edx
cmpq $0x4, %rdx
jb 0x3a48
movl (%rsi), %edx
jmp 0x3a5d
leaq 0x84(%rsp), %rbx
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x20f0
movl (%rbx), %edx
movl (%r14,%r12), %esi
leaq 0xc6b6(%rip), %rdi      # 0x100b0
xorl %eax, %eax
callq 0x2040
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x3a87
movq 0x18(%rsp), %rsi
jmp 0x3a7f
leaq 0x8(%rsp), %rbx
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x20f0
movl (%rbx), %edx
movl (%r14), %esi
jmp 0x3a62
leaq 0x8(%rsp), %rbx
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x20f0
movl (%rbx), %edx
movl -0x7(%r12,%r14), %esi
jmp 0x3a62
leaq 0x8(%rsp), %rbx
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x20f0
movl (%rbx), %edx
movl -0x7(%rbp,%r13), %esi
leaq 0xc647(%rip), %rdi      # 0x100b0
xorl %eax, %eax
callq 0x2040
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3a87
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x800001, %eax         # imm = 0x800001
je 0x3ac5
addl $0xfe7fffff, %eax       # imm = 0xFE7FFFFF
cmpl $0x4, %eax
jbe 0x3adf
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3373
movq %rdx, %r15
movq 0x7(%r14), %rsi
testq %rsi, %rsi
je 0x3b06
movzwl 0x5(%r14), %edx
testq %rdx, %rdx
je 0x3b0a
movb (%rsi), %al
jmp 0x3b1c
leaq 0xc566(%rip), %rcx      # 0x1004c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a60
leaq 0xc7e5(%rip), %rdi      # 0x102e6
jmp 0x3b88
xorl %eax, %eax
jmp 0x3b1c
leaq 0x20(%rsp), %rbx
movb $0x0, (%rbx)
movq %rbx, %rdi
callq 0x20f0
movb (%rbx), %al
testb %al, %al
je 0x3b2e
movb $0x1, 0x10b41(%rip)     # 0x14668
movl $0x1, (%r15)
movzbl %al, %esi
leaq 0xc78e(%rip), %rdi      # 0x102c6
jmp 0x3b8a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a60
leaq 0xc7b0(%rip), %rdi      # 0x102fc
jmp 0x3b88
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a60
leaq 0xc7b3(%rip), %rdi      # 0x10313
jmp 0x3b88
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a60
leaq 0xc7b8(%rip), %rdi      # 0x1032c
jmp 0x3b88
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a60
leaq 0xc7bc(%rip), %rdi      # 0x10344
movl %eax, %esi
xorl %eax, %eax
callq 0x2040
jmp 0x3b97
jmp 0x3b97
jmp 0x3b97
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3bc5
movq 0x30(%rsp), %rsi
jmp 0x3bbd
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x3bc5
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x2240