Пример #1
0
/**
 * Checks if the last word of the answer is OK.
 * @param buffer pointer to the buffer
 * @param answerSize size of the modem answer
 * @param commandResult result of the command
 * @return 1
 */
int ATCommandManager::verifyLastOK(char* buffer,int answerSize,ATCommandResult& commandResult)
{

	int size = inputData.size();
	if(size==0)
	{
		commandResult=ATR_OTHER;
	}
	else
	{
		
		if(compareBuffer(&buffer[inputData[size-1].worldBeginInBuffer],inputData[size-1].worldSize(),ANS_OK))
		{
			commandResult=ATR_OK;
		}
		else
		{
			if(compareBuffer(&buffer[inputData[size-1].worldBeginInBuffer],inputData[size-1].worldSize(),ANS_ERROR))
			{
				commandResult=ATR_ERROR;
			}
			else
			{
				commandResult=ATR_OTHER;
			}
		}
		
	}

	return 1;
}
Пример #2
0
/**
 * Verifies the second step of the CMGS command.
 * @param buffer pointer to the buffer
 * @param answerSize size of the modem answer
 * @param commandResult result of the command
 * @return 1
 */
int ATCommandManager::verifyCMGS2(char* buffer,int answerSize,ATCommandResult& commandResult)
{
	
	if(inputData.size()<2)
	{
		commandResult=ATR_OTHER;
	}
	else
	{
		if(inputData.size()==2)
		{
			if(compareBufferBegin(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_CMGS))
			{
				//commandResult=ATR_WAIT_FOR_MESSAGE;
				if(compareBuffer(&buffer[inputData[1].worldBeginInBuffer],inputData[1].worldSize(),ANS_OK))
				{
					commandResult=ATR_OK;
				}
				else
				{
					if(compareBuffer(&buffer[inputData[1].worldBeginInBuffer],inputData[1].worldSize(),ANS_ERROR))
					{
						commandResult=ATR_ERROR;
					}
					else
					{
						commandResult=ATR_OTHER;
					}
				}
			}
			else
			{
				if(compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_ERROR))
				{
					commandResult=ATR_ERROR;
				}
				else
				{
					commandResult=ATR_OTHER;
				}
			}
		}
		else
		{
			commandResult=ATR_MORE_WORDS;
		}
	
	
	}
	return 1;
}
Пример #3
0
/**
 * Checks if the answer is OK.
 * @param buffer pointer to the buffer
 * @param answerSize size of the modem answer
 * @param commandResult result of the command
 * @return 1
 */
int ATCommandManager::verifyOK(char* buffer,int answerSize,ATCommandResult& commandResult)
{

	if(inputData.size()==0)
	{
		commandResult=ATR_OTHER;
	}
	else
	{
		if(inputData.size()==1)
		{
			if(compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_OK))
			{
				commandResult=ATR_OK;
			}
			else
			{
				if(compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_ERROR))
				{
					commandResult=ATR_ERROR;
				}
				else
				{
					commandResult=ATR_OTHER;
				}
			}
		}
		else
		{
			if(inputData.size()==2)
			{
				if(compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_AT))
				{
					if(compareBuffer(&buffer[inputData[1].worldBeginInBuffer],inputData[1].worldSize(),ANS_OK))
					{
						commandResult=ATR_AT_OK;
						return 1;
					}
				}
			}
			commandResult=ATR_MORE_WORDS;
		}
	
	
	}

	return 1;
}
Пример #4
0
/**
 * Verifies the first step of the CMGS command.
 * @param buffer pointer to the buffer
 * @param answerSize size of the modem answer
 * @param commandResult result of the command
 * @return 1
 */
