Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static char c_receive;
- static char rx_array[256];
- static int arraybuilder_finished;
- static int parser_finished;
- static float koeff1=0;
- static float koeff2=0;
- static float koeff3=0;
- static float koeff4=0;
- static float koeff5=0;
- static float koeff6=0;
- static float koeffs[5];
- void arraybuilder(char rxzeichen)
- {
- static int start = 0;
- static int errorflag = 0;
- static int i = 0;
- int j;
- if(rxzeichen == 80) //P
- {
- /*if(start == 1)
- {
- errorflag = 1;
- start=0;
- printf("ERROR ERROR\n");
- for(j=0;j<i;j++)
- {
- rx_array[j]='0';
- }
- }
- else
- {
- */
- //rx_array[0]=rxzeichen;
- start = 1;
- arraybuilder_finished=0;
- //printf("P detected!\t\t\t%d\n",i);
- //}
- }
- if(start == 1)
- {
- rx_array[i]=rxzeichen;
- i++;
- errorflag=0;
- //printf("zeichen dazugezaehlt\t\t%d\n",i);
- }
- if(rxzeichen == 35 && errorflag == 0)
- {
- rx_array[i]=rxzeichen;
- start=0;
- //printf("# detected\n");
- for(j=0; j<i; j++)
- {
- //printf("%c\t\t%d\n", rx_array[j],j);
- }
- //printf("\n\n");
- arraybuilder_finished=1;
- //resetten
- /*for(j=0;j<256;j++)
- {
- rx_array[j]='-';
- }*/
- i=0;
- }
- }
- void parser()
- {
- //static char rx_array[256]="P0001_3.252_52.85_14.12_25.1_36.87_1.1#";
- static char array[256];
- static int i=0; //index des arrays
- static int j=0; //wie oft wurde schon ein fertiger wert erkannt und gespeichert
- static int k=0; //index des temp arrays
- static int u=0; //kopieren
- static int a=0; //zaehlvariable
- static int first_=0;//flag ob erstes underscore
- static int punkt=0;
- char temp[16]="000000000000000\0"; //werden zeichen zwischengespeichert, entspricht den werten die in float umgewandelt werden
- float value=0; //zwischenspeicher des wertes
- parser_finished = 0;
- for(u=0;u<256;u++)
- {
- array[u]=rx_array[u];
- }
- if(array[0]==80 && array[1]==48 && array[2]==48 && array[3]==48 && array[4]==49) //P0001
- {
- i=5;
- while(array[i] != 35) //solange keine endezeichen
- {
- printf("\nin schleife\n");
- if(array[i]==95) //Trennzeichen, Wert berechnen (string konvertieren into float)
- {
- printf("\ntrennzeichen erkannt\n");
- for(a=0;a<15;a++)
- {
- if(temp[a]=='.')
- {
- punkt = 1;
- }
- }
- if(punkt==0)
- {
- temp[k]='.';
- }
- printf("\ntemporaeres array: %s\n",temp);
- value = atof(temp); //atof converts the string argument str to a floating-point number (type double)
- //printf("\n\tbisher wurden %d Werte erkannt!\n",j);
- if(j==0)
- {
- first_ = 1;
- //printf("\n\tfirst underscore\n");
- }
- else
- {
- first_=0;
- }
- j++;
- if(first_ == 0)
- {
- switch(j-1)
- {
- case 1: koeff1=value;
- //printf("\nWert1:\t %f\n",koeff1);
- break;
- case 2: koeff2=value;
- //printf("\nWert2:\t %f\n",koeff2);
- break;
- case 3: koeff3=value;
- //printf("\nWert3:\t %f\n",koeff3);
- break;
- case 4: koeff4=value;
- //printf("\nWert4:\t %f\n",koeff4);
- break;
- case 5: koeff5=value;
- //printf("\nWert5:\t %f\n",koeff5);
- break;
- case 6: koeff6=value;
- //printf("\nWert6:\t %f\n",koeff6);
- break;
- }
- }
- for(a=0;a<15;a++) //reset des tempor‰ren arrays
- {
- temp[a]='0';
- }
- temp[15]='\0'; //terminierung
- k=0;
- punkt=0;
- }
- else //kein Trennzeichen, Wert noch nicht "vollst‰ndig"
- {
- temp[k]=array[i]; //zeichen ins temp array schreiben
- printf("\naktuelles zeichen: %c\n",temp[k]);
- k++;
- }
- i++;
- }
- if(array[i]==35) //endezeichen
- {
- for(a=0;a<15;a++)
- {
- if(temp[a]=='.')
- {
- punkt = 1;
- }
- }
- if(punkt==0)
- {
- temp[k]='.';
- }
- //printf("\ntemporaeres array: %s\n",temp);
- value = atof(temp); //atof converts the string argument str to a floating-point number (type double)
- //printf("\n\tbisher wurden %d Werte erkannt!\n",j);
- if(j==0)
- {
- first_ = 1;
- //printf("\n\tfirst underscore\n");
- }
- else
- {
- first_=0;
- }
- j++;
- if(first_ == 0)
- {
- switch(j-1)
- {
- case 1: koeff1=value;
- //printf("\nWert1:\t %f\n",koeff1);
- break;
- case 2: koeff2=value;
- //printf("\nWert2:\t %f\n",koeff2);
- break;
- case 3: koeff3=value;
- //printf("\nWert3:\t %f\n",koeff3);
- break;
- case 4: koeff4=value;
- //printf("\nWert4:\t %f\n",koeff4);
- break;
- case 5: koeff5=value;
- //printf("\nWert5:\t %f\n",koeff5);
- break;
- case 6: koeff6=value;
- //printf("\nWert6:\t %f\n",koeff6);
- break;
- }
- }
- for(a=0;a<15;a++) //reset des tempor‰ren arrays
- {
- temp[a]='0';
- }
- temp[15]='\0';
- k=0;
- punkt=0;
- parser_finished = 1;
- //printf("\n\n\nENDE ENDE \n\n\n");
- }
- }
- j=0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement