-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from ruza87/pylon_rs485
PylonTech RS485 protocol emulation
- Loading branch information
Showing
15 changed files
with
686 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"diybms_settings":{"totalNumberOfBanks":1,"totalNumberOfSeriesModules":16,"baudRate":10000,"interpacketgap":3000,"graph_voltagehigh":3650,"graph_voltagelow":3000,"BypassOverTempShutdown":65,"BypassThresholdmV":3450,"timeZone":0,"minutesTimeZone":0,"daylight":false,"ntpServer":"time.google.com","loggingEnabled":false,"loggingFrequencySeconds":15,"currentMonitoringEnabled":true,"currentMonitoringModBusAddress":90,"rs485baudrate":19200,"rs485databits":3,"rs485parity":0,"rs485stopbits":1,"language":"en","mqtt":{"enabled":true,"uri":"mqtt://192.168.0.26:1883","topic":"emon/diybms","username":"emonpi","password":"emonpimqtt2016"},"influxdb":{"enabled":false,"apitoken":"","bucket":"bucketname","org":"organisation","url":"http://192.168.0.49:8086/api/v2/write","logfreq":15},"outputs":{"default":[153,153,153,153],"type":[0,0,0,0]},"rules":{"EmergencyStop":{"value":0,"hysteresis":0,"state":[0,0,0,0]},"BMSError":{"value":0,"hysteresis":0,"state":[0,0,0,0]},"CurrentMonitorOverCurrentAmps":{"value":100,"hysteresis":100,"state":[0,0,0,0]},"ModuleOverVoltage":{"value":3650,"hysteresis":3500,"state":[255,0,0,0]},"ModuleUnderVoltage":{"value":2900,"hysteresis":3050,"state":[255,0,0,0]},"ModuleOverTemperatureInternal":{"value":75,"hysteresis":75,"state":[0,0,0,0]},"ModuleUnderTemperatureInternal":{"value":5,"hysteresis":5,"state":[0,0,0,0]},"ModuleOverTemperatureExternal":{"value":50,"hysteresis":50,"state":[0,0,0,0]},"ModuleUnderTemperatureExternal":{"value":2,"hysteresis":2,"state":[0,0,0,0]},"CurrentMonitorOverVoltage":{"value":57600,"hysteresis":57000,"state":[0,0,0,0]},"CurrentMonitorUnderVoltage":{"value":48000,"hysteresis":49000,"state":[0,0,0,0]},"BankOverVoltage":{"value":57600,"hysteresis":57000,"state":[0,0,0,0]},"BankUnderVoltage":{"value":48000,"hysteresis":49000,"state":[0,0,0,0]},"Timer2":{"value":1020,"hysteresis":1020,"state":[0,0,0,0]},"Timer1":{"value":480,"hysteresis":480,"state":[0,0,0,0]}},"canbusprotocol":2,"nominalbatcap":280,"chargevolt":568,"chargecurrent":650,"dischargecurrent":650,"dischargevolt":488,"chargetemplow":0,"chargetemphigh":50,"dischargetemplow":-30,"dischargetemphigh":55,"stopchargebalance":false,"socoverride":false,"socforcelow":false,"dynamiccharge":true,"preventdischarge":false,"preventcharging":false,"cellminmv":3050,"cellmaxmv":3460,"kneemv":3320,"cellmaxspikemv":3550,"sensitivity":27,"cur_val1":36,"cur_val2":7,"tilevisibility":[49152,0,62209,0,0]}} | ||
{"diybms_settings":{"totalNumberOfBanks":1,"totalNumberOfSeriesModules":16,"baudRate":10000,"interpacketgap":3000,"graph_voltagehigh":3650,"graph_voltagelow":3000,"BypassOverTempShutdown":65,"BypassThresholdmV":3450,"timeZone":0,"minutesTimeZone":0,"daylight":false,"ntpServer":"time.google.com","loggingEnabled":false,"loggingFrequencySeconds":15,"currentMonitoringEnabled":true,"currentMonitoringModBusAddress":90,"rs485baudrate":19200,"rs485databits":3,"rs485parity":0,"rs485stopbits":1,"language":"en","mqtt":{"enabled":true,"uri":"mqtt://192.168.0.26:1883","topic":"emon/diybms","username":"emonpi","password":"emonpimqtt2016"},"influxdb":{"enabled":false,"apitoken":"","bucket":"bucketname","org":"organisation","url":"http://192.168.0.49:8086/api/v2/write","logfreq":15},"outputs":{"default":[153,153,153,153],"type":[0,0,0,0]},"rules":{"EmergencyStop":{"value":0,"hysteresis":0,"state":[0,0,0,0]},"BMSError":{"value":0,"hysteresis":0,"state":[0,0,0,0]},"CurrentMonitorOverCurrentAmps":{"value":100,"hysteresis":100,"state":[0,0,0,0]},"ModuleOverVoltage":{"value":3650,"hysteresis":3500,"state":[255,0,0,0]},"ModuleUnderVoltage":{"value":2900,"hysteresis":3050,"state":[255,0,0,0]},"ModuleOverTemperatureInternal":{"value":75,"hysteresis":75,"state":[0,0,0,0]},"ModuleUnderTemperatureInternal":{"value":5,"hysteresis":5,"state":[0,0,0,0]},"ModuleOverTemperatureExternal":{"value":50,"hysteresis":50,"state":[0,0,0,0]},"ModuleUnderTemperatureExternal":{"value":2,"hysteresis":2,"state":[0,0,0,0]},"CurrentMonitorOverVoltage":{"value":57600,"hysteresis":57000,"state":[0,0,0,0]},"CurrentMonitorUnderVoltage":{"value":48000,"hysteresis":49000,"state":[0,0,0,0]},"BankOverVoltage":{"value":57600,"hysteresis":57000,"state":[0,0,0,0]},"BankUnderVoltage":{"value":48000,"hysteresis":49000,"state":[0,0,0,0]},"Timer2":{"value":1020,"hysteresis":1020,"state":[0,0,0,0]},"Timer1":{"value":480,"hysteresis":480,"state":[0,0,0,0]}},"protocol":2,"nominalbatcap":280,"chargevolt":568,"chargecurrent":650,"dischargecurrent":650,"dischargevolt":488,"chargetemplow":0,"chargetemphigh":50,"dischargetemplow":-30,"dischargetemphigh":55,"stopchargebalance":false,"socoverride":false,"socforcelow":false,"dynamiccharge":true,"preventdischarge":false,"preventcharging":false,"cellminmv":3050,"cellmaxmv":3460,"kneemv":3320,"cellmaxspikemv":3550,"sensitivity":27,"cur_val1":36,"cur_val2":7,"tilevisibility":[49152,0,62209,0,0]}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef DIYBMS_PYLON_RS485_H_ | ||
#define DIYBMS_PYLON_RS485_H_ | ||
|
||
#include "defines.h" | ||
#include "Rules.h" | ||
#include "HAL_ESP32.h" | ||
|
||
|
||
class PylonRS485 { | ||
public: | ||
/** | ||
* @brief Constructor of the PylonRS485 class | ||
*/ | ||
PylonRS485(uart_port_t portNum, diybms_eeprom_settings& settings, Rules& rules, currentmonitoring_struct& currentMonitor, | ||
ControllerState& controllerState, HAL_ESP32& hal); | ||
|
||
/** | ||
* @brief Call this to periodically check queries from inverter and to form a reply | ||
*/ | ||
void handle_rx(); | ||
|
||
private: | ||
typedef struct { | ||
uint8_t soh; | ||
uint16_t ver; | ||
uint16_t addr; | ||
uint16_t cid1; | ||
uint16_t cid2; | ||
char length[4]; | ||
} __attribute__((packed)) THeader; | ||
|
||
uart_port_t uart_num; | ||
diybms_eeprom_settings& settings; | ||
Rules& rules; | ||
currentmonitoring_struct& current_monitor; | ||
ControllerState& controller_state; | ||
HAL_ESP32& hal; | ||
|
||
uint16_t pack_voltage; | ||
uint16_t charge_voltage; | ||
uint16_t discharge_voltage; | ||
uint16_t charge_current_limit; | ||
uint16_t discharge_current_limit; | ||
bool stop_charging; | ||
bool stop_discharging; | ||
uint8_t flags; | ||
char tmp_buf[150]; | ||
|
||
uint32_t hex2int(char *hex, char len); | ||
void insertLength(char *buf, int payload_len); | ||
int appendChecksum(char *buf, int buf_size, int payload_len); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.