Пример #1
0
 Trajectory::Trajectory(size_t n, istream* fh) {
   string line;
   getline(*fh,line);
   istringstream iss(line);
   iss >> time;
   EpiState cur(n);
   for (size_t i(0); i < n; ++i) iss >> cur[i];
   initialState = cur;
   EpiState last(cur);
   while (getline(*fh,line)) {
     transitions.push_back(StateTransition(n));
     for (size_t i(0); i < n; ++i) {
       iss >> cur[i];
       transitions.back()[i] = last[i]-cur[i];
     }
   }
   curState = cur;
 }
Пример #2
0
static int stateobj_spy(struct state_object * self, int x, int input, int z, int t)
{
    int old_state = self->current_state;
    int ans = StateTransition(self, x, input, z, t);
    int new_state = self->current_state;
    
    if (self == SBS_STATE) { STR_APPEND(log, "SBS  :"); }
    else if (self == SCS_STATE) { STR_APPEND(log, "SCS  :"); }
    else if (self == SCSES_STATE) { STR_APPEND(log, "SCSes:"); }
    else if (self == SCSSR_STATE) { STR_APPEND(log, "SCSsr:"); }
    else if (self == SDS_REAR_STATE) { STR_APPEND(log, "SDSr :"); }
    else if (self == SDS_FRONT1_STATE) { STR_APPEND(log, "SDSf1:"); }
    else if (self == SDS_FRONT2_STATE) { STR_APPEND(log, "SDSf2:"); }
    else if (self == SDS_FRONT3_STATE) { STR_APPEND(log, "SDSf3:"); }
    else if (self == SDS_FRONT4_STATE) { STR_APPEND(log, "SDSf4:"); }
    else if (self == SPS_STATE) { STR_APPEND(log, "SPS  :"); }
    else if (self == FSS_STATE) { STR_APPEND(log, "FSS  :"); }
    else if (self == FCS_STATE) { STR_APPEND(log, "FCS  :"); }
    
    STR_APPEND(log, "(%d) -- %2d -->(%d)\n", old_state, input, new_state);
    
    return ans;
}
Пример #3
0
/* processes character read from serial port of gsm module */
void SimcomResponseParser::FeedChar(char c)
{	
	if (_state != ParserState::WaitingForEcho)
	{
		if (_currentCommand == AtCommand::CipSend)
		{
			if (_parserContext.CipsendState == CipsendStateType::WaitingForPrompt)
			{
				if (_promptSequenceDetector.NextChar(c))
				{
					_parserContext.CipsendState = CipsendStateType::WaitingForDataEcho;
					_response.clear();
					_logger.Log(F("Writing %d b of data"), _parserContext.CipsendDataLength);

					auto dataPtr = _parserContext.CipsendBuffer->c_str() + _parserContext.CipsendDataIndex;
					auto dataLength = _parserContext.CipsendDataLength;

					_serial.write(dataPtr, dataLength);
					_parserContext.CipsendDataEchoDetector.SetSequence(dataPtr, dataLength);
					return;
				}
			}
			if (_parserContext.CipsendState == CipsendStateType::WaitingForDataEcho)
			{
				if (_parserContext.CipsendDataEchoDetector.NextChar(c))
				{
					_parserContext.CipsendState = CipsendStateType::WaitingForDataAccept;
				}
				return;
			}
		}
	}
	if (_parserContext.CiprxGetLeftBytesToRead > 0)
	{
		_parserContext.CipRxGetBuffer->append(c);
		_parserContext.CiprxGetLeftBytesToRead--;
		return;
	}	
	int prevState = lineParserState;

	lineParserState = StateTransition(c);

	if(prevState  == PARSER_INITIAL || prevState == PARSER_LF || prevState == PARSER_LINE)
	{		
		if (lineParserState == PARSER_LINE)
		{
			if (_response.freeBytes() > 0)
			{
				_response.append(c);
			}
		}
	}
	// line -> delimiter
	if ((prevState == PARSER_LINE || prevState == PARSER_CR) && (lineParserState == PARSER_LF))
	{
		if (_response.length() == 0)
		{
			return;
		}

		_logger.LogAt(F("    <= %s"), (char*)_response.c_str());

		auto isUnsolicited = ParseUnsolicited(_response);

		if (isUnsolicited)
		{
			_response.clear();
			return;
		}
		ParserState parseResult = ParseLine();

		// if error or or success
		if (parseResult == ParserState::Success || parseResult == ParserState::Error)
		{
			commandReady = true;
			_state = parseResult;
		}
		
		// if command not parsed yet
		else if (parseResult == ParserState::None)
		{
			if (ParsingHelpers::CheckIfLineContainsGarbage(_response))
			{
				if (IsGarbageDetectionActive)
				{
					_garbageOnSerialDetected = true;
					_logger.Log(F(" Garbage detected(%d b): "), _response.length());
				}

			}
			else
			{
				_logger.Log(F( "Unknown response (%d b): "), _response.length());
			}

			FixedString200 printableLine;
			BinaryToString(_response, printableLine);
			_logger.Log(F(" '%s'"), printableLine.c_str());
			// do nothing, do not change _state to none
		}
		else
		{
			_state = parseResult;
		}
		
		_response.clear();
	}

}
Пример #4
0
 void SetInitialState(IStateBase* initial_state) {
     StateTransition(initial_state);
     EnterNextState();
 }