Пример #1
0
// Message delivered through _msg
void _processInternalMessages() {
	bool isMetric;
	uint8_t type = _msg.type;

	#if !defined(MY_DISABLE_REMOTE_RESET)
		if (type == I_REBOOT) {
			// Requires MySensors or other bootloader with watchdogs enabled
			hwReboot();
		} else
	#endif
		if (type == I_CONFIG) {
		// Pick up configuration from controller (currently only metric/imperial)
		// and store it in eeprom if changed
	 	if (_msg.getString() == NULL) {
			isMetric = true;
		} else {
			isMetric = _msg.getString()[0] == 'M';
		}
		_cc.isMetric = isMetric;
		hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
	} else if (type == I_PRESENTATION) {
		if (!mGetAck(_msg)) {
			// Re-send node presentation to controller
			#if defined(MY_RADIO_FEATURE)
				transportPresentNode();
			#endif
			if (presentation)
				presentation();
		}
	} else if (type == I_HEARTBEAT) {
		sendHeartbeat();
	} else if (type == I_TIME) {
		// Deliver time to callback
		if (receiveTime)
			receiveTime(_msg.getULong());
	}
	#if defined(MY_REPEATER_FEATURE)
		if (type == I_CHILDREN) {
			if (_msg.getString()[0] == 'C') {
				// Clears child relay data for this node
				debug(PSTR("clear routing table\n"));
				uint8_t i = 255;
				do {
					hwWriteConfig(EEPROM_ROUTES_ADDRESS+i, BROADCAST_ADDRESS);
				} while (i--);
				// Clear parent node id & distance to gw
				hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, AUTO);
				hwWriteConfig(EEPROM_DISTANCE_ADDRESS, DISTANCE_INVALID);
				// Find parent node
				transportFindParentNode();
				_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set(""));
			}
		}
	#endif
}