// File: /workspace/github_cpp_makefile_star2_O2/Eba-M[P]E3DC-Control/RscpExampleMain.cpp
// Function: createRequestWBData(SRscpFrameBuffer*)
int createRequestWBData(SRscpFrameBuffer * frameBuffer) {
    RscpProtocol protocol;
    SRscpValue rootValue;
    if (iWBStatus<12)
    iWBStatus=12;
    
    // 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,(uint8_t)e3dc_config.wallbox);

    
    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);
    iWBSoll = WBchar6[1];   // angeforderte Ladestromstärke;
    WBToggel = WBchar6[4];
    printf(" RQ %02X %02i %02X ",WBchar6[0],WBchar6[1],WBchar6[4]);


    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:
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
movq %rsp, %rdi
callq 0x12e18
cmpl $0xb, 0x34f36(%rip)     # 0x37ba8
jg 0x2c7e
movl $0xc, 0x34f2a(%rip)     # 0x37ba8
leaq 0x10(%rsp), %rdx
andl $0x0, (%rdx)
movq %rsp, %rdi
leaq 0x31(%rsp), %rsi
callq 0x12362
leaq 0x8(%rsp), %rdx
movl $0xe040000, (%rdx)      # imm = 0xE040000
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x12362
leaq 0x8(%rsp), %rdx
movl $0xe040001, (%rdx)      # imm = 0xE040001
movb 0x341e0(%rip), %al      # 0x36e9c
leaq 0xc(%rsp), %rcx
movb %al, (%rcx)
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x12372
leaq 0x8(%rsp), %rdx
movl $0xe041010, (%rdx)      # imm = 0xE041010
movq %rsp, %rdi
leaq 0x22(%rsp), %rsi
callq 0x12362
leaq 0x8(%rsp), %rdx
movl $0xe042011, (%rdx)      # imm = 0xE042011
leaq 0xc(%rsp), %rcx
movl $0x6, (%rcx)
movq %rsp, %rdi
leaq 0x22(%rsp), %rsi
callq 0x1238e
leaq 0x8(%rsp), %rdx
movl $0xe042010, (%rdx)      # imm = 0xE042010
leaq 0x34e8f(%rip), %rcx     # 0x37bac
leaq 0x287c8(%rip), %r8      # 0x2b4ec
movq %rsp, %rdi
leaq 0x22(%rsp), %rsi
callq 0x123aa
movzbl 0x34e75(%rip), %edx     # 0x37bad
movl %edx, 0x34e76(%rip)     # 0x37bb4
movzbl 0x34e6b(%rip), %ecx     # 0x37bb0
movb %cl, 0x34e6d(%rip)      # 0x37bb8
movzbl 0x34e5a(%rip), %esi     # 0x37bac
leaq 0x287d0(%rip), %rdi     # 0x2b529
xorl %eax, %eax
callq 0x2040
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x22(%rsp), %rdx
callq 0x123bc
movq %rsp, %rdi
leaq 0x22(%rsp), %rsi
callq 0x13a7c
movq %rsp, %rdi
leaq 0x31(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x123bc
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x13a7c
movq 0x38(%rsp), %rdx
movzwl 0x36(%rsp), %ecx
movq %rsp, %rdi
pushq $0x1
popq %r8
movq %rbx, %rsi
callq 0x12ef4
movq %rsp, %rdi
leaq 0x31(%rsp), %rsi
callq 0x13a7c
movq %rsp, %rdi
callq 0x12e24
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
retq
jmp 0x2de0
jmp 0x2de0
jmp 0x2de0
jmp 0x2de0
jmp 0x2de0
jmp 0x2de0
movq %rax, %rbx
movq %rsp, %rdi
callq 0x12e24
movq %rbx, %rdi
callq 0x24d0