Example #1
0
int main(){ 
  
    FILE* img=NULL;
    char target[100];
    char path[100]="\0";
    char* ptr;
    int command;

    if((img = fopen("abc.img","rb"))==NULL) {  
    	myprint("File cannot be opened\n");  
   	    exit(0);  
    } 
     
	struct DirEntry entryListPtr[224];
	
	getBootDirEntry(img,entryListPtr);

//	printBootDir(img,entryListPtr);

	
	
	printAllDir(img,entryListPtr,BPB_RootEntCnt,path);
	
	
	while(1){
		//scanf("%s",target);
		gets(target);
		ptr=target;
		command=commandCheck(ptr);
		
		if(command==1){
			printDetailData(img,entryListPtr,BPB_RootEntCnt,path,ptr);	
		}else if(command==2){
			printCount(img,entryListPtr,BPB_RootEntCnt,path,ptr,""); 
		}else if(command!=-1){
			break;
		}
		
	}
	
//	printDetailData(img,entryListPtr,BPB_RootEntCnt,path,target);
	 
	
//	puts(buffer);

    if(fclose(img)!=0) {  
    	myprint("File cannot be closed\n");   
    	exit(1);   
    }else{
		myprint("File is now closed\n"); 
    }
  
    getchar();
	getchar();
    return 0;
} 
Example #2
0
LexType LexicalAnalizer::GetLexType(Lexem type)
{
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

	if (commandCheck(type.text))
		return LexType::COMMAND;
	else if (reg32Check(type.text))
		return LexType::REG32;
	else if (reg8Check(type.text))
		return LexType::REG8;
	else if (segmentRegCheck(type.text))
		return LexType::SEG_REG;
	else if (directiveCheck(type.text))
		return LexType::DIRECTIVE;
	else if (identCheck(type.text))
		return LexType::IDENT_TYPE;
	else if (operatorCheck(type.text))
		return LexType::OPERATOR;
	else if (quoteCheck(type.text[0]) && quoteCheck(type.text[type.text.length() - 1]))
		return LexType::TEXT_CONST;
	else if (quoteCheck(type.text[0]) && !quoteCheck(type.text[type.text.length() - 1]))
		return LexType::WRONG_LEX;
	else if (numCheck(type.text[0]))
	{
		if (type.text[type.text.length() - 1] == 'B')
			return LexType::BIN_CONST;
		else if (type.text[type.text.length() - 1] == 'H')
			return LexType::HEX_CONST;
		else if (type.text[type.text.length() - 1] == 'D' || numCheck(type.text[type.text.length() - 1]))
			return LexType::DEC_CONST;
		else if (!numCheck(type.text[type.text.length() - 1]))
		{
			SetConsoleTextAttribute(hConsole, 4);
			cout << "Wrong number: ";
			SetConsoleTextAttribute(hConsole, 7);
			cout << "(" << type.row << " row): " << type.text << endl;
			ERR_FLAG = true;

			return LexType::WRONG_LEX;
		}
	}
	else if (type.text.length() == 1)
	{
		if (singleCheck(type.text[0]))
			return LexType::SINGLE_SYMB;
		else
			return LexType::USER_IDENT;
	}
	else
	{
		if (type.text.length() > 8)
		{
			SetConsoleTextAttribute(hConsole, 4);
			cout << "Identeficator length more then 8 symbols:";
			SetConsoleTextAttribute(hConsole, 7);
			cout << "(" << type.row << " row): " << type.text << endl;
			ERR_FLAG = true;

			return LexType::WRONG_LEX;
		}
		
		for (auto n_iter : type.text)
			if (!alphabetCheck(n_iter))
				return LexType::WRONG_LEX;

		return LexType::USER_IDENT;
	}	
}
Example #3
0
void ProtocolFSM::update() {
  if(state > RESET) {
    esp.process();
  }
     
  if(state > CONNECTING_WIFI && !wifi_connected) {
    // we're newly disconnected disconnected
    state = DISCONNECTED_WIFI;
  }
  
  if(state > CONNECTING_WIFI && readyCheckTime()) {
    Serial.println(F("PFSM: Checking readyness"));
    resetReadyCheck();
    if(!esp.ready()) {
      state = ENABLE;
      wifi_connected = false;
    }
  }
  
  if(state > CONNECTING_WIFI && isResetTime()) {
    // nothing conclusive has happened to convince us we still
    // have comms so it's time to reset
    Serial.println(F("PFSM: Forcing reset"));
    resetResetTime();
    state = STARTUP;
  }
  
  if(state == POWER_ON) {
    // ESP12 is fairly high current so we want to give it time to stabalize
    // and give the other electronics a chance to stabalize as well
    digitalWrite(RESET_PIN, LOW);
    delay_end = millis() + 1000;
    state = POWER_ON_RESET;
        
    // correct our swarm id in the endpoint string
    insertBase10(&command_endpoint[sizeof(command_endpoint) - 4], swarmID());
    Serial.println(command_endpoint);
  }
  
  if(state == POWER_ON_RESET && delayComplete()) {
    digitalWrite(RESET_PIN, HIGH);
    state = STARTUP;
  }
  
  if(state == STARTUP) {
    resetResetTime();
    esp.enable();
    delay_end = millis() + 500;
    state = ENABLE;
  }
  
  if(state == ENABLE && delayComplete()) {
    resetResetTime();
    esp.reset();
    delay_end = millis() + 500;
    state = RESET;
  }
  
  if(state == RESET && delayComplete() && esp.ready()) {
    resetResetTime();
    resetReadyCheck();
    state = DISCONNECTED_WIFI;
  }

  
  if(state == DISCONNECTED_WIFI) {
    esp.wifiCb.attach(this, &ProtocolFSM::wifiCallback);
    esp.wifiConnect(ssid, password);
    state = CONNECTING_WIFI;
  }
  
  if(state == CONNECTING_WIFI && wifi_connected) {
    state = DISCONNECTED_REST;
  }
  
  if(state == DISCONNECTED_REST) {
    if(rest.begin(server, port, false)) {
      state = IDLE;
    }
  }
  
  if(state == IDLE && !command_valid && commandCheck()) {
    state = FETCH_COMMAND;
  }
  
  if(state == IDLE && command_complete) {
    state = ACK_COMMAND;
  }
  
  if(state == IDLE && status_pending) {
    state = SENDING_STATUS;
    status_pending = false;
    
    StaticJsonBuffer<256> jsonBuffer;
    char buffer[256];
    
    JsonObject& obj = jsonBuffer.createObject();
    status.toJson(obj);
    obj.printTo(buffer, sizeof(buffer));
    rest.setContentType("application/json");
    rest.put("/status", buffer);
    
    // prepare for response
    rest.getResponse(NULL, 0, true);
    delay_end = millis() + 1000;
    state = SENDING_STATUS;
  }

  if(state == SENDING_STATUS) {
    char buffer[128];
    int resp;
    if((resp = rest.getResponse(buffer, sizeof(buffer), false)) == HTTP_STATUS_OK) {
      Serial.println(F("PFSM: Status delivered"));
      resetResetTime();
      resetReadyCheck();
      state = IDLE;
    } else if(delayComplete()) {
      Serial.println(F("PFSM: Status timed out"));
      state = IDLE;
    }
  }

  if(state == FETCH_COMMAND) {
    rest.get(command_endpoint);
    
    // prepare for response
    rest.getResponse(NULL, 0, true);
    delay_end = millis() + 1000;
    state = AWAITING_COMMAND;
  }
  
  if(state == AWAITING_COMMAND) {
    StaticJsonBuffer<256> jsonBuffer;
    char buffer[256];
    int resp;
    if((resp = rest.getResponse(buffer, sizeof(buffer), false)) == HTTP_STATUS_OK) {    
      // parse the response
      resetResetTime();
      resetReadyCheck();
      char* ptr = buffer;
      // skip to the payload
      for(uint16_t ii = 0; ii < sizeof(buffer); ++ii) {
        if(buffer[ii] == '\n') {
          ptr = &buffer[ii+1];
          break;
        }
      }
      JsonArray& root = jsonBuffer.parseArray(ptr);
      if(!root.success()) {
        Serial.print(F("PFSM: Failed to parse "));
        Serial.println(ptr);
        command_check = millis() + 1000;
        state = IDLE;
      } else {
        if(root.size() == 0) {
          // nothing in our queue
          Serial.println(F("No commands waiting"));
          command_check = millis() + 1000;
          state = IDLE;
        } else {
          if(command.fromJson(root[0])) {
            command_valid = true;
            command_complete = false;
            state = IDLE;
          } else {
            Serial.print(F("PFSM: Message invalid "));
            Serial.println(buffer);
            command_check = millis() + 1000;
            state = IDLE;
          }
        }
      }
    } else if(delayComplete()) {
      Serial.println(F("PFSM: Command request timed out"));
      command_check = millis() + 1000;
      state = IDLE;
    } 
  }
  
  if(state == ACK_COMMAND) {
    StaticJsonBuffer<128> jsonBuffer;
    char buffer[128];
    
    JsonObject& obj = jsonBuffer.createObject();
    obj["pid"] = swarmID();
    obj["cid"] = command.cid;
    obj["complete"] = true;
    obj.printTo(buffer, sizeof(buffer));
    
    rest.put(command_endpoint, buffer);
    
    // prepare for response
    rest.getResponse(NULL, 0, true);
    delay_end = millis() + 1000;
    state = AWAITING_ACK;
  }
  
  if(state == AWAITING_ACK) {
    char buffer[128];
    int resp;
    if((resp = rest.getResponse(buffer, sizeof(buffer), false)) == HTTP_STATUS_OK) {    
      // assume we got goodness
      state = IDLE;
      command_valid = false;
      command_complete = false;
    } else if(delayComplete()) {
      // this is the one case we retry forever. It's important that the mothership know that
      // we did what we said we would do.
      Serial.println(F("PFSM: Ack timed out"));
      state = ACK_COMMAND;
    }
  }
}