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

High-Speed-Mode TCP Implementation #10

Open
wants to merge 2 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
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ project(keyence_experimental)

include_directories(include)

add_definitions(-std=c++11 -Wall -Wextra)

# Boost is used for threads
FIND_PACKAGE( Boost 1.54 COMPONENTS system thread REQUIRED )

# Build the underlying implementation library
add_library(keyence_impl src/impl/keyence_tcp_client.cpp
# messages
src/impl/messages/high_speed_single_profile.cpp
src/impl/ljv7_rawdata.cpp)
target_link_libraries(keyence_impl socket++)
src/impl/ljv7_rawdata.cpp
src/impl/messages/prepare_high_speed.cpp
src/impl/messages/start_high_speed.cpp
src/impl/keyence_high_speed_tcp.cpp)

target_link_libraries(keyence_impl socket++ ${Boost_LIBRARIES})

# Build test program for changing active program
add_executable(keyence_change_program src/utilities/change_program.cpp)
Expand All @@ -16,3 +26,11 @@ target_link_libraries(keyence_change_program keyence_impl)
# Build test program for single keyence profile
add_executable(keyence_get_profile src/utilities/get_profile.cpp)
target_link_libraries(keyence_get_profile keyence_impl)

# Build test program for starting high speed mode with raw request calls
add_executable(keyence_highspeed_raw src/utilities/high_speed_raw.cpp)
target_link_libraries(keyence_highspeed_raw keyence_impl)

# Build test program for starting high speed mode with helper interface
add_executable(keyence_highspeed src/utilities/high_speed.cpp)
target_link_libraries(keyence_highspeed keyence_impl)
43 changes: 43 additions & 0 deletions include/keyence/impl/keyence_high_speed_tcp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef KEYENCE_HIGH_SPEED_TCP_H
#define KEYENCE_HIGH_SPEED_TCP_H

#include "keyence/impl/keyence_tcp_client.h"
#include "keyence/impl/high_speed_defs.h"

#include <boost/function.hpp>

namespace keyence
{

class HighSpeedTcpClient
{
public:
// Callback types
typedef boost::function<void(int32_t*, uint32_t)> callback_type;

// Constructors
HighSpeedTcpClient(TcpClient& client, const std::string& port);

~HighSpeedTcpClient();

const ProfileInformation& profileInfo() const;

void start(callback_type cb);

void stop();

private:
HighSpeedTcpClient operator=(const HighSpeedTcpClient&); // deleted
HighSpeedTcpClient(const HighSpeedTcpClient&); // deleted


TcpClient& client_;
// Pimpl technique
struct Impl;
Impl* impl_;
};

}

#endif // KEYENCE_HIGH_SPEED_TCP_H

3 changes: 3 additions & 0 deletions include/keyence/impl/keyence_tcp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class TcpClient : public Client
virtual int send(const void* data, std::size_t size); // override
virtual int recv(void* data, std::size_t size); // override

std::string hostName() const { return sock_.gethost(); }
std::string hostPort() const { return sock_.getport(); }

protected:
libsocket::inet_stream sock_;
};
Expand Down
52 changes: 52 additions & 0 deletions include/keyence/impl/messages/prepare_high_speed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef PREPARE_HIGH_SPEED_H
#define PREPARE_HIGH_SPEED_H

#include "../keyence_message.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you chose to use relative references here? Why not include paths relative to the package include?

#include "../high_speed_defs.h"

namespace keyence
{
namespace command
{

class PrepareHighSpeed
{
public:
// Forward declares
struct Request;
struct Response;

struct Request
{
// Required definitions
typedef Response response_type;
const static uint32_t size = 4;
const static uint8_t command_code = 0x47;
// Constructor
enum StartPosition { POSITION_PREVIOUS, POSITION_OLDEST, POSITION_NEXT };

Request(StartPosition position);

// Request Data
uint8_t send_position;

// Required encode function
void encodeInto(MutableBuffer buffer);
};

struct Response
{
ProfileInformation profile_info;
uint32_t start_code;

void decodeFrom(MutableBuffer buffer);
};

};

} // namespace command
} // namespace keyence


#endif // PREPARE_HIGH_SPEED_H

48 changes: 48 additions & 0 deletions include/keyence/impl/messages/start_high_speed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef START_HIGH_SPEED_H
#define START_HIGH_SPEED_H

#include "../keyence_message.h"
#include "../high_speed_defs.h"

namespace keyence
{
namespace command
{

class StartHighSpeed
{
public:
// Forward declares
struct Request;
struct Response;

struct Request
{
// Required definitions
typedef Response response_type;
const static uint32_t size = 8;
const static uint8_t command_code = 0xA0;

Request(uint32_t code);

// Request Data
uint32_t start_code;

// Required encode function
void encodeInto(MutableBuffer buffer);
};

struct Response
{
void decodeFrom(MutableBuffer) {}
};

};

} // namespace command
} // namespace keyence



#endif // START_HIGH_SPEED_H

38 changes: 38 additions & 0 deletions include/keyence/impl/messages/stop_high_speed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef STOP_HIGH_SPEED_H
#define STOP_HIGH_SPEED_H

namespace keyence
{
namespace command
{

class StopHighSpeed
{
public:
// Forward declares
struct Request;
struct Response;

struct Request
{
// Required definitions
typedef Response response_type;
const static uint32_t size = 0;
const static uint8_t command_code = 0x48;

// Required encode function
void encodeInto(MutableBuffer) {}
};

struct Response
{
void decodeFrom(MutableBuffer) {}
};

};

} // namespace command
} // namespace keyence

#endif // STOP_HIGH_SPEED_H

Loading