Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
SerialList.h
1 /*
2 * Copyright (c) 2013-15, 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 
39 {
40 public:
43  : m_port(_T("")){};
44 
46  SerialDevice(LPCTSTR port)
47  : m_port(port){};
48 
50  virtual ~SerialDevice(){};
51 
53  virtual CString GetString() { return (m_port); };
55  virtual uint32_t GetNum() { return _ttoi(m_port.Mid(3)); };
56 private:
57  CString m_port;
58 };
59 
64 {
65 public:
68 
70  virtual ~SerialList(){};
71 
73  SerialDevice GetDevice(int index) { return m_serialDevices.at(index); };
75  size_t GetDeviceCount() { return m_serialDevices.size(); };
78  {
79  std::vector<SerialDevice>::iterator it;
80  for (it = m_serialDevices.begin(); it != m_serialDevices.end(); it++)
81  {
82  // Check next index.
83  if (device.GetNum() > it->GetNum())
84  {
85  continue;
86  }
87  // The same COM device in the list, return the index
88  else if (device.GetNum() == it->GetNum())
89  {
90  return it - m_serialDevices.begin();
91  }
92  // No matched, return negative.
93  else
94  {
95  return -1;
96  }
97  }
98  return -1;
99  }
100 
102  void ScanSerialDevices();
103 
105  void SortSerialDevices();
106 
107 private:
108  std::vector<SerialDevice> m_serialDevices;
109 };
110 
111 extern SerialList *g_pAllComDevices;
SerialList class contains all serial devices on host.
Definition: SerialList.h:63
SerialDevice class represent a COM port hardware on host.
Definition: SerialList.h:38
SerialList()
Generated standard constructor.
Definition: SerialList.h:67
size_t GetDeviceCount()
Get the number of devices in the list.
Definition: SerialList.h:75
virtual ~SerialList()
Generated standard destructor.
Definition: SerialList.h:70
SerialDevice GetDevice(int index)
Get SerialDevice variable at specified index.
Definition: SerialList.h:73
int FindSerialDevice(SerialDevice device)
Find whether the specified device is in the list.
Definition: SerialList.h:77
virtual ~SerialDevice()
Generated standard destructor.
Definition: SerialList.h:50
SerialDevice(LPCTSTR port)
Generated standard constructor with a parameter.
Definition: SerialList.h:46
SerialDevice()
Generated standard constructor.
Definition: SerialList.h:42
virtual CString GetString()
Get the string containing COM port.(COMxx)
Definition: SerialList.h:53
virtual uint32_t GetNum()
Get the port number only.
Definition: SerialList.h:55