Initial commit: HC900 Crawler
Honeywell HC900을 Modbus TCP로 직접 폴링 → gRPC → C# 크롤러 → PostgreSQL. 기존 Experion OPC UA 데이터 경로를 HC900 직접 통신으로 대체. - industrial-comm/cpp: C++ Modbus 게이트웨이 (gRPC 서버) - src: C# .NET 8 ASP.NET Core 크롤러 + 웹 UI (3-Layer) - mcp-server: Python FastMCP (RAG/NL2SQL/P&ID) - 다중 컨트롤러(N-Controller) 지원 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
61
industrial-comm/cpp/include/modbus_tcp.hpp
Normal file
61
industrial-comm/cpp/include/modbus_tcp.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
#include "modbus_exception.hpp"
|
||||
#include "itransport.hpp"
|
||||
#include "transport_error.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
class ModbusTCP : public ITransport {
|
||||
public:
|
||||
ModbusTCP();
|
||||
~ModbusTCP() override;
|
||||
|
||||
bool connect(const char* host, std::uint16_t port) override;
|
||||
void disconnect() override;
|
||||
bool is_connected() const override;
|
||||
|
||||
TransportState state() const override { return state_; }
|
||||
TransportError last_error() const override { return last_error_; }
|
||||
|
||||
bool read_registers(std::uint16_t addr,
|
||||
std::uint16_t count,
|
||||
std::vector<std::uint16_t>& out) override;
|
||||
|
||||
bool write_registers(std::uint16_t addr,
|
||||
const std::vector<std::uint16_t>& values) override;
|
||||
|
||||
void poll() override; // watchdog
|
||||
|
||||
void reset() override;
|
||||
|
||||
private:
|
||||
bool reconnect();
|
||||
bool recv_all(void* buf, std::size_t len);
|
||||
|
||||
private:
|
||||
// socket
|
||||
int sock_;
|
||||
std::uint16_t transaction_id_{0};
|
||||
|
||||
// connection info
|
||||
std::string host_;
|
||||
std::uint16_t port_{0};
|
||||
|
||||
// state machine
|
||||
TransportState state_{TransportState::Disconnected};
|
||||
TransportError last_error_{TransportError::None};
|
||||
ModbusException exception_;
|
||||
|
||||
// watchdog
|
||||
static constexpr int WATCHDOG_SEC = 5;
|
||||
static constexpr int MAX_RETRY = 5;
|
||||
static constexpr int FAULT_RESET_SEC = 30; // Fault 후 자동 리셋 대기
|
||||
std::chrono::steady_clock::time_point last_ok_;
|
||||
std::chrono::steady_clock::time_point fault_since_;
|
||||
int retry_count_{0};
|
||||
bool can_io() const;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user