BowlerKernel
hexLine.java
Go to the documentation of this file.
1 package com.neuronrobotics.sdk.bootloader;
2 //import java.util.LinkedList;
3 //import java.util.Queue;
4 import java.util.ArrayList;
5 
6 // TODO: Auto-generated Javadoc
10 public class hexLine {
11 
13  private ArrayList<Byte> dataBytes = new ArrayList<Byte>();
14 
16  private int address;
17 
19  private int byteCount;
20 
22  private int recordType;
23 
25  private int checkSum;
26 
28  private boolean hasSetHighAddress=false;
29 
35  public int getCheckSum() {
36  return checkSum;
37  }
38 
45  public hexLine(String s) throws Exception{
46  char data[] = s.toCharArray();
47  if ((data.length<11)||data[0]!=':')
48  throw new Exception("This line is not a hex line");
49 
50  char[] bc={data[1],data[2]};
51  byteCount = Integer.parseInt(new String(bc), 16);
52 
53  char[] ad={data[3],data[4],data[5],data[6]};
54  address = Integer.parseInt(new String(ad), 16);
55 
56  char[] rt={data[7],data[8]};
57  recordType = Integer.parseInt(new String(rt), 16);
58 
59  char[] cs={data[data.length-2],data[data.length-1]};
60  checkSum = Integer.parseInt(new String(cs), 16);
61 
62  for (int i=0;i<byteCount;i++){
63  char[] d={data[9+(i*2)],data[9+1+(i*2)]};
64  Byte b =new Byte((byte) Integer.parseInt(new String(d), 16));
65  dataBytes.add(b);
66  }
67 
68  }
69 
75  public int getStartAddress() {
76  return address;
77  }
78 
84  public int getEndAddress() {
85  return address+dataBytes.size();
86  }
87 
93  public void setHighAddress(long highAddress){
94  if(!hasSetHighAddress){
95  hasSetHighAddress=true;
96  address+=highAddress;
97  }
98  }
99 
105  public int getByteCount() {
106  return byteCount;
107  }
108 
114  public int getRecordType() {
115  return recordType;
116  }
117 
123  public byte[] getDataBytes() {
124  if (dataBytes.size()==0)
125  return null;
126  return dataToArray(dataBytes);
127  }
128 
134  public Boolean hasData(){
135  if (dataBytes==null) return false;
136  return true;
137  }
138 
145  private byte [] dataToArray( ArrayList<Byte> bl){
146  byte [] b = new byte[bl.size()];
147  int i=0;
148  for (Byte bld:bl){
149  b[i++]=bld.byteValue();
150  }
151  return b;
152  }
153 
154  /* (non-Javadoc)
155  * @see java.lang.Object#toString()
156  */
157  public String toString(){
158  String s="";
159  if (getRecordType()==0){
160  s+="Address = "+getStartAddress();
161  s+=" Data: [";
162  for (byte b: getDataBytes()){
163  s+=b+",";
164  }
165  s+="]";
166  }else if (getRecordType()==4){
167  s="High Address Set: ";
168  }
169  return s;
170  }
171 
172 }
byte[] dataToArray(ArrayList< Byte > bl)
Definition: hexLine.java:145
void setHighAddress(long highAddress)
Definition: hexLine.java:93