コード例 #1
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
// assign address
void bt_openwebnet::Assegna_indirizzo()
{
	string sup;
	string orig;
	indirizzo.reserve(4);

	// WHO
	sup = chi;
	orig = chi;

	if (sup.find("#") != string::npos)
	{
		chi = FirstToken(sup, "#");
		// ADDRESS
		indirizzo.clear();
		sup = orig.substr(chi.length() + 1);
		if (sup.find('#') == string::npos)
		{
			// unique serial address
			if (sup.length() != 0)
				indirizzo.push_back(sup);
			else
				frame_type = ERROR_FRAME;
		}
		else
		{
		  // IP address
		  indirizzo[0] = FirstToken(sup, "#");
		  sup = orig.substr(chi.length() + 1 + indirizzo[0].length() + 1);
		  if(sup.find('#') != string::npos)
		  {
			// IP address
			indirizzo[1] = FirstToken(sup, "#");
			sup = orig.substr(chi.length() + 1 + indirizzo[0].length() + 1 + indirizzo[1].length() + 1);
			if(sup.find('#') != string::npos)
			{
			  // IP address
			  indirizzo[2] = FirstToken(sup, "#");
			  sup = orig.substr(chi.length() + 1 + indirizzo[0].length() + 1 + indirizzo[1].length() + 1 + indirizzo[2].length() + 1);
			  if(sup.find('#') == string::npos)
			  {
				// IP address
				if(sup.length() != 0)
				  indirizzo[3] = sup;
				else
				  frame_type = ERROR_FRAME;
			  }
			  else
				frame_type = ERROR_FRAME;
			}
			else
			  frame_type = ERROR_FRAME;
		  }
		  else
			frame_type = ERROR_FRAME;
		}
  }

  return;
}
コード例 #2
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
//assign level interface for extended frame
void bt_openwebnet::Assegna_livello_interfaccia()
{
	string sup;
  string orig;

  // WHERE
  if (dove.at(0) == '#')
	  sup = dove.substr(1);
  else
	  sup = dove;
  orig = dove;
  if(sup.find('#') != string::npos)
  {
    extended = true;
    if(orig.at(0) == '#')
      dove, "#" +  FirstToken(sup, "#");
    else
      dove = FirstToken(sup, "#");
    // LEVEL + INTERFACE
    sup= orig.substr(dove.length()+1);
    if(sup.find('#') != string::npos)
    {
      livello = FirstToken(sup, "#");
      interfaccia = orig.substr(dove.length()+1+livello.length()+1);
      if(interfaccia.length() == 0)
        frame_type = ERROR_FRAME;
    }
    else
      //Modified by Bt_vctMM for "accensione telecamere esetrne" (*6*0*4000#2*##)
      //frame_type = ERROR_FRAME;
      livello = sup;
  }
  
  return;
}
コード例 #3
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
// assigns who where dimension and values for the write dimension frame
void bt_openwebnet::Assegna_chi_dove_grandezza_valori()
{
	string sup;
  int len = 0;
  int i = -1;

  // WHO
  sup = frame_open.substr(2);
  if(sup[0] != '*')
    chi = FirstToken(sup, "*");
  // WHERE
  sup =  frame_open.substr(2+chi.length()+1);
  if(sup.find('*') == string::npos)
    dove = sup.substr(0,sup.length()-2);
  else
  {
    if(sup.at(0) != '*')
      dove =FirstToken(sup, "*");
    // DIMENSION
    sup = frame_open.substr(2+chi.length()+1+dove.length()+2);
    if(sup.find('*') == string::npos)
      frame_type = ERROR_FRAME;
    else
    {
      if(sup.at(0) != '*')
        grandezza = FirstToken(sup, "*");
      // VALUES
	  len = 2 + chi.length() + 1 + dove.length() + 2 + grandezza.length() + 1;
	  sup = frame_open.substr(len);
      while (sup.find('*') != string::npos && (sup.at(0) != '*'))
      {
		  string newValue = FirstToken(sup, "*");
		  valori.push_back(newValue);
			len = len+ newValue.length() +1;
			sup = frame_open.substr(len);
        while(sup.at(0) == '*')
        {
          len++;
		  sup = frame_open.substr(len);
		  valori.push_back("");
        }
        if (sup.at(0) != '*')
			valori.push_back("");
      }
      if ((sup.at(0) != '*') && (sup.at(0) != '#'))
      {
		  valori.push_back(sup.substr(0, sup.length()-2));
      }
    }
  }

  return;
}
コード例 #4
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
// assigns who where dimension required for the request dimension frame
void bt_openwebnet::Assegna_chi_dove_grandezza()
{
  string sup;
  size_t len = 0;

  // WHO
  sup = frame_open.substr(2);
  if (sup.at(0) != '*') {
	  chi = FirstToken(sup, "*");
  }
  // WHERE
  sup = frame_open.substr(2 + chi.length() + 1);
  if(sup.find("*") == string::npos)
    dove = sup.substr(0, sup.length()-2);
  else
  {
    if(sup.at(0) != '*')
      dove = FirstToken(sup, "*");
    // DIMENSION
    sup = frame_open.substr(2+chi.length()+1+dove.length()+1);
    if(sup.find("*") == string::npos)
		grandezza = sup.substr(0, sup.length() - 2);
    else
    {
		if (sup.at(0) != '*') {
			grandezza = FirstToken(sup, "*");
		}
      // VALUES **##
      sup = frame_open.substr(2+ chi.length() + 1 + dove.length() + 1 +grandezza.length()+1);
      len = 2 + chi.length() + 1 + dove.length() + 1 + grandezza.length() + 1;
      while ((sup.find("*") != string::npos) && (sup.at(0) != '*'))
      {
        string valoriValue = FirstToken(sup, "*");
		valori.push_back(valoriValue);
        len = len+ valoriValue.length()+1;
        sup = frame_open.substr(len);
      }
      if ((sup[0] != '*') && (sup[0] != '#'))
      {
		  string valoriValue = sup.substr(0, sup.length()-2);
		  valori.push_back(valoriValue);
      }
    }
  }

  return;
}
コード例 #5
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
// assigns who what where and when for the normal frames
void bt_openwebnet::Assegna_chi_cosa_dove_quando()
{
	string sup;

	// CHI
	sup = frame_open.substr(1);
	if (sup.at(0) != '*') {
		chi = FirstToken(sup, "*");
	}
	// COSA
	sup = frame_open.substr(1 + chi.length() + 1);
	if (sup.find("*") == string::npos) {
		cosa = sup.substr(0, sup.length() - 2);
	}
	else {
		if (sup[0] != '*')
			cosa = FirstToken(sup, "*");
		// DOVE
		sup = frame_open.substr(1 + chi.length() + 1 + cosa.length() + 1);
		if (sup.find("*") == string::npos) {
			dove = sup.substr(0, sup.length() - 2);
		}
		else
		{
			if (sup[0] != '*')
				dove = FirstToken(sup, "*");
			// QUANDO
			sup = frame_open.substr(1 + chi.length() + 1 + cosa.length() + 1 + dove.length() + 1);
			if (sup.find("*") == string::npos) {
				quando = sup.substr(0, sup.length() - 2);
			}
			else
				if (sup[0] != '*')
					quando = FirstToken(sup, "*");
		}
	}

	return;
}
コード例 #6
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
// assigns who and where required for the request dimension frame
void bt_openwebnet::Assegna_chi_dove()
{
  string sup;

  // WHO
  sup = frame_open.substr(2);
  if (sup.at(0) != '*') {
	  chi = FirstToken(sup, "*");
  }
  // WHERE
  sup = frame_open.substr(2 + chi.length() + 1);
  if (sup.find("*") == string::npos) {
	  dove = sup.substr(0, sup.length() - 2);
  }
  else {
	  if (sup.at(0) != '*') {
		  dove = FirstToken(sup, "*");
	  }
  }

  return;
}
コード例 #7
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
// assignes who for the frame processing password
void bt_openwebnet::Assegna_chi()
{
	string sup;

	// WHO
	sup = frame_open.substr(2);
	if (sup.at(0) != '#') {
		chi = FirstToken(sup, "#");
	}
	else {
		frame_type = ERROR_FRAME;
	}
	
	sup = frame_open.substr(2+chi.length());
	if (sup.at(1) != '#') {
		frame_type = ERROR_FRAME;
	}

  return;
}
コード例 #8
0
ファイル: socket.cpp プロジェクト: k1643/StratagusAI
void HandleRequest() {
    char* token;
    short keep_processing = 1;
    int offset;

    DebugPrint("Received request %s" _C_ recv_buffer);
    token = FirstToken();
    while (token != 0 && keep_processing) {
        switch (to_request(token)) {
            case ACTIVITY:
                HandleActivity();
                break;
            case COMMAND: // COMMAND
                HandleCommand();
                break;
            case EXIT: // EXIT
                HandleQuit();
                break;
            case GET: // GET
                HandleGet();
                break;
            case KILL:
                HandleKill();
                break;
            case LISPGET: // LISPGET {STATE | GAMEINFO | MAPINFO}
                HandleLispGet();
                break;
            case MAP: // Load new map
                if (HandleNewMap()) {
                    LastPausedCycle = 0;
                    keep_processing = 0;
                }
                break;
            case PING: // PING
                HandlePing();
                break;
            case QUIT: // QUIT
                HandleQuit();
                break;
            case RESTART: // RESTART / RESET
                HandleRestart();
                LastPausedCycle = 0;
                keep_processing = 0;
                break;
            case SPEED: // SPEED
                HandleSpeed();
                break;
            case TRANSITION: // TRANSITION
                HandleTransition();
                keep_processing = 0;
                break;
            case VIDEO: // VIDEO
                HandleVideo();
                break;
            case WRITE:
                HandleWrite();
                break;
            case CYCLE:
                HandleGetCycle();
                break;
            case Z:
                HandleRandomSeed();
                break;
            default:
                SendResponseMessage("Unknown command.\n", 3);
        }
        token = NextToken();
    }

    // Bring pending commands to the front of recv_buffer
    if (token != 0) {
        offset = token + strlen(token) - temp_buffer;
        temp_buffer[offset] = recv_buffer[offset];
        strcpy(recv_buffer, token);
    } else
        memset(recv_buffer, 0, RECV_BUFFER_SIZE); // Clear the command buffer
}
コード例 #9
0
ファイル: bt_openwebnet.cpp プロジェクト: AbsolutK/domoticz
// performs syntax checking
void bt_openwebnet::IsCorrect()
{
  int j  = 0;
  string sup;
  string campo;

  // if frame ACK -->
  if (frame_open.compare(OPENWEBNET_MSG_OPEN_OK) == 0)
  {
    frame_type = OK_FRAME;
    return;
  }

  // if frame NACK -->
  if (frame_open.compare(OPENWEBNET_MSG_OPEN_KO) == 0)
  {
    frame_type = KO_FRAME;
    return;
  }


  //if the first character is not *
  //or the frame is too long
  //or the frame does not end with two '#'
  if ((frame_open[0] != '*') ||
      (length_frame_open >	MAX_LENGTH_OPEN) ||
      (frame_open[length_frame_open-1] != '#') ||
      (frame_open[length_frame_open-2] != '#'))
  {
    frame_type = ERROR_FRAME;
    return;
  }

  //Check if there are typed character
  for (j=0;j<length_frame_open;j++)
  {
    if(!isdigit(frame_open[j]))
    {
      if((frame_open[j] != '*') && (frame_open[j] != '#'))
      {
        frame_type = ERROR_FRAME;
        return;
      }
    }
  }

  // normal frame...
  //*who#address*what*where#level#address*when##
  if (frame_open[1] != '#')
  {
    frame_type = NORMAL_FRAME;
    //extract the various fields of the open frame in the first mode (who + address and where + level + interface)
    Assegna_chi_cosa_dove_quando();
    //extract any address values
    Assegna_indirizzo();
    //extract any level values and interface
    Assegna_livello_interfaccia();
    return;
  }

  // frame password ...
  //*#pwd##
  if(frame_open.find('*', 2) == string::npos)
  {
    frame_type = PWD_FRAME;
    //I extract the who
    Assegna_chi();
    return;
  }

  //for other types of frames
  sup = frame_open.substr(2);
  campo = FirstToken(sup, "*");
  sup = frame_open.substr(2 + campo.length() + 1);
  if (sup.at(0) != '*')
  {
	  campo = campo + FirstToken(sup, "*");
	  sup = frame_open.substr(2 + campo.length() + 1);
  }

  //frame request was ...
  //*#who*where##
  if(sup[0] != '*')
  {
    frame_type = STATE_FRAME;
	//extract the various fields of the open frame in the first mode (who + address and where + level + interface)
    Assegna_chi_dove();
	//extract any address values
	Assegna_indirizzo();
	//extract any level values and interface
	Assegna_livello_interfaccia();
    return;
  }
  else
  {
    //frame measurement request ...
    //*#who*where*dimension## or *#who*where*dimension*valueN##
    if(sup[1] != '#')
    {
      frame_type = MEASURE_FRAME;
      //extract the various fields of the open frame in the first mode (who + address and where + level + interface)
	  Assegna_chi_dove_grandezza();
	  //extract any address values
      Assegna_indirizzo();
	  //extract any level values and interface
      Assegna_livello_interfaccia();
      return;
    }
    //writing dimension frame ...
    //*#who*where*#dimension*valueN##
    else
    {
      frame_type = WRITE_FRAME;
      //extract the different fields of the open frame in the first mode (who+address and where+level+interface)
      Assegna_chi_dove_grandezza_valori();
	  //extract any address values
      Assegna_indirizzo();
	  //extract any level values and interface
      Assegna_livello_interfaccia();
      return;
    }
  }

  // frame errata !!!
  frame_type = ERROR_FRAME;
  return;
}