Esempio n. 1
0
void LoginScreen::show() {
	bool complete = false;
	do {
		drawTitle();
		stringstream cmdline;
		cout << "(u)ser: " << name << endl;
		cout << "(p)assword: " << string(pass.length(),'*') << endl;
		//cout << endl << "Write 'u' to edit the username, 'p' to edit the password." << endl;
		cmdline << "[u,p,";
		if(pass != "" && name != "") {
			cout << "(l)ogin" << endl;
			cmdline << "l] > ";
		}else{
			cout << "login as (g)uest" << endl;
			cmdline << "g] > ";
		}
		string cmd = readCommand(cmdline.str());
		if(cmd == "u") {
			string name = readCommand("User > ");
			this->name = name;
		}else if(cmd == "p") {
			string pass = readCommand("Pass > ");
			this->pass = pass;
		}else if(pass == "" && name == "" && cmd == "g") {
			complete = true;
			guest = true;
		}else if(pass != "" && name != "" && cmd == "l") {
			complete = true;
		}
	}while(!complete);
}
Esempio n. 2
0
bool ESP8266wifi::send(char channel, const char * message, bool sendNow){
    watchdog();
    byte avail = sizeof(msgOut) - strlen(msgOut) - 1;
    strncat(msgOut, message, avail);
    if (!sendNow)
        return true;
    byte length = strlen(msgOut);
    
    if(flags.endSendWithNewline)
        length += 2;
    
    writeCommand(CIPSEND);
    _serialOut -> print(channel);
    writeCommand(COMMA);
    _serialOut -> println(length);
    byte prompt = readCommand(1000, PROMPT, LINK_IS_NOT);
    if (prompt != 2) {
        if(flags.endSendWithNewline)
            _serialOut -> println(msgOut);
        else
            _serialOut -> print(msgOut);
        byte sendStatus = readCommand(5000, SEND_OK, BUSY);
        if (sendStatus == 1) {
            msgOut[0] = '\0';
            if(channel == SERVER)
                flags.connectedToServer = true;
            return true;
        }
    }
    //else
    if(channel == SERVER)
        flags.connectedToServer = false;
    msgOut[0] = '\0';
    return false;
}
Esempio n. 3
0
/**
Main function

argv - command line arguments
argc - number of arguments
**/
int main(char** argv, int argc) {
  Array command=(Array){NULL,0};
  
  while (1) {
    //Write a user prompt, unless there's multiple simple commands in one line of input 
    if ( command.c==NULL || !isBooleanOperator(command.c[command.length-1].str) ){
      write(0,">",1);
    }
    
    //Read the command in
    command = readCommand();
    
    //If exit is the command called, quit running
    if (strcmp(command.c[0].str, "exit") == 0){
      break;
    }
    
    //Run the process
    int status = processMgmt(command);	
    
    int consume=1;
    //If there's a boolean operator, decide if you need to ignore the next command
    while ( isBooleanOperator(command.c[command.length-1].str)  && consume){
      switch (command.c[command.length-1].str[0]){
        case '&':
          if (status!=0){
            command=readCommand();
          }
          else{
            consume=0;
          }
          break;
        case '|':
          if (status==0){
            command=readCommand();
          }
          else{
            consume=0;
          }
          break;
        case ';':
          consume=0;
          
          break;
      }
    }
    
  }
  
  write(0,"Good bye.\n",10);
  return 0;
}
Esempio n. 4
0
char* ESP8266wifi::getMAC(){
    msgIn[0] = '\0';
    writeCommand(CIFSR, EOL);
    byte code = readCommand(1000, STAMAC, ERROR);
    if (code == 1) {
        // found stamac
        readBuffer(&msgIn[0], sizeof(msgIn) - 1, '"');
        readCommand(10, OK, ERROR);
        return &msgIn[0];
    }
    readCommand(1000, OK, ERROR);
    return &msgIn[0];
}
Esempio n. 5
0
CCM_FUNC static THD_FUNCTION(ThreadBDU, arg)
{
  event_listener_t el1;
  eventmask_t flags;
  (void)arg;
  chRegSetThreadName("BDU");

  chEvtRegisterMask(chnGetEventSource(&SDU2), &el1, ALL_EVENTS);

  while(USBD1.state != USB_READY) chThdSleepMilliseconds(10);
  while(SDU2.state != SDU_READY) chThdSleepMilliseconds(10);

  while (TRUE)
  {
    chEvtWaitAnyTimeout(ALL_EVENTS, TIME_IMMEDIATE);
    flags = chEvtGetAndClearFlags(&el1);

    pwmEnableChannel(&PWMD_LED2, CHN_LED2, PWM_PERCENTAGE_TO_WIDTH(&PWMD_LED2, 8000));

    if (flags & CHN_INPUT_AVAILABLE)
    {
      pwmEnableChannel(&PWMD_LED2, CHN_LED2, PWM_PERCENTAGE_TO_WIDTH(&PWMD_LED2, 1000));
      readCommand((BaseChannel *)&SDU2);
    }
    else
      chThdSleepMilliseconds(2);
  }
  return;
}
int main(int argc, char *argv[]) {
  while (true) {
    char command[kMaxCommandLength + 1];
    readCommand(command, sizeof(command) - 1);
    if (feof(stdin)) break;
    char *arguments[kMaxArgumentCount + 1];
    int count = parseCommandLine(command, arguments, sizeof(arguments)/sizeof(arguments[0]));
    if (count == 0) continue;
    bool builtin = handleBuiltin(arguments);
    if (builtin) continue; // it's been handled, and backgrounding a builtin isn't an option
    bool isBackgroundProcess = strcmp(arguments[count - 1], "&") == 0;
    if (isBackgroundProcess) arguments[--count] = NULL; // overwrite "&"
    pid_t pid = forkProcess();
    if (pid == 0) {
      if (execvp(arguments[0], arguments) < 0) {
	printf("%s: Command not found\n", arguments[0]);
	exit(0);
      }
    }
    
    if (!isBackgroundProcess) {
      waitForChildProcess(pid);
    } else {
      // don't wait for child, and let it roll in the background,
      // but recognize that we currently aren't reaping any background
      // processes when they terminate, and that's something that
      // we need to fix in future iterations of the shell
      printf("%d %s\n", pid, command);
    }
  }
  
  printf("\n");
  return 0;
}
Esempio n. 7
0
static int gprs_readTimeStamp( lua_State* L )
{
int timeout = luaL_checkinteger(L, 1)*1000000;
uint8_t result = 3;
char *ret;

	if( gprs_StartSocket(L) == 1 )
	{
		result = 4;
		if( gprs_SendSocket(L,"GET") == 1 )
		{
			//if( (ret = readCommand(NULL,"}\r\n","}\r\n","{\"time\":","}\r\n",L)) != NULL )
			if( (ret = readCommand(NULL,"}\r\n","}\r\n","{","}\r\n",L)) != NULL )
			{
				char saida[512];
				memset(saida,0,512);
				c_memcpy(saida,ret,c_strlen(ret));
				sendCommand((char*)CIPCLOSE, MSG_OK, MSG_NOK, strlen(CIPCLOSE), timeout/10);
				//lua_pushlstring(L,tm, 10);
				lua_pushlstring(L,saida, c_strlen(saida));
				lua_pushinteger(L,0);
				return 2;
			}else
				result = 5;
		}
	}
	lua_pushinteger(L,result);
	return 1;
}
Esempio n. 8
0
/* Rotina do programa que gere o servidor */
void rotinaLigarServidor(int sinal)
{
	Command pgrep = NULL; /* Output do pgrep */
	int lines = 4;
	
	switch (sinal)
	{
		case SIGALRM:
			pgrep = readCommand("pidstat -urdh -C server");
			lines = pgrep->lines;
			if (lines < 4) /* Se tiver menos de 4 linhas é porque o PID não está na tabela */
				executeCommand("./server");
			alarm(3);
			break;
			
		case SIGINT: /* Ignorar SIGINT */
			break;
			
		case SIGQUIT: /* Ignorar SIGQUIT */
			break;
			
		default:
			break;
	}
}
Esempio n. 9
0
void main() {
  cJSON *userObject = NULL;
  char *password;
  char *fileInputTemp, *fileInput, *fileOutput;
  char filenameIn[LINE_LEN];
  char filenameOut[LINE_LEN];
  int filenameLen, passLen, fileLen;
  
  userObject = authenticateUser(FILENAME);
  if (!userObject) {
    printf("error\n");
		exit(EXIT_FAILURE); 
  } else {
		printf("Authenticated\n");
  }

	password = cJSON_GetObjectItem(userObject, "password")->valuestring; // password->valuestring
  
  while (1) {
	  printf("Please enter the filename that you wish to run encryption on (.crpt files will decrypt): ");
	  readCommand(filenameIn);
    fileCrypt(filenameIn, password);
  }
  
	exit(EXIT_SUCCESS); 
}
Esempio n. 10
0
bool ESP8266wifi::stopLocalServer(){
    writeCommand(CIPSERVERSTOP, EOL);
    boolean stopped = (readCommand(2000, OK, NO_CHANGE) > 0);
    flags.localServerRunning = !stopped;
    flags.localServerConfigured = false; //to prevent autostart
    return stopped;
}
uint8_t In4Dimmer4::writeSP(uint8_t _channel){

    writeCommand(((_channel << 4) | 0x08), fade[_channel]); // set fade
    writeCommand(((_channel << 4) | 0x07), setpoint[_channel]); // set SP

    #ifdef DEBUG_I2C_DIMMER
    Serial.print("relu SP=");
    Serial.println(readCommand((_channel << 4) | 0x0A));
    Serial.print("relu Fade=");
    Serial.println(readCommand((_channel << 4) | 0x0B));
    #endif

    bitClear(status, _channel); // on raz le flag changement

    return 0;

}
Esempio n. 12
0
void ScriptEngineRemoteLocal::connected()
{
    m_command = "";

    m_server_socket = nextPendingConnection();
    connect(m_server_socket, SIGNAL(readyRead()), this, SLOT(readCommand()));
    connect(m_server_socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
Esempio n. 13
0
bool ESP8266wifi::stopLocalAP(){
    writeCommand(CWMODE_1, EOL);

    boolean stopped = (readCommand(2000, OK, NO_CHANGE) > 0);
    flags.localApRunning = !stopped;
    flags.localApConfigured = false; //to prevent autostart
    return stopped;
}
Esempio n. 14
0
bool ESP8266wifi::startLocalServer(){
    // Start local server
    writeCommand(CIPSERVERSTART);
    _serialOut -> println(_localServerPort);
    
    flags.localServerRunning = (readCommand(2000, OK, NO_CHANGE) > 0);
    return flags.localServerRunning;
}
Esempio n. 15
0
int main(void) {
	init();
	printCommand();
	while(1) {
		readCommand();
	}
	return EXIT_SUCCESS;
}
Esempio n. 16
0
static int gprs_getlocation( lua_State* L )
{
size_t len;
//uint32_t timeout	= luaL_checkinteger(L, 1)*1000;
uint32_t period		= luaL_checkinteger(L, 3);
char *position;
double LAT	= 0.0f;
double LONG	= 0.0f;
double ALT	= 0.0f;
double DOP	= 0.0f;
char saida[15];
char cmd[15];
int ret = 0;

	/*
	 *  $GPGGA,180857.000,2524.83983,S,04917.42591,W,1,03,3.1,0.0,M,,M,,0000*47
		$GPGSA,A,2,09,23,22,,,,,,,,,,3.3,3.1,1.0*38
		$GPGSV,3,1,09,09,37,236,26,23,53,188,34,22,49,061,28,30,02,319,*77
		$GPGSV,3,2,09,26,20,117,,07,36,317,,06,18,230,,03,73,108,*77
		$GPGSV,3,3,09,01,29,352,*4E
		$GPRMC,180857.000,A,2524.83983,S,04917.42591,W,0.70,315.11,120617,,,A*69
		$GPVTG,315.11,T,,M,0.70,N,1.30,K,A*3F

	 * */
	if (ReadEnable == 0)
	{
		memset(cmd,0,15);
		c_sprintf(cmd,"%s=%d",GPSRD,period);
		if( sendCommonCommand(L,cmd) == 1)
			ReadEnable = 1;
	}

	//if( sendCommonCommand(L,cmd) == 1)

	if( (position = readCommand(NULL, "$GNACC", "$GNACC", GPSRDLOCAL, EOL, L)) != NULL )
	{
		ret = parse_gps(position, &LAT, &LONG, &ALT, &DOP);
		if( ret ==  4 )
		{
			c_memset(saida,0,15);
			c_sprintf(saida,"%.6f",LAT);
			lua_pushstring(L, saida);
			c_memset(saida,0,15);
			c_sprintf(saida,"%.6f",LONG);
			lua_pushstring(L, saida);
			c_memset(saida,0,15);
			c_sprintf(saida,"%.1f",ALT);
			lua_pushstring(L, saida);
			c_memset(saida,0,15);
			c_sprintf(saida,"%.1f",DOP);
			lua_pushstring(L, saida);
			return 4;  // 4 é o número de valores a serem retornados
		}
	}


	return 0;
}
Esempio n. 17
0
bool ESP8266wifi::startLocalAp(){
    // Start local ap mode (eg both local ap and ap)
    writeCommand(CWMODE_3, EOL);
    if (!readCommand(2000, OK, NO_CHANGE))
        return false;
    
    // Configure the soft ap
    writeCommand(CWSAP);
    _serialOut -> print(_localAPSSID);
    writeCommand(COMMA_2);
    _serialOut -> print(_localAPPassword);
    writeCommand(COMMA_1);
    _serialOut -> print(_localAPChannel);
    writeCommand(THREE_COMMA, EOL);
    
    flags.localApRunning = (readCommand(5000, OK, ERROR) == 1);
    return flags.localApRunning;
}
Esempio n. 18
0
bool SceneLoader::doCamera(istream &str, string &name)
{
    if (!getName(str, "camera", name))
        return false;

    SceneGroup *n = new SceneGroup();
    groups[name] = n;
    n->_name = name;

    n->_camera = new ParametricCamera();


    do {
        int state = findOpenOrClosedParen(str);
        if (state == ERROR) {
            SetCameraDefaults(n);
            return false;
        } else if (state == CLOSED) {
            SetCameraDefaults(n);
            return true;
        }
        else if (state == OPEN)
        {
            string cmd;
            vector<ParametricValue*> values;
            string sides = "lrbtnf";
            int side = 0;
            if (readCommand(str, cmd)) {
                if (cmd == "perspective") {
                    if (getValues(str, values) < 1) {
                        *err << "Perspective with no parameters at ";
                        errLine(str.tellg());
                    } else {
                        cleanAfter(values, 1);
                        n->_camera->_perspective = values[0];
                    }
                }
                else if (cmd.size() == 1 && (side = (int)sides.find(cmd)) != string::npos) {
                    if (getValues(str, values) < 1) {
                        *err << "l with no parameters at ";
                        errLine(str.tellg());
                    } else {
                        cleanAfter(values, 1);
                        n->_camera->_frustum[side] = values[0];
                    }
                }
                else
                {
                    *err << "Error: command " << cmd << " not recognized at ";
                    errLine(str.tellg());
                }
                findCloseParen(str);
            }
        }
    } while (true);
}
Esempio n. 19
0
//***********************************************************
// Write a word of 16 bits (data)  at the given address 
// Then returns the status code from the flash chip
//***********************************************************
u8 writeWord(struct FLContext *handle, u32 address, u16 data){
	// Enter in bit alterable mode	
	writeCommand(handle, address, 0x42);
	// Write data
	writeCommand(handle, address, data);
	
	// Get the status register
	u16 status=readCommand(handle, address);
	return status & 0xFF;
}
Esempio n. 20
0
// Returns the heading [-PI;PI] with East being 0 and North -PI/2
float HM55B::getHeading(){
  startMeasurementCommand(); // necessary!!
  delay(40); // the data is 40ms later ready
  readCommand();
  x_data = shiftIn(11); // Field strength in X
  y_data = shiftIn(11); // and Y direction
  digitalWrite(EN_PIN, HIGH); // ok deselect chip
  heading = atan2(x_data, -1 * y_data);
	return heading;
}
Esempio n. 21
0
void ScriptEngineRemote::connected()
{
    logMessage("ScriptEngineRemote::connected()");

    command = "";

    m_server_socket = m_server->nextPendingConnection();
    connect(m_server_socket, SIGNAL(readyRead()), this, SLOT(readCommand()));
    connect(m_server_socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
Esempio n. 22
0
bool ESP8266wifi::connectToAP(){
    writeCommand(CWJAP);
    _serialOut -> print(_ssid);
    writeCommand(COMMA_2);
    _serialOut -> print(_password);
    writeCommand(DOUBLE_QUOTE, EOL);

    readCommand(15000, OK, FAIL);
    return isConnectedToAP();
}
Esempio n. 23
0
bool ESP8266wifi::begin() {
    msgOut[0] = '\0';
    msgIn[0] = '\0';
    flags.connectedToServer = false;
    flags.localServerConfigured = false;
    flags.localApConfigured = false;
    serverRetries = 0;
    
    //Do a HW reset
    bool statusOk = false;
    byte i;
    for(i =0; i<HW_RESET_RETRIES; i++){
        readCommand(10, NO_IP); //Cleanup
        digitalWrite(_resetPin, LOW);
        delay(500);
        digitalWrite(_resetPin, HIGH); // select the radio
        // Look for ready string from wifi module
        statusOk = readCommand(3000, READY) == 1;
        if(statusOk)
            break;
    }
    if (!statusOk)
        return false;
    
    //Turn local AP = off
    writeCommand(CWMODE_1, EOL);
    if (readCommand(1000, OK, NO_CHANGE) == 0)
        return false;
    
    // Set echo on/off
    if(flags.echoOnOff)//if echo = true
        writeCommand(ATE1, EOL);
    else
        writeCommand(ATE0, EOL);
    if (readCommand(1000, OK, NO_CHANGE) == 0)
        return false;
    
    // Set mux to enable multiple connections
    writeCommand(CIPMUX_1, EOL);
    flags.started = readCommand(3000, OK, NO_CHANGE) > 0;
    return flags.started;
}
Esempio n. 24
0
static int gprs_getTimeStamp( lua_State* L )
{
char *tm;

	if( (tm = readCommand(CCLK, MSG_OK, MSG_NOK, CCLK_RESP, MSG_OK, L)) != NULL )//if( (time = readCommand(CCLK, MSG_OK, MSG_NOK, "+CCLK: ", "\r",L)) != NULL )
	{
		lua_pushlstring(L,tm+1, 17);
		return 1;
	}
	return 0;
}
Esempio n. 25
0
File: command.c Progetto: pd0wm/epo2
/**
 * @brief sends a get command to the robot
 * @param command command type
 * @param param parameter
 * @param val1 value1
 * @param val2 value2
 */
void getCommand(int sck, FILE* sckfd, int command, int param, int* val1, int* val2) {
    // Ask for a reply
    sprintf(send_buf, "$%s %d get 0 0#\n", ARG[command], param);
    send(sck, send_buf, strlen(send_buf), 0);

    // Both the simulator and communication module send data encapsulated in a command
    // like way (that is, starting with '$' and ending with '#')
    readCommand(sckfd, read_buf, BUF_SIZE);
    // As for now, the get_pos command is not used, so don't care about val2 for now
    sscanf(read_buf, "%d", val1);
}
/**
  * Attempts to read the 8 bit ID from the accelerometer, this can be used for
  * validation purposes.
  *
  * @return the 8 bit ID returned by the accelerometer, or MICROBIT_I2C_ERROR if the request fails.
  *
  * @code
  * accelerometer.whoAmI();
  * @endcode
  */
int MicroBitAccelerometer::whoAmI()
{
    uint8_t data;
    int result;

    result = readCommand(MMA8653_WHOAMI, &data, 1);
    if (result !=0)
        return MICROBIT_I2C_ERROR;

    return (int)data;
}
Esempio n. 27
0
void MessageScreen::show() {
	while(true) {
		drawTitle();
		std::cout << message << endl;
		std::cout << endl << "Write 'q' to close." << endl;
		std::string cmd = readCommand();
		if(cmd == "q") {
			break;
		}
	}
}
Esempio n. 28
0
void shell(){
	clearScreen();
	splash();
	welcome();
	while(1){
		typePrompt();
		readCommand();
		addToHistory(textBuffer);
		runCommand();
	}
}
uint8_t In4Dimmer4::readInput(){

    input=readCommand(R_INPUT);

    #ifdef DEBUG_I2C_DIMMER
    Serial.print("read input=");
    Serial.println(input, BIN);
    #endif

    return input; // read input

}
Esempio n. 30
0
DesignMng::DesignMng(){
	viewerProgram="";
	verboseMode=0;
	poscmdlog = 0;
	historyFile="";
	circuit=NULL;
	router=NULL;
	rules=NULL;
	placer=NULL;
	autocell=NULL;
	readCommand("new design astran_project");
}