Baseline for testing

Revision:
2:180c90fb759c
Parent:
1:a2073f60d3a6
Child:
3:573403f12cdd
--- a/AddressMap.cpp	Thu Sep 12 11:28:05 2019 +0000
+++ b/AddressMap.cpp	Tue Sep 17 13:48:33 2019 +0000
@@ -1,18 +1,35 @@
-
-#include "mbed.h"
+/**************************************************************************//**
+ * @file     AddressMap.cpp
+ * @brief    Base class for storage of Address Mapping data.
+ * @version: V1.0
+ * @date:    9/17/2019
 
+ *
+ * @note
+ * Copyright (C) 2019 E3 Design. All rights reserved.
+ *
+ * @par
+ * E3 Designers LLC is supplying this software for use with Cortex-M3 LPC1768
+ * processor based microcontroller for the ESCM 2000 Monitor and Display.  
+ *  *
+ * @par
+ * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
+ * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
+ * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ******************************************************************************/
+#include "mbed.h"
 #include "AddressMap.h"
-
 #include "stdio.h"
 #include "stdlib.h"
 
-#define TEXT_FILE 0
 #define ADDRESS_MAP_VERSION 0xFAFA0001
-#if TEXT_FILE 
-const char * filePath = "/local/address.txt";
-#else
+
 const char * filePath = "/local/address.bin";
-#endif
+
+/******************************************************************************/
 int AddressMap::reset()
 {
     int result = 0;
@@ -40,6 +57,7 @@
 }
 
 
+/******************************************************************************/
 int AddressMap::init()
 {
     int result = 0;
@@ -60,65 +78,13 @@
 
 }
 
-void trim(const char *input, char *result)
-{
-  int i, j, k = 0;
-  
-  j = strlen(input)-1;
-  
-  while (input[i] == 0x20 && input[i] != '\0' ) i++;
-  while (input[j] == 0x20 && j>0 ) j--;
-
-  for (i = 0; i<j; i++) {
-      result[k++] = input[i];
-  }
-}
-
+/******************************************************************************/
 int AddressMap::load()
 {   
     int result = 0;
         
     printf("Loading Address Map Data\n\r");
-    
-#if TEXT_FILE
-    FILE *input = fopen (filePath,"r");
-    
-    if (input != NULL) {
         
-        int i=0;
-        char line[128];
-        while (!feof(input)) {
-          
-          memset(line,0,sizeof(line));
-          
-          fgets(line,sizeof(line),input);
-          
-          sscanf(line,"%02d:%20s\n\r", 
-            &addresses[i].address,
-             addresses[i].description);
-         
-          printf("[%30s] :: %02d:%20s\n\r",
-             line,
-             addresses[i].address,
-             addresses[i].description);
-#if 0         
-             
-          printf (line);
-#endif
-        
-          i++;
-        }
-        fclose(input);
-        result = 1;        
-    }
-    else
-    {
-        printf("Error: Cannot read %s\n\r", filePath);
-        result = 0;        
-    }
-    
-#else
-    
     FILE *input = fopen(filePath, "rb");
     if(input){
         
@@ -133,7 +99,6 @@
         { 
             for (int i=0;i<MAX_ADDRESSES;i++)
             {
-                printf("." );
                 fread( &addresses[i].address,     sizeof(uint32_t),1 , input);
                 fread(  addresses[i].description, sizeof(char)    ,MAX_ADDR_LENGTH, input);
             }
@@ -152,39 +117,18 @@
         printf("Error: Cannot read %s\n\r",filePath );
         result = 0;        
     }
-#endif
     
     return result;
 }
 
 
 
+/******************************************************************************/
 int AddressMap::save()
 {
     int result = 0;
     printf("Saving %s\n\r",filePath );
     
-#if TEXT_FILE
-    FILE *output = fopen(filePath, "w");
-    
-    if (output )
-    {   
-        for (int i=0;i<MAX_ADDRESSES;i++)
-        {
-            //printf("." );
-            fprintf(output, "%02d:%-20s\n\r" ,
-                addresses[i].address, addresses[i].description);
-        }
-        fflush(output);
-        fclose(output);
-        result = 1;
-    }
-    else
-    {
-        printf("Error: Cannot write %s\n\r",filePath);
-        result = 0;
-    }
-#else
 
     FILE *output = fopen(filePath, "wb");
 
@@ -209,12 +153,12 @@
         printf("Error: Cannot write %s\n\r",filePath);
         result = 0;
     }
-#endif
     
     printf("Done \n\r" );
     return result;
 }
 
+/******************************************************************************/
 void AddressMap::display(Serial *pc)
 {
     pc->printf("\n\r");
@@ -229,23 +173,12 @@
 }
 
 
-void AddressMap::play(Serial *pc, int address)
-{
-    if (address>=0&&address<MAX_ADDRESSES){
-        pc->printf("%02d : %s is open\n\r", address, 
-            addresses[address].description);
-    }
-    else
-    {
-        pc->printf("%02d : error \n\r", address);
-    }
-}
-
-
+/******************************************************************************/
 char* AddressMap::getDescription(unsigned char idx )
 {
-    if (idx < MAX_ADDRESSES )
+    if (idx < MAX_ADDRESSES && idx >= 0 )
         return addresses[idx].description;
     else
         return "Invalid Address";
 }
+/******************************************************************************/