Rev 2178 Rev 2179
Line 133... Line 133...
133 printf("$TDC%s M2 ", VERSION); 133 printf("$TDC%s M2 ", VERSION);
134 printf("%3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3)); 134 printf("%3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
135   135  
136 } 136 }
137   137  
-   138 void get_command(char *ptr, unsigned int max) // gets string of defined maximum lenght
-   139 {
-   140 char c=0;
-   141 unsigned int len=0;
-   142  
-   143 while ((c=getc()) != 13)
-   144 {
-   145 ptr[len]=c;
-   146
-   147 if (len == max-2)
-   148 {
-   149 ptr[len+1]=0;
-   150 return;
-   151 }
-   152 len++;
-   153 }
-   154
-   155 return;
-   156 }
-   157  
138   158  
139 void main() 159 void main()
140 { 160 {
141   161  
142 char command[20]; 162 char command[20];
143 char tmp[5]; 163 char tmp[5];
-   164 char *ptr;
144 unsigned int parameter; 165 unsigned long parameter;
145 setup_adc_ports(NO_ANALOGS|VSS_VDD); 166 setup_adc_ports(NO_ANALOGS|VSS_VDD);
146 setup_adc(ADC_CLOCK_DIV_2); 167 setup_adc(ADC_CLOCK_DIV_2);
147 setup_spi(SPI_SS_DISABLED); 168 setup_spi(SPI_SS_DISABLED);
148 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); 169 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
149 setup_timer_1(T1_DISABLED); 170 setup_timer_1(T1_DISABLED);
Line 157... Line 178...
157 printf("\r\n\r\n# TDC%s (C) 2011 Jakub Kakona\r\n",VERSION); // Welcome message 178 printf("\r\n\r\n# TDC%s (C) 2011 Jakub Kakona\r\n",VERSION); // Welcome message
158 // printf("#%s\r\n",&REV[4]); 179 // printf("#%s\r\n",&REV[4]);
159   180  
160 while(TRUE) 181 while(TRUE)
161 { 182 {
162 printf("$TDC%s->", VERSION); 183 printf("$TDC%s->", VERSION); // print prompt
163 fgets(command); 184 get_command(command, 20); // receive command from terminal
164 printf("%s\r\n", command); 185 printf("%s\r\n", command); // echo received command
165 186
166 strcpy(tmp,"TM"); 187 strcpy(tmp,"TM");
167 if (!strncmp(command, tmp, 2)) temperature_measurement(); 188 if (!strncmp(command, tmp, 2)) temperature_measurement();
168   189  
169 strcpy(tmp,"M2 "); 190 strcpy(tmp,"M2 ");
170 if (!strncmp(command, tmp, 3)) 191 if (!strncmp(command, tmp, 3))
171 { 192 {
172 parameter=atoi(command[5]); 193 parameter=strtol(command+3,&ptr,10);
-   194
-   195 printf("%s\r\n", command+3);
173 printf("%u\r\n",parameter); 196 printf("%lu\r\n",parameter);
174 measurementM2(parameter); 197 measurementM2(parameter);
175 } 198 }
176 199
177 strcpy(tmp,"M1 "); 200 strcpy(tmp,"M1 ");
178 if (!strncmp(command, tmp, 3)) 201 if (!strncmp(command, tmp, 3))