Files
lighthub/lighthub/modules/out_modbus.h
Andrey 1bfd2d98ef MODBUS: prefetch option for write reg (check-before-write),
AC: suppressing garbage status after CMD,
PID: NOT_FILTER_PID_OUT for repeating values^ by default
2024-08-01 20:19:33 +03:00

54 lines
1.5 KiB
C++

#pragma once
#include "options.h"
#ifndef MBUS_DISABLE
#include <abstractout.h>
#include <item.h>
#include "itemCmd.h"
#include <utils.h>
class mbPersistent : public chPersistent {
public:
int baud;
serialParamType serialParam;
uint16_t pollingInterval;
uint32_t timestamp;
aJsonObject * pollingRegisters;
aJsonObject * pollingIrs;
aJsonObject * pollingCoils;
aJsonObject * poolingDiscreteIns;
aJsonObject * parameters;
};
#define MB_NEED_SEND 8
#define MB_SEND_ERROR 4
#define MB_SEND_ATTEMPTS 3
#define MB_VALUE_OUTDATED 1
class out_Modbus : public abstractOut {
public:
out_Modbus(Item * _item):abstractOut(_item){store = (mbPersistent *) item->getPersistent();};
int Setup() override;
int Poll(short cause) override;
int Stop() override;
int getChanType() override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
//int getDefaultStorageType(){return ST_INT32;};
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
protected:
mbPersistent * store;
bool getConfig();
itemCmd findRegister(uint16_t registerNum, uint16_t posInBuffer, uint8_t regType, uint16_t registerFrom, uint16_t registerTo, bool doExecution = true, bool * submitParam = NULL);
void pollModbus(aJsonObject * reg, int regType);
void initLine();
int sendModbus(char * paramName, aJsonObject * outValue);
int sendItemCmd(aJsonObject *templateParamObj, itemCmd cmd);
};
#endif