int ATCommandManager::verifyCMGS(char* buffer,int answerSize,ATCommandResult& commandResult)
{
	
	if(inputData.size()==0)
	{
		commandResult=ATR_OTHER;
	}
	else
	{
		if(inputData.size()==1)
		{
			if(compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_ADD_SMS1)||compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_ADD_SMS2))
			{
				commandResult=ATR_WAIT_FOR_MESSAGE;
			}
			else
			{
				if(compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_ERROR))
				{
					commandResult=ATR_ERROR;
				}
				else
				{
					commandResult=ATR_OTHER;
				}
			}
		}
		else
		{
			commandResult=ATR_MORE_WORDS;
		}
	
	
	}
	return 1;
}
Пример #5
0
void Cliente::enviarMensagem(Mensagem m) {
	// Send a message to the pipe server. 
	cbToWrite = sizeof(m);
	m.pid = _getpid();
	cout << "Sending " << cbToWrite << " byte message: " << m.msg << endl;

	fSuccess = WriteFile(
		hPipe,                  // pipe handle 
		&m,                      // message 
		cbToWrite,              // message length 
		&cbWritten,             // bytes written 
		NULL);                  // not overlapped 

	if (!fSuccess)
	{
		_tprintf(TEXT("WriteFile to pipe failed. GLE=%d\n"), GetLastError());
		return;
	}
	printf(L"\nMessage sent to server, receiving reply as follows:\n");

	do
	{
		// Read from the pipe. 
		fSuccess = ReadFile(
			hPipe,    // pipe handle 
			&chBuf,    // buffer to receive reply 
			sizeof(Mensagem),  // size of buffer 
			&cbRead,  // number of bytes read 
			NULL);    // not overlapped 

		if (!fSuccess && GetLastError() != ERROR_MORE_DATA)
			break;

		compareBuffer(chBuf);
		cout << chBuf.msg << endl;
		string temp(chBuf.msg);
		anteriorM = temp;
		vida = chBuf.vida;
		mapaLocal = chBuf.mapa;
	} while (!fSuccess);  // repeat loop if ERROR_MORE_DATA 

	if (!fSuccess)
	{
		_tprintf(TEXT("ReadFile from pipe failed. GLE=%d\n"), GetLastError());
		return;
	}
}
Пример #6
0
/**
 * Verifies the modem answer on the CREG command.
 * @param buffer pointer to the buffer
 * @param answerSize size of the modem answer
 * @param commandResult result of the command
 * @return 1
 */
int ATCommandManager::verifyCREG(char* buffer,int answerSize,ATCommandResult& commandResult)
{
	if(inputData.size()<2)
	{
		commandResult=ATR_OTHER;
	}
	else
	{
		if(inputData.size()==2)
		{
			int size=inputData[0].worldEndInBuffer+1;
			if(compareBufferBegin(&buffer[inputData[0].worldBeginInBuffer],size,ANS_CREG))
			{
				int commaIndex=-1;

				for(int i=inputData[0].worldBeginInBuffer+strlen(ANS_CREG);i<size;i++)
				{
					if(buffer[i]==',')
					{
						commaIndex=i;
						break;
					}
				}

				if(commaIndex>-1)
				{
					unsigned char answerDigit=buffer[commaIndex+1];
					if(answerDigit>='0'&&answerDigit<='9')
					{
						unsigned int answer=answerDigit-'0';
						if(answer==1||answer==5)
						{
							commandResult=ATR_REGISTERED;
						}
						else
						{
							if(answer==2)
							{
								commandResult=ATR_REGISTERING;
							}
							else
							{
								commandResult=ATR_OTHER;
							}
						}
					}
				}
				else
				{
				
				}
				
				if(!compareBuffer(&buffer[inputData[1].worldBeginInBuffer],inputData[1].worldSize(),ANS_OK))
				{
					if(compareBuffer(&buffer[inputData[1].worldBeginInBuffer],inputData[1].worldSize(),ANS_ERROR))
					{
						commandResult=ATR_ERROR;
					}
					else
					{
						commandResult=ATR_OTHER;
					}
				}
			}
			else
			{
				if(compareBuffer(&buffer[inputData[0].worldBeginInBuffer],inputData[0].worldSize(),ANS_ERROR))
				{
					commandResult=ATR_ERROR;
				}
				else
				{
					commandResult=ATR_OTHER;
				}
			}
		}
		else
		{
			commandResult=ATR_MORE_WORDS;
		}
	
	
	}
	return 1;
}
Пример #7
0
/**
 * Verifies answer on the CMGL command
 * @param buffer pointer to the buffer
 * @param answerSize size of the answer
 * @param position position of the SMS in modem storage
 * @param size of the SMS
 * @return error number
 */
