// File: 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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x200b0
cmpl $0xc, 0x6cd3e(%rip)     # 0x6fbc8
jge 0x2e96
movl $0xc, 0x6cd32(%rip)     # 0x6fbc8
movl $0x0, 0x54(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
leaq 0x54(%rsp), %rdx
callq 0x1c8c0
jmp 0x2eb4
movl $0xe040000, 0x20(%rsp)  # imm = 0xE040000
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x1c8c0
jmp 0x2ed2
movl $0xe040001, 0x1c(%rsp)  # imm = 0xE040001
movb 0x6bfd8(%rip), %al      # 0x6eeb8
movb %al, 0x1b(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x1b(%rsp), %rcx
callq 0x1c900
jmp 0x2eff
movl $0xe041010, 0x14(%rsp)  # imm = 0xE041010
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x1c8c0
jmp 0x2f1d
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 0x1c950
jmp 0x2f48
movl $0xe042010, 0x8(%rsp)   # imm = 0xE042010
leaq 0x6cc75(%rip), %rcx     # 0x6fbcc
leaq 0x5d382(%rip), %r8      # 0x602e0
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x1c9a0
jmp 0x2f74
movzbl 0x6cc52(%rip), %eax     # 0x6fbcd
movl %eax, 0x6cc53(%rip)     # 0x6fbd4
movb 0x6cc49(%rip), %al      # 0x6fbd0
movb %al, 0x6cc4b(%rip)      # 0x6fbd8
movzbl 0x6cc38(%rip), %esi     # 0x6fbcc
movzbl 0x6cc32(%rip), %edx     # 0x6fbcd
movzbl 0x6cc2e(%rip), %ecx     # 0x6fbd0
leaq 0x5d393(%rip), %rdi     # 0x6033c
xorl %eax, %eax
callq 0x2040
jmp 0x2fb2
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x26(%rsp), %rdx
callq 0x1c9f0
jmp 0x2fc8
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
callq 0x1cac0
jmp 0x2fd9
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
leaq 0x35(%rsp), %rdx
callq 0x1c9f0
jmp 0x2fef
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
callq 0x1cac0
jmp 0x3000
movq 0x70(%rsp), %rsi
movq 0x60(%rsp), %rdx
movzwl 0x5e(%rsp), %ecx
leaq 0x68(%rsp), %rdi
movl $0x1, %r8d
callq 0x20300
jmp 0x3021
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
callq 0x1cac0
jmp 0x3032
leaq 0x68(%rsp), %rdi
callq 0x200d0
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 0x200d0
movq 0x48(%rsp), %rdi
callq 0x24c0
nopw %cs:(%rax,%rax)