Beispiel #1
0
	byte I2CFlexel::readPS2Keypad()
	{
		return readKey(I2C_FLEXEL_COMMAND_READ_PS2_KEYPAD);
	}
Beispiel #2
0
	byte I2CFlexel::readRemoteControl()
	{
		return readKey(I2C_FLEXEL_COMMAND_READ_REMOTE_CONTROL);
	}
Beispiel #3
0
void Templateiser::processLoop ( std::string &code, std::string::const_iterator &inItr, const std::string &str )
{
  std::string key,loopSection,emptySection,param;

  // read the rest of the key
  std::string::const_iterator itr = readKey(key,inItr,str);

  std::vector<std::string> commandParts = tokenize(key,std::string(" "),0,0);
  if (commandParts.size() < 2)
  {
    inItr = itr;
    return;
  }

  // check the params
  makelower(commandParts[0]);
  makelower(commandParts[1]);

  if (commandParts.size() > 2)
    param = commandParts[2];

  if ( commandParts[0] != "start" )
  {
    inItr = itr;
    return;
  }

  std::vector<std::string> checkKeys;
  checkKeys.push_back(format("*end %s",commandParts[1].c_str()));

  std::string keyFound;
  itr = findNextTag(checkKeys,keyFound,loopSection,itr,str);

  if (itr == str.end())
  {
    inItr = itr;
    return;
  }

  // do the empty section
  // loops have to have both
  checkKeys.clear();
  checkKeys.push_back(format("*empty %s",commandParts[1].c_str()));
  itr = findNextTag(checkKeys,keyFound,emptySection,itr,str);

  if (callLoop(commandParts[1],param))
  {
    std::string newCode;
    processTemplate(newCode,loopSection);
    code += newCode;

    while(callLoop(commandParts[1],param))
    {
      newCode = "";
      processTemplate(newCode,loopSection);
      code += newCode;
    }
  }
  else
  {
    std::string newCode;
    processTemplate(newCode,emptySection);
    code += newCode;
  }
  inItr = itr;
}
Beispiel #4
0
	byte I2CFlexel::readButtons()
	{
		return readKey(I2C_FLEXEL_COMMAND_READ_BUTTONS);
	}
