mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-06 03:50:13 +02:00
Add Pylon skeleton
This commit is contained in:
parent
7633e7cd5d
commit
7bb165cdc1
5 changed files with 110 additions and 1 deletions
|
@ -44,7 +44,7 @@ Click "File" in the upper left corner -> Preferences -> Additional Development >
|
||||||
## Dependencies 📖
|
## Dependencies 📖
|
||||||
This code uses two libraries, ESP32-Arduino-CAN (https://github.com/miwagner/ESP32-Arduino-CAN/) slightly modified for this usecase, and the eModbus library (https://github.com/eModbus/eModbus). Both these are already located in the Software folder for an easy start.
|
This code uses two libraries, ESP32-Arduino-CAN (https://github.com/miwagner/ESP32-Arduino-CAN/) slightly modified for this usecase, and the eModbus library (https://github.com/eModbus/eModbus). Both these are already located in the Software folder for an easy start.
|
||||||
|
|
||||||
It is also based on the info found in the following excellent repositories:
|
It is also based on the info found in the following excellent repositories/websites:
|
||||||
- https://gitlab.com/pelle8/gen24
|
- https://gitlab.com/pelle8/gen24
|
||||||
- https://github.com/burra/byd_battery
|
- https://github.com/burra/byd_battery
|
||||||
- https://github.com/flodorn/TeslaBMSV2
|
- https://github.com/flodorn/TeslaBMSV2
|
||||||
|
@ -53,6 +53,7 @@ It is also based on the info found in the following excellent repositories:
|
||||||
- https://github.com/dalathegreat/leaf_can_bus_messages
|
- https://github.com/dalathegreat/leaf_can_bus_messages
|
||||||
- https://github.com/rand12345/solax_can_bus
|
- https://github.com/rand12345/solax_can_bus
|
||||||
- Renault Zoe CAN Matrix https://docs.google.com/spreadsheets/u/0/d/1Qnk-yzzcPiMArO-QDzO4a8ptAS2Sa4HhVu441zBzlpM/edit?pli=1#gid=0
|
- Renault Zoe CAN Matrix https://docs.google.com/spreadsheets/u/0/d/1Qnk-yzzcPiMArO-QDzO4a8ptAS2Sa4HhVu441zBzlpM/edit?pli=1#gid=0
|
||||||
|
- Pylon hacking https://www.eevblog.com/forum/programming/pylontech-sc0500-protocol-hacking/
|
||||||
|
|
||||||
## Like this project? 💖
|
## Like this project? 💖
|
||||||
Leave a ⭐ If you think this project is useful. Consider hopping onto my Patreon to encourage more open-source projects!
|
Leave a ⭐ If you think this project is useful. Consider hopping onto my Patreon to encourage more open-source projects!
|
||||||
|
|
|
@ -9,4 +9,8 @@
|
||||||
#include "BYD-CAN.h"
|
#include "BYD-CAN.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PYLON_CAN
|
||||||
|
#include "PYLON-CAN.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
61
Software/PYLON-CAN.cpp
Normal file
61
Software/PYLON-CAN.cpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#include "PYLON-CAN.h"
|
||||||
|
#include "ESP32CAN.h"
|
||||||
|
#include "CAN_config.h"
|
||||||
|
|
||||||
|
/* Do not change code below unless you are sure what you are doing */
|
||||||
|
//Actual content messages
|
||||||
|
CAN_frame_t PYLON_7310 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x7310,.data = {0x01, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x00}};
|
||||||
|
CAN_frame_t PYLON_7320 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x7320,.data = {0x4B, 0x00, 0x05, 0x0F, 0x2D, 0x00, 0x56, 0x00}};
|
||||||
|
|
||||||
|
CAN_frame_t PYLON_4210 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4210,.data = {0xA5, 0x09, 0x30, 0x75, 0x9D, 0x04, 0x2E, 0x64}};
|
||||||
|
CAN_frame_t PYLON_4220 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4220,.data = {0x8C, 0x0A, 0xE9, 0x07, 0x4A, 0x79, 0x4A, 0x79}};
|
||||||
|
CAN_frame_t PYLON_4230 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4230,.data = {0xDF, 0x0C, 0xDA, 0x0C, 0x03, 0x00, 0x06, 0x00}};
|
||||||
|
CAN_frame_t PYLON_4240 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4240,.data = {0x7E, 0x04, 0x62, 0x04, 0x11, 0x00, 0x03, 0x00}};
|
||||||
|
CAN_frame_t PYLON_4250 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4250,.data = {0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
CAN_frame_t PYLON_4260 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4260,.data = {0xAC, 0xC7, 0x74, 0x27, 0x03, 0x00, 0x02, 0x00}};
|
||||||
|
CAN_frame_t PYLON_4270 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4270,.data = {0x7E, 0x04, 0x62, 0x04, 0x05, 0x00, 0x01, 0x00}};
|
||||||
|
CAN_frame_t PYLON_4280 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4280,.data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
CAN_frame_t PYLON_4290 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = 0x4290,.data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
|
|
||||||
|
void update_values_can_pylon()
|
||||||
|
{ //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||||
|
//TODO, add mappings
|
||||||
|
}
|
||||||
|
|
||||||
|
void receive_can_pylon(CAN_frame_t rx_frame)
|
||||||
|
{
|
||||||
|
switch (rx_frame.MsgID)
|
||||||
|
{
|
||||||
|
case 0x4200: //Message originating from inverter. Depending on which data is required, act accordingly
|
||||||
|
if(rx_frame.data.u8[0] == 0x02)
|
||||||
|
{
|
||||||
|
send_setup_info();
|
||||||
|
}
|
||||||
|
if(rx_frame.data.u8[0] == 0x00)
|
||||||
|
{
|
||||||
|
send_system_data();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_setup_info()
|
||||||
|
{ //Ensemble information
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_7310);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_7320);
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_system_data()
|
||||||
|
{ //System equipment information
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4210);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4220);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4230);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4240);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4250);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4260);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4270);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4280);
|
||||||
|
ESP32Can.CANWriteFrame(&PYLON_4290);
|
||||||
|
}
|
35
Software/PYLON-CAN.h
Normal file
35
Software/PYLON-CAN.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef PYLON_CAN_H
|
||||||
|
#define PYLON_CAN_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "ESP32CAN.h"
|
||||||
|
|
||||||
|
extern uint16_t SOC;
|
||||||
|
extern uint16_t StateOfHealth;
|
||||||
|
extern uint16_t battery_voltage;
|
||||||
|
extern uint16_t battery_current;
|
||||||
|
extern uint16_t capacity_Wh;
|
||||||
|
extern uint16_t remaining_capacity_Wh;
|
||||||
|
extern uint16_t max_target_discharge_power;
|
||||||
|
extern uint16_t max_target_charge_power;
|
||||||
|
extern uint16_t bms_status;
|
||||||
|
extern uint16_t bms_char_dis_status;
|
||||||
|
extern uint16_t stat_batt_power;
|
||||||
|
extern uint16_t temperature_min;
|
||||||
|
extern uint16_t temperature_max;
|
||||||
|
extern uint16_t CANerror;
|
||||||
|
extern uint16_t min_volt_pylon_can;
|
||||||
|
extern uint16_t max_volt_pylon_can;
|
||||||
|
// Definitions for BMS status
|
||||||
|
#define STANDBY 0
|
||||||
|
#define INACTIVE 1
|
||||||
|
#define DARKSTART 2
|
||||||
|
#define ACTIVE 3
|
||||||
|
#define FAULT 4
|
||||||
|
#define UPDATING 5
|
||||||
|
|
||||||
|
void update_values_can_pylon();
|
||||||
|
void receive_can_pylon(CAN_frame_t rx_frame);
|
||||||
|
void send_system_data();
|
||||||
|
void send_setup_info();
|
||||||
|
|
||||||
|
#endif
|
|
@ -7,6 +7,7 @@
|
||||||
#define MODBUS_BYD //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU
|
#define MODBUS_BYD //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU
|
||||||
//#define CAN_BYD //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus
|
//#define CAN_BYD //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus
|
||||||
//#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" over CAN bus
|
//#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" over CAN bus
|
||||||
|
//#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus
|
||||||
|
|
||||||
/* Do not change any code below this line unless you are sure what you are doing */
|
/* Do not change any code below this line unless you are sure what you are doing */
|
||||||
/* Only change battery specific settings and limits in their respective .h files */
|
/* Only change battery specific settings and limits in their respective .h files */
|
||||||
|
@ -198,6 +199,7 @@ void handle_can()
|
||||||
#ifdef CAN_BYD
|
#ifdef CAN_BYD
|
||||||
receive_can_byd(rx_frame);
|
receive_can_byd(rx_frame);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -205,6 +207,9 @@ void handle_can()
|
||||||
#ifdef SOLAX_CAN
|
#ifdef SOLAX_CAN
|
||||||
receive_can_solax(rx_frame);
|
receive_can_solax(rx_frame);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PYLON_CAN
|
||||||
|
receive_can_pylon(rx_frame);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//When we are done checking if a CAN message has arrived, we can focus on sending CAN messages
|
//When we are done checking if a CAN message has arrived, we can focus on sending CAN messages
|
||||||
|
@ -244,6 +249,9 @@ void handle_inverter()
|
||||||
#ifdef CAN_BYD
|
#ifdef CAN_BYD
|
||||||
update_values_can_byd();
|
update_values_can_byd();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PYLON_CAN
|
||||||
|
update_values_can_pylon();
|
||||||
|
#endif
|
||||||
|
|
||||||
//Updata for ModbusRTU Server for GEN24
|
//Updata for ModbusRTU Server for GEN24
|
||||||
handle_update_data_modbusp201();
|
handle_update_data_modbusp201();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue