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 intaddressprotected java.io.BufferedInputStreambuffInprotected intendRecordprotected java.io.Filefileprotected HexRecord[]hexRecordsprotected java.io.FileInputStreaminprotected intlineNoprotected static intMAX_HEX_SIZEprotected java.lang.Stringnameprotected booleanreadprotected intreadIndex
-
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 voidcheckRecord(HexRecord r)DProcess record if requiredvoidclose()Close the currently open file.voiddispose()close the open fileintgetAddress()Get current address.intgetLineNo()Get current file line numberjava.lang.StringgetName()HexRecordgetNextRecord()Return the next TYPE_DATA record from the fileCbusParametersgetParams()Get the file parameters Create an invalid parameter set of necessary.intgetProgEnd()Return the highest address read from the hex fileintgetProgStart()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.voidopenRd()Open hex file for reading.intrdHexByte()Read a hex byte.voidread()Read a hex file.intreadChar()Read a character from the hex fileprotected HexRecordreadOneRecord()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- when needed
-
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- when needed
-
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
-
-