Esempio n. 1
0
TonePlayer::TonePlayer(QObject *parent) :
    QObject(parent)
{
    /* RAII */
    initAudio();
    initKeys();
}
RussianKeyboardLayout::RussianKeyboardLayout()
: KeyboardLayout()
{
    initCode();
    initShiftMap();
    initSpecialMaps();
    initKeys();
}
Esempio n. 3
0
	EMenuScreen KeyAssignMenu::run(MainWindow& window, EMenuScreen previous)
	{
		this->window = &window;

		errorKey.setVisible(false);
		
		initKeys();

		return IMenuScreen::run(window, previous);
	}
Esempio n. 4
0
int main( int argc, char **argv ) {
  if( argc < 2 ) {
    printf( "usage: %s <keyfile>\n", argv[0] );
    exit( 1 );
  }
  
  if( initKeys(argv[1]) ) {
    printf( "Error in reading in key file, aborting.\n" );
    exit(1);
  }

  //printkeys();

  doInteraction();

  return 0;
}
Esempio n. 5
0
Score::Score(QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) : QWidget(parent, name)
{
    setFocusPolicy(QWidget::StrongFocus);

    paused = FALSE;

    lastScore = -1;
    lastPlayer = -1;

    cursorBlinkTimer = 0;
    cursorBlinkMS = -1;
    cursor.x = -1;
    cursor.y = -1;
    cursor.on = FALSE;
    cursor.chr = QChar('?');

    initKeys();

    scheme = Scheme;
    mode = Mode;
    confScheme();

    bitfont = font;

    highscoreFile.setName(locateHighscoreFilePath().filePath());
    read();

    for (int p = 0; p < maxPlayer; p++) {
        playerScore[p] = 0;
        playerName[p] = getenv("LOGNAME");
        if (playerName[p].length() < minPlayerNameLength)
            playerName[p].setExpand(minPlayerNameLength-1, ' ');

        for (uint i = 0; i < playerName[p].length(); i++)
            if (playerName[p].at(i) < bitfont->firstChar() ||
                playerName[p].at(i) > bitfont->lastChar())
                playerName[p].at(i) = playerName[p].at(i).upper();
    }
}
Esempio n. 6
0
	void KeyAssignMenu::validPressed(EMenuScreen* nextScreen)
	{
		IControllerToMenu* controller = PolyBomberApp::getIControllerToMenu();

		for (int i=0; i<7; i++)
		{
			if (keyText[i]->getSelected())
			{
				keyText[i]->setString("...");
				errorKey.setVisible(false);

				this->window->clear();
				this->window->display(this->widgets);
				
				SKeysConfig k = controller->setPlayerKey(this->player, (EGameKeys)i);

				for (int j=0; j<7; j++)					
				{
					if (k.errors[j].compare("") != 0)
						errorKey.setVisible(true);
				}
				
				initKeys();
			}
		}

		if (cancel.getSelected())
		{
			controller->reloadConfig();
			*nextScreen = cancel.activate();
		}
		
		if (save.getSelected())
		{						
			controller->save();
			*nextScreen = save.activate();
		}
	}
Esempio n. 7
0
int main(int argc, char **argv)
{
    bool bShowSettings = false;

    MythWelcomeCommandLineParser cmdline;
    if (!cmdline.Parse(argc, argv))
    {
        cmdline.PrintHelp();
        return GENERIC_EXIT_INVALID_CMDLINE;
    }

    if (cmdline.toBool("showhelp"))
    {
        cmdline.PrintHelp();
        return GENERIC_EXIT_OK;
    }

    if (cmdline.toBool("showversion"))
    {
        cmdline.PrintVersion();
        return GENERIC_EXIT_OK;
    }
    
    QApplication a(argc, argv);
    QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHWELCOME);

    int retval;
    if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
        return retval;

    if (cmdline.toBool("setup"))
        bShowSettings = true;

