A simple WIP that logs data from a Grove sensor, and can send and receive information over USB and SMS.
Dependencies: DHT DS_1337 SDFileSystem USBDevice mbed
Handlers/SdHandler.h@0:2df78a4443cd, 2016-04-10 (annotated)
- Committer:
- Joseph Radford
- Date:
- Sun Apr 10 15:47:33 2016 +1000
- Revision:
- 0:2df78a4443cd
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Joseph Radford |
0:2df78a4443cd | 1 | #ifndef __SD_HANDLER_H__ |
Joseph Radford |
0:2df78a4443cd | 2 | #define __SD_HANDLER_H__ |
Joseph Radford |
0:2df78a4443cd | 3 | |
Joseph Radford |
0:2df78a4443cd | 4 | #include "SDFileSystem.h" |
Joseph Radford |
0:2df78a4443cd | 5 | #include "AbstractHandler.h" |
Joseph Radford |
0:2df78a4443cd | 6 | |
Joseph Radford |
0:2df78a4443cd | 7 | class CircBuff; |
Joseph Radford |
0:2df78a4443cd | 8 | |
Joseph Radford |
0:2df78a4443cd | 9 | /*! |
Joseph Radford |
0:2df78a4443cd | 10 | * \brief The SdHandler class writes messages to file and handles SD card status |
Joseph Radford |
0:2df78a4443cd | 11 | * |
Joseph Radford |
0:2df78a4443cd | 12 | * A data CSV file is written with timestamps and the result from the GroveDht22. |
Joseph Radford |
0:2df78a4443cd | 13 | * A system log, not yet fully implemented, tracks system events for debugging purposes. |
Joseph Radford |
0:2df78a4443cd | 14 | */ |
Joseph Radford |
0:2df78a4443cd | 15 | class SdHandler : public AbstractHandler |
Joseph Radford |
0:2df78a4443cd | 16 | { |
Joseph Radford |
0:2df78a4443cd | 17 | public: |
Joseph Radford |
0:2df78a4443cd | 18 | SdHandler(MyTimers * _timer); |
Joseph Radford |
0:2df78a4443cd | 19 | ~SdHandler(); |
Joseph Radford |
0:2df78a4443cd | 20 | |
Joseph Radford |
0:2df78a4443cd | 21 | void run(); |
Joseph Radford |
0:2df78a4443cd | 22 | |
Joseph Radford |
0:2df78a4443cd | 23 | void setRequest(int request, void *data = 0); |
Joseph Radford |
0:2df78a4443cd | 24 | |
Joseph Radford |
0:2df78a4443cd | 25 | bool sdOk(); |
Joseph Radford |
0:2df78a4443cd | 26 | |
Joseph Radford |
0:2df78a4443cd | 27 | enum request_t { |
Joseph Radford |
0:2df78a4443cd | 28 | sdreq_SdNone, ///< to init |
Joseph Radford |
0:2df78a4443cd | 29 | sdreq_LogData, ///< Send struct containing a result and timestamp. This turns it into a line in a csv file |
Joseph Radford |
0:2df78a4443cd | 30 | sdreq_LogSystem ///< write raw string to system logging file (errors, events, etc) |
Joseph Radford |
0:2df78a4443cd | 31 | }; |
Joseph Radford |
0:2df78a4443cd | 32 | |
Joseph Radford |
0:2df78a4443cd | 33 | private: |
Joseph Radford |
0:2df78a4443cd | 34 | SDFileSystem * m_sdfs; |
Joseph Radford |
0:2df78a4443cd | 35 | FILE * m_data; |
Joseph Radford |
0:2df78a4443cd | 36 | FILE * m_syslog; |
Joseph Radford |
0:2df78a4443cd | 37 | |
Joseph Radford |
0:2df78a4443cd | 38 | enum mode_t{ |
Joseph Radford |
0:2df78a4443cd | 39 | sd_Start, ///< Set up the state machine |
Joseph Radford |
0:2df78a4443cd | 40 | sd_CheckSysLogBuffer, ///< See if any data should be written to the log file |
Joseph Radford |
0:2df78a4443cd | 41 | sd_CheckDataLogBuffer, ///< See if any data should be written to the data file |
Joseph Radford |
0:2df78a4443cd | 42 | |
Joseph Radford |
0:2df78a4443cd | 43 | sd_WaitError ///< Error. wait for a while |
Joseph Radford |
0:2df78a4443cd | 44 | }; |
Joseph Radford |
0:2df78a4443cd | 45 | mode_t mode; |
Joseph Radford |
0:2df78a4443cd | 46 | |
Joseph Radford |
0:2df78a4443cd | 47 | request_t m_lastRequest; |
Joseph Radford |
0:2df78a4443cd | 48 | |
Joseph Radford |
0:2df78a4443cd | 49 | // helpers |
Joseph Radford |
0:2df78a4443cd | 50 | void csvStart(time_t time); |
Joseph Radford |
0:2df78a4443cd | 51 | void csvData(const char * s, int len); |
Joseph Radford |
0:2df78a4443cd | 52 | void csvEnd(); |
Joseph Radford |
0:2df78a4443cd | 53 | void logEvent(const char * s); |
Joseph Radford |
0:2df78a4443cd | 54 | |
Joseph Radford |
0:2df78a4443cd | 55 | CircBuff *m_dataLogBuff; ///< Data waiting to be written to the data CSV file |
Joseph Radford |
0:2df78a4443cd | 56 | CircBuff *m_sysLogBuff; ///< Data waiting to be written to the system log file (not yet implemented) |
Joseph Radford |
0:2df78a4443cd | 57 | }; |
Joseph Radford |
0:2df78a4443cd | 58 | |
Joseph Radford |
0:2df78a4443cd | 59 | #endif // __SD_HANDLER_H__ |