Sfoglia il codice sorgente

new main class for converting data for the mc03

Willie 6 anni fa
parent
commit
cbc8f9138f

+ 1 - 2
.classpath

@@ -24,9 +24,8 @@
 			<attribute name="maven.pomderived" value="true"/>
 		</attributes>
 	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-11.0.1">
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
 		<attributes>
-			<attribute name="module" value="true"/>
 			<attribute name="maven.pomderived" value="true"/>
 		</attributes>
 	</classpathentry>

+ 107 - 0
src/main/java/de/mcs/tools/midicontroller/ConvertJsonData2Hex.java

@@ -0,0 +1,107 @@
+/**
+ * MCS Media Computer Software
+ * <one line to give the program's name and a brief idea of what it does.>
+ * Copyright (C) 2018 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: ConvertJsonData2Hex.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 24.12.2018 wklaa
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.midicontroller;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+import de.mcs.tools.midicontroller.data.ProgramData;
+import de.mcs.tools.sps.utils.IntelHex;
+import de.mcs.utils.JacksonUtils;
+
+/**
+ * @author wklaa
+ *
+ */
+public class ConvertJsonData2Hex {
+
+	/**
+	 * @param args
+	 * @throws IOException
+	 * @throws JsonMappingException
+	 * @throws JsonParseException
+	 */
+	public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
+		InputStream source = ClassLoader.getSystemResourceAsStream("programdata.json");
+		ProgramData[] programDatas = JacksonUtils.getJsonMapper().readValue(source, ProgramData[].class);
+
+		try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+			for (ProgramData programData : programDatas) {
+				System.out.println(programData.toString());
+				byte[] name = copyInto(getEmptyByteArray(12), getStringAsByte(programData.getName(), 12));
+
+				out.write(name);
+
+				out.write((byte) programData.getPrgNumber());
+
+				for (int i = 0; i < 3; i++) {
+					byte[] button = getEmptyByteArray(8);
+					if ((programData.getButtons() != null) && (i < programData.getButtons().length)) {
+						button = copyInto(button, getStringAsByte(programData.getButtons()[i].getName(), 8));
+					}
+					out.write(button);
+				}
+				out.write(0xFF);
+			}
+			out.close();
+			byte[] outBytes = out.toByteArray();
+			System.out.printf("The file has %d bytes.\r\n", outBytes.length);
+			File dest = new File("programData.hex");
+			try (BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(dest))) {
+				IntelHex intelHex = new IntelHex();
+				intelHex.writeHexStream(output, outBytes);
+			}
+		}
+	}
+
+	private static byte[] getStringAsByte(String value, int count) throws UnsupportedEncodingException {
+		String newValue = value;
+		if (newValue.length() > count) {
+			newValue = newValue.substring(0, count);
+		}
+		return newValue.getBytes("US-ASCII");
+	}
+
+	private static byte[] getEmptyByteArray(int count) {
+		byte[] value = new byte[count];
+		for (int i = 0; i < value.length; i++) {
+			value[i] = 0;
+		}
+		return value;
+	}
+
+	private static byte[] copyInto(byte[] dest, byte[] source) {
+		for (int i = 0; i < source.length; i++) {
+			dest[i] = source[i];
+		}
+		return dest;
+	}
+}

+ 57 - 0
src/main/java/de/mcs/tools/midicontroller/data/ButtonData.java

@@ -0,0 +1,57 @@
+/**
+ * MCS Media Computer Software
+ * <one line to give the program's name and a brief idea of what it does.>
+ * Copyright (C) 2018 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: ButtonData.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 24.12.2018 wklaa
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.midicontroller.data;
+
+/**
+ * @author wklaa
+ *
+ */
+public class ButtonData {
+	enum TYPE {
+		SWITCH, MOMENTARY
+	}
+
+	private String name;
+	private TYPE type;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public TYPE getType() {
+		return type;
+	}
+
+	public void setType(TYPE type) {
+		this.type = type;
+	}
+
+	@Override
+	public String toString() {
+		return String.format("Button[name: %s, type: %s]", name, type.name());
+	}
+}

+ 80 - 0
src/main/java/de/mcs/tools/midicontroller/data/DataData.java

