// File: /workspace/github_cpp_makefile_star2_O1/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 $0x50, %rsp
movq %rdi, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1599c
cmpl $0xb, 0x37c2b(%rip)     # 0x3ab88
jg 0x2f69
movl $0xc, 0x37c1f(%rip)     # 0x3ab88
leaq 0x20(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x18(%rsp), %r9
movb $0xe, (%r9)
leaq 0x32(%rsp), %r8
movw $0x0, (%r8)
leaq 0x10(%rsp), %rdi
leaq 0x41(%rsp), %rsi
xorl %ecx, %ecx
callq 0x163c8
leaq 0x18(%rsp), %rdx
movl $0xe040000, (%rdx)      # imm = 0xE040000
leaq 0xc(%rsp), %r9
movb $0xe, (%r9)
leaq 0x1c(%rsp), %r8
movw $0x0, (%r8)
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %ecx, %ecx
callq 0x163c8
leaq 0x18(%rsp), %rdx
movl $0xe040001, (%rdx)      # imm = 0xE040001
movb 0x36ea2(%rip), %al      # 0x39e7c
leaq 0xf(%rsp), %rcx
movb %al, (%rcx)
leaq 0x1c(%rsp), %r8
movw $0x1, (%r8)
leaq 0xc(%rsp), %r9
movb $0x3, (%r9)
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1658a
leaq 0x18(%rsp), %rdx
movl $0xe041010, (%rdx)      # imm = 0xE041010
leaq 0xc(%rsp), %r9
movb $0xe, (%r9)
leaq 0x1c(%rsp), %r8
movw $0x0, (%r8)
leaq 0x10(%rsp), %rdi
leaq 0x32(%rsp), %rsi
xorl %ecx, %ecx
callq 0x163c8
leaq 0x18(%rsp), %rdx
movl $0xe042011, (%rdx)      # imm = 0xE042011
leaq 0x1c(%rsp), %rcx
movl $0x6, (%rcx)
leaq 0xc(%rsp), %r8
movw $0x4, (%r8)
leaq 0xf(%rsp), %r9
movb $0x6, (%r9)
leaq 0x10(%rsp), %rdi
leaq 0x32(%rsp), %rsi
callq 0x1658a
leaq 0x18(%rsp), %rdx
movl $0xe042010, (%rdx)      # imm = 0xE042010
leaq 0x1c(%rsp), %r9
movb $0x10, (%r9)
leaq 0x37b04(%rip), %rcx     # 0x3ab8c
leaq 0x2d529(%rip), %r8      # 0x305b8
leaq 0x10(%rsp), %rdi
leaq 0x32(%rsp), %rsi
callq 0x1658a
movzbl 0x37ae8(%rip), %edx     # 0x3ab8d
movl %edx, 0x37ae9(%rip)     # 0x3ab94
movzbl 0x37ade(%rip), %ecx     # 0x3ab90
movb %cl, 0x37ae0(%rip)      # 0x3ab98
movzbl 0x37acd(%rip), %esi     # 0x3ab8c
leaq 0x2d52f(%rip), %rdi     # 0x305f5
xorl %eax, %eax
callq 0x2040
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x32(%rsp), %rdx
callq 0x151ec
leaq 0x10(%rsp), %rdi
leaq 0x32(%rsp), %rsi
callq 0x168a8
leaq 0x10(%rsp), %rdi
leaq 0x41(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x151ec
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x168a8
movq 0x48(%rsp), %rdx
movzwl 0x46(%rsp), %ecx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %r8d
callq 0x15a84
leaq 0x10(%rsp), %rdi
leaq 0x41(%rsp), %rsi
callq 0x168a8
leaq 0x10(%rsp), %rdi
callq 0x159a8
xorl %eax, %eax
addq $0x50, %rsp
popq %rbx
retq
jmp 0x315d
jmp 0x315d
jmp 0x315d
jmp 0x315d
jmp 0x315d
jmp 0x315d
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x159a8
movq %rbx, %rdi
callq 0x24a0