Пример #1
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;
}