/*
ISC License (ISCL)

Copyright (c) 2010.  Leszek Loboda - Zakład Elektroniczny Letronik.
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*


20100414
ll4650lib.c
biblioteka specyficzna dla liczników 4650


*/
#if ! defined (ll4650lib_b)
#define ll4650lib_b

#include <stdlib.h>

#include <stdio.h>
#include <string.h>


int getdata(char buf[],  int *num, int *bladF)
//jak zwraca zero, to dobra transmija.
//buf dane z com
//anum - stan licznika postaci ascii
//num -  stan licznika w postaci int
//bladF ilosc bledow fotokomorki
{//getdata
int n=0, m=0, res=-1;
*bladF=0;
char anum[10];
while((buf[n]) && (n<255))
{
if((m==2)&&(buf[n]=='F'))
{
(*bladF)++;
//printf("F");
//printf("%d",*bladF);
m=0;

}

if((m>1) && (m<8))
{
if((buf[n] >= '0') && (buf[n] <= '9'))
{

anum[m-2]=buf[n];
m++;
}
else
m=0;

}

if(m==8) 
{
anum[m-2]=0;
*num=atoi(anum);
m=0;
}


if(m==1)
{
 if(buf[n] == 0x0d)
m=2;
else
m=0;

}

if(m==0)
{
if(buf[n] == 0x0a)
m=1;
else
m=0;
}


res=m;
n++;
}
return(res);

}//getdata

#endif

