Refactor class naming
This commit is contained in:
parent
01f5c61d4d
commit
f49cc7a483
|
@ -6,3 +6,4 @@
|
|||
*.ear
|
||||
/build/
|
||||
/nbproject/private/
|
||||
/dist/
|
|
@ -53,7 +53,7 @@ javadoc.splitindex=true
|
|||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=cz.jaybee.intelhex.IntelHexParserDemo
|
||||
main.class=cz.jaybee.cli.Hex2bin
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
|
|
|
@ -23,8 +23,13 @@
|
|||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package cz.jaybee.intelhex;
|
||||
package cz.jaybee.cli;
|
||||
|
||||
import cz.jaybee.intelhex.IntelHexException;
|
||||
import cz.jaybee.intelhex.Parser;
|
||||
import cz.jaybee.intelhex.Region;
|
||||
import cz.jaybee.intelhex.listeners.RangeDetector;
|
||||
import cz.jaybee.intelhex.listeners.BinWriter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -37,17 +42,17 @@ import java.util.logging.Logger;
|
|||
*
|
||||
* @author Jan Breuer
|
||||
*/
|
||||
public class IntelHexParserDemo {
|
||||
public class Hex2bin {
|
||||
|
||||
/**
|
||||
* Convert Intel HEX to bin
|
||||
*
|
||||
* usage:
|
||||
*
|
||||
* IntelHexParserDemo {source} {target}
|
||||
* Hex2bin {source} {target}
|
||||
*
|
||||
* Hex2bin {source} {target} {address_from} {address_to}
|
||||
*
|
||||
* IntelHexParserDemo {source} {target} {address_from} {address_to}
|
||||
*
|
||||
* {source} is source Intel HEX file name
|
||||
*
|
||||
* {target} is target BIN file name
|
||||
|
@ -69,7 +74,7 @@ public class IntelHexParserDemo {
|
|||
|
||||
if (args.length == 0) {
|
||||
System.out.println("usage:");
|
||||
System.out.println(" hex2bin <hex> <bin> <start address> <end address> [minimize]");
|
||||
System.out.println(" hex2bin <hex> <bin> <start address> <end address> [minimize]");
|
||||
System.out.println();
|
||||
System.out.println(" full address range of app.hex");
|
||||
System.out.println(" hex2bin app.hex app.bin");
|
||||
|
@ -82,7 +87,7 @@ public class IntelHexParserDemo {
|
|||
System.out.println(" hex2bin app.hex app.bin 0x0000 0x1fff minimize");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (args.length >= 1) {
|
||||
fileIn = args[0];
|
||||
}
|
||||
|
@ -98,8 +103,8 @@ public class IntelHexParserDemo {
|
|||
if (args.length >= 4) {
|
||||
dataTo = args[3];
|
||||
}
|
||||
|
||||
if (args.length >=5 ) {
|
||||
|
||||
if (args.length >= 5) {
|
||||
if (args[4].equals("minimize")) {
|
||||
minimize = true;
|
||||
}
|
||||
|
@ -108,19 +113,19 @@ public class IntelHexParserDemo {
|
|||
try (FileInputStream is = new FileInputStream(fileIn)) {
|
||||
OutputStream os = new FileOutputStream(fileOut);
|
||||
// init parser
|
||||
IntelHexParser parser = new IntelHexParser(is);
|
||||
Parser parser = new Parser(is);
|
||||
|
||||
// 1st iteration - calculate maximum output range
|
||||
// 1st iteration - calculate maximum output range
|
||||
RangeDetector rangeDetector = new RangeDetector();
|
||||
parser.setDataListener(rangeDetector);
|
||||
parser.parse();
|
||||
is.getChannel().position(0);
|
||||
Region outputRegion = rangeDetector.getFullRangeRegion();
|
||||
|
||||
|
||||
// if address parameter is "max", calculate maximum memory region
|
||||
if (!("min".equals(dataFrom))) {
|
||||
outputRegion.setAddressStart(Long.parseLong(dataFrom.substring(2), 16));
|
||||
}
|
||||
}
|
||||
if (!("max".equals(dataTo))) {
|
||||
outputRegion.setAddressEnd(Long.parseLong(dataTo.substring(2), 16));
|
||||
}
|
||||
|
@ -137,10 +142,9 @@ public class IntelHexParserDemo {
|
|||
|
||||
System.out.print("Written output: ");
|
||||
System.out.println(outputRegion);
|
||||
|
||||
|
||||
} catch (IntelHexException | IOException ex) {
|
||||
Logger.getLogger(IntelHexParserDemo.class.getName()).log(Level.SEVERE, null, ex);
|
||||
Logger.getLogger(Hex2bin.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ package cz.jaybee.intelhex;
|
|||
*
|
||||
* @author Jan Breuer
|
||||
*/
|
||||
public interface IntelHexDataListener {
|
||||
public interface DataListener {
|
||||
|
||||
/**
|
||||
* Every time new data are read from file, this listener method is called
|
|
@ -34,10 +34,10 @@ import java.io.*;
|
|||
* @author Kristian Sloth Lauszus
|
||||
* @author riilabs
|
||||
*/
|
||||
public class IntelHexParser {
|
||||
public class Parser {
|
||||
|
||||
private final BufferedReader reader;
|
||||
private IntelHexDataListener dataListener = null;
|
||||
private DataListener dataListener = null;
|
||||
private static final int HEX = 16;
|
||||
private boolean eof = false;
|
||||
private int recordIdx = 0;
|
||||
|
@ -51,7 +51,7 @@ public class IntelHexParser {
|
|||
|
||||
int length;
|
||||
int address;
|
||||
IntelHexRecordType type;
|
||||
RecordType type;
|
||||
byte[] data;
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,7 @@ public class IntelHexParser {
|
|||
*
|
||||
* @param reader
|
||||
*/
|
||||
public IntelHexParser(Reader reader) {
|
||||
public Parser(Reader reader) {
|
||||
this.reader = (reader instanceof BufferedReader) ? (BufferedReader) reader : new BufferedReader(reader);
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class IntelHexParser {
|
|||
*
|
||||
* @param stream
|
||||
*/
|
||||
public IntelHexParser(InputStream stream) {
|
||||
public Parser(InputStream stream) {
|
||||
this.reader = new BufferedReader(new InputStreamReader(stream));
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class IntelHexParser {
|
|||
*
|
||||
* @param listener
|
||||
*/
|
||||
public void setDataListener(IntelHexDataListener listener) {
|
||||
public void setDataListener(DataListener listener) {
|
||||
this.dataListener = listener;
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,8 @@ public class IntelHexParser {
|
|||
result.address = ((hexRecord[1] & 0xFF) << 8) + (hexRecord[2] & 0xFF);
|
||||
|
||||
// determine record type
|
||||
result.type = IntelHexRecordType.fromInt(hexRecord[3] & 0xFF);
|
||||
if (result.type == IntelHexRecordType.UNKNOWN) {
|
||||
result.type = RecordType.fromInt(hexRecord[3] & 0xFF);
|
||||
if (result.type == RecordType.UNKNOWN) {
|
||||
throw new IntelHexException("Unsupported record type " + (hexRecord[3] & 0xFF) + " (" + recordIdx + ")");
|
||||
}
|
||||
|
||||
|
@ -219,6 +219,7 @@ public class IntelHexParser {
|
|||
} else {
|
||||
throw new IntelHexException("Invalid START_SEG record at line #" + recordIdx + " " + record);
|
||||
}
|
||||
break;
|
||||
case UNKNOWN:
|
||||
break;
|
||||
}
|
|
@ -30,7 +30,7 @@ package cz.jaybee.intelhex;
|
|||
*
|
||||
* @author Jan Breuer
|
||||
*/
|
||||
public enum IntelHexRecordType {
|
||||
public enum RecordType {
|
||||
|
||||
DATA(0x00),
|
||||
EOF(0x01),
|
||||
|
@ -41,7 +41,7 @@ public enum IntelHexRecordType {
|
|||
UNKNOWN(0xFF);
|
||||
int id;
|
||||
|
||||
IntelHexRecordType(int id) {
|
||||
RecordType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
@ -60,12 +60,12 @@ public enum IntelHexRecordType {
|
|||
* @param id record type integer value
|
||||
* @return record type enum value
|
||||
*/
|
||||
public static IntelHexRecordType fromInt(int id) {
|
||||
for (IntelHexRecordType d : IntelHexRecordType.values()) {
|
||||
public static RecordType fromInt(int id) {
|
||||
for (RecordType d : RecordType.values()) {
|
||||
if (d.id == id) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return IntelHexRecordType.UNKNOWN;
|
||||
return RecordType.UNKNOWN;
|
||||
}
|
||||
}
|
|
@ -23,8 +23,11 @@
|
|||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package cz.jaybee.intelhex;
|
||||
package cz.jaybee.intelhex.listeners;
|
||||
|
||||
import cz.jaybee.intelhex.DataListener;
|
||||
import cz.jaybee.intelhex.MemoryRegions;
|
||||
import cz.jaybee.intelhex.Region;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
@ -36,7 +39,7 @@ import java.util.logging.Logger;
|
|||
*
|
||||
* @author Jan Breuer
|
||||
*/
|
||||
public class BinWriter implements IntelHexDataListener {
|
||||
public class BinWriter implements DataListener {
|
||||
|
||||
private final Region outputRegion;
|
||||
private final OutputStream destination;
|
|
@ -23,7 +23,11 @@
|
|||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package cz.jaybee.intelhex;
|
||||
package cz.jaybee.intelhex.listeners;
|
||||
|
||||
import cz.jaybee.intelhex.DataListener;
|
||||
import cz.jaybee.intelhex.MemoryRegions;
|
||||
import cz.jaybee.intelhex.Region;
|
||||
|
||||
/**
|
||||
* First pass listener to calculate data address range for further use
|
||||
|
@ -31,7 +35,7 @@ package cz.jaybee.intelhex;
|
|||
* @author riilabs
|
||||
* @author Jan Breuer
|
||||
*/
|
||||
public class RangeDetector implements IntelHexDataListener {
|
||||
public class RangeDetector implements DataListener {
|
||||
|
||||
private final MemoryRegions regions = new MemoryRegions();
|
||||
|
Loading…
Reference in New Issue