LightHub  v4.0.0
Smarthome controller firmware
out_uartbridge.h
Go to the documentation of this file.
1 #pragma once
2 #include "options.h"
3 #ifdef UARTBRIDGE_ENABLE
4 #include <abstractout.h>
5 #include <item.h>
6 #include "itemCmd.h"
7 #include "utils.h"
8 
9 #if defined(ESP32)
10 #define serialParamType uint32_t
11 #else
12 #define serialParamType uint16_t
13 #endif
14 
15 #define SOURCE_PORT_A 5551
16 #define SOURCE_PORT_B 5552
17 #define MAX_PDU 64
18 
19 #ifndef MODULE_UATRBRIDGE_UARTA
20 #define MODULE_UATRBRIDGE_UARTA Serial1
21 #endif
22 
23 #ifndef MODULE_UATRBRIDGE_UARTB
24 #define MODULE_UATRBRIDGE_UARTB Serial2
25 #endif
26 
27 #ifndef MODULE_UATRBRIDGE_UARTA_RX_PIN
28 #define MODULE_UATRBRIDGE_UARTA_RX_PIN 15
29 #endif
30 
31 #ifndef MODULE_UATRBRIDGE_UARTA_TX_PIN
32 #define MODULE_UATRBRIDGE_UARTA_TX_PIN 2
33 #endif
34 
35 #ifndef MODULE_UATRBRIDGE_UARTB_RX_PIN
36 #define MODULE_UATRBRIDGE_UARTB_RX_PIN -1
37 #endif
38 
39 #ifndef MODULE_UATRBRIDGE_UARTB_TX_PIN
40 #define MODULE_UATRBRIDGE_UARTB_TX_PIN -1
41 #endif
42 
43 class ubPersistent : public chPersistent {
44 
45 public:
46 // int addr
47  int8_t driverStatus;
48  int baud;
49  serialParamType serialParam;
50  //uint16_t pollingInterval;
51  //uint32_t timestamp;
52  //aJsonObject * pollingRegisters;
53  //aJsonObject * pollingIrs;
54  //aJsonObject * parameters;
55 };
56 
57 #define PDELAY 10
58 
59 class out_UARTbridge : public abstractOut {
60 public:
61 
62  out_UARTbridge(Item * _item):abstractOut(_item){store = (ubPersistent *) item->getPersistent();};
63  int Setup() override;
64  int Poll(short cause) override;
65  int Stop() override;
66  int Status() override;
67  int getChanType() override;
68  int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
69  int getDefaultStorageType(){return ST_INT32;};
70  //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
71 
72 protected:
73  ubPersistent * store;
74  bool getConfig();
75 // int findRegister(int registerNum, int posInBuffer, int regType);
76 // void pollModbus(aJsonObject * reg, int regType);
77 };
78 #endif
abstractOut::Ctrl
virtual int Ctrl(itemCmd cmd, char *subItem=NULL, bool toExecute=true)=0
itemCmd.h
itemCmd
Definition: itemCmd.h:153
abstractCh::Stop
virtual int Stop()
Definition: abstractch.h:15
chPersistent
Definition: abstractout.h:7
ST_INT32
#define ST_INT32
Definition: itemCmd.h:96
serialParamType
#define serialParamType
Definition: utils.h:49
options.h
abstractOut
Definition: abstractout.h:8
utils.h
abstractOut::getDefaultStorageType
virtual int getDefaultStorageType()
Definition: abstractout.h:15
Item
Definition: item.h:104
abstractout.h
abstractOut::Setup
int Setup() override
Remove?? Now getChanType used instead.
Definition: abstractout.cpp:20
abstractCh::Poll
virtual int Poll(short cause)=0
abstractOut::getChanType
virtual int getChanType()
Definition: abstractout.h:14
abstractCh::Status
virtual int Status()
Definition: abstractch.h:16
item.h