| 
					
				 | 
			
			
				@@ -26,15 +26,14 @@ 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.ButtonData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import de.mcs.tools.midicontroller.data.EventData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import de.mcs.tools.midicontroller.data.ProgramData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import de.mcs.tools.sps.utils.IntelHex; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import de.mcs.utils.Files; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import de.mcs.utils.JacksonUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -43,65 +42,125 @@ import de.mcs.utils.JacksonUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param args 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public static void main(String[] args) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        out.write((byte) programData.getInternalMidi()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        out.write((byte) programData.getExternalMidi()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        byte switchSettings = 0x00; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if ((programData.getButtons() != null) && (programData.getButtons().length > 2)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          for (int i = 0; i < programData.getButtons().length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            byte[] buttonName = getEmptyByteArray(8); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ButtonData buttonData = programData.getButtons()[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (i < 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              buttonName = copyInto(buttonName, getStringAsByte(buttonData.getName(), 8)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              out.write(buttonName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (ButtonData.TYPE.SWITCH.equals(buttonData.getType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              switchSettings = (byte) (switchSettings | (0x01 << i)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          throw new Exception("buttons not correct configured."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        out.write(switchSettings); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 15; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          byte[] data = getEmptyByteArray(33); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          if ((programData.getEvents() != null) && (programData.getEvents().length > i)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int eventTyp = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            EventData eventData = programData.getEvents()[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            switch (eventData.getType()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case INTERNAL: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              eventTyp = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case EXPRESSION: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              eventTyp = 0xE0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case BUTTON: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              eventTyp = 0x20 * (eventData.getValue() + 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            eventTyp = eventTyp | eventData.getEvent().ordinal(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data[0] = (byte) (eventTyp & 0xFF); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          out.write(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		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(0xFF); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      out.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      byte[] outBytes = out.toByteArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      StringBuilder b1 = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      StringBuilder b2 = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      StringBuilder b3 = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      for (int i = 0; i < outBytes.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        byte myByte = outBytes[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if ((myByte & 0xFF) == 0xFF) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b1.append(String.format("    ", (char) myByte)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b1.append(String.format("  %1s ", (char) myByte)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        b2.append(String.format(" %2x,", myByte)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (((i + 1) % 8) == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b3.append(b1.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b3.append("\r\n"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b3.append(b2.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b3.append("\r\n"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b1 = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          b2 = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      System.out.println(b3.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      File text = new File("programData.txt"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      Files.writeStringToFile(text, b3.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				out.write(name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      System.out.printf("The file has %d bytes.\r\n", outBytes.length); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				out.write((byte) programData.getPrgNumber()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      File dest = new File("programData.hex"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      try (BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(dest))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        IntelHex intelHex = new IntelHex(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        intelHex.writeHexStream(output, outBytes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				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[] 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[] 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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private static byte[] copyInto(byte[] dest, byte[] source) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (int i = 0; i < source.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      dest[i] = source[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return dest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |