Class HexFile

java.lang.Object
jmri.jmrix.can.cbus.swing.bootloader.HexFile
Direct Known Subclasses:
CbusPicHexFile

public class HexFile extends 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 Details

  • Constructor Details

    • HexFile

      public HexFile(String fileName)
      Create a new HexFile object and initialize data to unprogrammed state.
      Parameters:
      fileName - file name to use for the hex file
  • Method Details

    • getName

      public String getName()
      Returns:
      name of the open file
    • openRd

      public void openRd() throws FileNotFoundException
      Open hex file for reading.
      Throws:
      FileNotFoundException - if pre-defined file can't be opened
    • close

      public void close()
      Close the currently open file.

      Safe to call if the file was never opened, or has already been closed. The records already read remain available in memory.

    • checkRecord

      protected void checkRecord(HexRecord r)
      DProcess record if required
      Parameters:
      r - hex record
    • readOneRecord

      protected HexRecord readOneRecord() throws IOException
      Read one hex record from the file
      Returns:
      the hex record
      Throws:
      IOException - on read error.
    • read

      public void read() throws IOException
      Read a hex file.

      Read hex records and store TYPE_DATA records in the array.

      Only data, end of file and extended linear address records are understood. Any other record type causes the file to be rejected.

      Throws:
      IOException - on read error, or if the file contains an unsupported record type, or too many records
    • readChar

      public int readChar() throws IOException
      Read a character from the hex file
      Returns:
      the character
      Throws:
      IOException - from the underlying read operation
    • rdHexByte

      public int rdHexByte() throws IOException
      Read a hex byte.
      Returns:
      the byte
      Throws:
      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

      Return the next TYPE_DATA record from the file

      Once the records read from the file are exhausted, an END record is returned so that callers stop cleanly.

      Returns:
      the next hex record
    • getRecordForAddress

      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.

      Only the records actually read from the file are searched.

      Parameters:
      addr - The address
      Returns:
      the hex record, or empty if no data record contains the address
    • 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