versadac  1
versadac - Scalable Recorder Firmware
mc_deviceRunnable.h
1 /*******************************************************************************
2 FILE : mc_deviceRunnable.h
3 VERSION : $Id: mc_deviceRunnable.h 4938 2006-10-10 14:20:18Z martinto $
4 SYSTEM : __GNUC__ on vxworks
5 DESCRIPTION : Master comms deviceRunnable
6 *******************************************************************************/
7 
8 #ifndef __MC_DEVICE_RUNNABLE_H
9 #define __MC_DEVICE_RUNNABLE_H
10 
11 #include "OSTask.h"
12 #include "mc_dataList.h"
13 #include "ENUM_MCUpdateIntervals.h"
14 #include "ENUM_MCStatus.h"
15 #include "mc_debug.h"
16 
17 extern "C"
18 {
19  #include "system_ticks.h"
20 }
21 
22 // this clamps the number of devices as a static value is required. It is possible
23 // to dynamically change the number of devices between 0 and this value.
24 
25 #define MAX_MC_DEVICES 32
26 
27 class mc_data;
28 
30 {
31  friend void mcd_verboseUnregistered(bool on);
32  friend void mcd_verbosePort(int, int);
33 
34  public:
35  mc_deviceRunnable(sint16 z_deviceNumber);
36  virtual ~mc_deviceRunnable();
37  void runTask();
38 
39  // used to add transaction requests to registered devices
40  static void add(uint8 z_deviceNumber,
41  mc_data *z_data,
42  ENUM_MCUpdateIntervals z_frequency);
43  // used to add transaction requests for unregistered devices.
44  // NOTE these will all be acyclic, one shot transactions.
45  static void add( mc_data *z_data, uint32 z_timeout, uint16 z_network);
46 
47  inline bool getEnable(){return m_enable;};
48  inline bool getOnline(){return m_online;};
49  inline uint8 getModbusAddress(){return m_modbusAddress;};
50  inline uint32 getTimeout(){return m_timeout;};
51  inline uint16 getNetwork(){return m_network;};
52  inline double getAHIGHI(){return m_AHIGHI/get_ticks_per_second();};
53  inline double getAMEDI(){return m_AMEDI/get_ticks_per_second();};
54  inline double getALOWI(){return m_ALOWI/get_ticks_per_second();};
55  // the following block of services are only for the use of
56  // the functionblock and are not to be called elsewhere.
57  inline uint32 getTOTAL_RQ(){uint32 t = m_TOTAL_RQ; m_TOTAL_RQ = 0; return t;};
58  inline uint32 getTOTAL_GD(){uint32 t = m_TOTAL_GD; m_TOTAL_GD = 0; return t;};
59  inline uint32 getTOTAL_BD(){uint32 t = m_TOTAL_BD; m_TOTAL_BD = 0; return t;};
60  inline uint32 getTOTAL_01(){uint32 t = m_TOTAL_01; m_TOTAL_01 = 0; return t;};
61  inline uint32 getTOTAL_09(){uint32 t = m_TOTAL_09; m_TOTAL_09 = 0; return t;};
62  inline uint32 getTOTAL_02(){uint32 t = m_TOTAL_02; m_TOTAL_02 = 0; return t;};
63  inline uint32 getTOTAL_03(){uint32 t = m_TOTAL_03; m_TOTAL_03 = 0; return t;};
64  inline uint32 getTOTAL_04(){uint32 t = m_TOTAL_04; m_TOTAL_04 = 0; return t;};
65  inline uint32 getTOTAL_10(){uint32 t = m_TOTAL_10; m_TOTAL_10 = 0; return t;};
66  inline uint32 getTOTAL_11(){uint32 t = m_TOTAL_11; m_TOTAL_11 = 0; return t;};
67  inline uint32 getTOTAL_TO(){uint32 t = m_TOTAL_TO; m_TOTAL_TO = 0; return t;};
68  inline uint32 getTOTAL_RT(){uint32 t = m_TOTAL_RT; m_TOTAL_RT = 0; return t;};
69  inline uint32 getTOTAL_LB(){uint32 t = m_TOTAL_LB; m_TOTAL_LB = 0; return t;};
70  inline uint32 getTOTAL_MR(){uint32 t = m_TOTAL_MR; m_TOTAL_MR = 0; return t;};
71  inline ENUM_MCStatus getStatus(){ return m_lastStatus;};
72 
73  void lock();
74  void unlock();
75 
76  static void setNumberOfDevices(uint16 z_numberOfDevices);
77  static mc_deviceRunnable *getDevice(uint16 z_deviceNumber);
78  static mc_deviceRunnable *getUnregisteredDevice();
79  static void setTaskPriority(uint8 z_priority);
80  static void setTaskStack(uint16 z_stackSize);
81 
82  int open(char *z_addressOrName);
83  ENUM_MCStatus login(int z_socketFd, uint8 z_modbusAddress);
84  ENUM_MCStatus getDataStatus(void);
85 
86  void setAddressOrName(char *z_addressOrName);
87  void setModbusAddress(uint8 z_modbusAddress);
88  void setPidAddress(uint8 z_pidAddress);
89  void setUsername(char *z_username);
90  void setPassword(char *z_password);
91  void setSocketTimeout(uint32 z_timeout);
92  void setNetwork(uint16 z_network);
93  void setRetries(uint16 z_retries);
94  void setMaxBlockSize(uint16 z_maxBlock);
95  void setEnable(bool z_enable);
96  void setOnline(bool z_online);
97  void setBoundaries(uint16 z_numberOfBoundaries, uint16 *z_boundaries);
98  void setLoginRequired(bool z_loginRequired){m_loginRequired = z_loginRequired;};
99  void setShareSocket(bool z_shareSocket){m_shareSocket = z_shareSocket;};
100  void setUpdateRate(uint8 z_rateSpecifier, double z_interval);
101  inline void setVerbose(bool z_verbose){m_verbose = z_verbose;};
102  inline void setVerboseLists(){m_verboseLists = TRUE;};
103  inline void setVerboseFile(FILE *z_verboseFile){m_verboseFile = z_verboseFile;};
104  void setEnableMerge(bool z_enable);
105 
106  void transact(mc_data *z_transaction);
107  void change_priority(sint16 z_increment, uint8 * z_old_priority);
108 
109  // Array of pointers to each device task
110  static mc_deviceRunnable *m_devices[MAX_MC_DEVICES];
111 
112  private:
113  void add(mc_data *z_data, ENUM_MCUpdateIntervals z_frequency);
114  mc_dataList m_highPriorityList;
115  mc_dataList m_mediumPriorityList;
116  mc_dataList m_lowPriorityList;
117  mc_dataList m_asynchronousList;
118  double m_highPriorityInterval;
119  double m_mediumPriorityInterval;
120  double m_lowPriorityInterval;
121  double m_highPriorityListStartTicks;
122  double m_mediumPriorityListStartTicks;
123  double m_lowPriorityListStartTicks;
124  bool m_processingHighPriorityList;
125  bool m_processingMediumPriorityList;
126  bool m_processingLowPriorityList;
127  char m_username[41];
128  char m_password[41];
129  char m_addressOrName[104];
130  char m_lastAddressOrName[104];
131  uint8 m_modbusAddress;
132  uint16 m_pidAddress;
133  uint32 m_timeout;
134  uint16 m_network;
135  uint16 m_retries;
136  uint16 m_workingRetries;
137  uint16 m_maxBlock;
138  uint16 *m_boundaries;
139  sint16 m_deviceNumber;
140  bool m_enable;
141  bool m_online;
142  bool m_loginRequired;
143  bool m_loggedIn;
144  bool m_timeoutMode;
145  bool m_verbose;
146  bool m_verboseLists;
147  bool m_shareSocket;
148  static mc_deviceRunnable *m_unregisteredDevice;
149  static uint8 s_priority;
150  static uint16 s_stack;
151  SEM_ID m_enableChangeSemaphore;
152  SEM_ID m_lockSem;
153  ENUM_MCStatus m_lastStatus;
154 
155  double m_AHIGHI;
156  double m_AMEDI;
157  double m_ALOWI;
158  uint32 m_TOTAL_RQ;
159  uint32 m_TOTAL_GD;
160  uint32 m_TOTAL_BD;
161  uint32 m_TOTAL_01;
162  uint32 m_TOTAL_09;
163  uint32 m_TOTAL_02;
164  uint32 m_TOTAL_03;
165  uint32 m_TOTAL_04;
166  uint32 m_TOTAL_10;
167  uint32 m_TOTAL_11;
168  uint32 m_TOTAL_TO;
169  uint32 m_TOTAL_RT;
170  uint32 m_TOTAL_LB;
171  uint32 m_TOTAL_MR;
172 
173  FILE *m_verboseFile;
174 
175  public:
176  static uint16 m_numberOfDevices;
177 };
178 
179 #endif
Definition: ostask.h:16
Definition: mc_data.h:17
Definition: mc_dataList.h:20
Definition: mc_deviceRunnable.h:29