-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for SERIAL transport on Windows
Signed-off-by: THOMAS Sebastien <[email protected]>
- Loading branch information
1 parent
2cbbc4a
commit d2edf12
Showing
9 changed files
with
605 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef UXR_AGENT_TRANSPORT_SERIAL_SERIALAGENTWINDOWS_HPP_ | ||
#define UXR_AGENT_TRANSPORT_SERIAL_SERIALAGENTWINDOWS_HPP_ | ||
|
||
#include <uxr/agent/transport/Server.hpp> | ||
#include <uxr/agent/transport/endpoint/SerialEndPoint.hpp> | ||
#include <uxr/agent/transport/stream_framing/StreamFramingProtocol.hpp> | ||
|
||
#include <cstdint> | ||
#include <cstddef> | ||
#include <WinSock2.h> | ||
|
||
namespace eprosima { | ||
namespace uxr { | ||
|
||
class SerialAgent : public Server<SerialEndPoint> | ||
{ | ||
public: | ||
SerialAgent( | ||
uint8_t addr, | ||
Middleware::Kind middleware_kind); | ||
|
||
#ifdef UAGENT_DISCOVERY_PROFILE | ||
bool has_discovery() final { return false; } | ||
#endif | ||
|
||
#ifdef UAGENT_P2P_PROFILE | ||
bool has_p2p() final { return false; } | ||
#endif | ||
|
||
private: | ||
virtual bool init() = 0; | ||
|
||
virtual bool fini() = 0; | ||
|
||
bool recv_message( | ||
InputPacket<SerialEndPoint>& input_packet, | ||
int timeout, | ||
TransportRc& transport_rc) final; | ||
|
||
bool send_message( | ||
OutputPacket<SerialEndPoint> output_packet, | ||
TransportRc& transport_rc) final; | ||
|
||
ssize_t write_data( | ||
uint8_t* buf, | ||
size_t len, | ||
TransportRc& transport_rc); | ||
|
||
ssize_t read_data( | ||
uint8_t* buf, | ||
size_t len, | ||
int timeout, | ||
TransportRc& transport_rc); | ||
|
||
protected: | ||
const uint8_t addr_; | ||
HANDLE serial_handle; | ||
uint8_t buffer_[SERVER_BUFFER_SIZE]; | ||
FramingIO framing_io_; | ||
}; | ||
|
||
} // namespace uxr | ||
} // namespace eprosima | ||
|
||
#endif // UXR_AGENT_TRANSPORT_SERIAL_SERIALAGENTWINDOWS_HPP_ |
49 changes: 49 additions & 0 deletions
49
include/uxr/agent/transport/serial/TermiosAgentWindows.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef UXR_AGENT_TRANSPORT_SERIAL_TERMIOSAGENTWINDOWS_HPP_ | ||
#define UXR_AGENT_TRANSPORT_SERIAL_TERMIOSAGENTWINDOWS_HPP_ | ||
|
||
#include <uxr/agent/transport/serial/SerialAgentWindows.hpp> | ||
namespace eprosima { | ||
namespace uxr { | ||
|
||
class TermiosAgent : public SerialAgent | ||
{ | ||
public: | ||
TermiosAgent( | ||
char const * dev, | ||
DCB const & termios_attrs, | ||
uint8_t addr, | ||
Middleware::Kind middleware_kind); | ||
|
||
~TermiosAgent(); | ||
|
||
HANDLE getfd() { return serial_handle; }; | ||
|
||
private: | ||
bool init() final; | ||
bool fini() final; | ||
bool handle_error( | ||
TransportRc transport_rc) final; | ||
|
||
private: | ||
const std::string dev_; | ||
const DCB termios_attrs_; | ||
}; | ||
|
||
} // namespace uxr | ||
} // namespace eprosima | ||
|
||
#endif // UXR_AGENT_TRANSPORT_SERIAL_TERMIOSAGENTWINDOWS_HPP_ |
86 changes: 86 additions & 0 deletions
86
include/uxr/agent/transport/serial/baud_rate_table_windows.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef UXR_AGENT_TRANSPORT_SERIAL_BAUD_RATE_TABLE_H | ||
#define UXR_AGENT_TRANSPORT_SERIAL_BAUD_RATE_TABLE_H | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
inline | ||
DWORD getBaudRate(const char* baudrate_str) | ||
{ | ||
DWORD rv; | ||
if (0 == strcmp(baudrate_str, "0")) | ||
{ | ||
rv = 0; | ||
} | ||
else if (0 == strcmp(baudrate_str, "110")) | ||
{ | ||
rv = CBR_110; | ||
} | ||
else if (0 == strcmp(baudrate_str, "300")) { | ||
rv = CBR_300; | ||
} | ||
else if (0 == strcmp(baudrate_str, "600")) { | ||
rv = CBR_600; | ||
} | ||
else if (0 == strcmp(baudrate_str, "1200")) { | ||
rv = CBR_1200; | ||
} | ||
else if (0 == strcmp(baudrate_str, "2400")) { | ||
rv = CBR_2400; | ||
} | ||
else if (0 == strcmp(baudrate_str, "4800")) { | ||
rv = CBR_4800; | ||
} | ||
else if (0 == strcmp(baudrate_str, "9600")) { | ||
rv = CBR_9600; | ||
} | ||
else if (0 == strcmp(baudrate_str, "14400")) { | ||
rv = CBR_14400; | ||
} | ||
else if (0 == strcmp(baudrate_str, "19200")) { | ||
rv = CBR_19200; | ||
} | ||
else if (0 == strcmp(baudrate_str, "38400")) { | ||
rv = CBR_38400; | ||
} | ||
else if (0 == strcmp(baudrate_str, "56000")) { | ||
rv = CBR_56000; | ||
} | ||
else if (0 == strcmp(baudrate_str, "57600")) { | ||
rv = CBR_57600; | ||
} | ||
else if (0 == strcmp(baudrate_str, "115200")) { | ||
rv = CBR_115200; | ||
} | ||
else if (0 == strcmp(baudrate_str, "128000")) { | ||
rv = CBR_128000; | ||
} | ||
else if (0 == strcmp(baudrate_str, "256000")) { | ||
rv = CBR_256000; | ||
} | ||
else | ||
{ | ||
DWORD custom_baud_rate = (DWORD)atoi(baudrate_str); | ||
printf("Warning: Custom baud rate set to: %d\n", custom_baud_rate); | ||
rv = custom_baud_rate; | ||
} | ||
return rv; | ||
} | ||
|
||
#endif // UXR_AGENT_TRANSPORT_SERIAL_BAUD_RATE_TABLE_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.