// File: 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:
subq $0x198, %rsp            # imm = 0x198
movq %rdi, 0x188(%rsp)
movq %rsi, 0x180(%rsp)
movq %rdx, 0x178(%rsp)
movq 0x180(%rsp), %rax
movl (%rax), %eax
subl $0x1000082, %eax        # imm = 0x1000082
jne 0x376d
jmp 0x2d06
movq 0x188(%rsp), %rsi
movq 0x180(%rsp), %rdx
leaq 0x160(%rsp), %rdi
callq 0x5de0
movq $0x0, 0x158(%rsp)
movq 0x158(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x5e80
movq %rax, %rcx
movq 0xe8(%rsp), %rax
cmpq %rcx, %rax
jae 0x3523
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movzbl 0x4(%rax), %eax
cmpl $0xff, %eax
jne 0x2e32
movq 0x188(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movq 0xd8(%rsp), %rdi
movq %rax, %rsi
callq 0x5ec0
movl %eax, 0xe4(%rsp)
jmp 0x2dc2
movl 0xe4(%rsp), %eax
movl %eax, 0x154(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movl (%rax), %esi
movl 0x154(%rsp), %edx
leaq 0x1d2c8(%rip), %rdi     # 0x200bd
xorl %eax, %eax
callq 0x2040
jmp 0x2dfe
movl $0xffffffff, 0x194(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x140(%rsp)
jmp 0x3741
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x375e
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movl (%rax), %eax
addl $0xfeffff7d, %eax       # imm = 0xFEFFFF7D
movl %eax, %ecx
movq %rcx, 0xd0(%rsp)
subl $0x6, %eax
ja 0x3508
movq 0xd0(%rsp), %rax
leaq 0x1d194(%rip), %rcx     # 0x20004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x188(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movq 0xc0(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0xcf(%rsp)
jmp 0x2eb7
movb 0xcf(%rsp), %cl
movq 0x178(%rsp), %rax
movb %cl, (%rax)
jmp 0x3508
movq 0x188(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0xbf(%rsp)
jmp 0x2f0b
movb 0xbf(%rsp), %cl
movq 0x178(%rsp), %rax
movb %cl, 0x1(%rax)
jmp 0x3508
movq 0x188(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movq 0xa0(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0xaf(%rsp)
jmp 0x2f60
movb 0xaf(%rsp), %cl
movq 0x178(%rsp), %rax
movb %cl, 0x2(%rax)
jmp 0x3508
movq 0x188(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movq 0x98(%rsp), %rsi
movq %rax, %rdx
leaq 0x128(%rsp), %rdi
callq 0x5de0
jmp 0x2fb6
movq $0x0, 0x120(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x5e80
movq %rax, %rcx
movq 0x90(%rsp), %rax
cmpq %rcx, %rax
jae 0x3221
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movzbl 0x4(%rax), %eax
cmpl $0xff, %eax
jne 0x30d2
movq 0x188(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movq 0x80(%rsp), %rdi
movq %rax, %rsi
callq 0x5ec0
movl %eax, 0x8c(%rsp)
jmp 0x3055
movl 0x8c(%rsp), %eax
movl %eax, 0x11c(%rsp)
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movl (%rax), %esi
movl 0x11c(%rsp), %edx
leaq 0x1d035(%rip), %rdi     # 0x200bd
xorl %eax, %eax
callq 0x2040
jmp 0x3091
movl $0xffffffff, 0x194(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x140(%rsp)
jmp 0x322c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x5f20
jmp 0x375e
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
subl $0x1000087, %eax        # imm = 0x1000087
je 0x3106
jmp 0x30f6
movl 0x7c(%rsp), %eax
subl $0x1000088, %eax        # imm = 0x1000088
je 0x314f
jmp 0x3195
movq 0x188(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0x7b(%rsp)
jmp 0x313b
movb 0x7b(%rsp), %cl
movq 0x178(%rsp), %rax
movb %cl, 0x3(%rax)
jmp 0x3206
movq 0x188(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0x6f(%rsp)
jmp 0x3184
movb 0x6f(%rsp), %cl
movq 0x178(%rsp), %rax
movb %cl, 0x4(%rax)
jmp 0x3206
movq 0x188(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0x5f(%rsp)
jmp 0x31ca
movb 0x5f(%rsp), %al
movb %al, 0x11b(%rsp)
movq 0x120(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x5ea0
movl (%rax), %esi
movzbl 0x11b(%rsp), %edx
leaq 0x1cee6(%rip), %rdi     # 0x200e1
xorl %eax, %eax
callq 0x2040
jmp 0x3204
jmp 0x3206
jmp 0x3208
movq 0x120(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x120(%rsp)
jmp 0x2fc2
movl $0x6, 0x140(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x5f20
movl 0x140(%rsp), %eax
subl $0x6, %eax
je 0x3508
jmp 0x3741
movq 0x188(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x5ea0
movq 0x48(%rsp), %rsi
movq %rax, %rdx
leaq 0x100(%rsp), %rdi
callq 0x5de0
jmp 0x3287
movq $0x0, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x5e80
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jae 0x34de
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movzbl 0x4(%rax), %eax
cmpl $0xff, %eax
jne 0x3391
movq 0x188(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x5ec0
movl %eax, 0x3c(%rsp)
jmp 0x3317
movl 0x3c(%rsp), %eax
movl %eax, 0xf4(%rsp)
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movl (%rax), %esi
movl 0xf4(%rsp), %edx
leaq 0x1cd76(%rip), %rdi     # 0x200bd
xorl %eax, %eax
callq 0x2040
jmp 0x3350
movl $0xffffffff, 0x194(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x140(%rsp)
jmp 0x34e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x5f20
jmp 0x375e
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
subl $0x1000087, %eax        # imm = 0x1000087
je 0x33c5
jmp 0x33b5
movl 0x2c(%rsp), %eax
subl $0x1000088, %eax        # imm = 0x1000088
je 0x340e
jmp 0x3454
movq 0x188(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0x2b(%rsp)
jmp 0x33fa
movb 0x2b(%rsp), %cl
movq 0x178(%rsp), %rax
movb %cl, 0x5(%rax)
jmp 0x34c3
movq 0x188(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0x1f(%rsp)
jmp 0x3443
movb 0x1f(%rsp), %cl
movq 0x178(%rsp), %rax
movb %cl, 0x6(%rax)
jmp 0x34c3
movq 0x188(%rsp), %rax
movq %rax, (%rsp)
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x5ef0
movb %al, 0xf(%rsp)
jmp 0x3487
movb 0xf(%rsp), %al
movb %al, 0xf3(%rsp)
movq 0xf8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x5ea0
movl (%rax), %esi
movzbl 0xf3(%rsp), %edx
leaq 0x1cc29(%rip), %rdi     # 0x200e1
xorl %eax, %eax
callq 0x2040
jmp 0x34c1
jmp 0x34c3
jmp 0x34c5
movq 0xf8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xf8(%rsp)
jmp 0x3293
movl $0x6, 0x140(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x5f20
movl 0x140(%rsp), %eax
subl $0x6, %eax
jne 0x3741
jmp 0x3508
jmp 0x350a
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x2d2f
movq 0x178(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x3549
leaq 0x1cbc6(%rip), %rdi     # 0x20101
xorl %eax, %eax
callq 0x2040
jmp 0x3544
jmp 0x3642
movq 0x178(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x1, %eax
jne 0x356f
leaq 0x1cbae(%rip), %rdi     # 0x2010f
xorl %eax, %eax
callq 0x2040
jmp 0x356a
jmp 0x3640
movq 0x178(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x2, %eax
jne 0x3595
leaq 0x1cb96(%rip), %rdi     # 0x2011d
xorl %eax, %eax
callq 0x2040
jmp 0x3590
jmp 0x363e
movq 0x178(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x3, %eax
jne 0x35bb
leaq 0x1cb7e(%rip), %rdi     # 0x2012b
xorl %eax, %eax
callq 0x2040
jmp 0x35b6
jmp 0x363c
movq 0x178(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x4, %eax
jne 0x35de
leaq 0x1cb66(%rip), %rdi     # 0x20139
xorl %eax, %eax
callq 0x2040
jmp 0x35dc
jmp 0x363a
movq 0x178(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x5, %eax
jne 0x3601
leaq 0x1cb51(%rip), %rdi     # 0x20147
xorl %eax, %eax
callq 0x2040
jmp 0x35ff
jmp 0x3638
movq 0x178(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x6, %eax
jne 0x3624
leaq 0x1cb3c(%rip), %rdi     # 0x20155
xorl %eax, %eax
callq 0x2040
jmp 0x3622
jmp 0x3636
leaq 0x1cb38(%rip), %rdi     # 0x20163
xorl %eax, %eax
callq 0x2040
jmp 0x3634
jmp 0x3636
jmp 0x3638
jmp 0x363a
jmp 0x363c
jmp 0x363e
jmp 0x3640
jmp 0x3642
movq 0x178(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x3664
leaq 0x1cb18(%rip), %rdi     # 0x20171
xorl %eax, %eax
callq 0x2040
jmp 0x3662
jmp 0x369a
movq 0x178(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x3686
leaq 0x1cb02(%rip), %rdi     # 0x2017d
xorl %eax, %eax
callq 0x2040
jmp 0x3684
jmp 0x3698
leaq 0x1caff(%rip), %rdi     # 0x2018c
xorl %eax, %eax
callq 0x2040
jmp 0x3696
jmp 0x3698
jmp 0x369a
movq 0x178(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x1, %eax
jne 0x36d6
movq 0x178(%rsp), %rax
movzbl 0x3(%rax), %esi
movzbl 0x4(%rax), %edx
movzbl 0x5(%rax), %ecx
movzbl 0x6(%rax), %r8d
leaq 0x1cacf(%rip), %rdi     # 0x2019a
xorl %eax, %eax
callq 0x2040
jmp 0x36d4
jmp 0x3726
movq 0x178(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x3712
movq 0x178(%rsp), %rax
movzbl 0x3(%rax), %esi
movzbl 0x4(%rax), %edx
movzbl 0x5(%rax), %ecx
movzbl 0x6(%rax), %r8d
leaq 0x1cab3(%rip), %rdi     # 0x201ba
xorl %eax, %eax
callq 0x2040
jmp 0x3710
jmp 0x3724
leaq 0x1cac1(%rip), %rdi     # 0x201da
xorl %eax, %eax
callq 0x2040
jmp 0x3722
jmp 0x3724
jmp 0x3726
leaq 0x1cb09(%rip), %rdi     # 0x20236
xorl %eax, %eax
callq 0x2040
jmp 0x3736
movl $0x2, 0x140(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x5f20
movl 0x140(%rsp), %eax
subl $0x1, %eax
je 0x37c0
jmp 0x375c
jmp 0x37a9
leaq 0x160(%rsp), %rdi
callq 0x5f20
jmp 0x37cf
movq 0x188(%rsp), %rdi
movq 0x180(%rsp), %rsi
callq 0x5ef0
movb %al, 0xf2(%rsp)
movq 0x180(%rsp), %rax
movl (%rax), %esi
movzbl 0xf2(%rsp), %edx
leaq 0x1ca4b(%rip), %rdi     # 0x201ed
movb $0x0, %al
callq 0x2040
movq 0x188(%rsp), %rdi
movq 0x180(%rsp), %rsi
callq 0x94d0
ud2
movl 0x194(%rsp), %eax
addq $0x198, %rsp            # imm = 0x198
retq
movq 0x148(%rsp), %rdi
callq 0x22a0
nopl (%rax)