package org.openhab.binding.maxcul.internal.messages;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class TimeInfoMsg extends BaseMsg {

	final static private int TIME_INFO_PAYLOAD_LEN = 5; /* in bytes */

	public TimeInfoMsg(String rawMsg) {
		super(rawMsg);
		// TODO Process message to extract time - not used at the moment
	}

	public TimeInfoMsg(byte msgCount, byte msgFlag,
			byte groupId, String srcAddr, String dstAddr) {
		super(msgCount, msgFlag, MaxCulMsgType.TIME_INFO, groupId, srcAddr, dstAddr);

		updateTime();
	}

	public void updateTime()
	{
		byte[] payload = new byte[TIME_INFO_PAYLOAD_LEN];

		Calendar now = new GregorianCalendar();

		payload[0] = (byte) (now.get(Calendar.YEAR) - 2000);
		payload[1] = (byte) now.get(Calendar.DAY_OF_MONTH);
		payload[2] = (byte) now.get(Calendar.HOUR);
		payload[3] = (byte) (now.get(Calendar.MINUTE) | ((now.get(Calendar.MONTH) & 0x0C)<<4));
		payload[4] = (byte) (now.get(Calendar.SECOND) | ((now.get(Calendar.MONTH) & 0x03)<<6));

		super.appendPayload(payload);
	}
}

@@ -112,16 +112,74 @@
 endar;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 public c
@@ -283,16 +283,102 @@
 tes */%0A%0A
+%09private static final Logger logger =%0A%09%09%09LoggerFactory.getLogger(TimeInfoMsg.class);%0A%0A
 %09public 
@@ -1045,24 +1045,26 @@
 lendar.MONTH
++1
 ) & 0x0C)%3C%3C4
@@ -1141,16 +1141,18 @@
 ar.MONTH
++1
 ) & 0x03
@@ -1160,16 +1160,120 @@
 %3C%3C6));%0A%0A
+%09%09for (int i=0; i%3C TIME_INFO_PAYLOAD_LEN; i++)%0A%09%09%09logger.debug(%22TimeInfo byte%5B%22+i+%22%5D =%3E %22+payload%5Bi%5D);%0A%0A
 %09%09super.

Add debug to time information message and correct month being 0 indexed.