void test_log() { Log("test log %d", 1); char buffer[32]; memset(buffer, 0x00, sizeof(buffer)); LogHex(buffer, sizeof(buffer)); }
void LogHex(byte* s , int len, boolean noNL) { LogHex(s,len); }
bool RKPClass::loop_PanelMon() { static int msgbufLen = 0; static byte msgbuf[ixMaxPanel]; static bool bReceivingPacketNow = false; static byte lastByte=-1; //Note - nothing here is to be blocking //- so sending emails must not block receiving serial logs /*static byte buf[64]; static int bufix=0; while(Serial1.available()) { buf[bufix++] = Serial1.read(); if (bufix==64) { bufix=0; LogHex(buf,64); } } return;*/ //Knock off the "We Sent To Panel" Led not less than 100ms after we turn it on if (timeToSwitchOffLed != 0 && millis() > timeToSwitchOffLed) { timeToSwitchOffLed = 0; digitalWrite(LED_Stat, LOW); } //Software UART not great at receiving for some reason :/ - ok for sending. while(Serial1.available()) //if(Serial1.available()) { byte rx = Serial1.read(); if (bReceivingPacketNow == false) { if(lastByte == 0) {//last char was a zero - this was the end of the last message if (rx==0) continue; //CD34 sends 0 at start And 0 at End - different to CD72 and 92 - so ignore extra zero //It may be for us or not - but get whole message before testing so we stay in sync bReceivingPacketNow = true; msgbufLen=0; //not necessary to blank - but good for debug for(int n=0;n<ixMaxPanel;n++) msgbuf[n]=0xFF; msgbuf[msgbufLen++]=rx; } lastByte = rx; continue; //wait for byte#3 (0,id,..) } lastByte = rx; //needed in case cs error msgbuf[msgbufLen++]=rx; if (rx!=0) {//wasn't end of packet - is buffer full? if (msgbufLen>=ixMaxPanel) {//packet never terminated - bytes lost :( Log(F("Buf overflow")); bReceivingPacketNow = false; continue; } } else {//End of the packet bReceivingPacketNow = false; byte idDev = (msgbuf[0] & 0xf0)>>4; //ID of remote that message is for 0x0-0xf are valid ids //Uncomment to Display all packets //Log(F("DevID:"));Log(idDev);Log(' ');LogHex(msgbuf,msgbufLen); //LogLn(idDev); byte cs = 0; for(int n=0;n<msgbufLen;n++) { byte rx = msgbuf[n]; if (n<msgbufLen-2) //dont sum cs or terminator cs+=rx; //Log((char)rx); } if (cs == 0) cs++; //protocol avoids 0 except for end marker- so will send cs 00 as 01 if (cs != msgbuf[msgbufLen-2]) { LogLn(F("CS Fail :( ")); LogHex(msgbuf,msgbufLen); //Log(F("Dev:"));LogLn(idDev);LogLn(F("!")); continue; } //For CD34 this is ok- but not for 72/92 as there is no start 0. lastByte=-1; //good message - so waiting again for next zero //for us? if (idDev==mdevID) { bool bAck = (msgbuf[0] & 0x04) != 0; //required for good comms SendToPanel(mdevID, bAck); DisplayScreen(msgbuf, msgbufLen); //try display what device 0 sees //LogLn(F("-OK-")); } else { //LogLn("-Not for us-"); } {//Send Email if alarm lights come on bool bIsPanelWarning = (msgbuf[1] & 0x04) != 0; if (bIsPanelWarning == true && RKPClass::mbIsPanelWarning == false) SMTP::QueueEmail(); RKPClass::mbIsPanelWarning = bIsPanelWarning; bool bIsPanelAlarm = (msgbuf[1] & 0x02) != 0; if (bIsPanelAlarm == true && RKPClass::mbIsPanelAlarm == false) SMTP::QueueEmail(); RKPClass::mbIsPanelAlarm = bIsPanelAlarm; } } } return bScreenHasUpdated; }