Rev 41 | Rev 89 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 41 | Rev 88 | ||
---|---|---|---|
Line 60... | Line 60... | ||
60 | #include "91x_lib.h" |
60 | #include "91x_lib.h" |
61 | #include "fat16.h" |
61 | #include "fat16.h" |
62 | #include "settings.h" |
62 | #include "settings.h" |
63 | #include "uart1.h" |
63 | #include "uart1.h" |
Line 64... | Line 64... | ||
64 | 64 | ||
65 | struct str_setting_parameter CFG_Parameter[] = |
65 | typedef struct |
- | 66 | { |
|
- | 67 | ParamId_t ParamId; |
|
66 | { |
68 | s8 Name[16]; |
- | 69 | u8 Group; // 0 = reserved 1,2,3,4 |
|
- | 70 | u16 Value; |
|
- | 71 | u16 Default; |
|
- | 72 | u16 Min; |
|
- | 73 | u16 Max; |
|
- | 74 | } __attribute__((packed)) Parameter_t; |
|
- | 75 | ||
- | 76 | Parameter_t CFG_Parameter[] = |
|
67 | //{"1234567890123456" , "12345678901234567890123456789012", Group, Value, Default , Min, Max }, |
77 | { |
68 | {"Parameter1 " , "12345678901234567890123456789012", 1 , 0 , 222 , 200 , 230 }, |
78 | //{PID , "1234567890123456" , Group, Value, Default, Min, Max }, |
69 | {"Parameter2 " , "12345678901234567890123456789012", 1 , 0 , 0 , 0 , 220 }, |
79 | {PID_KML_LOGGING , "KMLLogging " , 1, 500, 500, 0, 60000}, // the log interval for KML logging, 0 = off |
70 | {"Parameter22 " , "12345678901234567890123456789012", 1 , 0 , 0 , 0 , 220 }, |
80 | {PID_GPX_LOGGING , "GPXLogging " , 1, 0, 0, 0, 60000} // the log interval for GPX logging, 0 = off |
Line 71... | Line 81... | ||
71 | }; |
81 | }; |
- | 82 | ||
72 | 83 | ||
73 | 84 | //---------------------------------------------------------------------------------- |
|
74 | //---------------------------------------------------------------------------------- |
85 | // initialize all parameters by its default value |
- | 86 | void Settings_SetDefaultValues(void) |
|
75 | void InitDefaultParameters(void) |
87 | { |
76 | { |
88 | u8 i; |
77 | u8 i; |
89 | // run thrue all parameters and set value to default |
78 | for (i=0;i<sizeof(CFG_Parameter) / sizeof(struct str_setting_parameter);i++) |
90 | for (i = 0; i < sizeof(CFG_Parameter) / sizeof(Parameter_t); i++) |
79 | { |
- | |
80 | CFG_Parameter[i].Value = CFG_Parameter[i].Default; |
91 | { |
Line 81... | Line 92... | ||
81 | } |
92 | CFG_Parameter[i].Value = CFG_Parameter[i].Default; |
- | 93 | } |
|
82 | 94 | } |
|
83 | } |
95 | |
84 | 96 | //---------------------------------------------------------------------------------- |
|
85 | //---------------------------------------------------------------------------------- |
97 | // set parameter from string based name and value |
Line 86... | Line 98... | ||
86 | void SetParameter(char *name, char *value) |
98 | void Settings_SetParameterFromString(s8 *name, s8 *value) |
87 | { |
99 | { |
Line 88... | Line 100... | ||
88 | u8 i; |
100 | u8 i; |
89 | char string[] = " \0"; |
101 | s8 string[] = " \0"; // null terminated string of 16 characters |
Line -... | Line 102... | ||
- | 102 | ||
90 | 103 | i = strlen(name); // lenght of the parameter name |
|
91 | i=strlen(name); |
104 | if (i > 16) i = 16; // cut off at 16 |
92 | if (i>16) i=16; |
105 | |
93 | 106 | memcpy(string, name, i); // copy name to local buffer |
|
94 | memcpy(string, name, i); |
107 | //sprintf(text,"#%s#%s#\n\r", name, string); SerialPutString(text); |
95 | // sprintf(text,"#%s#%s#\n\r", name, string); SerialPutString(text); |
108 | |
96 | - | ||
- | 109 | // search name in parameter list |
|
97 | for (i=0;i<sizeof(CFG_Parameter) / sizeof(struct str_setting_parameter);i++) |
110 | for (i = 0; i < sizeof(CFG_Parameter) / sizeof(Parameter_t); i++) |
98 | { |
- | |
99 | // sprintf(text,"#%s#\n\r", CFG_Parameter[i].Name); SerialPutString(text); |
111 | { |
100 | if (strncmp(string, CFG_Parameter[i].Name, 16) == 0) |
112 | //sprintf(text,"#%s#\n\r", CFG_Parameter[i].Name); SerialPutString(text); |
- | 113 | if(strncmp(string, CFG_Parameter[i].Name, 16) == 0) // names are matching |
|
101 | { |
114 | { |
102 | CFG_Parameter[i].Value = (unsigned char) atoi(value); |
115 | CFG_Parameter[i].Value = (u16)atoi(value); // convert string to number and set value |
103 | 116 | // range within min/max |
|
104 | if (CFG_Parameter[i].Value < CFG_Parameter[i].Min || CFG_Parameter[i].Value > CFG_Parameter[i].Max) |
117 | if(CFG_Parameter[i].Value < CFG_Parameter[i].Min) CFG_Parameter[i].Value = CFG_Parameter[i].Min; |
Line 105... | Line 118... | ||
105 | CFG_Parameter[i].Value = CFG_Parameter[i].Default; |
118 | |
- | 119 | //sprintf(text,"%s = %d\n\r", string, CFG_Parameter[i].Value); |
|
106 | 120 | //SerialPutString(text); |
|
107 | sprintf(text,"%s = %d\n\r", string, CFG_Parameter[i].Value); SerialPutString(text); |
121 | break; // end loop |
- | 122 | } |
|
108 | break; |
123 | } |
109 | } |
124 | } |
110 | } |
- | |
111 | } |
125 | |
Line 112... | Line 126... | ||
112 | 126 | //---------------------------------------------------------------------------------- |
|
- | 127 | // read settings from file on sd-card |
|
- | 128 | void Settings_Init(void) |
|
Line 113... | Line -... | ||
113 | //---------------------------------------------------------------------------------- |
- | |
114 | void ReadSetting(u8 number) |
129 | { |
115 | { |
- | |
116 | File_t *fp; |
- | |
117 | u8 text[32]; |
130 | #define LINE_MAX 32 |
118 | u8 tmp; |
131 | File_t *fp; |
119 | u8 *token; |
132 | u8 text[LINE_MAX]; |
120 | 133 | u8 *token; |
|
Line 121... | Line 134... | ||
121 | InitDefaultParameters(); |
134 | |
- | 135 | Settings_SetDefaultValues(); |
|
122 | 136 | SerialPutString("\n\rReading settings from file...\n\r"); |
|
- | 137 | fp = fopen_("settings.ini", 'r'); |
|
- | 138 | ||
123 | SerialPutString("\n\rReading setting file...\n\r"); |
139 | if (fp == NULL) // could not open the file |
124 | fp = fopen_("setting1.txt", 'r'); |
140 | { |
- | 141 | SerialPutString("ERROR: File not found !"); |
|
- | 142 | return; |
|
125 | 143 | } |
|
126 | if (fp == NULL) |
- | |
127 | { |
144 | |
128 | SerialPutString("ERROR: File not found !\n\r"); |
145 | // read all lines from file |
129 | return; |
146 | while(fgets_(text, LINE_MAX, fp) != NULL) |
130 | } |
147 | { |
131 | 148 | if ( // ignorelines starting with \r,\n,' ',';','#' |
|
132 | for (tmp=0;tmp<10;tmp++) |
149 | (text[0] != '\n') && |
133 | { |
- | |
134 | fgets_(text , 31, fp); |
150 | (text[0] != '\r') && |
135 | if (text[0] == 0) break; |
151 | (text[0] != ' ' ) && |
136 | 152 | (text[0] != ';' ) && |
|
137 | if (text[0] != '\n' && text[0] != '\r' && text[0] != ' ' && text[0] != ';' && text[0] != '#') |
153 | (text[0] != '#' ) |
138 | { |
154 | ) |
139 | token = strtok(text, "="); |
- | |
- | 155 | { |
|
140 | if (token != NULL) |
156 | token = strtok(text, "="); //find the '=' |
Line -... | Line 157... | ||
- | 157 | if (token != NULL) // if '=' has been found |
|
- | 158 | { |
|
- | 159 | //SerialPutString(token);SerialPutString(" --> "); |
|
- | 160 | Settings_SetParameterFromString(token, strtok(NULL, "=")); |
|
- | 161 | //SerialPutString("\n\r"); |
|
- | 162 | } |
|
- | 163 | } |
|
- | 164 | } |
|
- | 165 | fclose_(fp); |
|
- | 166 | SerialPutString("ok"); |
|
- | 167 | } |
|
- | 168 | ||
- | 169 | ||
- | 170 | //---------------------------------------------------------------------------------- |
|
- | 171 | // read value of a paramter identified by its id |
|
- | 172 | // returns 1 on success and 0 on error |
|
- | 173 | u8 Settings_GetParamValue(ParamId_t Pid, u16 * pValue) |
|
- | 174 | { |
|
- | 175 | u8 i, retval = 0; |