Skip to content

Commit

Permalink
Check path exists before attempting to find the canonical path in the…
Browse files Browse the repository at this point in the history
… Flash helper.
  • Loading branch information
parnham committed Mar 16, 2019
1 parent 3780da5 commit 9e8c81e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
40 changes: 23 additions & 17 deletions include/psinc/flash/Flash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ namespace psinc
bool Initialise(const std::string &connection)
{
#ifdef __linux__
this->connection = std::experimental::filesystem::canonical(connection);
if (std::experimental::filesystem::exists(connection))
{
this->connection = std::experimental::filesystem::canonical(connection);
}
#else
this->connection = connection;
#endif
Expand Down Expand Up @@ -382,27 +385,30 @@ namespace psinc
{
this->Free();

if (sp_get_port_by_name(this->connection.c_str(), &this->serial) == SP_OK)
if (!this->connection.empty())
{
if (sp_open(this->serial, SP_MODE_READ_WRITE) == SP_OK)
if (sp_get_port_by_name(this->connection.c_str(), &this->serial) == SP_OK)
{
sp_set_baudrate(this->serial, 9600);
sp_set_bits(this->serial, 8);
sp_set_parity(this->serial, SP_PARITY_NONE);
sp_set_stopbits(this->serial, 1);
sp_set_flowcontrol(this->serial, SP_FLOWCONTROL_NONE);
if (sp_open(this->serial, SP_MODE_READ_WRITE) == SP_OK)
{
sp_set_baudrate(this->serial, 9600);
sp_set_bits(this->serial, 8);
sp_set_parity(this->serial, SP_PARITY_NONE);
sp_set_stopbits(this->serial, 1);
sp_set_flowcontrol(this->serial, SP_FLOWCONTROL_NONE);

sp_set_dtr(this->serial, SP_DTR_OFF);
sp_set_rts(this->serial, SP_RTS_OFF);
sp_set_dtr(this->serial, SP_DTR_OFF);
sp_set_rts(this->serial, SP_RTS_OFF);

sp_flush(this->serial, SP_BUF_BOTH);
sp_flush(this->serial, SP_BUF_BOTH);

emg::Log::Info("Flash control connected on '%s'", this->connection);
}
else
{
sp_free_port(this->serial);
this->serial = nullptr;
emg::Log::Info("Flash control connected on '%s'", this->connection);
}
else
{
sp_free_port(this->serial);
this->serial = nullptr;
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
libpsinc0 (0.1.26) unstable; urgency=medium

* Check path exists before attempting to find the canonical path in the Flash helper.

-- Dan <dan@kryten> Sat, 16 Mar 2019 11:17:01 +0000

libpsinc0 (0.1.25) unstable; urgency=medium

* Fix for mingw builds
Expand Down
2 changes: 1 addition & 1 deletion packages/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.25
0.1.26
2 changes: 1 addition & 1 deletion src/psinc/Psinc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "psinc/Psinc.h"

#define PSINC_VERSION "0.1.25"
#define PSINC_VERSION "0.1.26"


namespace psinc
Expand Down

0 comments on commit 9e8c81e

Please sign in to comment.