EDN Admin
Well-known member
I have the following problem:
If I convert a <span style="font-weight:bold unint8, which only contents numbers like "1234123412341234" it works perfectly fine.
But if there is one letter (A-F) inside the whole number gets displayed wrongly. An example would be "123456789ABCDEF"
I really need some help here.
My current Code is here:
<div style="text-align:left
<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% Code Snippet
CONST uint8 strDevice[] = "Device:0x";
void zb_ReceiveDataIndication( uint16 source, /*contains Short Address*/
uint16 command, /*contains command word*/
uint16 len, /*contains length of pData*/
uint8 *pData )
{
uint8 buf[32];
uint8 *pBuf;
uint8 tmpLen;
if ( pData[0] == REPORT_RESPONSE )
{
tmpLen = (uint8)osal_strlen( (char*)strDevice ); // length of "strDevice"
pBuf = osal_memcpy( buf, strDevice, tmpLen ); // copy "Device: 0x"
_ltoa( source, pBuf, 16 ); // copy ShortAddr
pBuf += 4;
*pBuf++ = _; // add seperation character
/*****************************
* problem zone starts here
*/
uint8 AddrValue[8];
AddrValue[0] = pData[1]; // write Extended Address in variable
AddrValue[1] = pData[2];
AddrValue[2] = pData[3];
AddrValue[3] = pData[4];
AddrValue[4] = pData[5];
AddrValue[5] = pData[6];
AddrValue[6] = pData[7];
AddrValue[7] = pData[8];
for( int i=0; i<8; i++)
{
*pBuf++ = (AddrValue / 10 ) + 0; // convert msb to ascii
*pBuf++ = (AddrValue % 10 ) + 0; // convert lsb to ascii
}
/*****************************
* problem zone ends here
*/
*pBuf++ = (uint8)_; //seperation between ExtendedAddress & CounterValue
uint8 counterValue[2];
counterValue[0] = pData[9];
counterValue[1] = pData[10];
*pBuf++ = (counterValue[0] / 10 ) + 0; // convert msb to ascii
*pBuf++ = (counterValue[0] % 10 ) + 0; // convert lsb to ascii
*pBuf++ = (counterValue[1] / 10 ) + 0; // convert msb to ascii
*pBuf++ = (counterValue[1] % 10 ) + 0; // convert lsb to ascii
*pBuf++ = r; // add endings
*pBuf++ = n;
*pBuf = ;
#if defined( MT_TASK )
debug_str( (uint8 *)buf ); // debug output (is defined in program)
#endif
}
}
View the full article
If I convert a <span style="font-weight:bold unint8, which only contents numbers like "1234123412341234" it works perfectly fine.
But if there is one letter (A-F) inside the whole number gets displayed wrongly. An example would be "123456789ABCDEF"
I really need some help here.
My current Code is here:
<div style="text-align:left
<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% Code Snippet
CONST uint8 strDevice[] = "Device:0x";
void zb_ReceiveDataIndication( uint16 source, /*contains Short Address*/
uint16 command, /*contains command word*/
uint16 len, /*contains length of pData*/
uint8 *pData )
{
uint8 buf[32];
uint8 *pBuf;
uint8 tmpLen;
if ( pData[0] == REPORT_RESPONSE )
{
tmpLen = (uint8)osal_strlen( (char*)strDevice ); // length of "strDevice"
pBuf = osal_memcpy( buf, strDevice, tmpLen ); // copy "Device: 0x"
_ltoa( source, pBuf, 16 ); // copy ShortAddr
pBuf += 4;
*pBuf++ = _; // add seperation character
/*****************************
* problem zone starts here
*/
uint8 AddrValue[8];
AddrValue[0] = pData[1]; // write Extended Address in variable
AddrValue[1] = pData[2];
AddrValue[2] = pData[3];
AddrValue[3] = pData[4];
AddrValue[4] = pData[5];
AddrValue[5] = pData[6];
AddrValue[6] = pData[7];
AddrValue[7] = pData[8];
for( int i=0; i<8; i++)
{
*pBuf++ = (AddrValue / 10 ) + 0; // convert msb to ascii
*pBuf++ = (AddrValue % 10 ) + 0; // convert lsb to ascii
}
/*****************************
* problem zone ends here
*/
*pBuf++ = (uint8)_; //seperation between ExtendedAddress & CounterValue
uint8 counterValue[2];
counterValue[0] = pData[9];
counterValue[1] = pData[10];
*pBuf++ = (counterValue[0] / 10 ) + 0; // convert msb to ascii
*pBuf++ = (counterValue[0] % 10 ) + 0; // convert lsb to ascii
*pBuf++ = (counterValue[1] / 10 ) + 0; // convert msb to ascii
*pBuf++ = (counterValue[1] % 10 ) + 0; // convert lsb to ascii
*pBuf++ = r; // add endings
*pBuf++ = n;
*pBuf = ;
#if defined( MT_TASK )
debug_str( (uint8 *)buf ); // debug output (is defined in program)
#endif
}
}
View the full article