#ifndef _WIN32
    QList<int> signallist;
    signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
               << SIGILL;
    SignalHandler handler(signallist);
    signal(SIGHUP, SIG_IGN);
#endif

    gContext = new MythContext(MYTH_BINARY_VERSION);
    if (!gContext->Init())
    {
        LOG(VB_GENERAL, LOG_ERR,
            "mythwelcome: Could not initialize MythContext. Exiting.");
        return GENERIC_EXIT_NO_MYTHCONTEXT;
    }

    if (!MSqlQuery::testDBConnection())
    {
        LOG(VB_GENERAL, LOG_ERR,
            "mythwelcome: Could not open the database. Exiting.");
        return -1;
    }

    LCD::SetupLCD();

    if (LCD *lcd = LCD::Get())
        lcd->switchToTime();

    MythTranslation::load("mythfrontend");

    GetMythUI()->LoadQtConfig();

    MythMainWindow *mainWindow = GetMythMainWindow();
    mainWindow->Init();

    initKeys();

    if (bShowSettings)
    {
        MythShutdownSettings settings;
        settings.exec();
    }
    else
    {
        MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();

        WelcomeDialog *welcome = new WelcomeDialog(mainStack, "mythwelcome");

        if (welcome->Create())
            mainStack->AddScreen(welcome, false);
        else
            return -1;

        do
        {
            qApp->processEvents();
            usleep(5000);
        } while (mainStack->TotalScreens() > 0);
    }

    DestroyMythMainWindow();

    delete gContext;

    return 0;
}
Esempio n. 8
0
bool ZIPPKCrackerGPU::verifyPassword(std::string& pass) {
    ZIPKeys keys;
    initKeys(&keys,reinterpret_cast<const unsigned char*>(pass.c_str()),pass.length(),(*data)[0].streamBuffer);
    return verify(&keys,&(*data)[0]);
}
Esempio n. 9
0
int Kernel::start(char *argv[], Display *display, MSettings *themeSettings,
                   MSettings *commonSettings, MSettings *actionSettings,
                   MSettings *sessionSettings, bool isFirstRun)
{

    runlevel_ = START;

    // init, order is very important
    display_ = display;
    monitors_ = new CMonitor(this);
    themeSettings_ = themeSettings;
    commonSettings_ = commonSettings;
    actionSettings_ = actionSettings;
    sessionSettings_ = sessionSettings;
    actionBindings_ = new MBindings();
    isRecording_ = false;
    isMenuMode_ = false;
    isSloppyMode_ = true;
    isStackedTabbing_ = Util::get(commonSettings_, "cycle.mode") != "default";
    borderWidth_ = Util::strToUInt(Util::get(commonSettings_, "border.width"));

    LOGDEBUG("--- begin of new NCWM session ---");
    XSetErrorHandler(XCore::handleErrors);
    LOGDEBUG("error handler installed");
    XCORE->setDisplay(display_);
    LOGDEBUG("xcore initialized");
    Atoms::initAtoms();
    LOGDEBUG("atoms initialized");
    Cursors::initCursors();
    LOGDEBUG("cursors initialized");
    Actions::instance()->initInternActions(actionBindings_);
    LOGDEBUG("intern actions initialized");
    initActionBindings();
    LOGDEBUG("action bindings initialized");
    initMonitors();
    LOGDEBUG("monitors initialized");
    initKeys();
    LOGDEBUG("keys initialized");
    Launcher::instance()->exec(
            Util::get(themeSettings_, "exec"));
    if (isFirstRun) {
        Actions::instance()->executeTerm(0, "man ncwm");
    }
    // Sync all X buffers and wait until all events has been
    // processed
    XCORE->sync();
    initWindows();
    LOGDEBUG("windows initialized");

    defaultPrompt_ = new Prompt(": ", &Binder::queryActionKeysForPattern);

    Action* startupAction = new Action("startup", &Actions::sequence,
                                       &Validators::isAlwaysPossible,
                                       Action::SEQUENCE, 
                                       strdup(Util::get(commonSettings_,
                                                 "startup.chain").c_str()));
    startupAction->perform();
    delete startupAction;
    Expander::instance(); // rehash expander

    // Launch main event loop
    runlevel_ = RUN;
    int result = run();

    serialize();
    LOGDEBUG("current state serialized");
    LOGDEBUG("--- end of NCWM session ---");

    cleanup();

    if (runlevel_ == RESTART) {
        saveSettings();
        execvp(argv[0], argv);
        LOGERROR("restart failed", false);
        exit(1);
    }

    return result;
}
Esempio n. 10
0
int main(int argc, char **argv)
{
    XEvent event;
    
    done = False;
    rainbow = True;
    /* default to fullscreen */
    GLWin.fs = True;
    createGLWindow("NeHe's Particle Engine", 1920, 1280, 24, GLWin.fs);
    initKeys();
    /* wait for events*/ 
    while (!done)
    {
        /* handle the events in the queue */
        while (XPending(GLWin.dpy) > 0)
        {
            XNextEvent(GLWin.dpy, &event);
            switch (event.type)
            {
                case Expose:
	                if (event.xexpose.count != 0)
	                    break;
                    drawGLScene();
                    break;
                case ConfigureNotify:
                /* call resizeGLScene only if our window-size changed */
                    if ((event.xconfigure.width != GLWin.width) || 
                        (event.xconfigure.height != GLWin.height))
                    {
                        GLWin.width = event.xconfigure.width;
                        GLWin.height = event.xconfigure.height;
                        printf("Resize event\n");
                        resizeGLScene(event.xconfigure.width,
                            event.xconfigure.height);
                    }
                    break;
                /* exit in case of a mouse button press */
                case ButtonPress:     
                    done = True;
                    break;
                case KeyPress:
                    keys[event.xkey.keycode] = True;
                    break;
                case KeyRelease:
                    keys[event.xkey.keycode] = False;
                    break;
                case ClientMessage:    
                    if (*XGetAtomName(GLWin.dpy, event.xclient.message_type) == 
                        *"WM_PROTOCOLS")
                    {
                        printf("Exiting sanely...\n");
                        done = True;
                    }
                    break;
                default:
                    break;
            }
        }
        keyAction();
        drawGLScene();
    }
    killGLWindow();
    return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{
    bool bShowSettings = false;

    bool cmdline_err;

    MythCommandLineParser cmdline(
        kCLPOverrideSettingsFile |
        kCLPOverrideSettings     |
        kCLPQueryVersion);

    for (int argpos = 0; argpos < argc; ++argpos)
    {
        if (cmdline.PreParse(argc, argv, argpos, cmdline_err))
        {
            if (cmdline_err)
                return GENERIC_EXIT_INVALID_CMDLINE;

            if (cmdline.WantsToExit())
                return GENERIC_EXIT_OK;
        }
    }

    QApplication a(argc, argv);

    QFileInfo finfo(a.argv()[0]);
    QString binname = finfo.baseName();

    // Check command line arguments
    for (int argpos = 1; argpos < a.argc(); ++argpos)
    {
        if (!strcmp(a.argv()[argpos],"-v") ||
            !strcmp(a.argv()[argpos],"--verbose"))
        {
            if (a.argc()-1 > argpos)
            {
                if (parse_verbose_arg(a.argv()[argpos+1]) ==
                        GENERIC_EXIT_INVALID_CMDLINE)
                    return GENERIC_EXIT_INVALID_CMDLINE;

                ++argpos;
            }
            else
            {
                cerr << "Missing argument to -v/--verbose option\n";
                return GENERIC_EXIT_INVALID_CMDLINE;
            }
        }
        else if (!strcmp(a.argv()[argpos],"-s") ||
            !strcmp(a.argv()[argpos],"--setup"))
        {
            bShowSettings = true;
        }
        else if (!strcmp(a.argv()[argpos], "-l") ||
            !strcmp(a.argv()[argpos], "--logfile"))
        {
            if (a.argc()-1 > argpos)
            {
                logfile = a.argv()[argpos+1];
                if (logfile.startsWith("-"))
                {
                    cerr << "Invalid or missing argument to -l/--logfile option\n";
                    return GENERIC_EXIT_INVALID_CMDLINE;
                }
                else
                {
                    ++argpos;
                }
            }
            else
            {
                cerr << "Missing argument to -l/--logfile option\n";
                return GENERIC_EXIT_INVALID_CMDLINE;
            }
        }
        else if (cmdline.Parse(a.argc(), a.argv(), argpos, cmdline_err))
        {
            if (cmdline_err)
                return GENERIC_EXIT_INVALID_CMDLINE;

            if (cmdline.WantsToExit())
                return GENERIC_EXIT_OK;
        }
        else
        {
            showUsage(cmdline);
            return GENERIC_EXIT_INVALID_CMDLINE;
        }
    }

    gContext = new MythContext(MYTH_BINARY_VERSION);
    if (!gContext->Init())
    {
        VERBOSE(VB_IMPORTANT, "mythwelcome: Could not initialize MythContext. "
                        "Exiting.");
        return GENERIC_EXIT_NO_MYTHCONTEXT;
    }

    gCoreContext->SetAppName(binname);

    if (!MSqlQuery::testDBConnection())
    {
        VERBOSE(VB_IMPORTANT, "mythwelcome: Could not open the database. "
                        "Exiting.");
        return -1;
    }

    if (!logfile.isEmpty())
    {
        if (!log_rotate(true))
            cerr << "cannot open logfile; using stdout/stderr" << endl;
        else
            signal(SIGHUP, &log_rotate_handler);
    }

    LCD::SetupLCD();

    if (LCD *lcd = LCD::Get())
        lcd->switchToTime();

    MythTranslation::load("mythfrontend");

    GetMythUI()->LoadQtConfig();

#ifdef Q_WS_MACX
    // Mac OS 10.4 and Qt 4.4 have window-focus problems
    gCoreContext->SetSetting("RunFrontendInWindow", "1");
#endif

    MythMainWindow *mainWindow = GetMythMainWindow();
    mainWindow->Init();

    initKeys();

    if (bShowSettings)
    {
        MythShutdownSettings settings;
        settings.exec();
    }
    else
    {
        MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();

        WelcomeDialog *welcome = new WelcomeDialog(mainStack, "mythwelcome");

        if (welcome->Create())
            mainStack->AddScreen(welcome, false);
        else
            return -1;

        do
        {
            qApp->processEvents();
            usleep(5000);
        } while (mainStack->TotalScreens() > 0);
    }

    DestroyMythMainWindow();

    delete gContext;

    return 0;
}
Esempio n. 12
0
File: cpm.c Progetto: atluxity/cpm
/* if don't have any envorin variable at all */
int main(int argc, char **argv, char **envp)
#endif
#endif
  {
    rlim_t              memlock_limit = -2;
    int                 error = 0,
                        max_mem_lock = 0,
                        memory_safe = 0,
                        ptrace_safe = 0;
#ifdef TEST_OPTION
    int                 testrun = 0;
#endif
    char*               binaryname;

    savetermios();
    TRACE(99, "main()", NULL);

#ifndef HAVE_EXTERN_ENVIRON
#ifndef MANUAL_EXTERN_ENVIRON
    /* since in solaris environ does not exist, we manually pass it along */
    environ = envp;
#endif
#endif

    if (initSecurity(&max_mem_lock, &memory_safe, &ptrace_safe, &memlock_limit))
      { exit(1); }

    /* we initialize gettext */
    setlocale(LC_ALL, "");
#ifdef TEST_OPTION
    bindtextdomain(PACKAGE_NAME, "./po/");
#else
    bindtextdomain(PACKAGE_NAME, LOCALEDIR);
#endif
    textdomain(PACKAGE_NAME);

#ifndef LIBXML_TREE_ENABLED
    fprintf(stderr, _("Tree support not compiled in to libxml2 %s\n"),
        LIBXML_DOTTED_VERSION);
    exit(1);
#endif

    /*
     * This function installs "sighandler" to handle the SIGINT and returns a
     * pointer to the previously installed handler for this signal (which is
     * the default handler SIG_DFL initially). If we try to install another
     * handler to handle SIGINT at some other time... Then the new handler
     * replaces this current one and returns a pointer to this handler.
     */
    signal(SIGINT, sighandler);
    signal(SIGTERM, sighandler);
    /* the SIGWINCH handler is set in userInterface() */

    initConfiguration();

    runtime -> memlock_limit  = memlock_limit;
    runtime -> max_mem_lock   = max_mem_lock;
    runtime -> memory_safe    = memory_safe;
    runtime -> ptrace_safe    = ptrace_safe;

    initKeys();
    initPatternparser();
    initXML();
    initXMLInterface();

    if (getOptions(argc, argv))
      {
        fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
        error = 1;
      }
    if (!error && config -> help)
      { showHelp(); }
    else if (!error && config -> version)
      { showVersion(); }
    else if (!error)
      {
        getDefaultOptions();
        if (readResources())
            return 1;

        if (config -> dbfilecmd)
          {   /* the --file option must overwrite the resource file */
            runtime -> dbfile = resolveFilelink(config -> dbfilecmd);
          }
        else
          {   /* we use the resource file configuration or the compiletime
               * default
               */
            runtime -> dbfile = resolveFilelink(config -> dbfilerc);
          }
      }

    /* we switch to read-only mode on request */
    if (config -> readonly)
      { runtime -> readonly = 1; }

    /* in case our basename is cpmv, we switch to read-only mode */
    binaryname = basename(argv[0]);
    if (!strcmp(binaryname, "cpmv"))
      { runtime -> readonly = 1; }

    initGPG();

    if (!error && config -> security)
      { checkSecurity(0); }

#ifdef TEST_OPTION
    if (!error &&
        config -> testrun &&
        !strncmp(config -> testrun, "compress", 8))
      {
        testCompress();
        testrun = 1;
      }
    if (!error &&
        config -> testrun &&
        !strcmp(config -> testrun, "environment"))
      {
        testEnvironment();
        testrun = 1;
      }
    if (!error &&
        config -> testrun && (
        !strcmp(config -> testrun, "backup") ||
        !strcmp(config -> testrun, "garbage") ||
        !strcmp(config -> testrun, "searchpattern")))
      { testrun = 1; }
#endif

    if (config -> configtest &&
        !error)
      { fprintf(stderr, _("configuration ok.\n")); }

    if (config -> environtmentlist &&
        !error)
      { listEnvironment(); }

    if (!error &&
        !config -> configtest &&
        !config -> environtmentlist &&
        !config -> help &&
        !config -> security &&
        !config -> version)
      {
#ifdef TEST_OPTION
        if (checkSecurity(1) != MAX_SECURITY_LEVEL &&
            !config -> testrun)
#else
        if (checkSecurity(1) != MAX_SECURITY_LEVEL)
#endif
          {
            checkSecurity(0);
            printf("\n%s %s\n%s\n",
                _("Maximum security level not reached."),
                _("Your database will be less protected while CPM is running."),
                _("Are you sure you want to continue?"),
                _("Press CTRL+C to stop now or ENTER to continue."));

            fgetc(stdin);
          }
        if (runtime -> guimode)
          {   /* we run in interactive mode */
            userInterface();
          }
        else
          {   /* we run in CLI mode */
            error = cliInterface();
#ifdef TEST_OPTION
            if (error == 2)
              {   /* for testruns, we must modify the stuff a little */
                error = 0;
                testrun = 1;
              }
#endif
          }
      }

    freeGPG();
    freeXMLInterface();
    freeUTF8Interface();
    freeXML();
    freePatternparser();
    freeKeys();
    freeConfiguration();

    if (memCheck())
      {   /* we validate our memory consumption */
        fprintf(stderr, _("error: memory leak detected.\n"));
        if (memCheck() > 0)
          {
            fprintf(stderr, _("%ld byte of memory were not freed.\n"),
                memCheck());
          }
        else
          {
            fprintf(stderr,
                _("%ld byte of memory were freed without being allocated.\n"),
                memCheck());
          }

        fprintf(stderr, _("Please send a report about this problem to Harry Brueckner <*****@*****.**>.\n"));

        error = 1;
      }

#ifdef TEST_OPTION
    if (testrun)
      { return 0; }
    else
      { return error; }
#else
    return error;
#endif
  }
Esempio n. 13
0
int main(void)
{
	sysInfo = 0;
	
	SCS |= 0x01;
	FIODIR0 |= ((1<<21) | (1<<4) | (1<<11) | (1<<6) | (1<<23) | (1<<19) | (1<<17));
	FIODIR0 |= (1<<12);
	FIOSET0 |= (1<<12);
	xx = 0x00;

	setSpeed(SPEED_30);

	lcd_init(0);
	serial_init();

	startTimerIRQ();
	startADC();

	initKeys();

	initSound();
	startSoundIRQ();

	initIR();
	startIrIRQ();

    RF_init();
    startcc1100IRQ();
	enableWOR();
	
	initRTC();
	startRtcIRQ();
	
	enableIRQ();

	testmenu_init();
	init_menu();
	
	initBacklight();

	oldkeys[0] = keys[0];
	oldkeys[1] = keys[0];

	key_state = KEY_IDLE;

	set_font(BOLDFONT);
	
	BFS_Mount();
	load_RC_setting();
	load_RF_setting();
	load_setting();
	
	{
		struct RAWset_ RAWset;
        unsigned char x;
        unsigned long RAWcmdbase;
        
        RAWcmdbase = FLASH1_BASE +(secaddr[0]<<1);
        x=memcmp((void*)RAWcmdbase,"RC01",4);
		
        if(!x) {
               
				memcpy(&RAWset,(void *)RAWcmdbase,sizeof(struct RAWset_));
				RAWset.name[7] = 0;
				BFS_SaveFile(BFS_ID_RAWslot0, sizeof(struct RAWset_), (unsigned char*) &RAWset);
				eraseSector(1,0);
        }
	}
	
	if (EncIsValid(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set)) {
		setEncoder(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set);
	}	
	
	drawMainscreen();
	ask_for_time(0);
	
						
/*
	playSound((unsigned char*)sound1_data, sound1_len);
	waitSound();
	playSound((unsigned char*)sound2_data, sound2_len);
*/

	while (1)
	{
		if(keys[0] != oldkeys[0] || keys[1] != oldkeys[1])
		{
			oldkeys[0] = keys[0];
			oldkeys[1] = keys[1];
			sysInfo |= 0x40;
		}

		switch(key_state)
		{
			case KEY_IDLE:
				if(sysInfo & 0x40)
				{
					sysInfo &= 0xBF;
					if(KEY_Betty)
					{
						setBacklight(BL_AUTO);
						menu_exec(&mainMenu);
						if (EncIsValid(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set)) {
							setEncoder(irDevTab.device[irDevTab.active].encoder, irDevTab.device[irDevTab.active].set);
						}
						drawMainscreen();
					}
					else if(KEY_2)
					{
						//setSpeed(SPEED_30);
					}
					else if(KEY_3)
					{
						//setSpeed(SPEED_60);
					}
					else  if(KEY_A || KEY_B || KEY_C || KEY_D)
					{
						unsigned char x;
						//playSound((unsigned char*)sound3_data, sound3_len);
						x=0;
						if (KEY_B) x=1;
						if (KEY_C) x=2;
						if (KEY_D) x=3;
						
						if (EncIsValid(irDevTab.device[x].encoder, irDevTab.device[x].set)) {
							setBacklight(BL_AUTO);
							irDevTab.active = x;
							setEncoder(irDevTab.device[x].encoder, irDevTab.device[x].set);
							drawMainscreen();
						}	
					}
/*					else if(KEY_B)
					{
					
					}
					else if(KEY_C)
					{	
//						playSound((unsigned char*)sound1_data, sound1_len);
					}
					else if(KEY_D)
					{	
//						playSound((unsigned char*)sound2_data, sound2_len);
					}*/
					if((keys[0] != 0) || (keys[1] != 0))
						key_state = KEY_PRESS;
				}
				break;
			case KEY_PRESS:
				irSend(getCode());
				key_state = KEY_HOLD;
//				autorepeat = 0;
				break;
			case KEY_HOLD:
//				if(autorepeat >= AUTO_TIMEOUT)
					irRepeat();

				if(keys[0] == 0 && keys[1] == 0)
					key_state = KEY_RELEASE;

				break;
			case KEY_RELEASE:
				irStop();
				key_state = KEY_IDLE;
				break;
		}

		if(serial_tstc() > 0)
		{
			i = serial_getc();
			if(i=='.')
			{
				serial_puts("HELO");
			}
			else if(i=='0')
			{
				setBacklight(0x00);	// pwm value
			}
			else if(i=='1')
			{
				setBacklight(0x1F);	// pwm value
			}
			else if(i=='2')
			{
				setBacklight(0x3F);	// pwm value
			}
			else
				serial_putc(i);
		}
		
		if ((bl_val == 0) && (key_state == KEY_IDLE) && !((FIOPIN0 & (1<<30)) == 0) && (((RFstatus & (WORrxon | RXenabled)) == 0))) {
			EXTINT = 0x08;
			PCON = 0x02;
			PLLFEED = 0xAA;
			PLLFEED = 0x55;
		}
		
		if (timeInfo & timechanged) {
			printTime(86,152,(struct time_ *)&time);
			printDate(0,152,(struct date_ *)&date,0);
			
			timeInfo &= ~timechanged;
		}
		
	}
	return 0;
}
Esempio n. 14
0
int main(int argc, const char * argv[]) {
    
    //time
    char start_time[100];
    time_t now = time (0);
    strftime (start_time, 100, "%Y-%m-%d %H:%M:%S.000", localtime (&now));
    printf ("%s\n", start_time);
    
    /*for inputs */
    char binaryNumber[MAX],hexaDecimal[MAX];
    char *in;
    long int i=0,j=15;
    int temp;
    in = malloc(sizeof(in)*MAX);
    
    printf("Enter binary number of Input plain text: ");
    scanf("%s",binaryNumber);
    
    while(binaryNumber[i]){
        binaryNumber[i] = binaryNumber[i] -48;
        ++i;
    }
    
    --i;
    while(i-2>=0){
        temp =  binaryNumber[i-3] *8 + binaryNumber[i-2] *4 +  binaryNumber[i-1] *2 + binaryNumber[i] ;
        if(temp > 9){
            hexaDecimal[j] = temp + 55;
            j=j-1;
        }
        else{
            hexaDecimal[j] = temp + 48;
            j=j-1;
        }
        i=i-4;
    }
    
    if(i ==1)
        hexaDecimal[j] = binaryNumber[i-1] *2 + binaryNumber[i] + 48 ;
    else if(i==0)
        hexaDecimal[j] =  binaryNumber[i] + 48 ;
    else
        j++;
    
    printf("Equivalent hexadecimal value of input text is: ");
    int z = 15;
    while(z>=0){
        printf("%c",hexaDecimal[z]);
        z = z-1;
    }
    
    in = hexaDecimal;
    Input_Text = strtoull(in, (char **)NULL, 16);
    printf("\n Input text is : %016llx", Input_Text);
    
    
    
    //cypher text
    char binaryNumber1[MAX],hexaDecimal1[MAX];
    char *in1;
    long int i1=0,j1=15;
    int temp1;
    in1 = malloc(sizeof(in)*MAX);
    
    printf("\n Enter cipher text number: ");
    scanf("%s",binaryNumber1);
    
    while(binaryNumber1[i1]){
        binaryNumber1[i1] = binaryNumber1[i1] -48;
        ++i1;
    }
    
    --i1;
    while(i1-2>=0){
        temp1 =  binaryNumber1[i1-3] *8 + binaryNumber1[i1-2] *4 +  binaryNumber1[i1-1] *2 + binaryNumber1[i1] ;
        if(temp1 > 9){
            hexaDecimal1[j1] = temp1 + 55;
            j1=j1-1;
        }
        else{
            hexaDecimal1[j1] = temp1 + 48;
            j1=j1-1;
        }
        i1=i1-4;
    }
    
    if(i1 ==1)
        hexaDecimal1[j1] = binaryNumber1[i1-1] *2 + binaryNumber1[i1] + 48 ;
    else if(i1==0)
        hexaDecimal1[j1] =  binaryNumber1[i1] + 48 ;
    else
        j1++;
    
    printf("Equivalent hexadecimal value of cypher text: ");
    int z1 = 15;
    while(z1>=0){
        printf("%c",hexaDecimal1[z1]);
        z1 = z1-1;
    }
    
    in1 = hexaDecimal1;
    Cypher_Text = strtoull(in1, (char **)NULL, 16);
    printf("\n cypher text is : %016llx", Cypher_Text);
    
    
    int round_input;
    printf("\n no of rounds");
    scanf("%d",&round_input);
    
    clock_t start, end;
    start = clock();
    end = clock();
    
    ip_address = getIP();   //Fetch the current system IP Address
    
    /* socket - client connection */
    
    struct sockaddr_in serverAddr;
    socklen_t addr_size;
    
    /*---- Create the socket. The three arguments are: ----*/
    /* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */
    int client_socket;
    client_socket = socket(PF_INET, SOCK_STREAM, 0);
    
    /*---- Configure settings of the server address struct ----*/
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port = htons(9999);
    serverAddr.sin_addr.s_addr = inet_addr(ip_address);
    memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
    
    /*---- Connect the socket to the server using the address struct ----*/
    addr_size = sizeof serverAddr;
    if (connect(client_socket, (struct sockaddr *) &serverAddr, addr_size) < 0){
        printf("not connected to server \n");
    }
    
    
    //creating a thread for listing from server all time of process
    pthread_t sockThread;
    int res = pthread_create(&sockThread, NULL, handleHostMessages,(void *)&client_socket);
    
    
    /* Params initialisation */
    
    initKeys();
    
    for (int i=0; i < NTHREADS; i++) {
        params[i].input_text = Input_Text;
        params[i].key = keys[i];
        params[i].client_socket = client_socket;
        params[i].round = round_input;
        params[i].cipher_Text =Cypher_Text;
    }
    printf("client socket is : %d \n",params[0].client_socket);
    
    /* thread creation */
    
    pthread_t threads[NTHREADS];
    int thread_args[NTHREADS];
    int rc;
    
    for (int i=0; i < NTHREADS; i++) {
        thread_args[i] = i;
        rc = pthread_create(&threads[i], NULL, DES_Algorithm,(void *)&params[i]);
        if (rc != 0) {
            printf("Thread %d creation failed ! \n", i);
        }
    }
    
    /* wait for threads to finish */
    for (int i=0; i<NTHREADS; ++i) {
        rc = pthread_join(threads[i], NULL);
    }
    
    printf("\n time taken is :%lu \n",start-end);
    
    exit (0);
}