// File: /workspace/github_cpp_makefile_star2_O2/rellla[P]E3DC-Rscp/RscpMain.cpp
// Function: handleResponseEMSGetIdlePeriods(RscpProtocol*, SRscpValue*, idle_period_t*)
int
handleResponseEMSGetIdlePeriods(RscpProtocol * protocol,
				SRscpValue * emsData,
				idle_period_t *periods)
{
    // check each idle periods sub tag
    switch (emsData->tag) {
    case TAG_EMS_IDLE_PERIOD:{
	    std::vector < SRscpValue > idleData =
		protocol->getValueAsContainer(emsData);
	    // check each idle period sub tag
	    for (size_t j = 0; j < idleData.size(); ++j) {
		if (idleData[j].dataType == RSCP::eTypeError) {
		    // handle error for example access denied errors
		    uint32_t uiErrorCode =
			protocol->getValueAsUInt32(&idleData[j]);
		    printf("Tag 0x%08X received error code %u.\n",
			   idleData[j].tag, uiErrorCode);
		    return -1;
		}
		switch (idleData[j].tag) {
		case TAG_EMS_IDLE_PERIOD_TYPE:{
			periods->type = protocol->getValueAsUChar8(&idleData[j]);
			break;
		    }
		case TAG_EMS_IDLE_PERIOD_DAY:{
			periods->day = protocol->getValueAsUChar8(&idleData[j]);
			break;
		    }
		case TAG_EMS_IDLE_PERIOD_ACTIVE:{
			periods->active = protocol->getValueAsUChar8(&idleData[j]);
			break;
		    }
		case TAG_EMS_IDLE_PERIOD_START:{
			std::vector < SRscpValue >
			    periodData =
			    protocol->getValueAsContainer(&idleData[j]);
			// check each idle period start sub tag
			for (size_t k = 0; k < periodData.size(); ++k) {
			    if (periodData[k].dataType == RSCP::eTypeError) {
				// handle error for example access denied errors
				uint32_t
				    uiErrorCode =
				    protocol->getValueAsUInt32(&periodData
							       [k]);
				printf
				    ("Tag 0x%08X received error code %u.\n",
				     periodData[k].tag, uiErrorCode);
				return -1;
			    }
			    switch (periodData[k].tag) {
			    case TAG_EMS_IDLE_PERIOD_HOUR:{
				    periods->start.hour =
					protocol->getValueAsUChar8
					(&periodData[k]);
				    break;
				}
			    case TAG_EMS_IDLE_PERIOD_MINUTE:{
				    periods->start.minute =
					protocol->getValueAsUChar8
					(&periodData[k]);
				    break;
				}
			    default:
				// default behaviour
				uint8_t unknown =
				    protocol->getValueAsUChar8(&periodData
							       [k]);
				printf("Unknown period tag %08X -> %i.\n",
				       periodData[k].tag, unknown);
				break;
			    }
			}
			break;
		    }
		case TAG_EMS_IDLE_PERIOD_END:{
			std::vector < SRscpValue >
			    periodData =
			    protocol->getValueAsContainer(&idleData[j]);
			// check each idle period stop sub tag
			for (size_t k = 0; k < periodData.size(); ++k) {
			    if (periodData[k].dataType == RSCP::eTypeError) {
				// handle error for example access denied errors
				uint32_t
				    uiErrorCode =
				    protocol->getValueAsUInt32(&periodData
							       [k]);
				printf
				    ("Tag 0x%08X received error code %u.\n",
				     periodData[k].tag, uiErrorCode);
				return -1;
			    }
			    switch (periodData[k].tag) {
			    case TAG_EMS_IDLE_PERIOD_HOUR:{
				    periods->stop.hour =
					protocol->getValueAsUChar8
					(&periodData[k]);
				    break;
				}
			    case TAG_EMS_IDLE_PERIOD_MINUTE:{
				    periods->stop.minute =
					protocol->getValueAsUChar8
					(&periodData[k]);
				    break;
				}
			    default:
				// default behaviour
				uint8_t unknown =
				    protocol->getValueAsUChar8(&periodData
							       [k]);
				printf("Unknown period tag %08X -> %i.\n",
				       periodData[k].tag, unknown);
				break;
			    }
			}
			break;
		    }
		}
	    }
	    // print idle periods summary
	    if (periods->day == MONDAY)
		printf("Monday:     \t");
	    else if (periods->day == TUESDAY)
		printf("Tuesday:    \t");
	    else if (periods->day == WEDNESDAY)
		printf("Wednesday:  \t");
	    else if (periods->day == THURSDAY)
		printf("Thursday:   \t");
	    else if (periods->day == FRIDAY)
		printf("Friday:     \t");
	    else if (periods->day == SATURDAY)
		printf("Saturday:   \t");
	    else if (periods->day == SUNDAY)
		printf("Sunday:     \t");
	    else
		printf("Unknown day:\t");

	    if (periods->type == LOAD)
		printf("Ladesperre ");
	    else if (periods->type == UNLOAD)
		printf("Entladesperre ");
	    else
		printf("Unknown type!");

	    if (periods->active == ACTIVE)
		printf
		    ("aktiv von %02i:%02i - %02i:%02i",
		     periods->start.hour, periods->start.minute, periods->stop.hour, periods->stop.minute);
	    else if (periods->active == INACTIVE)
		printf
		    ("inaktiv (%02i:%02i - %02i:%02i)",
		     periods->start.hour, periods->start.minute, periods->stop.hour, periods->stop.minute);
	    else
		printf("Activity unknown! ");
	    printf("\n");
	    break;
	}
    default:
	// default behaviour
	uint8_t unknown = protocol->getValueAsUChar8(emsData);
	printf("Unknown ems tag %08X -> %i.\n", emsData->tag, unknown);
	break;
    }
    protocol->destroyValueData(emsData);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpl $0x1000082, (%rsi)      # imm = 0x1000082
movq %rsi, 0x38(%rsp)
jne 0x2ce7
movq %rdx, %r15
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3f18
leaq 0x2(%r15), %rax
movq %rax, 0x40(%rsp)
leaq 0x1(%r15), %rax
movq %rax, 0x18(%rsp)
movl $0xfeffff7d, %r12d      # imm = 0xFEFFFF7D
xorl %ebp, %ebp
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0xf
popq %rsi
idivq %rsi
cmpq %rax, %rbp
jae 0x2c14
imulq $0xf, %rbp, %r14
leaq (%rcx,%r14), %rdx
cmpb $-0x1, 0x4(%rcx,%r14)
je 0x2bbd
movl (%rdx), %eax
addl %r12d, %eax
cmpl $0x6, %eax
ja 0x2bb5
leaq 0xc5c5(%rip), %rcx      # 0xf004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %r15, %r14
jmpq *%rax
movq 0x18(%rsp), %r14
jmp 0x2b6e
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x3f18
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0xf
popq %rsi
idivq %rsi
movq %rax, %r14
cmpq %rax, %r12
jae 0x2b65
leaq (%rcx,%r13), %rsi
cmpb $-0x1, 0x4(%rcx,%r13)
je 0x2b7e
movl (%rsi), %r14d
movq %rbx, %rdi
callq 0x4178
cmpl $0x1000088, %r14d       # imm = 0x1000088
je 0x2ab9
cmpl $0x1000087, %r14d       # imm = 0x1000087
jne 0x2abf
movb %al, 0x3(%r15)
jmp 0x2ad8
movb %al, 0x4(%r15)
jmp 0x2ad8
movq (%rsp), %rcx
movl (%rcx,%r13), %esi
movzbl %al, %edx
leaq 0xc603(%rip), %rdi      # 0xf0d4
xorl %eax, %eax
callq 0x2040
incq %r12
addq $0xf, %r13
jmp 0x2a66
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x3f18
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0xf
popq %rsi
idivq %rsi
movq %rax, %r14
cmpq %rax, %r12
jae 0x2b65
leaq (%rcx,%r13), %rsi
cmpb $-0x1, 0x4(%rcx,%r13)
je 0x2b7e
movl (%rsi), %r14d
movq %rbx, %rdi
callq 0x4178
cmpl $0x1000088, %r14d       # imm = 0x1000088
je 0x2b3d
cmpl $0x1000087, %r14d       # imm = 0x1000087
jne 0x2b43
movb %al, 0x5(%r15)
jmp 0x2b5c
movb %al, 0x6(%r15)
jmp 0x2b5c
movq (%rsp), %rcx
movl (%rcx,%r13), %esi
movzbl %al, %edx
leaq 0xc57f(%rip), %rdi      # 0xf0d4
xorl %eax, %eax
callq 0x2040
incq %r12
addq $0xf, %r13
jmp 0x2af2
pushq $0x6
jmp 0x2ba0
movq 0x40(%rsp), %r14
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x4178
movb %al, (%r14)
jmp 0x2bb5
movq %rbx, %rdi
callq 0x413a
movq (%rsp), %rcx
movl (%rcx,%r13), %esi
leaq 0xc51b(%rip), %rdi      # 0xf0b0
movl %eax, %edx
xorl %eax, %eax
callq 0x2040
pushq $0x1
popq %r13
movq %rsp, %rdi
callq 0x4050
cmpq %r14, %r12
movl $0xfeffff7d, %r12d      # imm = 0xFEFFFF7D
jb 0x2bee
incq %rbp
jmp 0x29f8
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x413a
leaq 0x20(%rsp), %rbx
movq (%rbx), %rcx
movl (%rcx,%r14), %esi
leaq 0xc4d5(%rip), %rdi      # 0xf0b0
movl %eax, %edx
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
callq 0x4050
jmp 0x2c02
leaq 0x20(%rsp), %rdi
callq 0x4050
cmpl $0x1, %r13d
jne 0x2cda
pushq $-0x1
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
cmpq $0x6, %rax
ja 0x2c32
leaq 0xc453(%rip), %rcx      # 0xf07c
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
jmp 0x2c39
leaq 0xc51d(%rip), %rdi      # 0xf156
xorl %eax, %eax
callq 0x2040
movb (%r15), %al
cmpb $0x1, %al
leaq 0xc524(%rip), %rcx      # 0xf170
leaq 0xc52c(%rip), %rdx      # 0xf17f
cmoveq %rcx, %rdx
testb %al, %al
leaq 0xc504(%rip), %rdi      # 0xf164
cmovneq %rdx, %rdi
xorl %eax, %eax
callq 0x2040
movzbl 0x2(%r15), %eax
testl %eax, %eax
je 0x2c96
cmpl $0x1, %eax
jne 0x2cba
movzbl 0x3(%r15), %esi
movzbl 0x4(%r15), %edx
movzbl 0x5(%r15), %ecx
movzbl 0x6(%r15), %r8d
leaq 0xc4f9(%rip), %rdi      # 0xf18d
jmp 0x2cb1
movzbl 0x3(%r15), %esi
movzbl 0x4(%r15), %edx
movzbl 0x5(%r15), %ecx
movzbl 0x6(%r15), %r8d
leaq 0xc4fc(%rip), %rdi      # 0xf1ad
xorl %eax, %eax
callq 0x2040
jmp 0x2cc8
leaq 0xc50c(%rip), %rdi      # 0xf1cd
xorl %eax, %eax
callq 0x2040
pushq $0xa
popq %rdi
callq 0x2200
leaq 0x20(%rsp), %rdi
callq 0x4050
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
callq 0x4fe4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4178
movl (%r14), %esi
movzbl %al, %edx
leaq 0xc4e1(%rip), %rdi      # 0xf1e0
xorl %eax, %eax
callq 0x2040
jmp 0x2cda
jmp 0x2d0a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4050
movq %rbx, %rdi
callq 0x2280