// File: /workspace/github_cpp_makefile_star2_O3/CDISC2020[P]Projet_satellite_agile/src/planManager/Controller.cpp
// Function: Controller::executeInstruction(GenericInstruction*, int*)
void Controller::executeInstruction(GenericInstruction* instruction, int* responseController)
{
	if(instruction->getType() == 'p')
	{
		Camera C;
		C.code=1;
		C.exposure = ((PhotoInstruction*)instruction)->getExposure();
		string aux = ((PhotoInstruction*)instruction)->getPhotoName();
		strcpy(C.photoName,aux.c_str());

		cout << endl << "New photo! Smile!" << endl;
		cout<<"name ="<<C.photoName<<"    exposure = "<<C.exposure<<endl;
		string path="src/communication/toSend/" + (string) C.photoName; // where to save pictures
                sc.returnControl = myCameraController.photoShoot(path, C.exposure);
		if(sc.returnControl)
		{
			//call traitement image
			/*char cmde[100]="";
			remove("res_image_processing.txt")
			sprintf(cmde,"python image_processing.py %s &", path.c_str());
			system(cmde);
			sleep(3);
			ifstream file;
			file.open("res_image_processing.txt");
			if(!file){
				cout << "No response from image processing" << endl;
				*responseController=1; // Let the Ground choose if ok
			}
			else
			{
				string line;
				getline(file,line);
				if(atoi(line.c_str()))
					*responseController=1;
				else
					*responseController=-1;
				file.close();
				remove("res_image_processing.txt")
			}
			*/

			// by pass algo, algo expensive to execute, never really tested
			// remove this line if the above isn't commented
			*responseController=1;
			//////
		}
		else
			*responseController=-1;
	}
	else if(instruction->getType() == 'a')
	{
		Attitude A; 
		A.code = 0; 
		A.yaw = ((AttitudeInstruction*)instruction)->getYaw(); 
		A.pitch = ((AttitudeInstruction*)instruction)->getPitch(); 
		A.roll = ((AttitudeInstruction*)instruction)->getRoll(); 

		cout << endl << "New attitude change!!" << endl;
		cout<<"yaw ="<<A.yaw<<"    pitch = "<<A.pitch<<"    roll = "<<A.roll<<endl;
                sc.returnControl = myAttitudeController.attitudeChange(A.roll, A.pitch, A.yaw);
		if(sc.returnControl)
			*responseController=1;
		else
			*responseController=-1;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x442a
cmpb $0x70, %al
jne 0x6992
leaq -0xfc(%rbp), %r15
movl $0x1, -0x4(%r15)
movq %rbx, %rdi
callq 0x46a0
movl %eax, 0x40(%r15)
leaq -0xb8(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x46aa
movq (%r12), %rsi
movq %r15, %rdi
callq 0x3260
movq 0x3799(%rip), %rdi      # 0x9fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq 0x377e(%rip), %rdi      # 0x9fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %rbx
leaq 0xfc1(%rip), %rsi       # 0x782a
movl $0x11, %edx
movq %rax, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x372c(%rip), %rdi      # 0x9fd0
leaq 0xf91(%rip), %rsi       # 0x783c
movl $0x6, %edx
callq 0x3300
movq %r15, %rdi
callq 0x3130
movq 0x370c(%rip), %rdi      # 0x9fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x3300
movq 0x36fa(%rip), %rdi      # 0x9fd0
leaq 0xf66(%rip), %rsi       # 0x7843
movl $0xf, %edx
callq 0x3300
movl -0xbc(%rbp), %esi
movq 0x36dc(%rip), %rdi      # 0x9fd0
callq 0x3460
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq -0x88(%rbp), %r12
movq %r12, -0x10(%r12)
movq %r15, %rdi
callq 0x3130
leaq (%rax,%r15), %rdx
leaq -0x98(%rbp), %rdi
movq %r15, %rsi
callq 0x5d0c
leaq 0xf02(%rip), %rcx       # 0x7853
leaq -0x98(%rbp), %rdi
movl $0x19, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x32d0
leaq -0x48(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x6aed
movq %rsi, -0x58(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x48(%rbp)
jmp 0x6af7
movq %rbx, %rdi
callq 0x442a
cmpb $0x61, %al
jne 0x6b96
movq %rbx, %rdi
callq 0x48ce
movl %eax, %r12d
movq %rbx, %rdi
callq 0x48c4
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x48d8
movq %r13, -0x38(%rbp)
movl %eax, %r13d
movq 0x3602(%rip), %rbx      # 0x9fd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %r15
leaq 0xe6e(%rip), %rsi       # 0x786d
movl $0x15, %edx
movq %rax, %rdi
callq 0x3300
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq 0xe49(%rip), %rsi       # 0x7883
movl $0x5, %edx
movq %rbx, %rdi
callq 0x3300
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3460
movq %rax, %rbx
leaq 0xe2d(%rip), %rsi       # 0x7889
movl $0xc, %edx
movq %rax, %rdi
callq 0x3300
movq %rbx, %rdi
movl -0x2c(%rbp), %r15d
movl %r15d, %esi
callq 0x3460
movq %rax, %rbx
leaq 0xe14(%rip), %rsi       # 0x7896
movl $0xb, %edx
movq %rax, %rdi
callq 0x3300
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3460
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq 0x1(%r14), %rdi
movl %r13d, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x5db2
movb %al, 0x1c(%r14)
movzbl %al, %eax
decl %eax
orl $0x1, %eax
movq -0x38(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x6b96
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq %r15, %rsi
movq 0x8(%rax), %rdx
movq %rdx, -0x50(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x6b27
callq 0x3270
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
leaq -0x68(%rbp), %r12
movq %r12, -0x10(%r12)
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x48e2
movl -0xbc(%rbp), %edx
leaq -0x78(%rbp), %rsi
movq %r14, %rdi
callq 0x5e4e
movb %al, 0x1c(%r14)
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x6b64
callq 0x3270
movb 0x1c(%r14), %al
movzbl %al, %eax
andl $0x1, %eax
decl %eax
orl $0x1, %eax
movl %eax, (%r13)
movq -0x58(%rbp), %rdi
cmpq %r15, %rdi
je 0x6b81
callq 0x3270
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6b96
callq 0x3270
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x6bbe
callq 0x3270
jmp 0x6bbe
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r15, %rdi
jne 0x6bd8
jmp 0x6be4
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x6be4
callq 0x3270
jmp 0x6be4
jmp 0x6be1
movq %rax, %rbx
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6bf9
callq 0x3270
movq %rbx, %rdi
callq 0x3490