// File: awbrenn[P]robot-controller/Middleware.cpp
// Function: detectCommand(char*)
void detectCommand(char *command)
{
    // when satisfied , remove all the cout(s) to make the code more readable and concise.

    char *temp = 0;
    char *value = 0;

    if(strcmp(command , "GET IMAGE")==0)
    {
        FILE_PATH = FILE_PATH + "snapshot?topic=/robot_8/image?width=100?height=100" ; // semi-hd :P  ; constant for now ; change later
        printf("%s\n", FILE_PATH.c_str());
        ROBOT_PORT = 8081;
        cout<<"request for image\n"<<endl;
    }
    else if(strcmp(command , "GET GPS")==0)
    {
        FILE_PATH = FILE_PATH + STATE_ID;
        ROBOT_PORT = 8082;
        printf("%s\n", FILE_PATH.c_str());
        cout<<"request for gps\n"<< endl;
    }
    else if(strcmp(command , "GET DGPS")==0)
    {
        FILE_PATH = FILE_PATH + STATE_ID ;
        printf("%s\n", FILE_PATH.c_str());
        ROBOT_PORT = 8084;
        cout<<"request for dgps\n"<<endl;
    }
    else if(strcmp(command , "GET LASERS")==0)
    {
        FILE_PATH = FILE_PATH + STATE_ID ;
        printf("%s\n", FILE_PATH.c_str());
        ROBOT_PORT = 8083;
        cout<<"request for lasers\n"<<endl;
    }
    else if(strstr(command , "MOVE")!=NULL)
    {
        temp = strrchr(command , ' ');
        temp++;
        value= temp;
        FILE_PATH = FILE_PATH + TWIST_ID + "lx=" + value ;
        ROBOT_PORT = 8082;
        printf("%s\n", FILE_PATH.c_str());
        cout<<"request for movement"<<endl;
        cout<<"move value is : "<<value<<endl;
    }
    else if(strstr(command , "TURN")!=NULL)
    {
        temp = strrchr(command , ' ');
        temp++;
        value = temp;
        FILE_PATH = FILE_PATH + TWIST_ID + "az=" + value ;
        ROBOT_PORT = 8082;
        printf("%s\n", FILE_PATH.c_str());
        cout<<"request for turn"<<endl;
        cout<<"turn value is : "<<value<<endl;
    }
    else if(strstr(command , "STOP")!=NULL)
    {
        FILE_PATH = FILE_PATH + TWIST_ID + "lx=0";
        ROBOT_PORT = 8082;
        printf("%s\n", FILE_PATH.c_str());
        cout<<"request for stop"<<endl;
        cout<<"move value is : 0"<< "\n" << endl;
    }

    else
        cout<<"unknown command"<<endl;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x2dac(%rip), %rsi      # 0x7136
callq 0x33f0
cmpl $0x0, %eax
jne 0x4411
leaq -0x38(%rbp), %rdi
leaq 0x5f39(%rip), %rsi      # 0xa2d8
leaq 0x2d9a(%rip), %rdx      # 0x7140
callq 0x5380
leaq 0x5f26(%rip), %rdi      # 0xa2d8
leaq -0x38(%rbp), %rsi
callq 0x3380
leaq -0x38(%rbp), %rdi
callq 0x3518
leaq 0x5f0d(%rip), %rdi      # 0xa2d8
callq 0x3110
movq %rax, %rsi
leaq 0x2f2a(%rip), %rdi      # 0x7304
movb $0x0, %al
callq 0x3030
movw $0x1f91, 0x5eae(%rip)   # imm = 0x1F91
movq 0x5bdf(%rip), %rdi      # 0x9fd0
leaq 0x2d7b(%rip), %rsi      # 0x7173
callq 0x32b0
movq %rax, %rdi
movq 0x5bb1(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a33
movq -0x8(%rbp), %rdi
leaq 0x2d6a(%rip), %rsi      # 0x7186
callq 0x33f0
cmpl $0x0, %eax
jne 0x44a3
leaq -0x58(%rbp), %rdi
leaq 0x5ea7(%rip), %rsi      # 0xa2d8
leaq 0x5f40(%rip), %rdx      # 0xa378
callq 0x5400
leaq 0x5e94(%rip), %rdi      # 0xa2d8
leaq -0x58(%rbp), %rsi
callq 0x3380
leaq -0x58(%rbp), %rdi
callq 0x3518
movw $0x1f92, 0x5e39(%rip)   # imm = 0x1F92
leaq 0x5e72(%rip), %rdi      # 0xa2d8
callq 0x3110
movq %rax, %rsi
leaq 0x2e8f(%rip), %rdi      # 0x7304
movb $0x0, %al
callq 0x3030
movq 0x5b4d(%rip), %rdi      # 0x9fd0
leaq 0x2d04(%rip), %rsi      # 0x718e
callq 0x32b0
movq %rax, %rdi
movq 0x5b1f(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a31
movq -0x8(%rbp), %rdi
leaq 0x2cf1(%rip), %rsi      # 0x719f
callq 0x33f0
cmpl $0x0, %eax
jne 0x4535
leaq -0x78(%rbp), %rdi
leaq 0x5e15(%rip), %rsi      # 0xa2d8
leaq 0x5eae(%rip), %rdx      # 0xa378
callq 0x5400
leaq 0x5e02(%rip), %rdi      # 0xa2d8
leaq -0x78(%rbp), %rsi
callq 0x3380
leaq -0x78(%rbp), %rdi
callq 0x3518
leaq 0x5de9(%rip), %rdi      # 0xa2d8
callq 0x3110
movq %rax, %rsi
leaq 0x2e06(%rip), %rdi      # 0x7304
movb $0x0, %al
callq 0x3030
movw $0x1f94, 0x5d8a(%rip)   # imm = 0x1F94
movq 0x5abb(%rip), %rdi      # 0x9fd0
leaq 0x2c8c(%rip), %rsi      # 0x71a8
callq 0x32b0
movq %rax, %rdi
movq 0x5a8d(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a2f
movq -0x8(%rbp), %rdi
leaq 0x2c7a(%rip), %rsi      # 0x71ba
callq 0x33f0
cmpl $0x0, %eax
jne 0x45d4
leaq -0x98(%rbp), %rdi
leaq 0x5d7c(%rip), %rsi      # 0xa2d8
leaq 0x5e15(%rip), %rdx      # 0xa378
callq 0x5400
leaq 0x5d69(%rip), %rdi      # 0xa2d8
leaq -0x98(%rbp), %rsi
callq 0x3380
leaq -0x98(%rbp), %rdi
callq 0x3518
leaq 0x5d4a(%rip), %rdi      # 0xa2d8
callq 0x3110
movq %rax, %rsi
leaq 0x2d67(%rip), %rdi      # 0x7304
movb $0x0, %al
callq 0x3030
movw $0x1f93, 0x5ceb(%rip)   # imm = 0x1F93
movq 0x5a1c(%rip), %rdi      # 0x9fd0
leaq 0x2c0a(%rip), %rsi      # 0x71c5
callq 0x32b0
movq %rax, %rdi
movq 0x59ee(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a2d
movq -0x8(%rbp), %rdi
leaq 0x2bfa(%rip), %rsi      # 0x71d9
callq 0x3090
cmpq $0x0, %rax
je 0x475e
movq -0x8(%rbp), %rdi
movl $0x20, %esi
callq 0x3350
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
incq %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq 0x5cbe(%rip), %rsi      # 0xa2d8
leaq 0x5d77(%rip), %rdx      # 0xa398
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x5400
movq -0x1b0(%rbp), %rsi
leaq 0x2b9c(%rip), %rdx      # 0x71de
leaq -0xd8(%rbp), %rdi
callq 0x5220
jmp 0x4650
movq -0x18(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x5220
jmp 0x4669
leaq 0x5c68(%rip), %rdi      # 0xa2d8
leaq -0xb8(%rbp), %rsi
callq 0x3380
leaq -0xb8(%rbp), %rdi
callq 0x3518
leaq -0xd8(%rbp), %rdi
callq 0x3518
leaq -0xf8(%rbp), %rdi
callq 0x3518
movw $0x1f92, 0x5bef(%rip)   # imm = 0x1F92
leaq 0x5c28(%rip), %rdi      # 0xa2d8
callq 0x3110
movq %rax, %rsi
leaq 0x2c45(%rip), %rdi      # 0x7304
movb $0x0, %al
callq 0x3030
movq 0x5903(%rip), %rdi      # 0x9fd0
leaq 0x2b0e(%rip), %rsi      # 0x71e2
callq 0x32b0
movq %rax, %rdi
movq 0x58d5(%rip), %rsi      # 0x9fb8
callq 0x3300
movq 0x58e1(%rip), %rdi      # 0x9fd0
leaq 0x2b01(%rip), %rsi      # 0x71f7
callq 0x32b0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x32b0
movq %rax, %rdi
movq 0x58a7(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x474d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3518
leaq -0xf8(%rbp), %rdi
callq 0x3518
jmp 0x4a3c
movq -0x8(%rbp), %rdi
leaq 0x2a9f(%rip), %rsi      # 0x7208
callq 0x3090
cmpq $0x0, %rax
je 0x48e8
movq -0x8(%rbp), %rdi
movl $0x20, %esi
callq 0x3350
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
incq %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq 0x5b34(%rip), %rsi      # 0xa2d8
leaq 0x5bed(%rip), %rdx      # 0xa398
leaq -0x168(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x5400
movq -0x1b8(%rbp), %rsi
leaq 0x2a41(%rip), %rdx      # 0x720d
leaq -0x148(%rbp), %rdi
callq 0x5220
jmp 0x47da
movq -0x18(%rbp), %rdx
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x5220
jmp 0x47f3
leaq 0x5ade(%rip), %rdi      # 0xa2d8
leaq -0x128(%rbp), %rsi
callq 0x3380
leaq -0x128(%rbp), %rdi
callq 0x3518
leaq -0x148(%rbp), %rdi
callq 0x3518
leaq -0x168(%rbp), %rdi
callq 0x3518
movw $0x1f92, 0x5a65(%rip)   # imm = 0x1F92
leaq 0x5a9e(%rip), %rdi      # 0xa2d8
callq 0x3110
movq %rax, %rsi
leaq 0x2abb(%rip), %rdi      # 0x7304
movb $0x0, %al
callq 0x3030
movq 0x5779(%rip), %rdi      # 0x9fd0
leaq 0x29b3(%rip), %rsi      # 0x7211
callq 0x32b0
movq %rax, %rdi
movq 0x574b(%rip), %rsi      # 0x9fb8
callq 0x3300
movq 0x5757(%rip), %rdi      # 0x9fd0
leaq 0x29a2(%rip), %rsi      # 0x7222
callq 0x32b0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x32b0
movq %rax, %rdi
movq 0x571d(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x48d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x3518
leaq -0x168(%rbp), %rdi
callq 0x3518
jmp 0x4a3c
movq -0x8(%rbp), %rdi
leaq 0x2940(%rip), %rsi      # 0x7233
callq 0x3090
cmpq $0x0, %rax
je 0x4a05
leaq 0x59cf(%rip), %rsi      # 0xa2d8
leaq 0x5a88(%rip), %rdx      # 0xa398
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x5400
movq -0x1c0(%rbp), %rsi
leaq 0x2907(%rip), %rdx      # 0x7238
leaq -0x188(%rbp), %rdi
callq 0x5220
jmp 0x493f
leaq 0x5992(%rip), %rdi      # 0xa2d8
leaq -0x188(%rbp), %rsi
callq 0x3380
leaq -0x188(%rbp), %rdi
callq 0x3518
leaq -0x1a8(%rbp), %rdi
callq 0x3518
movw $0x1f92, 0x5925(%rip)   # imm = 0x1F92
leaq 0x595e(%rip), %rdi      # 0xa2d8
callq 0x3110
movq %rax, %rsi
leaq 0x297b(%rip), %rdi      # 0x7304
movb $0x0, %al
callq 0x3030
movq 0x5639(%rip), %rdi      # 0x9fd0
leaq 0x289f(%rip), %rsi      # 0x723d
callq 0x32b0
movq %rax, %rdi
movq 0x560b(%rip), %rsi      # 0x9fb8
callq 0x3300
movq 0x5617(%rip), %rdi      # 0x9fd0
leaq 0x288e(%rip), %rsi      # 0x724e
callq 0x32b0
movq %rax, %rdi
leaq 0x2765(%rip), %rsi      # 0x7134
callq 0x32b0
movq %rax, %rdi
movq 0x55da(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3518
jmp 0x4a3c
movq 0x55c4(%rip), %rdi      # 0x9fd0
leaq 0x284d(%rip), %rsi      # 0x7260
callq 0x32b0
movq %rax, %rdi
movq 0x5596(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4a29
jmp 0x4a2b
jmp 0x4a2d
jmp 0x4a2f
jmp 0x4a31
jmp 0x4a33
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x3490
nopl (%rax,%rax)