2018-09-23 06:31:09 +00:00
|
|
|
#include "TxManage.h"
|
|
|
|
|
|
|
|
extern void SerialReport(const char* hdr, const unsigned char* pData, const char* ftr);
|
|
|
|
|
2018-10-15 07:14:12 +00:00
|
|
|
CTxManage::CTxManage(int TxEnbPin, HardwareSerial& serial) :
|
2018-09-23 06:31:09 +00:00
|
|
|
m_Serial(serial),
|
2018-09-23 09:15:49 +00:00
|
|
|
m_Frame(CProtocol::CtrlMode)
|
2018-09-23 06:31:09 +00:00
|
|
|
{
|
|
|
|
m_bOnReq = false;
|
|
|
|
m_bOffReq = false;
|
|
|
|
m_bTxPending = false;
|
|
|
|
m_nStartTime = 0;
|
|
|
|
m_nTxEnbPin = TxEnbPin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTxManage::begin()
|
|
|
|
{
|
|
|
|
pinMode(m_nTxEnbPin, OUTPUT);
|
|
|
|
digitalWrite(m_nTxEnbPin, LOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CTxManage::RequestOn()
|
|
|
|
{
|
|
|
|
m_bOnReq = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CTxManage::RequestOff()
|
|
|
|
{
|
|
|
|
m_bOffReq = true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 08:59:19 +00:00
|
|
|
void
|
2018-09-23 09:15:49 +00:00
|
|
|
CTxManage::Start(const CProtocol& ref, unsigned long timenow, bool self)
|
2018-09-23 06:31:09 +00:00
|
|
|
{
|
|
|
|
m_Frame = ref;
|
2018-09-23 08:59:19 +00:00
|
|
|
// 0x78 prevents the controller showing bum information when we parrot the OEM controller
|
|
|
|
// heater is happy either way, the OEM controller has set the max/min stuff already
|
|
|
|
m_Frame.Data[0] = self ? 0x76 : 0x78;
|
2018-09-23 06:31:09 +00:00
|
|
|
|
|
|
|
if(timenow == 0)
|
|
|
|
timenow++;
|
|
|
|
|
|
|
|
m_nStartTime = timenow;
|
|
|
|
m_bTxPending = true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 08:59:19 +00:00
|
|
|
bool
|
|
|
|
CTxManage::CheckTx(unsigned long timenow)
|
2018-09-23 06:31:09 +00:00
|
|
|
{
|
|
|
|
if(m_nStartTime) {
|
|
|
|
|
|
|
|
long diff = timenow - m_nStartTime;
|
|
|
|
|
|
|
|
if(diff > m_nStartDelay) {
|
|
|
|
// begin front porch of Tx gating pulse
|
|
|
|
digitalWrite(m_nTxEnbPin, HIGH);
|
|
|
|
}
|
|
|
|
if(m_bTxPending && (diff > (m_nStartDelay + m_nFrontPorch))) {
|
|
|
|
// begin serial transmission
|
|
|
|
m_bTxPending = false;
|
|
|
|
_send();
|
|
|
|
}
|
|
|
|
if(diff > (m_nStartDelay + m_nFrameTime)) {
|
|
|
|
// conclude Tx gating
|
|
|
|
m_nStartTime = 0;
|
|
|
|
digitalWrite(m_nTxEnbPin, LOW);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 08:59:19 +00:00
|
|
|
return m_nStartTime == 0;
|
2018-09-23 06:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CTxManage::_send()
|
|
|
|
{
|
2018-09-23 08:59:19 +00:00
|
|
|
// install on/off commands if required
|
2018-09-23 06:31:09 +00:00
|
|
|
if(m_bOnReq) {
|
|
|
|
m_bOnReq = false;
|
2018-09-23 08:59:19 +00:00
|
|
|
m_Frame.Controller.Command = 0xa0;
|
2018-09-23 06:31:09 +00:00
|
|
|
}
|
|
|
|
else if(m_bOffReq) {
|
|
|
|
m_bOffReq = false;
|
2018-09-23 08:59:19 +00:00
|
|
|
m_Frame.Controller.Command = 0x05;
|
2018-09-23 06:31:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-09-23 08:59:19 +00:00
|
|
|
m_Frame.Controller.Command = 0x00;
|
2018-09-23 06:31:09 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 08:59:19 +00:00
|
|
|
// ensure CRC valid
|
2018-09-23 06:31:09 +00:00
|
|
|
m_Frame.setCRC();
|
|
|
|
|
|
|
|
// send to heater - using binary
|
|
|
|
for(int i=0; i<24; i++) {
|
|
|
|
m_Serial.write(m_Frame.Data[i]); // write native binary values
|
|
|
|
}
|
|
|
|
|
|
|
|
Report();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CTxManage::Report()
|
|
|
|
{
|
|
|
|
SerialReport("Self ", m_Frame.Data, " ");
|
|
|
|
}
|