int main(int argc, char *argv[])
{
	int opt;
	char* appName = NULL;
	char* resourceID = NULL;
	char* payloadBuffer = NULL;
	char* fileName = NULL;
	unsigned char* writeBuffer = NULL;
	eOperationMode opMode = modeInvalid;
	unsigned int user_no = 0, seat_no = 0;
	unsigned int ldbid = 0xFF;    // default value
	unsigned int doHexdump = 0;

	printf("\n");
   /// debug log and trace (DLT) setup
   DLT_REGISTER_APP("Ptool","persistence client library tools");


	while ((opt = getopt(argc, argv, "hVo:a:u:s:r:-l:p:f:H")) != -1)
	{
		switch (opt)
		{
		   case 'o':      // option
		      if(strcmp(optarg, "readkey")  == 0)
            {
		         opMode = modeReadKey;
            }
		      else if(strcmp(optarg, "writekey")  == 0)
            {
		         opMode = modeWriteKey;
            }
		      else if(strcmp(optarg, "deletekey")  == 0)
            {
		         opMode = modeDeleteKey;
            }
		      else if(strcmp(optarg, "getkeysize")  == 0)
            {
		         opMode = modeGetKeySize;
            }
		      else
		      {
		         printf("Unsupported Unsupported mode: %s\"\n\"", optarg);
		         printSynopsis();
	            exit(EXIT_FAILURE);
		      }
		      break;
		   case 'a':   // application name
		   {
		      size_t len = strlen(optarg);
            appName = malloc(len + 1);
            if(appName != NULL)
            {
               memset(appName, 0, len + 1);
               strncpy(appName, optarg, len);
            }
		   }
		      break;
		   case 'r':   // resource ID
         {
            size_t len = strlen(optarg);
            resourceID = malloc(len + 1);
            if(resourceID != NULL)
            {
               memset(resourceID, 0, len + 1);
               strncpy(resourceID, optarg, len);
            }
         }
            break;
         case 'p':   // payload to write
         {
            size_t len = strlen(optarg);
            payloadBuffer = malloc(len + 1);
            if(payloadBuffer != NULL)
            {
               memset(payloadBuffer, 0, len + 1);
               strncpy(payloadBuffer, optarg, len);
            }
         }
            break;
         case 'f':   // filename to read data from, write data to
         {
            size_t len = strlen(optarg);
            fileName = malloc(len + 1);
            if(fileName != NULL)
            {
               memset(fileName, 0, len + 1);
               strncpy(fileName, optarg, len);
            }
         }
            break;
		   case 'u':   // user number
		      user_no = (unsigned int)atoi(optarg);
		      break;
		   case 's':   // seat number
            seat_no = (unsigned int)atoi(optarg);
            break;
		   case 'l':
		      ldbid = (unsigned int)strtol(optarg, NULL, 16);
		      break;
		   case 'H':   // hexdump of data
		      doHexdump = 1;
		      break;
	   	case 'h':   // help
	   	   printSynopsis();
	         break;
	   	case 'v':   // version
	   		printf("Version: %s\n", PCLT_VERSION);
	         break;
	   	default: /* '?' */
	      	printSynopsis();
	         exit(EXIT_FAILURE);
	         break;
		}
   }


	if(appName != NULL && resourceID != NULL)
	{
	   printf("Application name: %s\n", appName);

	   int shutdownReg = PCL_SHUTDOWN_TYPE_NONE;
	   (void)pclInitLibrary(appName, shutdownReg);

      switch(opMode)
      {
         case modeReadKey:
         {
            unsigned char* buffer = NULL;
            int keysize = pclKeyGetSize(ldbid, resourceID, user_no, seat_no);

            if(keysize > 0)
            {
               buffer = malloc((size_t)keysize + 1);
               if(buffer != NULL)
               {
                  memset(buffer, 0, (size_t)(keysize + 1));
                  readKey(resourceID, user_no, seat_no, ldbid, doHexdump, buffer, keysize);

                  if(fileName != NULL)
                     (void)writeDataToFile(fileName, buffer, keysize);

                  free(buffer);
               }
            }
            else
            {
               printf("readkey: key is empty: %d\n", keysize);
            }
            break;
         }
         case modeWriteKey:
            if(fileName != NULL)    // if filename is available, read data from file
            {
               writeBuffer = readDataFromFile(fileName);
            }
            else
            {
               writeBuffer = (unsigned char*)payloadBuffer;    // use data from payload parameter
            }

            if(writeBuffer != NULL)
            {
               writeKey(resourceID, user_no, seat_no, ldbid, writeBuffer, doHexdump);
            }
            else
            {
               printf("No Data to write to key\n");
            }
            break;
         case modeDeleteKey:
            deletekey(resourceID, user_no, seat_no, ldbid);
            break;
         case modeGetKeySize:
            getkeysize(resourceID, user_no, seat_no, ldbid);
            break;
         default:
            printSynopsis();
            break;
      }

      if(appName != NULL)
         free(appName);

      if(resourceID != NULL)
         free(resourceID);

      if(writeBuffer != NULL)
         free(writeBuffer);

      if(fileName != NULL)
         free(fileName);


      pclLifecycleSet(PCL_SHUTDOWN);

      pclDeinitLibrary();
	}
	else
	{
	   printf("Invalid application name or resourceID\n");
	   exit(EXIT_FAILURE);
	}

   // unregister debug log and trace
   DLT_UNREGISTER_APP();
   dlt_free();

   printf("\n");

   return 0;
}
Beispiel #6
0
void Templateiser::processComment ( std::string & /* code */, std::string::const_iterator &inItr, const std::string &str )
{
  std::string key;
  inItr = readKey(key,inItr,str);
}
Beispiel #7
0
void SfzRegion::readOp(const QString& b, const QString& data, SfzControl &c)
      {
      QString opcode           = QString(b);
      QString opcode_data_full = QString(data);

      for(auto define : c.defines) {
            opcode.replace(define.first, define.second);
            opcode_data_full.replace(define.first, define.second);
            }

      QStringList splitData = opcode_data_full.split(" "); // no spaces in opcode values except for sample definition
      QString opcode_data = splitData[0];

      int i = opcode_data.toInt();

      if (opcode == "amp_veltrack")
            readDouble(opcode_data, &amp_veltrack);
      else if (opcode == "ampeg_delay")
            readDouble(opcode_data, &ampeg_delay);
      else if (opcode == "ampeg_start")
            readDouble(opcode_data, &ampeg_start);
      else if (opcode == "ampeg_attack")
            readDouble(opcode_data, &ampeg_attack);
      else if (opcode == "ampeg_hold")
            readDouble(opcode_data, &ampeg_hold);
      else if (opcode == "ampeg_decay")
            readDouble(opcode_data, &ampeg_decay);
      else if (opcode == "ampeg_sustain")
            readDouble(opcode_data, &ampeg_sustain);
      else if (opcode == "ampeg_release")
            readDouble(opcode_data, &ampeg_release);
      else if (opcode == "ampeg_vel2delay")
            readDouble(opcode_data, &ampeg_vel2delay);
      else if (opcode == "ampeg_vel2attack")
            readDouble(opcode_data, &ampeg_vel2attack);
      else if (opcode == "ampeg_vel2hold")
            readDouble(opcode_data, &ampeg_vel2hold);
      else if (opcode == "ampeg_vel2decay")
            readDouble(opcode_data, &ampeg_vel2decay);
      else if (opcode == "ampeg_vel2sustain")
            readDouble(opcode_data, &ampeg_vel2sustain);
      else if (opcode == "ampeg_vel2release")
            readDouble(opcode_data, &ampeg_vel2release);
      else if (opcode == "sample") {
            sample = path + "/" + c.defaultPath + "/" + opcode_data_full; // spaces are allowed
            sample.replace("\\", "/");
            sample = sample.trimmed();
            }
      else if (opcode == "default_path") {
            c.defaultPath = opcode_data_full;
            }
      else if (opcode == "key") {
            lokey = readKey(opcode_data, c);
            hikey = lokey;
            pitch_keycenter = lokey;
            }
      else if (opcode == "pitch_keytrack")
            readDouble(opcode_data, &pitch_keytrack);
      else if (opcode == "trigger") {
            if (opcode_data == "attack")
                  trigger = Trigger::ATTACK;
            else if (opcode_data == "release")
                  trigger = Trigger::RELEASE;
            else if (opcode_data == "first")
                  trigger = Trigger::FIRST;
            else if (opcode_data == "legato")
                  trigger = Trigger::LEGATO;
            else
                  qDebug("SfzRegion: bad trigger value: %s", qPrintable(opcode_data));
            }
      else if (opcode == "loop_mode") {
            if (opcode_data == "no_loop")
                  loop_mode = LoopMode::NO_LOOP;
            else if (opcode_data == "one_shot")
                  loop_mode = LoopMode::ONE_SHOT;
            else if (opcode_data == "loop_continuous")
                  loop_mode = LoopMode::CONTINUOUS;
            else if (opcode_data == "loop_sustain")
                  loop_mode = LoopMode::SUSTAIN;
            //if (loop_mode != LoopMode::ONE_SHOT)
            //      qDebug("SfzRegion: loop_mode <%s>", qPrintable(opcode_data));
            }
      else if(opcode == "loop_start")
            readLongLong(opcode_data, loopStart);
      else if(opcode == "loop_end")
            readLongLong(opcode_data, loopEnd);
      else if (opcode.startsWith("on_locc")) {
            int idx = b.mid(7).toInt();
            if (idx >= 0 && idx < 128)
                  on_locc[idx] = i;
            }
      else if (opcode.startsWith("on_hicc")) {
            int idx = b.mid(7).toInt();
            if (idx >= 0 && idx < 128)
                  on_hicc[idx] = i;
            }
      else if (opcode.startsWith("locc")) {
            int idx = b.mid(4).toInt();
            if (!use_cc)
                  use_cc = i != 0;
            if (idx >= 0 && idx < 128)
                  locc[idx] = i;
            }
      else if (opcode.startsWith("hicc")) {
            int idx = b.mid(4).toInt();
            if (!use_cc)
                  use_cc = i != 127;
            if (idx >= 0 && idx < 128)
                  hicc[idx] = i;
            }
      else if (opcode.startsWith("set_cc")) {
            int idx = b.mid(6).toInt();
            if (idx >= 0 && idx < 128)
                  c.set_cc[idx] = i;
            }
      else if (opcode == "off_mode") {
            if (opcode_data == "fast")
                  off_mode = OffMode::FAST;
            else if (opcode_data == "normal")
                  off_mode = OffMode::NORMAL;
            }
      else if (opcode.startsWith("gain_cc")) {
            int idx = b.mid(7).toInt();
            double v;
            if (idx >= 0 && idx < 128) {
                  readDouble(opcode_data, &v);
                  gain_oncc.insert(std::pair<int, double>(idx, v));
                  }
            }
      else if (opcode.startsWith("gain_oncc")) {
            int idx = b.mid(9).toInt();
            double v;
            if (idx >= 0 && idx < 128) {
                  readDouble(opcode_data, &v);
                  gain_oncc.insert(std::pair<int, double>(idx, v));
                  }
            }
      else if (opcode == "tune")
            tune = i;
      else if (opcode == "rt_decay")
            readDouble(opcode_data, &rt_decay);
      else if (opcode == "hirand")
            readDouble(opcode_data, &hirand);
      else if (opcode == "lorand")
            readDouble(opcode_data, &lorand);
      else if (opcode == "volume")
            readDouble(opcode_data, &volume);
      else if (opcode == "pitch_keycenter")
            pitch_keycenter = readKey(opcode_data ,c);
      else if (opcode == "lokey")
            lokey = readKey(opcode_data, c);
      else if (opcode == "hikey")
            hikey = readKey(opcode_data, c);
      else if (opcode == "lovel")
            lovel = i;
      else if (opcode == "hivel")
            hivel = i;
      else if (opcode == "off_by")
            off_by = i;
      else if (opcode == "group")
            group = i;
      else if (opcode == "lochan")
            lochan = i;
      else if (opcode == "hichan")
            hichan = i;
      else if (opcode == "note_offset")
            c.note_offset = i;
      else if (opcode == "octave_offset")
            c.octave_offset = i;
      else if (opcode == "seq_length")
            seq_length = i;
      else if (opcode == "seq_position")
            seq_position = i;
      else if (opcode == "transpose")
            transpose = i;
      else if (opcode == "delay")
            readFloat(opcode_data, delay);
      else if (opcode == "pan")
            pan = i;
      else if (opcode == "offset")
            readLongLong(opcode_data, offset);
      else if (opcode == "group_volume")
            readFloat(opcode_data, group_volume);
      else if (opcode == "global_volume")
            readFloat(opcode_data, global_volume);
      else if (opcode == "cutoff") {
            isCutoffDefined = true;
            readFloat(opcode_data, cutoff);
            }
      else if (opcode == "fil_keycenter")
            fil_keycenter = i;
      else if (opcode == "fil_keytrack")
            fil_keytrack = i;
      else if (opcode == "fil_veltrack")
            fil_veltrack = i;
      else if (opcode == "fil_type")
            readFilterType(opcode_data, fil_type);
      else
            qDebug("SfzRegion: unknown opcode <%s>", qPrintable(opcode));
      }
