// File: /workspace/github_cpp_makefile_star2_O1/Eba-M[P]E3DC-Control/RscpExampleMain.cpp
// Function: shellyem_get(int&, long&)
int shellyem_get(int &power,int64_t &total){
    FILE *fp;
    char line[256];
    char EM[] = "EM";
    char EMData[] = "EMData";
    char Data[20];
    int WP_status,status;
    char path[4096];
    static time_t shellytimer = 0;
    memset(line,0,sizeof(line));
    memset(path,0,sizeof(path));
    int x2=0;
    if  (t - shellytimer >= 60)
    {
        x2 = 1;
        shellytimer = t;
    }
    else
        x2=0;

    
    
//    if (shellytimer+10<t&&strcmp(e3dc_config.shellyEM_ip,"0.0.0.0")!=0)
    if (strcmp(e3dc_config.shellyEM_ip,"0.0.0.0")!=0)
    for(int x1=0;x1<=x2;x1++)
        
    {
            fp = NULL;
            memset(Data,0,sizeof(Data));

            if (x1 == 0) strcpy(Data, EM);
            if (x1 == 1) strcpy(Data, EMData);

            sprintf(line,"curl -X POST -s -d  '{\"id\":1,\"method\":\"%s.GetStatus\",\"params\":{\"id\":0}}' http://%s/rpc",Data,e3dc_config.shellyEM_ip);
//            system(line);

            fp = popen(line, "r");

//        fp = fopen("shellyem1.txt","r");
        
            const cJSON *item = NULL;
            const cJSON *item1 = NULL;
            const cJSON *item2 = NULL;
            if (fp != NULL)
                if (fgets(path, sizeof(path), fp) != NULL)
                    
                {
//                    printf("\n%s\n",path);
                if (e3dc_config.debug)
                printf("%s\n",path);
                    
                    std::string feld;
//                    cJSON *wolf_json = cJSON_Parse(path);
                    cJSON *wolf_json = cJSON_ParseWithLength(path,sizeof(path));
                    feld = "result";
                    char * c = &feld[0];
                    item = cJSON_GetObjectItemCaseSensitive(wolf_json, c );
                    feld = "total_act_power";
                    char * d = &feld[0];
                    item1 = cJSON_GetObjectItemCaseSensitive(item, d );
//                    char * d = &feld[0];
                    feld = "total_act";
                    item2 = cJSON_GetObjectItemCaseSensitive(item, d );
                }
            status = pclose(fp);
            
        if (item1!=NULL)
        {
            power = item1->valueint;
            if (e3dc_config.debug)
                printf("power %i\n",power);
        }
        if (item2!=NULL)
        {
            total = item2->valuedouble*3600;
            if (e3dc_config.debug)
                printf("total %2.2f\n",item2->valuedouble);
            if (e3dc_config.debug)
                printf("total Ws %lld\n",total);

        }
    }
/*    power = 550;
    if (total<0)
        total = 844441200;
    else
        total = total + power;
*/
    return(-2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1158, %rsp           # imm = 0x1158
movq %rsi, 0x28(%rsp)
movq %rdi, 0x48(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x2140
leaq 0x150(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x2140
movq 0x3316e(%rip), %rax     # 0x3abb8
movq %rax, %rcx
subq 0x344b4(%rip), %rcx     # 0x3bf08
movl $0x1, 0x4(%rsp)
cmpq $0x3c, %rcx
jl 0x7a71
movq %rax, 0x3449f(%rip)     # 0x3bf08
movl $0x2, 0x4(%rsp)
movabsq $0x302e302e302e30, %rax # imm = 0x302E302E302E30
cmpq %rax, 0x31f70(%rip)     # 0x399f2
je 0x7ca7
leaq 0x50(%rsp), %r13
leaq 0x150(%rsp), %r12
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movl $0x0, 0x40(%rsp)
cmpl $0x1, %ebx
je 0x7ac0
testl %ebx, %ebx
jne 0x7ad0
movb $0x0, 0x32(%rsp)
movw $0x4d45, 0x30(%rsp)     # imm = 0x4D45
jmp 0x7ad0
movl $0x617461, 0x33(%rsp)   # imm = 0x617461
movl $0x61444d45, 0x30(%rsp) # imm = 0x61444D45
movq %r13, %rdi
leaq 0x293b9(%rip), %rsi     # 0x30e93
leaq 0x30(%rsp), %rdx
leaq 0x31f0c(%rip), %rcx     # 0x399f2
xorl %eax, %eax
callq 0x2050
movq %r13, %rdi
leaq 0x2af31(%rip), %rsi     # 0x32a28
callq 0x20a0
movq %rax, %r15
testq %rax, %rax
je 0x7c0e
movq %r12, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r15, %rdx
callq 0x2440
testq %rax, %rax
je 0x7c0e
cmpb $0x1, 0x322fd(%rip)     # 0x39e25
jne 0x7b32
movq %r12, %rdi
callq 0x2400
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movl $0x1000, %esi           # imm = 0x1000
movq %r12, %rdi
callq 0x2c8db
movq %rax, %r14
movq 0x10(%rsp), %rdx
movl $0x6, %r8d
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
leaq 0x29377(%rip), %rcx     # 0x30eea
callq 0x2410
movq %r12, %r13
movq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x2d176
movq %rax, %rbp
movq 0x10(%rsp), %rdx
movl $0xf, %r8d
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
leaq 0x2934d(%rip), %rcx     # 0x30ef1
callq 0x2410
movq 0x8(%rsp), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2d176
movq %rax, %r14
movq 0x10(%rsp), %rdx
movl $0x9, %r8d
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
leaq 0x2932c(%rip), %rcx     # 0x30f01
callq 0x2410
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2d176
movq %rax, %rbp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x7c04
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x22b0
movq %r13, %r12
leaq 0x50(%rsp), %r13
jmp 0x7c13
xorl %r14d, %r14d
xorl %ebp, %ebp
movq %r15, %rdi
callq 0x23a0
testq %r14, %r14
je 0x7c42
movl 0x28(%r14), %esi
movq 0x48(%rsp), %rax
movl %esi, (%rax)
cmpb $0x1, 0x321f3(%rip)     # 0x39e25
jne 0x7c42
leaq 0x292d0(%rip), %rdi     # 0x30f0b
xorl %eax, %eax
callq 0x2040
testq %rbp, %rbp
je 0x7c9b
movsd 0x30(%rbp), %xmm0
movapd %xmm0, %xmm1
mulsd 0x28620(%rip), %xmm1    # 0x30278
cvttsd2si %xmm1, %rax
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
cmpb $0x1, 0x321b9(%rip)     # 0x39e25
jne 0x7c7c
leaq 0x292a0(%rip), %rdi     # 0x30f15
movb $0x1, %al
callq 0x2040
cmpb $0x1, 0x321a2(%rip)     # 0x39e25
jne 0x7c9b
movq 0x28(%rsp), %rax
movq (%rax), %rsi
leaq 0x2928e(%rip), %rdi     # 0x30f22
xorl %eax, %eax
callq 0x2040
incl %ebx
cmpl %ebx, 0x4(%rsp)
jne 0x7a97
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x1158, %rsp           # imm = 0x1158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7cc2
jmp 0x7cc2
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x7ce1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x22b0
movq %rbx, %rdi
callq 0x24a0