package org.josast.kaikai.generated;

//This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import io.kaitai.struct.ByteBufferKaitaiStream;
import io.kaitai.struct.KaitaiStruct;
import io.kaitai.struct.KaitaiStream;
import java.io.IOException;
import java.nio.charset.Charset;

public class FrameTlmEntrySat extends KaitaiStruct {
	public static FrameTlmEntrySat fromFile(String fileName) throws IOException {
		return new FrameTlmEntrySat(new ByteBufferKaitaiStream(fileName));
	}

	public FrameTlmEntrySat(KaitaiStream _io) {
		this(_io, null, null);
	}

	public FrameTlmEntrySat(KaitaiStream _io, KaitaiStruct _parent) {
		this(_io, _parent, null);
	}

	public FrameTlmEntrySat(KaitaiStream _io, KaitaiStruct _parent, FrameTlmEntrySat _root) {
		super(_io);
		this._parent = _parent;
		this._root = _root == null ? this : _root;
		_read();
	}

	private void _read() {
		this.frameTlmEntrySat = new Ax25Frame(this._io, this, _root);
	}

	public static class Ax25Frame extends KaitaiStruct {
		public static Ax25Frame fromFile(String fileName) throws IOException {
			return new Ax25Frame(new ByteBufferKaitaiStream(fileName));
		}

		public Ax25Frame(KaitaiStream _io) {
			this(_io, null, null);
		}

		public Ax25Frame(KaitaiStream _io, FrameTlmEntrySat _parent) {
			this(_io, _parent, null);
		}

		public Ax25Frame(KaitaiStream _io, FrameTlmEntrySat _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.ax25Header = new Ax25Header(this._io, this, _root);
			switch ((ax25Header().ctl() & 19)) {
			case 0: {
				this.payload = new IFrame(this._io, this, _root);
				break;
			}
			case 3: {
				this.payload = new UiFrameTlmEntrySat(this._io, this, _root);
				break;
			}
			case 19: {
				this.payload = new IFrame(this._io, this, _root);
				break;
			}
			case 16: {
				this.payload = new IFrame(this._io, this, _root);
				break;
			}
			case 18: {
				this.payload = new IFrame(this._io, this, _root);
				break;
			}
			case 2: {
				this.payload = new IFrame(this._io, this, _root);
				break;
			}
			}
		}

		private Ax25Header ax25Header;
		private KaitaiStruct payload;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat _parent;

		public Ax25Header ax25Header() {
			return ax25Header;
		}

		public KaitaiStruct payload() {
			return payload;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat _parent() {
			return _parent;
		}
	}

	public static class UiFrameTlmEntrySat extends KaitaiStruct {
		public static UiFrameTlmEntrySat fromFile(String fileName) throws IOException {
			return new UiFrameTlmEntrySat(new ByteBufferKaitaiStream(fileName));
		}

		public UiFrameTlmEntrySat(KaitaiStream _io) {
			this(_io, null, null);
		}

		public UiFrameTlmEntrySat(KaitaiStream _io, FrameTlmEntrySat.Ax25Frame _parent) {
			this(_io, _parent, null);
		}

		public UiFrameTlmEntrySat(KaitaiStream _io, FrameTlmEntrySat.Ax25Frame _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.pid = this._io.readU1();
			this.time = this._io.readU4be();
			this.packetheader = new Packetheader(this._io, this, _root);
			this.telemetryDataFiledHearder = new TelemetryDataFiledHearder(this._io, this, _root);
			this.telemetryData = new TelemetryData(this._io, this, _root);
			this.ax25Info = this._io.readBytesFull();
		}

		private int pid;
		private long time;
		private Packetheader packetheader;
		private TelemetryDataFiledHearder telemetryDataFiledHearder;
		private TelemetryData telemetryData;
		private byte[] ax25Info;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.Ax25Frame _parent;

		public int pid() {
			return pid;
		}

		public long time() {
			return time;
		}

		public Packetheader packetheader() {
			return packetheader;
		}

		public TelemetryDataFiledHearder telemetryDataFiledHearder() {
			return telemetryDataFiledHearder;
		}

		public TelemetryData telemetryData() {
			return telemetryData;
		}

		public byte[] ax25Info() {
			return ax25Info;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.Ax25Frame _parent() {
			return _parent;
		}
	}

	public static class DestCallsign extends KaitaiStruct {
		public static DestCallsign fromFile(String fileName) throws IOException {
			return new DestCallsign(new ByteBufferKaitaiStream(fileName));
		}

		public DestCallsign(KaitaiStream _io) {
			this(_io, null, null);
		}

		public DestCallsign(KaitaiStream _io, FrameTlmEntrySat.DestCallsignRaw _parent) {
			this(_io, _parent, null);
		}

