Class 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 required
      void close()
      Close the currently open file.
      void dispose()
      close the open file
      int getAddress()
      Get current address.
      int getLineNo()
      Get current file line number
      java.lang.String getName()  
      HexRecord getNextRecord()
      Return the next TYPE_DATA record from the file
      CbusParameters getParams()
      Get the file parameters Create an invalid parameter set of necessary.
      int getProgEnd()
      Return the highest address read from the hex file
      int getProgStart()
      Return the lowest address read from the hex file
      java.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 file
      protected HexRecord readOneRecord()
      Read one hex record from the file
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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<HexRecordgetRecordForAddress​(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