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