Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build compatibility for MSVC++ 2017 #90

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BossaProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void
BossaProgress::SetValue(int pos)
{
_statusGauge->SetValue(pos);
#if __WIN32
#if defined(__WIN32__) || defined(WIN32)
// Work around slow update on Windows
_statusGauge->SetValue(pos - 1);
_statusGauge->SetValue(pos);
Expand Down
2 changes: 1 addition & 1 deletion src/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DriverBase
virtual bool update() = 0;
};

#ifdef __WIN32__
#if defined(__WIN32__) || defined(WIN32)
#include "WinDriver.h"
typedef WinDriver Driver;
#else
Expand Down
6 changes: 5 additions & 1 deletion src/EefcFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
#include "EefcFlash.h"

#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#if defined(__WIN32__) || defined(WIN32)
#include "usleep.h"
#else
#include <unistd.h>
#endif

#define EEFC_KEY 0x5a

Expand Down
6 changes: 5 additions & 1 deletion src/EfcFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
#include "EfcFlash.h"

#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#if defined(__WIN32__) || defined(WIN32)
#include "usleep.h"
#else
#include <unistd.h>
#endif

#define EFC_KEY 0x5a

Expand Down
30 changes: 15 additions & 15 deletions src/Flasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,34 +112,34 @@ Flasher::write(const char* filename, uint32_t foffset)
{
uint32_t offset = 0;
uint32_t bufferSize = _samba.writeBufferSize();
uint8_t buffer[bufferSize];
std::vector<uint8_t> buffer(bufferSize);

while ((fbytes = fread(buffer, 1, bufferSize, infile)) > 0)
while ((fbytes = fread(buffer.data(), 1, bufferSize, infile)) > 0)
{
_observer.onProgress(offset / pageSize, numPages);

if (fbytes < bufferSize)
{
memset(buffer + fbytes, 0, bufferSize - fbytes);
memset(buffer.data() + fbytes, 0, bufferSize - fbytes);
fbytes = (fbytes + pageSize - 1) / pageSize * pageSize;
}

_flash->loadBuffer(buffer, fbytes);
_flash->loadBuffer(buffer.data(), fbytes);
_flash->writeBuffer(foffset + offset, fbytes);
offset += fbytes;
}

}
else
{
uint8_t buffer[pageSize];
std::vector<uint8_t> buffer(pageSize);
uint32_t pageOffset = foffset / pageSize;

while ((fbytes = fread(buffer, 1, pageSize, infile)) > 0)
while ((fbytes = fread(buffer.data(), 1, pageSize, infile)) > 0)
{
_observer.onProgress(pageNum, numPages);

_flash->loadBuffer(buffer, fbytes);
_flash->loadBuffer(buffer.data(), fbytes);
_flash->writePage(pageOffset + pageNum);

pageNum++;
Expand All @@ -164,8 +164,8 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError
{
FILE* infile;
uint32_t pageSize = _flash->pageSize();
uint8_t bufferA[pageSize];
uint8_t bufferB[pageSize];
std::vector<uint8_t> bufferA(pageSize);
std::vector<uint8_t> bufferB(pageSize);
uint32_t pageNum = 0;
uint32_t numPages;
uint32_t pageOffset;
Expand Down Expand Up @@ -200,7 +200,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError

_observer.onStatus("Verify %ld bytes of flash\n", fsize);

while ((fbytes = fread(bufferA, 1, pageSize, infile)) > 0)
while ((fbytes = fread(bufferA.data(), 1, pageSize, infile)) > 0)
{
byteErrors = 0;

Expand All @@ -215,7 +215,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError

if (flashCrc != calcCrc)
{
_flash->readPage(pageOffset + pageNum, bufferB);
_flash->readPage(pageOffset + pageNum, bufferB.data());

for (uint32_t i = 0; i < fbytes; i++)
{
Expand All @@ -226,7 +226,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError
}
else
{
_flash->readPage(pageOffset + pageNum, bufferB);
_flash->readPage(pageOffset + pageNum, bufferB.data());

for (uint32_t i = 0; i < fbytes; i++)
{
Expand Down Expand Up @@ -267,7 +267,7 @@ Flasher::read(const char* filename, uint32_t fsize, uint32_t foffset)
{
FILE* outfile;
uint32_t pageSize = _flash->pageSize();
uint8_t buffer[pageSize];
std::vector<uint8_t> buffer(pageSize);
uint32_t pageNum = 0;
uint32_t pageOffset;
uint32_t numPages;
Expand Down Expand Up @@ -297,11 +297,11 @@ Flasher::read(const char* filename, uint32_t fsize, uint32_t foffset)
{
_observer.onProgress(pageNum, numPages);

_flash->readPage(pageOffset + pageNum, buffer);
_flash->readPage(pageOffset + pageNum, buffer.data());

if (pageNum == numPages - 1 && fsize % pageSize > 0)
pageSize = fsize % pageSize;
fbytes = fwrite(buffer, 1, pageSize, outfile);
fbytes = fwrite(buffer.data(), 1, pageSize, outfile);
if (fbytes != pageSize)
throw FileShortError();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PortFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PortFactoryBase
virtual SerialPort::Ptr create(const std::string& name, bool isUsb) = 0;
};

#if defined(__WIN32__)
#if defined(__WIN32__) || defined(WIN32)
#include "WinPortFactory.h"
typedef WinPortFactory PortFactory;
#elif defined(__linux__)
Expand Down
6 changes: 5 additions & 1 deletion src/PosixSerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@

#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <errno.h>
#include <sys/ioctl.h>
#if defined(__WIN32__) || defined(WIN32)
#include "usleep.h"
#else
#include <unistd.h>
#endif

#include <string>

Expand Down
6 changes: 5 additions & 1 deletion src/Samba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
#include <stdint.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#if defined(__WIN32__) || defined(WIN32)
#include "usleep.h"
#else
#include <unistd.h>
#endif

using namespace std;

Expand Down
8 changes: 5 additions & 3 deletions src/WinPortFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
///////////////////////////////////////////////////////////////////////////////
#include <vector>

#include "WinPortFactory.h"
#include "WinSerialPort.h"

Expand Down Expand Up @@ -102,14 +104,14 @@ WinPortFactory::begin()
if (size < 1)
return error();

GUID guids[size];
std::vector<GUID> guids(size);

if (!SetupDiClassGuidsFromNameA("Ports", guids, size * sizeof(GUID), &size))
if (!SetupDiClassGuidsFromNameA("Ports", guids.data(), size * sizeof(GUID), &size))
{
return error();
}

_devInfo = SetupDiGetClassDevs(guids, NULL, NULL, DIGCF_PRESENT);
_devInfo = SetupDiGetClassDevs(guids.data(), NULL, NULL, DIGCF_PRESENT);
if(_devInfo == INVALID_HANDLE_VALUE)
return error();

Expand Down
2 changes: 1 addition & 1 deletion src/WinPortFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class WinPortFactory : public PortFactoryBase
SerialPort::Ptr create(const std::string& name, bool isUsb);

private:
typedef DWORD WINAPI (*CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD);
typedef DWORD (WINAPI *CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD);

HDEVINFO _devInfo;
HINSTANCE _cfgMgr;
Expand Down
8 changes: 8 additions & 0 deletions src/usleep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <chrono>
#include <thread>

// Replacement for sleep
void inline
usleep(int length) {
std::this_thread::sleep_for(std::chrono::milliseconds(length));
}