Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
HistoryData.h
1 /*
2 * Copyright (c) 2013-16, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #pragma once
32 #include <vector>
33 #include <cstring>
34 
40 {
41 public:
44  : m_currentDevice(-1)
45  , m_currentBaudRate(-1)
46  , m_imageAddress(0){};
47 
49  virtual ~HistoryData(){};
50 
52  enum FileType
53  {
59  };
60 
65  int32_t GetCurrentDevice() { return m_currentDevice; };
69  void SetCurrentDevice(int32_t index) { m_currentDevice = index; };
75  int32_t GetBaudRate(size_t index) { return m_baudRate.at(index); };
79  size_t GetBaudRateCount() { return m_baudRate.size(); };
84  int32_t GetCurrentBaudRate() { return m_currentBaudRate; };
88  void SetCurrentBaudRate(int32_t index) { m_currentBaudRate = index; };
92  void AddBaudRate(int32_t baudrate)
93  {
94  // Find whether the new baudrate already exists in the list
95  for (std::vector<int32_t>::iterator it = m_baudRate.begin(); it != m_baudRate.end(); it++)
96  {
97  // If find the matched baud rate, return.
98  if (baudrate == *it)
99  {
100  return;
101  }
102  }
103  // If no matched, add it to end of list.
104  m_baudRate.push_back(baudrate);
105  };
106 
111  void InsertBaudRate(int32_t baudrate)
112  {
113  // If find index of the baud rate to insert.
114  for (std::vector<int32_t>::iterator it = m_baudRate.begin(); it != m_baudRate.end(); it++)
115  {
116  // Check next index.
117  if (baudrate > *it)
118  {
119  continue;
120  }
121  // The same baudrate in the list, just set it as current selected baud rate.
122  else if (baudrate == *it)
123  {
124  SetCurrentBaudRate(it - m_baudRate.begin());
125  return;
126  }
127  // Find the correct index, insert it and set it as current selected baud rate.
128  else
129  {
130  m_baudRate.insert(it, baudrate);
131  SetCurrentBaudRate(it - m_baudRate.begin());
132  return;
133  }
134  }
135  // If baudrate is bigger than any one in the list, add it to list back.
136  m_baudRate.push_back(baudrate);
138  return;
139  };
140 
146  uint16_t GetVid(size_t index) { return m_vids.at(index); };
150  size_t GetVidCount() { return m_vids.size(); };
154  void AddVid(uint16_t vid)
155  {
156  // Find whether the new vid already exists in the list.
157  for (std::vector<uint16_t>::iterator it = m_vids.begin(); it != m_vids.end(); it++)
158  {
159  // If find the matched vid, return.
160  if (vid == *it)
161  {
162  return;
163  }
164  }
165  // If no matched, add it to end of list.
166  m_vids.push_back(vid);
167  };
168 
173  void InsertVid(uint16_t vid)
174  {
175  // Find whether the new vid already exists in the list.
176  for (std::vector<uint16_t>::iterator it = m_vids.begin(); it != m_vids.end(); it++)
177  {
178  // If find the matched vid, bubble it to the head of list. Then return.
179  if (vid == *it)
180  {
181  BubbleSelectedVid(it - m_vids.begin());
182  return;
183  }
184  }
185  // If no matched, add it to head of list.
186  m_vids.insert(m_vids.begin(), vid);
187  };
188 
192  void BubbleSelectedVid(size_t index)
193  {
194  uint16_t vid = m_vids.at(index);
195  m_vids.erase(m_vids.begin() + index);
196  m_vids.insert(m_vids.begin(), vid);
197  }
198 
204  uint16_t GetPid(size_t index) { return m_pids.at(index); };
208  size_t GetPidCount() { return m_pids.size(); };
212  void AddPid(uint16_t pid)
213  {
214  // Find whether the new pid already exists in the list.
215  for (std::vector<uint16_t>::iterator it = m_pids.begin(); it != m_pids.end(); it++)
216  {
217  // If find the matched pid, return.
218  if (pid == *it)
219  {
220  return;
221  }
222  }
223  // If no matched, add it to end of list.
224  m_pids.push_back(pid);
225  };
226 
231  void InsertPid(uint16_t pid)
232  {
233  // Find whether the new pid already exists in the list.
234  for (std::vector<uint16_t>::iterator it = m_pids.begin(); it != m_pids.end(); it++)
235  {
236  // If find the matched pid, bubble it to the head of list. Then return.
237  if (pid == *it)
238  {
239  BubbleSelectedPid(it - m_pids.begin());
240  return;
241  }
242  }
243  // If no matched, add it to head of list.
244  m_pids.insert(m_pids.begin(), pid);
245  };
246 
250  void BubbleSelectedPid(size_t index)
251  {
252  uint16_t pid = m_pids.at(index);
253  m_pids.erase(m_pids.begin() + index);
254  m_pids.insert(m_pids.begin(), pid);
255  }
256 
262  CString GetFilePath(int index) { return m_imageFile.at(index); };
268  CString GetFileName(int index)
269  {
270  CString fullPath = m_imageFile.at(index);
271  int pos = fullPath.ReverseFind(_T('\\'));
272  return fullPath.Right(fullPath.GetLength() - pos - 1);
273  };
274 
281  {
282  CString extension = PathFindExtension(m_imageFile.at(index));
283  if (extension.CompareNoCase(_T(".bin")) == 0)
284  {
285  return kBinary;
286  }
287  else if (extension.CompareNoCase(_T(".sb")) == 0)
288  {
289  return kSBFile;
290  }
291  else if (extension.CompareNoCase(_T(".hex")) == 0)
292  {
293  return kIntelHex;
294  }
295  else if ((extension.CompareNoCase(_T(".srec")) == 0) || (extension.CompareNoCase(_T(".s19")) == 0))
296  {
297  return kSRecord;
298  }
299  else
300  {
301  return kUnsupported;
302  }
303  }
307  size_t GetFileCount() { return m_imageFile.size(); };
311  void AddFile(CString fullPath)
312  {
313  // Find whether this file already exists in the file list.
314  for (std::vector<CString>::iterator it = m_imageFile.begin(); it != m_imageFile.end(); it++)
315  {
316  // If find the matched file, return.
317  if (fullPath.Compare(*it) == 0)
318  {
319  return;
320  }
321  }
322  // If no matched file, add it to end of file list.
323  m_imageFile.push_back(fullPath);
324  };
325 
330  void InsertFile(CString fullPath)
331  {
332  // Find whether this file already exists in the file list.
333  for (std::vector<CString>::iterator it = m_imageFile.begin(); it != m_imageFile.end(); it++)
334  {
335  // If find the matched file, bubble it to the head of file list. Then return.
336  if (fullPath.Compare(*it) == 0)
337  {
338  BubbleSelectedFile(it - m_imageFile.begin());
339  return;
340  }
341  }
342  // If no matched file, add it to head of file list.
343  m_imageFile.insert(m_imageFile.begin(), fullPath);
344  };
345 
349  void BubbleSelectedFile(int32_t index)
350  {
351  CString file = m_imageFile.at(index);
352  m_imageFile.erase(m_imageFile.begin() + index);
353  m_imageFile.insert(m_imageFile.begin(), file);
354  }
355 
359  uint32_t GetImageAddress() { return m_imageAddress; };
363  void SetImageAddress(uint32_t imageAddress) { m_imageAddress = imageAddress; };
367  CString GetBackdoorKey() { return m_backdoorKey; }
371  void SetBackdoorKey(CString backdoorKey) { m_backdoorKey = backdoorKey; };
372 private:
373  int32_t m_currentDevice;
374  std::vector<int32_t> m_baudRate;
375  int32_t m_currentBaudRate;
376  std::vector<uint16_t> m_vids;
377  std::vector<uint16_t> m_pids;
378  std::vector<CString> m_imageFile;
379  uint32_t m_imageAddress;
380  CString m_backdoorKey;
381 };
382 
383 extern HistoryData *g_pHistoryData; //!< Global point to HistoryData class.
virtual ~HistoryData()
Generated standard destructor.
Definition: HistoryData.h:49
void BubbleSelectedVid(size_t index)
bubble the VID at the specified index to the head of the VID list
Definition: HistoryData.h:192
uint32_t GetImageAddress()
Get image address previous used.
Definition: HistoryData.h:359
int32_t GetCurrentDevice()
Get current selected device index at device list.
Definition: HistoryData.h:65
size_t GetFileCount()
Get count of the files in the list .
Definition: HistoryData.h:307
Unsupported file type.
Definition: HistoryData.h:58
HistoryData class stores the operation history. Save users operation steps.
Definition: HistoryData.h:39
Binary file.(.bin)
Definition: HistoryData.h:54
HistoryData()
Generated standard constructor.
Definition: HistoryData.h:43
Intel hex file.(.hex)
Definition: HistoryData.h:56
void BubbleSelectedFile(int32_t index)
bubble the file at the specified index to the head of the file list
Definition: HistoryData.h:349
CString GetBackdoorKey()
Get the string of backdoor key previous used.
Definition: HistoryData.h:367
uint16_t GetPid(size_t index)
Get the PID at the specified index.
Definition: HistoryData.h:204
void SetBackdoorKey(CString backdoorKey)
Change the string of backdoor key.
Definition: HistoryData.h:371
FileType GetFileType(int index)
Get the file type of the file at the specified index of the file list.
Definition: HistoryData.h:280
void BubbleSelectedPid(size_t index)
bubble the PID at the specified index to the head of the PID list
Definition: HistoryData.h:250
size_t GetPidCount()
Get count of the PID in the list .
Definition: HistoryData.h:208
void AddPid(uint16_t pid)
Append a new PID at the end of the list.
Definition: HistoryData.h:212
CString GetFilePath(int index)
Get the file full path at the specified index of the file list.
Definition: HistoryData.h:262
void SetCurrentBaudRate(int32_t index)
Change the index of current selected baud rate.
Definition: HistoryData.h:88
FileType
File types.
Definition: HistoryData.h:52
void AddFile(CString fullPath)
Append a new file at the end of the list.
Definition: HistoryData.h:311
uint16_t GetVid(size_t index)
Get the VID at the specified index.
Definition: HistoryData.h:146
void InsertFile(CString fullPath)
Insert a file at the head of the list. If the file already exists in the list, only bubble that file ...
Definition: HistoryData.h:330
void InsertBaudRate(int32_t baudrate)
Insert a new baud rate, and change the current selected baud rate. If the baud rate already exists in...
Definition: HistoryData.h:111
void InsertVid(uint16_t vid)
Insert a VID at the head of the list. If the VID already exists in the list, only bubble that VID to ...
Definition: HistoryData.h:173
void InsertPid(uint16_t pid)
Insert a PID at the head of the list. If the PID already exists in the list, only bubble it to list h...
Definition: HistoryData.h:231
size_t GetBaudRateCount()
Get count of the baud rates in the list.
Definition: HistoryData.h:79
void AddBaudRate(int32_t baudrate)
Append a new baud rate at the end of the list.
Definition: HistoryData.h:92
int32_t GetCurrentBaudRate()
Get current selected baud rate index at the list.
Definition: HistoryData.h:84
size_t GetVidCount()
Get count of the VID in the list .
Definition: HistoryData.h:150
void SetImageAddress(uint32_t imageAddress)
Change image address.
Definition: HistoryData.h:363
void AddVid(uint16_t vid)
Append a new VID at the end of the list.
Definition: HistoryData.h:154
void SetCurrentDevice(int32_t index)
Change the index of current selected device.
Definition: HistoryData.h:69
SB file.(.sb)
Definition: HistoryData.h:55
CString GetFileName(int index)
Get the file name at the specified index of the file list.
Definition: HistoryData.h:268
Srecord file.(.srec, s19)
Definition: HistoryData.h:57
int32_t GetBaudRate(size_t index)
Get the baud rate at the specified index.
Definition: HistoryData.h:75