Advertisement
Guest User

Untitled

a guest
May 28th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. static char c_receive;
  2. static char rx_array[256];
  3. static int arraybuilder_finished;
  4. static int parser_finished;
  5.  
  6. static float koeff1=0;
  7. static float koeff2=0;
  8. static float koeff3=0;
  9. static float koeff4=0;
  10. static float koeff5=0;
  11. static float koeff6=0;
  12.  
  13. static float koeffs[5];
  14.  
  15. void arraybuilder(char rxzeichen)
  16. {
  17.  
  18. static int start = 0;
  19. static int errorflag = 0;
  20. static int i = 0;
  21. int j;
  22.  
  23. if(rxzeichen == 80) //P
  24. {
  25. /*if(start == 1)
  26. {
  27. errorflag = 1;
  28. start=0;
  29. printf("ERROR ERROR\n");
  30. for(j=0;j<i;j++)
  31. {
  32. rx_array[j]='0';
  33. }
  34. }
  35.  
  36. else
  37. {
  38. */
  39. //rx_array[0]=rxzeichen;
  40. start = 1;
  41. arraybuilder_finished=0;
  42. //printf("P detected!\t\t\t%d\n",i);
  43. //}
  44. }
  45.  
  46. if(start == 1)
  47. {
  48. rx_array[i]=rxzeichen;
  49. i++;
  50. errorflag=0;
  51. //printf("zeichen dazugezaehlt\t\t%d\n",i);
  52. }
  53.  
  54. if(rxzeichen == 35 && errorflag == 0)
  55. {
  56. rx_array[i]=rxzeichen;
  57. start=0;
  58. //printf("# detected\n");
  59.  
  60. for(j=0; j<i; j++)
  61. {
  62. //printf("%c\t\t%d\n", rx_array[j],j);
  63. }
  64. //printf("\n\n");
  65.  
  66. arraybuilder_finished=1;
  67.  
  68.  
  69. //resetten
  70. /*for(j=0;j<256;j++)
  71. {
  72. rx_array[j]='-';
  73. }*/
  74.  
  75. i=0;
  76. }
  77. }
  78.  
  79.  
  80. void parser()
  81. {
  82. //static char rx_array[256]="P0001_3.252_52.85_14.12_25.1_36.87_1.1#";
  83. static char array[256];
  84. static int i=0; //index des arrays
  85. static int j=0; //wie oft wurde schon ein fertiger wert erkannt und gespeichert
  86. static int k=0; //index des temp arrays
  87. static int u=0; //kopieren
  88. static int a=0; //zaehlvariable
  89. static int first_=0;//flag ob erstes underscore
  90. static int punkt=0;
  91.  
  92. char temp[16]="000000000000000\0"; //werden zeichen zwischengespeichert, entspricht den werten die in float umgewandelt werden
  93.  
  94. float value=0; //zwischenspeicher des wertes
  95.  
  96. parser_finished = 0;
  97.  
  98. for(u=0;u<256;u++)
  99. {
  100. array[u]=rx_array[u];
  101. }
  102.  
  103.  
  104. if(array[0]==80 && array[1]==48 && array[2]==48 && array[3]==48 && array[4]==49) //P0001
  105. {
  106. i=5;
  107.  
  108. while(array[i] != 35) //solange keine endezeichen
  109. {
  110. printf("\nin schleife\n");
  111. if(array[i]==95) //Trennzeichen, Wert berechnen (string konvertieren into float)
  112. {
  113. printf("\ntrennzeichen erkannt\n");
  114.  
  115. for(a=0;a<15;a++)
  116. {
  117. if(temp[a]=='.')
  118. {
  119. punkt = 1;
  120. }
  121. }
  122.  
  123. if(punkt==0)
  124. {
  125. temp[k]='.';
  126. }
  127.  
  128. printf("\ntemporaeres array: %s\n",temp);
  129.  
  130. value = atof(temp); //atof converts the string argument str to a floating-point number (type double)
  131.  
  132. //printf("\n\tbisher wurden %d Werte erkannt!\n",j);
  133. if(j==0)
  134. {
  135. first_ = 1;
  136. //printf("\n\tfirst underscore\n");
  137. }
  138. else
  139. {
  140. first_=0;
  141. }
  142.  
  143. j++;
  144.  
  145. if(first_ == 0)
  146. {
  147. switch(j-1)
  148. {
  149. case 1: koeff1=value;
  150. //printf("\nWert1:\t %f\n",koeff1);
  151. break;
  152. case 2: koeff2=value;
  153. //printf("\nWert2:\t %f\n",koeff2);
  154. break;
  155. case 3: koeff3=value;
  156. //printf("\nWert3:\t %f\n",koeff3);
  157. break;
  158. case 4: koeff4=value;
  159. //printf("\nWert4:\t %f\n",koeff4);
  160. break;
  161. case 5: koeff5=value;
  162. //printf("\nWert5:\t %f\n",koeff5);
  163. break;
  164. case 6: koeff6=value;
  165. //printf("\nWert6:\t %f\n",koeff6);
  166. break;
  167. }
  168. }
  169.  
  170. for(a=0;a<15;a++) //reset des tempor‰ren arrays
  171. {
  172. temp[a]='0';
  173. }
  174. temp[15]='\0'; //terminierung
  175.  
  176. k=0;
  177. punkt=0;
  178. }
  179. else //kein Trennzeichen, Wert noch nicht "vollst‰ndig"
  180. {
  181. temp[k]=array[i]; //zeichen ins temp array schreiben
  182. printf("\naktuelles zeichen: %c\n",temp[k]);
  183. k++;
  184. }
  185. i++;
  186. }
  187.  
  188. if(array[i]==35) //endezeichen
  189. {
  190. for(a=0;a<15;a++)
  191. {
  192. if(temp[a]=='.')
  193. {
  194. punkt = 1;
  195. }
  196. }
  197.  
  198. if(punkt==0)
  199. {
  200. temp[k]='.';
  201. }
  202.  
  203. //printf("\ntemporaeres array: %s\n",temp);
  204.  
  205. value = atof(temp); //atof converts the string argument str to a floating-point number (type double)
  206.  
  207. //printf("\n\tbisher wurden %d Werte erkannt!\n",j);
  208. if(j==0)
  209. {
  210. first_ = 1;
  211. //printf("\n\tfirst underscore\n");
  212. }
  213. else
  214. {
  215. first_=0;
  216. }
  217.  
  218. j++;
  219.  
  220. if(first_ == 0)
  221. {
  222. switch(j-1)
  223. {
  224. case 1: koeff1=value;
  225. //printf("\nWert1:\t %f\n",koeff1);
  226. break;
  227. case 2: koeff2=value;
  228. //printf("\nWert2:\t %f\n",koeff2);
  229. break;
  230. case 3: koeff3=value;
  231. //printf("\nWert3:\t %f\n",koeff3);
  232. break;
  233. case 4: koeff4=value;
  234. //printf("\nWert4:\t %f\n",koeff4);
  235. break;
  236. case 5: koeff5=value;
  237. //printf("\nWert5:\t %f\n",koeff5);
  238. break;
  239. case 6: koeff6=value;
  240. //printf("\nWert6:\t %f\n",koeff6);
  241. break;
  242. }
  243. }
  244.  
  245. for(a=0;a<15;a++) //reset des tempor‰ren arrays
  246. {
  247. temp[a]='0';
  248. }
  249. temp[15]='\0';
  250.  
  251. k=0;
  252. punkt=0;
  253.  
  254. parser_finished = 1;
  255.  
  256. //printf("\n\n\nENDE ENDE \n\n\n");
  257. }
  258.  
  259. }
  260. j=0;
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement