Exemple #1
0
void RSSIModule::MeshConnectionChangedHandler(Connection* connection)
{
    //New connection has just been made
    if(connection->handshakeDone){
        if(Config->enableConnectionRSSIMeasurement){
            if(configuration.connectionRSSISamplingMode == RSSISamplingModes::RSSI_SAMPLING_HIGH){
                StartConnectionRSSIMeasurement(connection);
            }
        }
    }
}
void StatusReporterModule::MeshConnectionChangedHandler(Connection* connection)
{
	//New connection has just been made
	if(connection->handshakeDone()){
		//TODO: Implement low and medium rssi sampling with timer handler
		//TODO: disable and enable rssi sampling on existing connections
		if(Config->enableConnectionRSSIMeasurement){
			if(configuration.connectionRSSISamplingMode == RSSISampingModes::RSSI_SAMLING_HIGH){
				StartConnectionRSSIMeasurement(connection);
			}
		}
	}
}
bool StatusReporterModule::TerminalCommandHandler(string commandName, vector<string> commandArgs)
{

	if(commandName == "rssistart")
	{
		for (int i = 0; i < Config->meshMaxConnections; i++)
		{
			StartConnectionRSSIMeasurement(cm->connections[i]);
		}

		return true;
	}
	else if(commandName == "rssistop")
	{
		for (int i = 0; i < Config->meshMaxConnections; i++)
		{
			StopConnectionRSSIMeasurement(cm->connections[i]);
		}

		return true;
	}

	//React on commands, return true if handled, false otherwise
	if(commandArgs.size() >= 2 && commandArgs[1] == moduleName)
	{
		if(commandName == "action")
		{
			//Rewrite "this" to our own node id, this will actually build the packet
			//But reroute it to our own node
			nodeID destinationNode = (commandArgs[0] == "this") ? node->persistentConfig.nodeId : atoi(commandArgs[0].c_str());

			if(commandArgs.size() == 3 && commandArgs[2] == "get_status")
			{
				SendModuleActionMessage(
					MESSAGE_TYPE_MODULE_TRIGGER_ACTION,
					destinationNode,
					StatusModuleTriggerActionMessages::GET_STATUS,
					0,
					NULL,
					0,
					false
				);

				return true;
			}
			else if(commandArgs.size() == 3 && commandArgs[2] == "get_device_info")
			{
				SendModuleActionMessage(
					MESSAGE_TYPE_MODULE_TRIGGER_ACTION,
					destinationNode,
					StatusModuleTriggerActionMessages::GET_DEVICE_INFO,
					0,
					NULL,
					0,
					false
				);

				return true;
			}
			else if(commandArgs.size() == 3 && commandArgs[2] == "get_connections")
			{
				SendModuleActionMessage(
					MESSAGE_TYPE_MODULE_TRIGGER_ACTION,
					destinationNode,
					StatusModuleTriggerActionMessages::GET_ALL_CONNECTIONS,
					0,
					NULL,
					0,
					false
				);

				return true;
			}
			else if(commandArgs.size() == 3 && commandArgs[2] == "get_nearby")
			{
				SendModuleActionMessage(
					MESSAGE_TYPE_MODULE_TRIGGER_ACTION,
					destinationNode,
					StatusModuleTriggerActionMessages::GET_NEARBY_NODES,
					0,
					NULL,
					0,
					false
				);

				return true;
			}
			else if(commandArgs.size() == 3 && commandArgs[2] == "set_init")
			{
				SendModuleActionMessage(
					MESSAGE_TYPE_MODULE_TRIGGER_ACTION,
					destinationNode,
					StatusModuleTriggerActionMessages::SET_INITIALIZED,
					0,
					NULL,
					0,
					false
				);

				return true;
			}
		}
	}

	//Must be called to allow the module to get and set the config
	return Module::TerminalCommandHandler(commandName, commandArgs);
}