Beispiel #8
0
static int processPacketGroup( INOUT STREAM *stream, 
							   INOUT PGP_INFO *pgpInfo,
							   IN_OPT const KEY_MATCH_INFO *keyMatchInfo,
							   INOUT_OPT PGP_KEYINFO **matchedKeyInfoPtrPtr,
							   IN_INT_SHORT_Z const int keyGroupNo,
							   INOUT ERROR_INFO *errorInfo )
	{
	int iterationCount, status;

	assert( isWritePtr( stream, sizeof( STREAM ) ) );
	assert( isWritePtr( pgpInfo, sizeof( PGP_INFO ) ) );
	assert( ( keyMatchInfo == NULL && matchedKeyInfoPtrPtr == NULL ) || \
			( isReadPtr( keyMatchInfo, sizeof( KEY_MATCH_INFO ) ) && \
			  isWritePtr( matchedKeyInfoPtrPtr, sizeof( PGP_KEYINFO * ) ) ) );

	REQUIRES( ( keyMatchInfo == NULL && matchedKeyInfoPtrPtr == NULL ) || \
			  ( keyMatchInfo != NULL && matchedKeyInfoPtrPtr != NULL && \
				pgpInfo->keyData != NULL && \
				pgpInfo->keyDataLen == KEYRING_BUFSIZE ) );
	REQUIRES( keyGroupNo >= 0 && keyGroupNo < MAX_INTLENGTH_SHORT );
	REQUIRES( errorInfo != NULL );

	/* Clear the index information before we read the current key(s), since 
	   it may already have been initialised during a previous (incomplete) 
	   key read */
	memset( &pgpInfo->key, 0, sizeof( PGP_KEYINFO ) );
	memset( &pgpInfo->subKey, 0, sizeof( PGP_KEYINFO ) );
	memset( pgpInfo->userID, 0, sizeof( char * ) * MAX_PGP_USERIDS );
	memset( pgpInfo->userIDlen, 0, sizeof( int ) * MAX_PGP_USERIDS );
	pgpInfo->lastUserID = 0;

	/* Read all the packets in this packet group */
	for( status = CRYPT_OK, iterationCount = 0;
		 cryptStatusOK( status ) && sMemDataLeft( stream ) > 0 && \
			iterationCount++ < FAILSAFE_ITERATIONS_MED;
		 iterationCount++ )
		{
		status = readKey( stream, pgpInfo, keyGroupNo, errorInfo );
		}
	ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
	if( cryptStatusError( status ) )
		{
		if( status != OK_SPECIAL && status != CRYPT_ERROR_NOSECURE )
			return( status );

		/* There's either something in the key information that we can't 
		   handle or it's stored with no security, skip the key */
		if( keyMatchInfo == NULL )
			pgpFreeEntry( pgpInfo );
		return( status );
		}

	/* If we're reading all keys, we're done */
	if( keyMatchInfo == NULL )
		return( CRYPT_OK );

	/* We're searching for a particular key, see if this is the one */
	if( pgpCheckKeyMatch( pgpInfo, &pgpInfo->key, keyMatchInfo ) )
		{
		*matchedKeyInfoPtrPtr = &pgpInfo->key;
		return( CRYPT_OK );
		}
	if( pgpCheckKeyMatch( pgpInfo, &pgpInfo->subKey, keyMatchInfo ) )
		{
		*matchedKeyInfoPtrPtr = &pgpInfo->subKey;
		return( CRYPT_OK );
		}

	/* No match, tell the caller to keep looking */
	return( CRYPT_ERROR_NOTFOUND );
	}
