File manager
FileManager.cpp@23:7ffd9724e105, 2016-05-25 (annotated)
- Committer:
- nsrwsurasak
- Date:
- Wed May 25 12:00:59 2016 +0000
- Revision:
- 23:7ffd9724e105
- Parent:
- 22:2fc64ad66e35
- Child:
- 24:5ee719582d1e
Add comment & Clean up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lucyjungz | 14:4ba6147f067b | 1 | /** |
Lucyjungz | 14:4ba6147f067b | 2 | ****************************************************************************** |
Lucyjungz | 14:4ba6147f067b | 3 | * @file FileManager.cpp |
Lucyjungz | 14:4ba6147f067b | 4 | * @author Narut T |
Lucyjungz | 14:4ba6147f067b | 5 | * @version V1 |
Lucyjungz | 14:4ba6147f067b | 6 | * @date 19/05/2016 |
Lucyjungz | 14:4ba6147f067b | 7 | * @brief File Manager for managing file system in SD Card |
Lucyjungz | 14:4ba6147f067b | 8 | ******************************************************************************/ |
Lucyjungz | 14:4ba6147f067b | 9 | |
nsrwsurasak | 13:d83e2dcc882d | 10 | #include "main.h" |
nsrwsurasak | 0:a27e0d3581d1 | 11 | |
Lucyjungz | 14:4ba6147f067b | 12 | char m_StrGpsInterval[XMLTEXT_SIZE]; // GPS Interval |
Lucyjungz | 14:4ba6147f067b | 13 | char m_StrDataInterval[XMLTEXT_SIZE]; // Data Interval |
Lucyjungz | 14:4ba6147f067b | 14 | |
Lucyjungz | 14:4ba6147f067b | 15 | uint32_t m_GpsInterval; |
Lucyjungz | 14:4ba6147f067b | 16 | uint32_t m_DataInterval; |
Lucyjungz | 3:6e08d0bba1bb | 17 | Variable_Data_TypeDef m_varList[MAX_VAR]; // Variable List |
Lucyjungz | 3:6e08d0bba1bb | 18 | unsigned int m_amountVarList = 0; // Amount of variable list |
Lucyjungz | 21:0c52dbc23f52 | 19 | bool m_SdCardHasDisconnected = false; // flag to indicate sd card has disconnected |
Lucyjungz | 21:0c52dbc23f52 | 20 | char m_varListFileName[MAX_FILE_NAME_SIZE]; // Variable File Name |
Lucyjungz | 21:0c52dbc23f52 | 21 | bool m_sdCardIsPresent; // Flag to indicate sd card is present |
Lucyjungz | 21:0c52dbc23f52 | 22 | /** Connect pin for SD Card LED */ |
Lucyjungz | 11:e21d4c5bfd1b | 23 | #ifdef LED_SDCARD |
Lucyjungz | 17:d24d2b2bbd42 | 24 | DigitalOut ledStatus(LED_SDCARD); |
Lucyjungz | 11:e21d4c5bfd1b | 25 | #else |
Lucyjungz | 11:e21d4c5bfd1b | 26 | DigitalOut ledStatus(NC); |
Lucyjungz | 11:e21d4c5bfd1b | 27 | #endif |
Lucyjungz | 11:e21d4c5bfd1b | 28 | |
Lucyjungz | 17:d24d2b2bbd42 | 29 | /** Connect pin for SD Card Switch */ |
Lucyjungz | 17:d24d2b2bbd42 | 30 | #ifdef SDCARD_SWITCH |
nsrwsurasak | 22:2fc64ad66e35 | 31 | //InterruptIn sdSwitch(SDCARD_SWITCH); |
Lucyjungz | 17:d24d2b2bbd42 | 32 | #else |
Lucyjungz | 21:0c52dbc23f52 | 33 | InterruptIn sdSwitch(NC); |
Lucyjungz | 17:d24d2b2bbd42 | 34 | #endif |
Lucyjungz | 17:d24d2b2bbd42 | 35 | |
Lucyjungz | 3:6e08d0bba1bb | 36 | /* ############### Static function prototype ################## */ |
nsrwsurasak | 0:a27e0d3581d1 | 37 | |
Lucyjungz | 14:4ba6147f067b | 38 | static void FILEMANAGER_RemoveSpaces(char* s , int size); |
Lucyjungz | 14:4ba6147f067b | 39 | static void FILEMANAGER_GetXmlText(char *str, char *ret); |
Lucyjungz | 14:4ba6147f067b | 40 | static void FILEMANAGER_GenerateFileNameWithTime(time_t timestamp, char * file_name); |
Lucyjungz | 14:4ba6147f067b | 41 | static void FILEMANAGER_SetLedStatus(bool on); |
Lucyjungz | 3:6e08d0bba1bb | 42 | |
Lucyjungz | 3:6e08d0bba1bb | 43 | /** |
Lucyjungz | 3:6e08d0bba1bb | 44 | * @brief Utility function to Remove space charector from given char array |
Lucyjungz | 3:6e08d0bba1bb | 45 | * @note |
Lucyjungz | 3:6e08d0bba1bb | 46 | * @param char array to process remove spaces |
Lucyjungz | 3:6e08d0bba1bb | 47 | * @param size of char array |
Lucyjungz | 3:6e08d0bba1bb | 48 | * @retval space removed char array |
Lucyjungz | 3:6e08d0bba1bb | 49 | */ |
Lucyjungz | 14:4ba6147f067b | 50 | static void FILEMANAGER_RemoveSpaces(char* s , int size) |
nsrwsurasak | 0:a27e0d3581d1 | 51 | { |
nsrwsurasak | 0:a27e0d3581d1 | 52 | char* cpy = s; // an alias to iterate through s without moving s |
nsrwsurasak | 0:a27e0d3581d1 | 53 | char* temp = s; |
nsrwsurasak | 0:a27e0d3581d1 | 54 | |
nsrwsurasak | 0:a27e0d3581d1 | 55 | for (int i = 0 ; i < size ; i++) { |
nsrwsurasak | 0:a27e0d3581d1 | 56 | if (*cpy != ' ') |
nsrwsurasak | 0:a27e0d3581d1 | 57 | *temp++ = *cpy; |
nsrwsurasak | 0:a27e0d3581d1 | 58 | cpy++; |
nsrwsurasak | 0:a27e0d3581d1 | 59 | } |
nsrwsurasak | 0:a27e0d3581d1 | 60 | *temp = 0; |
nsrwsurasak | 0:a27e0d3581d1 | 61 | return; |
nsrwsurasak | 0:a27e0d3581d1 | 62 | } |
Lucyjungz | 3:6e08d0bba1bb | 63 | /** |
Lucyjungz | 3:6e08d0bba1bb | 64 | * @brief Utility function to get XML tag |
Lucyjungz | 3:6e08d0bba1bb | 65 | * @note Only First tag will be returned |
Lucyjungz | 3:6e08d0bba1bb | 66 | * @param char array to get XML Text |
Lucyjungz | 3:6e08d0bba1bb | 67 | * @param char array to be populate XML text |
Lucyjungz | 3:6e08d0bba1bb | 68 | * @retval XML text |
Lucyjungz | 3:6e08d0bba1bb | 69 | */ |
Lucyjungz | 14:4ba6147f067b | 70 | static void FILEMANAGER_GetXmlText(char *str, char *ret) |
nsrwsurasak | 0:a27e0d3581d1 | 71 | { |
nsrwsurasak | 0:a27e0d3581d1 | 72 | int size = strlen(str); |
nsrwsurasak | 0:a27e0d3581d1 | 73 | int i; |
nsrwsurasak | 0:a27e0d3581d1 | 74 | bool begin_text = false; |
nsrwsurasak | 0:a27e0d3581d1 | 75 | char * ret_addr = ret; |
Lucyjungz | 3:6e08d0bba1bb | 76 | /* initialized our return value */ |
nsrwsurasak | 0:a27e0d3581d1 | 77 | memset (ret,' ',XMLTEXT_SIZE); |
nsrwsurasak | 0:a27e0d3581d1 | 78 | |
Lucyjungz | 3:6e08d0bba1bb | 79 | /* Loop to check XML tag symbols */ |
nsrwsurasak | 0:a27e0d3581d1 | 80 | for(i = 0; i < size ; i++) { |
nsrwsurasak | 0:a27e0d3581d1 | 81 | |
nsrwsurasak | 0:a27e0d3581d1 | 82 | if (*str == '>') { |
Lucyjungz | 3:6e08d0bba1bb | 83 | /* Found begining of the tag */ |
nsrwsurasak | 0:a27e0d3581d1 | 84 | begin_text = true; |
nsrwsurasak | 0:a27e0d3581d1 | 85 | } else if (begin_text && *str == '<') { |
Lucyjungz | 3:6e08d0bba1bb | 86 | /* Reach the end of text message */ |
nsrwsurasak | 0:a27e0d3581d1 | 87 | begin_text = false; |
nsrwsurasak | 0:a27e0d3581d1 | 88 | break; |
nsrwsurasak | 0:a27e0d3581d1 | 89 | } else if (begin_text && *str != ' ') { |
Lucyjungz | 3:6e08d0bba1bb | 90 | /* Populate the return value */ |
nsrwsurasak | 0:a27e0d3581d1 | 91 | *ret = *str; |
nsrwsurasak | 0:a27e0d3581d1 | 92 | ret++; |
nsrwsurasak | 0:a27e0d3581d1 | 93 | } |
Lucyjungz | 3:6e08d0bba1bb | 94 | /* Move to next char */ |
nsrwsurasak | 0:a27e0d3581d1 | 95 | str++; |
nsrwsurasak | 0:a27e0d3581d1 | 96 | } |
Lucyjungz | 3:6e08d0bba1bb | 97 | |
Lucyjungz | 3:6e08d0bba1bb | 98 | /* Remove space from return value */ |
Lucyjungz | 14:4ba6147f067b | 99 | FILEMANAGER_RemoveSpaces(ret_addr, XMLTEXT_SIZE); |
nsrwsurasak | 0:a27e0d3581d1 | 100 | } |
Lucyjungz | 3:6e08d0bba1bb | 101 | /** |
Lucyjungz | 3:6e08d0bba1bb | 102 | * @brief Utility function to get File Name with Date |
Lucyjungz | 3:6e08d0bba1bb | 103 | * @note Format file will be YYYY-MM-DD.filename |
Lucyjungz | 3:6e08d0bba1bb | 104 | * @param timestamp - time structure to get Date |
Lucyjungz | 3:6e08d0bba1bb | 105 | * @param file_name - char array to file name |
Lucyjungz | 3:6e08d0bba1bb | 106 | * @retval renamed file name |
Lucyjungz | 3:6e08d0bba1bb | 107 | */ |
Lucyjungz | 14:4ba6147f067b | 108 | static void FILEMANAGER_GenerateFileNameWithTime(time_t timestamp, char * file_name) |
Lucyjungz | 1:1f1f2b99756b | 109 | { |
Lucyjungz | 14:4ba6147f067b | 110 | char str[RENAME_FILE_BUFFER_SIZE]; |
Lucyjungz | 1:1f1f2b99756b | 111 | struct tm * ptm; |
Lucyjungz | 1:1f1f2b99756b | 112 | |
Lucyjungz | 3:6e08d0bba1bb | 113 | /* Convert timestamp to readable format */ |
Lucyjungz | 3:6e08d0bba1bb | 114 | ptm = localtime ( ×tamp ); |
Lucyjungz | 3:6e08d0bba1bb | 115 | |
Lucyjungz | 3:6e08d0bba1bb | 116 | /* Replacing YYYY to the converted year */ |
Lucyjungz | 14:4ba6147f067b | 117 | sprintf(str,"%04d", ptm->tm_year + YEAR_4DIGITS_OFFSET); |
Lucyjungz | 14:4ba6147f067b | 118 | memcpy(&file_name[TIMESTAMP_YEAR_OFFSET], str, TIMESTAMP_YEAR_SIZE); |
Lucyjungz | 1:1f1f2b99756b | 119 | |
Lucyjungz | 3:6e08d0bba1bb | 120 | /* Replacing MM to converted month */ |
Lucyjungz | 1:1f1f2b99756b | 121 | sprintf(str,"%02d", ptm->tm_mon+1); |
Lucyjungz | 14:4ba6147f067b | 122 | memcpy(&file_name[TIMESTAMP_MONTH_OFFSET], str, TIMESTAMP_MONTH_SIZE); |
Lucyjungz | 1:1f1f2b99756b | 123 | |
Lucyjungz | 3:6e08d0bba1bb | 124 | /* Replacing DD to converted date */ |
Lucyjungz | 1:1f1f2b99756b | 125 | sprintf(str,"%02d", ptm->tm_mday); |
Lucyjungz | 14:4ba6147f067b | 126 | memcpy(&file_name[TIMESTAMP_DATE_OFFSET], str,TIMESTAMP_DATE_SIZE); |
Lucyjungz | 1:1f1f2b99756b | 127 | } |
Lucyjungz | 3:6e08d0bba1bb | 128 | /** |
Lucyjungz | 3:6e08d0bba1bb | 129 | * @brief Function to perform read setup file |
Lucyjungz | 3:6e08d0bba1bb | 130 | * @note filename must be defined in FileManager.h, GPS/ Data interval will be stored in dedicated variable |
Lucyjungz | 3:6e08d0bba1bb | 131 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 132 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 133 | */ |
Lucyjungz | 14:4ba6147f067b | 134 | void FILEMANAGER_ReadSetupFile() |
nsrwsurasak | 0:a27e0d3581d1 | 135 | { |
Lucyjungz | 3:6e08d0bba1bb | 136 | /* Open file in reading mode */ |
nsrwsurasak | 0:a27e0d3581d1 | 137 | FILE *fp = fopen(SETUP_FILE_NAME, "r"); |
nsrwsurasak | 0:a27e0d3581d1 | 138 | |
Lucyjungz | 3:6e08d0bba1bb | 139 | if (fp == NULL) { |
Lucyjungz | 3:6e08d0bba1bb | 140 | /* In case of error, print the message */ |
nsrwsurasak | 0:a27e0d3581d1 | 141 | printf("\nError! Unable to open file! %s \n", SETUP_FILE_NAME); |
Lucyjungz | 11:e21d4c5bfd1b | 142 | |
Lucyjungz | 11:e21d4c5bfd1b | 143 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 144 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 145 | } else { |
nsrwsurasak | 0:a27e0d3581d1 | 146 | |
Lucyjungz | 3:6e08d0bba1bb | 147 | /* Initialized state */ |
nsrwsurasak | 0:a27e0d3581d1 | 148 | ReadingFileState state = STATE_FINDING; |
Lucyjungz | 3:6e08d0bba1bb | 149 | |
Lucyjungz | 3:6e08d0bba1bb | 150 | /* Allocate buffer for reading file */ |
Lucyjungz | 14:4ba6147f067b | 151 | char buf[READ_FILE_BUFFER_SIZE]; |
Lucyjungz | 3:6e08d0bba1bb | 152 | |
Lucyjungz | 11:e21d4c5bfd1b | 153 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 154 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 155 | |
Lucyjungz | 3:6e08d0bba1bb | 156 | /* Read line from the file */ |
nsrwsurasak | 0:a27e0d3581d1 | 157 | while (fgets(buf, sizeof(buf), fp) != NULL) { |
Lucyjungz | 3:6e08d0bba1bb | 158 | |
Lucyjungz | 3:6e08d0bba1bb | 159 | /* Check the TAG */ |
Lucyjungz | 3:6e08d0bba1bb | 160 | if (strstr (buf,DATA_TAG)) |
Lucyjungz | 3:6e08d0bba1bb | 161 | { |
Lucyjungz | 3:6e08d0bba1bb | 162 | /* Found the DATA TAG */ |
nsrwsurasak | 0:a27e0d3581d1 | 163 | state = STATE_FOUND_DATA; |
Lucyjungz | 21:0c52dbc23f52 | 164 | } |
Lucyjungz | 21:0c52dbc23f52 | 165 | else if (strstr (buf,GPS_TAG)) |
Lucyjungz | 3:6e08d0bba1bb | 166 | { |
Lucyjungz | 3:6e08d0bba1bb | 167 | /* Found GPS TAG */ |
nsrwsurasak | 0:a27e0d3581d1 | 168 | state = STATE_FOUND_GPS; |
Lucyjungz | 21:0c52dbc23f52 | 169 | } |
Lucyjungz | 21:0c52dbc23f52 | 170 | else if (strstr (buf,UPDATE_INTERVAL_TAG)) |
Lucyjungz | 3:6e08d0bba1bb | 171 | { |
Lucyjungz | 3:6e08d0bba1bb | 172 | /* Found Interval TAG */ |
Lucyjungz | 3:6e08d0bba1bb | 173 | if (state == STATE_FOUND_GPS) |
Lucyjungz | 3:6e08d0bba1bb | 174 | { |
Lucyjungz | 3:6e08d0bba1bb | 175 | /* Get XML text for GPS Interval */ |
Lucyjungz | 14:4ba6147f067b | 176 | FILEMANAGER_GetXmlText(buf, m_StrGpsInterval); |
Lucyjungz | 14:4ba6147f067b | 177 | m_GpsInterval = atoi(m_StrGpsInterval); |
Lucyjungz | 8:5af4e12c43b2 | 178 | #if DEBUG |
Lucyjungz | 14:4ba6147f067b | 179 | printf("\r\n-found GPS interval %s ", m_StrGpsInterval); |
Lucyjungz | 8:5af4e12c43b2 | 180 | #endif |
Lucyjungz | 8:5af4e12c43b2 | 181 | |
Lucyjungz | 8:5af4e12c43b2 | 182 | /* Set state to indicate that we are finding */ |
nsrwsurasak | 0:a27e0d3581d1 | 183 | state = STATE_FINDING; |
Lucyjungz | 3:6e08d0bba1bb | 184 | } |
Lucyjungz | 3:6e08d0bba1bb | 185 | else if(state == STATE_FOUND_DATA) |
Lucyjungz | 3:6e08d0bba1bb | 186 | { |
Lucyjungz | 3:6e08d0bba1bb | 187 | /* Get XML text for Data Interval */ |
Lucyjungz | 14:4ba6147f067b | 188 | FILEMANAGER_GetXmlText(buf, m_StrDataInterval); |
Lucyjungz | 14:4ba6147f067b | 189 | m_DataInterval = atoi(m_StrDataInterval); |
Lucyjungz | 8:5af4e12c43b2 | 190 | #if DEBUG |
Lucyjungz | 14:4ba6147f067b | 191 | printf("\r\n-found Data interval %s ", m_StrDataInterval); |
Lucyjungz | 8:5af4e12c43b2 | 192 | #endif |
Lucyjungz | 8:5af4e12c43b2 | 193 | |
Lucyjungz | 8:5af4e12c43b2 | 194 | /* Set state to indicate that we are finding */ |
nsrwsurasak | 0:a27e0d3581d1 | 195 | state = STATE_FINDING; |
nsrwsurasak | 0:a27e0d3581d1 | 196 | } |
nsrwsurasak | 0:a27e0d3581d1 | 197 | } |
Lucyjungz | 21:0c52dbc23f52 | 198 | else if (strstr (buf,VAR_LIST_FILE_TAG)) |
Lucyjungz | 21:0c52dbc23f52 | 199 | { |
Lucyjungz | 21:0c52dbc23f52 | 200 | /* Get XML text for Variable File Name */ |
Lucyjungz | 21:0c52dbc23f52 | 201 | char bufFileName[MAX_FILE_NAME_SIZE]; |
Lucyjungz | 21:0c52dbc23f52 | 202 | FILEMANAGER_GetXmlText(buf, bufFileName); |
Lucyjungz | 21:0c52dbc23f52 | 203 | memcpy(m_varListFileName,PREFIX_FILE_NAME,strlen(PREFIX_FILE_NAME)); |
Lucyjungz | 21:0c52dbc23f52 | 204 | memcpy(&m_varListFileName[strlen(PREFIX_FILE_NAME)],bufFileName,strlen(bufFileName)); |
Lucyjungz | 21:0c52dbc23f52 | 205 | |
Lucyjungz | 21:0c52dbc23f52 | 206 | } |
nsrwsurasak | 0:a27e0d3581d1 | 207 | } |
Lucyjungz | 3:6e08d0bba1bb | 208 | /* Ensure file is closed */ |
Lucyjungz | 3:6e08d0bba1bb | 209 | fclose(fp); |
nsrwsurasak | 0:a27e0d3581d1 | 210 | } |
nsrwsurasak | 0:a27e0d3581d1 | 211 | } |
Lucyjungz | 3:6e08d0bba1bb | 212 | /** |
Lucyjungz | 3:6e08d0bba1bb | 213 | * @brief Function to log GPS Data |
Lucyjungz | 3:6e08d0bba1bb | 214 | * @note |
Lucyjungz | 3:6e08d0bba1bb | 215 | * @param timestamp - time structure to get Date |
Lucyjungz | 3:6e08d0bba1bb | 216 | * @param lat - char array for lattitude |
Lucyjungz | 3:6e08d0bba1bb | 217 | * @param longti - char array for longtitude |
Lucyjungz | 3:6e08d0bba1bb | 218 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 219 | */ |
Lucyjungz | 14:4ba6147f067b | 220 | void FILEMANAGER_LogGPSData(time_t timestamp ,char lat[], char longti[]) |
nsrwsurasak | 0:a27e0d3581d1 | 221 | { |
nsrwsurasak | 23:7ffd9724e105 | 222 | if (!m_sdCardIsPresent) |
nsrwsurasak | 23:7ffd9724e105 | 223 | { |
nsrwsurasak | 23:7ffd9724e105 | 224 | /** Turn off LED */ |
nsrwsurasak | 23:7ffd9724e105 | 225 | FILEMANAGER_SetLedStatus(false); |
nsrwsurasak | 23:7ffd9724e105 | 226 | |
nsrwsurasak | 23:7ffd9724e105 | 227 | printf("Error! SD Card is not connected \n"); |
nsrwsurasak | 23:7ffd9724e105 | 228 | |
nsrwsurasak | 23:7ffd9724e105 | 229 | /** Return as nothing to be done */ |
nsrwsurasak | 23:7ffd9724e105 | 230 | return; |
nsrwsurasak | 23:7ffd9724e105 | 231 | } |
Lucyjungz | 3:6e08d0bba1bb | 232 | /* Get File name */ |
Lucyjungz | 1:1f1f2b99756b | 233 | char file_name[] = GPS_LOG_FILE_NAME; |
Lucyjungz | 1:1f1f2b99756b | 234 | |
Lucyjungz | 3:6e08d0bba1bb | 235 | /* Generate file name with time stamp */ |
Lucyjungz | 14:4ba6147f067b | 236 | FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name); |
Lucyjungz | 3:6e08d0bba1bb | 237 | |
Lucyjungz | 3:6e08d0bba1bb | 238 | /* Open file with "APPEND" mode */ |
Lucyjungz | 1:1f1f2b99756b | 239 | FILE *fp = fopen(file_name, "a"); |
Lucyjungz | 1:1f1f2b99756b | 240 | |
Lucyjungz | 3:6e08d0bba1bb | 241 | if (fp == NULL) |
Lucyjungz | 3:6e08d0bba1bb | 242 | { |
Lucyjungz | 3:6e08d0bba1bb | 243 | /* if it can't open the file then print error message */ |
Lucyjungz | 1:1f1f2b99756b | 244 | printf("Error! Unable to open file %s!\n",file_name); |
Lucyjungz | 11:e21d4c5bfd1b | 245 | |
Lucyjungz | 11:e21d4c5bfd1b | 246 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 247 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 248 | } |
Lucyjungz | 11:e21d4c5bfd1b | 249 | else |
Lucyjungz | 11:e21d4c5bfd1b | 250 | { |
Lucyjungz | 11:e21d4c5bfd1b | 251 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 252 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 253 | |
Lucyjungz | 3:6e08d0bba1bb | 254 | /* Print some message for information */ |
Lucyjungz | 1:1f1f2b99756b | 255 | printf("\r\n Writing to Gps Log File (%s)....",file_name); |
Lucyjungz | 1:1f1f2b99756b | 256 | |
Lucyjungz | 3:6e08d0bba1bb | 257 | /* Write the line with lattitude and longtitude */ |
Lucyjungz | 3:6e08d0bba1bb | 258 | fprintf(fp, "%d,%s,%s\n",timestamp,lat,longti); |
Lucyjungz | 1:1f1f2b99756b | 259 | |
Lucyjungz | 1:1f1f2b99756b | 260 | printf("Done"); |
Lucyjungz | 3:6e08d0bba1bb | 261 | /* Close file once it done */ |
Lucyjungz | 3:6e08d0bba1bb | 262 | fclose(fp); |
Lucyjungz | 1:1f1f2b99756b | 263 | } |
Lucyjungz | 1:1f1f2b99756b | 264 | } |
Lucyjungz | 3:6e08d0bba1bb | 265 | /** |
Lucyjungz | 3:6e08d0bba1bb | 266 | * @brief Function to log RMS Data |
Lucyjungz | 3:6e08d0bba1bb | 267 | * @note sequence must be in the same order with variableList |
Lucyjungz | 3:6e08d0bba1bb | 268 | * @param timestamp - time structure to get Date |
Lucyjungz | 3:6e08d0bba1bb | 269 | * @param var - float array to be log in the file |
Lucyjungz | 3:6e08d0bba1bb | 270 | * @param size - size of the float array |
Lucyjungz | 3:6e08d0bba1bb | 271 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 272 | */ |
Lucyjungz | 21:0c52dbc23f52 | 273 | void FILEMANAGER_LogRMSData(time_t timestamp ,float * var, int size, bool * p_headerRequired) |
Lucyjungz | 1:1f1f2b99756b | 274 | { |
nsrwsurasak | 23:7ffd9724e105 | 275 | if (!m_sdCardIsPresent) |
nsrwsurasak | 23:7ffd9724e105 | 276 | { |
nsrwsurasak | 23:7ffd9724e105 | 277 | /** Turn off LED */ |
nsrwsurasak | 23:7ffd9724e105 | 278 | FILEMANAGER_SetLedStatus(false); |
nsrwsurasak | 23:7ffd9724e105 | 279 | |
nsrwsurasak | 23:7ffd9724e105 | 280 | printf("Error! SD Card is not connected \n"); |
nsrwsurasak | 23:7ffd9724e105 | 281 | |
nsrwsurasak | 23:7ffd9724e105 | 282 | /** Return as nothing to be done */ |
nsrwsurasak | 23:7ffd9724e105 | 283 | return; |
nsrwsurasak | 23:7ffd9724e105 | 284 | } |
Lucyjungz | 3:6e08d0bba1bb | 285 | /* Get File name */ |
Lucyjungz | 1:1f1f2b99756b | 286 | char file_name[] = RTL_LOG_FILE_NAME; |
Lucyjungz | 1:1f1f2b99756b | 287 | |
Lucyjungz | 3:6e08d0bba1bb | 288 | /* Generate File name with timestamp */ |
Lucyjungz | 14:4ba6147f067b | 289 | FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name); |
Lucyjungz | 21:0c52dbc23f52 | 290 | if (*p_headerRequired || !FILEMANAGER_IsFileExist(file_name)) |
Lucyjungz | 1:1f1f2b99756b | 291 | { |
Lucyjungz | 3:6e08d0bba1bb | 292 | /* If file is not exist, log the header */ |
Lucyjungz | 14:4ba6147f067b | 293 | FILEMANAGER_LogRMSHeader(timestamp); |
Lucyjungz | 21:0c52dbc23f52 | 294 | |
Lucyjungz | 21:0c52dbc23f52 | 295 | /* Clear flag once header has been written */ |
Lucyjungz | 21:0c52dbc23f52 | 296 | *p_headerRequired = false; |
Lucyjungz | 1:1f1f2b99756b | 297 | } |
Lucyjungz | 3:6e08d0bba1bb | 298 | /* Open file with "APPEND" mode */ |
Lucyjungz | 1:1f1f2b99756b | 299 | FILE *fp = fopen(file_name, "a"); |
nsrwsurasak | 0:a27e0d3581d1 | 300 | |
Lucyjungz | 3:6e08d0bba1bb | 301 | if (fp == NULL) |
Lucyjungz | 3:6e08d0bba1bb | 302 | { |
Lucyjungz | 3:6e08d0bba1bb | 303 | /* In case of error, print the error message */ |
Lucyjungz | 1:1f1f2b99756b | 304 | printf("Error! Unable to open file %s!\n",file_name); |
Lucyjungz | 11:e21d4c5bfd1b | 305 | |
Lucyjungz | 11:e21d4c5bfd1b | 306 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 307 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 308 | } |
Lucyjungz | 3:6e08d0bba1bb | 309 | else |
Lucyjungz | 3:6e08d0bba1bb | 310 | { |
Lucyjungz | 11:e21d4c5bfd1b | 311 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 312 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 313 | |
Lucyjungz | 3:6e08d0bba1bb | 314 | /* Print some message for information */ |
Lucyjungz | 1:1f1f2b99756b | 315 | printf("\r\n Writing to Log File (%s)....",file_name); |
Lucyjungz | 1:1f1f2b99756b | 316 | |
Lucyjungz | 3:6e08d0bba1bb | 317 | /* Write timestamp */ |
nsrwsurasak | 22:2fc64ad66e35 | 318 | fprintf(fp, "%d,%d",timestamp,(msec.read_ms()%MSEC_SCALE)); |
Lucyjungz | 1:1f1f2b99756b | 319 | |
Lucyjungz | 3:6e08d0bba1bb | 320 | /* Write variable data */ |
Lucyjungz | 1:1f1f2b99756b | 321 | for(int i = 0; i < size; i++) |
Lucyjungz | 1:1f1f2b99756b | 322 | { |
nsrwsurasak | 19:5af5c60e7a9f | 323 | fprintf(fp, ",%g",var[i]); |
Lucyjungz | 1:1f1f2b99756b | 324 | } |
Lucyjungz | 3:6e08d0bba1bb | 325 | /* Write new line as we done */ |
Lucyjungz | 3:6e08d0bba1bb | 326 | fprintf(fp, "\n"); |
nsrwsurasak | 0:a27e0d3581d1 | 327 | |
Lucyjungz | 1:1f1f2b99756b | 328 | printf("Done"); |
Lucyjungz | 3:6e08d0bba1bb | 329 | /* Close the file */ |
Lucyjungz | 3:6e08d0bba1bb | 330 | fclose(fp); |
Lucyjungz | 3:6e08d0bba1bb | 331 | } |
Lucyjungz | 3:6e08d0bba1bb | 332 | } |
Lucyjungz | 3:6e08d0bba1bb | 333 | /** |
Lucyjungz | 3:6e08d0bba1bb | 334 | * @brief Function to log RMS Header |
Lucyjungz | 3:6e08d0bba1bb | 335 | * @note sequence must be in the same order with variableList |
Lucyjungz | 3:6e08d0bba1bb | 336 | * @param timestamp - time structure to get Date |
Lucyjungz | 3:6e08d0bba1bb | 337 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 338 | */ |
Lucyjungz | 14:4ba6147f067b | 339 | void FILEMANAGER_LogRMSHeader(time_t timestamp) |
nsrwsurasak | 23:7ffd9724e105 | 340 | { |
nsrwsurasak | 23:7ffd9724e105 | 341 | |
Lucyjungz | 3:6e08d0bba1bb | 342 | /* Get File name */ |
Lucyjungz | 3:6e08d0bba1bb | 343 | char file_name[] = RTL_LOG_FILE_NAME; |
Lucyjungz | 3:6e08d0bba1bb | 344 | |
Lucyjungz | 3:6e08d0bba1bb | 345 | /* Generate file name with time */ |
Lucyjungz | 14:4ba6147f067b | 346 | FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name); |
Lucyjungz | 3:6e08d0bba1bb | 347 | |
Lucyjungz | 3:6e08d0bba1bb | 348 | /* Open file in append mode */ |
Lucyjungz | 3:6e08d0bba1bb | 349 | FILE *fp = fopen(file_name, "a"); |
Lucyjungz | 3:6e08d0bba1bb | 350 | |
Lucyjungz | 3:6e08d0bba1bb | 351 | if (fp == NULL) |
Lucyjungz | 3:6e08d0bba1bb | 352 | { |
Lucyjungz | 3:6e08d0bba1bb | 353 | /* In case of error, print the error message */ |
Lucyjungz | 3:6e08d0bba1bb | 354 | printf("Error! Unable to open file %s!\n",file_name); |
Lucyjungz | 11:e21d4c5bfd1b | 355 | |
Lucyjungz | 11:e21d4c5bfd1b | 356 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 357 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 358 | } |
Lucyjungz | 3:6e08d0bba1bb | 359 | else |
Lucyjungz | 3:6e08d0bba1bb | 360 | { |
Lucyjungz | 11:e21d4c5bfd1b | 361 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 362 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 363 | |
Lucyjungz | 3:6e08d0bba1bb | 364 | /* opened file so can write */ |
Lucyjungz | 3:6e08d0bba1bb | 365 | printf("\r\n Writing to Log File (%s)....",file_name); |
Lucyjungz | 3:6e08d0bba1bb | 366 | |
Lucyjungz | 3:6e08d0bba1bb | 367 | /* Write the header to the file */ |
Lucyjungz | 14:4ba6147f067b | 368 | fprintf(fp, "%s,%s",RMS_HEADER_TIME,RMS_HEADER_MSECOND); |
Lucyjungz | 7:ab015947e368 | 369 | |
Lucyjungz | 14:4ba6147f067b | 370 | for(int i = 0; i < m_amountVarList; i++) |
Lucyjungz | 14:4ba6147f067b | 371 | { |
Lucyjungz | 14:4ba6147f067b | 372 | fprintf(fp, ",%s",m_varList[i].varName); |
Lucyjungz | 14:4ba6147f067b | 373 | } |
Lucyjungz | 14:4ba6147f067b | 374 | /* Write new line as done */ |
Lucyjungz | 14:4ba6147f067b | 375 | fprintf(fp, "\n"); |
Lucyjungz | 14:4ba6147f067b | 376 | |
Lucyjungz | 14:4ba6147f067b | 377 | /* Write the timestamp unit to the file */ |
Lucyjungz | 14:4ba6147f067b | 378 | fprintf(fp, "-,-"); |
Lucyjungz | 14:4ba6147f067b | 379 | |
Lucyjungz | 15:b63a539c3754 | 380 | |
Lucyjungz | 15:b63a539c3754 | 381 | /* Write the unit of variables to the file */ |
Lucyjungz | 3:6e08d0bba1bb | 382 | for(int i = 0; i < m_amountVarList; i++) |
Lucyjungz | 3:6e08d0bba1bb | 383 | { |
Lucyjungz | 15:b63a539c3754 | 384 | fprintf(fp, ",%s",m_varList[i].varUnit); |
Lucyjungz | 3:6e08d0bba1bb | 385 | } |
Lucyjungz | 15:b63a539c3754 | 386 | |
Lucyjungz | 3:6e08d0bba1bb | 387 | /* Write new line as done */ |
Lucyjungz | 3:6e08d0bba1bb | 388 | fprintf(fp, "\n"); |
Lucyjungz | 3:6e08d0bba1bb | 389 | |
Lucyjungz | 3:6e08d0bba1bb | 390 | printf("Done"); |
Lucyjungz | 3:6e08d0bba1bb | 391 | |
Lucyjungz | 3:6e08d0bba1bb | 392 | /* Close the file */ |
Lucyjungz | 3:6e08d0bba1bb | 393 | fclose(fp); |
Lucyjungz | 3:6e08d0bba1bb | 394 | } |
Lucyjungz | 3:6e08d0bba1bb | 395 | } |
Lucyjungz | 3:6e08d0bba1bb | 396 | /** |
Lucyjungz | 3:6e08d0bba1bb | 397 | * @brief Function to log Mini RMS System Data |
Lucyjungz | 3:6e08d0bba1bb | 398 | * @note this file is only for debug |
Lucyjungz | 3:6e08d0bba1bb | 399 | * @param gps_interval - |
Lucyjungz | 3:6e08d0bba1bb | 400 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 401 | */ |
Lucyjungz | 14:4ba6147f067b | 402 | void FILEMANAGER_LogSystemData(float gps_interval) |
Lucyjungz | 3:6e08d0bba1bb | 403 | { |
Lucyjungz | 3:6e08d0bba1bb | 404 | /* Open the file in append mode */ |
Lucyjungz | 3:6e08d0bba1bb | 405 | FILE *fp = fopen(MINIRMS_LOG_FILE_NAME, "a"); |
Lucyjungz | 3:6e08d0bba1bb | 406 | |
Lucyjungz | 3:6e08d0bba1bb | 407 | if (fp == NULL) { |
Lucyjungz | 3:6e08d0bba1bb | 408 | /* In case of error, print the msg */ |
Lucyjungz | 3:6e08d0bba1bb | 409 | printf("Error! Unable to open file!\n"); |
Lucyjungz | 11:e21d4c5bfd1b | 410 | |
Lucyjungz | 11:e21d4c5bfd1b | 411 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 412 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 413 | } |
Lucyjungz | 3:6e08d0bba1bb | 414 | else |
Lucyjungz | 3:6e08d0bba1bb | 415 | { |
Lucyjungz | 11:e21d4c5bfd1b | 416 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 417 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 418 | |
Lucyjungz | 3:6e08d0bba1bb | 419 | /* Write some message, which is TBD */ |
Lucyjungz | 3:6e08d0bba1bb | 420 | fprintf(fp, "\nStart Mini-RMS System with Gps Interval = %f",gps_interval); |
Lucyjungz | 1:1f1f2b99756b | 421 | fclose(fp); // ensure you close the file after writing |
Lucyjungz | 1:1f1f2b99756b | 422 | } |
Lucyjungz | 1:1f1f2b99756b | 423 | } |
Lucyjungz | 3:6e08d0bba1bb | 424 | /** |
Lucyjungz | 3:6e08d0bba1bb | 425 | * @brief Utility to delete file |
Lucyjungz | 3:6e08d0bba1bb | 426 | * @note |
Lucyjungz | 3:6e08d0bba1bb | 427 | * @param filename - file name to be deleted |
Lucyjungz | 3:6e08d0bba1bb | 428 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 429 | */ |
Lucyjungz | 14:4ba6147f067b | 430 | void FILEMANAGER_Deletefile(char filename[]) |
nsrwsurasak | 0:a27e0d3581d1 | 431 | { |
nsrwsurasak | 0:a27e0d3581d1 | 432 | printf("Deleting file '%s'...",filename); |
nsrwsurasak | 0:a27e0d3581d1 | 433 | FILE *fp = fopen(filename, "r"); // try and open file |
nsrwsurasak | 0:a27e0d3581d1 | 434 | if (fp != NULL) { // if it does open... |
nsrwsurasak | 0:a27e0d3581d1 | 435 | fclose(fp); // close it |
nsrwsurasak | 0:a27e0d3581d1 | 436 | remove(filename); // and then delete |
nsrwsurasak | 0:a27e0d3581d1 | 437 | printf("Done!\n"); |
nsrwsurasak | 0:a27e0d3581d1 | 438 | } |
nsrwsurasak | 0:a27e0d3581d1 | 439 | // if we can't open it, it doesn't exist and so we can't delete it |
nsrwsurasak | 0:a27e0d3581d1 | 440 | } |
Lucyjungz | 3:6e08d0bba1bb | 441 | /** |
Lucyjungz | 3:6e08d0bba1bb | 442 | * @brief Utility to check file available |
Lucyjungz | 3:6e08d0bba1bb | 443 | * @note |
Lucyjungz | 3:6e08d0bba1bb | 444 | * @param filename - file name to be checked |
Lucyjungz | 3:6e08d0bba1bb | 445 | * @retval true - file is exist , false - file is not exist |
Lucyjungz | 3:6e08d0bba1bb | 446 | */ |
Lucyjungz | 14:4ba6147f067b | 447 | bool FILEMANAGER_IsFileExist(char filename[]) |
Lucyjungz | 1:1f1f2b99756b | 448 | { |
Lucyjungz | 1:1f1f2b99756b | 449 | bool exist = false; |
Lucyjungz | 1:1f1f2b99756b | 450 | FILE *fp = fopen(filename, "r"); // try and open file |
Lucyjungz | 1:1f1f2b99756b | 451 | if (fp != NULL) { // if it does open... |
Lucyjungz | 1:1f1f2b99756b | 452 | fclose(fp); // close it |
Lucyjungz | 1:1f1f2b99756b | 453 | exist = true; |
Lucyjungz | 1:1f1f2b99756b | 454 | } |
Lucyjungz | 1:1f1f2b99756b | 455 | |
Lucyjungz | 1:1f1f2b99756b | 456 | return exist; |
Lucyjungz | 1:1f1f2b99756b | 457 | } |
Lucyjungz | 3:6e08d0bba1bb | 458 | /** |
Lucyjungz | 3:6e08d0bba1bb | 459 | * @brief Utility to get GPS Interval |
Lucyjungz | 14:4ba6147f067b | 460 | * @note must be called after read the setup file |
Lucyjungz | 3:6e08d0bba1bb | 461 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 462 | * @retval GPS interval |
Lucyjungz | 3:6e08d0bba1bb | 463 | */ |
Lucyjungz | 14:4ba6147f067b | 464 | int FILEMANAGER_GPSInterval() |
nsrwsurasak | 0:a27e0d3581d1 | 465 | { |
Lucyjungz | 3:6e08d0bba1bb | 466 | /* Return interval in int */ |
Lucyjungz | 14:4ba6147f067b | 467 | return ( m_GpsInterval ); |
nsrwsurasak | 0:a27e0d3581d1 | 468 | } |
Lucyjungz | 3:6e08d0bba1bb | 469 | /** |
Lucyjungz | 3:6e08d0bba1bb | 470 | * @brief Utility to get Data Interval |
Lucyjungz | 14:4ba6147f067b | 471 | * @note must be called after read the setup file |
Lucyjungz | 3:6e08d0bba1bb | 472 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 473 | * @retval Data interval |
Lucyjungz | 3:6e08d0bba1bb | 474 | */ |
Lucyjungz | 14:4ba6147f067b | 475 | int FILEMANAGER_DataInterval() |
nsrwsurasak | 0:a27e0d3581d1 | 476 | { |
Lucyjungz | 3:6e08d0bba1bb | 477 | /* Return interval in int */ |
Lucyjungz | 14:4ba6147f067b | 478 | return ( m_DataInterval ); |
nsrwsurasak | 0:a27e0d3581d1 | 479 | } |
Lucyjungz | 3:6e08d0bba1bb | 480 | /** |
Lucyjungz | 3:6e08d0bba1bb | 481 | * @brief Function to read the variable list file |
Lucyjungz | 3:6e08d0bba1bb | 482 | * @note Recommended to call this function at initilization phase |
Lucyjungz | 3:6e08d0bba1bb | 483 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 484 | * @retval pointer to variable list |
Lucyjungz | 3:6e08d0bba1bb | 485 | */ |
Lucyjungz | 14:4ba6147f067b | 486 | Variable_Data_TypeDef * FILEMANAGER_ReadVarFile() |
nsrwsurasak | 0:a27e0d3581d1 | 487 | { |
Lucyjungz | 3:6e08d0bba1bb | 488 | /* Open the file with reading mode */ |
Lucyjungz | 21:0c52dbc23f52 | 489 | FILE *fp = fopen(m_varListFileName, "r"); |
nsrwsurasak | 0:a27e0d3581d1 | 490 | |
Lucyjungz | 3:6e08d0bba1bb | 491 | if (fp == NULL) |
Lucyjungz | 3:6e08d0bba1bb | 492 | { |
Lucyjungz | 3:6e08d0bba1bb | 493 | /* if it can't open the file then print error message */ |
Lucyjungz | 21:0c52dbc23f52 | 494 | printf("\nError! Unable to open file! %s \n", m_varListFileName); |
Lucyjungz | 11:e21d4c5bfd1b | 495 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 496 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 11:e21d4c5bfd1b | 497 | |
nsrwsurasak | 0:a27e0d3581d1 | 498 | return NULL; |
Lucyjungz | 3:6e08d0bba1bb | 499 | } |
Lucyjungz | 3:6e08d0bba1bb | 500 | else |
Lucyjungz | 3:6e08d0bba1bb | 501 | { |
Lucyjungz | 11:e21d4c5bfd1b | 502 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 503 | FILEMANAGER_SetLedStatus(true); |
nsrwsurasak | 0:a27e0d3581d1 | 504 | |
Lucyjungz | 3:6e08d0bba1bb | 505 | /* Allocate buffer for reading */ |
Lucyjungz | 14:4ba6147f067b | 506 | char buf[READ_FILE_BUFFER_SIZE]; |
nsrwsurasak | 0:a27e0d3581d1 | 507 | int index = 0; |
Lucyjungz | 3:6e08d0bba1bb | 508 | |
Lucyjungz | 3:6e08d0bba1bb | 509 | /* Initialize return value */ |
nsrwsurasak | 0:a27e0d3581d1 | 510 | memset(m_varList, ' ', sizeof(m_varList)); |
Lucyjungz | 3:6e08d0bba1bb | 511 | |
Lucyjungz | 3:6e08d0bba1bb | 512 | /* Read line from the file */ |
Lucyjungz | 3:6e08d0bba1bb | 513 | while (fgets(buf, sizeof(buf), fp) != NULL) |
Lucyjungz | 3:6e08d0bba1bb | 514 | { |
Lucyjungz | 3:6e08d0bba1bb | 515 | /* Check the TAG */ |
Lucyjungz | 3:6e08d0bba1bb | 516 | if (strstr (buf,VAR_NAME_TAG)) |
Lucyjungz | 3:6e08d0bba1bb | 517 | { |
Lucyjungz | 3:6e08d0bba1bb | 518 | /* Found variable TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 519 | FILEMANAGER_GetXmlText(buf , m_varList[index].varName); |
Lucyjungz | 3:6e08d0bba1bb | 520 | } |
Lucyjungz | 3:6e08d0bba1bb | 521 | else if (strstr (buf,VAR_ADDR_TAG)) |
Lucyjungz | 3:6e08d0bba1bb | 522 | { |
Lucyjungz | 3:6e08d0bba1bb | 523 | /* Found variable address TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 524 | FILEMANAGER_GetXmlText(buf , m_varList[index].varAddress); |
Lucyjungz | 5:7c513eee7b2b | 525 | } |
Lucyjungz | 10:a8003d357cf2 | 526 | else if (strstr (buf,VAR_TYPE_TAG)) |
Lucyjungz | 10:a8003d357cf2 | 527 | { |
Lucyjungz | 10:a8003d357cf2 | 528 | /* Found variable type TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 529 | FILEMANAGER_GetXmlText(buf , m_varList[index].varType); |
Lucyjungz | 10:a8003d357cf2 | 530 | } |
Lucyjungz | 6:5bd75c0f607c | 531 | else if (strstr (buf,VAR_LSB1_TAG)) |
Lucyjungz | 6:5bd75c0f607c | 532 | { |
Lucyjungz | 6:5bd75c0f607c | 533 | /* Found variable LSB1 TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 534 | FILEMANAGER_GetXmlText(buf , m_varList[index].varLSB1); |
Lucyjungz | 6:5bd75c0f607c | 535 | } |
Lucyjungz | 6:5bd75c0f607c | 536 | else if (strstr (buf,VAR_LSB2_TAG)) |
Lucyjungz | 5:7c513eee7b2b | 537 | { |
Lucyjungz | 6:5bd75c0f607c | 538 | /* Found variable LSB2 TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 539 | FILEMANAGER_GetXmlText(buf , m_varList[index].varLSB2); |
Lucyjungz | 6:5bd75c0f607c | 540 | } |
Lucyjungz | 6:5bd75c0f607c | 541 | else if (strstr (buf,VAR_BITMASK_TAG)) |
Lucyjungz | 6:5bd75c0f607c | 542 | { |
Lucyjungz | 6:5bd75c0f607c | 543 | /* Found variable BitMask TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 544 | FILEMANAGER_GetXmlText(buf , m_varList[index].varBitMask); |
Lucyjungz | 5:7c513eee7b2b | 545 | } |
Lucyjungz | 5:7c513eee7b2b | 546 | else if (strstr (buf,VAR_UNIT_TAG)) |
Lucyjungz | 5:7c513eee7b2b | 547 | { |
Lucyjungz | 5:7c513eee7b2b | 548 | /* Found variable unit TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 549 | FILEMANAGER_GetXmlText(buf , m_varList[index].varUnit); |
nsrwsurasak | 0:a27e0d3581d1 | 550 | index++; |
nsrwsurasak | 0:a27e0d3581d1 | 551 | } |
nsrwsurasak | 0:a27e0d3581d1 | 552 | |
nsrwsurasak | 0:a27e0d3581d1 | 553 | } |
Lucyjungz | 3:6e08d0bba1bb | 554 | /* Close File */ |
Lucyjungz | 3:6e08d0bba1bb | 555 | fclose(fp); |
Lucyjungz | 3:6e08d0bba1bb | 556 | |
Lucyjungz | 3:6e08d0bba1bb | 557 | /* Populate amount */ |
nsrwsurasak | 0:a27e0d3581d1 | 558 | m_amountVarList = index; |
Lucyjungz | 3:6e08d0bba1bb | 559 | |
Lucyjungz | 3:6e08d0bba1bb | 560 | /* Return variable list */ |
nsrwsurasak | 0:a27e0d3581d1 | 561 | return m_varList; |
nsrwsurasak | 0:a27e0d3581d1 | 562 | } |
nsrwsurasak | 0:a27e0d3581d1 | 563 | } |
Lucyjungz | 3:6e08d0bba1bb | 564 | /** |
Lucyjungz | 3:6e08d0bba1bb | 565 | * @brief Function to amount of variable for data logging |
Lucyjungz | 3:6e08d0bba1bb | 566 | * @note Must be called after readVarFile |
Lucyjungz | 3:6e08d0bba1bb | 567 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 568 | * @retval amount of variable list |
Lucyjungz | 3:6e08d0bba1bb | 569 | */ |
Lucyjungz | 14:4ba6147f067b | 570 | int FILEMANAGER_GetAmountVarList() |
nsrwsurasak | 0:a27e0d3581d1 | 571 | { |
nsrwsurasak | 0:a27e0d3581d1 | 572 | return m_amountVarList; |
nsrwsurasak | 0:a27e0d3581d1 | 573 | } |
Lucyjungz | 3:6e08d0bba1bb | 574 | /** |
Lucyjungz | 3:6e08d0bba1bb | 575 | * @brief Function to get variable list |
Lucyjungz | 3:6e08d0bba1bb | 576 | * @note Must be called after readVarFile |
Lucyjungz | 3:6e08d0bba1bb | 577 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 578 | * @retval pointer to variable list |
Lucyjungz | 3:6e08d0bba1bb | 579 | */ |
Lucyjungz | 14:4ba6147f067b | 580 | Variable_Data_TypeDef * FILEMANAGER_GetVarList() |
nsrwsurasak | 0:a27e0d3581d1 | 581 | { |
nsrwsurasak | 0:a27e0d3581d1 | 582 | return m_varList; |
nsrwsurasak | 0:a27e0d3581d1 | 583 | } |
Lucyjungz | 14:4ba6147f067b | 584 | |
Lucyjungz | 11:e21d4c5bfd1b | 585 | /** |
Lucyjungz | 11:e21d4c5bfd1b | 586 | * @brief Utility to play with LED status |
Lucyjungz | 11:e21d4c5bfd1b | 587 | * @note Libary user need to assign proper PinName to LED_SDCARD |
Lucyjungz | 11:e21d4c5bfd1b | 588 | * @param on - True for turning LED ON, otherwise LED off |
Lucyjungz | 11:e21d4c5bfd1b | 589 | * @retval None |
Lucyjungz | 11:e21d4c5bfd1b | 590 | */ |
Lucyjungz | 14:4ba6147f067b | 591 | static void FILEMANAGER_SetLedStatus(bool on) |
Lucyjungz | 11:e21d4c5bfd1b | 592 | { |
Lucyjungz | 12:0045fca3c160 | 593 | /* Check LED Connection */ |
nsrwsurasak | 22:2fc64ad66e35 | 594 | if (ledStatus.is_connected()) |
Lucyjungz | 11:e21d4c5bfd1b | 595 | { |
Lucyjungz | 21:0c52dbc23f52 | 596 | /* Set LED regarding to given argment */ |
nsrwsurasak | 22:2fc64ad66e35 | 597 | if (m_sdCardIsPresent) |
nsrwsurasak | 22:2fc64ad66e35 | 598 | { |
nsrwsurasak | 22:2fc64ad66e35 | 599 | ledStatus = on; |
nsrwsurasak | 22:2fc64ad66e35 | 600 | } |
nsrwsurasak | 22:2fc64ad66e35 | 601 | else |
nsrwsurasak | 22:2fc64ad66e35 | 602 | { |
nsrwsurasak | 22:2fc64ad66e35 | 603 | ledStatus = false; |
nsrwsurasak | 22:2fc64ad66e35 | 604 | } |
nsrwsurasak | 22:2fc64ad66e35 | 605 | |
Lucyjungz | 12:0045fca3c160 | 606 | } |
Lucyjungz | 12:0045fca3c160 | 607 | #if DEBUG |
Lucyjungz | 12:0045fca3c160 | 608 | else |
Lucyjungz | 12:0045fca3c160 | 609 | { |
Lucyjungz | 14:4ba6147f067b | 610 | printf("\r\nSDCard LED is not connected !!"); |
Lucyjungz | 12:0045fca3c160 | 611 | } |
Lucyjungz | 12:0045fca3c160 | 612 | #endif |
Lucyjungz | 11:e21d4c5bfd1b | 613 | } |
Lucyjungz | 15:b63a539c3754 | 614 |