Beispiel #1
0
/**
*Receive requested files from server
*/
int sendFiles(int *socket,char *req_buffer)
{
	int size = BUFFER_SIZE*2;
	char *file_buffer = malloc(size);
	memset(file_buffer,0,size);
	if(file_buffer == NULL)
	{
		fprintf(stderr,"Cannot allocate %d bytes for buffer\n",size);
    	exit(1);
	}
	char *tok_ptr = strtok(req_buffer,"/");
	FILE *fptr;
	int read_size = 0,total = 0,pending = 0;
	while (tok_ptr != NULL)
  	{
  		total = 0;
		fptr = fopen (tok_ptr, "rb");
		if(fptr == NULL)
		{
			printf("Server requested for a file that doesn't exist\n");
            free(file_buffer);
			return 0;
		}
        if(sendMessage(socket,"rlock\4")) //send lock request
        {
            handleLocks(socket,tok_ptr);
        }
		while((read_size = fread(file_buffer, sizeof(char), size, fptr))>0)
        {
        	total += read_size;
            if(send(*socket, file_buffer, read_size, 0) < 0)
            {
                printf("Failed to send data\n");
                return 0;
            }
            ioctl(*socket, FIONREAD, &pending); //check for data to read from socket
            if(pending != 0)    //if there is something to read
                if(!handleLocks(socket,tok_ptr))    //server sent a message about file locks (timeout occurred)
                {
                    fclose(fptr);
                    free(file_buffer);
                    return 0;
                }
        }
       	printf ("Done sending file %s.Total bytes sent %d\n",tok_ptr,total);
        fclose(fptr);
		tok_ptr = strtok (NULL, "/");
  	}
    free(file_buffer);
  	return 1;
}
Beispiel #2
0
void operatorControl() {

	while (true)
	{

		calibrate();
		handleLocks();
		handleLcdButtons();
		legs();

		int shouldshoot = 0;

		while (joystickGetDigital(1, 7, JOY_LEFT)){
			shouldshoot = 1;
		}

		//start the shoot loop
		if (shouldshoot){
			shootgo = 1;
			bot = shoot;
			shootLoop();
		}

		int shouldlift = 0;

		while (joystickGetDigital(2, 8, JOY_LEFT)){
			shouldlift = 1;
		}

		if (shouldlift){
			if (bot == lift){
				bot = control;
			} else {
				bot = lift;
			}
		}

		if (bot == control){
			if (joystickGetDigital(1, 8, JOY_LEFT)){
				shootLeft();
			}

			if (joystickGetDigital(1, 8, JOY_RIGHT)){
				shootRight();
			}
		}

		delay(25);
	}
}