Tezzeret  1
Tezzeret
/home/kddev/dev/TivaWorkspace/TezzeretApps/GmWebServer.hpp
1 #ifndef GMWEBSERVER_HPP_
2 #define GMWEBSERVER_HPP_
3 
4 #ifndef _GEO_APPDEFS_HPP
5 #include <GmCommon/GeoAppDefs.hpp>
6 #endif
7 
8 /* XDCtools Header files */
9 #include <xdc/std.h>
10 #include <xdc/cfg/global.h>
11 #include <xdc/runtime/System.h>
12 
13 /* BIOS Header files */
14 //#include <ti/sysbios/BIOS.h>
15 #include <ti/sysbios/BIOS.h>
16 #include <ti/sysbios/knl/Task.h>
17 #include <ti/sysbios/knl/Clock.h>
18 
19 
20 #include <inc/hw_memmap.h>
21 #if GEO_NET_NDK == GEO_TRUE
22 #include <usertype.h>
23 #include <netmain.h>
24 #include "GmEth/http-port/rhc_usertype.h"
25 #include "GmEth/http-port/rhc_osif.h"
26 #include "GmEth/http-port/rhc_httpif.h"
27 #include "GmEth/http-port/rhc_http.h"
28 /*
29 #include <ti/ndk/nettools/http/http.h>
30 #include <ti/ndk/nettools/http/http.h>
31 #include <ti/ndk/inc/nettools/inc/httpif.h>
32 #include <ti/ndk/inc/os/osif.h>
33 */
34 #endif
35 #if GEO_NET_3100 == GEO_TRUE
36 #include <socket.h>
37 #include <simplelink.h>
38 #include "GmEth/http-port/rhc_usertype.h"
39 #include "GmEth/http-port/rhc_osif.h"
40 #include "GmEth/http-port/rhc_httpif.h"
41 #include "GmEth/http-port/rhc_http.h"
42 //#include <netmain.h>
43 #endif
44 #include <TezzeretBoardAliases.h>
45 
46 #if UNMIRRORED_STORAGE == GEO_TRUE
47 #include <GmCharRingBufferStorage.hpp>
48 #else
49 #if GEO_SDCARD == GEO_TRUE
50 #include <GmTivaSDStorage.hpp>
51 #endif
52 #if GEO_USB_STORAGE == GEO_TRUE
53 #include <GmTivaUsbStorage.hpp>
54 #endif
55 #endif
56 #include <GmSdStorage.hpp>
57 #include <GmError.hpp>
58 #include <GmStatus.hpp>
59 #include <functional>
60 
61 #if MFAM_SYS_MGMT == GEO_TRUE
62 #include "GmSysMgmt.hpp"
63 #endif
64 
65 #if MFAM_MODULE == GEO_TRUE
66 #include <GmMFAMDataSource.hpp>
67 #endif
68 
69 #include <TezzeretApp.hpp>
70 
71 namespace Geometrics
72 {
83  class GmWebServer {
84  public:
85  GmWebServer();
86  virtual ~GmWebServer();
87 
88  protected:
89  static int ProcessAcquisitionDataFiles (char *pSurveyId, char *strAcquisitionId,
90  Bool isPreprocessingStage,
91  const int filesReported,
92  const int kbytesInFiles,
93  std::function<int (const char * buffer)> handler,
94  std::function<int (const int filesReported,
95  const int kbytesInFiles)> finalReport);
96 
97  public:
98  // (SOCKET,RHC_HTTP_MSG *pMsg, UINT8* args);
99  static Int WebCommand (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
100  static Int ListAcquisitionDataFilesJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
101  static Int ListAcquisitionDataFiles (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
102  static Int ListSurveys (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
103  static Int ListSurveysJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
104  static Int ListAcquisitionsJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
105  static Int ListAcquisitionsJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
106  static Int CloseCurrentSurveyExJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
107  static Int CloseCurrentAcqExJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
108  static Int NewAcquisition (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
109  static Int SelectSurveyJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
110  static Int SelectAcqJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
111  static Int NewAcqJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
112  static Int NewAcquisitionJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
113  static Int NewSurveyJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
114  static Int DeleteSurvey (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
115  static Int SetActiveAcquisition (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
116  static Int NameActiveAcquisitionJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
117  static Int SetActiveAcquisitionNameJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
118  static Int AddAcquisitionInfoJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
119  static Int GetActiveAcquisitionNameJson (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
120  static Int WebDeleteSession (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
121  static int ShowLoggingConfig (SOCKET s, char* buf);
122  static int StatusJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
123  static Int JsonGet (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
124  static Int GetTestFileUploadForm (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
125  static Int statusDetails (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
126  static Int getStatus (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
127  static Int getStatusInternal (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args, Bool autoRefresh = FALSE);
128  static Int sysInfo (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
129  static Int CleanOldFiles (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
130  static Int ShutdownSystem (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
131  static Int ResetSystem (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
132  static Int TestFileUpload (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
133  static Int getStatusTxt (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
134  static Int WifiCheck (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
135 
136  /********************************************************************************************/
137  /* Support for MagArrow HTML JSON-based UI */
138  /********************************************************************************************/
139  static Int DiagnosticsJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
140  #if (GEO_7998_BATTERY_MONITOR == GEO_TRUE)||(GEO_7993_BATTERY_MONITOR == GEO_TRUE)||(MFAM_SYS_MGMT == GEO_TRUE)
141  static Int BatteryJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
142  #endif
143  #if (GEO_4151_BATTERY_MONITOR == GEO_TRUE)||(GEO_7998_BATTERY_MONITOR == GEO_TRUE)||(GEO_7993_BATTERY_MONITOR == GEO_TRUE)
144  static int Batteries (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
145  #endif
146  static int StatusJsonEx2 (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
147 
148  /* Query the system about current status and configuration. New fields may be added to the
149  * response, as long as existing fields remain intact; clients must be able to decode the
150  * JSON document using keywords and not depending on absolute position. See implementation
151  * for fields returned in the JSON.
152  */
153  static int SysInfoJsonEx (SOCKET s, struct rhc_http_msg *pMsg, UINT8* args);
154  static int GpsJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
155  static int Mark (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
156  static int MarkTarget (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
157  // #if LOKI_PICKLE_SWITCH == GEO_TRUE
158  static int Destination (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
159  // #endif
160  static int RequestSynch (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
161  static int RequestDeleteSegment (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
162  static int SetSamplePeriod (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
163  static int AcquisitionsJsonEx2 (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
164  static int MagnetometersJsonEx (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
165 
167  static int GenericJsonRequest (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
168  static int AcquisitionEx (SOCKET s, const char *strSurveyId, const char *strAcquisitionId, RHC_HTTP_MSG *pMsg, UINT8* args);
169  static int FilesJsonEx (SOCKET s, const char *strSurveyId, const char *strAcquisitionId, RHC_HTTP_MSG *pMsg, UINT8* args);
170  static Bool UriIsAcquisition (const char *strUri,
171  char *strSurveyId,
172  char *strAcquisitionId);
173  static Bool GetSurveyIdFromUri (const char *strUri,
174  char *dest);
175  static int DownloadDataFile (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
176  static int DownloadAcquisition (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args,
177  const char *strSurveyId, const char *strAcquisitionId);
178 
179  /******************************************************************************************************/
180  /* Stream contents without header. This is when streaming acquisition consisting of multiple files. */
181  /******************************************************************************************************/
182  static int StreamFileContents (SOCKET s, const char *strSurveyId, const char *strAcquisitionId,
183  const char *strFileName);
184  static int StreamFileContents (SOCKET s, const char *strSurveyId, const char *strAcquisitionId,
185  const int fileIndex, const bool filesInDirectories,
186  const int directorySize);
187 
188  static Int SystemTest (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
189 
190  #if MFAM_SYS_MGMT == GEO_TRUE
191  /********************************************************************************************/
192  /* EB System Tests */
193  /********************************************************************************************/
194  //static Int SystemTest (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
195  static Int RunSystemTests (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
196  #endif
197 
198  private:
199  /********************************************************************************************/
200  /* Internal/utility functions. */
201  /********************************************************************************************/
202  static Bool GetAcquisitionIdFromUri (const char *strUri,
203  char *dest);
204 
205  static int DownloadAcquisitionData(SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
206 
207 
208 
209  #if (EMULATE_MFAM_SENSOR == GEO_TRUE) || (MFAM_MODULE == GEO_TRUE)
210  static void AppendMagStatus (char *buffer);
211  static int AppendShortInstrumentStatus (char *buffer);
212  #endif
213  static Int StatusObject (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8 *args, const char *strName,
214  const char *value);
215 
216  /* Append storage status info. Return count of characters added to buffer. */
217  static int AppendStorageIfFailed (char *buffer);
218  static int AppendApplicationName (char *buffer);
219  static int GetGetParameter (char *dest, int iBufferSize, const char *szArgName, UINT8* args);
220  static Int getEmptyList (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
221  static UInt32 GetCommandFromQueryString (char* szArgs);
222 
223 
224  #if (GEO_4151_BATTERY_MONITOR == GEO_TRUE)||(GEO_7998_BATTERY_MONITOR == GEO_TRUE)||(GEO_7993_BATTERY_MONITOR == GEO_TRUE)||(MFAM_SYS_MGMT == GEO_TRUE)
225  static void ReportBatteryMonitor (SOCKET s, RHC_HTTP_MSG *pMsg, UINT8* args);
226  #endif
227 
228  /*********************************************************************************************/
229  /* Support for POST requests. */
230  /*********************************************************************************************/
231  static int SearchStringWithEnd (const char *strHaystack,
232  const char *strNeedle, int iLengthOfHaystack, int *piLengthFound);
233  static int SearchAndShiftString (SOCKET s, RHC_HTTP_MSG *pMsg, char *pData,
234  const char *strBoundary, int iSizeData, int iSizeBuffer,
235  int iContentBytesRead, int *piDataRemainingInBuffer,
236  int *piDataReadFromNetwork);
237  static int FindPostBoundary (SOCKET s, RHC_HTTP_MSG *pMsg, char *pData,
238  const char *strBoundary, int iSizeData, int iContentBytesRead,
239  int *piDataRemainingInBuffer, int *piBytesReadFromNetwork,
240  int iBufferSize);
241  static int ScanToDelimiter (SOCKET s, char* caMetaData,
242  int iMetadataBufferFree, int iDataSize, char *pData,
243  int iDataBufferSize, const char *strDelimiter, int iDelimiterSize,
244  int iContentLengthStillInNetwork, int *piDataCopied,
245  int *piDataReadFromNetwork);
246  static int ReadFormMetadata (SOCKET s, char* caMetaData,
247  int iMetadataBufferSize, char *pData, int iDataBufferSize,
248  int iDataInBuffer, int iTotalContentLengthStillInNetwork,
249  const char *strTerminator, int iDelimiterSize, int *piDataCopied,
250  int *piDataReadFromNetwork);
251  static int DiscardToDelimiter ( SOCKET s,
252  int iDataSize,
253  char *pData,
254  int iDataBufferSize,
255  char *strDelimiter,
256  int iDelimiterSize,
257  int *piDataCopied,
258  int *piDataReadFromNetwork);
259 
260  };
261 }
262 #endif /* GMWEBSERVER_HPP_ */
An HTTP server is an integral part of the framework, both to display UI in a browser and to provide a...
Definition: GmWebServer.hpp:83
static int GenericJsonRequest(SOCKET s, RHC_HTTP_MSG *pMsg, UINT8 *args)
Definition: GmWebServer.cpp:2944
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47