package org.josast.EntrySat.app;

import org.josast.kaikai.generated.FrameTlmEntrySat;
import org.josast.kaikai.generated.FrameTlmEntrySat.Ax25Frame;
import org.josast.kaikai.generated.FrameTlmEntrySat.UiFrameTlmEntrySat;

import io.kaitai.struct.ByteBufferKaitaiStream;

public class Testkaikaigenerated {

	private Testkaikaigenerated() {

	}

	public static void main(String[] args) {

		// FrameTlmEntrySat frame = FrameTlmEntrySat.fromFile("myfile2.dat");
		// byte[] tlm =
		// hexStringToByteArray("8c6c96a88240e09e9c60648ca46103f0000000000801c1200017100102249a78f25d1801dc010002a5a52175fe0800001603b0f2789a24c0");
		byte[] tlm = hexStringToByteArray(
				"8c6c96a88240e09e9c60648ca46103f0000000000801c729001210031923febdcd170600f16b00009ea0981fc6b009befe23c0");
		FrameTlmEntrySat frame = new FrameTlmEntrySat(new ByteBufferKaitaiStream(tlm));
		Ax25Frame ax = frame.frameTlmEntrySat();
		System.out.println(ax.ax25Header().destSsidRaw());
		System.out.println(ax.ax25Header().srcSsidRaw());
		System.out.println(ax.ax25Header().destCallsignRaw().destCallsignRor().destCallsign());
		System.out.println(ax.ax25Header().srcCallsignRaw().srcCallsignRor().srcCallsign());
		System.out.println(ax.ax25Header().ctl());
		UiFrameTlmEntrySat Ui = (UiFrameTlmEntrySat) ax.payload();
		System.out.println(Ui.packetheader().version());
		System.out.println(Ui.packetheader().packetType());
		System.out.println(Ui.packetheader().packetFlag());
		System.out.println(Ui.packetheader().packetApid());
		System.out.println(Ui.packetheader().sequenceControl());
		System.out.println(Ui.packetheader().packetLenght());
		System.out.println("SID  : " + Ui.telemetryData().sid());
		System.out.println("battTemp : " + Ui.telemetryData().battTemp());
		System.out.println("eps33VCurrent : " + Ui.telemetryData().eps33VCurrent());
		System.out.println("eps5VCurrent : " + Ui.telemetryData().eps5VCurrent());
		System.out.println("epsBattVcurrent : " + Ui.telemetryData().epsBattVcurrent());
		System.out.println("epsTemp : " + Ui.telemetryData().epsTemp());
		System.out.println("trxTemp : " + Ui.telemetryData().trxTemp());
	}

	public static byte[] hexStringToByteArray(String s) {
		byte[] b = new byte[s.length() / 2];
		for (int i = 0; i < b.length; i++) {
			int index = i * 2;
			int v = Integer.parseInt(s.substring(index, index + 2), 16);
			b[i] = (byte) v;
		}
		return b;
	}

}
