Esempio n. 1
0
void *runPeriodicTask (void *t){
  TaskInfo           s;      // self reference
  Time               c = 0;  // completion time
  Time               d = 0;  // deadline

  s = periodicTaskTable[*(int *)t];

  while (systemNotCompleted()){

    // Compute the deadline or the next activation
    d=nextActivation(s.period);

    putHeader (s.name);
    putString ("activated");
    newLine();

    // Simulate the execution of this task using
    // computeDuringTimeSpan. Provide the name of the task, its worst
    // case execution time, and the period of the task. ATTENTION :
    // the period parameter in computeDuringTimeSPan is used to
    // compute the execution priority. It returns the completion time
    // that should be used to check whether the task missed its
    // deadline. Use variable c to save this value. See tasks.h.


    //    NYI("compute task for its computation time");
    //********************************************************
      c = computeDuringTimeSpan(s.name, s.computation, s.period);
    
    //    NYI("save the completion time in variable c for later use");
    //********************************************************
    // c = timeAfterTimeSpan(s.computation);
    
    putHeader (s.name);
    putString ("completed");
    newLine();

    // Check that the completion time did not occur after the deadline
    if (d < c) {
      putHeader (s.name);
      putString ("OVERRUN ");
      putTime   (d);
      putString (" < ");
      putTime   (c);
      newLine();
      break;
    };

    // Wait for the next activation. In other words, wait for the deadline.
    // NYI("wait for the next activation");
    //**********************************************************
    delayUntil(d);

    
  }

  return NULL;
}
void ShowTaskInfo(Serial *serial, unsigned int argc, char **argv)
{
    putHeader(serial, "Task Info");

    serial->put_s("Status\tPri\tStackHR\tTask#\tName");
    put_crlf(serial);

    /*
     * Memory info from vTaskList can be misleading.  See
     * http://www.freertos.org/uxTaskGetSystemState.html for
     * more detail about how it works and value meanings.
     */
    char *taskList = (char *) portMalloc(1024);
    if (NULL != taskList) {
        vTaskList(taskList);
        serial->put_s(taskList);
        portFree(taskList);
    } else {
        serial->put_s("Out of Memory!");
    }
    put_crlf(serial);

    put_crlf(serial);
    serial->put_s("[Note] StackHR: If StackHR < 0; then stack smash");
    put_crlf(serial);
}
void HttpRequest::buildRequest(const std::string &req)
{
    std::stringstream ss;

    ss << req;

    std::string temp;
    std::getline(ss, temp);

    request = temp;

    while(std::getline(ss, temp) && temp.find(":") != std::string::npos)
    {
        std::string key = temp.substr(0, temp.find_first_of(":"));
        std::string value = temp.substr(temp.find_first_of(" ") + 1);
        putHeader(key, value);
    }

    if(headers.find("Content-Length") != headers.end())
    {
        int len = std::stoi(headers["Content-Length"]);
        body = req.substr(req.size()-len);
    }
    else
    {
        while(std::getline(ss, temp))
        {
            body += temp;
        }
    }

    putBody(body);
}
void GetVersion(Serial *serial, unsigned int argc, char **argv)
{
    putHeader(serial, "Version Info");
    put_nameString(serial, "major", MAJOR_REV_STR);
    put_nameString(serial, "minor", MINOR_REV_STR);
    put_nameString(serial, "bugfix", BUGFIX_REV_STR);
    put_nameString(serial, "serial", cpu_get_serialnumber());
    put_crlf(serial);
}
void ShowStats(Serial *serial, unsigned int argc, char **argv)
{
    // Memory Info
    putHeader(serial, "Memory Info");

    putDataRowHeader(serial, "Total Memory");
    put_uint(serial, (unsigned int) &_CONFIG_HEAP_SIZE);
    put_crlf(serial);

    putDataRowHeader(serial, "Free Memory");
    put_uint(serial, portGetFreeHeapSize());
    put_crlf(serial);

    // LUA Info
    putHeader(serial, "Lua Info");

    //TODO: this was done for unit testing. fix when Lua runtime is part of unit testing framework
    lua_State *L = (lua_State *) getLua();
    lua_gc(L, LUA_GCCOLLECT, 0);

    putDataRowHeader(serial, "Lua Top");
    put_int(serial, lua_gettop(L));
    put_crlf(serial);

    putDataRowHeader(serial, "Lua Memory Usage (KB)");
    put_int(serial, lua_gc(L, LUA_GCCOUNT, 0));
    put_crlf(serial);

    // Misc Info
    putHeader(serial, "Misc");

    putDataRowHeader(serial, "Size of LoggerConfig");
    put_int(serial, sizeof(LoggerConfig));
    put_crlf(serial);

    putDataRowHeader(serial, "Size of ChannelSample");
    put_int(serial, sizeof(ChannelSample));
    put_crlf(serial);
}
Esempio n. 6
0
void
writeHeader(char *label)
{
	PaqHeader hdr;
	uchar buf[HeaderSize];

	memset(&hdr, 0, sizeof(hdr));
	hdr.magic = HeaderMagic;
	hdr.version = Version;
	hdr.blocksize = blocksize;
	hdr.time = time(nil);
	strncpy(hdr.label, label, sizeof(hdr.label));
	hdr.label[sizeof(hdr.label)-1] = 0;
	putHeader(buf, &hdr);
	outWrite(buf, sizeof(buf));
}
Esempio n. 7
0
static int UpdateHdr (char *output) {

    extern int status;

    Hdr phdr;               /* primary header */
    IODescPtr im;		/* descriptor for output image */

    int PutKeyBool (Hdr *, char *, Bool, char *);

    sprintf(MsgText, "Trying to open %s...",output);
    trlmessage (MsgText);

    initHdr (&phdr);

    /* Open input image in order to read its primary header. */
    im = openUpdateImage (output, "", 0, &phdr);				
    if (hstio_err()) {
        trlopenerr (output);
        closeImage(im);
        return (status = OPEN_FAILED);
    }

    if (PutKeyBool (&phdr, "ASN_PROD", True, "") ) {
        freeHdr (&phdr);
        trlerror ("Couldn't update ASN_PROD keyword in ASN table header");
        return(status = KEYWORD_MISSING);
    }

    /* write out primary header */
    if (putHeader (im))
        status = HEADER_PROBLEM;	
    if (hstio_err() || status) {
        trlreaderr (output);
        closeImage (im);
        return (status = OPEN_FAILED);
    }

    closeImage (im);
    /* Close the ASN table's primary header. */
    freeHdr (&phdr);

    sprintf(MsgText, "Updated Global Header for %s...",output);
    trlmessage (MsgText);

    return (status);

}
Esempio n. 8
0
void dec_prepare_output_file (FILE *fp)
{
     if(putHeader(input_file_header, fp)){
        ERROR("putHeader");
     }
   
    uint32_t k = 0, **vector = NULL, *size_vector;

    vector = calloc(input_file_header->numChannels, sizeof(uint32_t *));
    size_vector = calloc(input_file_header->numChannels, sizeof(uint32_t));

    for(curr_channel=0; curr_channel<input_file_header->numChannels; curr_channel++) {
        size_vector[curr_channel] = b_to_uint32(&output_buffer[curr_channel], &vector[curr_channel], input_file_header->bitsPerSample, 0);
    }

    for (k=0; k<size_vector[0]; k++){
        for(curr_channel=0; curr_channel<input_file_header->numChannels; curr_channel++) {
            switch (input_file_header->bitsPerSample/8){
            case 1:
                if ( write_1_byte32(fp, &vector[curr_channel][k], input_file_header->endianness)){
                    printf("ERROR: io chunkSize\n");
                }break;
            case 2:
                if (write_2_bytes32(fp, &vector[curr_channel][k], input_file_header->endianness)) {
                    printf("ERROR: io chunkSize\n");
                }break;   
            case 3:
                if (write_3_bytes(fp, &vector[curr_channel][k], input_file_header->endianness)) {
                    printf("ERROR: io chunkSize\n");
                }break;   
            case 4:
                if (write_4_bytes(fp, &vector[curr_channel][k], input_file_header->endianness)) {
                    printf("ERROR: io chunkSize\n");
                }   
            }   
        }
    }

    for(curr_channel=0; curr_channel<input_file_header->numChannels; curr_channel++) {
        
        /*bprint(&output_buffer[curr_channel]);*/
        if(output_vector[curr_channel])
                free(output_vector[curr_channel]);
        if(data_vector[curr_channel])
                free(data_vector[curr_channel]);
        bdestroy(&output_buffer[curr_channel]);
        bdestroy(&data_buffer[curr_channel]);
        if(frequencies && frequencies[curr_channel])
            free(frequencies[curr_channel]);
        if(vector[curr_channel])
            free(vector[curr_channel]);
    }
    free(size_vector);
    free(vector);
    if(nbits_run)
        free(nbits_run);
    if(nbits_code)
        free(nbits_code);
    if(firsts)
        free(firsts);
    if(max_bits)
        free(max_bits);
    if(frequencies)
        free(frequencies);
    free(data_buffer);
    free(data_vector);
    free(output_buffer);
    free(output_vector);
    free(input_file_header);
}
Esempio n. 9
0
int main (int    argc,
	  char** argv)
