trivial RFID tag database

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Wed Sep 24 18:52:53 2014 +0000
Parent:
2:5a7b822b54d7
Commit message:
renamed

Changed in this revision

ReportDB.cpp Show annotated file Show diff for this revision Revisions of this file
ReportDB.h Show annotated file Show diff for this revision Revisions of this file
WidgetDB.cpp Show diff for this revision Revisions of this file
WidgetDB.h Show diff for this revision Revisions of this file
diff -r 5a7b822b54d7 -r ea6ac7464011 ReportDB.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ReportDB.cpp	Wed Sep 24 18:52:53 2014 +0000
@@ -0,0 +1,115 @@
+/* Copyright C2014 ARM, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files the "Software", to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+ 
+ #include "ReportDB.h"
+ 
+ // min function
+ extern "C" int min(int val1,int val2) {
+     if (val1 < val2) return val1;
+     return val2;
+ }
+ 
+ // constructor
+ ReportDB::ReportDB() {
+     this->initDB();
+ }
+ 
+ // destructor
+ ReportDB::~ReportDB() {
+ }
+ 
+ // lookup and return a report
+ ReportEntry *ReportDB::lookup(int rfid) {
+     ReportEntry *entry = NULL;
+     bool         found = false;
+     
+     // linear search through the list until we end or find something...
+     for(int i=0;i<DB_MAX_NUM_REPORTS &&!found;++i) {
+         if (this->m_db[i].rfid == rfid) {
+             found = true;
+             entry = &(this->m_db[i]);
+         }
+     }
+     
+     return entry;
+ }
+ 
+ // lookup a report and return its name
+ char *ReportDB::lookupReportName(int rfid) {
+     ReportEntry *entry = this->lookup(rfid);
+     if (entry != NULL) return entry->name;
+     return NULL;
+ }
+ 
+  // lookup a report and return its description
+ char *ReportDB::lookupReportDescription(int rfid) {
+     ReportEntry *entry = this->lookup(rfid);
+     if (entry != NULL) return entry->description;
+     return NULL;
+ }
+     
+ // lookup a report and return its condition
+ char *ReportDB::lookupReportCondition(int rfid) {
+     ReportEntry *entry = this->lookup(rfid);
+     if (entry != NULL) return entry->condition;
+     return NULL;
+ }
+ 
+ // lookup a report and return its latitude
+ char *ReportDB::lookupReportLatitude(int rfid) {
+     ReportEntry *entry = this->lookup(rfid);
+     if (entry != NULL) return entry->latitude;
+     return NULL;
+ }
+ 
+ // lookup a report and return its longitude
+ char *ReportDB::lookupReportLongitude(int rfid) {
+     ReportEntry *entry = this->lookup(rfid);
+     if (entry != NULL) return entry->longitude;
+     return NULL;
+ }
+ 
+ // initialize the simple report DB
+ void ReportDB::initDB() {
+     // First Report
+     memset((void *)&(this->m_db[FIRST_REPORT]),0,sizeof(ReportEntry));
+     this->m_db[FIRST_REPORT].rfid = FIRST_REPORT_RFID;
+     strncpy(this->m_db[FIRST_REPORT].name,FIRST_REPORT_NAME,min(strlen(FIRST_REPORT_NAME),DB_MAX_NAME_LENGTH));
+     strncpy(this->m_db[FIRST_REPORT].description,FIRST_REPORT_DESCRIPTION,min(strlen(FIRST_REPORT_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
+     strncpy(this->m_db[FIRST_REPORT].condition,FIRST_REPORT_CONDITION,min(strlen(FIRST_REPORT_CONDITION),DB_MAX_CONDITION_LENGTH));
+     strncpy(this->m_db[FIRST_REPORT].latitude,FIRST_REPORT_LATITUDE,min(strlen(FIRST_REPORT_LATITUDE),DB_MAX_LATLONG_LENGTH));
+     strncpy(this->m_db[FIRST_REPORT].longitude,FIRST_REPORT_LONGITUDE,min(strlen(FIRST_REPORT_LONGITUDE),DB_MAX_LATLONG_LENGTH));
+     
+     // Second Report
+     memset((void *)&(this->m_db[SECOND_REPORT]),0,sizeof(ReportEntry));
+     this->m_db[SECOND_REPORT].rfid = SECOND_REPORT_RFID;
+     strncpy(this->m_db[SECOND_REPORT].name,SECOND_REPORT_NAME,min(strlen(SECOND_REPORT_NAME),DB_MAX_NAME_LENGTH));
+     strncpy(this->m_db[SECOND_REPORT].description,SECOND_REPORT_DESCRIPTION,min(strlen(SECOND_REPORT_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
+     strncpy(this->m_db[SECOND_REPORT].condition,SECOND_REPORT_CONDITION,min(strlen(SECOND_REPORT_CONDITION),DB_MAX_CONDITION_LENGTH));
+     strncpy(this->m_db[SECOND_REPORT].latitude,SECOND_REPORT_LATITUDE,min(strlen(SECOND_REPORT_LATITUDE),DB_MAX_LATLONG_LENGTH));
+     strncpy(this->m_db[SECOND_REPORT].longitude,SECOND_REPORT_LONGITUDE,min(strlen(SECOND_REPORT_LONGITUDE),DB_MAX_LATLONG_LENGTH));
+     
+     // Third Report
+     memset((void *)&(this->m_db[THIRD_REPORT]),0,sizeof(ReportEntry));
+     this->m_db[THIRD_REPORT].rfid = THIRD_REPORT_RFID;
+     strncpy(this->m_db[THIRD_REPORT].name,THIRD_REPORT_NAME,min(strlen(THIRD_REPORT_NAME),DB_MAX_NAME_LENGTH));
+     strncpy(this->m_db[THIRD_REPORT].description,THIRD_REPORT_DESCRIPTION,min(strlen(THIRD_REPORT_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
+     strncpy(this->m_db[THIRD_REPORT].condition,THIRD_REPORT_CONDITION,min(strlen(THIRD_REPORT_CONDITION),DB_MAX_CONDITION_LENGTH));
+     strncpy(this->m_db[THIRD_REPORT].latitude,THIRD_REPORT_LATITUDE,min(strlen(THIRD_REPORT_LATITUDE),DB_MAX_LATLONG_LENGTH));
+     strncpy(this->m_db[THIRD_REPORT].longitude,THIRD_REPORT_LONGITUDE,min(strlen(THIRD_REPORT_LONGITUDE),DB_MAX_LATLONG_LENGTH));
+ }
\ No newline at end of file
diff -r 5a7b822b54d7 -r ea6ac7464011 ReportDB.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ReportDB.h	Wed Sep 24 18:52:53 2014 +0000
@@ -0,0 +1,55 @@
+/* Copyright C2014 ARM, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files the "Software", to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+ 
+ #ifndef _REPORT_DB_H_
+ #define _REPORT_DB_H_
+ 
+ #include "Definitions.h"
+ 
+ // trivial widget db entry...
+ typedef struct {
+     int  rfid;
+     char name[DB_MAX_NAME_LENGTH+1];
+     char description[DB_MAX_DESCRIPTION_LENGTH+1];
+     char condition[DB_MAX_CONDITION_LENGTH+1];
+     char latitude[DB_MAX_LATLONG_LENGTH+1];
+     char longitude[DB_MAX_LATLONG_LENGTH+1];
+     
+ } ReportEntry;
+ 
+ // trivial database of reports to generate cases with ...    
+ class ReportDB {
+     private:
+        ReportEntry m_db[DB_MAX_NUM_REPORTS];
+     
+     public:
+        ReportDB();
+        virtual ~ReportDB();
+        
+        char *lookupReportName(int rfid);
+        char *lookupReportDescription(int rfid);
+        char *lookupReportCondition(int rfid);
+        char *lookupReportLatitude(int rfid);
+        char *lookupReportLongitude(int rfid);
+        
+     private:
+        void initDB();
+        ReportEntry *lookup(int rfid);
+ };
+ 
+ #endif // _REPORT_DB_H_
\ No newline at end of file
diff -r 5a7b822b54d7 -r ea6ac7464011 WidgetDB.cpp
--- a/WidgetDB.cpp	Thu Aug 28 21:06:21 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/* Copyright C2014 ARM, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files the "Software", to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- 
- #include "WidgetDB.h"
- 
- // min function
- extern "C" int min(int val1,int val2) {
-     if (val1 < val2) return val1;
-     return val2;
- }
- 
- // constructor
- WidgetDB::WidgetDB() {
-     this->initDB();
- }
- 
- // destructor
- WidgetDB::~WidgetDB() {
- }
- 
- // lookup and return a widget
- WidgetEntry *WidgetDB::lookup(int rfid) {
-     WidgetEntry *entry = NULL;
-     bool         found = false;
-     
-     // linear search through the list until we end or find something...
-     for(int i=0;i<DB_MAX_NUM_WIDGETS &&!found;++i) {
-         if (this->m_db[i].rfid == rfid) {
-             found = true;
-             entry = &(this->m_db[i]);
-         }
-     }
-     
-     return entry;
- }
- 
- // lookup a widget and return its name
- char *WidgetDB::lookupWidgetName(int rfid) {
-     WidgetEntry *entry = this->lookup(rfid);
-     if (entry != NULL) return entry->name;
-     return NULL;
- }
-     
- // lookup a widget and return its description
- char *WidgetDB::lookupWidgetDescription(int rfid) {
-     WidgetEntry *entry = this->lookup(rfid);
-     if (entry != NULL) return entry->description;
-     return NULL;
- }
- 
- // initialize the DB
- void WidgetDB::initDB() {
-     // First Widget
-     memset((void *)&(this->m_db[FIRST_WIDGET]),0,sizeof(WidgetEntry));
-     this->m_db[FIRST_WIDGET].rfid = FIRST_WIDGET_RFID;
-     strncpy(this->m_db[FIRST_WIDGET].name,FIRST_WIDGET_NAME,min(strlen(FIRST_WIDGET_NAME),DB_MAX_NAME_LENGTH));
-     strncpy(this->m_db[FIRST_WIDGET].description,FIRST_WIDGET_DESCRIPTION,min(strlen(FIRST_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
-     
-     // Second Widget
-     memset((void *)&(this->m_db[SECOND_WIDGET]),0,sizeof(WidgetEntry));
-     this->m_db[SECOND_WIDGET].rfid = SECOND_WIDGET_RFID;
-     strncpy(this->m_db[SECOND_WIDGET].name,SECOND_WIDGET_NAME,min(strlen(SECOND_WIDGET_NAME),DB_MAX_NAME_LENGTH));
-     strncpy(this->m_db[SECOND_WIDGET].description,SECOND_WIDGET_DESCRIPTION,min(strlen(SECOND_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
-     
-     // Third Widget
-     memset((void *)&(this->m_db[THIRD_WIDGET]),0,sizeof(WidgetEntry));
-     this->m_db[THIRD_WIDGET].rfid = THIRD_WIDGET_RFID;
-     strncpy(this->m_db[THIRD_WIDGET].name,THIRD_WIDGET_NAME,min(strlen(THIRD_WIDGET_NAME),DB_MAX_NAME_LENGTH));
-     strncpy(this->m_db[THIRD_WIDGET].description,THIRD_WIDGET_DESCRIPTION,min(strlen(THIRD_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
- }
\ No newline at end of file
diff -r 5a7b822b54d7 -r ea6ac7464011 WidgetDB.h
--- a/WidgetDB.h	Thu Aug 28 21:06:21 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/* Copyright C2014 ARM, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files the "Software", to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- 
- #ifndef _WIDGET_DB_H_
- #define _WIDGET_DB_H_
- 
- #include "Definitions.h"
- 
- // trivial widget db entry...
- typedef struct {
-     int  rfid;
-     char name[DB_MAX_NAME_LENGTH+1];
-     char description[DB_MAX_DESCRIPTION_LENGTH+1];
- } WidgetEntry;
- 
- // trivial database of widgets...    
- class WidgetDB {
-     private:
-        WidgetEntry m_db[DB_MAX_NUM_WIDGETS];
-     
-     public:
-        WidgetDB();
-        virtual ~WidgetDB();
-        
-        char *lookupWidgetName(int rfid);
-        char *lookupWidgetDescription(int rfid);
-        
-     private:
-        void initDB();
-        WidgetEntry *lookup(int rfid);
- };
- 
- #endif // _WIDGET_DB_H_
\ No newline at end of file