HistoryData.h
/*
* Copyright (c) 2013-16, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <vector>
#include <cstring>
class HistoryData
{
public:
HistoryData()
: m_currentDevice(-1)
, m_currentBaudRate(-1)
, m_imageAddress(0){};
virtual ~HistoryData(){};
enum FileType
{
kBinary,
kSBFile,
kIntelHex,
kSRecord,
kUnsupported
};
int32_t GetCurrentDevice() { return m_currentDevice; };
void SetCurrentDevice(int32_t index) { m_currentDevice = index; };
int32_t GetBaudRate(size_t index) { return m_baudRate.at(index); };
size_t GetBaudRateCount() { return m_baudRate.size(); };
int32_t GetCurrentBaudRate() { return m_currentBaudRate; };
void SetCurrentBaudRate(int32_t index) { m_currentBaudRate = index; };
void AddBaudRate(int32_t baudrate)
{
// Find whether the new baudrate already exists in the list
for (std::vector<int32_t>::iterator it = m_baudRate.begin(); it != m_baudRate.end(); it++)
{
// If find the matched baud rate, return.
if (baudrate == *it)
{
return;
}
}
// If no matched, add it to end of list.
m_baudRate.push_back(baudrate);
};
void InsertBaudRate(int32_t baudrate)
{
// If find index of the baud rate to insert.
for (std::vector<int32_t>::iterator it = m_baudRate.begin(); it != m_baudRate.end(); it++)
{
// Check next index.
if (baudrate > *it)
{
continue;
}
// The same baudrate in the list, just set it as current selected baud rate.
else if (baudrate == *it)
{
SetCurrentBaudRate(it - m_baudRate.begin());
return;
}
// Find the correct index, insert it and set it as current selected baud rate.
else
{
m_baudRate.insert(it, baudrate);
SetCurrentBaudRate(it - m_baudRate.begin());
return;
}
}
// If baudrate is bigger than any one in the list, add it to list back.
m_baudRate.push_back(baudrate);
SetCurrentBaudRate(GetBaudRateCount());
return;
};
uint16_t GetVid(size_t index) { return m_vids.at(index); };
size_t GetVidCount() { return m_vids.size(); };
void AddVid(uint16_t vid)
{
// Find whether the new vid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_vids.begin(); it != m_vids.end(); it++)
{
// If find the matched vid, return.
if (vid == *it)
{
return;
}
}
// If no matched, add it to end of list.
m_vids.push_back(vid);
};
void InsertVid(uint16_t vid)
{
// Find whether the new vid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_vids.begin(); it != m_vids.end(); it++)
{
// If find the matched vid, bubble it to the head of list. Then return.
if (vid == *it)
{
BubbleSelectedVid(it - m_vids.begin());
return;
}
}
// If no matched, add it to head of list.
m_vids.insert(m_vids.begin(), vid);
};
void BubbleSelectedVid(size_t index)
{
uint16_t vid = m_vids.at(index);
m_vids.erase(m_vids.begin() + index);
m_vids.insert(m_vids.begin(), vid);
}
uint16_t GetPid(size_t index) { return m_pids.at(index); };
size_t GetPidCount() { return m_pids.size(); };
void AddPid(uint16_t pid)
{
// Find whether the new pid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_pids.begin(); it != m_pids.end(); it++)
{
// If find the matched pid, return.
if (pid == *it)
{
return;
}
}
// If no matched, add it to end of list.
m_pids.push_back(pid);
};
void InsertPid(uint16_t pid)
{
// Find whether the new pid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_pids.begin(); it != m_pids.end(); it++)
{
// If find the matched pid, bubble it to the head of list. Then return.
if (pid == *it)
{
BubbleSelectedPid(it - m_pids.begin());
return;
}
}
// If no matched, add it to head of list.
m_pids.insert(m_pids.begin(), pid);
};
void BubbleSelectedPid(size_t index)
{
uint16_t pid = m_pids.at(index);
m_pids.erase(m_pids.begin() + index);
m_pids.insert(m_pids.begin(), pid);
}
CString GetFilePath(int index) { return m_imageFile.at(index); };
CString GetFileName(int index)
{
CString fullPath = m_imageFile.at(index);
int pos = fullPath.ReverseFind(_T('\\'));
return fullPath.Right(fullPath.GetLength() - pos - 1);
};
FileType GetFileType(int index)
{
CString extension = PathFindExtension(m_imageFile.at(index));
if (extension.CompareNoCase(_T(".bin")) == 0)
{
return kBinary;
}
else if (extension.CompareNoCase(_T(".sb")) == 0)
{
return kSBFile;
}
else if (extension.CompareNoCase(_T(".hex")) == 0)
{
return kIntelHex;
}
else if ((extension.CompareNoCase(_T(".srec")) == 0) || (extension.CompareNoCase(_T(".s19")) == 0))
{
return kSRecord;
}
else
{
return kUnsupported;
}
}
size_t GetFileCount() { return m_imageFile.size(); };
void AddFile(CString fullPath)
{
// Find whether this file already exists in the file list.
for (std::vector<CString>::iterator it = m_imageFile.begin(); it != m_imageFile.end(); it++)
{
// If find the matched file, return.
if (fullPath.Compare(*it) == 0)
{
return;
}
}
// If no matched file, add it to end of file list.
m_imageFile.push_back(fullPath);
};
void InsertFile(CString fullPath)
{
// Find whether this file already exists in the file list.
for (std::vector<CString>::iterator it = m_imageFile.begin(); it != m_imageFile.end(); it++)
{
// If find the matched file, bubble it to the head of file list. Then return.
if (fullPath.Compare(*it) == 0)
{
BubbleSelectedFile(it - m_imageFile.begin());
return;
}
}
// If no matched file, add it to head of file list.
m_imageFile.insert(m_imageFile.begin(), fullPath);
};
void BubbleSelectedFile(int32_t index)
{
CString file = m_imageFile.at(index);
m_imageFile.erase(m_imageFile.begin() + index);
m_imageFile.insert(m_imageFile.begin(), file);
}
uint32_t GetImageAddress() { return m_imageAddress; };
void SetImageAddress(uint32_t imageAddress) { m_imageAddress = imageAddress; };
CString GetBackdoorKey() { return m_backdoorKey; }
void SetBackdoorKey(CString backdoorKey) { m_backdoorKey = backdoorKey; };
private:
int32_t m_currentDevice;
std::vector<int32_t> m_baudRate;
int32_t m_currentBaudRate;
std::vector<uint16_t> m_vids;
std::vector<uint16_t> m_pids;
std::vector<CString> m_imageFile;
uint32_t m_imageAddress;
CString m_backdoorKey;
};
extern HistoryData *g_pHistoryData; //!< Global point to HistoryData class.
HistoryData::~HistoryData
virtual ~HistoryData()
Generated standard destructor.
Definition: HistoryData.h:49
HistoryData::BubbleSelectedVid
void BubbleSelectedVid(size_t index)
bubble the VID at the specified index to the head of the VID list
Definition: HistoryData.h:192
HistoryData::GetImageAddress
uint32_t GetImageAddress()
Get image address previous used.
Definition: HistoryData.h:359
HistoryData::GetCurrentDevice
int32_t GetCurrentDevice()
Get current selected device index at device list.
Definition: HistoryData.h:65
HistoryData::GetFileCount
size_t GetFileCount()
Get count of the files in the list .
Definition: HistoryData.h:307
HistoryData::kUnsupported
Unsupported file type.
Definition: HistoryData.h:58
HistoryData
HistoryData class stores the operation history. Save users operation steps.
Definition: HistoryData.h:39
HistoryData::kBinary
Binary file.(.bin)
Definition: HistoryData.h:54
HistoryData::HistoryData
HistoryData()
Generated standard constructor.
Definition: HistoryData.h:43
HistoryData::kIntelHex
Intel hex file.(.hex)
Definition: HistoryData.h:56
HistoryData::BubbleSelectedFile
void BubbleSelectedFile(int32_t index)
bubble the file at the specified index to the head of the file list
Definition: HistoryData.h:349
HistoryData::GetBackdoorKey
CString GetBackdoorKey()
Get the string of backdoor key previous used.
Definition: HistoryData.h:367
HistoryData::GetPid
uint16_t GetPid(size_t index)
Get the PID at the specified index.
Definition: HistoryData.h:204
HistoryData::SetBackdoorKey
void SetBackdoorKey(CString backdoorKey)
Change the string of backdoor key.
Definition: HistoryData.h:371
HistoryData::GetFileType
FileType GetFileType(int index)
Get the file type of the file at the specified index of the file list.
Definition: HistoryData.h:280
HistoryData::BubbleSelectedPid
void BubbleSelectedPid(size_t index)
bubble the PID at the specified index to the head of the PID list
Definition: HistoryData.h:250
HistoryData::GetPidCount
size_t GetPidCount()
Get count of the PID in the list .
Definition: HistoryData.h:208
HistoryData::AddPid
void AddPid(uint16_t pid)
Append a new PID at the end of the list.
Definition: HistoryData.h:212
HistoryData::GetFilePath
CString GetFilePath(int index)
Get the file full path at the specified index of the file list.
Definition: HistoryData.h:262
HistoryData::SetCurrentBaudRate
void SetCurrentBaudRate(int32_t index)
Change the index of current selected baud rate.
Definition: HistoryData.h:88
HistoryData::FileType
FileType
File types.
Definition: HistoryData.h:52
HistoryData::AddFile
void AddFile(CString fullPath)
Append a new file at the end of the list.
Definition: HistoryData.h:311
HistoryData::GetVid
uint16_t GetVid(size_t index)
Get the VID at the specified index.
Definition: HistoryData.h:146
HistoryData::InsertFile
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
HistoryData::InsertBaudRate
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
HistoryData::InsertVid
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
HistoryData::InsertPid
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
HistoryData::GetBaudRateCount
size_t GetBaudRateCount()
Get count of the baud rates in the list.
Definition: HistoryData.h:79
HistoryData::AddBaudRate
void AddBaudRate(int32_t baudrate)
Append a new baud rate at the end of the list.
Definition: HistoryData.h:92
HistoryData::GetCurrentBaudRate
int32_t GetCurrentBaudRate()
Get current selected baud rate index at the list.
Definition: HistoryData.h:84
HistoryData::GetVidCount
size_t GetVidCount()
Get count of the VID in the list .
Definition: HistoryData.h:150
HistoryData::SetImageAddress
void SetImageAddress(uint32_t imageAddress)
Change image address.
Definition: HistoryData.h:363
HistoryData::AddVid
void AddVid(uint16_t vid)
Append a new VID at the end of the list.
Definition: HistoryData.h:154
HistoryData::SetCurrentDevice
void SetCurrentDevice(int32_t index)
Change the index of current selected device.
Definition: HistoryData.h:69
HistoryData::kSBFile
SB file.(.sb)
Definition: HistoryData.h:55
HistoryData::GetFileName
CString GetFileName(int index)
Get the file name at the specified index of the file list.
Definition: HistoryData.h:268
HistoryData::kSRecord
Srecord file.(.srec, s19)
Definition: HistoryData.h:57
HistoryData::GetBaudRate
int32_t GetBaudRate(size_t index)
Get the baud rate at the specified index.
Definition: HistoryData.h:75