/* $Id$ */

#pragma once

#include <string>
#include <inttypes.h>

namespace Chan
{
	struct SBin
	{
		uint8_t name[6];
		uint8_t rfreq[4], tfreq[4];
		uint8_t rctc[2], tctc[2];
		uint8_t busylock;
		uint8_t txmode;
		uint8_t dunno[2];
	};

	struct SCsv
	{
		std::string name;
		std::string rfreq, tfreq;
		std::string rctc, tctc;
		std::string busylock;
		std::string txmode;
		std::string dunno;
	};

	std::string GetName(const uint8_t *data);
	std::string GetFreq(const uint8_t *data);
	std::string GetCTCSS(const uint8_t *data);
	std::string GetBusyLock(const uint8_t &data);
	std::string GetTXMode(const uint8_t &data);
	std::string GetDunno(const uint8_t *data);

	void SetName(uint8_t *out, const std::string &in);
	void SetFreq(uint8_t *out, const std::string &in);
	void SetCTCSS(uint8_t *out, const std::string &in);
	void SetBusyLock(uint8_t *out, const std::string &in);
	void SetTXMode(uint8_t *out, const std::string &in);
	void SetDunno(uint8_t *out, const std::string &in);

	void BufToBin(SBin &bin, const unsigned char *data);
	void BinToCsv(SCsv &csv, const SBin &bin);
	void CsvToString(std::string &s, const SCsv &csv, size_t i);

	void StringToCsv(SCsv &csv, const std::string &s);
	void CsvToBin(SBin &bin, const SCsv &csv);
	void BinToBuf(unsigned char *buf, const SBin &bin);
};
