The (alpha of the) official Exosite library, CoAP version.

NOTE: This mirror repository may be out of date, check the main repo for changes. If there are any remind me to update this mirror.

This is an unstable alpha of the Official Exosite library, there are known issues with the port to this platform. You probably shouldn't use this library yet if you just want to get things done.

This version uses CoAP for the application protocol.

Committer:
Patrick Barrett
Date:
Wed Jan 07 14:20:56 2015 -0600
Revision:
29:004c318e63fa
Parent:
11:08bae8fb9824
added retry on network error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Patrick Barrett 0:c7393ae16c16 1 /*****************************************************************************
Patrick Barrett 0:c7393ae16c16 2 *
Patrick Barrett 0:c7393ae16c16 3 * exosite.h - Exosite Activator Library
Patrick Barrett 0:c7393ae16c16 4 * Copyright (C) 2015 Exosite LLC
Patrick Barrett 0:c7393ae16c16 5 *
Patrick Barrett 0:c7393ae16c16 6 * Redistribution and use in source and binary forms, with or without
Patrick Barrett 0:c7393ae16c16 7 * modification, are permitted provided that the following conditions
Patrick Barrett 0:c7393ae16c16 8 * are met:
Patrick Barrett 0:c7393ae16c16 9 *
Patrick Barrett 0:c7393ae16c16 10 * Redistributions of source code must retain the above copyright
Patrick Barrett 0:c7393ae16c16 11 * notice, this list of conditions and the following disclaimer.
Patrick Barrett 0:c7393ae16c16 12 *
Patrick Barrett 0:c7393ae16c16 13 * Redistributions in binary form must reproduce the above copyright
Patrick Barrett 0:c7393ae16c16 14 * notice, this list of conditions and the following disclaimer in the
Patrick Barrett 0:c7393ae16c16 15 * documentation and/or other materials provided with the
Patrick Barrett 0:c7393ae16c16 16 * distribution.
Patrick Barrett 0:c7393ae16c16 17 *
Patrick Barrett 0:c7393ae16c16 18 * Neither the name of Texas Instruments Incorporated nor the names of
Patrick Barrett 0:c7393ae16c16 19 * its contributors may be used to endorse or promote products derived
Patrick Barrett 0:c7393ae16c16 20 * from this software without specific prior written permission.
Patrick Barrett 0:c7393ae16c16 21 *
Patrick Barrett 0:c7393ae16c16 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Patrick Barrett 0:c7393ae16c16 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Patrick Barrett 0:c7393ae16c16 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Patrick Barrett 0:c7393ae16c16 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Patrick Barrett 0:c7393ae16c16 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Patrick Barrett 0:c7393ae16c16 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Patrick Barrett 0:c7393ae16c16 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Patrick Barrett 0:c7393ae16c16 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Patrick Barrett 0:c7393ae16c16 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Patrick Barrett 0:c7393ae16c16 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Patrick Barrett 0:c7393ae16c16 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Patrick Barrett 0:c7393ae16c16 33 *
Patrick Barrett 0:c7393ae16c16 34 *****************************************************************************/
Patrick Barrett 0:c7393ae16c16 35
Patrick Barrett 0:c7393ae16c16 36 #ifndef EXOSITE_H
Patrick Barrett 0:c7393ae16c16 37 #define EXOSITE_H
Patrick Barrett 0:c7393ae16c16 38
Patrick Barrett 0:c7393ae16c16 39 #include <stdint.h>
Patrick Barrett 0:c7393ae16c16 40 #include "exosite_pal.h"
Patrick Barrett 0:c7393ae16c16 41
Patrick Barrett 0:c7393ae16c16 42
Patrick Barrett 0:c7393ae16c16 43 // DEFINES
Patrick Barrett 0:c7393ae16c16 44 #define CIK_LENGTH 40
Patrick Barrett 0:c7393ae16c16 45
Patrick Barrett 0:c7393ae16c16 46 // ENUMS
Patrick Barrett 0:c7393ae16c16 47 typedef enum exo_error
Patrick Barrett 0:c7393ae16c16 48 {
Patrick Barrett 0:c7393ae16c16 49 EXO_OK = 0,
Patrick Barrett 0:c7393ae16c16 50 EXO_GENERAL_ERROR,
Patrick Barrett 0:c7393ae16c16 51 EXO_OUT_OF_SPACE,
Patrick Barrett 0:c7393ae16c16 52 EXO_FATAL_ERROR_PAL,
Patrick Barrett 0:c7393ae16c16 53 } exo_error;
Patrick Barrett 0:c7393ae16c16 54
Patrick Barrett 0:c7393ae16c16 55 typedef enum exo_state
Patrick Barrett 0:c7393ae16c16 56 {
Patrick Barrett 0:c7393ae16c16 57 EXO_IDLE,
Patrick Barrett 0:c7393ae16c16 58 EXO_WAITING,
Patrick Barrett 0:c7393ae16c16 59 EXO_BUSY,
Patrick Barrett 10:76deeaebfafb 60 EXO_NEW_RESPONSE,
Patrick Barrett 11:08bae8fb9824 61 EXO_ERROR,
Patrick Barrett 0:c7393ae16c16 62 EXO_CONNECTION_ERROR,
Patrick Barrett 0:c7393ae16c16 63 EXO_DEVICE_NOT_ENABLED,
Patrick Barrett 0:c7393ae16c16 64 EXO_DEVICE_DOES_NOT_EXIST,
Patrick Barrett 0:c7393ae16c16 65 } exo_state;
Patrick Barrett 0:c7393ae16c16 66
Patrick Barrett 0:c7393ae16c16 67 typedef enum exo_data_format
Patrick Barrett 0:c7393ae16c16 68 {
Patrick Barrett 0:c7393ae16c16 69 EXO_STRING,
Patrick Barrett 0:c7393ae16c16 70 EXO_FLOAT,
Patrick Barrett 0:c7393ae16c16 71 EXO_INTEGER
Patrick Barrett 0:c7393ae16c16 72 } exo_data_format;
Patrick Barrett 0:c7393ae16c16 73
Patrick Barrett 0:c7393ae16c16 74 typedef enum exo_device_state
Patrick Barrett 0:c7393ae16c16 75 {
Patrick Barrett 0:c7393ae16c16 76 EXO_STATE_UNINITIALIZED,
Patrick Barrett 0:c7393ae16c16 77 EXO_STATE_INITIALIZED,
Patrick Barrett 0:c7393ae16c16 78 EXO_STATE_GOOD,
Patrick Barrett 11:08bae8fb9824 79 EXO_STATE_BAD_CIK,
Patrick Barrett 0:c7393ae16c16 80 } exo_device_state;
Patrick Barrett 0:c7393ae16c16 81
Patrick Barrett 0:c7393ae16c16 82 typedef enum exo_request_type
Patrick Barrett 0:c7393ae16c16 83 {
Patrick Barrett 0:c7393ae16c16 84 EXO_NULL = 0,
Patrick Barrett 0:c7393ae16c16 85 EXO_WRITE,
Patrick Barrett 0:c7393ae16c16 86 EXO_READ,
Patrick Barrett 0:c7393ae16c16 87 EXO_SUBSCRIBE,
Patrick Barrett 11:08bae8fb9824 88 EXO_ACTIVATE,
Patrick Barrett 0:c7393ae16c16 89 } exo_request_type;
Patrick Barrett 0:c7393ae16c16 90
Patrick Barrett 0:c7393ae16c16 91 typedef enum exo_request_state
Patrick Barrett 0:c7393ae16c16 92 {
Patrick Barrett 0:c7393ae16c16 93 EXO_REQUEST_NULL,
Patrick Barrett 0:c7393ae16c16 94 EXO_REQUEST_NEW,
Patrick Barrett 0:c7393ae16c16 95 EXO_REQUEST_PENDING,
Patrick Barrett 0:c7393ae16c16 96 EXO_REQUEST_SUBSCRIBED,
Patrick Barrett 0:c7393ae16c16 97 EXO_REQUEST_SUB_ACK,
Patrick Barrett 0:c7393ae16c16 98 EXO_REQUEST_SUB_ACK_NEW,
Patrick Barrett 0:c7393ae16c16 99 EXO_REQUEST_SUCCESS,
Patrick Barrett 0:c7393ae16c16 100 EXO_REQUEST_ERROR,
Patrick Barrett 0:c7393ae16c16 101 } exo_request_state;
Patrick Barrett 0:c7393ae16c16 102
Patrick Barrett 0:c7393ae16c16 103 typedef struct exo_op
Patrick Barrett 0:c7393ae16c16 104 {
Patrick Barrett 0:c7393ae16c16 105 exo_request_type type;
Patrick Barrett 0:c7393ae16c16 106 exo_request_state state;
Patrick Barrett 0:c7393ae16c16 107 const char * alias;
Patrick Barrett 0:c7393ae16c16 108 char * value;
Patrick Barrett 0:c7393ae16c16 109 size_t value_max;
Patrick Barrett 0:c7393ae16c16 110 uint16_t mid;
Patrick Barrett 0:c7393ae16c16 111 uint32_t obs_seq;
Patrick Barrett 0:c7393ae16c16 112 uint8_t tkl;
Patrick Barrett 0:c7393ae16c16 113 uint64_t token;
Patrick Barrett 0:c7393ae16c16 114 uint64_t timeout;
Patrick Barrett 29:004c318e63fa 115 uint8_t retries;
Patrick Barrett 0:c7393ae16c16 116 } exo_op;
Patrick Barrett 0:c7393ae16c16 117
Patrick Barrett 0:c7393ae16c16 118 // PUBLIC FUNCTIONS
Patrick Barrett 0:c7393ae16c16 119 exo_error exo_init(const char * vendor, const char *model, const char *sn);
Patrick Barrett 0:c7393ae16c16 120
Patrick Barrett 0:c7393ae16c16 121 void exo_write(exo_op *op, const char * alias, const char * value);
Patrick Barrett 0:c7393ae16c16 122 void exo_read(exo_op *op, const char * alias, char * value, const size_t value_max);
Patrick Barrett 0:c7393ae16c16 123 void exo_subscribe(exo_op *op, const char * alias, char * value, const size_t value_max);
Patrick Barrett 0:c7393ae16c16 124
Patrick Barrett 0:c7393ae16c16 125 void exo_op_init(exo_op *op);
Patrick Barrett 0:c7393ae16c16 126 void exo_op_done(exo_op *op);
Patrick Barrett 0:c7393ae16c16 127
Patrick Barrett 0:c7393ae16c16 128 uint8_t exo_is_op_valid(exo_op *op);
Patrick Barrett 0:c7393ae16c16 129 uint8_t exo_is_op_success(exo_op *op);
Patrick Barrett 0:c7393ae16c16 130 uint8_t exo_is_op_finished(exo_op *op);
Patrick Barrett 0:c7393ae16c16 131 uint8_t exo_is_op_read(exo_op *op);
Patrick Barrett 0:c7393ae16c16 132 uint8_t exo_is_op_subscribe(exo_op *op);
Patrick Barrett 0:c7393ae16c16 133 uint8_t exo_is_op_write(exo_op *op);
Patrick Barrett 0:c7393ae16c16 134
Patrick Barrett 0:c7393ae16c16 135 exo_state exo_operate(exo_op * ops, uint8_t count);
Patrick Barrett 0:c7393ae16c16 136
Patrick Barrett 0:c7393ae16c16 137
Patrick Barrett 0:c7393ae16c16 138 #endif
Patrick Barrett 0:c7393ae16c16 139
Patrick Barrett 0:c7393ae16c16 140
Patrick Barrett 0:c7393ae16c16 141