versadac  1
versadac - Scalable Recorder Firmware
msg_try.h
1 /*******************************************************************************
2 FILE : msg_try.h
3 VERSION : $Id: msg_try.h 32375 2010-07-07 11:03:01Z richardhi $
4 AUTHOR : Richard Hine
5 SYSTEM : Diab C for PowerPC under vxWorks
6 DESCRIPTION : This file contains The retry class
7 *******************************************************************************/
8 #ifndef __MSG_TRY_H
9 #define __MSG_TRY_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #if SPI_MSG_FAILURE_DEBUG
16  extern unsigned long g_SPImsgIocRxFailures[];
17  extern unsigned long g_SPImsgModRxFailures[];
18  extern unsigned long g_SPImsgSuccesses[];
19 #endif
20 
22 {
23  public:
24  MsgRetryCounter(unsigned char z_maxRetries) ;
25  unsigned char readRetriesRemaining() { return triesRemaining; };
26  bool checkCommsOk(){return (triesRemaining>0);}; // checks retry count is OK
27  bool setMaxRetries(unsigned char z_maxRetries); // sets the max re-tries
28  void init(){triesRemaining = maxTries;}; // re-initialises counter.
29 #if SPI_MSG_FAILURE_DEBUG
30  void setMessageState(bool msgOk, bool msgRxOk) // call this for each message received
31 #else
32  void setMessageState(bool msgOk) // call this for each message received
33 #endif
34  {
35  if (triesRemaining > 0)
36  {
37  if (msgOk)
38  triesRemaining = maxTries;
39  else
40  triesRemaining--;
41  }
42 #if SPI_MSG_FAILURE_DEBUG
43  if (msgOk)
44  successes++;
45  else
46  failures++;
47  if (!msgRxOk)
48  mod_rx_failures++;
49 #endif
50  };
51 #if SPI_MSG_FAILURE_DEBUG
52  unsigned long getFailureCount() { return failures; };
53  unsigned long getSuccessCount() { return successes; };
54  unsigned long getModRxFailureCount() { return mod_rx_failures; };
55  void resetFailureCount() { failures = 0; successes = 0; mod_rx_failures = 0; };
56 #endif
57 
58  private:
59  unsigned char triesRemaining; // the update message re-try count for this module
60  unsigned char maxTries;
61 #if SPI_MSG_FAILURE_DEBUG
62  unsigned long failures; // ioc reports failure to rx good msg from module
63  unsigned long successes; // ioc receives good msg (poss contains report of module rx failure)
64  unsigned long mod_rx_failures; // module reports failure to rx good msg from ioc
65 #endif
66 };
67 
68 #ifdef __cplusplus
69 } /* extern "C" */
70 #endif
71 #endif /*__EIOT2DOF_H */
Definition: msg_try.h:21