Tezzeret  1
Tezzeret
GeoFatFsStorage.hpp
1 /*
2  * GmTivaSDStorage.hpp
3  *
4  * Created on: May 10, 2016
5  * Author: rcram
6  */
7 
8 #ifndef GM_FATFS_STORAGE_HPP_
9 #define GM_FATFS_STORAGE_HPP_
10 
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <stdbool.h>
15 #include <GmFatFs/ff.h>
16 #include "GmStorage.hpp"
17 
18 
19 
20 /********************************************************************/
21 /* 1024 and 512 work fine with SD cards, but not with
22  USB storage, so 256 it is. It could be possible to switch conditionally
23  during execution, but it's not clear for now why that would be necessary;
24  th4 256-bite issue is not currently a limit.
25  Some discussion about this on the TI forums; the USB standard may
26  limit block transfers to 256 bytes for low speed.
27  (5/2018) RHC */
28 /********************************************************************/
29 #define GEO_MAX_FATFS_BLOCK_SIZE 1024
30 #define GEO_MIN_FATFS_BLOCK_SIZE 256
31 #define GEO_SD_FATFS_BLOCK_SIZE 1024
32 #define GEO_USB_FATFS_BLOCK_SIZE 512
33 
34 namespace Geometrics
35 {
36 
37  class GeoFatFsStorage : public GmStorage
38  {
39  public:
40  GeoFatFsStorage ();
41  ~GeoFatFsStorage ();
42  virtual int Open (const char* szName,
43  const char* szReadWrite);
44  int Seek (UInt32 uiLocation);
45  bool EndOfFile () { return FALSE; };
46  int Verify (int iMarker);
47  int RunTestSuite ();
48  virtual int Shutdown () = 0;
49  int Flush ();
50  int FileSize (const char *strFileName,
51  UInt32* uiSize);
52  int ReadStr (char *strBuffer,
53  int iLength);
54  int ReadRaw (int dummy,
55  char* pcBuffer,
56  UInt32 uiLength,
57  UInt32 *uiActualLengthRead);
58  virtual int Close (int iFileIndex);
59  virtual int WriteData (const char* pcData,
60  unsigned int iDataSize,
61  UInt32 ui32Topic);
62 
63 
64 
65  virtual const char *GetDrive () = 0;
66  virtual int IsFileStorage () { return TRUE; };
67  virtual int IsDataStorage () { return TRUE; };
68 
69 
70 
71 
72  protected: // TODO RHC should not be.
73  bool m_hasOsFile;
74  FIL m_fOsFile;
75  protected:
76  char m_caCurrentOpenFileName [50];
77  int m_iCurrentOpenFile,
78  m_iBufferCount;
79 
80  bool m_bReadOnly;
81  int m_iFatFsBlockSize;
82  char m_caBlockBuffer[GEO_MAX_FATFS_BLOCK_SIZE];
83  virtual int GetFatFsBlockSize () = 0;
84 
85  public:
86  static int s_iLastError;
87 
89  {
90  public:
91  virtual GeoFatFsStorage *MakeNewStorage () = 0;
92  };
93 
94  static GeoFatFsStorage::IFatFsStorageFactory *s_pStorageFactoryPrimary,
95  *s_pStorageFactoryZero,
96  *s_pStorageFactoryOne;
97 
98  static GeoFatFsStorage::IFatFsStorageFactory *GetFactory (const char whichStorage = 0);
99  static void SetFactory (const char whichStorage, GeoFatFsStorage::IFatFsStorageFactory *pFactory);
100  };
101 }
102 
103 
104 
105 #endif /* GMTIVASDSTORAGE_HPP_ */
Definition: GeoFatFsStorage.hpp:89
Definition: GeoFatFsStorage.hpp:38
Definition: GmStorage.hpp:81
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47