SIde-Channel Analysis toolKit (SICAK)
Software toolkit for side-channel analysis
serialport.h
Go to the documentation of this file.
1 /*
2 * SICAK - SIde-Channel Analysis toolKit
3 * Copyright (C) 2018 Petr Socha, FIT, CTU in Prague
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18 
29 #ifndef SERIALPORT_H
30 #define SERIALPORT_H
31 
32 #include <QObject>
33 #include <QtPlugin>
34 #include "chardevice.h"
35 #include "exceptions.hpp"
36 
37 #ifdef _WIN32
38 
39 #include <windows.h>
40 
41 #else
42 
43 #include <termios.h>
44 #include <unistd.h>
45 #include <fcntl.h>
46 
47 #endif
48 
56 class SerialPort : public QObject, CharDevice {
57 
58  Q_OBJECT
59  Q_PLUGIN_METADATA(IID "cz.cvut.fit.Sicak.CharDeviceInterface/1.0" FILE "serialport.json")
60  Q_INTERFACES(CharDevice)
61 
62 public:
63 
64  SerialPort();
65  virtual ~SerialPort() override;
66 
67  virtual QString getPluginName() override;
68  virtual QString getPluginInfo() override;
69 
71  virtual void init(const char * filename, int baudrate = 9600, int parity = 0, int stopBits = 1) override;
72  virtual void deInit() override;
73 
74  virtual QString queryDevices() override;
75 
76  virtual void setTimeout(int ms = 5000) override;
77 
78  virtual size_t send(const VectorType<uint8_t> & data) override;
79  virtual size_t receive(VectorType<uint8_t> & data) override;
80 
81  virtual size_t send(const VectorType<uint8_t> & data, size_t len) override;
82  virtual size_t receive(VectorType<uint8_t> & data, size_t len) override;
83 
84  virtual size_t send(const uint8_t * buffer, size_t len) override;
85  virtual size_t receive(uint8_t * buffer, size_t len) override;
86 
87 protected:
88 
89  #ifdef _WIN32
90 
91  HANDLE m_osHandle;
92 
93  #else
94 
95  int m_osHandle;
96 
97  #endif
98 
99  bool m_opened;
100 
101 };
102 
103 #endif /* SERIALPORT_H */
104 
virtual QString getPluginName() override
Plugin name.
Definition: serialport.cpp:45
This header file contains exceptions.
Character device QT plugin interface.
Definition: chardevice.h:42
virtual void setTimeout(int ms=5000) override
Set communication timeout of the character device, in milliseconds, default 5s.
Definition: serialport.cpp:304
virtual size_t receive(VectorType< uint8_t > &data) override
Fills the given VectorType.
Definition: serialport.cpp:453
Character device plugin interface for use e.g. in meas.
virtual QString queryDevices() override
Query available devices/filenames.
Definition: serialport.cpp:290
virtual void init(const char *filename, int baudrate=9600, int parity=0, int stopBits=1) override
Initializes the serial port, on Win32 e.g. filename=COM2, on Posix e.g. filename=/dev/ttyUSB0,...
Definition: serialport.cpp:53
virtual void deInit() override
Deinitialize the plugin.
Definition: serialport.cpp:271
virtual size_t send(const VectorType< uint8_t > &data) override
Sends out the VectorType.
Definition: serialport.cpp:387
virtual QString getPluginInfo() override
Plugin info.
Definition: serialport.cpp:49
Serial port interface (Win32/Posix) SICAK CharDevice plugin.
Definition: serialport.h:56