@@ -0,0 +1,80 @@
+/**
+ * MCS Media Computer Software
+ * <one line to give the program's name and a brief idea of what it does.>
+ * Copyright (C) 2018 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: DataData.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 24.12.2018 wklaa
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.midicontroller.data;
+
+/**
+ * @author wklaa
+ *
+ */
+public class DataData {
+
+	enum CHANNEL {
+		INTERNAL, EXTERNAL
+	}
+
+	enum TYPE {
+		CC, PC
+	}
+
+	private CHANNEL channel;
+	private TYPE type;
+	private int data1;
+	private int data2;
+
+	public CHANNEL getChannel() {
+		return channel;
+	}
+
+	public void setChannel(CHANNEL channel) {
+		this.channel = channel;
+	}
+
+	public TYPE getType() {
+		return type;
+	}
+
+	public void setType(TYPE type) {
+		this.type = type;
+	}
+
+	public int getData1() {
+		return data1;
+	}
+
+	public void setData1(int data1) {
+		this.data1 = data1;
+	}
+
+	public int getData2() {
+		return data2;
+	}
+
+	public void setData2(int data2) {
+		this.data2 = data2;
+	}
+
+	@Override
+	public String toString() {
+		return String.format("data[channel: %s, type: %s, data1: %d, data2: %d]", channel.name(), type.name(), data1, data2);
+	}
+}

+ 84 - 0
src/main/java/de/mcs/tools/midicontroller/data/EventData.java

@@ -0,0 +1,84 @@
+/**
+ * MCS Media Computer Software
+ * <one line to give the program's name and a brief idea of what it does.>
+ * Copyright (C) 2018 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: EventData.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 24.12.2018 wklaa
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.midicontroller.data;
+
+import java.util.Arrays;
+
+/**
+ * @author wklaa
+ *
+ */
+public class EventData {
+	enum EVENTTYPE {
+		INTERNAL, BUTTON, EXPRESSION
+	};
+
+	enum EVENT {
+		START, STOP, PUSH, RELEASE, CLICK, DOUBLECLICK, LONGCLICK, VALUECHANGE, CC
+	}
+
+	private EVENTTYPE type;
+
+	private EVENT event;
+
+	private int value;
+
+	private DataData[] datas;
+
+	@Override
+	public String toString() {
+		return String.format("Event[ type: %s, event: %s, value: %d, datas: %s]", type.name(), event.name(), value, Arrays.toString(datas));
+	}
+
+	public EVENTTYPE getType() {
+		return type;
+	}
+
+	public void setType(EVENTTYPE type) {
+		this.type = type;
+	}
+
+	public EVENT getEvent() {
+		return event;
+	}
+
+	public void setEvent(EVENT event) {
+		this.event = event;
+	}
+
+	public DataData[] getDatas() {
+		return datas;
+	}
+
+	public void setDatas(DataData[] datas) {
+		this.datas = datas;
+	}
+
+	public int getValue() {
+		return value;
+	}
+
+	public void setValue(int value) {
+		this.value = value;
+	}
+}

+ 73 - 0
src/main/java/de/mcs/tools/midicontroller/data/ProgramData.java

