Skip to content

Commit

Permalink
fix memory leak and high cpu usage on long running processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Vierengel committed Aug 22, 2024
1 parent 8d36899 commit ba21e93
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions GoodWe/GoodWe.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class GoodWeUdp {
#bmsInfo = new GoodweBmSInfo();

constructor() {
this.#client.setMaxListeners(0);
// the next line of code should be deleted. I think it was probably introduced to silence the ever increasing listeners on #client
// because of the .on()-calls which installs a listener on each invocation, but does not remove it.
// this.#client.setMaxListeners(0);
}

destructor() {
Expand Down Expand Up @@ -219,13 +221,13 @@ class GoodWeUdp {
sendbuf[8] = crc & 0x00ff;

/*
this.#client.on("listening", function () {
this.#client.once("listening", function () {
console.log("GoodWePacket listening");
});
*/

try {
this.#client.on("message", (rcvbuf) => {
this.#client.once("message", (rcvbuf) => {
if (this.#CheckRecPacket(rcvbuf, sendbuf[4], sendbuf[5])) {
this.#idInfo.FirmwareVersion = this.#GetStringFromByteArray(rcvbuf, 7, 5);
this.#idInfo.ModelName = this.#GetStringFromByteArray(rcvbuf, 12, 10);
Expand Down Expand Up @@ -270,12 +272,12 @@ class GoodWeUdp {
sendbuf[7] = crc & 0x00ff;

/*
this.#client.on("listening", function () {
this.#client.once("listening", function () {
console.log("GoodWeDeviceInfo listening");
});
*/
try {
this.#client.on("message", (rcvbuf) => {
this.#client.once("message", (rcvbuf) => {
if (this.#CheckRecRegisterData(rcvbuf, sendbuf[1], sendbuf[5])) {
this.#deviceInfo.ModbusProtocolVersion = this.#GetUintFromByteArray(rcvbuf, 5, 2);
this.#deviceInfo.RatedPower = this.#GetUintFromByteArray(rcvbuf, 7, 2);
Expand Down Expand Up @@ -324,13 +326,13 @@ class GoodWeUdp {
sendbuf[7] = crc & 0x00ff;

/*
this.#client.on("listening", function () {
this.#client.once("listening", function () {
console.log("GoodWeDeviceInfo listening");
});
*/

try{
this.#client.on("message", (rcvbuf) => {
this.#client.once("message", (rcvbuf) => {
if (this.#CheckRecRegisterData(rcvbuf, sendbuf[1], sendbuf[5])) {
this.#runningData.Pv1.Voltage = this.#GetUintFromByteArray(rcvbuf, 11, 2) / 10;
this.#runningData.Pv1.Current = this.#GetUintFromByteArray(rcvbuf, 13, 2) / 10;
Expand Down Expand Up @@ -458,13 +460,13 @@ class GoodWeUdp {
sendbuf[7] = crc & 0x00ff;

/*
this.#client.on("listening", function () {
this.#client.once("listening", function () {
console.log("GoodWeExtComData listening");
});
*/

try {
this.#client.on("message", (rcvbuf) => {
this.#client.once("message", (rcvbuf) => {
if (this.#CheckRecRegisterData(rcvbuf, sendbuf[1], sendbuf[5])) {
this.#extComData.Commode = this.#GetUintFromByteArray(rcvbuf, 5, 2);
this.#extComData.Rssi = this.#GetUintFromByteArray(rcvbuf, 7, 2);
Expand Down Expand Up @@ -519,13 +521,13 @@ class GoodWeUdp {
sendbuf[7] = crc & 0x00ff;

/*
this.#client.on("listening", function () {
this.#client.once("listening", function () {
console.log("GoodWeExtComData listening");
});
*/

try {
this.#client.on("message", (rcvbuf) => {
this.#client.once("message", (rcvbuf) => {
if (this.#CheckRecRegisterData(rcvbuf, sendbuf[1], sendbuf[5])) {
this.#bmsInfo.Status = this.#GetUintFromByteArray(rcvbuf, 5, 2);
this.#bmsInfo.PackTemperature = this.#GetUintFromByteArray(rcvbuf, 7, 2) / 10;
Expand Down

0 comments on commit ba21e93

Please sign in to comment.