		public DestCallsign(KaitaiStream _io, FrameTlmEntrySat.DestCallsignRaw _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.destCallsign = new String(this._io.readBytes(6), Charset.forName("ASCII"));
		}

		private String destCallsign;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.DestCallsignRaw _parent;

		public String destCallsign() {
			return destCallsign;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.DestCallsignRaw _parent() {
			return _parent;
		}
	}

	public static class Ax25Header extends KaitaiStruct {
		public static Ax25Header fromFile(String fileName) throws IOException {
			return new Ax25Header(new ByteBufferKaitaiStream(fileName));
		}

		public Ax25Header(KaitaiStream _io) {
			this(_io, null, null);
		}

		public Ax25Header(KaitaiStream _io, FrameTlmEntrySat.Ax25Frame _parent) {
			this(_io, _parent, null);
		}

		public Ax25Header(KaitaiStream _io, FrameTlmEntrySat.Ax25Frame _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.destCallsignRaw = new DestCallsignRaw(this._io, this, _root);
			this.destSsidRaw = this._io.readU1();
			this.srcCallsignRaw = new SrcCallsignRaw(this._io, this, _root);
			this.srcSsidRaw = this._io.readU1();
			this.ctl = this._io.readU1();
		}

		private Integer srcSsid;

		public Integer srcSsid() {
			if (this.srcSsid != null)
				return this.srcSsid;
			int _tmp = (int) (((srcSsidRaw() & 15) >> 1));
			this.srcSsid = _tmp;
			return this.srcSsid;
		}

		private Integer destSsid;

		public Integer destSsid() {
			if (this.destSsid != null)
				return this.destSsid;
			int _tmp = (int) (((destSsidRaw() & 15) >> 1));
			this.destSsid = _tmp;
			return this.destSsid;
		}

		private DestCallsignRaw destCallsignRaw;
		private int destSsidRaw;
		private SrcCallsignRaw srcCallsignRaw;
		private int srcSsidRaw;
		private int ctl;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.Ax25Frame _parent;

		public DestCallsignRaw destCallsignRaw() {
			return destCallsignRaw;
		}

		public int destSsidRaw() {
			return destSsidRaw;
		}

		public SrcCallsignRaw srcCallsignRaw() {
			return srcCallsignRaw;
		}

		public int srcSsidRaw() {
			return srcSsidRaw;
		}

		public int ctl() {
			return ctl;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.Ax25Frame _parent() {
			return _parent;
		}
	}

	public static class SrcCallsignRaw extends KaitaiStruct {
		public static SrcCallsignRaw fromFile(String fileName) throws IOException {
			return new SrcCallsignRaw(new ByteBufferKaitaiStream(fileName));
		}

		public SrcCallsignRaw(KaitaiStream _io) {
			this(_io, null, null);
		}

		public SrcCallsignRaw(KaitaiStream _io, FrameTlmEntrySat.Ax25Header _parent) {
			this(_io, _parent, null);
		}

		public SrcCallsignRaw(KaitaiStream _io, FrameTlmEntrySat.Ax25Header _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this._raw__raw_srcCallsignRor = this._io.readBytes(6);
			this._raw_srcCallsignRor = KaitaiStream.processRotateLeft(this._raw__raw_srcCallsignRor, 8 - (1), 1);
			KaitaiStream _io__raw_srcCallsignRor = new ByteBufferKaitaiStream(_raw_srcCallsignRor);
			this.srcCallsignRor = new SrcCallsign(_io__raw_srcCallsignRor, this, _root);
		}

		private SrcCallsign srcCallsignRor;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.Ax25Header _parent;
		private byte[] _raw__raw_srcCallsignRor;
		private byte[] _raw_srcCallsignRor;

		public SrcCallsign srcCallsignRor() {
			return srcCallsignRor;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.Ax25Header _parent() {
			return _parent;
		}

		public byte[] _raw__raw_srcCallsignRor() {
			return _raw__raw_srcCallsignRor;
		}

		public byte[] _raw_srcCallsignRor() {
			return _raw_srcCallsignRor;
		}
	}

	public static class IFrame extends KaitaiStruct {
		public static IFrame fromFile(String fileName) throws IOException {
			return new IFrame(new ByteBufferKaitaiStream(fileName));
		}

		public IFrame(KaitaiStream _io) {
			this(_io, null, null);
		}

		public IFrame(KaitaiStream _io, FrameTlmEntrySat.Ax25Frame _parent) {
			this(_io, _parent, null);
		}

		public IFrame(KaitaiStream _io, FrameTlmEntrySat.Ax25Frame _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.pid = this._io.readU1();
			this.ax25Info = this._io.readBytesFull();
		}

		private int pid;
		private byte[] ax25Info;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.Ax25Frame _parent;

