LRAUV  revA
BPC1.h
Go to the documentation of this file.
1 
13 #ifndef BPC1_H
14 #define BPC1_H
15 
17 #include "io/LoadControl.h"
18 #include "io/UartStream.h"
19 #include "logger/Logger.h"
20 #include "BPC1IF.h"
21 #define NUMBATTSA BPC1IF::NUMBATTSA
22 #define NUMBATTSB BPC1IF::NUMBATTSB
23 
24 #define SHORT_MSG_MIN_SIZE 199 // bytes. For the mux that has only 7 sticks
25 #define SHORT_MSG_MAX_SIZE 216 // bytes. For the other 3 mux that have 8 sticks
26 #define FULL_MSG_MIN_SIZE 1676 // bytes. Includes echoed "X" and spaces
27 #define FULL_MSG_MAX_SIZE 1904 // bytes. Includes echoed "X" and spaces
28 
29 #define MESSAGE_OFFSET 77 // bytes. Length of system and controller data
30 #define SMBUS_MSG_LEN 228 // bytes. Includes the $B1n and checksum that IBPS adds
31 
32 #define MAX_STICKS 8 // There can only be up to 8 sticks connected.
33 
36 
45 class BPC1 : public SyncSensorComponent
46 {
47 public:
48 
49  BPC1( const Module* module );
50 
51  virtual ~BPC1();
52 
53  virtual void run();
54 
57  virtual RunState start();
58 
60  virtual RunState starting();
61 
63  virtual RunState pause();
64 
66  virtual RunState pausing();
67 
69  virtual RunState paused();
70 
72  virtual RunState resume();
73 
75  virtual RunState resuming();
76 
78  virtual RunState runnable();
79 
81  virtual RunState resetting()
82  {
83  return stop();
84  }
85 
87  virtual RunState stop();
88 
89  virtual RunState stopping();
90 
92  virtual RunState stopped();
93 
94  virtual void uninitialize();
95 
97  virtual ConfigURI getConfigURI( ConfigOption configOption ) const;
98 
99 private:
100 
101  // Note that the copy constructor below is private and not given a body.
102  // Any attempt to call it will return a compiler error.
103  BPC1( const BPC1& old ); // disallow copy constructor
104 
105  // scan configuraiton settings
106  bool readConfig();
107 
109  static BPC1* Instance_;
110 
111  // returns true if data is requested from one of the readers
112  bool isDataRequested();
113 
114  // Debugging outputs
115  bool debug_;
116 
120 
121  // The status returned from the battery controller
122  typedef enum
123  {
124  // ALARM BITS
127  OVER_TEMP_ALARM = 0x1000,
131  // STATUS BITS
132  INITIALIZED = 0x0080,
133  DISCHARGING = 0x0040,
134  FULLY_CHARGED = 0x0020,
136  } SMBStatus;
137 
138 
139  // Stores the current response from the battery server
140  char deviceResponseA_[2120];
141  char deviceResponseB_[2120];
142 
143  // Holds the communications device
146 
147  // Stores the totals
154 
155  // Threshold values from config
158 
159  struct BattStick
160  {
161  // Constructor
162  BattStick();
163 
164  // The battery temp
165  float temp_;
167 
168  // The battery voltage
169  float voltage_;
171 
172  // The battery current
173  float current_;
175 
176  // The battery capacity
177  float capacity_;
179 
180  // The battery status
181  int status_;
182  // And its writer
184 
185  // The battery serial number
186  unsigned int serialNumber_;
188  };
189 
190  // Array to store the battery packs and their associated writers
192 
197 
198  // Configuration Readers
199  ConfigReader* batteryCapacityThresholdCfgReader_; // Amount of charge left at which we return to the surface
200  ConfigReader* batteryVoltageThresholdCfgReader_; // Amount of voltage left at which we return to the surface
201 
202  // Reads in the SMBus data from the Ocean Server cards and writes to the slate
203  bool parseWriteDataA( int size, int offset );
204  bool parseWriteDataB( int size, int offset );
205 
206  // Checks all battery sticks to see if their voltage has been logged
207  // A return value of true indicates that data for a given stick has been recorded.
208  // Relies on setVoltagesNull to clear them again for further checking
209  bool voltagesPopulated();
210 
211  // Sets the voltage for each battery stick to null as a
212  // flag to indicate that recent data has not been obtained
213  // for a given stick
214  void setVoltagesNull( void );
215 
216  // Sets the writer's validity to invalid for true or valid for false
217  void setWritersInvalid( bool invalid );
218 
219  // Once all battery sticks have been freshly populated with
220  // data, this function will add up all the grand totals
221  void calculateTotals( void );
222 
223  // Checks to see that our current capacity is above the threshold
224  void checkBatt( const float capacity, const float voltage );
225 
226  // Returns a non-zero number of bytes that are valid or 0 if not valid.
227  // Sets the message offset based on the number of bytes received.
228  int validData( int dataToCheck, int &msgOffset );
229 
230  // Sends the break (space) character to the Intelligent Battery and Power System
231  void sendIBPSBreak( void );
232 
233  // Returns true if both ports are initialized to the banner menu offering hex output
234  bool menusInitialized();
235 
236  // indicates whether things are ok to run
237  bool ok_;
238 
239  // indicates that A or B banks have been sucessfully parsed
241 
242  // True if we have detected an under threshold value for capacity or voltage
245 
246 
247 };
248 
249 #endif /*BPC1_H*/
void calculateTotals(void)
Definition: BPC1.cpp:788
Contains the SyncComponent class definition.
virtual RunState pause()
Pause for a short period (indicated by pauseTime)
Definition: BPC1.cpp:306
Timestamp muxTime_
Definition: BPC1.h:119
Contains the LoadControl class declaration.
bool readConfig()
Definition: BPC1.cpp:185
bool aParsed_
Definition: BPC1.h:240
A DataAccessor that reads values from the Slate Contains a default dataValue that must not be NULL...
Definition: UniversalDataReader.h:26
bool voltagesPopulated()
Definition: BPC1.cpp:739
bool ok_
Definition: BPC1.h:237
virtual RunState pausing()
Waiting to be paused.
Definition: BPC1.cpp:320
virtual RunState starting()
Might follow a STOP...START sequence.
Definition: BPC1.cpp:269
BattStick()
Definition: BPC1.cpp:888
Abstract Base class for components that collect data for use later in the computation cycle...
Definition: SyncComponent.h:172
ConfigReader * batteryVoltageThresholdCfgReader_
Definition: BPC1.h:200
virtual ConfigURI getConfigURI(ConfigOption configOption) const
Should return [myNamespace]::SIMULATE_HARDWARE, or [myNamespace]::POWER, etc.
Definition: BPC1.cpp:873
DataWriter * battStatusWriter_
Definition: BPC1.h:183
BattStick battSticks_[NUMBATTSA+NUMBATTSB]
Definition: BPC1.h:191
virtual RunState stop()
Initial state – can be later followed by START.
Definition: BPC1.cpp:496
void setWritersInvalid(bool invalid)
Definition: BPC1.cpp:766
Timespan battTimeout_
Definition: BPC1.h:117
virtual RunState runnable()
Should eventually follow a START request or RESETTING.
Definition: BPC1.cpp:384
Definition: BPC1.h:129
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: UniversalDataWriter.h:24
DataWriter * battTempWriter_
Definition: BPC1.h:166
Definition: BPC1.h:130
RunState
Definition: Component.h:115
Contains the UartStream class declaration.
virtual ~BPC1()
Definition: BPC1.cpp:174
Timespan class, represents a delta of time.
Definition: Timestamp.h:248
Definition: BPC1.h:133
unsigned int serialNumber_
Definition: BPC1.h:186
static BPC1 * Instance_
Pointer to the singleton-like instance of this component.
Definition: BPC1.h:109
UniversalDataWriter * batteryChargeWriter_
Definition: BPC1.h:193
UartStream uartB_
Definition: BPC1.h:145
Implements both InStream and OutStream for the LPC3XXX Standard UART.
Definition: UartStream.h:26
#define NUMBATTSA
Definition: BPC1.h:21
bool isDataRequested()
Definition: BPC1.cpp:545
char deviceResponseA_[2120]
Definition: BPC1.h:140
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: DataWriter.h:27
float batteryCapacityThreshold_
Definition: BPC1.h:156
Definition: ElementURI.h:166
Definition: BPC1.h:126
UartStream uartA_
Definition: BPC1.h:144
virtual RunState resetting()
Might occur in case of Error.
Definition: BPC1.h:81
Timestamp startTimeA_
Definition: BPC1.h:118
Definition: BPC1.h:132
Definition: BPC1.h:125
virtual RunState stopped()
Initial state – can be later followed by START.
Definition: BPC1.cpp:521
float capacity_
Definition: BPC1.h:177
float totalVoltageA_
Definition: BPC1.h:151
Module is the abstract base class for a collection of Component objects that can be contained in a lo...
Definition: Module.h:45
float totalVoltageB_
Definition: BPC1.h:153
Definition: BPC1.h:128
void checkBatt(const float capacity, const float voltage)
Definition: BPC1.cpp:803
Timespan poTimeout_
Definition: BPC1.h:117
Definition: BPC1.h:135
Definition: BPC1.h:127
virtual RunState stopping()
Might follow a STOP request.
Definition: BPC1.cpp:510
char deviceResponseB_[2120]
Definition: BPC1.h:141
UniversalDataWriter * batteryFullyChargedWriter_
Definition: BPC1.h:196
float batteryVoltageThreshold_
Definition: BPC1.h:157
virtual RunState resume()
Resume from PAUSE.
Definition: BPC1.cpp:360
Specifies the interface details for the BPC1 component in the SensorModule.
float totalCapacity_
Definition: BPC1.h:148
bool voltageFailed_
Definition: BPC1.h:244
#define NUMBATTSB
Definition: BPC1.h:22
Definition: ConfigReader.h:13
virtual RunState resuming()
Might follow a PAUSE...RESUME sequence.
Definition: BPC1.cpp:377
bool debug_
Definition: BPC1.h:115
DataWriter * battCurrentWriter_
Definition: BPC1.h:174
virtual void uninitialize()
Provide a space for uninitialization.
Definition: BPC1.cpp:204
void setVoltagesNull(void)
Definition: BPC1.cpp:756
Contains the Logger class definition.
DataWriter * battSerialWriter_
Definition: BPC1.h:187
bool bParsed_
Definition: BPC1.h:240
bool parseWriteDataB(int size, int offset)
Definition: BPC1.cpp:642
Timespan muxTimeout_
Definition: BPC1.h:117
float totalVoltage_
Definition: BPC1.h:149
UniversalDataWriter * batteryDischargingWriter_
Definition: BPC1.h:195
BPC1(const Module *module)
Definition: BPC1.cpp:129
float voltage_
Definition: BPC1.h:169
virtual void run()
The actual "payload" of the component.
Definition: BPC1.cpp:180
void sendIBPSBreak(void)
Definition: BPC1.cpp:854
SMBStatus
Definition: BPC1.h:122
Definition: BPC1.h:134
Provides software interface to the Battery Pack Controller.
Definition: BPC1.h:45
int status_
Definition: BPC1.h:181
float temp_
Definition: BPC1.h:165
Definition: BPC1.h:159
Timestamp startTime_
Definition: BPC1.h:119
float totalCapacityB_
Definition: BPC1.h:152
virtual RunState start()
Do what needs to be done to run Similar to initialize, in old init/run/uninit sequence.
Definition: BPC1.cpp:219
bool parseWriteDataA(int size, int offset)
Definition: BPC1.cpp:551
bool menusInitialized()
Definition: BPC1.cpp:862
Timestamp startTimeB_
Definition: BPC1.h:118
ConfigOption
Definition: Component.h:456
int validData(int dataToCheck, int &msgOffset)
Definition: BPC1.cpp:819
bool capacityFailed_
Definition: BPC1.h:243
DataWriter * battCapacityWriter_
Definition: BPC1.h:178
float current_
Definition: BPC1.h:173
ConfigReader * batteryCapacityThresholdCfgReader_
Definition: BPC1.h:199
virtual RunState paused()
Should eventually follow a PAUSE request: should set continueTime.
Definition: BPC1.cpp:349
Represents absolute times.
Definition: Timestamp.h:31
UniversalDataWriter * batteryVoltageWriter_
Definition: BPC1.h:194
DataWriter * battVoltageWriter_
Definition: BPC1.h:170
float totalCapacityA_
Definition: BPC1.h:150