void dbug_printsbyte(SBYTE_ARRAY *inAry, LPCTSTR s) { if (inAry == NULL) { dtDebug(_T(" %s is NULL\n"), s); return; } dtDebug(_T(" %s: %lu bytes at 0x%08X\n"), s, inAry->NumOfBytes, inAry->BytePtr); if (inAry->BytePtr == NULL) { dtDebug(_T(" %s->BytePtr is NULL\n"), inAry); return; } if (inAry->NumOfBytes > 0) { std::basic_ostringstream<wchar_t> ssData; ssData << std::hex << std::setfill(_T('0')) << _T(" \\__"); for (unsigned long i=0; i < inAry->NumOfBytes; i++) { ssData << _T(" ") << std::setw(2) << inAry->BytePtr[i]; } ssData << std::endl; dtDebug(ssData.str().c_str()); } }
void dbug_printmsg(PASSTHRU_MSG mm[], LPCTSTR s, unsigned long * numMsgs, bool isWrite) { if (mm == NULL) dtDebug(_T(" %s is NULL\n"), s); if (numMsgs == NULL) dtDebug(_T(" numMsgs is NULL\n"), s); if (mm == NULL || numMsgs == NULL) return; dbug_printmsg(mm, s, *numMsgs, isWrite); }
void dbug_printtxflags(unsigned long TxFlags) { std::basic_ostringstream<wchar_t> ssTxFlags; if (TxFlags == 0) return; ssTxFlags << _T(" TxFlags:"); for (int i=0; i < 32; i++) { unsigned long mask = 1 << i; if ((mask & TxFlags) == 0) { continue; } else { ssTxFlags << _T(" ") << i << _T(":") << dbug_txflag2str(mask & TxFlags); } } ssTxFlags << std::endl; dtDebug(ssTxFlags.str().c_str()); }
void dbug_printretval(unsigned long retval) { if (retval == STATUS_NOERROR || retval == ERR_TIMEOUT || retval == ERR_BUFFER_EMPTY) { dtDebug(_T(" %.3fs %s\n"), GetTimeSinceInit(), dbug_return(retval).c_str()); } else { char szErrorDescription[80]; shim_PassThruGetLastError(szErrorDescription); CStringW cstrErrorDescription(szErrorDescription); dtDebug(_T(" %.3fs %s '%s'\n"), GetTimeSinceInit(), dbug_return(retval).c_str(), cstrErrorDescription); } }
void dbug_printrxstatus(unsigned long RxStatus) { std::basic_ostringstream<wchar_t> ssRxStatus; if (RxStatus == 0) return; ssRxStatus << _T(" RxStatus:"); for (int i=0; i < 32; i++) { unsigned long mask = 1 << i; if ((mask & RxStatus) == 0) { continue; } else { ssRxStatus << _T(" ") << i << _T(":") << dbug_rxstatus2str(mask & RxStatus); } } ssRxStatus << std::endl; dtDebug(ssRxStatus.str().c_str()); }
void dbug_printsconfig(SCONFIG_LIST *pList) { if (pList == NULL) { dtDebug(_T(" pList is NULL\n")); return; } dtDebug(_T(" %ld parameter(s) at 0x%08X:\n"), pList->NumOfParams, pList->ConfigPtr); if (pList->ConfigPtr == NULL) { dtDebug(_T(" pList->ConfigPtr is NULL\n")); return; } for (unsigned long i=0; i < pList->NumOfParams; i++) { dtDebug(_T(" %s = %ld\n"), dbug_param(pList->ConfigPtr[i].Parameter).c_str(), pList->ConfigPtr[i].Value); } }
/****************************************************************************** * * dtPoll * * PURPOSE * This routine is called by the system's main polling loop to * maintain the real time clock and second tick count. This routine * also detects start times for scheduled irrigation programs. * * PARAMETERS * None. * * RETURN VALUE * None. * * NOTES * This routine should be called frequently to keep the system clock * up-to-date and to insure that the intervals between tick count * one-second increments are reasonably precise. To maintain precision * of +/- 5%, this routine needs to be called at least once every 100 * ms. * *****************************************************************************/ void dtPoll(void) { uint8_t pgm; char debugBuf[2]; /* Maintain real time clock. */ dtPollRtc(); /* Manage automatic irrigation start. */ if (dtNewMinute()) { /* Check configuration to see if an irrigation program should start. */ if (sysIsAuto) { for (pgm = 0; pgm < SYS_N_PROGRAMS; pgm++) { /* confirm communication with master prior to schedule start * time if in pulse mode. if no communication then revert to runtime based system */ if((config.sys.pulseMode ==CONFIG_PULSEMODE_ON) & (config.sys.unitType != UNIT_TYPE_MASTER)) { if((ntohs(config.sched[dtIrrWday()][pgm].startTime)-TIME_BEFORE_SCHED_TIME) == dtCurTime) { /* send No Op command to Master to test communication */ expansionBusSendCmd(RADIO_CMD_NO_OP, config.sys.masterMac); } return; } if ((ntohs(config.sched[dtIrrWday()][pgm].startTime) == dtCurTime) & (irrStop == FALSE)& (radioCmdIrrStart==FALSE)) { /* Make sure watchdog doesn't timeout on long debug message writes. */ sysExecutionExtend(); if ((irrAutoPgmPending == IRR_PGM_NONE) | (irrExpRunningProg == IRR_PGM_NONE)) { /* Schedule program to auto-start. */ irrAutoPgmPending = pgm; /* Trace auto start queued event. */ sysEvent(DT_EVENT_AUTO_START_Q, pgm); dtDebug("PGM '"); sprintf(debugBuf, "%c", 'A' + pgm); debugWrite(debugBuf); debugWrite("' queued for auto-start.\n"); if(config.sys.unitType == UNIT_TYPE_MASTER) { expansionBusSendCmd(RADIO_CMD_IRR_STOP_OFF,RADIO_EXP_SEND_ALL); } } else { /* Already one program waiting in queue. */ /* Trace auto start - queue full event. */ sysEvent(DT_EVENT_AUTO_START_QF, pgm); dtDebug("PGM '"); sprintf(debugBuf, "%c", 'A' + pgm); debugWrite(debugBuf); debugWrite("' auto-start Failed. Queue is full.\n"); } } /*if a stop command was received before scheduled time cancel * scheduled program and once passed scheduled time clear the stop flag */ if (ntohs(config.sched[dtIrrWday()][pgm].startTime) < dtCurTime) { irrStop = FALSE; radioCmdIrrStart=FALSE; } } } } }
void dbug_printmsg(PASSTHRU_MSG mm[], LPCTSTR s, unsigned long numMsgs, bool isWrite) { if (mm == NULL) { dtDebug(_T(" %s is NULL\n"), s); return; } for (unsigned long i=0; i < numMsgs; i++) { if (isWrite == true) { dtDebug(_T(" %s[%2ld] %s. %lu bytes. TxF=0x%08lx\n"), s, i, //numMsgs, dbug_prot(mm[i].ProtocolID).c_str(), mm[i].DataSize, mm[i].TxFlags); } else { dtDebug(_T(" %s[%2ld] %fs. %s. Actual data %lu of %lu bytes. RxS=0x%08lx\n"), s, i, //numMsgs, mm[i].Timestamp / (float) 1000000, dbug_prot(mm[i].ProtocolID).c_str(), mm[i].ExtraDataIndex, mm[i].DataSize, mm[i].RxStatus); } // Display TxFlags if this is an outgoing message if (mm[i].TxFlags != 0 && isWrite == true) { dbug_printtxflags(mm[i].TxFlags); } // Display RxStatus if this is an incoming message if (mm[i].RxStatus != 0 && isWrite == false) { dbug_printrxstatus(mm[i].RxStatus); } // Display Data[] except for frames containing neither data nor extradata if (mm[i].DataSize > 0) { std::basic_ostringstream<wchar_t> ssData; unsigned long n = mm[i].ExtraDataIndex; ssData << std::hex << std::setfill(_T('0')) << _T(" \\__"); for (unsigned long x = 0; x < mm[i].DataSize && x < sizeof(mm[i].Data); x++) { if (x < mm[i].ExtraDataIndex || isWrite == true) { ssData << _T(" ") << std::setw(2) << mm[i].Data[x]; } else { ssData << _T(" [") << std::setw(2) << mm[i].Data[x] << _T("]"); } } ssData << std::endl; dtDebug(ssData.str().c_str()); } } }