/**
 * Copyright (c) 2010-2014, openHAB.org and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.zwave.internal.protocol.serialmessage;

import java.util.ArrayList;

import org.openhab.binding.zwave.internal.protocol.SerialMessage;
import org.openhab.binding.zwave.internal.protocol.ZWaveController;
import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessageClass;
import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessagePriority;
import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class processes a serial message from the zwave controller
 * @author Chris Jackson
 * @since 1.5.0
 */
public class SerialApiGetInitDataMessageClass extends ZWaveCommandProcessor {
	private static final Logger logger = LoggerFactory.getLogger(SerialApiGetInitDataMessageClass.class);

	private ArrayList<Integer>zwaveNodes = new ArrayList<Integer>();
	
	private static final int NODE_BYTES = 29; // 29 bytes = 232 bits, one for each supported node by Z-Wave;
	
	public SerialMessage doRequest() {
		return new SerialMessage(SerialMessageClass.SerialApiGetInitData, SerialMessageType.Request, SerialMessageClass.SerialApiGetInitData, SerialMessagePriority.High);
	}
	
	@Override
	public boolean handleResponse(ZWaveController zController, SerialMessage lastSentMessage, SerialMessage incomingMessage) {
		logger.debug(String.format("Got MessageSerialApiGetInitData response."));
		int nodeBytes = incomingMessage.getMessagePayloadByte(2);
		
		if (nodeBytes != NODE_BYTES) {
			logger.error("Invalid number of node bytes = {}", nodeBytes);
			return false;
		}

		int nodeId = 1;
		
		// loop bytes
		for (int i = 3;i < 3 + nodeBytes;i++) {
			int incomingByte = incomingMessage.getMessagePayloadByte(i);
			// loop bits in byte
			for (int j=0;j<8;j++) {
				int b1 = incomingByte & (int)Math.pow(2.0D, j);
				int b2 = (int)Math.pow(2.0D, j);
				if (b1 == b2) {
					logger.info("NODE {}: Node found", nodeId);

					zwaveNodes.add(nodeId);
				}
				nodeId++;
			}
		}
		
		logger.info("ZWave API {} API", incomingMessage.getMessagePayloadByte(1) & 0x01 ? "Controller" : "Slave");
		logger.info("ZWave Controller is {} Controller", incomingMessage.getMessagePayloadByte(1) & 0x04 ? "Primary" : "Secondary");
		logger.info("------------Number of Nodes Found Registered to ZWave Controller------------");
		logger.info(String.format("# Nodes = %d", zwaveNodes.size()));
		logger.info("----------------------------------------------------------------------------");
		
		checkTransactionComplete(lastSentMessage, incomingMessage);

		return true;
	}

	public ArrayList<Integer> getNodes() {
		return zwaveNodes;
	}
}

@@ -2357,19 +2357,32 @@
 (%22ZWave 
-API
+Controller using
  %7B%7D API%22
@@ -2434,16 +2434,26 @@
 0x01 ? %22
+Slave%22 : %22
 Controll
@@ -2458,18 +2458,8 @@
 ller
-%22 : %22Slave
 %22);%0A
@@ -2564,29 +2564,137 @@
  ? %22
-Primary%22 : %22Secondary
+Secondary%22 : %22Primary%22);%0A%09%09logger.info(%22ZWave Controller %7B%7D SUC%22, incomingMessage.getMessagePayloadByte(1) & 0x08 ? %22is%22 : %22isn't
 %22);%0A

Update SerialApiGetInitDataMessageClass.java