fork of ReportDB customized and renamed as a trivial support personnel database

Fork of ReportDB by Doug Anson

Committer:
ansond
Date:
Thu Oct 09 04:03:14 2014 +0000
Revision:
4:90df92778e77
Parent:
ReportDB.cpp@3:ea6ac7464011
updates including name change to support personnel

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 3:ea6ac7464011 1 /* Copyright C2014 ARM, MIT License
ansond 3:ea6ac7464011 2 *
ansond 3:ea6ac7464011 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 3:ea6ac7464011 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 3:ea6ac7464011 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 3:ea6ac7464011 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 3:ea6ac7464011 7 * furnished to do so, subject to the following conditions:
ansond 3:ea6ac7464011 8 *
ansond 3:ea6ac7464011 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 3:ea6ac7464011 10 * substantial portions of the Software.
ansond 3:ea6ac7464011 11 *
ansond 3:ea6ac7464011 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 3:ea6ac7464011 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 3:ea6ac7464011 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 3:ea6ac7464011 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 3:ea6ac7464011 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 3:ea6ac7464011 17 */
ansond 3:ea6ac7464011 18
ansond 4:90df92778e77 19 #include "SupportPersonnelDB.h"
ansond 3:ea6ac7464011 20
ansond 3:ea6ac7464011 21 // min function
ansond 3:ea6ac7464011 22 extern "C" int min(int val1,int val2) {
ansond 3:ea6ac7464011 23 if (val1 < val2) return val1;
ansond 3:ea6ac7464011 24 return val2;
ansond 3:ea6ac7464011 25 }
ansond 3:ea6ac7464011 26
ansond 3:ea6ac7464011 27 // constructor
ansond 4:90df92778e77 28 SupportPersonnelDB::SupportPersonnelDB() {
ansond 3:ea6ac7464011 29 this->initDB();
ansond 3:ea6ac7464011 30 }
ansond 3:ea6ac7464011 31
ansond 3:ea6ac7464011 32 // destructor
ansond 4:90df92778e77 33 SupportPersonnelDB::~SupportPersonnelDB() {
ansond 3:ea6ac7464011 34 }
ansond 3:ea6ac7464011 35
ansond 4:90df92778e77 36 // lookup and return a support person
ansond 4:90df92778e77 37 SupportPersonEntry *SupportPersonnelDB::lookup(int rfid) {
ansond 4:90df92778e77 38 SupportPersonEntry *entry = NULL;
ansond 3:ea6ac7464011 39 bool found = false;
ansond 3:ea6ac7464011 40
ansond 3:ea6ac7464011 41 // linear search through the list until we end or find something...
ansond 4:90df92778e77 42 for(int i=0;i<DB_MAX_NUM_SUPPORT_PERSONS &&!found;++i) {
ansond 3:ea6ac7464011 43 if (this->m_db[i].rfid == rfid) {
ansond 3:ea6ac7464011 44 found = true;
ansond 3:ea6ac7464011 45 entry = &(this->m_db[i]);
ansond 3:ea6ac7464011 46 }
ansond 3:ea6ac7464011 47 }
ansond 3:ea6ac7464011 48
ansond 3:ea6ac7464011 49 return entry;
ansond 3:ea6ac7464011 50 }
ansond 3:ea6ac7464011 51
ansond 4:90df92778e77 52 // lookup a support person and return the name
ansond 4:90df92778e77 53 char *SupportPersonnelDB::lookupName(int rfid) {
ansond 4:90df92778e77 54 SupportPersonEntry *entry = this->lookup(rfid);
ansond 3:ea6ac7464011 55 if (entry != NULL) return entry->name;
ansond 3:ea6ac7464011 56 return NULL;
ansond 3:ea6ac7464011 57 }
ansond 3:ea6ac7464011 58
ansond 4:90df92778e77 59 // lookup a support person and return the description
ansond 4:90df92778e77 60 char *SupportPersonnelDB::lookupDescription(int rfid) {
ansond 4:90df92778e77 61 SupportPersonEntry *entry = this->lookup(rfid);
ansond 3:ea6ac7464011 62 if (entry != NULL) return entry->description;
ansond 3:ea6ac7464011 63 return NULL;
ansond 3:ea6ac7464011 64 }
ansond 3:ea6ac7464011 65
ansond 4:90df92778e77 66 // lookup a support person and return the current status
ansond 4:90df92778e77 67 char *SupportPersonnelDB::lookupStatus(int rfid) {
ansond 4:90df92778e77 68 SupportPersonEntry *entry = this->lookup(rfid);
ansond 4:90df92778e77 69 if (entry != NULL) return entry->status;
ansond 3:ea6ac7464011 70 return NULL;
ansond 3:ea6ac7464011 71 }
ansond 3:ea6ac7464011 72
ansond 4:90df92778e77 73 // lookup a support person and return the current location(latitude)
ansond 4:90df92778e77 74 char *SupportPersonnelDB::lookupLocationLatitude(int rfid) {
ansond 4:90df92778e77 75 SupportPersonEntry *entry = this->lookup(rfid);
ansond 3:ea6ac7464011 76 if (entry != NULL) return entry->latitude;
ansond 3:ea6ac7464011 77 return NULL;
ansond 3:ea6ac7464011 78 }
ansond 3:ea6ac7464011 79
ansond 4:90df92778e77 80 // lookup a support person and return the current location(longitude)
ansond 4:90df92778e77 81 char *SupportPersonnelDB::lookupLocationLongitude(int rfid) {
ansond 4:90df92778e77 82 SupportPersonEntry *entry = this->lookup(rfid);
ansond 3:ea6ac7464011 83 if (entry != NULL) return entry->longitude;
ansond 3:ea6ac7464011 84 return NULL;
ansond 3:ea6ac7464011 85 }
ansond 3:ea6ac7464011 86
ansond 4:90df92778e77 87 // initialize the simple support personnel DB
ansond 4:90df92778e77 88 void SupportPersonnelDB::initDB() {
ansond 4:90df92778e77 89 // First Support Person
ansond 4:90df92778e77 90 memset((void *)&(this->m_db[FIRST_SUPPORT_PERSON]),0,sizeof(SupportPersonEntry));
ansond 4:90df92778e77 91 this->m_db[FIRST_SUPPORT_PERSON].rfid = FIRST_SUPPORT_PERSON_RFID;
ansond 4:90df92778e77 92 strncpy(this->m_db[FIRST_SUPPORT_PERSON].name,FIRST_SUPPORT_PERSON_NAME,min(strlen(FIRST_SUPPORT_PERSON_NAME),DB_MAX_NAME_LENGTH));
ansond 4:90df92778e77 93 strncpy(this->m_db[FIRST_SUPPORT_PERSON].description,FIRST_SUPPORT_PERSON_DESCRIPTION,min(strlen(FIRST_SUPPORT_PERSON_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
ansond 4:90df92778e77 94 strncpy(this->m_db[FIRST_SUPPORT_PERSON].status,FIRST_SUPPORT_PERSON_STATUS,min(strlen(FIRST_SUPPORT_PERSON_STATUS),DB_MAX_STATUS_LENGTH));
ansond 4:90df92778e77 95 strncpy(this->m_db[FIRST_SUPPORT_PERSON].latitude,FIRST_SUPPORT_PERSON_LATITUDE,min(strlen(FIRST_SUPPORT_PERSON_LATITUDE),DB_MAX_LATLONG_LENGTH));
ansond 4:90df92778e77 96 strncpy(this->m_db[FIRST_SUPPORT_PERSON].longitude,FIRST_SUPPORT_PERSON_LONGITUDE,min(strlen(FIRST_SUPPORT_PERSON_LONGITUDE),DB_MAX_LATLONG_LENGTH));
ansond 3:ea6ac7464011 97
ansond 4:90df92778e77 98 // Second Support Person
ansond 4:90df92778e77 99 memset((void *)&(this->m_db[SECOND_SUPPORT_PERSON]),0,sizeof(SupportPersonEntry));
ansond 4:90df92778e77 100 this->m_db[SECOND_SUPPORT_PERSON].rfid = SECOND_SUPPORT_PERSON_RFID;
ansond 4:90df92778e77 101 strncpy(this->m_db[SECOND_SUPPORT_PERSON].name,SECOND_SUPPORT_PERSON_NAME,min(strlen(SECOND_SUPPORT_PERSON_NAME),DB_MAX_NAME_LENGTH));
ansond 4:90df92778e77 102 strncpy(this->m_db[SECOND_SUPPORT_PERSON].description,SECOND_SUPPORT_PERSON_DESCRIPTION,min(strlen(SECOND_SUPPORT_PERSON_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
ansond 4:90df92778e77 103 strncpy(this->m_db[SECOND_SUPPORT_PERSON].status,SECOND_SUPPORT_PERSON_STATUS,min(strlen(SECOND_SUPPORT_PERSON_STATUS),DB_MAX_STATUS_LENGTH));
ansond 4:90df92778e77 104 strncpy(this->m_db[SECOND_SUPPORT_PERSON].latitude,SECOND_SUPPORT_PERSON_LATITUDE,min(strlen(SECOND_SUPPORT_PERSON_LATITUDE),DB_MAX_LATLONG_LENGTH));
ansond 4:90df92778e77 105 strncpy(this->m_db[SECOND_SUPPORT_PERSON].longitude,SECOND_SUPPORT_PERSON_LONGITUDE,min(strlen(SECOND_SUPPORT_PERSON_LONGITUDE),DB_MAX_LATLONG_LENGTH));
ansond 3:ea6ac7464011 106
ansond 4:90df92778e77 107 // Third Support Person
ansond 4:90df92778e77 108 memset((void *)&(this->m_db[THIRD_SUPPORT_PERSON]),0,sizeof(SupportPersonEntry));
ansond 4:90df92778e77 109 this->m_db[THIRD_SUPPORT_PERSON].rfid = THIRD_SUPPORT_PERSON_RFID;
ansond 4:90df92778e77 110 strncpy(this->m_db[THIRD_SUPPORT_PERSON].name,THIRD_SUPPORT_PERSON_NAME,min(strlen(THIRD_SUPPORT_PERSON_NAME),DB_MAX_NAME_LENGTH));
ansond 4:90df92778e77 111 strncpy(this->m_db[THIRD_SUPPORT_PERSON].description,THIRD_SUPPORT_PERSON_DESCRIPTION,min(strlen(THIRD_SUPPORT_PERSON_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
ansond 4:90df92778e77 112 strncpy(this->m_db[THIRD_SUPPORT_PERSON].status,THIRD_SUPPORT_PERSON_STATUS,min(strlen(THIRD_SUPPORT_PERSON_STATUS),DB_MAX_STATUS_LENGTH));
ansond 4:90df92778e77 113 strncpy(this->m_db[THIRD_SUPPORT_PERSON].latitude,THIRD_SUPPORT_PERSON_LATITUDE,min(strlen(THIRD_SUPPORT_PERSON_LATITUDE),DB_MAX_LATLONG_LENGTH));
ansond 4:90df92778e77 114 strncpy(this->m_db[THIRD_SUPPORT_PERSON].longitude,THIRD_SUPPORT_PERSON_LONGITUDE,min(strlen(THIRD_SUPPORT_PERSON_LONGITUDE),DB_MAX_LATLONG_LENGTH));
ansond 3:ea6ac7464011 115 }