		public int pid() {
			return pid;
		}

		public byte[] ax25Info() {
			return ax25Info;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.Ax25Frame _parent() {
			return _parent;
		}
	}

	public static class TelemetryDataFiledHearder extends KaitaiStruct {
		public static TelemetryDataFiledHearder fromFile(String fileName) throws IOException {
			return new TelemetryDataFiledHearder(new ByteBufferKaitaiStream(fileName));
		}

		public TelemetryDataFiledHearder(KaitaiStream _io) {
			this(_io, null, null);
		}

		public TelemetryDataFiledHearder(KaitaiStream _io, FrameTlmEntrySat.UiFrameTlmEntrySat _parent) {
			this(_io, _parent, null);
		}

		public TelemetryDataFiledHearder(KaitaiStream _io, FrameTlmEntrySat.UiFrameTlmEntrySat _parent,
				FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.spare1 = this._io.readBitsInt(1) != 0;
			this.pusVersion = this._io.readBitsInt(3);
			this.spare2 = this._io.readBitsInt(4);
			this._io.alignToByte();
			this.service = this._io.readU1();
			this.serviceSubtype = this._io.readU1();
			this.time2 = this._io.readBytes(5);
		}

		private boolean spare1;
		private long pusVersion;
		private long spare2;
		private int service;
		private int serviceSubtype;
		private byte[] time2;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.UiFrameTlmEntrySat _parent;

		public boolean spare1() {
			return spare1;
		}

		public long pusVersion() {
			return pusVersion;
		}

		public long spare2() {
			return spare2;
		}

		public int service() {
			return service;
		}

		public int serviceSubtype() {
			return serviceSubtype;
		}

		public byte[] time2() {
			return time2;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.UiFrameTlmEntrySat _parent() {
			return _parent;
		}
	}

	public static class TelemetryData extends KaitaiStruct {
		public static TelemetryData fromFile(String fileName) throws IOException {
			return new TelemetryData(new ByteBufferKaitaiStream(fileName));
		}

		public TelemetryData(KaitaiStream _io) {
			this(_io, null, null);
		}

		public TelemetryData(KaitaiStream _io, FrameTlmEntrySat.UiFrameTlmEntrySat _parent) {
			this(_io, _parent, null);
		}

		public TelemetryData(KaitaiStream _io, FrameTlmEntrySat.UiFrameTlmEntrySat _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.sid = this._io.readU1();
			this.modeSafe = this._io.readU1();
			this.epsVbatt = this._io.readU1();
			this.epsBattVcurrent = this._io.readU1();
			this.eps33VCurrent = this._io.readU1();
			this.eps5VCurrent = this._io.readU1();
			this.trxTemp = this._io.readU1();
			this.epsTemp = this._io.readU1();
			this.battTemp = this._io.readU1();
		}

		private int sid;
		private int modeSafe;
		private int epsVbatt;
		private int epsBattVcurrent;
		private int eps33VCurrent;
		private int eps5VCurrent;
		private int trxTemp;
		private int epsTemp;
		private int battTemp;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.UiFrameTlmEntrySat _parent;

		public int sid() {
			return sid;
		}

		/**
		 * Operational status. 0 = Safe mode 1 = Orbital or Entry mode
		 */
		public int modeSafe() {
			return modeSafe;
		}

		/**
		 * Battery voltage in V formulae ð?‘¦ = 3 + 0.05Ã—ð??Š
		 */
		public int epsVbatt() {
			return epsVbatt;
		}

		/**
		 * Battery bus current in A formulae ð?‘¦ = âˆ’1 + 0.0078740Ã—ð?‘¥
		 */
		public int epsBattVcurrent() {
			return epsBattVcurrent;
		}

		/**
		 * 3.3V bus current in A formulae ð?‘¦ = 0.025*x
		 */
		public int eps33VCurrent() {
			return eps33VCurrent;
		}

		/**
		 * 5V bus current in A formulae ð?‘¦ = 0.025*x
		 */
		public int eps5VCurrent() {
			return eps5VCurrent;
		}

		/**
		 * Transceiverâ€™s temperature in Â°C formulae ð?‘¦ = âˆ’15 + 0.25Ã—ð?‘¥
		 */
		public int trxTemp() {
			return trxTemp;
		}

		/**
		 * Power systemâ€™s temperature Â°C formulae ð?‘¦ = âˆ’15 + 0.25Ã—ð?‘¥
		 */
		public int epsTemp() {
			return epsTemp;
		}

		/**
		 * Batteries temperature in Â°C formulae ð?‘¦ = âˆ’15 + 0.25Ã—ð?‘¥
		 */
		public int battTemp() {
			return battTemp;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.UiFrameTlmEntrySat _parent() {
			return _parent;
		}
	}

