[Eastron] Make P078 Eastron compile, serial settings do not yet work

At this moment it is just using the same static configuration as P150 from the playground.
It is not yet using the settings. This will have to be changed later on.
This commit is contained in:
TD-er
2018-08-24 23:16:33 +02:00
parent b1fb308646
commit ab0ed4b5ca
5 changed files with 22 additions and 10 deletions
@@ -70,6 +70,7 @@ ESPeasySoftwareSerial::ESPeasySoftwareSerial(uint8_t receivePin, uint8_t transmi
m_rxValid = m_txValid = m_txEnableValid = false;
m_buffer = NULL;
m_invert = inverse_logic;
m_rxEnabled = false;
if (isValidGPIOpin(receivePin)) {
m_rxPin = receivePin;
m_buffSize = buffSize;
@@ -140,6 +141,8 @@ uint8_t ESPeasySoftwareSerial::pinToIndex(uint8_t pin) {
void ESPeasySoftwareSerial::begin(long speed) {
// Use getCycleCount() loop to get as exact timing as possible
m_bitTime = ESP.getCpuFreqMHz()*1000000/speed;
if (!m_rxEnabled)
enableRx(true);
}
void ESPeasySoftwareSerial::setTransmitEnablePin(uint8_t transmitEnablePin) {
@@ -160,6 +163,7 @@ void ESPeasySoftwareSerial::enableRx(bool on) {
} else {
detachInterrupt(m_rxPin);
}
m_rxEnabled = on;
}
}
@@ -54,6 +54,12 @@ public:
void rxRead();
// AVR compatibility methods
bool listen() { enableRx(true); return true; }
void end() { stopListening(); }
bool isListening() { return m_rxEnabled; }
bool stopListening() { enableRx(false); return true; }
using Print::write;
private:
@@ -62,7 +68,8 @@ private:
// Member variables
uint8_t m_rxPin, m_txPin, m_txEnablePin;
bool m_rxValid, m_txValid, m_txEnableValid;
bool m_rxValid, m_rxEnabled;
bool m_txValid, m_txEnableValid;
bool m_invert;
unsigned long m_bitTime;
uint16_t m_inPos, m_outPos;
+3 -3
View File
@@ -1,7 +1,7 @@
/* Library for reading SDM 120/220/230/630 Modbus Energy meters.
* Reading via Hardware or Software Serial library & rs232<->rs485 converter
* 2016-2018 Reaper7 (tested on wemos d1 mini->ESP8266 with Arduino 1.9.0-beta & 2.4.1 esp8266 core)
* crc calculation by Jaime García (https://github.com/peninquen/Modbus-Energy-Monitor-Arduino/)
* crc calculation by Jaime Garca (https://github.com/peninquen/Modbus-Energy-Monitor-Arduino/)
*/
//------------------------------------------------------------------------------
#include "SDM.h"
@@ -14,7 +14,7 @@ SDM::SDM(HardwareSerial& serial, long baud, int dere_pin, int config, bool swapu
this->_swapuart = swapuart;
}
#else
SDM::SDM(SoftwareSerial& serial, long baud, int dere_pin) : sdmSer(serial) {
SDM::SDM(ESPeasySoftwareSerial& serial, long baud, int dere_pin) : sdmSer(serial) {
this->_baud = baud;
this->_dere_pin = dere_pin;
}
@@ -119,7 +119,7 @@ float SDM::readVal(uint16_t reg, uint8_t node) {
if (readErr != SDM_ERR_NO_ERROR) { //if error then copy temp error value to global val and increment global error counter
readingerrcode = readErr;
readingerrcount++;
readingerrcount++;
}
#ifndef USE_HARDWARESERIAL
+5 -4
View File
@@ -12,7 +12,8 @@
#ifdef USE_HARDWARESERIAL
#include <HardwareSerial.h>
#else
#include <SoftwareSerial.h>
#include <ESPeasySoftwareSerial.h>
// #include <SoftwareSerial.h>
#endif
//------------------------------------------------------------------------------
//DEFAULT CONFIG (DO NOT CHANGE ANYTHING!!! for changes use SDM_Config_User.h):
@@ -150,7 +151,7 @@ class SDM {
#ifdef USE_HARDWARESERIAL
SDM(HardwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int config = SDM_UART_CONFIG, bool swapuart = SWAPHWSERIAL);
#else
SDM(SoftwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN);
SDM(ESPeasySoftwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN);
#endif
virtual ~SDM();
@@ -165,7 +166,7 @@ class SDM {
#ifdef USE_HARDWARESERIAL
HardwareSerial& sdmSer;
#else
SoftwareSerial& sdmSer;
ESPeasySoftwareSerial& sdmSer;
#endif
#ifdef USE_HARDWARESERIAL
@@ -175,7 +176,7 @@ class SDM {
long _baud = SDM_UART_BAUD;
int _dere_pin = DERE_PIN;
uint16_t readingerrcode = SDM_ERR_NO_ERROR; //4 = timeout; 3 = not enough bytes; 2 = number of bytes OK but bytes b0,b1 or b2 wrong, 1 = crc error
uint16_t readingerrcount = 0; //total errors couter
uint16_t readingerrcount = 0; //total errors couter
uint16_t calculateCRC(uint8_t *array, uint8_t num);
};
#endif //SDM_h
+2 -2
View File
@@ -17,8 +17,8 @@
boolean Plugin_078_init = false;
#include <SDM.h> // Requires SDM library from Reaper7 - https://github.com/reaper7/SDM_Energy_Meter/
SDM<2400, D6, D7> Plugin_078_SDM;
ESPeasySoftwareSerial swSerSDM(6, 7); //config SoftwareSerial (rx->pin6 / tx->pin7)
SDM Plugin_078_SDM(swSerSDM, 9600, NOT_A_PIN); //config SDM
boolean Plugin_078(byte function, struct EventStruct *event, String& string)
{