// File: /workspace/github_cpp_makefile_star2_O1/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 0x44b2
cmpb $0x70, %al
jne 0x6a22
leaq -0xfc(%rbp), %r15
movl $0x1, -0x4(%r15)
movq %rbx, %rdi
callq 0x4728
movl %eax, 0x40(%r15)
leaq -0xb8(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4732
movq (%r12), %rsi
movq %r15, %rdi
callq 0x3250
movq 0x3709(%rip), %rdi      # 0x9fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0x36ee(%rip), %rdi      # 0x9fd0
callq 0x3030
movq %rax, %rdi
callq 0x3190
movq %rax, %rbx
leaq 0xf31(%rip), %rsi       # 0x782a
movl $0x11, %edx
movq %rax, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3190
movq 0x369c(%rip), %rdi      # 0x9fd0
leaq 0xf01(%rip), %rsi       # 0x783c
movl $0x6, %edx
callq 0x32f0
movq %r15, %rdi
callq 0x3130
movq 0x367c(%rip), %rdi      # 0x9fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x32f0
movq 0x366a(%rip), %rdi      # 0x9fd0
leaq 0xed6(%rip), %rsi       # 0x7843
movl $0xf, %edx
callq 0x32f0
movl -0xbc(%rbp), %esi
movq 0x364c(%rip), %rdi      # 0x9fd0
callq 0x3450
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3190
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 0x5da0
leaq 0xe72(%rip), %rcx       # 0x7853
leaq -0x98(%rbp), %rdi
movl $0x19, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
leaq -0x48(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6b7d
movq %rdx, -0x58(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x48(%rbp)
jmp 0x6b84
movq %rbx, %rdi
callq 0x44b2
cmpb $0x61, %al
jne 0x6c1e
movq %rbx, %rdi
callq 0x4956
movl %eax, %r12d
movq %rbx, %rdi
callq 0x494c
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x4960
movq %r13, -0x38(%rbp)
movl %eax, %r13d
movq 0x3572(%rip), %rbx      # 0x9fd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3190
movq %rax, %r15
leaq 0xdde(%rip), %rsi       # 0x786d
movl $0x15, %edx
movq %rax, %rdi
callq 0x32f0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3190
leaq 0xdb9(%rip), %rsi       # 0x7883
movl $0x5, %edx
movq %rbx, %rdi
callq 0x32f0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3450
movq %rax, %rbx
leaq 0xd9d(%rip), %rsi       # 0x7889
movl $0xc, %edx
movq %rax, %rdi
callq 0x32f0
movq %rbx, %rdi
movl -0x2c(%rbp), %r15d
movl %r15d, %esi
callq 0x3450
movq %rax, %rbx
leaq 0xd84(%rip), %rsi       # 0x7896
movl $0xb, %edx
movq %rax, %rdi
callq 0x32f0
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3450
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3190
leaq 0x1(%r14), %rdi
movl %r13d, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x5e42
movb %al, 0x1c(%r14)
movzbl %al, %eax
decl %eax
orl $0x1, %eax
movq -0x38(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x6c1e
movups (%rcx), %xmm0
movups %xmm0, (%r15)
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 0x6bac
callq 0x3260
leaq -0x68(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x496a
movl -0xbc(%rbp), %edx
leaq -0x78(%rbp), %rsi
movq %r14, %rdi
callq 0x5ede
movb %al, 0x1c(%r14)
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x6bed
callq 0x3260
movzbl 0x1c(%r14), %eax
decl %eax
orl $0x1, %eax
movl %eax, (%r13)
movq -0x58(%rbp), %rdi
cmpq %r15, %rdi
je 0x6c09
callq 0x3260
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6c1e
callq 0x3260
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 0x6c46
callq 0x3260
jmp 0x6c46
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r15, %rdi
jne 0x6c60
jmp 0x6c6c
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x6c6c
callq 0x3260
jmp 0x6c6c
jmp 0x6c69
movq %rax, %rbx
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6c81
callq 0x3260
movq %rbx, %rdi
callq 0x3480