示例#1
0
uint16 NodeEeprom::readEeprom(uint16 location)
{
    uint16 result;

    bool canCacheEeprom = NodeEepromMap::canUseCache_read(location);

    //if we want to pull from the cache
    if(m_useCache && canCacheEeprom)
    {
        //attempt to read the value from the cache
        if(readCache(location, result))
        {
            //the value was found in the cache, just return the result
            return result;
        }
    }

    //we didn't get a value from the cache

    //attempt to read the value from the device
    if(updateCacheFromDevice(location, canCacheEeprom))
    {
        //successfully read from the device, the cache has been updated so read from it
        readCache(location, result);

        return result;
    }

    //we failed to read the eeprom value from the cache or the device
    throw Error_NodeCommunication(m_nodeAddress, "Failed to read EEPROM " + Utils::toStr(location) + " from Node " + Utils::toStr(m_nodeAddress));
}
示例#2
0
void calculateTime(int size){
        long length=size;
        long indexAt8K=size/2;

        unsigned t1 = 0;
        unsigned t2 = 0;
        unsigned t3 = 0;
        int i =0;
        for(i = 0;i < LOOPNUMBER;i++){

        long cacheLength=pow(2,20)/4;// length = 16K
        int *a ;
        unsigned adj;
        adj = 32 - ((unsigned)a%32);
a = a +adj;
        a=(int *)malloc(sizeof(int)*cacheLength);
        long j;
        for(j=0;j<cacheLength;j++){
                a[j]=0;
        }
        t1=readCache(a,0,indexAt8K);
        t2=readCache(a,indexAt8K,length);
        t3=readCache(a,0,indexAt8K);
        printf("%10u   %10u   %10u\n", t1,t2,t3);
        }
}
示例#3
0
uint32_t ScomRegister::ForceRead() const
{
    #define PRDF_FUNC "[ScomRegister::ForceRead] "

    uint32_t o_rc = FAIL;

    do
    {
        // No read allowed if register access attribute is write-only or no
        // access.
        if ( ( ACCESS_NONE == iv_operationType ) &&
                ( ACCESS_WO == iv_operationType ) )
        {
            PRDF_ERR( PRDF_FUNC"Write-only register: 0x%08x 0x%016llx",
                      getChip()->GetId(), iv_scomAddress );
            break;
        }

        // Read hardware.
        o_rc = Access( readCache(), MopRegisterAccess::READ );
        if ( SUCCESS != o_rc )
        {
            // The read failed. Remove the entry from the cache so a subsequent
            // Read() will attempt to read from hardware again.
            flushCache( getChip() );
        }

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}
示例#4
0
/**
* Retrieve the next token byte from the command buffer.
* Used to grab arguments for commands
*/
char CommandHandler::next() {
	char next = 0;

	if (isCacheAvailable()){
		next = readCache();
	}

	return next;
}
示例#5
0
bool NodeEeprom::determineReadWriteVersion()
{
    uint8 originalVersion = m_readWriteVersion;

    uint16 fwVersionEeprom = NodeEepromMap::FIRMWARE_VER.location();
    uint16 fwValue = 0;

    //check if the value is already in the cache
    if(m_eepromCache.find(fwVersionEeprom) == m_eepromCache.end())
    {
        //value was not found in the cache

        //set the version to 2
        m_readWriteVersion = 2;

        //try to read using v2
        if(!updateCacheFromDevice(fwVersionEeprom))
        {
            //failed to read with version 2

            //set the version to 1
            m_readWriteVersion = 1;

            //try to read using v1
            if(!updateCacheFromDevice(fwVersionEeprom, false))
            {
                //failed to read with version 1

                //set the read/write version back to its original value
                m_readWriteVersion = originalVersion;

                return false;
            }
        }
    }

    //if we got here, we successfully got the firmware version somewhere

    //value was updated in the cache successfully, now read it out
    readCache(fwVersionEeprom, fwValue);

    //build the fw version currently found on the node
    Version fwVersion(Utils::msb(fwValue), Utils::lsb(fwValue));

    static const Version MIN_FW_EEPROM2(8, 21);

    if(fwVersion >= MIN_FW_EEPROM2)
    {
        m_readWriteVersion = 2;
    }
    else
    {
        m_readWriteVersion = 1;
    }

    return true;
}
示例#6
0
const BIT_STRING_CLASS * ScomRegister::GetBitString(ATTENTION_TYPE i_type) const
{
    // Calling Read() will ensure that an entry exists in the cache and the
    // entry has at been synched with hardware at least once. Note that we
    // cannot read hardware for write-only registers. In this case, an entry
    // will be created in the cache, if it does not exist, when readCache() is
    // called below.
    if ( ( ACCESS_NONE != iv_operationType ) &&
            ( ACCESS_WO != iv_operationType ) )
    {
        Read();
    }
    return &(readCache());
}
示例#7
0
void NodeEeprom::writeEeprom(uint16 location, uint16 value)
{
    //if we want to check the cache
    if(m_useCache && NodeEepromMap::canUseCache_write(location))
    {
        //attempt to read the value from the cache
        uint16 valInCache;
        if(readCache(location, valInCache))
        {
            //if the value in the cache is the same we are trying to write
            if(valInCache == value)
            {
                //do not need to write anything, just return
                return;
            }
        }
    }

    //if we made it here, we want to actually write to the device

    //if the read/write version is unknown
    if(m_readWriteVersion == 0)
    {
        //try to determine the version of the read/write eeprom cmd
        if(!determineReadWriteVersion())
        {
            //failed to get the read/write version
            throw Error_NodeCommunication(m_nodeAddress, "Failed to write EEPROM " + Utils::toStr(location) + " to Node " + Utils::toStr(m_nodeAddress));
        }
    }

    //attempt to write the value to the Node
    if(m_baseStation.node_writeEeprom(m_readWriteVersion, m_nodeAddress, location, value))
    {
        //successfully wrote to the Node, update the cache
        updateCache(location, value);

        return;
    }

    //we failed to write the value to the Node

    //clear the eeprom cache for this location if we have one, just to be safe
    clearCacheLocation(location);

    throw Error_NodeCommunication(m_nodeAddress, "Failed to write EEPROM " + Utils::toStr(location) + " to Node " + Utils::toStr(m_nodeAddress));
}
示例#8
0
/**
* Process the buffer to find commands
*/
void CommandHandler::processCommands(){
	while (isCacheAvailable()){
		char command = readCache();
		int commandSlot = findCommand(command);
	
		// Command found; do the thing
		if (commandSlot >= 0){
			_commandList[commandSlot].function();
			
		}
		// Command not found; do the default thing
		else{
			(*defaultHandler)(command);
		}
	}
	clearCache();
}
int main(void)
{
	eLibrary_CLT_registerClient();
	for (;;)
	{
		eLibrary_CLT_createRequest(str, &request);
		cache_hit = readCache(request, &response);
		if (false == cache_hit)
		{
			eLibrary_CLT_getResponse();
		}
		fillCache(response);
		writeOutput();

		freeResponse();
	}
	eLibrary_CLT_destroyClient();
}
示例#10
0
uint32_t ScomRegister::Write()
{
    #define PRDF_FUNC "[ScomRegister::Write] "

    uint32_t o_rc = FAIL;

    do
    {
        // No write allowed if register access attribute is read-only or no
        // access.
        if ( ( ACCESS_NONE == iv_operationType ) &&
                 ( ACCESS_RO == iv_operationType ) )
        {
            PRDF_ERR( PRDF_FUNC"Read-only register: 0x%08x 0x%016llx",
                      getChip()->GetId(), iv_scomAddress );
            break;
        }

        // Query the cache for an existing entry.
        if ( !queryCache() )
        {
            // Something bad happened and there was nothing in the cache to
            // write to hardware.
            PRDF_ERR( PRDF_FUNC"No entry found in cache: 0x%08x 0x%016llx",
                      getChip()->GetId(), iv_scomAddress );
            break;
        }

        // Write hardware.
        o_rc = Access( readCache(), MopRegisterAccess::WRITE );

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}
示例#11
0
int
main (int argc, char** argv)
{
  // const char trace = 0;
  // const unsigned debug = 0;
  const char *me = "main";

  // parse and validate the command line options
  struct paramsStruct params;
  parseCommandLine(argc, argv, &params);

  // create results directory in ANALYSIS directory
  // permissions are read, write for the owner
  char resultsDirectoryName[256] = "";
  makeResultsDirectory(resultsDirectoryName, 
                       sizeof(resultsDirectoryName), 
                       &params);

  // start logging
  char logFilePath[256] = "";
  {
    const int outputLength =  snprintf(logFilePath, 
                                       sizeof(logFilePath), 
                                       "%s/run.log", 
                                       resultsDirectoryName);
    if (outputLength > (int) sizeof(logFilePath)) {
      fprintf(stderr, "%s: logFilePath too small", me);
      exit(1);
    }
  }
  Log_T log = Log_new(logFilePath, stderr);

  // log the command line parameters
  LOG(log,"started log file %s\n", logFilePath);

  LOG(log,"params: algo=%s\n",          params.algo);
  LOG(log,"      : obs=%s\n",           params.obs); 
  LOG(log,"      : radius=%d\n",        params.radius);
  LOG(log,"      : which=%s\n",         params.which);
  
  // check the command line parameters
  assert(strcmp(params.algo, "knn") == 0); 
  assert(strcmp(params.obs, "1A") == 0);
 
  // read the input files
  const unsigned nObservations = 217376;  // adjust of OBS != 1A
  const unsigned nFeatures = 55;

  double *apns = readCsvNoHeader(nObservations, "aps.csv");
  double *dates = readCsvNoHeader(nObservations, "date.csv");
  char   *featuresHeaderP;
  double *features = readFeatures(nObservations, 
				  nFeatures,
				  &featuresHeaderP);
  double *prices = readCsvNoHeader(nObservations, "SALE-AMOUNT-log.csv");

  // convert dates to days past the epoch
  unsigned dayStdColumn = 5; // the 6th column contains the standardized day value
  assert(columnHeaderEqual(featuresHeaderP, dayStdColumn, "day-std"));  
  double *days = convertDatesToDays(nObservations, dates);
  free(dates);
  double mean;
  double stdv;
  determineMeanStdv(nObservations, days, &mean, &stdv);
  double *daysStd = standardize(nObservations, days, mean, stdv);
  replaceDay(nObservations, nFeatures, features, daysStd, dayStdColumn);
  free(days);
  free(daysStd);


  // generate one set of estimates
  FILE *resultFile;
  {
    char resultFilePath[256];
    const int outputLength = 
      snprintf(resultFilePath,
               sizeof(resultFilePath),
               "%s/estimates-laufer.csv",
               resultsDirectoryName);
    if (outputLength > (int) sizeof(resultFilePath)) {
      fprintf(stderr, "%s: resultFilePath too small", me);
      exit(1);
    }
    LOG(log, " result file path: %s\n", resultFilePath);
    resultFile = fopen(resultFilePath, "w");
  }
  assert(resultFile);

  if (strcmp(params.which, "laufer"))
    createLaufer(nObservations, nFeatures, 
		 apns, dates, features, prices,
		 log,
		 resultFile);
  else
    assert(NULL != "logic error");

  // OLD CODE BELOW THIS LINE
#if 0
  double **pricesHatP = NULL;
  if (params.useCache)
    pricesHatP = readCache(nObservations, params.obs, log, kMax);

  // determine estimated prices for any missing entries in the cache
  // this operation could be fast or very slow
  // MAYBE: write out cache periodically 
  const unsigned cacheMutated = completeCache(nObservations, 
                                              pricesHatP, 
                                              params.obs, 
                                              log, 
                                              kMax, 
                                              pricesP, 
                                              debug);

  if (params.useCache && cacheMutated)
    writeCache(nObservations, pricesHatP, params.obs, log, kMax);


  // select which set of estimates to create
  if (paramsP->whichIsLaufer)
    createEstimatesLaufer(nObservations, nFeatures,
			  features, dates, prices);
  else
    assert(false); // should never get here

  // pricesHatP[i][k] is
  // the estimate priced of transaction indexed i for k nearest neighbors

  // for each value of k, determine RMSE overall all the test transactions
  // determine kArgMin, the k providing the lowest RMSE
  // write CSV containing <k, rmse> values
  char resultFilePath[256];
  {
    const int outputLength = 
      snprintf(resultFilePath,
               sizeof(resultFilePath),
               "%s/k-rmse.csv",
               directoryName);
    if (outputLength > (int) sizeof(resultFilePath)) {
      fprintf(stderr, "%s: resultFilePath too small", me);
      exit(1);
    }
    LOG(log, " result file path: %s\n", resultFilePath);
  }
  FILE *resultFile = fopen(resultFilePath, "w");
  assert(resultFile);

  // log best k for random sample of test observations
  bestK(0.01, nObservations, pricesHatP, pricesP, log, kMax);

  // write CSV header 
  fprintf(resultFile, "k,rmse\n");
  unsigned kArgMin = 0;
  double lowestRMSE = DBL_MAX;
  for (unsigned hpK = 0; hpK < kMax; hpK++) {

    // determine rmse for this k
    const double rmse = determineRmse(nObservations, pricesHatP, pricesP, hpK);

    // check if we have a new best k
    LOG(log, "hpK %u rmse %f\n", hpK + 1, rmse);
    fprintf(resultFile, "%u,%f\n", hpK + 1, rmse);
    if (rmse < lowestRMSE) {
      lowestRMSE = rmse;
      kArgMin = hpK;
    }
  }

#endif
  // 
  LOG(log, "%s\n", "finished");

  exit(0);
}