Exemplo n.º 1
0
int freespace_sendMessageAsync(FreespaceDeviceId id,
                               struct freespace_message* message,
                               unsigned int timeoutMs,
                               freespace_sendCallback callback,
                               void* cookie) {

    int rc;
    uint8_t msgBuf[FREESPACE_MAX_OUTPUT_MESSAGE_SIZE];
    struct FreespaceDeviceInfo info;
    
    // Address is reserved for now and must be set to 0 by the caller.
    if (message->dest == 0) {
        message->dest = FREESPACE_RESERVED_ADDRESS;
    }
    
    rc = freespace_getDeviceInfo(id, &info);
    if (rc != FREESPACE_SUCCESS) {
        return rc;
    }
    
    message->ver = info.hVer;
    rc = freespace_encode_message(message, msgBuf, FREESPACE_MAX_OUTPUT_MESSAGE_SIZE);
    if (rc <= FREESPACE_SUCCESS) {
        return rc;
    }

    return freespace_private_sendAsync(id, msgBuf, rc, timeoutMs, callback, cookie);
}
LIBFREESPACE_API int freespace_sendMessage(FreespaceDeviceId id,
                                           struct freespace_message* message) {

    int retVal;
    uint8_t msgBuf[FREESPACE_MAX_OUTPUT_MESSAGE_SIZE];
    struct FreespaceDeviceInfo info;

    memset(msgBuf, 0, sizeof(msgBuf));
    
    // Address is reserved for now and must be set to 0 by the caller.
    if (message->dest == 0) {
        message->dest = FREESPACE_RESERVED_ADDRESS;
    }

    retVal = freespace_getDeviceInfo(id, &info);
    if (retVal != FREESPACE_SUCCESS) {
        return retVal;
    }
    
    message->ver = info.hVer;
    retVal = freespace_encode_message(message, msgBuf, FREESPACE_MAX_OUTPUT_MESSAGE_SIZE);
    if (retVal <= FREESPACE_SUCCESS) {
        return retVal;
    }
    
    return freespace_private_send(id, msgBuf, retVal);
}