@@ -0,0 +1,73 @@
+/**
+ * MCS Media Computer Software
+ * <one line to give the program's name and a brief idea of what it does.>
+ * Copyright (C) 2018 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: ProgramData.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 24.12.2018 wklaa
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.midicontroller.data;
+
+import java.util.Arrays;
+
+/**
+ * @author wklaa
+ *
+ */
+public class ProgramData {
+	private String name;
+	private int prgNumber;
+	private ButtonData[] buttons;
+	private EventData[] events;
+
+	@Override
+	public String toString() {
+		return String.format("PRG[name: %s, prgNumber: %d, buttons: %s, events: %s]", name, prgNumber, Arrays.toString(buttons), Arrays.toString(events));
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public int getPrgNumber() {
+		return prgNumber;
+	}
+
+	public void setPrgNumber(int prgNumber) {
+		this.prgNumber = prgNumber;
+	}
+
+	public ButtonData[] getButtons() {
+		return buttons;
+	}
+
+	public void setButtons(ButtonData[] buttons) {
+		this.buttons = buttons;
+	}
+
+	public EventData[] getEvents() {
+		return events;
+	}
+
+	public void setEvents(EventData[] events) {
+		this.events = events;
+	}
+}

+ 3 - 1
src/main/java/de/mcs/tools/sps/utils/IntelHex.java

@@ -65,7 +65,9 @@ public class IntelHex {
 				crc += data[i];
 				address++;
 			}
-			writeCRC(crc, writer);
+			if (data.length > 0) {
+				writeCRC(crc, writer);
+			}
 			crc = 0;
 			writer.append(':');
 			writer.append(String.format("%02X", 0));

+ 56 - 0
src/main/java/de/mcs/utils/JacksonUtils.java

@@ -0,0 +1,56 @@
+package de.mcs.utils;
+/**
+ * 
+ */
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+
+/**
+ * @author wklaa_000
+ *
+ */
+public class JacksonUtils {
+
+  private static ObjectMapper ymlObjectMapper;
+
+  public static ObjectMapper getYmlMapper() {
+    if (ymlObjectMapper == null) {
+      ymlObjectMapper = new ObjectMapper(new YAMLFactory());
+      ymlObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+      ymlObjectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
+      ymlObjectMapper.setSerializationInclusion(Include.NON_NULL);
+    }
+    return ymlObjectMapper;
+  }
+
+  private static ObjectMapper jsonObjectMapper;
+
+  public static ObjectMapper getJsonMapper() {
+    if (jsonObjectMapper == null) {
+      jsonObjectMapper = new ObjectMapper();
+      jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+      jsonObjectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
+      jsonObjectMapper.setSerializationInclusion(Include.NON_NULL);
+    }
+    return jsonObjectMapper;
+  }
+
+  private static class StringMessage {
+    @JsonProperty
+    private String message;
+
+    public StringMessage(String message) {
+      this.message = message;
+    }
+  }
+
+  public static String messageToJson(String message) throws JsonProcessingException {
+    return getJsonMapper().writeValueAsString(new StringMessage(message));
+  }
+}

+ 37 - 15
src/main/resources/programdata.json

@@ -1,21 +1,27 @@
 [{
 		"name": "Rock",
 		"prgNumber": 100,
-		"button": [{
+		"buttons": [{
 				"name": "EQ0",
-				"type": "switch"
+				"type": "SWITCH"
 			}, {
 				"name": "Drv0",
-				"type": "switch"
+				"type": "SWITCH"
 			}, {
 				"name": "Chr0",
-				"type": "momentary"
+				"type": "MOMENTARY"
+			}, {
+				"type": "SWITCH"
+			}, {
+				"type": "SWITCH"
+			}, {
+				"type": "MOMENTARY"
 			}
 		],
 		"events": [{
 				"type": "INTERNAL",
-				"event": "START"
-				"data": [{
+				"event": "START",
+				"datas": [{
 						"channel": "INTERNAL",
 						"type": "CC",
 						"data1": 8,
@@ -32,34 +38,50 @@
                         "data2" : 3
 					}
 				]
-			},
+			},{
+				"type": "BUTTON",
+                "value": 1,
+				"event": "CLICK",
+				"datas": [{
+						"channel": "EXTERNAL",
+						"type": "CC",
+						"data1": 9,
+                        "data2" : 127
+					},{
+						"channel": "EXTERNAL",
+						"type": "CC",
+						"data1": 10,
+                        "data2" : 0
+					}
+				]
+			}
 		]
 	}, {
 		"name": "Pop",
 		"prgNumber": 0,
-		"button": [{
+		"buttons": [{
 				"name": "EQ0",
-				"type": "switch"
+				"type": "SWITCH"
 			}, {
 				"name": "Drv0",
-				"type": "momentary"
+				"type": "MOMENTARY"
 			}, {
 				"name": "Chr0",
-				"type": "switch"
+				"type": "SWITCH"
 			}
 		]
 	}, {
 		"name": "Soul",
 		"prgNumber": -1,
-		"button": [{
+		"buttons": [{
 				"name": "EQ0",
-				"type": "momentary"
+				"type": "MOMENTARY"
 			}, {
 				"name": "Drv0",
-				"type": "switch"
+				"type": "SWITCH"
 			}, {
 				"name": "Chr0",
-				"type": "switch"
+				"type": "SWITCH"
 			}
 		]
 	}