Class HexFile
- java.lang.Object
-
- jmri.jmrix.can.cbus.swing.bootloader.HexFile
-
- Direct Known Subclasses:
CbusPicHexFile
public class HexFile extends java.lang.Object
Class to encapsulate an intel format hex file for a CBUS PIC. Assumes hex record addresses are 8-byte aligned and that addresses increase monotonically.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
address
protected java.io.BufferedInputStream
buffIn
protected int
endRecord
protected java.io.File
file
protected HexRecord[]
hexRecords
protected java.io.FileInputStream
in
protected int
lineNo
protected static int
MAX_HEX_SIZE
protected java.lang.String
name
protected boolean
read
protected int
readIndex
-
Constructor Summary
Constructors Constructor Description HexFile(java.lang.String fileName)
Create a new HexFile object and initialize data to unprogrammed state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkRecord(HexRecord r)
DProcess record if requiredvoid
close()
Close the currently open file.void
dispose()
close the open fileint
getAddress()
Get current address.int
getLineNo()
Get current file line numberjava.lang.String
getName()
HexRecord
getNextRecord()
Return the next TYPE_DATA record from the fileCbusParameters
getParams()
Get the file parameters Create an invalid parameter set of necessary.int
getProgEnd()
Return the highest address read from the hex fileint
getProgStart()
Return the lowest address read from the hex filejava.util.Optional<HexRecord>
getRecordForAddress(int addr)
Get the hex record for a given address Expected that the address will be the start address of a record but will return the first record that encompasses the address and increment the index to point at the next record.void
openRd()
Open hex file for reading.int
rdHexByte()
Read a hex byte.void
read()
Read a hex file.int
readChar()
Read a character from the hex fileprotected HexRecord
readOneRecord()
Read one hex record from the file
-
-
-
Field Detail
-
name
protected java.lang.String name
-
file
protected java.io.File file
-
in
protected java.io.FileInputStream in
-
buffIn
protected java.io.BufferedInputStream buffIn
-
MAX_HEX_SIZE
protected static final int MAX_HEX_SIZE
- See Also:
- Constant Field Values
-
address
protected int address
-
read
protected boolean read
-
lineNo
protected int lineNo
-
hexRecords
protected HexRecord[] hexRecords
-
readIndex
protected int readIndex
-
endRecord
protected int endRecord
-
-
Constructor Detail
-
HexFile
public HexFile(java.lang.String fileName)
Create a new HexFile object and initialize data to unprogrammed state.- Parameters:
fileName
- file name to use for the hex file
-
-
Method Detail
-
getName
public java.lang.String getName()
- Returns:
- name of the open file
-
openRd
public void openRd() throws java.io.FileNotFoundException
Open hex file for reading.- Throws:
java.io.FileNotFoundException
- if pre-defined file can't be opened
-
close
public void close()
Close the currently open file.
-
checkRecord
protected void checkRecord(HexRecord r)
DProcess record if required- Parameters:
r
- hex record
-
readOneRecord
protected HexRecord readOneRecord() throws java.io.IOException
Read one hex record from the file- Returns:
- the hex record
- Throws:
java.io.IOException
- on read error.
-
read
public void read() throws java.io.IOException
Read a hex file.Read hex records and store TYPE_DATA records in the array.
- Throws:
java.io.IOException
- on read error
-
readChar
public int readChar() throws java.io.IOException
Read a character from the hex file- Returns:
- the character
- Throws:
java.io.IOException
- from the underlying read operation
-
rdHexByte
public int rdHexByte() throws java.io.IOException
Read a hex byte.- Returns:
- the byte
- Throws:
java.io.IOException
- from the underlying read operation
-
getAddress
public int getAddress()
Get current address.- Returns:
- int the current address
-
getLineNo
public int getLineNo()
Get current file line number- Returns:
- the file number
-
getNextRecord
public HexRecord getNextRecord() throws java.lang.ArrayIndexOutOfBoundsException
Return the next TYPE_DATA record from the file- Returns:
- the next hex record
- Throws:
java.lang.ArrayIndexOutOfBoundsException
-
getRecordForAddress
public java.util.Optional<HexRecord> getRecordForAddress(int addr) throws java.lang.ArrayIndexOutOfBoundsException
Get the hex record for a given address Expected that the address will be the start address of a record but will return the first record that encompasses the address and increment the index to point at the next record.- Parameters:
addr
- The address- Returns:
- the hex record
- Throws:
java.lang.ArrayIndexOutOfBoundsException
-
getParams
public CbusParameters getParams()
Get the file parameters Create an invalid parameter set of necessary. Override in hardware specific implementations.- Returns:
- CBUS parameters from the file
-
getProgStart
public int getProgStart()
Return the lowest address read from the hex file- Returns:
- the highest address
-
getProgEnd
public int getProgEnd()
Return the highest address read from the hex file- Returns:
- the highest address
-
dispose
public void dispose()
close the open file
-
-