module Trx {

	typedef unsigned long long frequency;
	typedef float signalstrength;

	struct TrxBandDescription {
		frequency low;  /* lower band edge */
		frequency high; /* upper band edge */
		frequency step; /* step size */
	};

	struct TrxDescription {
		string  manufacturer;    /* transceiver manufacturer */
		string  model;           /* model number */
		string  copyright;
		string  instid;          /* serial number or similar */
		sequence <TrxBandDescription>  rxbands;
		sequence <TrxBandDescription>  txbands;
		signalstrength rssimin;
		signalstrength rssimax;
	};

	enum TrxMode {
		trxunspec, trxpacket, trxaudio
	};

	struct TrxState {
		TrxMode mode;
		frequency rxfreq;
		frequency txfreq;
		boolean ptt;
		boolean manualptt;
		boolean dcd;
		signalstrength rssi;
	};

	enum BaycomUSBAdapterMode {
		fsk, external, afsk, audio
	};

	enum BaycomUSBAdapterLoopback {
		loopback_off, loopback_scrambler, loopback_modem
	};

	typedef char BaycomUSBAdapterAudioDev[64];

	struct BaycomUSBAdapterConfig {
		BaycomUSBAdapterMode mode;
		unsigned long fclk;
		unsigned long bitraterx;
		unsigned long bitratetx;
		BaycomUSBAdapterLoopback loopback;
		boolean pttmute;
		unsigned long filtmode;
		/* audio stuff */
		unsigned long samplerate;
		float gain;
		BaycomUSBAdapterAudioDev audiodevin;
		BaycomUSBAdapterAudioDev audiodevout;
		signalstrength rfsquelch;
		boolean audiosquelch;
	};

	typedef sequence<BaycomUSBAdapterAudioDev> BaycomUSBAdapterAudioDevSequence;

	struct BaycomUSBAdapterAudioDevs {
		BaycomUSBAdapterAudioDevSequence audiodevsin;
		BaycomUSBAdapterAudioDevSequence audiodevsout;
	};

	struct ChannelAccessConfig {
		unsigned long txdelay;
		unsigned long slottime;
		unsigned long ppersistence;
		unsigned long txtail;
		boolean fullduplex;
	};

	typedef octet IpAddress[4];

	struct InterfaceConfig {
		char ifname[16];
                char hwaddr[16];
                IpAddress ipaddr;
                IpAddress netmask;
                IpAddress broadcast;
		char gwhwaddr[128];
		IpAddress gwipaddr;
		IpAddress gwnetmask;
		char gwipmode;
	};

	enum ModemDisconnectRxC {
		mdisc_rxc_normal, mdisc_rxc_rxclock
	};

	enum ModemDisconnectTxC {
		mdisc_txc_normal, mdisc_txc_txclock
	};

	enum ModemDisconnectTxD {
		mdisc_txd_normal, mdisc_txd_txdata
	};

	struct ModemDisconnectConfig {
		unsigned long output;
		unsigned long direction;
		ModemDisconnectRxC rxc;
		ModemDisconnectTxC txc;
		ModemDisconnectTxD txd;
	};

	struct TrxAudioState {
		unsigned long samplerate;
		unsigned long micbufsz;
		unsigned long micbufptr;
		unsigned long spkbufsz;
		unsigned long spkbufptr;
		float micsigpwr;
		float spksigpwr;
		float spknoisepwr;
	};

	typedef sequence<octet> TrxAudioSamples;

	struct TrxAudioParams {
		signalstrength rfsquelch;
		boolean audiosquelch;
	};

	exception TrxError {
		string reason;
	};

	interface Control {
		void GetDescription(out TrxDescription desc);
		void GetState(out TrxState state) raises (TrxError);
		void SetPTT(in boolean ptt) raises (TrxError);
		oneway void SetFrequency(in frequency rx, in frequency tx) raises (TrxError);

		/* Raw UART */
		oneway void UartSend(in string str) raises (TrxError);
		void UartReceive(inout unsigned long ptr, out string str) raises (TrxError);

		/* Configuration stuff */
		void BaycomUSBAdapterGetConfig(out BaycomUSBAdapterConfig cfg) raises (TrxError);
		void BaycomUSBAdapterSetConfig(in BaycomUSBAdapterConfig cfg) raises (TrxError);
		void BaycomUSBAdapterGetAudioDevices(out BaycomUSBAdapterAudioDevs devs) raises (TrxError);

		void ChannelAccessGetConfig(out ChannelAccessConfig cfg) raises (TrxError);
		void ChannelAccessSetConfig(in ChannelAccessConfig cfg) raises (TrxError);
		
		void InterfaceGetConfig(out InterfaceConfig cfg) raises (TrxError);
		void InterfaceSetConfig(in InterfaceConfig cfg) raises (TrxError);

		void ModemDisconnectGetConfig(out ModemDisconnectConfig cfg) raises (TrxError);
		void ModemDisconnectSetConfig(in ModemDisconnectConfig cfg) raises (TrxError);

		/* Audio Stuff */
		void GetAudioState(out TrxAudioState state) raises (TrxError);
		void GetAudioMicSamples(in unsigned long ptr, in unsigned long len, out TrxAudioSamples samples) raises (TrxError);
		void GetAudioSpkSamples(in unsigned long ptr, in unsigned long len, out TrxAudioSamples samples) raises (TrxError);
		void SetAudioDTMF(in long ch) raises (TrxError);
		void SetAudioParams(in TrxAudioParams params);
	};
};
