Skip to content

Commit

Permalink
Bug fix branch #70 (#78)
Browse files Browse the repository at this point in the history
* Improvements for controllers with lots of modules
  • Loading branch information
stuartpittaway authored Jan 5, 2022
1 parent 81d4cb3 commit 8b166ac
Show file tree
Hide file tree
Showing 7 changed files with 731 additions and 697 deletions.
69 changes: 38 additions & 31 deletions ESPController/include/PacketRequestGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,67 @@
#include <cppQueue.h>
#include <defines.h>

//command byte
// WRRR CCCC
// W = 1 bit indicator packet was processed (controller send (0) module processed (1))
// R = 3 bits reserved not used
// C = 4 bits command (16 possible commands)
// command byte
// WRRR CCCC
// W = 1 bit indicator packet was processed (controller send (0) module processed (1))
// R = 3 bits reserved not used
// C = 4 bits command (16 possible commands)

//commands
// 1000 0000 = set bank identity
// 0000 0001 = read voltage and status
// 0000 0010 = identify module (flash leds)
// 0000 0011 = Read temperature
// 0000 0100 = Report number of bad packets
// 0000 0101 = Report settings/configuration
// commands
// 1000 0000 = set bank identity
// 0000 0001 = read voltage and status
// 0000 0010 = identify module (flash leds)
// 0000 0011 = Read temperature
// 0000 0100 = Report number of bad packets
// 0000 0101 = Report settings/configuration

class PacketRequestGenerator
{
public:
PacketRequestGenerator(cppQueue *requestQ) { _requestq = requestQ; }
~PacketRequestGenerator() {}
void sendGetSettingsRequest(uint8_t cellid);
void sendIdentifyModuleRequest(uint8_t cellid);
void sendSaveSetting(uint8_t m, uint16_t BypassThresholdmV, uint8_t BypassOverTempShutdown, float Calibration);
void sendSaveGlobalSetting(uint16_t BypassThresholdmV, uint8_t BypassOverTempShutdown);
void sendReadBadPacketCounter(uint8_t startmodule, uint8_t endmodule);
bool sendGetSettingsRequest(uint8_t cellid);
bool sendIdentifyModuleRequest(uint8_t cellid);
bool sendSaveSetting(uint8_t m, uint16_t BypassThresholdmV, uint8_t BypassOverTempShutdown, float Calibration);
bool sendSaveGlobalSetting(uint16_t BypassThresholdmV, uint8_t BypassOverTempShutdown);
bool sendReadBadPacketCounter(uint8_t startmodule, uint8_t endmodule);

void sendCellVoltageRequest(uint8_t startmodule, uint8_t endmodule);
void sendCellTemperatureRequest(uint8_t startmodule, uint8_t endmodule);
void sendReadBalancePowerRequest(uint8_t startmodule, uint8_t endmodule);
void sendReadBalanceCurrentCountRequest(uint8_t startmodule, uint8_t endmodule);
void sendReadPacketsReceivedRequest(uint8_t startmodule, uint8_t endmodule);
void sendBadPacketCounterReset();
void sendTimingRequest();
void sendResetBalanceCurrentCounter();
bool sendCellVoltageRequest(uint8_t startmodule, uint8_t endmodule);
bool sendCellTemperatureRequest(uint8_t startmodule, uint8_t endmodule);
bool sendReadBalancePowerRequest(uint8_t startmodule, uint8_t endmodule);
bool sendReadBalanceCurrentCountRequest(uint8_t startmodule, uint8_t endmodule);
bool sendReadPacketsReceivedRequest(uint8_t startmodule, uint8_t endmodule);
bool sendBadPacketCounterReset();
bool sendTimingRequest();
bool sendResetBalanceCurrentCounter();

uint32_t packetsGenerated = 0;
uint16_t queueLength() {
return _requestq->getCount();
}

void ResetCounters()
{
packetsGenerated = 0;
}

uint32_t packetsGenerated = 0;

private:
cppQueue *_requestq;
void pushPacketToQueue(PacketStruct *_packetbuffer);
void setPacketAddress(PacketStruct *_packetbuffer, uint8_t module);
bool pushPacketToQueue(PacketStruct *_packetbuffer);
void setPacketAddress(PacketStruct *_packetbuffer, uint8_t module);
void setPacketAddressModuleRange(PacketStruct *_packetbuffer, uint8_t startmodule, uint8_t endmodule);
void setPacketAddressBroadcast(PacketStruct *_packetbuffer);
void setmoduledataFFFF(PacketStruct *_packetbuffer);
void clearSettingsForAllModules();

void BuildAndSendRequest(COMMAND command,uint8_t startmodule, uint8_t endmodule);
void BuildAndSendRequest(COMMAND command);
bool BuildAndSendRequest(COMMAND command, uint8_t startmodule, uint8_t endmodule);
bool BuildAndSendRequest(COMMAND command);

void clearPacket(PacketStruct *_packetbuffer)
{
memset(_packetbuffer, 0, sizeof(PacketStruct));
}

};

#endif
Loading

0 comments on commit 8b166ac

Please sign in to comment.