int main()
{
	// not recommended to do something with sizes :(
	COORD size = {9, 8};
	drawTable(size);

	// task - aim, request - user input
	i4 task(generateTask());
	i4 request;

	// index to watch which digit user is entered
	// line - offset for the log output
	int index = 0, line = 4;
	
	bool bQuit = false;
	while (!bQuit)
	{
		char ch[] = {readKey(), '\0'};
		int code = (int)(ch[0]);

		// if input is digit
		if (code > 47 && code < 58 && index < 4)
		{
			int num = code - 48;
			bool bDublicate = false;
			for (int i = 0; i < index; ++i)
			{
				if (request[i] == num)
				{
					bDublicate = true;
					break;
				}
			}

			if (bDublicate)
				continue;

			request[index] = num;
			++index;
			print({2 + index, 1}, ch);
		}

		// if input is erase
		if (code == KEY_BACK && index > 0)
			print({2 + index--, 1}, "_");

		// if input is confirm
		if (code == KEY_ENTER && index == 4)
		{
			print({3, 1}, "____");
			i2 fb = getFeedback(request, task);

			// hard way to do simple thing
			char c[] = {
				request[0] + 48,
				request[1] + 48,
				request[2] + 48,
				request[3] + 48,
				' ',
				fb[0] + 48,
				':',
				fb[1] + 48,
				'\0'
			};
			print({1, line}, c);
			++line;
			index = 0;

			// make the table longer if needed
			if (line > size.Y-1)
			{
				print({0, size.Y}, "|");
				print({size.X, size.Y}, "|");
				++size.Y;
			}

			// win event
			if (fb[0] == 4)
			{
				for (int i = 0; i < size.X-1; ++i)
					print({1 + i, line}, "!");

				readKey();
				break;
			}
		}

		// if input is exit
		if (code == KEY_ESC)
			return 0;
		//printf("%d", code);
	}
	clearScreen();
	system("pause");
	return 0;
}
Beispiel #10
0
static int
brl_readCommand (BrailleDisplay *brl, KeyTableCommandContext context) {
   int key = readKey();
   if (context != currentContext) {
      logMessage(LOG_DEBUG, "Context switch: %d -> %d", currentContext, context);
      switch (currentContext = context) {
         case KTB_CTX_DEFAULT:
            deviceStatus = DEV_ONLINE;
            break;
         default:
            break;
      }
   }
   if (key != EOF) {
      switch (key) {
         case KEY_FUNCTION_ENTER:
            return BRL_BLK_PASSKEY + BRL_KEY_ENTER;
         case KEY_FUNCTION_TAB:
            return BRL_BLK_PASSKEY + BRL_KEY_TAB;
         case KEY_FUNCTION_CURSOR_UP:
            return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_UP;
         case KEY_FUNCTION_CURSOR_DOWN:
            return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_DOWN;
         case KEY_FUNCTION_CURSOR_LEFT:
            return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_LEFT;
         case KEY_FUNCTION_CURSOR_RIGHT:
            return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_RIGHT;
         case KEY_FUNCTION_CURSOR_UP_JUMP:
            return BRL_BLK_PASSKEY + BRL_KEY_HOME;
         case KEY_FUNCTION_CURSOR_DOWN_JUMP:
            return BRL_BLK_PASSKEY + BRL_KEY_END;
         case KEY_FUNCTION_CURSOR_LEFT_JUMP:
            return BRL_BLK_PASSKEY + BRL_KEY_PAGE_UP;
         case KEY_FUNCTION_CURSOR_RIGHT_JUMP:
            return BRL_BLK_PASSKEY + BRL_KEY_PAGE_DOWN;
         case KEY_FUNCTION_F1:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 0;
         case KEY_FUNCTION_F2:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 1;
         case KEY_FUNCTION_F3:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 2;
         case KEY_FUNCTION_F4:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 3;
         case KEY_FUNCTION_F5:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 4;
         case KEY_FUNCTION_F6:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 5;
         case KEY_FUNCTION_F7:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 6;
         case KEY_FUNCTION_F9:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 8;
         case KEY_FUNCTION_F10:
            return BRL_BLK_PASSKEY + BRL_KEY_FUNCTION + 9;
         case KEY_COMMAND: {
            int command;
            while ((command = readKey()) == EOF) approximateDelay(1);
            logMessage(LOG_DEBUG, "Received command: (0x%2.2X) 0x%4.4X", KEY_COMMAND, command);
            switch (command) {
               case KEY_COMMAND:
                  /* pressing the escape command twice will pass it through */
                  return BRL_BLK_PASSDOTS + translateInputCell(KEY_COMMAND);
               case KEY_COMMAND_SWITCHVT_PREV:
                  return BRL_CMD_SWITCHVT_PREV;
               case KEY_COMMAND_SWITCHVT_NEXT:
                  return BRL_CMD_SWITCHVT_NEXT;
               case KEY_COMMAND_SWITCHVT_1:
                  return BRL_BLK_SWITCHVT + 0;
               case KEY_COMMAND_SWITCHVT_2:
                  return BRL_BLK_SWITCHVT + 1;
               case KEY_COMMAND_SWITCHVT_3:
                  return BRL_BLK_SWITCHVT + 2;
               case KEY_COMMAND_SWITCHVT_4:
                  return BRL_BLK_SWITCHVT + 3;
               case KEY_COMMAND_SWITCHVT_5:
                  return BRL_BLK_SWITCHVT + 4;
               case KEY_COMMAND_SWITCHVT_6:
                  return BRL_BLK_SWITCHVT + 5;
               case KEY_COMMAND_SWITCHVT_7:
                  return BRL_BLK_SWITCHVT + 6;
               case KEY_COMMAND_SWITCHVT_8:
                  return BRL_BLK_SWITCHVT + 7;
               case KEY_COMMAND_SWITCHVT_9:
                  return BRL_BLK_SWITCHVT + 8;
               case KEY_COMMAND_SWITCHVT_10:
                  return BRL_BLK_SWITCHVT + 9;
               case KEY_COMMAND_PAGE_UP:
                  return BRL_BLK_PASSKEY + BRL_KEY_PAGE_UP;
               case KEY_COMMAND_PAGE_DOWN:
                  return BRL_BLK_PASSKEY + BRL_KEY_PAGE_DOWN;
               case KEY_COMMAND_PREFMENU:
                  currentLine = 0;
                  cursorRow = 0;
                  cursorColumn = 31;
                  sendCursorRow();
                  return BRL_CMD_PREFMENU;
               case KEY_COMMAND_PREFSAVE:
                  return BRL_CMD_PREFSAVE;
               case KEY_COMMAND_PREFLOAD:
                  return BRL_CMD_PREFLOAD;
               case KEY_COMMAND_FREEZE_ON:
                  return BRL_CMD_FREEZE | BRL_FLG_TOGGLE_ON;
               case KEY_COMMAND_FREEZE_OFF:
                  return BRL_CMD_FREEZE | BRL_FLG_TOGGLE_OFF;
               case KEY_COMMAND_RESTARTBRL:
                  return BRL_CMD_RESTARTBRL;
               case KEY_COMMAND_DOWNLOAD:
                  downloadFile();
                  break;
               default:
                  logMessage(LOG_WARNING, "Unknown command: (0X%2.2X) 0X%4.4X", KEY_COMMAND, command);
                  break;
            }
            break;
         }
         default:
            switch (key & KEY_MASK) {
               case KEY_UPDATE:
                  handleUpdate(key >> KEY_SHIFT);
                  break;
               case KEY_FUNCTION:
                  logMessage(LOG_WARNING, "Unknown function: (0X%2.2X) 0X%4.4X", KEY_COMMAND, key>>KEY_SHIFT);
                  break;
               default: {
                  unsigned char dots = translateInputCell(key);
                  logMessage(LOG_DEBUG, "Received character: 0X%2.2X dec=%d dots=%2.2X", key, key, dots);
                  return BRL_BLK_PASSDOTS + dots;
               }
            }
            break;
      }
   }
   return EOF;
}
Beispiel #11
0
int main(int argc, char* const argv[]) {
    if (testQueue() != 0) {
        exit(-1);
    }
    // Check for flags
    int nrOfCryptThreads = 0;
    nrOfReadThreads = 0;
    int nrOfBuffers = 0;
    int ch;
    const char *optstring = "C:P:B:";
    while((ch = getopt(argc, argv, optstring)) != -1) {
        switch (ch) {
        case 'P': /* Number of read-threads */
            nrOfReadThreads = atoi(optarg);
            break;
        case 'C': /* Number of computers (crypt-threads) */
            nrOfCryptThreads = atoi(optarg);
            break;
        case 'B': /* Number of buffers */
            nrOfBuffers = atoi(optarg);
            break;
        case '?':
        default:
            usage();
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    if (nrOfBuffers < 1 || nrOfCryptThreads < 1 || nrOfReadThreads < 1) {
        printf("nrOfBuffers: %d\n", nrOfBuffers);
        printf("nrOfCryptThreads: %d\n", nrOfCryptThreads);
        printf("nrOfReadThreads: %d\n", nrOfReadThreads);
        usage();
        exit(1);
    }

    /* Init Queues to hold Buffers with log messages */
    //extern Queue *freeBufQueue;
    createQueue(&freeBufQueue, nrOfBuffers);
    //extern Queue *filledBufQueue;
    createQueue(&filledBufQueue, nrOfBuffers);

    printf("filledbufqueue: ");
    printQueue(&filledBufQueue);
    int i;
    for (i = 0; i < nrOfBuffers; i++) {
        LogBuf *b;
        b = malloc(sizeof(LogBuf));
        b->fifo = -1;
        b->message = malloc(LOG_MSG_SIZE);
        enqueue(&freeBufQueue, b);
        printf("enqueueing%d\n", i);
    }

    printf("freeBufQueue: ");
    printQueue(&freeBufQueue);

    /* Read key from file `keys' */
    readKey(key, MAXKEYSIZE);
    printf("key: %s\n", key);

    /* Init fifo_count and fifo_mutex */
    fifo_count = malloc(nrOfReadThreads * sizeof(int));
    for (i = 0; i < nrOfReadThreads; i++) {
        fifo_count[i] = 0;
    }
    if (pthread_mutex_init(&fifo_mutex, NULL) != 0) {
        fprintf(stderr, "Couldn't init fifo_mutex\n");
        exit(1);
    }

    /* Start read threads */
    pthread_t readThreadArray[nrOfReadThreads];
    for (i = 0; i < nrOfReadThreads; i++) {
        if (pthread_create(&readThreadArray[i], NULL, readThreadInit,
                           (void*) i) != 0) {
            fprintf(stderr, "Failed to create thread.\n");
        }
    }

    /* Start crypt threads */
    pthread_t cryptThreadArray[nrOfCryptThreads];
    for (i = 0; i < nrOfCryptThreads; i++) {
        if (pthread_create(&cryptThreadArray[i], NULL, cryptThreadInit,
                           (void*) i) != 0) {
            fprintf(stderr, "Failed to create thread.\n");
        }
    }

    // Wait for read threads
    for (i = 0; i < nrOfReadThreads; i++) {
        pthread_join(readThreadArray[i], NULL);
    }

    // Wait for crypt threads
    for (i = 0; i < nrOfCryptThreads; i++) {
        pthread_join(cryptThreadArray[i], NULL);
    }

    /* TODO: Cleanup free stuff */
    return 0;
}
Beispiel #12
0
void readKey(char* key, byte keySize, const char* salt) {
  long value = getLong(salt);
  readKey(key, keySize);
  deshuffle(key, keySize, value);
}
Beispiel #13
0
void _main_Process(void)
{
		u8 *fname;
		USART_InitTypeDef USART_InitStruct;
		u8 temp;u16 recvLenth=0;u32 savelenth=0;
		KEY_Press kp=KEY_none;char ssid[30]={"SP400-"};char buf[20]={0};
		if(isAppExist)
                 printf("|OK|--Boot to Application\n");
            else printf("|OK|--Load new ver from SD\n");
		     printf("| <|--Load factory ver from SD");
		     printf("| >|--Update form PC\n");
		     printf("******************************");

		kp=readKey();
		if(kp==KEY_ok)
		{
                  if( isAppExist)JumpToApplication(AppProgramAddr);
                  else 
                  {
                        Frimware=f_open(&f_bin,"new.bin",FA_OPEN_EXISTING);
                        f_close(&f_bin);
                        if(Frimware==FR_OK)
                        {
                              clearAppVersion();
                              printf("Firmware Loading......\n");
                              printf("%d Bytes to load\n",WriteFlashFromFile("new.bin"));
                              printf("Jump To Application\n");
                              JumpToApplication(AppProgramAddr);
                        }
                        else
                        {
                                    printf("Can not found file\n");
                        }   
                  }
		}
		else if(kp==KEY_left)
		{
			Frimware=f_open(&f_bin,"factory.bin",FA_OPEN_EXISTING);
                  f_close(&f_bin);
			if(Frimware==FR_OK)
			{
				clearAppVersion();
				printf("Firmware Loading......\n");
				printf("%d Bytes to load\n",WriteFlashFromFile("factory.bin"));
				printf("Jump To Application\n");
				JumpToApplication(AppProgramAddr);
			}
			else
			{
					printf("Can not found file\n");
			}

		}
		else if(kp==KEY_right)
		{
			printf("Starting Wifi...\n");
			EMW_HAL_InitWithDefault();
			EMW_Get_Config(&wifi_paraG);
			memset(wifi_paraG.wifi_ssid,0,sizeof(wifi_paraG.wifi_ssid));
			sprintf(buf,"%d",Bp.serialNum);
			strcat(ssid,buf);
			strcat(wifi_paraG.wifi_ssid,ssid);
			wifi_paraG.use_dhcp=1;
			EMW_Set_Config(&wifi_paraG);
			EMW_Set_Mode(DTU_mode);
			printf("WIFI Network: %s Created\n",wifi_paraG.wifi_ssid);
			rut=ReciveFile2SD(fname);
			SysTick->CTRL=0;
			if(rut)
			{
				clearAppVersion();
				printf("Firmware Loading......\n");
                        if(isFactory)
                        {
                            printf("%d Bytes to load\n",WriteFlashFromFile("factory.bin"));
                        }
                        else 
                        {
                            printf("%d Bytes to load\n",WriteFlashFromFile("new.bin"));  
                        }
				
				printf("Jump To Application\n");
				JumpToApplication(AppProgramAddr);
			}
			else
			{
				SystemReset();
			}
		}
		while(1);
}