Пример #1
0
void create_script_drive(int speed, int direction) {
	write_script_byte(OI_DRIVE_DIRECT);
	write_script_byte(get_high_byte(direction * speed));
	write_script_byte(get_low_byte(direction * speed));
	write_script_byte(get_high_byte(direction * speed));
	write_script_byte(get_low_byte(direction * speed));
}
Пример #2
0
void create_spin(int speed, int direction) {
	write_byte(OI_DRIVE);
    write_byte(get_high_byte(speed));
	write_byte(get_low_byte(speed));
    if(direction < 0) {
        write_byte(255);
        write_byte(255);
    }
    if(direction > 0) {
        write_byte(0);
        write_byte(1);
    }
}
Пример #3
0
	/* returns ?? */
static int dos33_add_file(int fd, char dos_type,
		int file_type, int address, int length,
		char *filename, char *apple_filename) {

	int free_space,file_size,needed_sectors;
	struct stat file_info;
	int size_in_sectors=0;
	int initial_ts_list=0,ts_list=0,i,data_ts,x,bytes_read=0,old_ts_list;
	int catalog_track,catalog_sector,sectors_used=0;
	int input_fd;
	int result;
	int first_write=1;

	if (apple_filename[0]<64) {
		fprintf(stderr,"Error!  First char of filename "
				"must be ASCII 64 or above!\n");
		return ERROR_INVALID_FILENAME;
	}

	/* Check for comma in filename */
	for(i=0;i<strlen(apple_filename);i++) {
		if (apple_filename[i]==',') {
			fprintf(stderr,"Error!  "
				"Cannot have , in a filename!\n");
			return ERROR_INVALID_FILENAME;
		}
	}

	/* FIXME */
	/* check type */
	/* and sanity check a/b filesize is set properly */

	/* Determine size of file to upload */
	if (stat(filename,&file_info)<0) {
		fprintf(stderr,"Error!  %s not found!\n",filename);
		return ERROR_FILE_NOT_FOUND;
	}

	file_size=(int)file_info.st_size;

	if (debug) printf("Filesize: %d\n",file_size);

	if (file_type==ADD_BINARY) {
		if (debug) printf("Adding 4 bytes for size/offset\n");
		if (length==0) length=file_size;
		file_size+=4;
	}

	/* We need to round up to nearest sector size */
	/* Add an extra sector for the T/S list */
	/* Then add extra sector for a T/S list every 122*256 bytes (~31k) */
	needed_sectors=(file_size/BYTES_PER_SECTOR)+ /* round sectors */
			((file_size%BYTES_PER_SECTOR)!=0)+/* tail if needed */
			1+/* first T/S list */
			(file_size/(122*BYTES_PER_SECTOR)); /* extra t/s lists */

	/* Get free space on device */
	free_space=dos33_free_space(fd);

	/* Check for free space */
	if (needed_sectors*BYTES_PER_SECTOR>free_space) {
		fprintf(stderr,"Error!  Not enough free space "
				"on disk image (need %d have %d)\n",
				needed_sectors*BYTES_PER_SECTOR,free_space);
		return ERROR_NO_SPACE;
	}

	/* plus one because we need a sector for the tail */
	size_in_sectors=(file_size/BYTES_PER_SECTOR)+
		((file_size%BYTES_PER_SECTOR)!=0);
	if (debug) printf("Need to allocate %i data sectors\n",size_in_sectors);
	if (debug) printf("Need to allocate %i total sectors\n",needed_sectors);

	/* Open the local file */
	input_fd=open(filename,O_RDONLY);
	if (input_fd<0) {
		fprintf(stderr,"Error! could not open %s\n",filename);
		return ERROR_IMAGE_NOT_FOUND;
	}

	i=0;
	while (i<size_in_sectors) {

		/* Create new T/S list if necessary */
		if (i%TSL_MAX_NUMBER==0) {
			old_ts_list=ts_list;

			/* allocate a sector for the new list */
			ts_list=dos33_allocate_sector(fd);
			sectors_used++;
			if (ts_list<0) return -1;

			/* clear the t/s sector */
			for(x=0;x<BYTES_PER_SECTOR;x++) {
				sector_buffer[x]=0;
			}
			lseek(fd,DISK_OFFSET((ts_list>>8)&0xff,ts_list&0xff),SEEK_SET);
			result=write(fd,sector_buffer,BYTES_PER_SECTOR);

			if (i==0) {
				initial_ts_list=ts_list;
			}
			else {
				/* we aren't the first t/s list so do special stuff */

				/* load in the old t/s list */
				lseek(fd,
					DISK_OFFSET(get_high_byte(old_ts_list),
					get_low_byte(old_ts_list)),
					SEEK_SET);

				result=read(fd,&sector_buffer,BYTES_PER_SECTOR);

				/* point from old ts list to new one we just made */
				sector_buffer[TSL_NEXT_TRACK]=get_high_byte(ts_list);
				sector_buffer[TSL_NEXT_SECTOR]=get_low_byte(ts_list);

				/* set offset into file */
				sector_buffer[TSL_OFFSET_H]=get_high_byte((i-122)*256);
				sector_buffer[TSL_OFFSET_L]=get_low_byte((i-122)*256);

				/* write out the old t/s list with updated info */
				lseek(fd,
					DISK_OFFSET(get_high_byte(old_ts_list),
					get_low_byte(old_ts_list)),
					SEEK_SET);

				result=write(fd,sector_buffer,BYTES_PER_SECTOR);
			}
		}

		/* allocate a sector */
		data_ts=dos33_allocate_sector(fd);
		sectors_used++;

		if (data_ts<0) return -1;

		/* clear sector */
		for(x=0;x<BYTES_PER_SECTOR;x++) sector_buffer[x]=0;

		/* read from input */
		if ((first_write) && (file_type==ADD_BINARY)) {
			first_write=0;
			sector_buffer[0]=address&0xff;
			sector_buffer[1]=(address>>8)&0xff;
			sector_buffer[2]=(length)&0xff;
			sector_buffer[3]=((length)>>8)&0xff;
			bytes_read=read(input_fd,sector_buffer+4,
					BYTES_PER_SECTOR-4);
			bytes_read+=4;
		}
Пример #4
0
static void create_write_int(int decimal) {
  	// [high byte][low byte]
    create.write_byte(get_high_byte(decimal));
    create.write_byte(get_low_byte(decimal));
}
Пример #5
0
__interrupt void Timer_A (void)
{
	timer_counter++;
	//while (!(IFG2&UCA0TXIFG));
	//UCA0TXBUF = timer_counter;
	if(isFlowing == 1){
		isFlowing = 0;
		flowing_time++;
		//while (!(IFG2&UCA0TXIFG));
		//UCA0TXBUF = flowing_time;
	}
	// If water flow has stopped
	else{
		// Pulse characteristic: 7Q L/MIN (Q is flow rate in L/MIN)
		// Flow-pulse: 1L/MIN = 8Hz;
		// Dividing it by 60 to get the flow pulse per second
		// Multiplying it by flowing time to get the amount of water flowed
		/*water_used += ((pulse_counter / 0.125) * (flowing_time));
		water_used += pulse_counter;
		if(pulse_counter != 0){
			int data = (pulse_counter * flowing_time)/0.12;
			while (!(IFG2&UCA0TXIFG));
			UCA0TXBUF = data;
		}

		//UCA0TXBUF = water_used;
		//pulse_counter = 0;
		//flowing_time = 0;
		*/

		//flow_rate = ((float)pulse_counter) / calibration_factor;
		flow_rate = (float)pulse_counter / flowing_time;
		//flow_rate = (pulse_counter / calibration_factor) * (1000 / 60);		// flow rate in ml/s
		//water_used = flow_rate * flowing_time;
		// Divide the flow rate in litres/minute by 60 to determine how many litres have
		// passed through the sensor in this 1 second interval, then multiply by 1000 to
		// convert to millilitres. After that multiplying by flowing_time will give the total
		// amount of water flowed in this time duration.
		//flow_milli_litres = ((flow_rate / 60)) * flowing_time;
		/*
		 * 7Hz -> 60 second -> 1 Litre
		 * 1Hz -> 01 second -> 1 / (7 * 60)
		 * flow_rate Hz -> flowing_time second -> (flow_rate * flowing_time) / (7 * 60)
		 */
		//water_used = ((flow_rate * flowing_time) / (calibration_factor * 60)) * 1000;
		flow_milli_litres = ((flow_rate * flowing_time) / (calibration_factor * 60)) * 1000;
		// Calculate total amount of water flowed for a certain period (i.e. for 10 minute)
		total_flow_milli_litres += flow_milli_litres;

		total_flow_litres = total_flow_milli_litres / 1000;
		int_part = (unsigned int)total_flow_milli_litres;
		decimal_part = (total_flow_milli_litres - int_part) * 10;

		if(pulse_counter != 0){
			//int data = (pulse_counter * flowing_time)/0.12;
			while (!(IFG2&UCA0TXIFG));
			//UCA0TXBUF = int_part;
			//total_flow_milli_litres = 0;
		}

		pulse_counter = 0;
		flowing_time = 0;
		flow_milli_litres = 0;
		water_used = 0;
		flow_rate = 0;

	}

	// Send data to the server in every 1 min
	if(timer_counter == 10){

		timer_counter = 0;							// reset timer counter
		unsigned char low_byte = get_low_byte(10004);
		unsigned char high_byte = get_high_byte(10004);
		//pulse_counter = 0;
		//flowing_time = 0;
		while (!(IFG2&UCA0TXIFG));     						// Wait until TX buffer is ready
		UCA0TXBUF = high_byte;              				// Send amount of water used to the server(to UART)
		//water_used = 0;										// reset the amount of water used to 0

		//total_flow_milli_litres = 0;
	}

}
Пример #6
0
   /* returns ?? */
static int dos33_add_file(int fd,char type,char *filename,
			  char *apple_filename) {
   
    int free_space,file_size,needed_sectors;
    struct stat file_info;
    int size_in_sectors=0;
    int initial_ts_list=0,ts_list=0,i,data_ts,x,bytes_read=0,old_ts_list;
    int catalog_track,catalog_sector,sectors_used=0;
    int input_fd;
    int result;

    if (apple_filename[0]<64) {
       fprintf(stderr,"Error!  First char of filename must be ASCII 64 or above!\n");
       exit(3);
    }
    {
       int i;
       
       for(i=0;i<strlen(apple_filename);i++) {
	  if (apple_filename[i]==',') {
	     fprintf(stderr,"Error!  Cannot have , in a filename!\n");
	     exit(3);
	  }
       }
    }
   
   /* FIXME */
   /* check type */
   /* and sanity check a/b filesize is set properly */
   
   
       /* Determine size of file to upload */
    if (stat(filename,&file_info)<0) {
       fprintf(stderr,"Error!  %s not found!\n",filename);
       exit(3);
    }
    file_size=(int)file_info.st_size;
   
       /* We need to round up to nearest sector size */
       /* Add an extra sector for the T/S list */
       /* Then add extra sector for a T/S list every 122*256 bytes (~31k) */   
    needed_sectors=(file_size/BYTES_PER_SECTOR)+ /* round sectors */
                   ((file_size%BYTES_PER_SECTOR)!=0)+/* tail if needed */
                   1+/* first T/S list */
                   (file_size/(122*BYTES_PER_SECTOR)); /* extra t/s lists */
   
       /* Get free space on device */
    free_space=dos33_free_space(fd);

       /* Check for free space */
    if (needed_sectors*BYTES_PER_SECTOR>free_space) {
       fprintf(stderr,"Error!  Not enough free space on disk image (need %d have %d)\n",
	      needed_sectors*BYTES_PER_SECTOR,free_space);
       exit(4);
    }

       /* plus one because we need a sector for the tail */
    size_in_sectors=(file_size/BYTES_PER_SECTOR)+
     ((file_size%BYTES_PER_SECTOR)!=0);
//    printf("Need to allocate %i data sectors\n",size_in_sectors);
//    printf("Need to allocate %i total sectors\n",needed_sectors);
   
        /* Open the local file */
    input_fd=open(filename,O_RDONLY);
    if (input_fd<0) {
       fprintf(stderr,"Error! could not open %s\n",filename);
       return -1;
    }

    i=0;
    while (i<size_in_sectors) {
       
          /* Create new T/S list if necessary */
       if (i%TSL_MAX_NUMBER==0) {	  
	  old_ts_list=ts_list;

	     /* allocate a sector for the new list */
	  ts_list=dos33_allocate_sector(fd);
	  sectors_used++;
          if (ts_list<0) return -1;
	  
	     /* clear the t/s sector */
	  for(x=0;x<BYTES_PER_SECTOR;x++) sector_buffer[x]=0;
	  lseek(fd,DISK_OFFSET((ts_list>>8)&0xff,ts_list&0xff),SEEK_SET);
	  result=write(fd,sector_buffer,BYTES_PER_SECTOR);
	  
	  if (i==0) initial_ts_list=ts_list;
	  else {
	        /* we aren't the first t/s list so do special stuff */

	        /* load in the old t/s list */
             lseek(fd,
                   DISK_OFFSET(get_high_byte(old_ts_list),
                               get_low_byte(old_ts_list)),
                   SEEK_SET);

             result=read(fd,&sector_buffer,BYTES_PER_SECTOR);
	     
	        /* point from old ts list to new one we just made */
	     sector_buffer[TSL_NEXT_TRACK]=get_high_byte(ts_list);
	     sector_buffer[TSL_NEXT_SECTOR]=get_low_byte(ts_list);
	     
	        /* set offset into file */
	     sector_buffer[TSL_OFFSET_H]=get_high_byte((i-122)*256);
	     sector_buffer[TSL_OFFSET_L]=get_low_byte((i-122)*256);
	        
	        /* write out the old t/s list with updated info */
	     lseek(fd,
                   DISK_OFFSET(get_high_byte(old_ts_list),
                               get_low_byte(old_ts_list)),
                   SEEK_SET);

	     result=write(fd,sector_buffer,BYTES_PER_SECTOR);
	  }
       }       
       
       
          /* allocate a sector */
       data_ts=dos33_allocate_sector(fd);
       sectors_used++;
       
       if (data_ts<0) return -1;
       
          /* clear sector */
       for(x=0;x<BYTES_PER_SECTOR;x++) sector_buffer[x]=0;

          /* read from input */
       bytes_read=read(input_fd,sector_buffer,BYTES_PER_SECTOR);
       if (bytes_read<0) fprintf(stderr,"Error reading bytes!\n");

          /* write to disk image */
       lseek(fd,DISK_OFFSET((data_ts>>8)&0xff,data_ts&0xff),SEEK_SET);
       result=write(fd,sector_buffer,BYTES_PER_SECTOR);
//       printf("Writing %i bytes to %i/%i\n",bytes_read,(data_ts>>8)&0xff,
//	       data_ts&0xff);
       

       
          /* add to T/s table */
       
          /* read in t/s list */
       lseek(fd,DISK_OFFSET((ts_list>>8)&0xff,ts_list&0xff),SEEK_SET);
       result=read(fd,sector_buffer,BYTES_PER_SECTOR);
       
          /* point to new data sector */
       sector_buffer[((i%TSL_MAX_NUMBER)*2)+TSL_LIST]=(data_ts>>8)&0xff;
       sector_buffer[((i%TSL_MAX_NUMBER)*2)+TSL_LIST+1]=(data_ts&0xff);
       
          /* write t/s list back out */
       lseek(fd,DISK_OFFSET((ts_list>>8)&0xff,ts_list&0xff),SEEK_SET);
       result=write(fd,sector_buffer,BYTES_PER_SECTOR);	  
       
       i++;   
    }
Пример #7
0
void _wait_degrees(int degrees) {
	write_byte(OI_WAIT_ANGLE);
	write_byte(get_high_byte(degrees));
	write_byte(get_low_byte(degrees));
}
Пример #8
0
void _wait_script_distance(int distance) {
	write_script_byte(OI_WAIT_DISTANCE);
	write_script_byte(get_high_byte(distance));
	write_script_byte(get_low_byte(distance));
}