Untested port of the Ishtar protocol, actually not much of a port since there was really not much to change. http://kisvm2.epfl.ch/record/125676/files/emav08-ishtar-final.pdf
ishtar.h@0:086ea145b6d7, 2011-05-12 (annotated)
- Committer:
- ssozonoff
- Date:
- Thu May 12 08:30:17 2011 +0000
- Revision:
- 0:086ea145b6d7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ssozonoff | 0:086ea145b6d7 | 1 | /* |
ssozonoff | 0:086ea145b6d7 | 2 | Ishtar Embedded |
ssozonoff | 0:086ea145b6d7 | 3 | Copyright (C) 2008-2010: |
ssozonoff | 0:086ea145b6d7 | 4 | |
ssozonoff | 0:086ea145b6d7 | 5 | Alexandre Habersaat <alexandre dot habersaat at gmail dot com> |
ssozonoff | 0:086ea145b6d7 | 6 | Antoine Beyeler <abeyeler at ab-ware dot com> |
ssozonoff | 0:086ea145b6d7 | 7 | (http://www.ab-ware.com) |
ssozonoff | 0:086ea145b6d7 | 8 | Stephane Magnenat <stephane at magnenat dot net> |
ssozonoff | 0:086ea145b6d7 | 9 | (http://stephane.magnenat.net) |
ssozonoff | 0:086ea145b6d7 | 10 | |
ssozonoff | 0:086ea145b6d7 | 11 | All rights reserved. |
ssozonoff | 0:086ea145b6d7 | 12 | |
ssozonoff | 0:086ea145b6d7 | 13 | Ishtar Embedded is free software: you can redistribute it and/or modify |
ssozonoff | 0:086ea145b6d7 | 14 | it under the terms of the GNU Lesser General Public License as published by |
ssozonoff | 0:086ea145b6d7 | 15 | the Free Software Foundation, either version 3 of the License, or |
ssozonoff | 0:086ea145b6d7 | 16 | (at your option) any later version. |
ssozonoff | 0:086ea145b6d7 | 17 | |
ssozonoff | 0:086ea145b6d7 | 18 | Ishtar Embedded is distributed in the hope that it will be useful, |
ssozonoff | 0:086ea145b6d7 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
ssozonoff | 0:086ea145b6d7 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ssozonoff | 0:086ea145b6d7 | 21 | GNU General Public License for more details. |
ssozonoff | 0:086ea145b6d7 | 22 | |
ssozonoff | 0:086ea145b6d7 | 23 | You should have received a copy of the GNU Lesser General Public License |
ssozonoff | 0:086ea145b6d7 | 24 | along with Ishtar Embedded. If not, see <http://www.gnu.org/licenses/>. |
ssozonoff | 0:086ea145b6d7 | 25 | */ |
ssozonoff | 0:086ea145b6d7 | 26 | |
ssozonoff | 0:086ea145b6d7 | 27 | /*! |
ssozonoff | 0:086ea145b6d7 | 28 | * \file ishtar.h |
ssozonoff | 0:086ea145b6d7 | 29 | * \brief Header file of the Ishtar Embedded server |
ssozonoff | 0:086ea145b6d7 | 30 | * |
ssozonoff | 0:086ea145b6d7 | 31 | * \author Alexandre Habersaat, Antoine Beyeler |
ssozonoff | 0:086ea145b6d7 | 32 | * |
ssozonoff | 0:086ea145b6d7 | 33 | * This file contains the public interface of the Ishtar Embedded server |
ssozonoff | 0:086ea145b6d7 | 34 | */ |
ssozonoff | 0:086ea145b6d7 | 35 | |
ssozonoff | 0:086ea145b6d7 | 36 | #ifndef __ISHTAR_H__ |
ssozonoff | 0:086ea145b6d7 | 37 | #define __ISHTAR_H__ |
ssozonoff | 0:086ea145b6d7 | 38 | |
ssozonoff | 0:086ea145b6d7 | 39 | #ifdef ISHTAR_PREFIX |
ssozonoff | 0:086ea145b6d7 | 40 | #include ISHTAR_PREFIX |
ssozonoff | 0:086ea145b6d7 | 41 | #endif |
ssozonoff | 0:086ea145b6d7 | 42 | |
ssozonoff | 0:086ea145b6d7 | 43 | // #include <stdio.h> |
ssozonoff | 0:086ea145b6d7 | 44 | |
ssozonoff | 0:086ea145b6d7 | 45 | #include "ishtar_def.h" |
ssozonoff | 0:086ea145b6d7 | 46 | |
ssozonoff | 0:086ea145b6d7 | 47 | //----------------------------- |
ssozonoff | 0:086ea145b6d7 | 48 | // Module's options |
ssozonoff | 0:086ea145b6d7 | 49 | //----------------------------- |
ssozonoff | 0:086ea145b6d7 | 50 | |
ssozonoff | 0:086ea145b6d7 | 51 | #ifndef ISHTAR_DEBUG |
ssozonoff | 0:086ea145b6d7 | 52 | //! Ishtar debug mode |
ssozonoff | 0:086ea145b6d7 | 53 | #define ISHTAR_DEBUG 1 |
ssozonoff | 0:086ea145b6d7 | 54 | #endif |
ssozonoff | 0:086ea145b6d7 | 55 | |
ssozonoff | 0:086ea145b6d7 | 56 | #ifndef ISHTAR_MAX_NUMBER_OF_SERVICES |
ssozonoff | 0:086ea145b6d7 | 57 | //! The maximum number of services / variables that can be registered in Ishtar |
ssozonoff | 0:086ea145b6d7 | 58 | #define ISHTAR_MAX_NUMBER_OF_SERVICES 250 |
ssozonoff | 0:086ea145b6d7 | 59 | #endif |
ssozonoff | 0:086ea145b6d7 | 60 | |
ssozonoff | 0:086ea145b6d7 | 61 | #ifndef ISHTAR_BUFFER_SIZE |
ssozonoff | 0:086ea145b6d7 | 62 | //! The size of the reception buffer |
ssozonoff | 0:086ea145b6d7 | 63 | #define ISHTAR_BUFFER_SIZE 800 |
ssozonoff | 0:086ea145b6d7 | 64 | #endif |
ssozonoff | 0:086ea145b6d7 | 65 | |
ssozonoff | 0:086ea145b6d7 | 66 | #ifndef ISHTAR_STRING_MAX_SIZE |
ssozonoff | 0:086ea145b6d7 | 67 | //! The maximum size of a string in Ishtar Embedded |
ssozonoff | 0:086ea145b6d7 | 68 | #define ISHTAR_STRING_MAX_SIZE 100 |
ssozonoff | 0:086ea145b6d7 | 69 | #endif |
ssozonoff | 0:086ea145b6d7 | 70 | |
ssozonoff | 0:086ea145b6d7 | 71 | |
ssozonoff | 0:086ea145b6d7 | 72 | #ifdef __cplusplus |
ssozonoff | 0:086ea145b6d7 | 73 | extern "C" { |
ssozonoff | 0:086ea145b6d7 | 74 | #endif |
ssozonoff | 0:086ea145b6d7 | 75 | |
ssozonoff | 0:086ea145b6d7 | 76 | #ifndef ISHTAR_MAX_VEC_SIZE |
ssozonoff | 0:086ea145b6d7 | 77 | //! Maximum size for vectors |
ssozonoff | 0:086ea145b6d7 | 78 | #define ISHTAR_MAX_VEC_SIZE 65535 |
ssozonoff | 0:086ea145b6d7 | 79 | #endif |
ssozonoff | 0:086ea145b6d7 | 80 | |
ssozonoff | 0:086ea145b6d7 | 81 | #ifndef ISHTAR_MAX_SERVICES_COUNT |
ssozonoff | 0:086ea145b6d7 | 82 | // Maximum number of services |
ssozonoff | 0:086ea145b6d7 | 83 | #define ISHTAR_MAX_SERVICES_COUNT 65535 |
ssozonoff | 0:086ea145b6d7 | 84 | #endif |
ssozonoff | 0:086ea145b6d7 | 85 | |
ssozonoff | 0:086ea145b6d7 | 86 | #if ISHTAR_MAX_VEC_SIZE > 65535 |
ssozonoff | 0:086ea145b6d7 | 87 | typedef unsigned long ishtar_ValueVectorSize; |
ssozonoff | 0:086ea145b6d7 | 88 | #elif ISHTAR_MAX_VEC_SIZE > 255 |
ssozonoff | 0:086ea145b6d7 | 89 | typedef unsigned short ishtar_ValueVectorSize; |
ssozonoff | 0:086ea145b6d7 | 90 | #else |
ssozonoff | 0:086ea145b6d7 | 91 | typedef unsigned char ishtar_ValueVectorSize; |
ssozonoff | 0:086ea145b6d7 | 92 | #endif |
ssozonoff | 0:086ea145b6d7 | 93 | |
ssozonoff | 0:086ea145b6d7 | 94 | typedef unsigned char ishtar_ValueVectorType; |
ssozonoff | 0:086ea145b6d7 | 95 | |
ssozonoff | 0:086ea145b6d7 | 96 | #if ISHTAR_MAX_SERVICES_COUNT > 65535 |
ssozonoff | 0:086ea145b6d7 | 97 | typedef unsigned long ishtar_ServiceId; |
ssozonoff | 0:086ea145b6d7 | 98 | #else |
ssozonoff | 0:086ea145b6d7 | 99 | typedef unsigned short ishtar_ServiceId; |
ssozonoff | 0:086ea145b6d7 | 100 | #endif |
ssozonoff | 0:086ea145b6d7 | 101 | |
ssozonoff | 0:086ea145b6d7 | 102 | typedef unsigned char ishtar_ServiceFlags; |
ssozonoff | 0:086ea145b6d7 | 103 | typedef unsigned short ishtar_MessageId; |
ssozonoff | 0:086ea145b6d7 | 104 | typedef unsigned short ishtar_RequestId; |
ssozonoff | 0:086ea145b6d7 | 105 | |
ssozonoff | 0:086ea145b6d7 | 106 | typedef unsigned long ishtar_ProtocolType; |
ssozonoff | 0:086ea145b6d7 | 107 | typedef unsigned long ishtar_NodeType; |
ssozonoff | 0:086ea145b6d7 | 108 | typedef unsigned long ishtar_VersionType; |
ssozonoff | 0:086ea145b6d7 | 109 | |
ssozonoff | 0:086ea145b6d7 | 110 | // forward declaration |
ssozonoff | 0:086ea145b6d7 | 111 | //typedef struct ishtar_ServiceDescription ishtar_ServiceDescriptionPtr; |
ssozonoff | 0:086ea145b6d7 | 112 | typedef struct ishtar_ServiceDescriptionTag* ishtar_ServiceDescriptionPtr; |
ssozonoff | 0:086ea145b6d7 | 113 | |
ssozonoff | 0:086ea145b6d7 | 114 | //! Type definition for the external function used to send data through communication |
ssozonoff | 0:086ea145b6d7 | 115 | typedef void (*ishtar_ExternalSendFunc)(unsigned char *, unsigned long); |
ssozonoff | 0:086ea145b6d7 | 116 | //! Type definition for the external function used to flush the data output buffer at the end of each message that is sent |
ssozonoff | 0:086ea145b6d7 | 117 | typedef void (*ishtar_ExternalFlushFunc)(); |
ssozonoff | 0:086ea145b6d7 | 118 | //! Type definition for the external function used to write data in non-volatile memory |
ssozonoff | 0:086ea145b6d7 | 119 | typedef unsigned short (*ishtar_MemoryWriteFunc)(unsigned short address, void* data, unsigned short length); |
ssozonoff | 0:086ea145b6d7 | 120 | //! Type definition for the external function used to read data from non-volatile memory |
ssozonoff | 0:086ea145b6d7 | 121 | typedef unsigned short (*ishtar_MemoryReadFunc)(unsigned short address, void* data, unsigned short length); |
ssozonoff | 0:086ea145b6d7 | 122 | //! Type definition for the variable modified callback. |
ssozonoff | 0:086ea145b6d7 | 123 | typedef void (*ishtar_VariableModifiedFunc)(ishtar_ServiceDescriptionPtr variable); |
ssozonoff | 0:086ea145b6d7 | 124 | |
ssozonoff | 0:086ea145b6d7 | 125 | //! The structure for the description of services / variables |
ssozonoff | 0:086ea145b6d7 | 126 | typedef struct ishtar_ServiceDescriptionTag |
ssozonoff | 0:086ea145b6d7 | 127 | { |
ssozonoff | 0:086ea145b6d7 | 128 | const char* name; //!< The name of the variable |
ssozonoff | 0:086ea145b6d7 | 129 | ishtar_ValueVectorType type; //!< The type of the variable |
ssozonoff | 0:086ea145b6d7 | 130 | ishtar_ValueVectorSize length; //!< The length of the array |
ssozonoff | 0:086ea145b6d7 | 131 | ishtar_ServiceFlags flags; //!< The flags for the variable (READ_ONLY) |
ssozonoff | 0:086ea145b6d7 | 132 | void* value; //!< The pointer to the local real variable |
ssozonoff | 0:086ea145b6d7 | 133 | unsigned char inSnapshot; //!< If this variable is part of the snapshot |
ssozonoff | 0:086ea145b6d7 | 134 | ishtar_VariableModifiedFunc feedbackFunc; //!< Function called when the variable is remotely modified |
ssozonoff | 0:086ea145b6d7 | 135 | } ishtar_ServiceDescription; |
ssozonoff | 0:086ea145b6d7 | 136 | |
ssozonoff | 0:086ea145b6d7 | 137 | |
ssozonoff | 0:086ea145b6d7 | 138 | //----------------------------- |
ssozonoff | 0:086ea145b6d7 | 139 | // Public functions |
ssozonoff | 0:086ea145b6d7 | 140 | //----------------------------- |
ssozonoff | 0:086ea145b6d7 | 141 | |
ssozonoff | 0:086ea145b6d7 | 142 | //! This function inits the Ishtar Embedded server |
ssozonoff | 0:086ea145b6d7 | 143 | void ishtar_Init(ishtar_ExternalSendFunc externalSendFunc, ishtar_ExternalFlushFunc externalFlushFunc); |
ssozonoff | 0:086ea145b6d7 | 144 | //! This function inits the Ishtar Embedded server, and configures it to work with two different send functions, a non-blocking one and a blocking one |
ssozonoff | 0:086ea145b6d7 | 145 | void ishtar_InitWithBlock(ishtar_ExternalSendFunc externalSendFunc, ishtar_ExternalSendFunc externalSendBlockFunc, ishtar_ExternalFlushFunc externalFlushFunc); |
ssozonoff | 0:086ea145b6d7 | 146 | //! This function inits the non-volatile memory access functions |
ssozonoff | 0:086ea145b6d7 | 147 | void ishtar_InitMemoryAccess(ishtar_MemoryReadFunc memoryReadFunc, ishtar_MemoryWriteFunc memoryWriteFunc, unsigned short minAddress, unsigned short maxAddress); |
ssozonoff | 0:086ea145b6d7 | 148 | |
ssozonoff | 0:086ea145b6d7 | 149 | //! This function registers a local variable in the Ishtar library to make it accessible to external clients connected to the server |
ssozonoff | 0:086ea145b6d7 | 150 | ishtar_ServiceId ishtar_Variable(const char* name, void* var, ishtar_ValueVectorType type, ishtar_ValueVectorSize length, ishtar_ServiceFlags flags); |
ssozonoff | 0:086ea145b6d7 | 151 | //! This function registers a local variable in the Ishtar library to make it accessible to external clients connected to the server |
ssozonoff | 0:086ea145b6d7 | 152 | ishtar_ServiceId ishtar_VariableFeedback(const char* name, void* var, ishtar_ValueVectorType type, ishtar_ValueVectorSize length, ishtar_ServiceFlags flags, ishtar_VariableModifiedFunc feedbackFunc); |
ssozonoff | 0:086ea145b6d7 | 153 | //! This function checks treats every packet that arrived since the last call |
ssozonoff | 0:086ea145b6d7 | 154 | void ishtar_Step(); |
ssozonoff | 0:086ea145b6d7 | 155 | |
ssozonoff | 0:086ea145b6d7 | 156 | //! This function should be called each time data bytes are received through communication |
ssozonoff | 0:086ea145b6d7 | 157 | void ishtar_ReceiveData(unsigned char * data, unsigned long len); |
ssozonoff | 0:086ea145b6d7 | 158 | //! This function should be called each time a data byte is received through communication |
ssozonoff | 0:086ea145b6d7 | 159 | void ishtar_ReceiveDataByte(unsigned char c); |
ssozonoff | 0:086ea145b6d7 | 160 | //! This function sends the active snapshot if any, otherwise it does nothing |
ssozonoff | 0:086ea145b6d7 | 161 | void ishtar_Snapshot(); |
ssozonoff | 0:086ea145b6d7 | 162 | |
ssozonoff | 0:086ea145b6d7 | 163 | //! This function reads the values from the memory and assign them to the Ishtar variables |
ssozonoff | 0:086ea145b6d7 | 164 | void ishtar_LoadFromMemory(); |
ssozonoff | 0:086ea145b6d7 | 165 | //! This function writes the values of the Ishtar variables to the memory |
ssozonoff | 0:086ea145b6d7 | 166 | void ishtar_SaveToMemory(); |
ssozonoff | 0:086ea145b6d7 | 167 | |
ssozonoff | 0:086ea145b6d7 | 168 | //! This function returns true if the server already received a Hello message from a client |
ssozonoff | 0:086ea145b6d7 | 169 | unsigned char ishtar_IsConnected(); |
ssozonoff | 0:086ea145b6d7 | 170 | |
ssozonoff | 0:086ea145b6d7 | 171 | //! This funtion returns the number of currently registered variable. |
ssozonoff | 0:086ea145b6d7 | 172 | unsigned short ishtar_ServiceCount(); |
ssozonoff | 0:086ea145b6d7 | 173 | |
ssozonoff | 0:086ea145b6d7 | 174 | #ifdef __cplusplus |
ssozonoff | 0:086ea145b6d7 | 175 | } |
ssozonoff | 0:086ea145b6d7 | 176 | #endif |
ssozonoff | 0:086ea145b6d7 | 177 | |
ssozonoff | 0:086ea145b6d7 | 178 | #endif |