PR-790 Fix several style issues caused by merging
This commit is contained in:
parent
100302f8e1
commit
2523f6cd3f
|
@ -57,7 +57,7 @@ binding = sized
|
|||
; modbus interface. This starts capabilities to poll one or more Modbus
|
||||
; servers and exchange data with the located variables.
|
||||
|
||||
enabled = true
|
||||
enabled = false
|
||||
|
||||
; We support multiple Modbus masters. Each master should specify
|
||||
; a complete set of configuration information within this section.
|
||||
|
@ -65,21 +65,24 @@ enabled = true
|
|||
; index of the master. Indices start at 0 and go up from there.
|
||||
|
||||
; A user defined name for the connection. This name appears in log messages.
|
||||
name.0 = 1
|
||||
; name.0 = 1
|
||||
|
||||
; How long to wait for a response before indicating an error.
|
||||
; Measured in microseconds.
|
||||
response_timeout.0 = 100000
|
||||
; response_timeout.0 = 100000
|
||||
; The rate at which to poll the server. Measured in microseconds.
|
||||
; The actual poll rate may be greater than this depending on response times
|
||||
; from the remote server and availability of resources on the local host.
|
||||
poll_interval.0 = 250000
|
||||
; poll_interval.0 = 250000
|
||||
|
||||
; The protocol to use for connection. This value must be one of:
|
||||
; tcp
|
||||
; rtu
|
||||
; If you set this to any other value, then this configuration item group
|
||||
; is not created. You might use this to disable connecting to a particular
|
||||
; Modbus slave.
|
||||
poll_interval.0 = 500000
|
||||
; protocol.0 = tcp
|
||||
|
||||
; When there are communication failures, should we keep trying
|
||||
; or backoff intelligently. The default behaviour is no backoff
|
||||
; but you can specify one of the following:
|
||||
|
@ -88,25 +91,25 @@ poll_interval.0 = 500000
|
|||
; linear_bounded - Back off linearly based on the number of
|
||||
; failed attempts. Bounded to 10x the poll
|
||||
; interval.
|
||||
backoff_strategy.0 = linear_bounded
|
||||
protocol.0 = tcp
|
||||
slave_id.0 = 1
|
||||
ip_address.0 = 127.0.0.1
|
||||
ip_port.0 = 1000
|
||||
; rtu_baud_rate.0 =
|
||||
; rtu_parity.0
|
||||
; rtu_data_bit.0
|
||||
; rtu_stop_bit.0
|
||||
discrete_inputs_start.0 = 0
|
||||
discrete_inputs_size.0 = 1
|
||||
;coils_start.0
|
||||
;coils_size.0
|
||||
;input_registers_start.0
|
||||
;input_registers_size.0
|
||||
;holding_registers_read_start.0
|
||||
;holding_registers_read_size.0
|
||||
;holding_registers_start.0
|
||||
;holding_registers_size.0
|
||||
; backoff_strategy.0 = linear_bounded
|
||||
|
||||
; slave_id.0 = 1
|
||||
; ip_address.0 = 127.0.0.1
|
||||
; ip_port.0 = 1000
|
||||
; rtu_baud_rate.0 =
|
||||
; rtu_parity.0 =
|
||||
; rtu_data_bit.0 =
|
||||
; rtu_stop_bit.0 =
|
||||
; discrete_inputs_start.0 = 0
|
||||
; discrete_inputs_size.0 = 1
|
||||
; coils_start.0
|
||||
; coils_size.0
|
||||
; input_registers_start.0
|
||||
; input_registers_size.0
|
||||
; holding_registers_read_start.0
|
||||
; holding_registers_read_size.0
|
||||
; holding_registers_start.0
|
||||
; holding_registers_size.0
|
||||
|
||||
; ---------------------------------------------------------
|
||||
; ---------------------------------------------------------
|
||||
|
@ -119,7 +122,7 @@ enabled = false
|
|||
; How long should we wait between write cycle. The persistent storage
|
||||
; checks at this rate for changes and only persists to disk if a
|
||||
; value has changed within the poll period
|
||||
poll_interval = 10
|
||||
; poll_interval = 10
|
||||
|
||||
; ---------------------------------------------------------
|
||||
; ---------------------------------------------------------
|
||||
|
@ -132,7 +135,7 @@ enabled = false
|
|||
|
||||
; Bind OpenPLC bit-sized output 0.0 to DNP3 binary input at index 0
|
||||
; Note that the second hierarchical index must be 0
|
||||
bind_location = name:%QX0.0,group:1,index:0,
|
||||
; bind_location = name:%QX0.0,group:1,index:0,
|
||||
|
||||
; Bind OpenPLC word-sized output 2 to DNP3 analog input at index 1
|
||||
; bind_location = name:%QW2,group:30,index:1,
|
||||
|
@ -144,33 +147,32 @@ bind_location = name:%QX0.0,group:1,index:0,
|
|||
; bind_location = name:%QL2,group:30,index:10,
|
||||
|
||||
; Bind OpenPLC bit-sized input 0.0 to DNP3 analog input at index 10
|
||||
bind_location = name:%IX0.0,group:12,index:0,
|
||||
bind_location = name:%IX1.0,group:12,index:1,
|
||||
; bind_location = name:%IX0.0,group:12,index:0,
|
||||
; bind_location = name:%IX1.0,group:12,index:1,
|
||||
|
||||
; Bind OpenPLC word-sized input 2 to DNP3 analog command at index 0
|
||||
; bind_location = name:%IW2,group:41,index:0,
|
||||
|
||||
; TCP Settings
|
||||
; ------------
|
||||
address = 127.0.0.1
|
||||
port = 20000
|
||||
; address = 127.0.0.1
|
||||
; port = 20000
|
||||
|
||||
; Link Settings
|
||||
; -------------
|
||||
|
||||
; The remote and local address
|
||||
local_address = 10
|
||||
remote_address = 1
|
||||
; local_address = 10
|
||||
; remote_address = 1
|
||||
|
||||
; Keep alive timeout. A value in seconds, or the keyword MAX
|
||||
; keep_alive_timeout = MAX
|
||||
|
||||
|
||||
; Parameters
|
||||
; ----------
|
||||
|
||||
; Enable unsolicited reporting if master allows it
|
||||
enable_unsolicited = true
|
||||
; enable_unsolicited = true
|
||||
|
||||
; How long (seconds) the outstation will allow a operate
|
||||
; to follow a select
|
||||
|
|
|
@ -155,7 +155,8 @@ void bootstrap()
|
|||
struct sched_param sp;
|
||||
sp.sched_priority = 30;
|
||||
spdlog::info("Setting main thread priority to RT");
|
||||
if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) {
|
||||
if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp))
|
||||
{
|
||||
spdlog::warn("Failed to set main thread to real-time priority");
|
||||
}
|
||||
|
||||
|
@ -174,7 +175,8 @@ void bootstrap()
|
|||
// Our next step here is to start the main loop, so start any
|
||||
// services that we want now.
|
||||
|
||||
for (auto it = config.services.begin(); it != config.services.end(); ++it) {
|
||||
for (auto it = config.services.begin(); it != config.services.end(); ++it)
|
||||
{
|
||||
const char* service_config = "";
|
||||
ServiceDefinition* def = services_find(it->c_str());
|
||||
def->start(service_config);
|
||||
|
|
|
@ -217,24 +217,25 @@ struct ContiguousMappedValues
|
|||
template <typename T>
|
||||
struct MappedValue
|
||||
{
|
||||
MappedValue() : cached_value(0), value(nullptr) {}
|
||||
T cached_value;
|
||||
T* value;
|
||||
MappedValue() : cached_value(0), value(nullptr) {}
|
||||
T cached_value;
|
||||
T* value;
|
||||
|
||||
/// Initialize the glue link and the cached value.
|
||||
/// @param val The glue variable to initialize from.
|
||||
inline void init(T* val)
|
||||
{
|
||||
this->value = val;
|
||||
this->cached_value = *val;
|
||||
}
|
||||
|
||||
inline void update_cache()
|
||||
{
|
||||
if (this->value) {
|
||||
this->cached_value = *this->value;
|
||||
/// Initialize the glue link and the cached value.
|
||||
/// @param val The glue variable to initialize from.
|
||||
inline void init(T* val)
|
||||
{
|
||||
this->value = val;
|
||||
this->cached_value = *val;
|
||||
}
|
||||
|
||||
inline void update_cache()
|
||||
{
|
||||
if (this->value)
|
||||
{
|
||||
this->cached_value = *this->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// Defines a write that has been submitted via a protocol
|
||||
|
@ -243,16 +244,17 @@ struct MappedValue
|
|||
/// items having the same indices for efficient lookup to the
|
||||
/// located variable.
|
||||
template <typename T>
|
||||
struct PendingValue {
|
||||
PendingValue() : has_pending(false), value(0) {}
|
||||
bool has_pending;
|
||||
T value;
|
||||
struct PendingValue
|
||||
{
|
||||
PendingValue() : has_pending(false), value(0) {}
|
||||
bool has_pending;
|
||||
T value;
|
||||
|
||||
/// Set the value and mark it as updated.
|
||||
inline void set(T val) {
|
||||
this->has_pending = true;
|
||||
this->value = val;
|
||||
}
|
||||
/// Set the value and mark it as updated.
|
||||
inline void set(T val) {
|
||||
this->has_pending = true;
|
||||
this->value = val;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace oplc
|
||||
|
|
|
@ -80,7 +80,8 @@ class Dnp3ToSpdLogger final : public openpal::ILogHandler, private openpal::Unco
|
|||
spdlog::info("{}", entry.message);
|
||||
}
|
||||
|
||||
static std::shared_ptr<openpal::ILogHandler>Create() {
|
||||
static std::shared_ptr<openpal::ILogHandler>Create()
|
||||
{
|
||||
return std::make_shared<Dnp3ToSpdLogger>();
|
||||
}
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@ inline int strcmp_with_index(const char* name, const char* expected,
|
|||
}
|
||||
|
||||
size_t name_len = strlen(name);
|
||||
if (name_len >= expected_len + 2 && name[expected_len] == '.') {
|
||||
if (name_len >= expected_len + 2 && name[expected_len] == '.')
|
||||
{
|
||||
auto read_index = atoi(name + (expected_len + 1));
|
||||
if (read_index <= max_index) {
|
||||
if (read_index <= max_index)
|
||||
{
|
||||
*index = read_index;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -242,39 +242,45 @@ void interactive_client_command(const char* command, int client_fd)
|
|||
|
||||
spdlog::trace("Process command received {}", command);
|
||||
|
||||
if (strncmp(command, "quit()", 6) == 0) {
|
||||
if (strncmp(command, "quit()", 6) == 0)
|
||||
{
|
||||
spdlog::info("Issued quit() command");
|
||||
run_openplc = 0;
|
||||
}
|
||||
else if (strncmp(command, "start_modbus(", 13) == 0) {
|
||||
else if (strncmp(command, "start_modbus(", 13) == 0)
|
||||
{
|
||||
ServiceDefinition* def = services_find("modbusslave");
|
||||
if (def && copy_command_config(command + 13, command_buffer, BUFFER_MAX_SIZE) == 0)
|
||||
{
|
||||
def->start(command_buffer);
|
||||
}
|
||||
}
|
||||
else if (strncmp(command, "stop_modbus()", 13) == 0) {
|
||||
else if (strncmp(command, "stop_modbus()", 13) == 0)
|
||||
{
|
||||
ServiceDefinition* def = services_find("modbusslave");
|
||||
if (def) {
|
||||
def->stop();
|
||||
}
|
||||
}
|
||||
#ifdef OPLC_DNP3_OUTSTATION
|
||||
else if (strncmp(command, "start_dnp3(", 11) == 0) {
|
||||
else if (strncmp(command, "start_dnp3(", 11) == 0)
|
||||
{
|
||||
ServiceDefinition* def = services_find("dnp3s");
|
||||
if (def && copy_command_config(command + 11, command_buffer, BUFFER_MAX_SIZE) == 0)
|
||||
{
|
||||
def->start(command_buffer);
|
||||
}
|
||||
}
|
||||
else if (strncmp(command, "stop_dnp3()", 11) == 0) {
|
||||
else if (strncmp(command, "stop_dnp3()", 11) == 0)
|
||||
{
|
||||
ServiceDefinition* def = services_find("dnp3s");
|
||||
if (def) {
|
||||
def->stop();
|
||||
}
|
||||
}
|
||||
#endif // OPLC_DNP3_OUTSTATION
|
||||
else if (strncmp(command, "start_enip(", 11) == 0) {
|
||||
else if (strncmp(command, "start_enip(", 11) == 0)
|
||||
{
|
||||
spdlog::info("Issued start_enip() command to start on port: {}", readCommandArgument(command));
|
||||
enip_port = readCommandArgument(command);
|
||||
if (run_enip) {
|
||||
|
@ -288,7 +294,8 @@ void interactive_client_command(const char* command, int client_fd)
|
|||
run_enip = 1;
|
||||
pthread_create(&enip_thread, NULL, enipThread, NULL);
|
||||
}
|
||||
else if (strncmp(command, "stop_enip()", 11) == 0) {
|
||||
else if (strncmp(command, "stop_enip()", 11) == 0)
|
||||
{
|
||||
spdlog::info("Issued stop_enip() command");
|
||||
if (run_enip)
|
||||
{
|
||||
|
@ -297,33 +304,38 @@ void interactive_client_command(const char* command, int client_fd)
|
|||
spdlog::info("EtherNet/IP server was stopped");
|
||||
}
|
||||
}
|
||||
else if (strncmp(command, "start_pstorage(", 15) == 0) {
|
||||
else if (strncmp(command, "start_pstorage(", 15) == 0)
|
||||
{
|
||||
ServiceDefinition* def = services_find("pstorage");
|
||||
if (def && copy_command_config(command + 15, command_buffer, BUFFER_MAX_SIZE) == 0)
|
||||
{
|
||||
def->start(command_buffer);
|
||||
}
|
||||
}
|
||||
else if (strncmp(command, "stop_pstorage()", 15) == 0) {
|
||||
else if (strncmp(command, "stop_pstorage()", 15) == 0)
|
||||
{
|
||||
ServiceDefinition* def = services_find("pstorage");
|
||||
if (def) {
|
||||
def->stop();
|
||||
}
|
||||
}
|
||||
else if (strncmp(command, "runtime_logs()", 14) == 0) {
|
||||
else if (strncmp(command, "runtime_logs()", 14) == 0)
|
||||
{
|
||||
spdlog::debug("Issued runtime_logs() command");
|
||||
std::string data = log_sink->data();
|
||||
write(client_fd, data.c_str(), data.size());
|
||||
return;
|
||||
}
|
||||
else if (strncmp(command, "exec_time()", 11) == 0) {
|
||||
else if (strncmp(command, "exec_time()", 11) == 0)
|
||||
{
|
||||
time_t end_time;
|
||||
time(&end_time);
|
||||
int count_char = sprintf(command_buffer, "%llu\n", (unsigned long long)difftime(end_time, start_time));
|
||||
write(client_fd, command_buffer, count_char);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
int count_char = sprintf(command_buffer, "Error: unrecognized command\n");
|
||||
write(client_fd, command_buffer, count_char);
|
||||
return;
|
||||
|
|
|
@ -166,12 +166,12 @@ int main(int argc, char **argv)
|
|||
//======================================================
|
||||
// MAIN LOOP
|
||||
//======================================================
|
||||
while (run_openplc) {
|
||||
while (run_openplc)
|
||||
{
|
||||
|
||||
// Read input image - this method tries to get the lock
|
||||
// so don't put it in the lock context.
|
||||
updateBuffersIn();
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(bufferLock);
|
||||
updateCustomIn();
|
||||
|
|
|
@ -32,18 +32,6 @@ namespace modbusm
|
|||
|
||||
#define MAX_MB_IO 400
|
||||
|
||||
struct InputOutputBuffer {
|
||||
std::uint8_t bool_input_buf[MAX_MB_IO];
|
||||
std::uint8_t bool_output_buf[MAX_MB_IO];
|
||||
std::uint16_t int_input_buf[MAX_MB_IO];
|
||||
std::uint16_t int_output_buf[MAX_MB_IO];
|
||||
|
||||
/// A count of how many errors have occurred since the last
|
||||
/// exchange. This value should be reset to 0 after each
|
||||
/// write-cycle.
|
||||
IEC_LINT error;
|
||||
};
|
||||
|
||||
/// @brief Define the mapping for modbus addresses to located variables
|
||||
/// that is is based on a sequence starting an an offset in the located
|
||||
/// variables and an offset in the Modbus server.
|
||||
|
|
|
@ -38,7 +38,8 @@ ServiceDefinition* services[] = {
|
|||
|
||||
ServiceDefinition* services_find(const char* name)
|
||||
{
|
||||
ServiceDefinition** item = find_if(begin(services), end(services), [name] (ServiceDefinition* def) {
|
||||
ServiceDefinition** item = find_if(begin(services), end(services), [name] (ServiceDefinition* def)
|
||||
{
|
||||
return strcmp(def->id(), name) == 0;
|
||||
});
|
||||
|
||||
|
@ -47,33 +48,38 @@ ServiceDefinition* services_find(const char* name)
|
|||
|
||||
void services_stop()
|
||||
{
|
||||
for_each(begin(services), end(services), [] (ServiceDefinition* def) {
|
||||
for_each(begin(services), end(services), [] (ServiceDefinition* def)
|
||||
{
|
||||
def->stop();
|
||||
});
|
||||
}
|
||||
|
||||
void services_init()
|
||||
{
|
||||
for_each(begin(services), end(services), [] (ServiceDefinition* def) {
|
||||
for_each(begin(services), end(services), [] (ServiceDefinition* def)
|
||||
{
|
||||
def->initialize();
|
||||
});
|
||||
}
|
||||
|
||||
void services_finalize()
|
||||
{
|
||||
for_each(begin(services), end(services), [] (ServiceDefinition* def) {
|
||||
for_each(begin(services), end(services), [] (ServiceDefinition* def)
|
||||
{
|
||||
def->finalize();
|
||||
});
|
||||
}
|
||||
|
||||
void services_before_cycle() {
|
||||
std::for_each(std::begin(services), std::end(services), [] (ServiceDefinition* def) {
|
||||
std::for_each(std::begin(services), std::end(services), [] (ServiceDefinition* def)
|
||||
{
|
||||
def->before_cycle();
|
||||
});
|
||||
}
|
||||
|
||||
void services_after_cycle() {
|
||||
std::for_each(std::begin(services), std::end(services), [] (ServiceDefinition* def) {
|
||||
std::for_each(std::begin(services), std::end(services), [] (ServiceDefinition* def)
|
||||
{
|
||||
def->after_cycle();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
- lib
|
||||
- vendor
|
||||
- hardware_layers
|
||||
- test/mock_headers
|
||||
- test
|
||||
~ RULE_3_1_A_do_not_start_filename_with_underbar
|
||||
~ RULE_3_2_B_do_not_use_same_filename_more_than_once
|
||||
~ RULE_3_2_CD_do_not_use_special_characters_in_filename
|
||||
~ RULE_3_2_F_use_representitive_classname_for_cpp_filename
|
||||
~ RULE_3_2_H_do_not_use_uppercase_for_c_filename
|
||||
~ RULE_3_3_A_start_function_name_with_is_or_has_when_return_bool
|
||||
~ RULE_3_3_A_start_function_name_with_lowercase_unix
|
||||
~ RULE_3_3_B_start_private_function_name_with_underbar
|
||||
~ RULE_4_1_A_B_use_space_for_indentation
|
||||
~ RULE_4_1_B_indent_each_enum_item_in_enum_block
|
||||
~ RULE_4_1_B_locate_each_enum_item_in_seperate_line
|
||||
~ RULE_4_1_C_align_long_function_parameter_list
|
||||
~ RULE_4_1_E_align_conditions
|
||||
~ RULE_4_2_A_A_space_around_operator
|
||||
~ RULE_4_2_A_B_space_around_word
|
||||
~ RULE_4_4_A_do_not_write_over_120_columns_per_line
|
||||
~ RULE_4_5_A_brace_for_namespace_should_be_located_in_seperate_line
|
||||
~ RULE_4_5_A_braces_for_function_definition_should_be_located_in_seperate_line
|
||||
~ RULE_4_5_A_braces_for_type_definition_should_be_located_in_seperate_line
|
||||
~ RULE_4_5_A_braces_inside_of_function_should_be_located_in_end_of_line
|
||||
~ RULE_4_5_A_indent_blocks_inside_of_function
|
||||
~ RULE_4_5_A_matching_braces_inside_of_function_should_be_located_same_column
|
||||
~ RULE_4_5_B_use_braces_even_for_one_statement
|
||||
~ RULE_6_1_A_do_not_omit_function_parameter_names
|
||||
~ RULE_6_1_E_do_not_use_more_than_5_paramters_in_function
|
||||
~ RULE_6_1_G_write_less_than_200_lines_for_function
|
||||
~ RULE_6_2_A_do_not_use_system_dependent_type
|
||||
~ RULE_6_4_B_initialize_first_item_of_enum
|
||||
~ RULE_6_5_B_do_not_use_lowercase_for_macro_constants
|
||||
~ RULE_6_5_B_do_not_use_macro_for_constants
|
||||
~ RULE_7_1_B_A_do_not_use_double_assignment
|
||||
~ RULE_7_2_B_do_not_use_goto_statement
|
||||
~ RULE_8_1_A_provide_file_info_comment
|
||||
~ RULE_9_1_A_do_not_use_hardcorded_include_path
|
||||
~ RULE_9_2_D_use_reentrant_function
|
||||
~ RULE_A_3_avoid_too_deep_blocks
|
Loading…
Reference in New Issue