Exemplo n.º 1
0
Network::msg_l3_status_t BaseRFApplication::sendMetaReportCluster(univmsg_l7_any_t* msg, uint8_t flags, bool cmd_mc_last,
		uint8_t clusterID) {
	MW_LOG_DEBUG_TRACE(MW_LOG_BASERF);

	bool allEndpoints = flags & BASERF_CMD_METAFLAG_ALL_ENDPOINTS;
	bool allClusters = flags & BASERF_CMD_METAFLAG_ALL_CLUSTERS;
	uint8_t nextClusterID = allClusters? 0 : clusterID;
	uint8_t cluster_count = m_device->getClusterCount();
	uint8_t lastClusterID = allClusters ? cluster_count : clusterID;
	Network::msg_l3_status_t result = ERROR_INVALID_DATA;

	Cluster* nextCluster = NULL;

	do {
		nextCluster = NULL;m_device->getCluster(nextClusterID);

		msg->data[2] = nextClusterID;
		msg->data[3] = nextCluster->getType();
		msg->data[4] = nextCluster->getSubtype();
		msg->data[5] = nextCluster->getEndpointCount();

		msg->msg_header.cmd_id = BASERF_CMD_META_CLUSTER_REP;
		//about the cmd_mc flag:
		//a) if cmd_mc_last is false then we are not the last reporter and all our reports have it as true
		//a) if cmd_mc_last is true then we are the last reporter in the chain and then:
		//b.1) if we are sending just one cluster report then it is false
		//b.2) if we are sending report for all clusters then it is true for all but the last one, unless we also send allEndpoints
		msg->msg_header.cmd_mc = cmd_mc_last ? (allClusters ? (nextClusterID == lastClusterID && !allEndpoints) : false) : true;
		msg->msg_header.seq_meta = true;
		msg->msg_header.dataLen = 6;

		result = sendMessage(msg);
		MW_LOG_DEBUG_TRACE(MW_LOG_BASERF) << PSTR("result=") << result;

		if ( result >= Meshwork::L3::Network::OK ) {
			if ( allEndpoints ) {
				result = sendMetaReportEndpoint(msg, flags, cmd_mc_last ? (allClusters ? (nextClusterID == lastClusterID) : false) : true, nextClusterID, 0);
				if ( result < Meshwork::L3::Network::OK )
					break;
			}
		}

	} while ( ++nextClusterID <= lastClusterID );
	MW_LOG_DEBUG_TRACE(MW_LOG_BASERF) << PSTR("result=") << result;
	return result;
}
Exemplo n.º 2
0
Network::msg_l3_status_t BaseRFApplication::sendMetaReportEndpoint(univmsg_l7_any_t* msg, uint8_t flags, bool cmd_mc_last,
		uint8_t clusterID, uint8_t endpointID) {
	MW_LOG_DEBUG_TRACE(MW_LOG_BASERF);

	bool allEndpoints = flags & BASERF_CMD_METAFLAG_ALL_ENDPOINTS;
	uint8_t nextEndpointID = allEndpoints ? 0 : endpointID;
	Cluster* cluster = m_device->getCluster(clusterID);
	uint8_t lastEndpointID = allEndpoints ? cluster->getEndpointCount() - 1 : endpointID;
	Network::msg_l3_status_t result = ERROR_INVALID_DATA;

	Endpoint* nextEndpoint = cluster->getEndpoint(nextEndpointID);

	do {
		msg->data[2] = clusterID;
		msg->data[3] = nextEndpointID;

		uint16_t temp = nextEndpoint->getType();
		msg->data[4] = (temp >> 8) & 0xFF;
		msg->data[5] = (temp >> 0) & 0xFF;

		temp = nextEndpoint->getUnitType();
		msg->data[6] = (temp >> 8) & 0xFF;
		msg->data[7] = (temp >> 0) & 0xFF;

		msg->msg_header.cmd_id = BASERF_CMD_META_ENDPOINT_REP;
		//about the cmd_mc flag:
		//a) if cmd_mc_last is false then we are not the last reporter and all our reports have it as true
		//a) if cmd_mc_last is true then we are the last reporter in the chain and then:
		//b.1) if we are sending just one endpoint report then it is false
		//b.2) if we are sending report for all endpoints then it is true for all but the last one
		msg->msg_header.cmd_mc = cmd_mc_last ? (allEndpoints ? (nextEndpointID == lastEndpointID) : false) : true;
		msg->msg_header.seq_meta = true;
		msg->msg_header.dataLen = 8;

		result = sendMessage(msg);
		MW_LOG_DEBUG_TRACE(MW_LOG_BASERF) << PSTR("result=") << result;

		if ( result < Meshwork::L3::Network::OK )
			break;

	} while ( ++nextEndpointID <= lastEndpointID );
	MW_LOG_DEBUG_TRACE(MW_LOG_BASERF) << PSTR("result=") << result;
	return result;
}