// File: bummelbaerchen[P]e3dc/RscpExampleMain.cpp
// Function: createRequestWBData(SRscpFrameBuffer*)
int createRequestWBData(SRscpFrameBuffer * frameBuffer) {
    RscpProtocol protocol;
    SRscpValue rootValue;

    iWBStatus=7;
    
    // The root container is create with the TAG ID 0 which is not used by any device.
    protocol.createContainerValue(&rootValue, 0);
    
    // request Power Meter information
    SRscpValue WBContainer;
    SRscpValue WB2Container;

    // request Wallbox data

    protocol.createContainerValue(&WBContainer, TAG_WB_REQ_DATA) ;
    // add index 0 to select first wallbox
    protocol.appendValue(&WBContainer, TAG_WB_INDEX,0);

    
    protocol.createContainerValue(&WB2Container, TAG_WB_REQ_SET_EXTERN);
    protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA_LEN,6);
    protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA,WBchar6,iWBLen);

    protocol.appendValue(&WBContainer, WB2Container);
    // free memory of sub-container as it is now copied to rootValue
    protocol.destroyValueData(WB2Container);

    
// append sub-container to root container
    protocol.appendValue(&rootValue, WBContainer);
//    protocol.appendValue(&rootValue, WB2Container);
    // free memory of sub-container as it is now copied to rootValue
    protocol.destroyValueData(WBContainer);
    
    // 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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
leaq 0x68(%rsp), %rdi
movq %rdi, (%rsp)
callq 0xadf0
movq (%rsp), %rdi
movl $0x7, 0x23f2f(%rip)     # 0x267e4
movl $0x0, 0x54(%rsp)
leaq 0x59(%rsp), %rsi
leaq 0x54(%rsp), %rdx
callq 0x8d50
jmp 0x28ce
movl $0xe040000, 0x20(%rsp)  # imm = 0xE040000
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x8d50
jmp 0x28ec
movl $0xe040001, 0x1c(%rsp)  # imm = 0xE040001
movl $0x0, 0x18(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
callq 0x8d90
jmp 0x2917
movl $0xe041010, 0x14(%rsp)  # imm = 0xE041010
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x8d50
jmp 0x2935
movl $0xe042011, 0x10(%rsp)  # imm = 0xE042011
movl $0x6, 0xc(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x8d90
jmp 0x2960
movl $0xe042010, 0x8(%rsp)   # imm = 0xE042010
leaq 0x23e79(%rip), %rcx     # 0x267e8
leaq 0x1e79a(%rip), %r8      # 0x21110
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x8f80
jmp 0x298c
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x26(%rsp), %rdx
callq 0x8de0
jmp 0x29a2
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
callq 0x8eb0
jmp 0x29b3
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
leaq 0x35(%rsp), %rdx
callq 0x8de0
jmp 0x29c9
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
callq 0x8eb0
jmp 0x29da
movq 0x70(%rsp), %rsi
movq 0x60(%rsp), %rdx
movzwl 0x5e(%rsp), %ecx
leaq 0x68(%rsp), %rdi
movl $0x1, %r8d
callq 0xb040
jmp 0x29fb
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
callq 0x8eb0
jmp 0x2a0c
leaq 0x68(%rsp), %rdi
callq 0xae10
xorl %eax, %eax
addq $0x78, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
leaq 0x68(%rsp), %rdi
callq 0xae10
movq 0x48(%rsp), %rdi
callq 0x2300
nop