package ru.r2cloud.jradio.quetzal1;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

import ru.r2cloud.jradio.Beacon;
import ru.r2cloud.jradio.ax25.Header;
import ru.r2cloud.jradio.fec.ccsds.UncorrectableException;

public class Quetzal1Beacon extends Beacon {

	private Header ax25Header;
	private ru.r2cloud.jradio.csp.Header cspHeader;
	private Telemetry telemetry;
	private byte[] unknownPayload;

	@Override
	public void readBeacon(byte[] data) throws IOException, UncorrectableException {
		DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));
		ax25Header = new Header(dis);
		cspHeader = new ru.r2cloud.jradio.csp.Header(dis);
		if (dis.available() == 137) {
			telemetry = new Telemetry(dis);
		} else {
			unknownPayload = new byte[dis.available()];
			dis.readFully(unknownPayload);
		}
	}

	public Header getAx25Header() {
		return ax25Header;
	}

	public void setAx25Header(Header ax25Header) {
		this.ax25Header = ax25Header;
	}

	public ru.r2cloud.jradio.csp.Header getCspHeader() {
		return cspHeader;
	}

	public void setCspHeader(ru.r2cloud.jradio.csp.Header cspHeader) {
		this.cspHeader = cspHeader;
	}

	public Telemetry getTelemetry() {
		return telemetry;
	}

	public void setTelemetry(Telemetry telemetry) {
		this.telemetry = telemetry;
	}

	public byte[] getUnknownPayload() {
		return unknownPayload;
	}

	public void setUnknownPayload(byte[] unknownPayload) {
		this.unknownPayload = unknownPayload;
	}

}

@@ -428,30 +428,150 @@
  byte%5B%5D 
-unknownPayload
+ackPayload;%0A%09private byte%5B%5D imagePayload;%0A%09private byte%5B%5D unknownPayload;%0A%09private RamParams ramParams;%0A%09private RamParams flashParams
 ;%0A%0A%09@Ove
@@ -887,16 +887,352 @@
 y(dis);%0A
+%09%09%7D else if (dis.available() == 232) %7B%0A%09%09%09imagePayload = new byte%5Bdis.available()%5D;%0A%09%09%09dis.readFully(imagePayload);%0A%09%09%7D else if (dis.available() == 2) %7B%0A%09%09%09ackPayload = new byte%5Bdis.available()%5D;%0A%09%09%09dis.readFully(ackPayload);%0A%09%09%7D else if (dis.available() == 44) %7B%0A%09%09%09ramParams = new RamParams(dis);%0A%09%09%09flashParams = new RamParams(dis);%0A
 %09%09%7D else
@@ -1905,24 +1905,24 @@
 nPayload) %7B%0A
-
 %09%09this.unkno
@@ -1953,10 +1953,602 @@
 ad;%0A%09%7D%0A%0A
+%09public byte%5B%5D getAckPayload() %7B%0A%09%09return ackPayload;%0A%09%7D%0A%0A%09public void setAckPayload(byte%5B%5D ackPayload) %7B%0A%09%09this.ackPayload = ackPayload;%0A%09%7D%0A%0A%09public byte%5B%5D getImagePayload() %7B%0A%09%09return imagePayload;%0A%09%7D%0A%0A%09public void setImagePayload(byte%5B%5D imagePayload) %7B%0A%09%09this.imagePayload = imagePayload;%0A%09%7D%0A%0A%09public RamParams getRamParams() %7B%0A%09%09return ramParams;%0A%09%7D%0A%0A%09public void setRamParams(RamParams ramParams) %7B%0A%09%09this.ramParams = ramParams;%0A%09%7D%0A%0A%09public RamParams getFlashParams() %7B%0A%09%09return flashParams;%0A%09%7D%0A%0A%09public void setFlashParams(RamParams flashParams) %7B%0A%09%09this.flashParams = flashParams;%0A%09%7D%0A%0A
 %7D%0A

add support for other frame types