// File: Eba-M[P]E3DC-Control/RscpExampleMain.cpp
// Function: createRequestWBData2(SRscpFrameBuffer*)
int createRequestWBData2(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_PARAM_1);
    protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA_LEN,8);
    protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA,WBchar,8);
    iWBSoll = WBchar[2];   // angeforderte Ladestromstärke;


    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, 0x6cb3e(%rip)     # 0x6fbc8
jge 0x3096
movl $0xc, 0x6cb32(%rip)     # 0x6fbc8
movl $0x0, 0x54(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
leaq 0x54(%rsp), %rdx
callq 0x1c8c0
jmp 0x30b4
movl $0xe040000, 0x20(%rsp)  # imm = 0xE040000
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x1c8c0
jmp 0x30d2
movl $0xe040001, 0x1c(%rsp)  # imm = 0xE040001
movb 0x6bdd8(%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 0x30ff
movl $0xe041018, 0x14(%rsp)  # imm = 0xE041018
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x1c8c0
jmp 0x311d
movl $0xe042011, 0x10(%rsp)  # imm = 0xE042011
movl $0x8, 0xc(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x1c950
jmp 0x3148
movl $0xe042010, 0x8(%rsp)   # imm = 0xE042010
movw $0x8, 0x6(%rsp)
leaq 0x6ca7b(%rip), %rcx     # 0x6fbd9
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x6(%rsp), %r8
callq 0x1c9a0
jmp 0x3179
movzbl 0x6ca5b(%rip), %eax     # 0x6fbdb
movl %eax, 0x6ca4e(%rip)     # 0x6fbd4
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
leaq 0x26(%rsp), %rdx
callq 0x1c9f0
jmp 0x319c
leaq 0x68(%rsp), %rdi
leaq 0x26(%rsp), %rsi
callq 0x1cac0
jmp 0x31ad
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
leaq 0x35(%rsp), %rdx
callq 0x1c9f0
jmp 0x31c3
leaq 0x68(%rsp), %rdi
leaq 0x35(%rsp), %rsi
callq 0x1cac0
jmp 0x31d4
movq 0x70(%rsp), %rsi
movq 0x60(%rsp), %rdx
movzwl 0x5e(%rsp), %ecx
leaq 0x68(%rsp), %rdi
movl $0x1, %r8d
callq 0x20300
jmp 0x31f5
leaq 0x68(%rsp), %rdi
leaq 0x59(%rsp), %rsi
callq 0x1cac0
jmp 0x3206
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
nopl (%rax)