AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/xplained/bname.c
int bacnet_name_copy(
    uint16_t offset,
    uint8_t *dest,
    uint8_t dest_len)
{
    uint8_t encoding = 0;
    uint8_t length = 0;
    char name[NVM_NAME_SIZE + 1] = "";
    unsigned i = 0;
    int bytes_read = -1;

    nvm_read(NVM_NAME_ENCODING(offset), &encoding, 1);
    nvm_read(NVM_NAME_LENGTH(offset), &length, 1);
    nvm_read(NVM_NAME_STRING(offset),
        (uint8_t *) & name, NVM_NAME_SIZE);
    if (bacnet_name_isvalid(encoding, length,  name)) {
        if (dest_len > NVM_NAME_SIZE) {
            dest_len = NVM_NAME_SIZE;
        }
        bytes_read = dest_len;
        for (i = 0; i < dest_len; i++) {
            if (i < length) {
                dest[i] = name[i];
            } else {
                dest[i] = 0;
            }
        }
    } else {
        for (i = 0; i < dest_len; i++) {
            dest[i] = 0;
        }
    }

    return bytes_read;
}
/*************************************************************************
* DESCRIPTION: Copy the name from non-volatile memory at offset
* RETURN: number of bytes read, or -1 on error
* NOTES: none
**************************************************************************/
Copy the name from non-volatile memory at offset
RETURN: number of bytes read, or -1 on error
NOTES: none
Copy the name from non - volatile memory at offset RETURN : number of bytes read or - 1 on error NOTES : none
int bacnet_name_copy(
    uint16_t offset,
    uint8_t *dest,
    uint8_t dest_len)
{
    uint8_t encoding = 0;
    uint8_t length = 0;
    char name[NVM_NAME_SIZE + 1] = "";
    unsigned i = 0;
    int bytes_read = -1;
    nvm_read(NVM_NAME_ENCODING(offset), &encoding, 1);
    nvm_read(NVM_NAME_LENGTH(offset), &length, 1);
    nvm_read(NVM_NAME_STRING(offset),
        (uint8_t *) & name, NVM_NAME_SIZE);
    if (bacnet_name_isvalid(encoding, length,  name)) {
        if (dest_len > NVM_NAME_SIZE) {
            dest_len = NVM_NAME_SIZE;
        }
        bytes_read = dest_len;
        for (i = 0; i < dest_len; i++) {
            if (i < length) {
                dest[i] = name[i];
            } else {
                dest[i] = 0;
            }
        }
    } else {
        for (i = 0; i < dest_len; i++) {
            dest[i] = 0;
        }
    }
    return bytes_read;
}
int bacnet_name_copy ( uint16_t offset , uint8_t * dest , uint8_t dest_len ) { uint8_t encoding = 0 ; uint8_t length = 0 ; char name [ NVM_NAME_SIZE + 1 ] = " " ; unsigned i = 0 ; int bytes_read = -1 ; nvm_read ( NVM_NAME_ENCODING ( offset ) , & encoding , 1 ) ; nvm_read ( NVM_NAME_LENGTH ( offset ) , & length , 1 ) ; nvm_read ( NVM_NAME_STRING ( offset ) , ( uint8_t * ) & name , NVM_NAME_SIZE ) ; if ( bacnet_name_isvalid ( encoding , length , name ) ) { if ( dest_len > NVM_NAME_SIZE ) { dest_len = NVM_NAME_SIZE ; } bytes_read = dest_len ; for ( i = 0 ; i < dest_len ; i ++ ) { if ( i < length ) { dest [ i ] = name [ i ] ; } else { dest [ i ] = 0 ; } } } else { for ( i = 0 ; i < dest_len ; i ++ ) { dest [ i ] = 0 ; } } return bytes_read ; }
DESCRIPTION: Copy the name from non-volatile memory at offset
RETURN: number of bytes read, or -1 on error
NOTES: none
DESCRIPTION : Copy the name from non - volatile memory at offset RETURN : number of bytes read or - 1 on error NOTES : none