fork of ReportDB customized and renamed as a trivial support personnel database
Fork of ReportDB by
ReportDB.cpp@3:ea6ac7464011, 2014-09-24 (annotated)
- Committer:
- ansond
- Date:
- Wed Sep 24 18:52:53 2014 +0000
- Revision:
- 3:ea6ac7464011
renamed
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:ea6ac7464011 | 19 | #include "ReportDB.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 | 3:ea6ac7464011 | 28 | ReportDB::ReportDB() { |
ansond | 3:ea6ac7464011 | 29 | this->initDB(); |
ansond | 3:ea6ac7464011 | 30 | } |
ansond | 3:ea6ac7464011 | 31 | |
ansond | 3:ea6ac7464011 | 32 | // destructor |
ansond | 3:ea6ac7464011 | 33 | ReportDB::~ReportDB() { |
ansond | 3:ea6ac7464011 | 34 | } |
ansond | 3:ea6ac7464011 | 35 | |
ansond | 3:ea6ac7464011 | 36 | // lookup and return a report |
ansond | 3:ea6ac7464011 | 37 | ReportEntry *ReportDB::lookup(int rfid) { |
ansond | 3:ea6ac7464011 | 38 | ReportEntry *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 | 3:ea6ac7464011 | 42 | for(int i=0;i<DB_MAX_NUM_REPORTS &&!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 | 3:ea6ac7464011 | 52 | // lookup a report and return its name |
ansond | 3:ea6ac7464011 | 53 | char *ReportDB::lookupReportName(int rfid) { |
ansond | 3:ea6ac7464011 | 54 | ReportEntry *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 | 3:ea6ac7464011 | 59 | // lookup a report and return its description |
ansond | 3:ea6ac7464011 | 60 | char *ReportDB::lookupReportDescription(int rfid) { |
ansond | 3:ea6ac7464011 | 61 | ReportEntry *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 | 3:ea6ac7464011 | 66 | // lookup a report and return its condition |
ansond | 3:ea6ac7464011 | 67 | char *ReportDB::lookupReportCondition(int rfid) { |
ansond | 3:ea6ac7464011 | 68 | ReportEntry *entry = this->lookup(rfid); |
ansond | 3:ea6ac7464011 | 69 | if (entry != NULL) return entry->condition; |
ansond | 3:ea6ac7464011 | 70 | return NULL; |
ansond | 3:ea6ac7464011 | 71 | } |
ansond | 3:ea6ac7464011 | 72 | |
ansond | 3:ea6ac7464011 | 73 | // lookup a report and return its latitude |
ansond | 3:ea6ac7464011 | 74 | char *ReportDB::lookupReportLatitude(int rfid) { |
ansond | 3:ea6ac7464011 | 75 | ReportEntry *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 | 3:ea6ac7464011 | 80 | // lookup a report and return its longitude |
ansond | 3:ea6ac7464011 | 81 | char *ReportDB::lookupReportLongitude(int rfid) { |
ansond | 3:ea6ac7464011 | 82 | ReportEntry *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 | 3:ea6ac7464011 | 87 | // initialize the simple report DB |
ansond | 3:ea6ac7464011 | 88 | void ReportDB::initDB() { |
ansond | 3:ea6ac7464011 | 89 | // First Report |
ansond | 3:ea6ac7464011 | 90 | memset((void *)&(this->m_db[FIRST_REPORT]),0,sizeof(ReportEntry)); |
ansond | 3:ea6ac7464011 | 91 | this->m_db[FIRST_REPORT].rfid = FIRST_REPORT_RFID; |
ansond | 3:ea6ac7464011 | 92 | strncpy(this->m_db[FIRST_REPORT].name,FIRST_REPORT_NAME,min(strlen(FIRST_REPORT_NAME),DB_MAX_NAME_LENGTH)); |
ansond | 3:ea6ac7464011 | 93 | strncpy(this->m_db[FIRST_REPORT].description,FIRST_REPORT_DESCRIPTION,min(strlen(FIRST_REPORT_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH)); |
ansond | 3:ea6ac7464011 | 94 | strncpy(this->m_db[FIRST_REPORT].condition,FIRST_REPORT_CONDITION,min(strlen(FIRST_REPORT_CONDITION),DB_MAX_CONDITION_LENGTH)); |
ansond | 3:ea6ac7464011 | 95 | strncpy(this->m_db[FIRST_REPORT].latitude,FIRST_REPORT_LATITUDE,min(strlen(FIRST_REPORT_LATITUDE),DB_MAX_LATLONG_LENGTH)); |
ansond | 3:ea6ac7464011 | 96 | strncpy(this->m_db[FIRST_REPORT].longitude,FIRST_REPORT_LONGITUDE,min(strlen(FIRST_REPORT_LONGITUDE),DB_MAX_LATLONG_LENGTH)); |
ansond | 3:ea6ac7464011 | 97 | |
ansond | 3:ea6ac7464011 | 98 | // Second Report |
ansond | 3:ea6ac7464011 | 99 | memset((void *)&(this->m_db[SECOND_REPORT]),0,sizeof(ReportEntry)); |
ansond | 3:ea6ac7464011 | 100 | this->m_db[SECOND_REPORT].rfid = SECOND_REPORT_RFID; |
ansond | 3:ea6ac7464011 | 101 | strncpy(this->m_db[SECOND_REPORT].name,SECOND_REPORT_NAME,min(strlen(SECOND_REPORT_NAME),DB_MAX_NAME_LENGTH)); |
ansond | 3:ea6ac7464011 | 102 | strncpy(this->m_db[SECOND_REPORT].description,SECOND_REPORT_DESCRIPTION,min(strlen(SECOND_REPORT_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH)); |
ansond | 3:ea6ac7464011 | 103 | strncpy(this->m_db[SECOND_REPORT].condition,SECOND_REPORT_CONDITION,min(strlen(SECOND_REPORT_CONDITION),DB_MAX_CONDITION_LENGTH)); |
ansond | 3:ea6ac7464011 | 104 | strncpy(this->m_db[SECOND_REPORT].latitude,SECOND_REPORT_LATITUDE,min(strlen(SECOND_REPORT_LATITUDE),DB_MAX_LATLONG_LENGTH)); |
ansond | 3:ea6ac7464011 | 105 | strncpy(this->m_db[SECOND_REPORT].longitude,SECOND_REPORT_LONGITUDE,min(strlen(SECOND_REPORT_LONGITUDE),DB_MAX_LATLONG_LENGTH)); |
ansond | 3:ea6ac7464011 | 106 | |
ansond | 3:ea6ac7464011 | 107 | // Third Report |
ansond | 3:ea6ac7464011 | 108 | memset((void *)&(this->m_db[THIRD_REPORT]),0,sizeof(ReportEntry)); |
ansond | 3:ea6ac7464011 | 109 | this->m_db[THIRD_REPORT].rfid = THIRD_REPORT_RFID; |
ansond | 3:ea6ac7464011 | 110 | strncpy(this->m_db[THIRD_REPORT].name,THIRD_REPORT_NAME,min(strlen(THIRD_REPORT_NAME),DB_MAX_NAME_LENGTH)); |
ansond | 3:ea6ac7464011 | 111 | strncpy(this->m_db[THIRD_REPORT].description,THIRD_REPORT_DESCRIPTION,min(strlen(THIRD_REPORT_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH)); |
ansond | 3:ea6ac7464011 | 112 | strncpy(this->m_db[THIRD_REPORT].condition,THIRD_REPORT_CONDITION,min(strlen(THIRD_REPORT_CONDITION),DB_MAX_CONDITION_LENGTH)); |
ansond | 3:ea6ac7464011 | 113 | strncpy(this->m_db[THIRD_REPORT].latitude,THIRD_REPORT_LATITUDE,min(strlen(THIRD_REPORT_LATITUDE),DB_MAX_LATLONG_LENGTH)); |
ansond | 3:ea6ac7464011 | 114 | strncpy(this->m_db[THIRD_REPORT].longitude,THIRD_REPORT_LONGITUDE,min(strlen(THIRD_REPORT_LONGITUDE),DB_MAX_LATLONG_LENGTH)); |
ansond | 3:ea6ac7464011 | 115 | } |