// File: /workspace/github_cpp_makefile_star2_O3/rellla[P]E3DC-Rscp/RscpMain.cpp
// Function: createRequest(SRscpFrameBuffer*, int)
int createRequest(SRscpFrameBuffer * frameBuffer, int requests)
{
    RscpProtocol protocol;
    SRscpValue rootValue;
    // The root container is create with the TAG ID 0 which is not used by any device.
    protocol.createContainerValue(&rootValue, 0);

    //---------------------------------------------------------------------------------------------------------
    // Create a request frame
    //---------------------------------------------------------------------------------------------------------
    printf("\nRequest data:\n");

    // request power data information
    if (requests & TAG_EMS) {
	protocol.appendValue(&rootValue, TAG_EMS_REQ_POWER_PV);
	protocol.appendValue(&rootValue, TAG_EMS_REQ_POWER_BAT);
	protocol.appendValue(&rootValue, TAG_EMS_REQ_POWER_HOME);
	protocol.appendValue(&rootValue, TAG_EMS_REQ_POWER_GRID);
	protocol.appendValue(&rootValue, TAG_EMS_REQ_POWER_ADD);
	protocol.appendValue(&rootValue, TAG_EMS_REQ_GET_POWER_SETTINGS);
	protocol.appendValue(&rootValue, TAG_EMS_REQ_STATUS);
	protocol.appendValue(&rootValue, TAG_EMS_REQ_MODE);
    }

    // request idle periods information
    if (requests & TAG_GET_IDLE_PERIODS) {
	protocol.appendValue(&rootValue, TAG_EMS_REQ_GET_IDLE_PERIODS);
    }

    // request battery information
    if (requests & TAG_BATTERY) {
	SRscpValue batteryContainer;
	protocol.createContainerValue(&batteryContainer, TAG_BAT_REQ_DATA);
	protocol.appendValue(&batteryContainer, TAG_BAT_INDEX, (uint8_t) 0);
	protocol.appendValue(&batteryContainer, TAG_BAT_REQ_RSOC);
	protocol.appendValue(&batteryContainer, TAG_BAT_REQ_MODULE_VOLTAGE);
	protocol.appendValue(&batteryContainer, TAG_BAT_REQ_CURRENT);
	protocol.appendValue(&batteryContainer, TAG_BAT_REQ_STATUS_CODE);
	protocol.appendValue(&batteryContainer, TAG_BAT_REQ_ERROR_CODE);
	// append sub-container to root container
	protocol.appendValue(&rootValue, batteryContainer);
	// free memory of sub-container as it is now copied to rootValue
	protocol.destroyValueData(batteryContainer);
    }

    // request some more power data information
    if (requests & TAG_WEATHER_ENABLE) {
	SRscpValue powerContainer;
	uint8_t enable = !!(requests & TAG_WEATHER_ENABLE_F);
	protocol.createContainerValue(&powerContainer,
				      TAG_EMS_REQ_SET_POWER_SETTINGS);
	protocol.appendValue(&powerContainer,
			     TAG_EMS_WEATHER_REGULATED_CHARGE_ENABLED,
			     enable);
	protocol.appendValue(&rootValue, powerContainer);
	protocol.destroyValueData(powerContainer);
    }

    // request setting idle periods
    // this is WIP and some example values are hardcoded for now
    // this is not useable for productive environments atm
    if (requests & TAG_SET_IDLE_PERIODS) {
	SRscpValue setTimeContainer;
	protocol.createContainerValue(&setTimeContainer,
				      TAG_EMS_REQ_SET_IDLE_PERIODS);

	    SRscpValue setDayContainer;
	    protocol.createContainerValue(&setDayContainer,
					  TAG_EMS_IDLE_PERIOD);
	    protocol.appendValue(&setDayContainer,
				 TAG_EMS_IDLE_PERIOD_TYPE, (uint8_t)LOAD);
	    protocol.appendValue(&setDayContainer,
				 TAG_EMS_IDLE_PERIOD_DAY, (uint8_t)TUESDAY);
	    protocol.appendValue(&setDayContainer,
				 TAG_EMS_IDLE_PERIOD_ACTIVE, (bool)ACTIVE);

		SRscpValue setStartContainer;
		protocol.createContainerValue(&setStartContainer,
					  TAG_EMS_IDLE_PERIOD_START);
		protocol.appendValue(&setStartContainer,
				 TAG_EMS_IDLE_PERIOD_MINUTE, (uint8_t)00);
		protocol.appendValue(&setStartContainer,
				 TAG_EMS_IDLE_PERIOD_HOUR, (uint8_t)11);
		protocol.appendValue(&setDayContainer, setStartContainer);
		protocol.destroyValueData(setStartContainer);

		SRscpValue setStopContainer;
		protocol.createContainerValue(&setStopContainer,
					  TAG_EMS_IDLE_PERIOD_END);
		protocol.appendValue(&setStopContainer,
				 TAG_EMS_IDLE_PERIOD_MINUTE, (uint8_t)42);
		protocol.appendValue(&setStopContainer,
				 TAG_EMS_IDLE_PERIOD_HOUR, (uint8_t)12);
		protocol.appendValue(&setDayContainer, setStopContainer);
		protocol.destroyValueData(setStopContainer);

	    protocol.appendValue(&setTimeContainer, setDayContainer);
	    protocol.destroyValueData(setDayContainer);

	protocol.appendValue(&rootValue, setTimeContainer);
	protocol.destroyValueData(setTimeContainer);
    }

    // create buffer frame to send data to the S10
    protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true);	// true to calculate CRC on for transfer
    // the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
    protocol.destroyValueData(rootValue);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x70, %rsp
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x49e0
leaq 0x40(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x20(%rsp), %r9
movb $0xe, (%r9)
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x61(%rsp), %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x53ae
leaq 0xdfd7(%rip), %rdi      # 0x1064f
callq 0x21c0
testb $0x2, %bpl
je 0x2807
leaq 0x40(%rsp), %rdx
movl $0x1000001, (%rdx)      # imm = 0x1000001
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x40(%rsp), %rdx
movl $0x1000002, (%rdx)      # imm = 0x1000002
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x40(%rsp), %rdx
movl $0x1000003, (%rdx)      # imm = 0x1000003
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x40(%rsp), %rdx
movl $0x1000004, (%rdx)      # imm = 0x1000004
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x40(%rsp), %rdx
movl $0x1000005, (%rdx)      # imm = 0x1000005
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x40(%rsp), %rdx
movl $0x100008b, (%rdx)      # imm = 0x100008B
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x40(%rsp), %rdx
movl $0x1000040, (%rdx)      # imm = 0x1000040
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x40(%rsp), %rdx
movl $0x1000011, (%rdx)      # imm = 0x1000011
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
testb $0x4, %bpl
je 0x283d
leaq 0x40(%rsp), %rdx
movl $0x1000080, (%rdx)      # imm = 0x1000080
leaq 0x30(%rsp), %r8
movw $0x0, (%r8)
leaq 0x20(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
testb $0x1, %bpl
je 0x29c0
leaq 0x30(%rsp), %rdx
movl $0x3040000, (%rdx)      # imm = 0x3040000
leaq 0x50(%rsp), %r9
movb $0xe, (%r9)
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x53ae
leaq 0x30(%rsp), %rdx
movl $0x3040001, (%rdx)      # imm = 0x3040001
leaq 0x18(%rsp), %rcx
movb $0x0, (%rcx)
leaq 0x20(%rsp), %r8
movw $0x1, (%r8)
leaq 0x50(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x5570
leaq 0x30(%rsp), %rdx
movl $0x3000001, (%rdx)      # imm = 0x3000001
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x50(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x30(%rsp), %rdx
movl $0x3000002, (%rdx)      # imm = 0x3000002
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x50(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x30(%rsp), %rdx
movl $0x3000003, (%rdx)      # imm = 0x3000003
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x50(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x30(%rsp), %rdx
movl $0x300000a, (%rdx)      # imm = 0x300000A
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x50(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x30(%rsp), %rdx
movl $0x300000b, (%rdx)      # imm = 0x300000B
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x50(%rsp), %r9
movb $0x0, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5570
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x46e4
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x588e
testb $0x8, %bpl
je 0x2a5b
movl %ebp, %eax
shrb $0x4, %al
andb $0x1, %al
movb %al, 0x18(%rsp)
leaq 0x30(%rsp), %rdx
movl $0x100008c, (%rdx)      # imm = 0x100008C
leaq 0x50(%rsp), %r9
movb $0xe, (%r9)
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x53ae
leaq 0x30(%rsp), %rdx
movl $0x1000105, (%rdx)      # imm = 0x1000105
leaq 0x20(%rsp), %r8
movw $0x1, (%r8)
leaq 0x50(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x18(%rsp), %rcx
callq 0x5570
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x46e4
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x588e
testb $0x20, %bpl
je 0x2d2b
leaq 0x30(%rsp), %rdx
movl $0x1000081, (%rdx)      # imm = 0x1000081
leaq 0x50(%rsp), %r9
movb $0xe, (%r9)
leaq 0x20(%rsp), %r8
movw $0x0, (%r8)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
xorl %ecx, %ecx
callq 0x53ae
leaq 0x20(%rsp), %rdx
movl $0x1000082, (%rdx)      # imm = 0x1000082
leaq 0x18(%rsp), %r9
movb $0xe, (%r9)
leaq 0x50(%rsp), %r8
movw $0x0, (%r8)
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
xorl %ecx, %ecx
callq 0x53ae
leaq 0x20(%rsp), %rdx
movl $0x1000083, (%rdx)      # imm = 0x1000083
leaq 0x16(%rsp), %rcx
movb $0x0, (%rcx)
leaq 0x50(%rsp), %r8
movw $0x1, (%r8)
leaq 0x18(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5570
leaq 0x20(%rsp), %rdx
movl $0x1000084, (%rdx)      # imm = 0x1000084
leaq 0x16(%rsp), %rcx
movb $0x1, (%rcx)
leaq 0x50(%rsp), %r8
movw $0x1, (%r8)
leaq 0x18(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5570
leaq 0x20(%rsp), %rdx
movl $0x1000089, (%rdx)      # imm = 0x1000089
movb $0x1, %al
leaq 0x16(%rsp), %rcx
movb %al, (%rcx)
leaq 0x50(%rsp), %r8
movw $0x1, (%r8)
leaq 0x18(%rsp), %r9
movb %al, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5570
leaq 0x50(%rsp), %rdx
movl $0x1000085, (%rdx)      # imm = 0x1000085
leaq 0x16(%rsp), %r9
movb $0xe, (%r9)
leaq 0x18(%rsp), %r8
movw $0x0, (%r8)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %ecx, %ecx
callq 0x53ae
leaq 0x50(%rsp), %rdx
movl $0x1000088, (%rdx)      # imm = 0x1000088
leaq 0x15(%rsp), %rcx
movb $0x0, (%rcx)
leaq 0x18(%rsp), %r8
movw $0x1, (%r8)
leaq 0x16(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5570
leaq 0x50(%rsp), %rdx
movl $0x1000087, (%rdx)      # imm = 0x1000087
leaq 0x15(%rsp), %rcx
movb $0xb, (%rcx)
leaq 0x18(%rsp), %r8
movw $0x1, (%r8)
leaq 0x16(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5570
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x46e4
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x588e
leaq 0x18(%rsp), %rdx
movl $0x1000086, (%rdx)      # imm = 0x1000086
leaq 0x15(%rsp), %r9
movb $0xe, (%r9)
leaq 0x16(%rsp), %r8
movw $0x0, (%r8)
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
xorl %ecx, %ecx
callq 0x53ae
leaq 0x18(%rsp), %rdx
movl $0x1000088, (%rdx)      # imm = 0x1000088
leaq 0x1f(%rsp), %rcx
movb $0x2a, (%rcx)
leaq 0x16(%rsp), %r8
movw $0x1, (%r8)
leaq 0x15(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x5570
leaq 0x18(%rsp), %rdx
movl $0x1000087, (%rdx)      # imm = 0x1000087
leaq 0x1f(%rsp), %rcx
movb $0xc, (%rcx)
leaq 0x16(%rsp), %r8
movw $0x1, (%r8)
leaq 0x15(%rsp), %r9
movb $0x3, (%r9)
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x5570
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x46e4
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x588e
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x46e4
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x588e
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x46e4
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x588e
movq 0x68(%rsp), %rdx
movzwl 0x66(%rsp), %ecx
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %r8d
callq 0x4ac8
leaq 0x8(%rsp), %rdi
leaq 0x61(%rsp), %rsi
callq 0x588e
leaq 0x8(%rsp), %rdi
callq 0x49ec
xorl %eax, %eax
addq $0x70, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
jmp 0x2db0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x49ec
movq %rbx, %rdi
callq 0x2240