// File: CDISC2020[P]Projet_satellite_agile/src/communication/comGroundManager.cpp
// Function: Communic_Interne(void*)
void* Communic_Interne(void* args)
{
	QueuingPort channelIn(1, 18003, s); 		// Server
	usleep(500000);
	channelIn.Display();
	usleep(300000);

	while(1)
	{
		channelIn.RecvQueuingMsg(buffer);

		status = (Status*)buffer;

 		/**************[ PM ---IMG---> CGM ]**************/
		// Remplir le tableau avec des photos prises
		if (status->code == 3)		// utilisation d'un type p
		{
			imageName = (PlanFilePath*)buffer;
			string aux(imageName->filepath);
			imageList[ptImageReceived] = aux;
			ptImageReceived = (ptImageReceived + 1)%128;
		}

 		/**************[ PM ---LOG---> CGM ]**************/
		// Plan manager --> Comunication Manager
		// Error identifier and description
		else if(status->code == 4)
		{
			string str(status->description);
			sm.newNotification(status->errorID, str);
		}

		/*************[ FDIR ---MODE---> CGM ]*************/
		// changement mode primary ou backup
		else if(status->code == 6)
		{
			m = (ModeStruct*)buffer;
			mode = m->rpiMode;
		}

		usleep(100);
	}

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x580, %rsp            # imm = 0x580
movq %rdi, -0x8(%rbp)
leaq -0x4d0(%rbp), %rdi
movl $0x1, %esi
movl $0x4653, %edx           # imm = 0x4653
leaq 0x5cf9(%rip), %rcx      # 0xa300
callq 0x2860
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x2390
leaq -0x4d0(%rbp), %rdi
callq 0x2cc0
movl $0x493e0, %edi          # imm = 0x493E0
callq 0x2390
leaq -0x4d0(%rbp), %rdi
leaq 0x5d36(%rip), %rsi      # 0xa370
callq 0x2b30
leaq 0x5d2a(%rip), %rax      # 0xa370
movq %rax, 0x4c83(%rip)      # 0x92d0
movq 0x4c7c(%rip), %rax      # 0x92d0
cmpl $0x3, (%rax)
jne 0x4749
leaq 0x5d0c(%rip), %rax      # 0xa370
movq %rax, 0x4c7d(%rip)      # 0x92e8
movq 0x4c76(%rip), %rax      # 0x92e8
addq $0x4, %rax
movq %rax, -0x560(%rbp)
leaq -0x4f1(%rbp), %rdi
movq %rdi, -0x558(%rbp)
callq 0x2490
movq -0x560(%rbp), %rsi
movq -0x558(%rbp), %rdx
leaq -0x4f0(%rbp), %rdi
callq 0x2370
jmp 0x46ac
leaq -0x4f1(%rbp), %rdi
callq 0x22c0
movslq 0x5c31(%rip), %rax      # 0xa2f0
shlq $0x5, %rax
leaq 0x4c26(%rip), %rdi      # 0x92f0
addq %rax, %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x2030
jmp 0x46db
movl 0x5c0f(%rip), %eax      # 0xa2f0
addl $0x1, %eax
movl $0x80, %ecx
cltd
idivl %ecx
movl %edx, 0x5bfe(%rip)      # 0xa2f0
leaq -0x4f0(%rbp), %rdi
callq 0x2190
jmp 0x4893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x500(%rbp)
movl %eax, -0x504(%rbp)
leaq -0x4f1(%rbp), %rdi
callq 0x22c0
jmp 0x48a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x500(%rbp)
movl %eax, -0x504(%rbp)
leaq -0x4f0(%rbp), %rdi
callq 0x2190
jmp 0x48a2
movq 0x4b80(%rip), %rax      # 0x92d0
cmpl $0x4, (%rax)
jne 0x4863
movq 0x4b70(%rip), %rax      # 0x92d0
addq $0x8, %rax
movq %rax, -0x570(%rbp)
leaq -0x529(%rbp), %rdi
movq %rdi, -0x568(%rbp)
callq 0x2490
movq -0x570(%rbp), %rsi
movq -0x568(%rbp), %rdx
leaq -0x528(%rbp), %rdi
callq 0x2370
jmp 0x479a
leaq -0x529(%rbp), %rdi
callq 0x22c0
movq 0x4b23(%rip), %rax      # 0x92d0
movl 0x4(%rax), %eax
movl %eax, -0x574(%rbp)
leaq -0x550(%rbp), %rdi
leaq -0x528(%rbp), %rsi
callq 0x2130
jmp 0x47cb
movl -0x574(%rbp), %esi
leaq 0x4ad8(%rip), %rdi      # 0x92b0
leaq -0x550(%rbp), %rdx
callq 0x3230
jmp 0x47e6
leaq -0x550(%rbp), %rdi
callq 0x2190
leaq -0x528(%rbp), %rdi
callq 0x2190
jmp 0x4891
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x500(%rbp)
movl %eax, -0x504(%rbp)
leaq -0x529(%rbp), %rdi
callq 0x22c0
jmp 0x48a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x500(%rbp)
movl %eax, -0x504(%rbp)
jmp 0x4855
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x500(%rbp)
movl %eax, -0x504(%rbp)
leaq -0x550(%rbp), %rdi
callq 0x2190
leaq -0x528(%rbp), %rdi
callq 0x2190
jmp 0x48a2
movq 0x4a66(%rip), %rax      # 0x92d0
cmpl $0x6, (%rax)
jne 0x488f
leaq 0x5afa(%rip), %rax      # 0xa370
movq %rax, 0x4a63(%rip)      # 0x92e0
movq 0x4a5c(%rip), %rax      # 0x92e0
movb 0x4(%rax), %al
andb $0x1, %al
movb %al, 0x5a69(%rip)       # 0xa2f8
jmp 0x4891
jmp 0x4893
movl $0x64, %edi
callq 0x2390
jmp 0x462c
movq -0x500(%rbp), %rdi
callq 0x2480
nop