bool Transition::triggers(const ACLMessage& msg, const ACLMessage& initiatingMsg, const RoleMapping& roleMapping) const
{
    // Set the standard validation flags
    validation::Flags flags = (validation::Flags) (validation::PERFORMATIVE | validation::SENDER | validation::RECEIVERS | validation::CONVERSATION_ID | validation::PROTOCOL);
    if( validateMessage(msg, initiatingMsg, roleMapping, flags) )
    {
	return true;
    } else {
        LOG_DEBUG("Message validation failed: message does not apply to transition");
    }
    return false;
}
//parses the queue of bits and translates them into messages
//returns "true" if a valid message was found
bool RF_reciever::convertBitToMessage(byte currentBit)
{
	//increment noise counter (used by heartbeat function)
	noiseCount++;

			if(currentBit==LONG_GAP)
			{
				debugPrint(F("\nGap"));
				resetMessage();
				return false;
			}
			else
			{
				debugPrint(String(currentBit));
			}


			//process 'ones', 'zeros' should have been done by resetMessage() function
		if(currentBit==ONE_BIT) // so process it but only if bit==1
		{
			if(bitNumber<=3) //preamble
			{
				bitSet(preamble,3-bitNumber);
			}
			else if(bitNumber>3 and bitNumber<=11) //ID
			{
				//check preamble
				if(bitNumber==4 and preamble!=5)
				{
					debugPrint(F("\nBadPre")); //bad preamble so exit
					resetMessage();
					return false;
				}

				bitSet(id,11-bitNumber); //set ID
			}
			else if(bitNumber==12) //battery
			{
				batteryOK=true;
			}
			else if(bitNumber==13) //manual transmit
			{
				ManualTransmit=true;
			}
			else if(bitNumber>13 and bitNumber<=15) //channel
			{
				bitSet(channel,15-bitNumber);
			}
			else if(bitNumber==16) //negative temperature flag
			{
				negativeTemperature=true;
			}
			else if(bitNumber>16 and bitNumber<=27) //temperature10 number
			{
				bitSet(temperature10,27-bitNumber);
			}
			else if(bitNumber>27 and bitNumber<=35) //relative humidity number
			{
				bitSet(relativeHumidity,35-bitNumber);
			}
		}

		if(bitNumber<35)
		{
			RF_reciever::bitNumber++;
		}
		else
		{
			//end of message so timestamp and validate

			timeMicros=micros(); //approximate time of this message
			RF_reciever::bitNumber=0;

			debugPrint(F("\nNew Message!\n"));


			if(validateMessage())
			{
				//have a new valid message!
				return true;

			}
			else
			{
				//message was invalid, clear message and begin again
				resetMessage();
				return false;
			}

		}

	return false; //no complete and valid message yet

}
Example #3
0
// This is the actual task that is run
static portTASK_FUNCTION( sensorTask, pvParameters )
{
	uint8_t rxLen, status; // not using status, and rxLen is always maxReceiveBytesForSpecificNumOfSensorSamples (define in .h)
	uint8_t buffer[vtI2CMLen]; // receive message
	uint8_t recvMsgType; // message type of the message put on I2C queue by moveTask (defined in I2CtaskMsgtypes)
    
	// Get the parameters
	SensorAStruct *sensorT = (SensorAStruct *) pvParameters;
    
    webServerTaskStruct *webServerData = sensorT->webServerData;
	// Get the I2C device pointer
	vtI2CStruct *i2cDevPtr = sensorT->i2cDev;
	MoveTaskStruct *moveTPtr = sensorT->moveT;
    
    
	uint8_t count = 0;

	uint16_t frontBuf[numOfSensorToDebounce] = {0, 0, 0};
	uint16_t sideTopBuf[numOfSensorToDebounce] = {0, 0, 0};
	uint16_t sideBottomBuf[numOfSensorToDebounce] = {0, 0, 0};

	int i = 0;
	for( i = 0; i < numOfSensorToDebounce; i++ )
	{
		frontBuf[i] = 0;
		sideTopBuf[i] = 0;
		sideBottomBuf[i] = 0;
	}
    
    
	// Like all good tasks, this should never exit
	for(;;)
	{
		// Wait for a message from an I2C operation
		if (vtI2CDeQ(i2cDevPtr, vtI2CMLen,buffer,&rxLen,&recvMsgType,&status) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}
        
        //		printf("buffer %x\n", buffer[0]);
        //
        //		uint8_t index = 0;
        //		for (index = 0; index < rxLen; index++)
        //		{
        //		 	printf("buffer %x\n", buffer[index]);
        //		}
        
		switch(recvMsgType)
		{
			case (sensor1):
			{
				break;
			}
			case (sensor2):
			{
				if( rxLen != 0 )
				{
                    // make sure the check sum is ok
					//printf("valid = %d\n", validateMessage(buffer, rxLen));
					if( validateMessage(buffer, rxLen) )
					{
						switch( getMessageId(buffer, rxLen) ) // recognize the msgID
						{
							case RoverWaitingForCommand:
							{
                                
                                
                                /*
                                 * We need to disable the timer so that the arm doesn't
                                 * retrieve multiple sensor values when the rover is stationary.
                                 * It is important to enable the timer back again so that the
                                 * Arm receives distance values the rover has travelled from the
                                 * last poll.
                                 */
                                
                                /*
                                 * Retrieve the sensor distances
                                 */
                                uint16_t frontDistanceInches = getFrontSensorDistanceInInches(buffer, rxLen);
                                uint16_t topRightDistanceInches = getTopRightSensorDistanceInInches(buffer, rxLen);
                                uint16_t bottomRightDistanceInches = getBottomRightSensorDistanceInInches(buffer, rxLen);

								uint8_t canFront = updateSensorBuf(frontBuf, frontDistanceInches);
								uint8_t canSideT = updateSensorBuf(sideTopBuf, topRightDistanceInches);
								uint8_t canSideB = updateSensorBuf(sideBottomBuf, bottomRightDistanceInches);

								uint8_t rightFeet = getRightFeet(buffer, rxLen);
								uint8_t rightInches = getRightInches(buffer, rxLen);
								uint8_t leftFeet = getLeftFeet(buffer, rxLen);								  
								uint8_t leftInches = getLeftInches(buffer, rxLen);

//								printf("rightF = %d, rightI = %d, leftF = %d, leftI = %d\n", rightFeet, rightInches, leftFeet
//										, leftInches);

								if ( canFront != 1 ||  canSideT != 1 || canSideB != 1){
									break;
								}


								sendWheelDistancesOnly(sensorT->mapT, leftFeet, leftInches, rightFeet, rightInches, 0);
                                
                               	printf("Front %d\n", frontDistanceInches);
                                printf("TR %d\n", topRightDistanceInches);
                                printf("BR %d\n", bottomRightDistanceInches);
                                
                                SendWebServerSensorData(webServerData,frontDistanceInches,
                                                        topRightDistanceInches,bottomRightDistanceInches, 0);

				performLogic(buffer , rxLen, moveTPtr, sensorT);
                                
								break;
							}
							case RoverBusy:
							{
                                /*
                                 * Simply pass the buffer received from the rover to the MAP Task.
                                 */
                                
                                /*
                                 * Since the rover has received the command, we want
                                 * to enable the timer so that we poll rover to receive
                                 * the distance in feet and inches the rover has moved.
                                 */
                                
                                break;
                            };
                                
							case RoverHitStartFinshLine:
							{
                                /*
                                 * Simply pass the buffer received from the rover to the MAP Task.
                                 */
								
								uint8_t cmd [] = {stop_cmd_ToRover};
								uint8_t t [] = {0};
								uint8_t deg [] = {0};
								uint8_t dist [] = {0,0};
								SendWebServerCommandBuf(webServerData, fillWebServerBuf(cmd[0], t[0], deg[0], dist[0], dist[1]), portMAX_DELAY);
                                //SendStopToRover(moveTPtr, portMAX_DELAY);
								SendStFinNotification(sensorT->mapT, portMAX_DELAY);
								performLogic(buffer , rxLen, moveTPtr, sensorT);
								RUN++;
                                break;
                            };
                                
                            case RoverReceiveMoveCommand:
                            {
                                /*
                                 * Since the rover has received the command, we want
                                 * to enable the timer so that we poll rover to receive
                                 * the distance in feet and inches the rover has moved.
                                 */
                                break;
                            };
                                
							case MessageDrop:
							{
                                // msg wasn't received in time
								SendDroppedNotification(moveTPtr, 0);
								break;
							};
						}
					}
                    
					else
					{
						// notify the moveTask that a message was droped or went bad
						SendDroppedNotification(moveTPtr, 0);
					}
				}
				else
				{
                    // message dropped
					SendDroppedNotification(moveTPtr, 0);
				}
                
				break;
			}
			case (cmdSend):
			{
				break;
			}
                
			default:
			{
				//VT_HANDLE_FATAL_ERROR(0);
				break;
			}
		}
	}
}