Skip to content

Commit 2ef6841

Browse files
committed
Fixing for windows plattform on multiple classes
1 parent beb77fa commit 2ef6841

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

source/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ add_library(modern.cpp.core
4545
Timing.h
4646
templates/CSVWriter.h
4747
templates/Timer.h
48-
unixservice/main.cpp
4948
)

source/CPU.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#ifdef _WIN32
3232
#include <intrin.h>
33-
using unsigned int = unsigned __int32;
3433
#endif
3534

3635
/* local header */
@@ -58,7 +57,12 @@ namespace VX {
5857
void CPU::updateNativeId( unsigned int _leaf, unsigned int _subleaf ) {
5958

6059
#ifdef _WIN32
61-
__cpuid( m_currentLeaf.data(), _leaf, _subleaf );
60+
std::array<int, 4> currentLeaf;
61+
__cpuidex( currentLeaf.data(), _leaf, _subleaf );
62+
m_currentLeaf[0] = currentLeaf[0];
63+
m_currentLeaf[1] = currentLeaf[1];
64+
m_currentLeaf[2] = currentLeaf[2];
65+
m_currentLeaf[3] = currentLeaf[3];
6266
#else
6367
asm volatile
6468
( "cpuid" : "=a"( m_currentLeaf[0] ), "=b"( m_currentLeaf[1] ), "=c"( m_currentLeaf[2] ), "=d"( m_currentLeaf[3] )

source/Exec.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ namespace VX {
4646

4747
std::array<char, bufferSize> buffer {};
4848
std::string result;
49+
#ifdef _WIN32
50+
std::unique_ptr<FILE, decltype( &_pclose )> pipe( _popen( _command.c_str(), "r" ), _pclose );
51+
#else
4952
std::unique_ptr<FILE, decltype( &pclose )> pipe( popen( _command.c_str(), "r" ), pclose );
53+
#endif
5054
if ( !pipe ) {
5155

5256
std::cout << "popen() failed for " << _command << std::endl;
5357
return {};
5458
}
55-
while ( fgets( buffer.data(), buffer.size(), pipe.get() ) != nullptr ) {
59+
while ( fgets( buffer.data(), static_cast<int>( buffer.size() ), pipe.get() ) != nullptr ) {
5660

5761
result += buffer.data();
5862
}

source/Serial.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535

3636
/* system header */
3737
#include <fcntl.h> // open
38+
#ifdef _WIN32
39+
#include <io.h> // write, read, close
40+
#else
3841
#include <termios.h>
3942
#include <unistd.h> // write, read, close
43+
#endif
4044

4145
/* stl header */
4246
#include <chrono>
@@ -57,13 +61,18 @@ namespace VX {
5761
Serial::Serial( const std::string &_path, Baudrate _baudrate ) {
5862

5963
/* Open port, checking for errors */
64+
#ifdef _WIN32
65+
m_descriptor = _open( _path.c_str(), ( O_RDWR | O_NOCTTY | O_NDELAY ) );
66+
#else
6067
m_descriptor = ::open( _path.c_str(), ( O_RDWR | O_NOCTTY | O_NDELAY ) );
68+
#endif
6169
if ( m_descriptor == -1 ) {
6270

6371
std::cout << "Unable to open serial port: " << _path << " at baud rate: " << static_cast<int>( _baudrate ) << std::endl;
6472
return;
6573
}
6674

75+
/* TODO: Rework for windows */
6776
/* Configure i/o baud rate settings */
6877
struct termios options = {};
6978
tcgetattr( m_descriptor, &options );
@@ -144,7 +153,11 @@ namespace VX {
144153

145154
bool Serial::write( const std::string &_data ) const {
146155

156+
#ifdef _WIN32
157+
int numBytesWritten = _write( m_descriptor, _data.c_str(), _data.size() );
158+
#else
147159
ssize_t numBytesWritten = ::write( m_descriptor, _data.c_str(), _data.size() );
160+
#endif
148161
if ( numBytesWritten < 0 ) {
149162

150163
#ifdef DEBUG
@@ -158,7 +171,11 @@ namespace VX {
158171
std::string Serial::read() const {
159172

160173
std::vector<char> buffer( bufferSize );
174+
#ifdef _WIN32
175+
int numBytesRead = _read( m_descriptor, buffer.data(), buffer.size() );
176+
#else
161177
ssize_t numBytesRead = ::read( m_descriptor, buffer.data(), buffer.size() );
178+
#endif
162179
if ( numBytesRead < 0 ) {
163180

164181
#ifdef DEBUG
@@ -173,7 +190,11 @@ namespace VX {
173190

174191
if ( m_isOpen ) {
175192

193+
#ifdef _WIN32
194+
_close( m_descriptor );
195+
#else
176196
::close( m_descriptor );
197+
#endif
177198
m_descriptor = -1;
178199
}
179200
}

0 commit comments

Comments
 (0)