Beispiel #1
0
int ProcessFocusedCommand(char* command)
{
	int ret = 0;
	int sec = 0;
	int NodeID;
	int NodeType;
	UNS32 data = 0;
	char buf[50];
    int size;
	int index;
	int subindex = 0;
	int datatype = 0;

	EnterMutex();
	switch(command[0])
	{

		case 's' : /* Slave Start*/
					StartNode(CurrentNode);
					break;
        case 't' : /* slave stop */
					StopNode(CurrentNode);
					break;
        case 'x' : /* slave reset */
					ResetNode(CurrentNode);
					break;
		case 'r' : /* Read device entry */
	                ret = sscanf(command, "r%4x,%2x", &index, &subindex);
                    if (ret)
                        ReadSDOEntry(CurrentNode,index,subindex);
					break;
		case 'w' : /* Write device entry */
	                ret = sscanf(command, "w%4x,%2x,%2x,%x", &index, &subindex, &size, &data);
                    if (ret)
                        WriteSDOEntry(CurrentNode,index,subindex,size,data);
					break;
		case '?' : /* Read device entry */
                    ReadSDOEntry(CurrentNode,0x6041,0);
					break;
		case 'c' : /* Write device entry */
	                ret = sscanf(command, "w%x", &data);
                    if (ret)
                        WriteSDOEntry(CurrentNode,0x6040,0,0x2,data);
					break;
		
		default :
					help_menu();
	}
	LeaveMutex();
	return 0;
}
Beispiel #2
0
int main(int argc, char** argv)
{
	extern char *optarg;
	char command[200];
	char* res;
	int ret=0;
	int sysret=0;
	int i=0;

	/* Print help and exit immediatly*/
	if(argc < 2)
	{
		help_menu();
		exit(1);
	}

	/* Init stack timer */
	TimerInit();

	/* Strip command-line*/
	for(i=1 ; i<argc ; i++)
	{
		if(ProcessCommand(argv[i]) == INIT_ERR) goto init_fail;
	}

	/* Enter in a loop to read stdin command until "quit" is called */
	while(ret != QUIT)
	{
		// wait on stdin for string command
		res = fgets(command, sizeof(command), stdin);
		sysret = system(CLEARSCREEN);
		ret = ProcessCommand(command);
		fflush(stdout);
	}

	printf("Finishing.\n");

	// Stop timer thread
	StopTimerLoop(&Exit);

	/* Close CAN board */
	canClose(CANOpenShellOD_Data);

init_fail:
	TimerCleanup();
	return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	QWidget container;
	container.resize(640, 680);
	container.setFocusPolicy ( Qt::NoFocus );
	Engine engine(NULL);

	QMenuBar open_menu_bar(&container);
	QMenu open_menu("&File", &container);

	QAction open("&Open", &container);
	open.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
	open_menu.addAction(&open);

	QAction reset("&Reset", &container);
	reset.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
	open_menu.addAction(&reset);

	QAction save("&Save", &container);
	save.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
	open_menu.addAction(&save);

	QAction close("&Close", &container);
	close.setShortcut(QKeySequence(Qt::ALT + Qt::Key_F4));
	open_menu.addAction(&close);

	QMenu draw_menu("&Drawmodes", &container);

	QAction points("&Points", &container);
	points.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
	draw_menu.addAction(&points);

	QAction wire("&Wireframe", &container);
	wire.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
	draw_menu.addAction(&wire);

	QAction flat("&Flat shaded", &container);
	flat.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F));
	draw_menu.addAction(&flat);

	QAction smooth("&Smooth shaded", &container);
	smooth.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
	draw_menu.addAction(&smooth);

	/**** MENU CONVEX HULL ****/
	QMenu convex_hull("Convex Hull", &container);

	QAction calc("&Calculate CH", &container);
	calc.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
	convex_hull.addAction(&calc);

	/**** MENU HELP ****/
	QMenu help_menu("&?", &container);

	QAction help("&Help", &container);
	help.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_H));
	help_menu.addAction(&help);

	QAction about("&About", &container);
	about.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A));
	help_menu.addAction(&about);
	
	open_menu_bar.addMenu(&open_menu);
	open_menu_bar.addMenu(&draw_menu);
	open_menu_bar.addMenu(&convex_hull);
	open_menu_bar.addMenu(&help_menu);
	
	Window_gl window(&container);
	window.setGeometry(0,22,640, 680);

	container.show();
	
	QDialog instructions( NULL );
	instructions.setFixedSize(300,180);
	instructions.setWindowTitle("Help");
	QLabel instr_text("\nUp - Sposta l'osservatore verso l'alto\nDown - Sposta l'osservatore verso il basso\nLeft - Ruota verso sinistra\nRight - Ruota verso destra\nShift+Up - Zoom In\nShift+Down - Zoom out\n\nSi ricorda che il programma e' in grado di gestire\nsolo files di tipo .OFF.\nAltri formati non sono attualmente supportati.", &instructions);
	instr_text.setTextFormat(Qt::AutoText);
	instr_text.setWordWrap(true);
	instructions.hide();

	QDialog credits( NULL );
	credits.setFixedSize(300,100);
	credits.setWindowTitle("Credits");
	QLabel cred_text("\tCGVew v.1.7\n\nA cura di Fabio Guggeri ([email protected])\ne Stefano Marras ([email protected]).\n", &credits);
	cred_text.setTextFormat(Qt::AutoText);
	cred_text.setWordWrap(true);
	credits.hide();

	QObject::connect( &open, SIGNAL(triggered()), &engine, SLOT(open_file()) );
	QObject::connect( &reset, SIGNAL(triggered()), &window, SLOT(reset()) );
	QObject::connect( &reset, SIGNAL(triggered()), &engine, SLOT(reset()) );
	QObject::connect( &save, SIGNAL(triggered()), &engine, SLOT(save_file()) );
	QObject::connect( &points, SIGNAL(triggered()), &window, SLOT(set_p_drawmode()) );
	QObject::connect( &wire, SIGNAL(triggered()), &window, SLOT(set_w_drawmode()) );
	QObject::connect( &flat, SIGNAL(triggered()), &window, SLOT(set_f_drawmode()) );
	QObject::connect( &smooth, SIGNAL(triggered()), &window, SLOT(set_s_drawmode()) );
	QObject::connect( &help, SIGNAL(triggered()), &instructions, SLOT(show()) );
	QObject::connect( &about, SIGNAL(triggered()), &credits, SLOT(show()) );
	QObject::connect( &close, SIGNAL(triggered()), &app, SLOT(quit()) );
	QObject::connect( &engine, SIGNAL(send_dcel(QVector<DCEL>&)), &window, SLOT(add_dcel(QVector<DCEL>&)) );
	QObject::connect( &calc, SIGNAL(triggered()), &engine, SLOT(calculate_ch()) );

	window.setFocus();

	return app.exec();
}
Beispiel #4
0
int ProcessCommand(char* command)
{
	int ret = 0;
	int sec = 0;
	int NodeID;
	int NodeType;

	EnterMutex();
	switch(cst_str4(command[0], command[1], command[2], command[3]))
	{
		case cst_str4('h', 'e', 'l', 'p') : /* Display Help*/
					help_menu();
					break;
		case cst_str4('s', 's', 't', 'a') : /* Slave Start*/
					StartNode(ExtractNodeId(command + 5));
					break;
		case cst_str4('s', 's', 't', 'o') : /* Slave Stop */
					StopNode(ExtractNodeId(command + 5));
					break;
		case cst_str4('s', 'r', 's', 't') : /* Slave Reset */
					ResetNode(ExtractNodeId(command + 5));
					break;
		case cst_str4('i', 'n', 'f', 'o') : /* Retrieve node informations */
					GetSlaveNodeInfo(ExtractNodeId(command + 5));
					break;
		case cst_str4('r', 's', 'd', 'o') : /* Read device entry */
					ReadDeviceEntry(command);
					break;
		case cst_str4('w', 's', 'd', 'o') : /* Write device entry */
					WriteDeviceEntry(command);
					break;
		case cst_str4('s', 'c', 'a', 'n') : /* Display master node state */
					DiscoverNodes();
					break;
		case cst_str4('w', 'a', 'i', 't') : /* Display master node state */
					ret = sscanf(command, "wait#%d", &sec);
					if(ret == 1) {
						LeaveMutex();
						SleepFunction(sec);
						return 0;
					}
					break;
		case cst_str4('q', 'u', 'i', 't') : /* Quit application */
					LeaveMutex();
					return QUIT;
		case cst_str4('l', 'o', 'a', 'd') : /* Library Interface*/
					ret = sscanf(command, "load#%100[^,],%30[^,],%4[^,],%d,%d",
							LibraryPath,
							BoardBusName,
							BoardBaudRate,
							&NodeID,
							&NodeType);

					if(ret == 5)
					{
						LeaveMutex();
						ret = NodeInit(NodeID, NodeType);
						return ret;
					}
					else
					{
						printf("Invalid load parameters\n");
					}
					break;
		default :
					help_menu();
	}
	LeaveMutex();
	return 0;
}
Beispiel #5
0
int main (int argc, char* argv[])
{  
  // switches to detect input
  bool inputGiven = false;
  
  // attempt to parse command line arguments
  po::variables_map vm;
  try
  {
    // initialize the input options
    po::options_description help_menu("Allowed options");
    help_menu.add_options()
      ("help,h", "display this help dialog")
      ("input,i", po::value<std::string>(), "path to input file")
      ("fast,f", po::value<int>()->default_value(12),
       "set the number of days to look back for the fast EMA, defaults to 12")
      ("slow,s", po::value<int>()->default_value(26),
       "set the number of days to look back for the slow EMA, defaults to 26")
      ("signal,g", po::value<int>()->default_value(9),
       "set the number of days to look back for the signal, defaults to 9");
    
    // parse the input options
    po::store(po::parse_command_line(argc, argv, help_menu), vm);
    po::notify(vm);    
    
    // if help is requested
    if (vm.count("help"))
    {
      std::cout << help_menu;
      return 0; // do not attempt anything else, simply return
    }

    // given an input file
    if (vm.count("input"))
    {
      inputGiven = true;
    }

  }
  catch(std::exception& e) {
    std::cerr << "error: " << e.what() << "\n";
    return 1;
  }
  catch(...) {
    std::cerr << "Exception of unknown type!" << "\n";
  } // try to read the input options

  // check if there was enough information given
  if (inputGiven)
  {
    // parse the input file
    std::string inputFilePath  = vm["input"].as<std::string>();
    hw3::GoogleHistoryParser parser;
    hw3::PriceHistory priceHistory = parser.parse(inputFilePath);
    
    // check if the parsing was successful
    if (parser.wasSuccessful())
    {
      // settings for the MACD analysis
      int fastEMA = vm["fast"].as<int>();
      int slowEMA = vm["slow"].as<int>();
      int signal  = vm["signal"].as<int>();
      
      // perform the MACD analysis
      hw3::MACD macd(fastEMA, slowEMA, signal);
      hw3::FullAnalysis analysis = macd.analyze(priceHistory);
      
      // search the analysis for entry pertaining june 1st 2015
      greg::date june1st(2015,06,01);
      hw3::FullAnalysis::const_iterator entry;
      entry = std::find_if(analysis.begin(), analysis.end(),
			   [&june1st](const hw3::AnalysisEntry& entry) -> bool
			   {
			     return entry.getDate() == june1st;
			   });
      
      // attempt to output the macd of the stock on 1 June, 2015
      if (entry != analysis.end())
      {
	std::cout << entry->getMACD() << std::endl;
      }
      else
      {
	std::cout << "No data for June 1st, 2015 found." << std::endl;
      }
    }
    else
    {
      std::cout << "Unable to parse pricing history!" << std::endl;
    } // if success parsing
  }
  else
  {
    std::cout << "No input file given" << std::endl;
  } // if input given
  
  return 0;
} // main
Beispiel #6
0
void Keyboard::read_keyboard (SDL_Event *pevento2) {

	unsigned int temporal_io;
	SDL_Event evento,evento2,*pevento;
	Sint16 valor;
	Uint8 eje;

	if (pevento2==NULL) {
		pevento=&evento;
		if (!SDL_PollEvent (&evento))
			return;
	} else {
		pevento=pevento2;
	}

	if (pevento->type==SDL_QUIT) {
		salir = 0;
		return;
	}

	if (pevento->type==SDL_MOUSEMOTION) {
		this->mouse_x += pevento->motion.xrel;
		this->mouse_y += pevento->motion.yrel;
		return;
	}

	if (pevento->type==SDL_MOUSEBUTTONDOWN) {
		switch (pevento->button.button) {
		case SDL_BUTTON_LEFT:
			this->mouse_left = true;
		break;
		case SDL_BUTTON_MIDDLE:
			this->mouse_center = true;
		break;
		case SDL_BUTTON_RIGHT:
			this->mouse_right = true;
		break;
		}
	}

	if (pevento->type==SDL_MOUSEBUTTONUP) {
		switch (pevento->button.button) {
		case SDL_BUTTON_LEFT:
			this->mouse_left = false;
		break;
		case SDL_BUTTON_MIDDLE:
			this->mouse_center = false;
		break;
		case SDL_BUTTON_RIGHT:
			this->mouse_right = false;
		break;
		}
	}

	if (pevento->type==SDL_JOYBUTTONDOWN) {
		pevento->type=SDL_KEYDOWN;
		pevento->key.keysym.sym=SDLK_MENU; // emulate pressing the MENU key
	}

	if (pevento->type==SDL_JOYBUTTONUP) {
		pevento->type=SDL_KEYUP;
		pevento->key.keysym.sym=SDLK_MENU; // emulate depressing the MENU key
	}

	if (pevento->type==SDL_JOYAXISMOTION) {
		eje=pevento->jaxis.axis;
		valor=pevento->jaxis.value;

		evento2.type=SDL_KEYUP;
		if ((valor<16384)&&(valor>-16384)) { // JoyStick centered
			pevento->type=SDL_KEYUP;
			if (eje==1) {
				evento2.key.keysym.sym=SDLK_DOWN;
				pevento->key.keysym.sym=SDLK_UP; // pull up both keys
				read_keyboard(&evento2);
			}
			if (eje==0) {
				evento2.key.keysym.sym=SDLK_LEFT;
				pevento->key.keysym.sym=SDLK_RIGHT;
				read_keyboard(&evento2);
			}
		} else { // JoyStick moved
			if (eje==0) {
				if (valor>=0) {
					evento2.key.keysym.sym=SDLK_LEFT; // pull up LEFT
					read_keyboard(&evento2);
					pevento->key.keysym.sym=SDLK_RIGHT; // and press RIGHT
				} else {
					evento2.key.keysym.sym=SDLK_RIGHT; // pull up RIGHT
					read_keyboard(&evento2);
					pevento->key.keysym.sym=SDLK_LEFT; // and press LEFT
				}
			}
			if (eje==1) {
				if (valor<0) {
					evento2.key.keysym.sym=SDLK_DOWN; // pull up DOWN
					pevento->key.keysym.sym=SDLK_UP; // and press UP
					read_keyboard(&evento2);
				} else {
					evento2.key.keysym.sym=SDLK_UP; // pull up UP
					pevento->key.keysym.sym=SDLK_DOWN; // and press DOWN
					read_keyboard(&evento2);
				}
			}
			pevento->type=SDL_KEYDOWN;
		}
	}

	if ((pevento->type != SDL_KEYDOWN) && (pevento->type != SDL_KEYUP))
		return;

	this->k8 = this->k9 = this->k10 = this->k11 =
		this->k12 = this->k13 = this->k14 =
		this->k15 = 0;
		this->jk = 0;

	temporal_io = (unsigned int) pevento->key.keysym.sym;

	if ((pevento->type==SDL_KEYUP)&&(temporal_io==SDLK_TAB)) {
		if (!this->tab_extended) {
			this->tab_extended = true;
			osd->set_message("Function Key mode on",2000);
			return;
		} else {
			this->tab_extended = false;
			osd->clear_message();
			return;
		}
	}

	if ((pevento->type==SDL_KEYDOWN)&&(this->tab_extended))
		return;

	if ((pevento->type==SDL_KEYUP)&&(this->tab_extended)) {
		this->tab_extended = false;

		osd->clear_message();

		switch(temporal_io) {
		case SDLK_1:
			temporal_io=SDLK_F1;
		break;
		case SDLK_2:
			temporal_io=SDLK_F2;
		break;
		case SDLK_3:
			temporal_io=SDLK_F3;
		break;
		case SDLK_4:
			temporal_io=SDLK_F4;
		break;
		case SDLK_5:
			temporal_io=SDLK_F5;
		break;
		case SDLK_6:
			temporal_io=SDLK_F6;
		break;
		case SDLK_7:
			temporal_io=SDLK_F7;
		break;
		case SDLK_8:
			temporal_io=SDLK_F8;
		break;
		case SDLK_9:
			temporal_io=SDLK_F9;
		break;
		case SDLK_0:
			temporal_io=SDLK_F10;
		break;
		case SDLK_o:
			temporal_io=SDLK_F11;
		break;
		case SDLK_p:
			temporal_io=SDLK_F12;
		break;
		}
	}


	if (pevento->type == SDL_KEYUP)
		switch (temporal_io) {
		case SDLK_ESCAPE:	// to exit from the emulator
			if (!this->esc_again) {
				this->esc_again = true;
				osd->set_message("ESC again to exit",2000);
			} else
				salir = 0;
			return;
			break;
		case SDLK_F1:
			help_menu ();	// shows the help menu
			break;

		case SDLK_F2:
		case SDLK_F3:
		case SDLK_F4:
		case SDLK_F7:
		case SDLK_F8:
			launch_menu(temporal_io);
			break;

		case SDLK_F5:   // STOP tape
			OOTape->set_pause(true);
			llsound->set_speed(ordenador->turbo);
			break;

		case SDLK_F6:	// PLAY tape
			OOTape->set_pause(false);
			if (ordenador->turbo_play) {
				llsound->set_speed(true);
			} else {
				llsound->set_speed(ordenador->turbo);
			}
			break;

		case SDLK_F9:
			llscreen->fullscreen_switch();
			break;

		case SDLK_F10:	// Reset emulator
			ResetComputer ();
			OOTape->set_pause(true);
			OOTape->rewind();
		break;

		case SDLK_F11:	// lower volume
			llsound->decrease_volume();
		break;

		case SDLK_F12:	// upper volume
			llsound->increase_volume();
		break;
		}

	// reorder joystick if screen is rotated

	if(ordenador->zaurus_mini==2) {
		switch(temporal_io) {
		case SDLK_UP:
			temporal_io=SDLK_LEFT;
		break;
		case SDLK_LEFT:
			temporal_io=SDLK_DOWN;
		break;
		case SDLK_DOWN:
			temporal_io=SDLK_RIGHT;
		break;
		case SDLK_RIGHT:
			temporal_io=SDLK_UP;
		break;
		}
	}


	// test for joystick

	switch (temporal_io) {
	case SDLK_UP:
		switch (this->joystick) {
		case 0:	// cursor
			temporal_io = SDLK_7;
		break;

		case 1:
			this->jk = 8;
		break;

		case 2:	// sinclair 1
			temporal_io = SDLK_4;
		break;

		case 3:	// sinclair 2
			temporal_io = SDLK_9;
		break;
		}
	break;

	case SDLK_DOWN:
		switch (this->joystick) {
		case 0:	// cursor
			temporal_io = SDLK_6;
		break;

		case 1:
			this->jk = 4;
		break;

		case 2:	// sinclair 1
			temporal_io = SDLK_3;
		break;

		case 3:	// sinclair 2
			temporal_io = SDLK_8;
		break;
		}
	break;

	case SDLK_RIGHT:
		switch (this->joystick) {
		case 0:	// cursor
			temporal_io = SDLK_8;
		break;

		case 1:
			this->jk = 1;
		break;

		case 2:	// sinclair 1
			temporal_io = SDLK_1;
		break;

		case 3:	// sinclair 2
			temporal_io = SDLK_6;
		break;

		}
	break;

	case SDLK_LEFT:
		switch (this->joystick) {
		case 0:	// cursor
			temporal_io = SDLK_5;
		break;

		case 1:
			this->jk = 2;
		break;

		case 2:	// sinclair 1
			temporal_io = SDLK_2;
		break;

		case 3:	// sinclair 2
			temporal_io = SDLK_7;
		break;
		}
	break;

	case SDLK_RALT:
	case SDLK_RMETA:
	case SDLK_LMETA:
	case SDLK_RSUPER:
	case SDLK_LSUPER:
	case SDLK_MENU:
		switch (this->joystick) {
		case 0:	// cursor
			temporal_io = SDLK_0;
		break;

		case 1:
			this->jk = 16;
		break;

		case 2:	// sinclair 1
			temporal_io = SDLK_5;
		break;

		case 3:	// sinclair 2
			temporal_io = SDLK_0;
		break;
		}
	break;
	}

	switch (temporal_io) {

	case SDLK_SPACE:
		this->k15 = 1;
	break;

	case SDLK_RCTRL:
	case SDLK_LCTRL:
		this->k15 = 2;
	break;

	case SDLK_m:
		this->k15 = 4;
	break;

	case SDLK_n:
		this->k15 = 8;
	break;

	case SDLK_b:
		this->k15 = 16;
	break;

	case SDLK_RETURN:
		this->k14 = 1;
	break;

	case SDLK_l:
		this->k14 = 2;
	break;

	case SDLK_k:
		this->k14 = 4;
	break;

	case SDLK_j:
		this->k14 = 8;
	break;

	case SDLK_h:
		this->k14 = 16;
	break;

	case SDLK_p:
		this->k13 = 1;
	break;

	case SDLK_o:
		this->k13 = 2;
	break;

	case SDLK_i:
		this->k13 = 4;
	break;

	case SDLK_u:
		this->k13 = 8;
	break;

	case SDLK_y:
		this->k13 = 16;
	break;

	case SDLK_0:
		this->k12 = 1;
	break;

	case SDLK_9:
		this->k12 = 2;
	break;

	case SDLK_8:
		this->k12 = 4;
	break;

	case SDLK_7:
		this->k12 = 8;
	break;

	case SDLK_6:
		this->k12 = 16;
	break;

	case SDLK_1:
		this->k11 = 1;
	break;

	case SDLK_2:
		this->k11 = 2;
	break;

	case SDLK_3:
		this->k11 = 4;
	break;

	case SDLK_4:
		this->k11 = 8;
	break;

	case SDLK_5:
		this->k11 = 16;
	break;

	case SDLK_q:
		this->k10 = 1;
	break;

	case SDLK_w:
		this->k10 = 2;
	break;

	case SDLK_e:
		this->k10 = 4;
	break;

	case SDLK_r:
		this->k10 = 8;
	break;

	case SDLK_t:
		this->k10 = 16;
	break;

	case SDLK_a:
		this->k9 = 1;
	break;

	case SDLK_s:
		this->k9 = 2;
	break;

	case SDLK_d:
		this->k9 = 4;
	break;

	case SDLK_f:
		this->k9 = 8;
	break;

	case SDLK_g:
		this->k9 = 16;
	break;

	case SDLK_RSHIFT:
	case SDLK_LSHIFT:
		this->k8 = 1;
	break;

	case SDLK_z:
		this->k8 = 2;
	break;

	case SDLK_x:
		this->k8 = 4;
	break;

	case SDLK_c:
		this->k8 = 8;
	break;

	case SDLK_v:
		this->k8 = 16;
	break;

	case SDLK_BACKSPACE:
		this->k12 = 1;
		this->k8 = 1;
	break;
	case SDLK_PERIOD:
		this->k15 = 6;
	break;
	case SDLK_COMMA:
		this->k15 = 10;
	break;

	}

	if (pevento->type == SDL_KEYUP) {
		this->s8 |= this->k8;
		this->s9 |= this->k9;
		this->s10 |= this->k10;
		this->s11 |= this->k11;
		this->s12 |= this->k12;
		this->s13 |= this->k13;
		this->s14 |= this->k14;
		this->s15 |= this->k15;
		this->js &= (this->jk ^ 255);
	} else {
		this->s8 &= (this->k8 ^ 255);
		this->s9 &= (this->k9 ^ 255);
		this->s10 &= (this->k10 ^ 255);
		this->s11 &= (this->k11 ^ 255);
		this->s12 &= (this->k12 ^ 255);
		this->s13 &= (this->k13 ^ 255);
		this->s14 &= (this->k14 ^ 255);
		this->s15 &= (this->k15 ^ 255);
		this->js |= this->jk;
	}

	return;
}
Beispiel #7
0
int main(int argc, char** argv)
{
	extern char *optarg;
	char command[200];
	char* res;
	int ret=0;
	int sysret=0;
	int i=0;

	if (sem_init(&Write_sem, 0, 0) == -1)
        handle_error("Writesem_init");
	if (sem_init(&Read_sem, 0, 0) == -1)
        handle_error("Readsem_init");	
	/* Defaults */
	strcpy(LibraryPath,"/usr/lib/libcanfestival_can_peak_linux.so");
	strcpy(BoardBusName,"0");
	strcpy(BoardBaudRate,"1M");

	/* Init stack timer */
	TimerInit();
        
	if (argc > 1){
        printf("ok\n");
		/* Strip command-line*/
		for(i=1 ; i<argc ; i++)
		{
			if(ProcessCommand(argv[i]) == INIT_ERR) goto init_fail;
		}
	}
    NodeInit(0,1);

    RegisterSetODentryCallBack(CANOpenShellOD_Data, 0x2003, 0, &OnStatus3Update);


	help_menu();
	CurrentNode = 3;
    sleep(1);
    //setState(CANOpenShellOD_Data, Operational);     // Put the master in operational mode
    stopSYNC(CANOpenShellOD_Data);

	/* Enter in a loop to read stdin command until "quit" is called */
	while(ret != QUIT)
	{
		// wait on stdin for string command
		rl_on_new_line ();
		res = rl_gets();
		//sysret = system(CLEARSCREEN);
		if(res[0]=='.'){
		ret = ProcessCommand(res+1);
		}
		else if(res[0]==','){
		ret = ProcessFocusedCommand(res+1);
		}
        else if (res[0]=='\n'){

        }
		else {
			
			EnterMutex();
			SDO_write(CANOpenShellOD_Data,CurrentNode,0x1023,0x01,strlen(res),visible_string, res, 0);

			EnterMutex();
			SDO_read(CANOpenShellOD_Data,CurrentNode,0x1023,0x03,visible_string,0);
			
			printf("%s\n",SDO_read_data);
		}
		fflush(stdout);
        usleep(500000);
	}

	printf("Finishing.\n");

	// Stop timer thread
	StopTimerLoop(&Exit);

	/* Close CAN board */
	canClose(CANOpenShellOD_Data);

init_fail:
	TimerCleanup();
	return 0;
}
Beispiel #8
0
int ProcessCommand(char* command)
{
	int ret = 0;
	int sec = 0;
	int NodeID;
	int NodeType;
	UNS32 data = 0;
	char buf[50];

	EnterMutex();
	switch(cst_str4(command[0], command[1], command[2], command[3]))
	{
		case cst_str4('h', 'e', 'l', 'p') : /* Display Help*/
					help_menu();
					break;
		case cst_str4('c', 'l', 'e', 'a') : /* Display Help*/
					system(CLEARSCREEN);
					break;					
		case cst_str4('s', 's', 't', 'a') : /* Slave Start*/
					StartNode(ExtractNodeId(command + 5));
					break;
		case cst_str4('s', 's', 't', 'o') : /* Slave Stop */
					StopNode(ExtractNodeId(command + 5));
					break;
		case cst_str4('s', 'r', 's', 't') : /* Slave Reset */
					ResetNode(ExtractNodeId(command + 5));
					break;
		case cst_str4('i', 'n', 'f', 'o') : /* Retrieve node informations */
					GetSlaveNodeInfo(ExtractNodeId(command + 5));
					break;
		case cst_str4('r', 's', 'd', 'o') : /* Read device entry */
					ReadDeviceEntry(command);
					break;
		case cst_str4('w', 's', 'd', 'o') : /* Write device entry */
					WriteDeviceEntry(command);
					break;
		case cst_str4('n', 'o', 'd', 'e') : /* Write device entry */
					ret = sscanf(command, "node %2x", &NodeID);
					data = 0;
					SDO_write(CANOpenShellOD_Data,NodeID,0x1024,0x00,1, 0, &data, 0);
					CurrentNode = NodeID;
					break;
		case cst_str4('c', 'm', 'd', ' ') : /* Write device entry */

					ret = sscanf(command, "cmd %2x,%s", &NodeID, buf );
					SDO_write(CANOpenShellOD_Data,NodeID,0x1023,0x01,strlen(buf),visible_string, buf, 0);
					SDO_read(CANOpenShellOD_Data,NodeID,0x1023,0x03,visible_string,0);
					
					return 0;
					break;

		case cst_str4('s', 'y', 'n', '0') : /* Display master node state */
                    stopSYNC(CANOpenShellOD_Data);
                    break;
		case cst_str4('s', 'y', 'n', '1') : /* Display master node state */
                    startSYNC(CANOpenShellOD_Data);
                    break;
		case cst_str4('s', 't', 'a', 't') : /* Display master node state */
                    printf("Status3: %x\n",Status3);
                    Status3 = 0;
                    break;
		case cst_str4('s', 'c', 'a', 'n') : /* Display master node state */
					DiscoverNodes();
					break;
		case cst_str4('w', 'a', 'i', 't') : /* Display master node state */
					ret = sscanf(command, "wait#%d", &sec);
					if(ret == 1) {
						LeaveMutex();
						SleepFunction(sec);
						return 0;
					}
					break;
		case cst_str4('g', 'o', 'o', 'o') : /* Quit application */
            setState(CANOpenShellOD_Data, Operational);
            break;
		case cst_str4('q', 'u', 'i', 't') : /* Quit application */
					LeaveMutex();
					return QUIT;
		case cst_str4('l', 'o', 'a', 'd') : /* Library Interface*/
					ret = sscanf(command, "load#%100[^,],%30[^,],%4[^,],%d,%d",
							LibraryPath,
							BoardBusName,
							BoardBaudRate,
							&NodeID,
							&NodeType);

					if(ret == 5)
					{
						LeaveMutex();
						ret = NodeInit(NodeID, NodeType);
						return ret;
					}
					else
					{
						printf("Invalid load parameters\n");
					}
					break;
		default :
					help_menu();
	}
	LeaveMutex();
	return 0;
}
Beispiel #9
0
int main_menu(WINDOW* screen)
{
    int max_x, max_y;
    getmaxyx(screen, max_y, max_x);

    char* title_menu_l[4] = {"Play!", "Options", "Help", "Quit"};
    struct Menu* title_menu = new_menu(max_x / 8, 8, 4, title_menu_l, BLUE_ON_BLACK, GREEN_ON_BLACK);

    //For the moving background...
    struct Ball* ball = make_ball(max_x / 2, max_y / 4, HARD_BALL_VX, HARD_BALL_VY);
    struct Paddle* paddle = make_paddle(0, max_y / 2, 5, 2);

    Timer* timer = sgl_timer_new();

    //Default settings...
    int difficulty = EASY;
    int sound = SOUND_OFF;

    char* random_name = ai_names[randint(ai_names_c)];
    struct Game* game = make_game(max_x, max_y, difficulty, sound, PADDLE_SENSITIVITY, random_name, getenv("USER"), 1, 0, DEFAULT_SCORE);
    int key;
    while (key != 'q'){
        switch (key = getch()){
            case KEY_DOWN:
                move_selected(title_menu, DOWN);
                break;
            case KEY_UP:
                move_selected(title_menu, UP);
                break;

            case KEY_RIGHT:
            case KEY_ENTER:
                switch (title_menu->selected){
                    case 0: //Play game
                        play_game(game);
                        break;
                    case 1: //Options
                        game = options_menu(screen, game, ball, paddle, max_x, max_y);
                        clear();
                        break;
                    case 2: //Help
                        help_menu(screen, ball, paddle, max_x, max_y);
                        break;
                    case 3: //Quit
                        return 0;
                        break;
                }
                break;
        }

        //Render the background
        if (sgl_timer_elapsed_milliseconds(timer) > 20){
            sgl_timer_reset(timer);
            update_background(ball, paddle, max_x, max_y);
            draw_background(screen, ball, paddle);
            refresh();
        }

        draw_strings(screen, 1, max_x / 2 - strlen(game_title[0]), game_title, 6);

        draw_menu(title_menu);
        wrefresh(title_menu->win);
    }

    clear();
    refresh();
    return 0;
}