// ---------------------------------------------------------------------------
// Driver.
// ---------------------------------------------------------------------------
{
  char              *session, *dump, *points = 0;
  int_t             NP, NZ,  NEL;
  int_t             np, nel, ntot;
  int_t             i, j, k, nf, step;
  ifstream          fldfile;
  istream*          pntfile;
  FEML*             F;
  Mesh*             M;
  real_t            c, time, timestep, kinvis, beta;
  vector<real_t>    r, s;
  vector<Point*>    point;
  vector<Element*>  elmt;
  vector<Element*>  Esys;
  vector<AuxField*> u;

  // -- Initialize.

  Femlib::initialize (&argc, &argv);
  getargs            (argc, argv, session, dump, points);

  fldfile.open (dump, ios::in);
  if (!fldfile) message (prog, "no field file", ERROR);

  // -- Set up 2D mesh information.
  
  F   = new FEML (session);
  M   = new Mesh (F);

  NEL = M -> nEl();  
  NP  = Femlib::ivalue ("N_P");
  NZ  = Femlib::ivalue ("N_Z");
  
  Geometry::set (NP, NZ, NEL, Geometry::Cartesian);
  Esys.resize   (NEL);

  for (k = 0; k < NEL; k++) Esys[k] = new Element (k, NP, M);
  
  // -- Construct the list of points, then find them in the Mesh.

  if (points) {
    pntfile = new ifstream (points);
    if (pntfile -> bad())
      message (prog, "unable to open point file", ERROR);
  } else 
    pntfile = &cin;

  np = nel = ntot = 0;

  loadPoints (*pntfile, np, nel, ntot, point);
  findPoints (point, Esys, elmt, r, s);

  // -- Load field file, interpolate within it.

  cout.precision (8);
  while (getDump (fldfile, u, Esys, NP, NZ, NEL,
		  step, time, timestep, kinvis, beta)) {

    if (np) putHeader (session, u,  np, NZ, nel,
		       step, time, timestep, kinvis, beta);

    nf = u.size();
    for (k = 0; k < NZ; k++)
      for (i = 0; i < ntot; i++) {
	for (j = 0; j < nf; j++) {
	  if   (elmt[i]) c = u[j] -> probe (elmt[i], r[i], s[i], k);
	  else           c = 0.0;
	  cout << setw(15) <<  c;
	}
	if (verbose && !((i + 1)% nreport))
	  cerr 
	    << "interp: plane " << k + 1 << ", "
	    << i + 1 << " points interpolated" << endl;
	cout << endl;
      }
  }

  Femlib::finalize();
  return EXIT_SUCCESS;
}
Esempio n. 10
0
/* This routine copies a FITS file. */
static int CopyFFile (char *infile, char *outfile) {

    /* arguments:
       infile    i: name of input file
       outfile   i: name of output file
    */

    extern int status;

    FILE *ifp, *ofp;  /* for input and output files */
    void *buf;        /* buffer for copying blocks */
    int nin, nout;    /* number read and written */
    int done;
    IODescPtr im;
    Hdr phdr;

    /* function from lib */
    void UFilename (char *, Hdr *);

    if ((buf = calloc (FITS_BUFSIZE, sizeof(char))) == NULL)
        return (status = OUT_OF_MEMORY);

    if ((ofp = fopen (outfile, "wb")) == NULL) {
        sprintf (MsgText,"Can't create temporary file %s.", outfile);
        trlerror(MsgText);
        free (buf);
        return (status = INVALID_TEMP_FILE);
    }

    if ((ifp = fopen (infile, "rb")) == NULL) {
        sprintf (MsgText, "Can't open %s.", infile);
        trlerror (MsgText);
        (void)fcloseWithStatus(&ofp);
        remove (outfile);
        free (buf);
        return (status = OPEN_FAILED);
    }

    done = 0;
    while (!done) {
        nin = fread (buf, sizeof(char), FITS_BUFSIZE, ifp);
        if (ferror (ifp)) {
            sprintf (MsgText, "Can't read from %s (copying to %s).",
            infile, outfile);
            trlerror (MsgText);
            (void)fcloseWithStatus(&ofp);
            (void)fcloseWithStatus(&ifp);
            free (buf);
            return (status = FILE_NOT_READABLE);
        }
        if (feof (ifp))
            done = 1;

        nout = fwrite (buf, sizeof(char), nin, ofp);
        if (nout < nin) {
            sprintf (MsgText, "Can't copy %s to %s.", infile, outfile);
            trlerror (MsgText);
            (void)fcloseWithStatus(&ofp);
            (void)fcloseWithStatus(&ifp);
            free (buf);
            return (status = COPY_NOT_POSSIBLE);
        }
    }

    (void)fcloseWithStatus(&ofp);
    (void)fcloseWithStatus(&ifp);
    free (buf);

    /* Update the FILENAME keyword in the primary header of the output file. */
    initHdr (&phdr);
    im = openUpdateImage (outfile, "", 0, &phdr);
    UFilename (outfile, &phdr);
    putHeader (im);

    closeImage (im);
    freeHdr (&phdr);

    return (status);
}
Esempio n. 11
0
int TargPos (StisInfo12 *sci, int extver, double shift1, double shift2) {

/* arguments:
StisInfo12 *sci        i: info about science data file
int extver             i: EXTVER number of extensions to update
double shift1, shift2  i: shift to be assigned to SHIFTAi keywords
*/

	int status;

	IODescPtr im;		/* descriptor for an image */
	Hdr hdr;		/* header for an extension */

	/* Update SCI extension. */

	initHdr (&hdr);
	im = openUpdateImage (sci->input, "SCI", extver, &hdr);
	if (hstio_err())
	    return (OPEN_FAILED);

	/* Update SHIFTAi. */
	if ((status = UpdateShift (&hdr, shift1, shift2)))
	    return (status);

	putHeader (im);
	if (hstio_err())
	    return (OPEN_FAILED);
	closeImage (im);
	freeHdr (&hdr);

	/* Update ERR extension. */

	im = openUpdateImage (sci->input, "ERR", extver, &hdr);
	if (hstio_err())
	    return (OPEN_FAILED);

	if ((status = UpdateShift (&hdr, shift1, shift2)))
	    return (status);

	putHeader (im);
	if (hstio_err())
	    return (OPEN_FAILED);
	closeImage (im);
	freeHdr (&hdr);

	/* Update DQ extension. */

	im = openUpdateImage (sci->input, "DQ", extver, &hdr);
	if (hstio_err())
	    return (OPEN_FAILED);

	if ((status = UpdateShift (&hdr, shift1, shift2)))
	    return (status);

	putHeader (im);
	if (hstio_err())
	    return (OPEN_FAILED);
	closeImage (im);
	freeHdr (&hdr);

	/* write to trailer */
	if (fabs (shift1) < MUCH_TOO_BIG)	/* shift is OK */
	    printf ("         SHIFTA1 set to %.6g\n", shift1);
	if (fabs (shift2) < MUCH_TOO_BIG)
	    printf ("         SHIFTA2 set to %.6g\n", shift2);

	return (0);
}
Esempio n. 12
0
void *runPollingServer (void *t){
  TaskInfo           s;
  EventInfo          e;
  TimeSpan           c = 0;
  Time               d = 0;
  int                i;
  
  s = periodicTaskTable[*(int *)t];

  // Schedule the initial replenishment event
  e.kind        = PRODUCE;
  e.name        = s.name;
  e.activation  = nextActivation (s.period);
  e.computation = s.computation;
  s.computation = 0;
  appendEvent (e);

  // Print the event pushed in the queue
  putHeader (s.name);
  putString ("@");
  putTime   (e.activation);
  putString (" ");
  putString (s.name);
  putString ("=+");
  putTime   (e.computation);
  newLine ();

  while (systemNotCompleted () && (0 <= lastEvent)) {
    e = getEvent (firstEvent);

    // When the first event to handle happens in the future, release the
    // server budget
    // NYI("if next event happens in the future, release the server budget"); recharger
    //**********************************************************************
    if ((((localClock() + 10000) / s.period) * s.period) < e.activation){
	s.computation = 0;
     }
   
    // Before handling next event check the server budget is not empty
    if (s.computation == 0) {

      // Look for the first PRODUCE event
      for (i=firstEvent; i <= lastEvent; i++){
	e = getEvent(i);
	if (e.kind == PRODUCE) {
	  if (systemCompletedAt (e.activation)) {
	    return NULL;
	  }

	  // Remove PRODUCE event and then wait for its activation time.
	  //  NYI("remove event and wait for its activation");
	  //****************************************************************
	  removeEvent(i);
	  delayUntil(e.activation);

	  
	  // Update the server budget and schedule the next PRODUCE
	  // event. To do so compute the next activation time and the
	  // computation time related to this replenishment event.
	  // NYI("update server budget and schedule replenishment");
	  //******************************************************************
	  s.computation = e.computation;
	  e.activation  = nextActivation (s.period);
	  appendEvent (e);

	  
	  // Print the arrival of this event
	  putHeader (s.name);
	  putString (s.name);
	  putString ("=+");
	  putTime   (e.computation);
	  newLine ();

	  // Print the event pushed in the queue
	  putHeader (s.name);
	  putString ("@");
	  putTime   (e.activation);
	  putString (" ");
	  putString (s.name);
	  putString ("=+");
	  putTime   (e.computation);
	  newLine ();
      
	  break;
	}
      }
    }

    e = getEvent (firstEvent);
    if (systemCompletedAt (e.activation)){
      return NULL;
    }

    if (e.kind == PRODUCE) {
      // Remove PRODUCE event and then wait for its activation time
      // NYI("remove event and wait for its activation time");
      //*******************************************************************
      removeEvent(firstEvent);
      delayUntil(e.activation);

      
      // As there are no Consume events to handle, the server discards
      // its budget. But it schedules its replenishment.
      //  NYI ("update server budget and schedule its replenishment");
      //***************************************************************
      s.computation = e.computation;
      e.activation  = nextActivation (s.period);
      appendEvent (e);

      // Print the event pushed in the queue
      putHeader (s.name);
      putString ("@");
      putTime   (e.activation);
      putString (" ");
      putString (s.name);
      putString ("=+");
      putTime   (e.computation);
      newLine ();
      
    } else {

      // Wait for event activation
      // NYI("wait for event activation");
      delayUntil(e.activation);
      

      // Evaluate the computation time needed to handle this
      // event that is the computation time requested and the
      // one available on the server.
      // NYI ("evaluate computation time for event");
      //***********************************************
      c = e.computation;
      
      // Update computation time needed to complete event in queue.
      // Remove the event once it is completed.
      // Do not update server budget yet.
      // We want to print the server status before and after this operation.
      // NYI("evaluate remaining computation time of current event");
      // NYI("remove event when completed");
      //NYI("update event in queue when not completed");
      //***********************************************************************

      if (e.computation <= s.computation){
	e.computation = 0;
	removeEvent(firstEvent);
      }else{
	removeEvent(firstEvent);
	 e.computation = e.computation - s.computation;
	 e.activation  = e.activation + 1;
	 appendEvent (e);
	 c = s.computation;
      }
      
      // Print status of both server and event status
      putHeader    (s.name);
      putString    (s.name);
      putString    ("=");
      putTime      (s.computation);
      putString    ("-");
      putTime      (c);
      putString    (" ");
      putString    (e.name);
      putString    ("=");
      putTime      (e.computation);
      newLine ();
      
      // Update the server budget after this operation.
      
      // Simulate the execution of this event using
      // computeDuringTimeSpan. Provide the name of the event, its
      // worst case execution time, and the period of the server.
      // ATTENTION : the period parameter in computeDuringTimeSPan is
      // used to compute the execution priority. See tasks.h.
      //   NYI("update server budget");
      //  NYI("compute event");
      if (e.computation > 0){
	computeDuringTimeSpan(e.name, s.computation, s.period);
	s.computation = 0;
      }else{
	computeDuringTimeSpan(e.name, c, s.period);
	s.computation -= c;
      }
      
      

      // Print event completion if needed
      if (e.computation == 0) {
	putHeader    (s.name);
	putString    ("completed ");
	putString    (e.name);
	newLine ();
      }
    }
  }

  return NULL;
}