Beispiel #1
0
int CSegDisplay::UpdateDisplay(const char* displayString, const unsigned length, const int index, const bool bDisplayColon) {

	char buffer[17];

	// convert the string before writing to the display
	convertStr(buffer, displayString, length, index, bDisplayColon);

	// Set slave address
	if (ioctl(m_fd, I2C_SLAVE, 0x70) < 0) {

		// If there was an error, attempt to reinitialize the display
		Init();

		usleep(100);

		// Reattempt to use the device
		if (ioctl(m_fd, I2C_SLAVE, 0x70) < 0) {
			perror("ioctl");
			fprintf(stderr, "Failed to set i2c slave address of the display\n");
			return -1;
		}
	}

	// Send the command and check the result code
	if (write(m_fd, buffer, 17) != 17) {
		perror("Update i2c Display");
		return -2;
	}
}
Beispiel #2
0
int FeaturesTable::LoadDataSet() {
	std::vector<std::string> fNames;
	std::string pattern("Class*");
	TraverseDirectory(Folder, pattern, false, fNames);

	size_t numFeatures = size_t(-1);
	CumSamplesPerClass.assign(fNames.size()+1,0);
	ClassDistribution.assign(fNames.size(), 0);
	// ClassDistributionSize = fNames.size();
	// ClassDistribution = new size_t[ClassDistributionSize];
	// std::fill(ClassDistribution, ClassDistribution + ClassDistributionSize, 0);
	std::string delimStr = "\t";
	for(size_t k=0;k<fNames.size();++k) {
		// std::cout << fNames[k] << std::endl;
		std::ifstream ifs(fNames[k].c_str(), std::ios_base::in);
		std::string line;
		while(!ifs.eof()) {
			line.clear();
			std::getline(ifs, line, '\n');
			std::vector<double>* L = new std::vector<double>;
			size_t tmpNumFeatures = convertStr(*L,line, delimStr, false);
			if(numFeatures==size_t(-1)) {
				numFeatures = tmpNumFeatures;
			} else {
				if(numFeatures!=tmpNumFeatures) {
					continue;
				}
			}
			size_t numEl = FlatData.size();
			FlatData.push_back(L);
			ValidDataIDXToLine.insert(std::make_pair<size_t,size_t>(numEl,numEl));
		}
		ifs.close();
		CumSamplesPerClass[k+1] = FlatData.size();
		ClassDistribution[k] = CumSamplesPerClass[k+1]-CumSamplesPerClass[k];
	}
	ValidClassDistribution = ClassDistribution;
	ValidCumSamplesPerClass = CumSamplesPerClass;
	return 0;
}
/* Search the data based on the CCN (the user's input from keyboard)
   PRE:  hash - the pointer to the header of the hash table
   POST: data printed out if found
		 print the notification if wrong input
*/
void searchManager(HASH *hash)
{
	char target[20];

	do
	{
		printf("Enter the target (no space) or 0 to stop: ");
		scanf("%s", target);

		if(strcmp("0", target))
		{
			if(isInteger(target) && strlen(target) == 16)
			{
				convertStr(target);
				//printf("%s\n", target);
				searchHash(hash, target);
			}
			else
				printf ("Invalid input!!!\n");
		}
	}while(strcmp("0", target));

	return;
}
string KvProxy::RedisCommand(vector<string>& command)
{
    convertStr(command[0]);
//	for (size_t i=0; i<command.size(); i++)
//	{
//		cout << "command=" << command[i] <<",";
//	}
//	cout << endl;
    size_t index = 0;
    for (; index<commands.size(); index++)
    {
        if(command[0] == commands[index])
        {
            break;
        }
    }

    if (index == commands.size())
    {
        return "-error command!\r\n";
    }

    string ret = "";
    Reply rep;
    Command comm;


    switch(index)
    {
    case 0:		//exist
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("EXISTS")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 1:		//del
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("DEL")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 2:		//type
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("TYPE")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 3:		//expire
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("EXPIRE")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 4:		//set
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SET")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 5:		//setnx
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SETNX")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 6:		//get
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("GET")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 7:		//getset
        rep = GetRedisClient().RedisCommand(Command("GETSET")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 8:		//mget
        return "-error command!\r\n";
        break;
    case 9:		//mset
        return "-error command!\r\n";
        break;
    case 10:	//incr
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("INCR")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 11:	//decr
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("DECR")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 12:	//incrby
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("INCRBY")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 13:	//decrby
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("DECRBY")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 14:	//append
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("APPEND")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 15:	//lpush
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("LPUSH")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 16:	//rpush
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("RPUSH")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 17:	//llen
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("LLEN")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 18:	//lrange
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("LRANGE")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 19:	//ltrim
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("LTRIM")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 20:	//lset
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("LSET")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 21:	//lrem
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("LREM")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 22:	//lpop
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("LPOP")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 23:	//rpop
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("RPOP")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 24:	//sadd
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SADD")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 25:	//srem
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SREM")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 26:	//spop
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SPOP")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 27:	//srandmember
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SRANDMEMBER")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 28:	//scard
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SCARD")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 29:	//sismember
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SISMEMBER")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 30:	//smembers
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("SMEMBERS")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 31:	//zadd
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZADD")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 32:	//zrem
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZREM")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 33:	//zincrby
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZINCRBY")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 34:	//zrank
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZRANK")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 35:	//zrevrank
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZREVRANK")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 36:	//zrange
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZRANGE")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 37:	//zrevrange
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZREVRANGE")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 38:	//zrangebyscore
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZRANGEBYSCORE")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 39:	//zcount
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZCOUNT")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 40:	//zcard
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZCARD")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 41:	//zscore
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZSCORE")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 42:	//zremrangebyrank
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZREMRANGEBYRANK")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 43:	//zremrangebyscore
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("ZREMRANGEBYSCORE")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 44:	//hset
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HSET")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 45:	//hget
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HGET")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 46:	//hmget
        if (command.size() < 3) return "-error command!\r\n";
        comm("HMGET");

        for (size_t i=1; i<command.size(); i++)
        {
            comm(command[i]);
        }
        rep = GetRedisClient().RedisCommand(comm);
        ret = ReplyToString(rep);
        break;
    case 47:	//hmset
        if (command.size() < 4) return "-error command!\r\n";
        comm("HMSET");

        for (size_t i=1; i<command.size(); i++)
        {
            comm(command[i]);
        }

        rep = GetRedisClient().RedisCommand(comm);
        ret = ReplyToString(rep);
        break;
    case 48:	//hincrby
        if (command.size() != 4) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HINCRBY")(command[1])(command[2])(command[3]));
        ret = ReplyToString(rep);
        break;
    case 49:	//hexists
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HEXISTS")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 50:	//hdel
        if (command.size() != 3) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HDEL")(command[1])(command[2]));
        ret = ReplyToString(rep);
        break;
    case 51:	//hlen
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HLEN")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 52:	//hkeys
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HKEYS")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 53:	//hvals
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HVALS")(command[1]));
        ret = ReplyToString(rep);
        break;
    case 54:	//hgetall
        if (command.size() != 2) return "-error command!\r\n";
        rep = GetRedisClient().RedisCommand(Command("HGETALL")(command[1]));
        ret = ReplyToString(rep);
        break;
    default:
        ret = "-error command!\r\n";
    }
    return ret;
}
Beispiel #5
0
void ossimDoqq::ldstr_v1(std::istream& in)
{
   static const char MODULE[] = "ossimDoqq::ldstr_v1(istream& in)";

   if (!in)
   {
      theErrorStatus = OSSIM_ERROR;
      return;
   }

   char tmp1[DATA_ORDER_SIZE+1];
   in.seekg(DATA_ORDER_OFFSET, std::ios::beg);
   in.get(tmp1, DATA_ORDER_SIZE+1);
   theDataOrder = tmp1;

   //***
   // Perform a sanity check on the data order just in case this isn't a
   // ossimDoqq file.
   //***  
   tmp1[DATA_ORDER_SIZE] = '\0';
   int data_order = atoi(tmp1);
   if ( (data_order != 1) && (data_order != 2) )
   {
      theErrorStatus = OSSIM_ERROR;

      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " NOTICE:\n"
            << "Invalid data ordering.  Not a doq?" << std::endl;
      }
   }
   
   char tmp2[LINE_SIZE+1];
   in.seekg(LINE_OFFSET, std::ios::beg);
   in.get(tmp2, LINE_SIZE+1);
   theLine = atoi(tmp2);

   char tmp3[SAMPLE_SIZE+1];
   in.seekg(SAMPLE_OFFSET,std::ios::beg);
   in.get(tmp3, SAMPLE_SIZE+1); 
   theSample = atoi(tmp3);

   // Check for valid lines and samples.
   if (theLine <= 0 || theSample <= 0)
   {
      theErrorStatus = OSSIM_ERROR;

      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " ERROR:\n"
            << "\tInvalid lines or samples."
            << std::endl;
      }
      
      return;
   }
   
   char tmp4[PROJECTION_SIZE+1];
   in.seekg(PROJECTION_OFFSET, std::ios::beg);
   in.get(tmp4, PROJECTION_SIZE+1);
   theProjection = tmp4;

   char tmp5[UTM_ZONE_SIZE+1];
   in.seekg(UTM_ZONE_OFFSET, std::ios::beg);
   in.get(tmp5, UTM_ZONE_SIZE+1);
   theUtmZone = atoi(tmp5);

   char tmp8[DATUM_SIZE+1];
   in.seekg(DATUM_OFFSET, std::ios::beg);
   in.get(tmp8, DATUM_SIZE+1);
   theDatum = tmp8;

   char rgbType[RGB_SIZE+1];
   in.seekg(RGB_OFFSET, std::ios::beg);
   in.get(rgbType, RGB_SIZE+1);


   if(atoi(rgbType) == 5)
   {
      theRgb = 3;
   }
   else
   {
      theRgb = 1;
   }
   
   theHeaderSize = (theSample * theRgb * 4);

   // Calculate the size of each record.
   theRecordSize = (theSample * theRgb);

   char tmp6[UL_EASTING_SIZE+1];
   in.seekg( (theRecordSize * 2) + UL_EASTING_OFFSET, std::ios::beg);
   in.get(tmp6, UL_EASTING_SIZE+1);

   char tmp7[UL_NORTHING_SIZE+1];
   in.seekg( (theRecordSize * 2) + UL_NORTHING_OFFSET, std::ios::beg);
   in.get(tmp7, UL_NORTHING_SIZE+1);
   
   // Get Easting and Northing.
   theEasting = convertStr(tmp6);
   theNorthing = convertStr(tmp7);

   char tmp10[GSD_SIZE+1];
   in.seekg( (theRecordSize*3) + GSD_X_OFFSET, std::ios::beg);
   in.get(tmp10, GSD_SIZE+1);
   theGsd.x = std::abs(ossimString(tmp10, tmp10+GSD_SIZE).toDouble());
   in.seekg( (theRecordSize*3) + GSD_Y_OFFSET, std::ios::beg);
   in.get(tmp10, GSD_SIZE+1);
   theGsd.y = std::abs(ossimString(tmp10, tmp10+GSD_SIZE).toDouble());
   
}
Beispiel #6
0
	ManagerEvent::ManagerEvent(const std::string& values) {
		internalNumber = (nextSequenceNumber++);
		received = std::time(0);
		convertStr(values);
	}