102 lines
5.4 KiB
C++
102 lines
5.4 KiB
C++
#ifndef _IO_BOX_API_H_
|
|
#define _IO_BOX_API_H_
|
|
#define ANSIO_API __declspec(dllexport)
|
|
#include "extcode.h"
|
|
#include <vector>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
#include <chrono>
|
|
#include <mutex>
|
|
#pragma comment(lib,"WS2_32")
|
|
// #pragma comment(lib, "Ws2_32.lib")
|
|
// #define TEST_FIX_IP
|
|
#define DEVICE_TCP_PORT 502
|
|
#define DEVICE_DATA_ADDRESS 100
|
|
#define DEVICE_DATA_LENGTH 17
|
|
namespace ANSCENTER {
|
|
typedef struct {
|
|
std::string model;
|
|
std::string ip_address;
|
|
std::string ip_public_address; //public ip
|
|
std::string mac_address;
|
|
std::string serial_number;
|
|
std::string firmware_version;
|
|
std::string hardware_version;
|
|
std::vector<std::string> channelNameList;
|
|
} iobox_info_t;
|
|
|
|
typedef struct {
|
|
int counting_get;
|
|
bool is_connected;
|
|
bool is_anthenticated;
|
|
SOCKET sock_tcp;
|
|
iobox_info_t iobox_info;
|
|
} iobox_profile_t;
|
|
class ANSIO_API iobox_api
|
|
{
|
|
private:
|
|
std::recursive_mutex _mutex;
|
|
std::string ip_mcast; //ip multicast
|
|
int port_mcast; //port multicast
|
|
std::vector<iobox_profile_t> iobox_profiles;
|
|
iobox_profile_t* findProfileByIp(const std::string& ip);
|
|
void save_info_iobox(iobox_info_t iobox_info);
|
|
void setSocketTimeout(SOCKET sock, int timeout);
|
|
void sendMulticastMessage(const std::string& message);
|
|
bool sendTcpMessage(const std::string& ip, const char* buffer, size_t length, bool needCheckAuthen);
|
|
bool receiveTcpMessage(const std::string& ip, char* buffer, size_t& length);
|
|
void show_profile_iobox(iobox_profile_t profile);
|
|
bool connectToIoboxWithoutAuthen(const std::string& ip, int port);
|
|
void remove_last_info_iobox();
|
|
uint16_t getIndexIoboxFromIp(const std::string& ip);
|
|
public:
|
|
iobox_api(std::string ip_mcast, int port_mcast);
|
|
~iobox_api();
|
|
void show_profile_iobox(std::string ip);
|
|
void show_profile_ioboxs();
|
|
std::string generateToken(const std::string& ip);
|
|
std::vector<std::string> scanNetworkDevicesMulticast(int timeout);
|
|
bool setAuthenticationIobox(const std::string& ip, const std::string& username, const std::string& password);
|
|
bool resetAuthenticationIobox(const std::string& ip, const std::string& token);
|
|
bool resetIobox(const std::string& ip, const std::string& token);
|
|
std::string connectToIobox(const std::string& ip, int port, const std::string& username, const std::string& password);
|
|
bool disconnectToIobox(const std::string& ip);
|
|
std::vector<std::string> getDeviceChannelNames(const std::string& ip);
|
|
std::string getValueDataStringIoboxFromChannelName(const std::string& ip, const std::string& channelName);
|
|
bool setValueDataStringIoboxFromChannelName(const std::string& ip, const std::string& channelName, const std::string& value);
|
|
|
|
// RS232
|
|
bool openRS232(const std::string& ip, const std::string& port, int baudrate, int databits, int stopbits, int parity);
|
|
bool closeRS232(const std::string& ip);
|
|
bool writeRS232(const std::string& ip, std::string dataToSend, int timeout);
|
|
bool readRS232(const std::string& ip, std::string &receivedData, const std::string& terminateString,int timeout);
|
|
bool readRS232Bytes(const std::string& ip, std::string& receivedData, int numBytes, int timeout);
|
|
|
|
};
|
|
}
|
|
extern "C" ANSIO_API int CreateANSIOHandle(ANSCENTER::iobox_api** Handle, const char* multicastIPAddress, int multicastPort);
|
|
extern "C" ANSIO_API int ScanANSIOHandle(ANSCENTER::iobox_api** Handle, int timeout, LStrHandle ipAddresses);
|
|
extern "C" ANSIO_API int ConnectANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, int ioBoxPort, const char* userName, const char* passWord, LStrHandle deviceStr);
|
|
extern "C" ANSIO_API int DisconnectANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP);
|
|
extern "C" ANSIO_API int GetChannelNamesANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, int timeout, LStrHandle channelNames);
|
|
extern "C" ANSIO_API int SetValueANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, const char* channelName, const char* value);
|
|
extern "C" ANSIO_API int GetValueANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, const char* channelName, LStrHandle lStrValue);
|
|
extern "C" ANSIO_API int SetAuthenticationANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, const char* userName, const char* passWord);
|
|
extern "C" ANSIO_API int ReleaseANSIOHandle(ANSCENTER::iobox_api** Handle);
|
|
extern "C" ANSIO_API int ResetAuthenticationANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, const char* token);
|
|
extern "C" ANSIO_API int ResetANSIOHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, const char* token);
|
|
extern "C" ANSIO_API int GenerateANSIOTokenHandle(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, LStrHandle tokenStr);
|
|
|
|
// C++ interface
|
|
extern "C" ANSIO_API int ScanANSIOHandle_CPP(ANSCENTER::iobox_api** Handle, int timeout, std::string& ipAddresses);
|
|
extern "C" ANSIO_API int GetChannelNamesANSIOHandle_CPP(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, int timeout, std::string& channelNames);
|
|
extern "C" ANSIO_API int GetValueANSIOHandle_CPP(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, const char* channelName, std::string& lStrValue);
|
|
extern "C" ANSIO_API int GenerateANSIOTokenHandle_CPP(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, std::string& tokenStr);
|
|
extern "C" ANSIO_API int ConnectANSIOHandle_CPP(ANSCENTER::iobox_api** Handle, const char* ioBoxIP, int ioBoxPort, const char* userName, const char* passWord, std::string& deviceStr);
|
|
|
|
#endif
|
|
|
|
|