int ATCommandManager::verifyCMGL(char* buffer,int answerSize,int& position,int& size)
{
	
	int commandSize=strlen(ANS_CMGL);
	bool bResult=compareBuffer(buffer,commandSize,ANS_CMGL);
	
	if(bResult==false)
	{
		return Undefined_modem_answer;
	}

	int firstCommaPosition=0;
	bool found=false;

	for(int i=commandSize;i<answerSize;i++)
	{
		if(buffer[i]==',')
		{
			found =true;
			firstCommaPosition=i;
			break;
		}
	}

	if(found==false)
	{
		return Undefined_modem_answer;
	}

	int valueSize=firstCommaPosition-commandSize;

	int value=getValueFromBuffer(&buffer[commandSize],valueSize);

	if(value<0)
	{
		return value;
	}
	else
	{
		position=value;
	}

	found=false;
	int lastCommaPossition=0;
	for(int i=answerSize-1;i>commandSize;i--)
	{
		if(buffer[i]==',')
		{
			lastCommaPossition=i;
			break;
		}
	}

	valueSize=answerSize-lastCommaPossition-1;

	value=getValueFromBuffer(&buffer[lastCommaPossition+1],valueSize);

	if(value<0)
	{
		return value;
	}
	else
	{
		size=value;
	}

	return 1;
}
Пример #8
0
/**
 * Verifies the incoming SMS.
 * @param buffer pointer to the buffer where the SMS is stored
 * @param answerSize size of the SMS frame
 * @param readData vector of the SMS frame words
 * @param smsInfo contains information about the SMS frame
 * @return error number
 */
int ATCommandManager::verifyReadSMS(char* buffer,int answerSize,vector<InputWord>& readData,vector<InputSMSinformation>& smsInfo)
{
	
	smsInfo.clear();
	prepareVeryfying(buffer,answerSize,readData);

	int size=readData.size();
	if((size>=2))
	{
		for(unsigned int i =0;i<readData.size()-1;i=i+2)
		{
			int smsIndex=0;
			int smsLength=0;
			int result=verifyCMGL(&buffer[readData[i].worldBeginInBuffer],readData[i].worldSize(),smsIndex,smsLength);
			
			if(result<0)
			{
				break;
			}

			InputSMSinformation input;
			input.length=smsLength;
			input.possition=smsIndex;
			smsInfo.push_back(input);
		}

		if(compareBuffer(&buffer[readData[readData.size()-1].worldBeginInBuffer],readData[readData.size()-1].worldSize(),ANS_OK))
		{
			return 1;
		}
		else
		{
			if(compareBuffer(&buffer[readData[readData.size()-1].worldBeginInBuffer],readData[readData.size()-1].worldSize(),ANS_ERROR))
			{
				return Error_respond_from_Modem;
			}
			else
			{
				return 1;
			}
		}
	}
	else
	{
		if(readData.size()==1)
		{
			if(compareBuffer(&buffer[readData[readData.size()-1].worldBeginInBuffer],readData[readData.size()-1].worldSize(),ANS_OK))
			{
				return 1;
			}
			else
			{
				if(compareBuffer(&buffer[readData[readData.size()-1].worldBeginInBuffer],readData[readData.size()-1].worldSize(),ANS_ERROR))
				{
					return Error_respond_from_Modem;
				}
				else
				{
					return default_error;
				}
			}
		}
		else
		{
		}
	}

	return 1;
}