	public static class Packetheader extends KaitaiStruct {
		public static Packetheader fromFile(String fileName) throws IOException {
			return new Packetheader(new ByteBufferKaitaiStream(fileName));
		}

		public Packetheader(KaitaiStream _io) {
			this(_io, null, null);
		}

		public Packetheader(KaitaiStream _io, FrameTlmEntrySat.UiFrameTlmEntrySat _parent) {
			this(_io, _parent, null);
		}

		public Packetheader(KaitaiStream _io, FrameTlmEntrySat.UiFrameTlmEntrySat _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.version = this._io.readBitsInt(3);
			this.packetType = this._io.readBitsInt(1) != 0;
			this.packetFlag = this._io.readBitsInt(1) != 0;
			this.packetApid = this._io.readBitsInt(11);
			this._io.alignToByte();
			this.sequenceControl = this._io.readU2be();
			this.packetLenght = this._io.readU2be();
		}

		private long version;
		private boolean packetType;
		private boolean packetFlag;
		private long packetApid;
		private int sequenceControl;
		private int packetLenght;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.UiFrameTlmEntrySat _parent;

		public long version() {
			return version;
		}

		public boolean packetType() {
			return packetType;
		}

		public boolean packetFlag() {
			return packetFlag;
		}

		public long packetApid() {
			return packetApid;
		}

		public int sequenceControl() {
			return sequenceControl;
		}

		public int packetLenght() {
			return packetLenght;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.UiFrameTlmEntrySat _parent() {
			return _parent;
		}
	}

	public static class DestCallsignRaw extends KaitaiStruct {
		public static DestCallsignRaw fromFile(String fileName) throws IOException {
			return new DestCallsignRaw(new ByteBufferKaitaiStream(fileName));
		}

		public DestCallsignRaw(KaitaiStream _io) {
			this(_io, null, null);
		}

		public DestCallsignRaw(KaitaiStream _io, FrameTlmEntrySat.Ax25Header _parent) {
			this(_io, _parent, null);
		}

		public DestCallsignRaw(KaitaiStream _io, FrameTlmEntrySat.Ax25Header _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this._raw__raw_destCallsignRor = this._io.readBytes(6);
			this._raw_destCallsignRor = KaitaiStream.processRotateLeft(this._raw__raw_destCallsignRor, 8 - (1), 1);
			KaitaiStream _io__raw_destCallsignRor = new ByteBufferKaitaiStream(_raw_destCallsignRor);
			this.destCallsignRor = new DestCallsign(_io__raw_destCallsignRor, this, _root);
		}

		private DestCallsign destCallsignRor;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.Ax25Header _parent;
		private byte[] _raw__raw_destCallsignRor;
		private byte[] _raw_destCallsignRor;

		public DestCallsign destCallsignRor() {
			return destCallsignRor;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.Ax25Header _parent() {
			return _parent;
		}

		public byte[] _raw__raw_destCallsignRor() {
			return _raw__raw_destCallsignRor;
		}

		public byte[] _raw_destCallsignRor() {
			return _raw_destCallsignRor;
		}
	}

	public static class SrcCallsign extends KaitaiStruct {
		public static SrcCallsign fromFile(String fileName) throws IOException {
			return new SrcCallsign(new ByteBufferKaitaiStream(fileName));
		}

		public SrcCallsign(KaitaiStream _io) {
			this(_io, null, null);
		}

		public SrcCallsign(KaitaiStream _io, FrameTlmEntrySat.SrcCallsignRaw _parent) {
			this(_io, _parent, null);
		}

		public SrcCallsign(KaitaiStream _io, FrameTlmEntrySat.SrcCallsignRaw _parent, FrameTlmEntrySat _root) {
			super(_io);
			this._parent = _parent;
			this._root = _root;
			_read();
		}

		private void _read() {
			this.srcCallsign = new String(this._io.readBytes(6), Charset.forName("ASCII"));
		}

		private String srcCallsign;
		private FrameTlmEntrySat _root;
		private FrameTlmEntrySat.SrcCallsignRaw _parent;

		public String srcCallsign() {
			return srcCallsign;
		}

		public FrameTlmEntrySat _root() {
			return _root;
		}

		public FrameTlmEntrySat.SrcCallsignRaw _parent() {
			return _parent;
		}
	}

	private Ax25Frame frameTlmEntrySat;
	private FrameTlmEntrySat _root;
	private KaitaiStruct _parent;

	/**
	 * @see <a href="https://www.tapr.org/pub_ax25.html">Source</a>
	 */
	public Ax25Frame frameTlmEntrySat() {
		return frameTlmEntrySat;
	}

	public FrameTlmEntrySat _root() {
		return _root;
	}

	public KaitaiStruct _parent() {
		return _parent;
	}
}
