Add collected changes from T.Sax
This commit is contained in:
371
src/tslib.cpp
Normal file → Executable file
371
src/tslib.cpp
Normal file → Executable file
@@ -610,3 +610,374 @@ bool tslib_strComp(uint8_t *buf, char *compStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char biox_StrComp(char *S1, char *S2, int len)
|
||||
{
|
||||
// retval=1 wenn gleich; ? in S2 =Jokerzeichen
|
||||
|
||||
int ii;
|
||||
|
||||
for (ii=0; ii<len; ii++)
|
||||
{
|
||||
if ((S1[ii] != S2[ii]) && (S2[ii] != '?') )
|
||||
return (0);
|
||||
}
|
||||
|
||||
return(1);
|
||||
|
||||
}
|
||||
|
||||
// *****************************************************************************************
|
||||
|
||||
uint16_t tslib_StrLen(char *str)
|
||||
{
|
||||
uint16_t zz;
|
||||
|
||||
for (zz=0; zz<0xF000; zz++)
|
||||
if (str[zz]==0)
|
||||
return(zz);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************************
|
||||
|
||||
uint16_t biox_StrLenInt(uint16_t *str)
|
||||
{
|
||||
uint16_t zz;
|
||||
|
||||
for (zz=0; zz<0xF000; zz++)
|
||||
if (str[zz]==0)
|
||||
return(zz);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
// *****************************************************************************************
|
||||
|
||||
void biox_MemCpy(uint8_t *src, uint8_t *dest, uint16_t Len)
|
||||
{
|
||||
// copy "Len" bytes from target to destination
|
||||
// if Len==0 then copy until first NULL in targ
|
||||
|
||||
uint16_t zz=0;
|
||||
if (Len==0)
|
||||
{
|
||||
while(src[zz]>0)
|
||||
{
|
||||
dest[zz]=src[zz];
|
||||
zz++;
|
||||
}
|
||||
dest[zz]=0; // termination
|
||||
} else
|
||||
{
|
||||
// Len>0 --> copy "Len" bytes
|
||||
for (zz=0; zz<Len; zz++)
|
||||
dest[zz]=src[zz];
|
||||
|
||||
dest[zz]=0; // termination
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void tslib_itoa(int n, char *str)
|
||||
{
|
||||
// -23456 -> str[0]='-' str[1]='2' ...[5]='6' str[6]=0
|
||||
// 5 -> str[0]='5' str[1..6]=0
|
||||
|
||||
uint8_t pp, zi[7];
|
||||
int itmp, pi=0;
|
||||
|
||||
for (pp=0;pp<7;pp++)
|
||||
{
|
||||
str[pp]=0;
|
||||
zi[pp]=0;
|
||||
}
|
||||
|
||||
itmp=n;
|
||||
pp=0;
|
||||
|
||||
if (itmp==0)
|
||||
str[pp++]=0x30;
|
||||
|
||||
if (itmp<0)
|
||||
{
|
||||
str[pp++]='-';
|
||||
itmp*=-1;
|
||||
}
|
||||
|
||||
while(itmp>0)
|
||||
{
|
||||
zi[pi++]=itmp%10;
|
||||
itmp/=10;
|
||||
}
|
||||
// now: zi[0]=6 zi[1]=5 zi[2]=4 zi[3]=3 zi[4]=2 zi[5]=0 zi[6]=0 pi=4
|
||||
while (pi>0)
|
||||
str[pp++]=zi[--pi]+0x30;
|
||||
|
||||
//str[0]='-'; str[1]='1'; str[3]='3'; // Test
|
||||
}
|
||||
|
||||
// ***********************************************************************************************
|
||||
|
||||
void tslib_uitoa(unsigned int n, char *str)
|
||||
{
|
||||
|
||||
uint8_t pp, zi[6];
|
||||
unsigned int itmp;
|
||||
int pi=0;
|
||||
|
||||
for (pp=0;pp<6;pp++)
|
||||
{
|
||||
str[pp]=0;
|
||||
zi[pp]=0;
|
||||
}
|
||||
|
||||
itmp=n;
|
||||
pp=0;
|
||||
|
||||
if (itmp==0)
|
||||
str[pp++]=0x30;
|
||||
|
||||
while(itmp>0)
|
||||
{
|
||||
zi[pi++]=itmp%10;
|
||||
itmp/=10;
|
||||
}
|
||||
// now: zi[0]=6 zi[1]=5 zi[2]=4 zi[3]=3 zi[4]=2 zi[5]=0 pi=4
|
||||
while (pi>0)
|
||||
str[pp++]=zi[--pi]+0x30;
|
||||
|
||||
//str[0]='-'; str[1]='1'; str[3]='3'; // Test
|
||||
}
|
||||
|
||||
// ***********************************************************************************************
|
||||
|
||||
void tslib_ltoa(long n, char *str)
|
||||
{
|
||||
// -2147483647 -> str[0]='-' str[1]='2' ...[10]='6' str[11]=0
|
||||
|
||||
uint8_t pp, zi[12];
|
||||
int pi=0;
|
||||
long ltmp;
|
||||
|
||||
for (pp=0;pp<12;pp++)
|
||||
{
|
||||
str[pp]=0;
|
||||
zi[pp]=0;
|
||||
}
|
||||
|
||||
ltmp=n;
|
||||
pp=0;
|
||||
|
||||
if (ltmp==0)
|
||||
str[pp++]=0x30;
|
||||
|
||||
if (ltmp<0)
|
||||
{
|
||||
str[pp++]='-';
|
||||
ltmp*=-1;
|
||||
}
|
||||
|
||||
while(ltmp>0)
|
||||
{
|
||||
zi[pi++]=ltmp%10;
|
||||
ltmp/=10;
|
||||
}
|
||||
|
||||
while (pi>0)
|
||||
str[pp++]=zi[--pi]+0x30;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ***********************************************************************************************
|
||||
|
||||
void tslib_ultoa(unsigned long n, char *str)
|
||||
{
|
||||
// 0... ->4294967296 str[0]='4' str[1]='2' ...[9]='6' str[10]=0 str[11]=0
|
||||
|
||||
uint8_t pp, zi[12];
|
||||
int pi=0;
|
||||
unsigned long ltmp;
|
||||
|
||||
for (pp=0;pp<12;pp++)
|
||||
{
|
||||
str[pp]=0;
|
||||
zi[pp]=0;
|
||||
}
|
||||
|
||||
ltmp=n;
|
||||
pp=0;
|
||||
|
||||
if (ltmp==0)
|
||||
str[pp++]=0x30;
|
||||
|
||||
while(ltmp>0)
|
||||
{
|
||||
zi[pi++]=ltmp%10;
|
||||
ltmp/=10;
|
||||
}
|
||||
|
||||
while (pi>0)
|
||||
str[pp++]=zi[--pi]+0x30;
|
||||
}
|
||||
|
||||
// ***********************************************************************************************
|
||||
|
||||
void tslib_uitobin(unsigned int decval, char *str)
|
||||
{
|
||||
uint16_t dv, bb;
|
||||
int ll;
|
||||
|
||||
dv=decval;
|
||||
ll=8; // show 8 bit
|
||||
if (dv>255) ll=16; // show 16 bit
|
||||
str[ll--]=0; // terminierung
|
||||
|
||||
bb=0;
|
||||
do
|
||||
{
|
||||
if (dv & (1<<bb) ) str[ll]=0x31; else str[ll]=0x30;
|
||||
bb++; ll--;
|
||||
} while(ll>=0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ***********************************************************************************************
|
||||
|
||||
long tslib_atol( char *AscString)
|
||||
{
|
||||
// change ascii string ( of ascii numbers '0'..'9') to number
|
||||
// AscString must be 0-terminated!
|
||||
// a leading '-' is ignored, a'.' or a ',' stops calculation
|
||||
|
||||
//aufruf mit ("1234")
|
||||
// aus IDE: ucatmp[0]='1' ucatmp[3]='4' ucatmp[4]='0' sl=4
|
||||
|
||||
unsigned long ultmp;
|
||||
unsigned char uctmp1, minus=0;
|
||||
unsigned int sl, zz;
|
||||
|
||||
sl=tslib_StrLen(AscString);
|
||||
if (sl>10) sl=10; // mehr passt im ULONG nicht rein!
|
||||
|
||||
ultmp=0;
|
||||
for (zz=0; zz<sl; zz++)
|
||||
{
|
||||
uctmp1=AscString[zz];
|
||||
if (zz==0 && uctmp1=='-')
|
||||
minus=1;
|
||||
else
|
||||
if (uctmp1>0x2F && uctmp1<0x3A)
|
||||
{
|
||||
ultmp*=10; // nur wenn eine neue Ziffer dazukommt und vor der addition!
|
||||
uctmp1-=0x30;
|
||||
ultmp+=(uint32_t)uctmp1;
|
||||
|
||||
} else
|
||||
if (uctmp1=='.' || uctmp1==',' || uctmp1==0 )
|
||||
{
|
||||
if (minus)
|
||||
ultmp*=(-1);
|
||||
return(ultmp);
|
||||
}
|
||||
}
|
||||
|
||||
if (minus)
|
||||
ultmp*=(-1);
|
||||
return(ultmp);
|
||||
|
||||
}
|
||||
|
||||
// *****************************************************************************************
|
||||
|
||||
unsigned long tslib_atoul( char *AscString)
|
||||
{
|
||||
// change ascii string ( of ascii numbers '0'..'9') to number
|
||||
// AscString must be 0-terminated!
|
||||
// a leading '-' is ignored, a'.' or a ',' stops calculation
|
||||
|
||||
//aufruf mit ("1234")
|
||||
// aus IDE: ucatmp[0]='1' ucatmp[3]='4' ucatmp[4]='0' sl=4
|
||||
|
||||
unsigned long ultmp;
|
||||
unsigned char uctmp1;
|
||||
unsigned int sl, zz;
|
||||
|
||||
sl=tslib_StrLen(AscString);
|
||||
if (sl>10) sl=10; // mehr passt im ULONG nicht rein!
|
||||
|
||||
ultmp=0;
|
||||
for (zz=0; zz<sl; zz++)
|
||||
{
|
||||
uctmp1=AscString[zz];
|
||||
if (uctmp1>0x2F && uctmp1<0x3A)
|
||||
{
|
||||
ultmp*=10; // nur wenn eine neue Ziffer dazukommt und vor der addition!
|
||||
uctmp1-=0x30;
|
||||
ultmp+=(uint32_t)uctmp1;
|
||||
|
||||
} else
|
||||
if (uctmp1=='.' || uctmp1==',' || uctmp1==0 )
|
||||
return(ultmp);
|
||||
}
|
||||
|
||||
return(ultmp);
|
||||
|
||||
}
|
||||
|
||||
// *****************************************************************************************
|
||||
|
||||
unsigned int tslib_ah2ui( char *AscString)
|
||||
{
|
||||
// change hex ascii string ( of ascii numbers '0'..'9', 'A' or 'a' ...'F','f') to number
|
||||
// AscString must be 0-terminated!
|
||||
// Example: "1A0C" = 6668
|
||||
|
||||
//unsigned long ultmp;
|
||||
unsigned char uctmp1;
|
||||
unsigned int sl, zz, uitmp;
|
||||
|
||||
sl=tslib_StrLen(AscString);
|
||||
if (sl>4) sl=4;
|
||||
|
||||
uitmp=0;
|
||||
for (zz=0; zz<sl; zz++)
|
||||
{
|
||||
uctmp1=AscString[zz];
|
||||
|
||||
if (uctmp1>=0x30 && uctmp1<=0x39)
|
||||
{
|
||||
uitmp<<=4; // nur wenn eine neue Ziffer dazukommt und vor der addition!
|
||||
uctmp1-=0x30;
|
||||
uitmp+=(uint16_t)uctmp1;
|
||||
} else
|
||||
|
||||
if (uctmp1>='A' && uctmp1<='F')
|
||||
{
|
||||
uitmp<<=4;
|
||||
uctmp1-=0x37;
|
||||
uitmp+=(uint16_t)uctmp1;
|
||||
} else
|
||||
|
||||
if (uctmp1>='a' && uctmp1<='f')
|
||||
{
|
||||
uitmp<<=4;
|
||||
uctmp1-=0x57;
|
||||
uitmp+=(uint16_t)uctmp1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return(uitmp);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user