Skip to content

Commit

Permalink
BasicFactory.FieldSet
Browse files Browse the repository at this point in the history
  • Loading branch information
JG1VPP committed Jun 2, 2024
1 parent ae8e6a1 commit cb361b8
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 220 deletions.
20 changes: 13 additions & 7 deletions src/main/java/gaas/table/CBinDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
import java.io.InputStream;
import java.util.Arrays;

import qxsl.draft.Band;
import qxsl.draft.Mode;
import qxsl.draft.Qxsl;
import qxsl.model.Item;
import qxsl.model.Node;
import qxsl.table.BasicDecoder;

import gaas.table.CBinFactory.BandEnum;
import gaas.table.CBinFactory.DateTime;
import gaas.table.CBinFactory.ModeEnum;

import static qxsl.table.BasicFactory.FieldSet;

/**
* LG8書式で永続化された交信記録を解読します。
Expand All @@ -29,7 +31,9 @@
*/
public final class CBinDecoder extends BasicDecoder {
private final DataInputStream source;
private DateTime cDTime;
private final FieldSet<Band> bandSet;
private final FieldSet<Mode> modeSet;
private final DateTime chrono;
private int numQSOs;

/**
Expand All @@ -41,7 +45,9 @@ public final class CBinDecoder extends BasicDecoder {
public CBinDecoder(InputStream stream) {
super("cbin");
this.source = new DataInputStream(stream);
this.cDTime = new DateTime();
this.chrono = new DateTime();
this.bandSet = CBinFactory.getBandSet();
this.modeSet = CBinFactory.getModeSet();
}

/**
Expand Down Expand Up @@ -157,7 +163,7 @@ private final String read(int max) throws IOException {
* @throws IOException 読み取りに失敗した場合
*/
private final void time(Node node) throws IOException {
node.set(cDTime.decode(source.readLong()));
node.set(chrono.decode(source.readLong()));
}

/**
Expand Down Expand Up @@ -193,7 +199,7 @@ private final void code(Node node) throws IOException {
* @throws IOException 読み取りに失敗した場合
*/
private final void mode(Node node) throws IOException {
node.set(ModeEnum.forIndex(source.read()).toMode());
node.set(modeSet.valueOf(source.read()));
}

/**
Expand All @@ -205,7 +211,7 @@ private final void mode(Node node) throws IOException {
* @throws IOException 読み取りに失敗した場合
*/
private final void band(Node node) throws IOException {
node.set(BandEnum.forIndex(source.read()).toBand());
node.set(bandSet.valueOf(source.read()));
}

/**
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/gaas/table/CBinEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import qxsl.table.BasicEncoder;
import qxsl.value.Field;

import gaas.table.CBinFactory.BandEnum;
import gaas.table.CBinFactory.DateTime;
import gaas.table.CBinFactory.ModeEnum;

import static qxsl.table.BasicFactory.FieldSet;

/**
* 標準構造の交信記録をLG8書式で永続化します。
Expand All @@ -34,7 +34,9 @@
*/
public final class CBinEncoder extends BasicEncoder {
private final DataOutputStream target;
private final DateTime cDTime;
private final FieldSet<Band> bandSet;
private final FieldSet<Mode> modeSet;
private final DateTime chrono;
private final Set<Name> names;
private Item last;
private int count;
Expand All @@ -48,8 +50,10 @@ public final class CBinEncoder extends BasicEncoder {
public CBinEncoder(OutputStream stream) {
super("cbin");
this.names = new LinkedHashSet<Name>();
this.chrono = new DateTime();
this.target = new DataOutputStream(stream);
this.cDTime = new DateTime();
this.bandSet = CBinFactory.getBandSet();
this.modeSet = CBinFactory.getModeSet();
}

/**
Expand Down Expand Up @@ -195,8 +199,7 @@ private final void names() throws IOException {
* @throws IOException 書き込みに失敗した場合
*/
private final void time(Time time) throws IOException {
if(time == null) target.write(new byte[8]);
else target.writeLong(cDTime.encode(time));
target.writeLong(chrono.encode(time));
}

/**
Expand All @@ -208,9 +211,8 @@ private final void time(Time time) throws IOException {
* @throws IOException 書き込みに失敗した場合
*/
private final void mode(Mode mode) throws IOException {
final var modes = ModeEnum.valueOf(mode);
if(mode == null) target.writeByte(0);
else target.writeByte(modes.ordinal());
else target.writeByte(modeSet.indexOf(mode));
}

/**
Expand All @@ -222,8 +224,7 @@ private final void mode(Mode mode) throws IOException {
* @throws IOException 書き込みに失敗した場合
*/
private final void band(Band band) throws IOException {
final var bands = BandEnum.valueOf(band);
if(bands == null) target.writeByte(0);
else target.writeByte(bands.ordinal());
if(band == null) target.writeByte(0);
else target.writeByte(bandSet.indexOf(band));
}
}
215 changes: 59 additions & 156 deletions src/main/java/gaas/table/CBinFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,173 +63,76 @@ public final TableEncoder encoder(OutputStream os) {
}

/**
* LG8書式の周波数帯の列挙型です
* この書式が対応する周波数帯の集合を返します
*
*
* @author 無線部開発班
* @return 周波数帯の集合
*
* @since 2017/06/12
* @since 2024/06/02
*/
public enum BandEnum {
M1_9 ( 1900),
M3_5 ( 3500),
M7 ( 7000),
M10 ( 10000),
M14 ( 14000),
M18 ( 18000),
M21 ( 21000),
M24 ( 24000),
M28 ( 28000),
M50 ( 50000),
M144 ( 144000),
M430 ( 430000),
M1200( 1200000),
M2400( 2400000),
M5600( 5600000),
G10 ( 10000000),
G24 ( 24000000),
G47 ( 47000000),
G75 ( 75000000),
G77 ( 77000000),
G135 (135000000),
G248 (248000000),
K136 ( 136);

private final Band band;

/**
* 周波数帯を指定して列挙子を生成します。
*
*
* @param kHz 周波数帯
*/
private BandEnum(int kHz) {
this.band = new Band(kHz);
}

@Override
public String toString() {
return band.toString();
}

/**
* この列挙子に対応する周波数帯を返します。
*
*
* @return 周波数帯
*/
public Band toBand() {
return band;
}

/**
* 指定された周波数に対応する列挙子を返します。
*
*
* @param band 周波数
*
* @return 対応する列挙子があれば返す
*/
public static BandEnum valueOf(Band band) {
for(var v: values()) if(v.band.equals(band)) return v;
return null;
}

/**
* 指定された序数に対応する列挙子を返します。
*
*
* @param band 序数
*
* @return 対応する列挙子があれば返す
*/
public static BandEnum forIndex(int band) {
for(var v: values()) if(v.ordinal() == band) return v;
return null;
}
public static final FieldSet<Band> getBandSet() {
final var set = new FieldSet<Band>("bands");
set.add(new Band( 1900));
set.add(new Band( 3500));
set.add(new Band( 7000));
set.add(new Band( 10000));
set.add(new Band( 14000));
set.add(new Band( 18000));
set.add(new Band( 21000));
set.add(new Band( 24000));
set.add(new Band( 28000));
set.add(new Band( 50000));
set.add(new Band( 144000));
set.add(new Band( 430000));
set.add(new Band( 1200000));
set.add(new Band( 2400000));
set.add(new Band( 5600000));
set.add(new Band( 10000000));
set.add(new Band( 24000000));
set.add(new Band( 47000000));
set.add(new Band( 75000000));
set.add(new Band( 77000000));
set.add(new Band(135000000));
set.add(new Band(248000000));
set.add(new Band( 136));
return set;
}

/**
* LG8書式の通信方式の列挙型です
* この書式が対応する通信方式の集合を返します
*
*
* @author 無線部開発班
* @return 通信方式の集合
*
* @since 2017/06/12
* @since 2024/06/02
*/
public enum ModeEnum {
CW ("CW"),
RTTY ("RTTY"),
SSB ("SSB"),
FM ("FM"),
AM ("AM"),
ATV ("ATV"),
SSTV ("SSTV"),
PSK ("PSK"),
GMSK ("GMSK"),
MFSK ("MFSK"),
QPSK ("QPSK"),
FSK ("FSK"),
DSTAR ("D-STAR"),
C4FM ("C4FM"),
JT65 ("JT65"),
JT9 ("JT9"),
ISCAT ("ISCAT"),
FT8 ("FT8"),
JT4 ("JT4"),
QRA64 ("QRA64"),
MSK144 ("MSK144"),
WSPR ("WSPR"),
JTMS ("JTMS"),
FT4 ("FT4");

private final Mode mode;

/**
* 通信方式を指定して列挙子を生成します。
*
*
* @param mode 通信方式
*/
private ModeEnum(String mode) {
this.mode = new Mode(mode);
}

/**
* この列挙子に対応するモードを返します。
*
*
* @return モード
*/
public Mode toMode() {
return mode;
}

/**
* 指定されたモードに対応する列挙子を返します。
*
*
* @param mode モード
*
* @return 対応する列挙子があれば返す
*/
public static ModeEnum valueOf(Mode mode) {
for(var v: values()) if(v.mode.equals(mode)) return v;
return null;
}

/**
* 指定された序数に対応する列挙子を返します。
*
*
* @param mode 序数
*
* @return 対応する列挙子があれば返す
*/
public static ModeEnum forIndex(int mode) {
for(var v: values()) if(v.ordinal() == mode) return v;
return null;
}
public static final FieldSet<Mode> getModeSet() {
final var set = new FieldSet<Mode>("modes");
set.add(new Mode("CW"));
set.add(new Mode("RTTY"));
set.add(new Mode("SSB"));
set.add(new Mode("FM"));
set.add(new Mode("AM"));
set.add(new Mode("ATV"));
set.add(new Mode("SSTV"));
set.add(new Mode("PSK"));
set.add(new Mode("GMSK"));
set.add(new Mode("MFSK"));
set.add(new Mode("QPSK"));
set.add(new Mode("FSK"));
set.add(new Mode("D-STAR"));
set.add(new Mode("C4FM"));
set.add(new Mode("JT65"));
set.add(new Mode("JT9"));
set.add(new Mode("ISCAT"));
set.add(new Mode("FT8"));
set.add(new Mode("JT4"));
set.add(new Mode("QRA64"));
set.add(new Mode("MSK144"));
set.add(new Mode("WSPR"));
set.add(new Mode("JTMS"));
set.add(new Mode("FT4"));
return set;
}

/**
Expand Down
Loading

0 comments on commit cb361b8

Please sign in to comment.