NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/daqLib/daqLib.cpp

Revision 14 (checked in by haines, 17 years ago)

--

Line 
1 /*
2  * daqLib.cpp: Simple library for NC-COOS tower computer
3  *
4  * Author: Sara Haines
5  *
6  * Copyright 2004 All Rights Reserved
7  * University of North Carolina at Chapel Hill
8  * Department of Marine Science
9  *
10  * Synopsis: This module provides system functions for the eVB program
11  * called "data_acquisition.vb" that are not available in embedded
12  * Visual Basic as required by the North Carolina Coastal Ocean
13  * Observing System (NC-COOS) tower computer package.
14  *
15  *
16  * version      date            description                                                                     initials
17  * -------      ----------      ------------------------------------------      --------
18  *
19  * 1.0          04/04/2004      API build, start with storageStatus                     SMH
20  * 1.0          04/09/2004      API test usage with daqLibTest (eVB)            SMH
21  * 1.0          04/10/2004      Added storagePercent, memoryStatus, and         SMH
22  *                                              memoryPercentage
23  * 1.0      05/04/2004  Added getDirNumFiles                        SMH
24  *
25  */
26
27 /*
28  * Includes
29  */
30
31 #include "stdafx.h"
32 #include "daqLib.h"
33
34 BOOL APIENTRY DllMain( HANDLE hModule,
35                        DWORD  ul_reason_for_call,
36                        LPVOID lpReserved
37                                          )
38 {
39     switch (ul_reason_for_call)
40         {
41                 case DLL_PROCESS_ATTACH:
42                 case DLL_THREAD_ATTACH:
43                 case DLL_THREAD_DETACH:
44                 case DLL_PROCESS_DETACH:
45                         break;
46     }
47     return TRUE;
48 }
49
50
51 /*
52  * Name: storageStatus
53  *
54  * Description: report disk usage and free space of specified disk
55  *
56  * returns: boolean which is true if no error
57  *
58  * args: localFilePath - string with full path to file name
59  *                          (e.g. "\\DiskOnChip")
60  *       returnInfo  - formatted string of free, total, and percentage of
61  *                     disk space
62  *
63  * Notes:
64  */
65
66 DAQLIB_API BOOL storageStatus(TCHAR* localFilePath, TCHAR* returnInfo)
67 {
68
69         TCHAR bfr[MAXIMUM_RETURN_INFO_LEN + 1];
70
71         ULARGE_INTEGER ulFree, ulTotalBytes, ulTotalFree;
72         double FreePercent;
73
74         if( GetDiskFreeSpaceEx(localFilePath,&ulFree,&ulTotalBytes,&ulTotalFree) )
75         {
76                 _stprintf(bfr, TEXT("Bytes available to caller: %lu\r\n"), ulFree);
77                 _tcscpy(returnInfo, bfr);
78
79                 _stprintf(bfr, TEXT("Total number of bytes: %lu\r\n"), ulTotalBytes);
80                 _tcscat(returnInfo, bfr);
81
82                 _stprintf(bfr, TEXT("Total num. of free bytes: %lu\r\n"), ulTotalFree);
83                 _tcscat(returnInfo, bfr);
84                        
85                 FreePercent = 100*double(ulTotalFree.LowPart)/double(ulTotalBytes.LowPart);
86
87                 _stprintf(bfr, TEXT("Percentage of free space: %5.2f\r\n"), FreePercent);
88                 _tcscat(returnInfo, bfr);
89
90                 return TRUE;
91         }
92         else
93         {
94                 _stprintf(bfr, TEXT("Could not read storage object\r\n"));
95                 _tcscpy(returnInfo, bfr);
96
97                 return FALSE;
98         }
99
100 }
101
102 /*
103  * Name: storagePercentage
104  *
105  * Description: report free space of specified disk as percent
106  *
107  * returns: boolean which is true if no error
108  *
109  * args: localFilePath - string with full path to file name
110  *                          (e.g. "\\DiskOnChip")
111  *       returnInfo  - formatted string of percentage of free disk space
112  *
113  * Notes:
114  */
115
116 DAQLIB_API BOOL storagePercentage(TCHAR* localFilePath, TCHAR* returnInfo)
117 {
118
119         TCHAR bfr[MAXIMUM_RETURN_INFO_LEN + 1];
120
121         ULARGE_INTEGER ulFree, ulTotalBytes, ulTotalFree;
122         double FreePercent, numMb;
123
124         if( GetDiskFreeSpaceEx(localFilePath,&ulFree,&ulTotalBytes,&ulTotalFree) )
125         {
126
127                 FreePercent = 100*double(ulTotalFree.LowPart)/double(ulTotalBytes.LowPart);
128                 numMb = double(ulTotalBytes.LowPart)/1000000;
129
130                 _stprintf(bfr, TEXT("%4.1f%c of %5.1f Mb"), FreePercent, char(37), numMb);
131                 _tcscpy(returnInfo, bfr);
132                
133                 return TRUE;
134         }
135         else
136         {
137                 _stprintf(bfr, TEXT("Could not read storage object\r\n"));
138                 _tcscpy(returnInfo, bfr);
139
140                 return FALSE;
141         }
142
143 }
144
145 /*
146  * Name: getDirNumFiles
147  *
148  * Description:
149  *
150  * Returns:
151  *
152  * Args: lpFileMask - long pointer to full path to file name and filename glob
153  *                          (e.g. "\\Storage Card\\Data\\*.*")
154  *
155  * Notes:
156  *
157  */
158
159 DAQLIB_API int getDirNumFiles(TCHAR* FileMask)
160 {
161         HANDLE hFindFile;
162         WIN32_FIND_DATA fdData;
163         int numFiles;
164
165         numFiles = 0;
166
167         //get first file
168         hFindFile = FindFirstFile(FileMask, &fdData);
169         if(hFindFile != INVALID_HANDLE_VALUE) {
170                 numFiles++;
171                 //PrintFindData(&fdData);
172                 while(FindNextFile(hFindFile, &fdData)) {
173                         //PrintFindData(&fdData);
174                         numFiles++;
175                 }
176                 FindClose(hFindFile);
177         }
178         else {
179                 // report error
180                 numFiles = 0;
181         }
182
183         return numFiles;
184
185 }
186
187 /*
188  * Name: memoryStatus
189  *
190  * Description: report instantaneous about current memory usage for Win CE
191  *
192  * returns: boolean which is true
193  *
194  * args: returnInfo  - formatted string of physical, page, and virtual memory
195  *
196  * Notes:
197  */
198
199 DAQLIB_API BOOL memoryStatus(TCHAR* returnInfo)
200 {
201         TCHAR bfr[MAXIMUM_RETURN_INFO_LEN + 1];
202         double FreePercent;
203
204         MEMORYSTATUS ms;
205         ms.dwLength = sizeof(ms);
206
207         GlobalMemoryStatus(&ms);
208
209         _stprintf(bfr, TEXT("Total Phys: %d\r\n"), ms.dwTotalPhys);
210         _tcscpy(returnInfo, bfr);
211
212         _stprintf(bfr, TEXT("Avail Phys: %d\r\n"), ms.dwAvailPhys);
213         _tcscat(returnInfo, bfr);
214
215         FreePercent = 100*double(ms.dwAvailPhys)/double(ms.dwTotalPhys);
216         _stprintf(bfr, TEXT("Free Percent Phys: %5.2f\r\n"), FreePercent);
217         _tcscat(returnInfo, bfr);
218
219         /* // paging not available in Win CE so do not report it
220         _stprintf(bfr, TEXT("Total Page: %d\r\n"), ms.dwTotalPageFile);
221         _tcscat(returnInfo, bfr);
222
223         _stprintf(bfr, TEXT("Avail Page: %d\r\n"), ms.dwAvailPageFile);
224         _tcscat(returnInfo, bfr);
225          */
226
227         _stprintf(bfr, TEXT("Total Virtual: %d\r\n"), ms.dwTotalVirtual);
228         _tcscat(returnInfo, bfr);
229
230         _stprintf(bfr, TEXT("Avail Virtual: %d\r\n"), ms.dwAvailVirtual);
231         _tcscat(returnInfo, bfr);
232
233         FreePercent = 100*double(ms.dwAvailVirtual)/double(ms.dwTotalVirtual);
234         _stprintf(bfr, TEXT("Free Percent Virtual: %5.2f\r\n"), FreePercent);
235         _tcscat(returnInfo, bfr);
236
237         return TRUE;
238 }
239
240 /*
241  * Name: memoryPhysPercentage
242  *
243  * Description: report instantaneous about current physical memory usage for Win CE
244  *
245  * returns: boolean which is true
246  *
247  * args: returnInfo  - formatted string of percent of free physical memory
248  *
249  * Notes:
250  */
251
252 DAQLIB_API BOOL memoryPhysPercentage(TCHAR* returnInfo)
253 {
254         TCHAR bfr[MAXIMUM_RETURN_INFO_LEN + 1];
255         double FreePercent, numMb;
256
257         MEMORYSTATUS ms;
258         ms.dwLength = sizeof(ms);
259
260         GlobalMemoryStatus(&ms);
261
262         FreePercent = 100*double(ms.dwAvailPhys)/double(ms.dwTotalPhys);
263         numMb = double(ms.dwTotalPhys)/1024/1024;
264
265         _stprintf(bfr, TEXT("%5.1f%c of %5.1f Mb"), FreePercent, char(37), numMb);
266         _tcscpy(returnInfo, bfr);
267
268         return TRUE;
269
270 }
271
272 /*
273  * Name: memoryVirutalPercentage
274  *
275  * Description: report instantaneous about current virtual memory usage for Win CE
276  *
277  * returns: boolean which is true
278  *
279  * args: returnInfo  - formatted string of percent of free virtual memory
280  *
281  * Notes:
282  */
283
284 DAQLIB_API BOOL memoryVirtualPercentage(TCHAR* returnInfo)
285 {
286         TCHAR bfr[MAXIMUM_RETURN_INFO_LEN + 1];
287         double FreePercent, numMb;
288
289         MEMORYSTATUS ms;
290         ms.dwLength = sizeof(ms);
291
292         GlobalMemoryStatus(&ms);
293
294         FreePercent = 100*double(ms.dwAvailVirtual)/double(ms.dwTotalVirtual);
295         numMb = double(ms.dwTotalVirtual)/1024/1024;
296
297         _stprintf(bfr, TEXT("%5.1f%c of %5.1f Mb"), FreePercent, char(37), numMb);
298         _tcscpy(returnInfo, bfr);
299
300         return TRUE;
301
302 }
Note: See TracBrowser for help on using the browser.