Ejemplo n.º 1
0
bool readEEPROM() {
  uint8_t i;
  global_conf.currentSet=0;
  eeprom_read_block((void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  print("Calcul Eprom = %d, Read conf = %d \n\r", calculate_sum((uint8_t*)&conf, sizeof(conf)), conf.checksum);
  if(calculate_sum((uint8_t*)&conf, sizeof(conf)) != conf.checksum) {
	print("Loading Defaults\n\r");
    blinkLED(6,100,3);
    LoadDefaults();                 // force load defaults
    return false;                   // defaults loaded, don't reload constants (EEPROM life saving)
  }
  // 500/128 = 3.90625    3.9062 * 3.9062 = 15.259   1526*100/128 = 1192
  for(i=0;i<5;i++) {
    lookupPitchRollRC[i] = (1526+conf.rcExpo8*(i*i-15))*i*(int32_t)conf.rcRate8/1192;
  }
  for(i=0;i<11;i++) {
    int16_t tmp = 10*i-conf.thrMid8;
    uint8_t y = 1;
    if (tmp>0) y = 100-conf.thrMid8;
    if (tmp<0) y = conf.thrMid8;
    lookupThrottleRC[i] = 10*conf.thrMid8 + tmp*( 100-conf.thrExpo8+(int32_t)conf.thrExpo8*(tmp*tmp)/(y*y) )/10; // [0;1000]
    lookupThrottleRC[i] = conf.minthrottle + (int32_t)(MAXTHROTTLE-conf.minthrottle)* lookupThrottleRC[i]/1000;  // [0;1000] -> [conf.minthrottle;MAXTHROTTLE]
  }
  return true;    // setting is OK
}
Ejemplo n.º 2
0
void writeParams(uint8_t b) {
  global_conf.currentSet=0;
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
}
Ejemplo n.º 3
0
void readGlobalSet() {
  eeprom_read_block((void*)&global_conf, (void*)0, sizeof(global_conf));
  if(calculate_sum((uint8_t*)&global_conf, sizeof(global_conf)) != global_conf.checksum) {
    global_conf.currentSet = 0;
    global_conf.accZero[ROLL] = 5000;    // for config error signalization
  }
}
Ejemplo n.º 4
0
void writeGlobalSet(uint8_t b) {
  global_conf.checksum = calculate_sum((uint8_t*)&global_conf, sizeof(global_conf));
  eeprom_write_block((const void*)&global_conf, (void*)0, sizeof(global_conf));
  if (b == 1) blinkLED(15,20,1);
  SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_1);

}
Ejemplo n.º 5
0
main(){
       make_linked_list();
       get_numbers();
       get_scale();
       calculate_sum();
       print_result();
       getch();
       }
Ejemplo n.º 6
0
// Read the given number of WP from the eeprom, supposedly we can use this during flight.
// Returns true when reading is successfull and returns false if there were some error (for example checksum)
bool recallWP(uint8_t wp_number) {
	if (wp_number > 254) return false;

	eeprom_read_block((void*)&mission_step, (void*)(PROFILES * sizeof(conf) + sizeof(global_conf)+sizeof(GPS_conf)+(sizeof(mission_step)*wp_number)), sizeof(mission_step));
	if(calculate_sum((uint8_t*)&mission_step, sizeof(mission_step)) != mission_step.checksum) return false;

	return true;
}
Ejemplo n.º 7
0
//Recall gps_configuration
bool recallGPSconf(void) {
  eeprom_read_block((void*)&GPS_conf, (void*)(PROFILES * sizeof(conf) + sizeof(global_conf)), sizeof(GPS_conf));
  if(calculate_sum((uint8_t*)&GPS_conf, sizeof(GPS_conf)) != GPS_conf.checksum) {
    loadGPSdefaults();
    return false;
  }
  return true;
}
Ejemplo n.º 8
0
void writeGlobalSet(uint8_t b) {
  global_conf.checksum = calculate_sum((uint8_t*)&global_conf, sizeof(global_conf));
  eeprom_write_block((const void*)&global_conf, (void*)0, sizeof(global_conf));
  if (b == 1) blinkLED(15,20,1);
  #if defined(BUZZER)
    alarmArray[7] = 1; 
  #endif

}
Ejemplo n.º 9
0
typename std::iterator_traits<iterator>::value_type calculate_mean( iterator begin, iterator end )
{
    typedef typename std::iterator_traits<iterator>::value_type value_t;
    typedef typename std::iterator_traits<iterator>::difference_type diff_t;
    diff_t length = end - begin;
    value_t tmp = calculate_sum( begin, end );
    if ( length > 1 )
        tmp /= length;
    return tmp;
}
Ejemplo n.º 10
0
//Stores the WP data in the wp struct in the EEPROM
void storeWP() {
#ifdef MULTIPLE_CONFIGURATION_PROFILES
    #define PROFILES 3
#else
    #define PROFILES 1
#endif
	if (mission_step.number >254) return;
	mission_step.checksum = calculate_sum((uint8_t*)&mission_step, sizeof(mission_step));
	eeprom_write_block((void*)&mission_step, (void*)(PROFILES * sizeof(conf) + sizeof(global_conf)+(sizeof(mission_step)*mission_step.number)),sizeof(mission_step));
}
Ejemplo n.º 11
0
void readPLog(void) {
  eeprom_read_block((void*)&plog, (void*)(E2END - 4 - sizeof(plog)), sizeof(plog));
  if(calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
    blinkLED(9,100,3);
    SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_ELSE);
    // force load defaults
    plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 0;
    plog.running = 1;
    plog.lifetime = plog.armed_time = 0;
    writePLog();
  }
}
Ejemplo n.º 12
0
// Read the given number of WP from the eeprom, supposedly we can use this during flight.
// Returns true when reading is successfull and returns false if there were some error (for example checksum)
bool recallWP(uint8_t wp_number) {
#ifdef MULTIPLE_CONFIGURATION_PROFILES
    #define PROFILES 3
#else
    #define PROFILES 1
#endif
	if (wp_number > 254) return false;

	eeprom_read_block((void*)&mission_step, (void*)(PROFILES * sizeof(conf) + sizeof(global_conf)+(sizeof(mission_step)*wp_number)), sizeof(mission_step));
	if(calculate_sum((uint8_t*)&mission_step, sizeof(mission_step)) != mission_step.checksum) return false;

	return true;
}
Ejemplo n.º 13
0
void readPLog(void) {
  eeprom_read_block((void*)&plog, (void*)(E2END - 4 - sizeof(plog)), sizeof(plog));
  if(calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
    blinkLED(9,100,3);
    #if defined(BUZZER)
      alarmArray[7] = 3;
    #endif
    // force load defaults
    plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 0;
    plog.running = 1;
    plog.lifetime = plog.armed_time = 0;
    writePLog();
  }
}
Ejemplo n.º 14
0
void writeParams(uint8_t b) {
  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
  #if defined(BUZZER)
    alarmArray[7] = 1; //beep if loaded from gui or android
  #endif
}
Ejemplo n.º 15
0
bool readEEPROM() {
  uint8_t i;
  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  eeprom_read_block((void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  if(calculate_sum((uint8_t*)&conf, sizeof(conf)) != conf.checksum) {
    blinkLED(6,100,3);    
    #if defined(BUZZER)
      alarmArray[7] = 3;
    #endif
    LoadDefaults();                 // force load defaults 
    return false;                   // defaults loaded, don't reload constants (EEPROM life saving)
  }
  
  // 500/128 = 3.90625    3.9062 * 3.9062 = 15.259   1526*100/128 = 1192
    conf.rcExpo8 = 0;
    conf.rcRate8 = PITCH_ROLL_RC_RATE_AIR;

  for(i=0;i<5;i++) {
    lookupPitchRollRC[i] = (1526+conf.rcExpo8*(i*i-15))*i*(int32_t)conf.rcRate8/1192;
  }
  
  for(i=0;i<11;i++) {
    //conf.thrExpo8 = 0;
    //conf.thrMid8 = 0;
    int16_t tmp = 10*i-conf.thrMid8;
    uint8_t y = 1;
    if (tmp>0) y = 100-conf.thrMid8;
    if (tmp<0) y = conf.thrMid8;
    lookupThrottleRC[i] = 10*conf.thrMid8 + tmp*( 100-conf.thrExpo8+(int32_t)conf.thrExpo8*(tmp*tmp)/(y*y) )/10; // [0;1000]
    //lookupThrottleRC[i] = conf.minthrottle + (int32_t)(MAXTHROTTLE - conf.minthrottle)* lookupThrottleRC[i]/1000;  // [0;1000] -> [conf.minthrottle;MAXTHROTTLE]
    lookupThrottleRC[i] = conf.minthrottle + (int32_t)(maxThrottle-conf.minthrottle)* lookupThrottleRC[i]/1000;  // [0;1000] -> [conf.minthrottle;MAXTHROTTLE]
  }

  #if defined(POWERMETER)
    pAlarm = (uint32_t) conf.powerTrigger1 * (uint32_t) PLEVELSCALE * (uint32_t) PLEVELDIV; // need to cast before multiplying
  #endif
  #if GPS
    GPS_set_pids();    // at this time we don't have info about GPS init done
  #endif
  #if defined(ARMEDTIMEWARNING)
    ArmedTimeWarningMicroSeconds = (conf.armedtimewarning *1000000);
  #endif
  return true;    // setting is OK
}
Ejemplo n.º 16
0
/* average and standard deviation of a vector */
size_t average (size_t N, double *data, double *av) {
  double sum;
  double n = (double) N; /* cast to double */

  /* check that we have at least two values for the determination of standard deviation */
  if (N==0) {
    err_message ("Insufficient data to perform average\n");
    return MYLIB_FAIL;
  }

  /* sum */
  calculate_sum (N, data, &sum);

  /* calculate average and standard deviation */
  *av = _AVERAGE (n,sum);

  return MYLIB_SUCCESS;
}
Ejemplo n.º 17
0
void writeParams(uint8_t b) {
  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));

#if GPS
  writeGPSconf();  //Write GPS parameters
  recallGPSconf(); //Read it to ensure correct eeprom content
#endif

  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
  SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_1);
}
Ejemplo n.º 18
0
void do_sleep(int proc, size_t numDoubles)
{
    stk::CommSparse comm(MPI_COMM_WORLD);

    if(proc==0)
        ::usleep(workTimeProc0*1e6);
    else
        calculate_sum(workTimeProcOthers*1e6);

    std::vector<double> dataSent(numDoubles,1);
    std::vector<std::vector<double> > dataRecvd(comm.parallel_size());
    stk::pack_and_communicate(comm, [&comm, &dataSent]() { send_data_to_other_procs(dataSent, comm); });
    stk::unpack_communications(comm,
                               [&comm, &dataRecvd](int procId)
                               {
                                    stk::unpack_vector_from_proc(comm, dataRecvd[procId], procId);
                               });
}
Ejemplo n.º 19
0
bool readEEPROM() {
  uint8_t i;
  int8_t tmp;
  uint8_t y;

  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  eeprom_read_block((void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  if(calculate_sum((uint8_t*)&conf, sizeof(conf)) != conf.checksum) {
    blinkLED(6,100,3);    
    SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_ELSE);
    LoadDefaults();                 // force load defaults 
    return false;                   // defaults loaded, don't reload constants (EEPROM life saving)
  }
  // 500/128 = 3.90625    3.9062 * 3.9062 = 15.259   1526*100/128 = 1192
  for(i=0;i<5;i++) {
    lookupPitchRollRC[i] = (1526+conf.rcExpo8*(i*i-15))*i*(int32_t)conf.rcRate8/1192;
  }
  for(i=0;i<11;i++) {
    tmp = 10*i-conf.thrMid8;
    y = conf.thrMid8;
    if (tmp>0) y = 100-y;
    lookupThrottleRC[i] = 100*conf.thrMid8 + tmp*( (int32_t)conf.thrExpo8*(tmp*tmp)/((uint16_t)y*y)+100-conf.thrExpo8 );       // [0;10000]
    lookupThrottleRC[i] = conf.minthrottle + (uint32_t)((uint16_t)(MAXTHROTTLE-conf.minthrottle))* lookupThrottleRC[i]/10000;  // [0;10000] -> [conf.minthrottle;MAXTHROTTLE]
  }
  #if defined(POWERMETER)
    pAlarm = (uint32_t) conf.powerTrigger1 * (uint32_t) PLEVELSCALE * (uint32_t) PLEVELDIV; // need to cast before multiplying
  #endif
  #if GPS
    GPS_set_pids();    // at this time we don't have info about GPS init done
    recallGPSconf();   // Load gps parameters
  #endif
  #if defined(ARMEDTIMEWARNING)
    ArmedTimeWarningMicroSeconds = (conf.armedtimewarning *1000000);
  #endif
  return true;    // setting is OK
}
static image_reconstruct_ERROR_CODE
do_reconstruction(const image_filter_IMG* original,
                  const image_reconstruct_PARAMETERS* params,
                  image_filter_IMG* result)
{
  image_reconstruct_ERROR_CODE ret = IMAGE_RECONSTRUCT_OK;
  image_filter_FILTER row_filter = {0};
  image_filter_FILTER col_filter = {0};
  image_filter_IMG approx_row = {0};
  image_filter_IMG approx_col = {0};
  image_filter_IMG approx_diag = {0};
  image_filter_IMG tmp = {0};
  double row_mask[] = PREWITT_ROW_MASK;
  double col_mask[] = PREWITT_COL_MASK;


  image_filter_create_filter_by_mask(3,
                                     row_mask,
                                     &row_filter);
  image_filter_create_filter_by_mask(3,
                                     col_mask,
                                     &col_filter);
  image_filter_create_image(original->width,
                            original->height,
                            &approx_row);
  image_filter_create_image(original->width,
                            original->height,
                            &tmp);
  image_filter_create_image(original->width,
                            original->height,
                            &approx_col);
  image_filter_create_image(original->width,
                            original->height,
                            &approx_diag);
  if ((ret = prepare_image(original, params, &tmp))
             != IMAGE_AMPLIFIER_OK)
  {}
  else if ((ret = apply_filter(&tmp,
                               &row_filter,
                               &approx_row)) != IMAGE_RECONSTRUCT_OK)
  {}
  else if ((ret = apply_filter(&tmp,
                               &col_filter,
                               &approx_col)) != IMAGE_RECONSTRUCT_OK)
  {}

  if (ret == IMAGE_RECONSTRUCT_OK)
  {
    haar_transformation_DATA_SOURCE data;

    calculate_sum(&approx_col,
                  &approx_row,
                  NULL,
                  &approx_diag);
 
    data.width = original->width;
    data.height = original->height;
    data.original_image = result->content;
    data.avg_image = tmp.content;
    data.vertical_edges = approx_col.content;
    data.horizontal_edges = approx_row.content;
    data.diagonal_edges = approx_diag.content;

  /*  DUMPER_TRACE_IMAGE(data.avg_image, data.width, data.height);
    DUMPER_TRACE_IMAGE(data.vertical_edges, data.width, data.height);
    DUMPER_TRACE_IMAGE(data.horizontal_edges, data.width, data.height);
    DUMPER_TRACE_IMAGE(data.diagonal_edges, data.width, data.height);
    DUMPER_TRACE_IMAGE(tmp.content, data.width, data.height); */
    data.width *= 2;
    data.height *= 2;
    haar_transformation_inverse_transformation(data);
 /*   DUMPER_TRACE_IMAGE(data.original_image, data.width, data.height); */
  }

  image_filter_destroy_image(&approx_diag);
  image_filter_destroy_image(&tmp);
  image_filter_destroy_image(&approx_col);
  image_filter_destroy_image(&approx_row);
  image_filter_destroy_filter(&row_filter);
  image_filter_destroy_filter(&col_filter);

  return ret;
}
Ejemplo n.º 21
0
//Stores the WP data in the wp struct in the EEPROM
void storeWP() {
  if (mission_step.number >254) return;
  mission_step.checksum = calculate_sum((uint8_t*)&mission_step, sizeof(mission_step));
  eeprom_write_block((void*)&mission_step, (void*)(PROFILES * sizeof(conf) + sizeof(global_conf) + sizeof(GPS_conf) +(sizeof(mission_step)*mission_step.number)),sizeof(mission_step));
}
Ejemplo n.º 22
0
void writeGPSLog(uint32_t gpstime, int32_t latitude, int32_t longitude, int32_t altitude) {
#else
void writeGPSLog(int32_t latitude, int32_t longitude, int32_t altitude) {
#endif
if (f.SDCARD == 0) return;
  if (gps_data.open(GPS_LOG_FILENAME, O_WRITE | O_CREAT | O_APPEND)) {
#ifdef UBLOX  
    gps_data.print(gpstime); gps_data.write(',');
#endif
    gps_data.print(latitude); gps_data.write(',');
    gps_data.print(longitude); gps_data.write(',');
    gps_data.print(altitude); gps_data.println();
    gps_data.close();
  } else { 
    return;
  }
}

void writePLogToSD() {
  if (f.SDCARD == 0) return;
  plog.checksum = calculate_sum((uint8_t*)&plog, sizeof(plog));
  if (permanent.open(PERMANENT_LOG_FILENAME, O_WRITE | O_CREAT | O_TRUNC)) {
    permanent.print(F("arm=")); permanent.println(plog.arm);
    permanent.print(F("disarm=")); permanent.println(plog.disarm);
    permanent.print(F("start=")); permanent.println(plog.start);
    permanent.print(F("armed_time=")); permanent.println(plog.armed_time);
    permanent.print(F("lifetime=")); permanent.println(plog.lifetime, DEC);
    permanent.print(F("failsafe=")); permanent.println(plog.failsafe);
    permanent.print(F("i2c=")); permanent.println(plog.i2c);
    permanent.print(F("running=")); permanent.println(plog.running, DEC);
    permanent.print(F("checksum=")); permanent.println(plog.checksum, DEC);
    permanent.print(F("debug=")); permanent.print(debug[0]);
    permanent.print(F(",")); permanent.print(debug[1]);
    permanent.print(F(",")); permanent.print(debug[2]);
    permanent.print(F(",")); permanent.println(debug[3]);
    permanent.println();
    permanent.close();
  } else { 
    return;
  }
}

void fillPlogStruct(char* key, char* value) {
  if (strcmp(key, "arm") == 0) sscanf(value, "%u", &plog.arm);
  if (strcmp(key, "disarm") == 0) sscanf(value, "%u", &plog.disarm);
  if (strcmp(key, "start") == 0) sscanf(value, "%u", &plog.start);
  if (strcmp(key, "armed_time") == 0) sscanf(value, "%lu", &plog.armed_time);
  if (strcmp(key, "lifetime") == 0) sscanf(value, "%lu", &plog.lifetime);
  if (strcmp(key, "failsafe") == 0) sscanf(value, "%u", &plog.failsafe);
  if (strcmp(key, "i2c") == 0) sscanf(value, "%u", &plog.i2c);
  if (strcmp(key, "running") == 0) sscanf(value, "%hhu", &plog.running);
  if (strcmp(key, "checksum") == 0) sscanf(value, "%hhu", &plog.checksum);
}

void readPLogFromSD() {
  if (f.SDCARD == 0) return;
  SdFile myfile;
  char key[12];
  char value[32];
  char* tabPtr = key;
  int c;
  uint8_t i = 0;
   
  if (myfile.open(PERMANENT_LOG_FILENAME, O_READ)) {
    while (myfile.available()) {
      c = myfile.read();
      switch ((char)c) {
        case ' ':
          break;
        case '=':
          *tabPtr = '\0';
          tabPtr = value;
          break;  
        case '\n':
          *tabPtr = '\0';
          tabPtr = key;
          i = 0;
          fillPlogStruct(key, value);
          memset(key, '\0', sizeof(key));
          memset(value, '\0', sizeof(value));
          break;
        default:
          i++;
          if (i <= 12) {
            *tabPtr = (char)c;
            tabPtr++;
          }
          break;
        }
    }
  } else return;
  if (calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
#if defined(BUZZER)
    alarmArray[7] = 3;
    blinkLED(9, 100, 3);
#endif
    // force load defaults
    plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 11;
    plog.running = 1;
    plog.lifetime = plog.armed_time = 3;
    writePLogToSD();
  }
}
Ejemplo n.º 23
0
void writeGPSconf(void) {
  GPS_conf.checksum = calculate_sum((uint8_t*)&GPS_conf, sizeof(GPS_conf));
  eeprom_write_block( (void*)&GPS_conf, (void*) (PROFILES * sizeof(conf) + sizeof(global_conf)), sizeof(GPS_conf) );
}
Ejemplo n.º 24
0
void writePLog(void) {
  plog.checksum = calculate_sum((uint8_t*)&plog, sizeof(plog));
  eeprom_write_block((const void*)&plog, (void*)(E2END - 4 - sizeof(plog)), sizeof(plog));
}
Ejemplo n.º 25
0
int main (void)
{
	FILE *infile = NULL, *outfile = NULL;
	double	gpa1 = 0.0, gpa2 = 0.0, gpa3 = 0.0, gpa4 = 0.0, gpa5 = 0.0,
			age1 = 0.0, age2 = 0.0, age3 = 0.0, age4 = 0.0, age5 = 0.0,
			sum_gpa = 0.0, sum_class_standing = 0.0, sum_age = 0.0,
			mean_gpa = 0.0, mean_class_standing = 0.0, mean_age = 0.0,
			gpa1_dev = 0.0, gpa2_dev = 0.0, gpa3_dev = 0.0, gpa4_dev = 0.0, gpa5_dev = 0.0, 
			gpa_variance = 0.0, gpa_std_dev = 0.0, min_gpa = 0.0, max_gpa = 0.0;
	int 	id1 = 0, id2 = 0, id3 = 0, id4 = 0, id5 =0,
			class_standing1 = 0, class_standing2 = 0, class_standing3 = 0, class_standing4 = 0, class_standing5 = 0;	
			
	//Opens an input file "input.dat" for reading;
	infile = fopen ("input.dat", "r");
    //Opens an output file "output.dat" for writing;
	outfile = fopen ("output.dat", "w");
	//Reads five records from the input file (input.dat); You will need to use a combination of read_double ( ) and read_integer ( ) function calls here!
    id1 = read_integer (infile);
	gpa1 = read_double (infile);
	class_standing1 = read_integer (infile);
	age1 = read_double (infile);

	id2 = read_integer (infile);
	gpa2 = read_double (infile);
	class_standing2 = read_integer (infile);
	age2 = read_double (infile);

	id3 = read_integer (infile);
	gpa3 = read_double (infile);
	class_standing3 = read_integer (infile);
	age3 = read_double (infile);

	id4 = read_integer (infile);
	gpa4 = read_double (infile);
	class_standing4 = read_integer (infile);
	age4 = read_double (infile);

	id5 = read_integer (infile);
	gpa5 = read_double (infile);
	class_standing5 = read_integer (infile);
	age5 = read_double (infile);

	//Calculates the sum of the GPAs;
	sum_gpa = calculate_sum (gpa1, gpa2, gpa3, gpa4, gpa5);

    //Calculates the sum of the class standings;
	sum_class_standing = calculate_sum (class_standing1, class_standing2, class_standing3, class_standing4, class_standing5);

    //Calculates the sum of the ages;
	sum_age = calculate_sum (age1, age2, age3, age4, age5);

    //Calculates the mean of the GPAs, writing the result to the output file (output.dat);
	mean_gpa = calculate_mean (sum_gpa, 5);
	fprintf (outfile, "The mean GPA is %lf\n", mean_gpa);

    //Calculates the mean of the class standings, writing the result to the output file (output.dat);
	mean_class_standing = calculate_mean (sum_class_standing, 5);
	fprintf (outfile, "The mean class standing is %lf\n", mean_class_standing);

    //Calculates the mean of the ages, writing the result to the output file (output.dat);
	mean_age = calculate_mean (sum_age, 5);
	fprintf (outfile, "The mean age is %lf\n", mean_age);
 
    //Calculates the deviation of each GPA from the mean (Hint: need to call calculate_deviation ( ) 5 times)
    //Calculates the variance of the GPAs
    //Calculates the standard deviation of the GPAs, writing the result to the output file (output.dat);
 
    //Determines the min of the GPAs, writing the result to the output file (output.dat);
    //Determines the max of the GPAs, writing the result to the output file (output.dat);
 
    //Closes the input and output files (i.e. input.dat and output.dat)
	fclose (infile);
	fclose (outfile);

	return 0;
}
Ejemplo n.º 26
0
void writeGlobalSet(uint8_t b) {
  global_conf.checksum = calculate_sum((uint8_t*)&global_conf, sizeof(global_conf));
  eeprom_write_block((const void*)&global_conf, (void*)0, sizeof(global_conf));
  if (b == 1) blinkLED(15,20,1);
}