jausPayloadInterface.h 16.7 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
/*****************************************************************************
 *  Copyright (c) 2008, University of Florida
 *  All rights reserved.
 *  
 *  This file is part of OpenJAUS.  OpenJAUS is distributed under the BSD 
 *  license.  See the LICENSE file for details.
 * 
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions 
 *  are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.
 *     * Neither the name of the University of Florida nor the names of its 
 *       contributors may be used to endorse or promote products derived from 
 *       this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
// File Name: jausPayloadInterface.h
//
// Written By: Bob Touchton (btouch AT comcast DOT net)
//
// Version: 3.3.0a
//
// Date: 08/07/08
//
// Description: This file defines the attributes of a ReportPayloadInterfaceMessage support functions

#ifndef REPORT_PAYLOAD_INTERFACE_H
#define REPORT_PAYLOAD_INTERFACE_H

#include "jaus.h"

#define NO_ENUM 	0
#define NO_HMI	 	0
//#define FAILURE 	-1
#define SUCCESS		1
#define FAILURE		0

// Type Codes
#define TYPE_CODE_SHORT			1
#define TYPE_CODE_INTEGER		2
#define TYPE_CODE_LONG			3
#define TYPE_CODE_BYTE			4
#define TYPE_CODE_U_SHORT		5
#define TYPE_CODE_U_INTEGER		6
#define TYPE_CODE_U_LONG		7
#define TYPE_CODE_FLOAT			8
#define TYPE_CODE_DOUBLE		9

#define TYPE_CODE_SCALED_U_BYTE			10
#define TYPE_CODE_SCALED_SHORT			11
#define TYPE_CODE_SCALED_U_SHORT		12
#define TYPE_CODE_SCALED_INTEGER		13
#define TYPE_CODE_SCALED_U_INTEGER		14
#define TYPE_CODE_SCALED_LONG			15
#define TYPE_CODE_SCALED_U_LONG			16

#define TYPE_CODE_ENUM			17
#define TYPE_CODE_BOOLEAN		18
#define TYPE_CODE_STRING		19

#define TYPE_CODE_U_BYTE_TUPLE			20
#define TYPE_CODE_U_SHORT_TUPLE			21
#define TYPE_CODE_U_INTEGER_TUPLE		22

// Presence Vector Bits
#ifndef JAUS_PAYLOAD_INTERFACE_PV
#define JAUS_PAYLOAD_INTERFACE_PV
#define JAUS_PAYLOAD_INTERFACE_PV_HMI_RECOMMENDATION_BIT		0
#define JAUS_PAYLOAD_INTERFACE_PV_HMI_XPOS_BIT		1
#define JAUS_PAYLOAD_INTERFACE_PV_HMI_YPOS_BIT		2
#define JAUS_PAYLOAD_INTERFACE_PV_HMI_WIDTH_BIT		3
#define JAUS_PAYLOAD_INTERFACE_PV_HMI_HEIGHT_BIT	4
#endif

// ************************************************************************************************************************************
//			Report PayloadInterface Support
// ************************************************************************************************************************************

typedef union
{
	JausShort shortValue;
	JausInteger integerValue;
	JausLong longValue;
	JausByte byteValue;
	JausUnsignedShort uShortValue;
	JausUnsignedInteger uIntegerValue;
	JausUnsignedLong uLongValue;
	JausFloat floatValue;
	JausDouble longFloatValue;	
	JausByte enumValue;
	JausBoolean booleanValue;
	struct
	{
		JausUnsignedShort length;
		char * value;
	}string;
	struct
	{
		JausByte one;
		JausByte two;		
	}byteTuple;
	struct
	{
		JausUnsignedShort one;
		JausUnsignedShort two;		
	}shortTuple;
	struct
	{
		JausUnsignedInteger one;
		JausUnsignedInteger two;		
	}integerTuple;
}JausTypeCode;

typedef struct
{
	JausByte presenceVector;	
	JausArray jausCommandInterfaces;		// Dynamic Array of command interfaces
	JausArray jausInformationInterfaces;	// Dynamic Array of information interfaces
}JausPayloadInterfaceStruct;
typedef JausPayloadInterfaceStruct *JausPayloadInterface;

typedef struct
{
	char* commandIdentifier;	// null-terminated string
	JausByte typeCode;				// per TYPE CODE table
	JausByte units;					// per UNITS table
	JausByte blockingFlag;			// 0 for blocking, 1 for non-blocking
	JausTypeCode minValue;					// minimum acceptable value
	JausTypeCode defaultValue;				// default value
	JausTypeCode maxValue;					// maximum acceptable value
	JausUnsignedShort enumerationLength; // length = 0 means no enumeration field; includes NULL character
	char* enumeration;				// enumeration content, comma delimited, NULL terminated
	JausByte hmiRecommendation;		// per HMI table
	JausUnsignedShort hmiRecommendedPositionXPixels;	
	JausUnsignedShort hmiRecommendedPositionYPixels;
	JausUnsignedShort hmiRecommendedPositionWidthPixels;
	JausUnsignedShort hmiRecommendedPositionHeightPixels;
	JausTypeCode currentValue;	// extra field to store the current data value
}JausCommandInterfaceStruct;
typedef JausCommandInterfaceStruct *JausCommandInterface;

typedef struct
{
	char* informationIdentifier;	// null-terminated string
	JausByte commandInterfaceAssociation; // index number of the assoc. command interface, 0 if none
	JausByte typeCode;				// per TYPE CODE table
	JausByte units;					// per UNITS table
	JausTypeCode minValue;					// minimum acceptable value
	JausTypeCode defaultValue;				// default value
	JausTypeCode maxValue;					// maximum acceptable value
	JausUnsignedShort enumerationLength; // length = 0 means no enumeration field; includes NULL character
	char* enumeration;				// enumeration content, comma delimited, NULL terminated
	JausByte hmiRecommendation;		// per HMI table
	JausUnsignedShort hmiRecommendedPositionXPixels;	
	JausUnsignedShort hmiRecommendedPositionYPixels;
	JausUnsignedShort hmiRecommendedPositionWidthPixels;
	JausUnsignedShort hmiRecommendedPositionHeightPixels;
	JausTypeCode currentValue;	// extra field to store the current data value
}JausInformationInterfaceStruct;
typedef JausInformationInterfaceStruct *JausInformationInterface;

// container to support multiple payload data element messages
typedef struct
{
	JausPayloadInterface payloadInterface;
	//JausByte numberInformationInterfaces;	
	JausArray jausPayloadDataElements;	// Dynamic Array of data elements
}JausPayloadDataElementsStruct;
typedef JausPayloadDataElementsStruct *JausPayloadDataElements;

// container to provide a specific payload data element
typedef struct
{
	char* dataElementIdentifier;	// null-terminated string
	JausByte dataElementIndex;
	JausTypeCode Value;
}JausPayloadDataElementStruct;
typedef JausPayloadDataElementStruct *JausPayloadDataElement;


// Command Interface Constructor
JAUS_EXPORT JausCommandInterface jausCommandInterfaceCreate(void);

// Information Interface Constructor
JAUS_EXPORT JausInformationInterface jausInformationInterfaceCreate(void);

// Command Interface Destructor
JAUS_EXPORT void jausCommandInterfaceDestroy(JausCommandInterface commandInterface);

// Information Interface Destructor
JAUS_EXPORT void jausInformationInterfaceDestroy(JausInformationInterface informationInterface);

// Interface Retrievers
JAUS_EXPORT JausCommandInterface jausCommandInterfaceRetrieve(JausPayloadInterface payloadInterface, char* identifier);

JAUS_EXPORT JausInformationInterface jausInformationInterfaceRetrieve(JausPayloadInterface payloadInterface, char* identifier);

// ************************************************************************************************************************************
//			Report PayloadInterface End User Functions
// ************************************************************************************************************************************

// Payload Interface Constructor
JAUS_EXPORT JausPayloadInterface jausPayloadInterfaceCreate(void);

// Payload Interface Destructor
JAUS_EXPORT void jausPayloadInterfaceDestroy(JausPayloadInterface payloadInterface);

// Interface Adders
JAUS_EXPORT JausCommandInterface jausAddNewCommandInterface(JausPayloadInterface payloadInterface, char* identifier, JausByte typeCode);
JAUS_EXPORT JausInformationInterface jausAddNewInformationInterface(JausPayloadInterface payloadInterface, char* identifier, JausByte typeCode);

// Report Payload Interface Message Support Functions

// NOTE: this function assumes end user is starting their index at 1, iaw the numbering scheme in the JAUS OPC ICD
JAUS_EXPORT char* jausGetCommandInterfaceIdentifierByIndex(JausPayloadInterface payloadInterface, int index, int* successFlag);

JAUS_EXPORT char* jausGetInformationInterfaceIdentifierByIndex(JausPayloadInterface payloadInterface, int index, int* successFlag);

JAUS_EXPORT JausByte jausGetCommandInterfaceTypeCode(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausByte jausGetInformationInterfaceTypeCode(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetCommandInterfaceUnits(JausPayloadInterface payloadInterface, char* identifier, JausByte units);

JAUS_EXPORT JausByte jausGetCommandInterfaceUnits(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetCommandInterfaceBlockingFlag(JausPayloadInterface payloadInterface, char* identifier);

JAUS_EXPORT JausBoolean jausClearCommandInterfaceBlockingFlag(JausPayloadInterface payloadInterface, char* identifier);

JAUS_EXPORT JausBoolean jausGetCommandInterfaceBlockingFlag(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetCommandInterfaceMinMax(JausPayloadInterface payloadInterface, char* identifier, JausTypeCode minValue, JausTypeCode maxValue);

JAUS_EXPORT JausTypeCode jausGetCommandInterfaceMin(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausTypeCode jausGetCommandInterfaceMax(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetCommandInterfaceDefault(JausPayloadInterface payloadInterface, char* identifier, JausTypeCode defaultValue);

JAUS_EXPORT JausTypeCode jausGetCommandInterfaceDefault(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetCommandInterfaceEnumeration(JausPayloadInterface payloadInterface, char* identifier, char* enumeration);

JAUS_EXPORT char* jausGetCommandInterfaceEnumeration(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetCommandInterfaceEnumerationLength(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetCommandInterfaceHmiRecommendation(JausPayloadInterface payloadInterface, char* identifier, JausByte hmiRecommendation);

JAUS_EXPORT JausByte jausGetCommandInterfaceHmiRecommendation(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

// NOTE: recommended HMI positioning must be set as a group
JAUS_EXPORT JausBoolean jausSetCommandInterfaceHmiParameters(JausPayloadInterface payloadInterface, char* identifier, JausUnsignedShort xPixels, JausUnsignedShort yPixels, JausUnsignedShort widthPixels, JausUnsignedShort heightPixels);

JAUS_EXPORT JausUnsignedShort jausGetCommandInterfaceHmiXPositionPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetCommandInterfaceHmiYPositionPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetCommandInterfaceHmiWidthPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetCommandInterfaceHmiHeightPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetInformationInterfaceUnits(JausPayloadInterface payloadInterface, char* identifier, JausByte units);

JAUS_EXPORT JausByte jausGetInformationInterfaceUnits(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetInformationInterfaceCommandInterfaceAssoc(JausPayloadInterface payloadInterface, char* identifier, JausByte commandInterfaceAssociation);

JAUS_EXPORT JausByte jausGetInformationInterfaceCommandInterfaceAssoc(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetInformationInterfaceMinMax(JausPayloadInterface payloadInterface, char* identifier, JausTypeCode minValue, JausTypeCode maxValue);

JAUS_EXPORT JausTypeCode jausGetInformationInterfaceMin(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausTypeCode jausGetInformationInterfaceMax(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetInformationInterfaceDefault(JausPayloadInterface payloadInterface, char* identifier, JausTypeCode defaultValue);

JAUS_EXPORT JausTypeCode jausGetInformationInterfaceDefault(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetInformationInterfaceEnumeration(JausPayloadInterface payloadInterface, char* identifier, char* enumeration);

JAUS_EXPORT char* jausGetInformationInterfaceEnumeration(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetInformationInterfaceEnumerationLength(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausBoolean jausSetInformationInterfaceHmiRecommendation(JausPayloadInterface payloadInterface, char* identifier, JausByte hmiRecommendation);

JAUS_EXPORT JausByte jausGetInformationInterfaceHmiRecommendation(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

// NOTE: recommended HMI positioning must be set as a group
JAUS_EXPORT JausBoolean jausSetInformationInterfaceHmiParameters(JausPayloadInterface payloadInterface, char* identifier, JausUnsignedShort xPixels, JausUnsignedShort yPixels, JausUnsignedShort widthPixels, JausUnsignedShort heightPixels);

JAUS_EXPORT JausUnsignedShort jausGetInformationInterfaceHmiXPositionPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetInformationInterfaceHmiYPositionPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetInformationInterfaceHmiWidthPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

JAUS_EXPORT JausUnsignedShort jausGetInformationInterfaceHmiHeightPixels(JausPayloadInterface payloadInterface, char* identifier, int* successFlag);

// decodes the Type Code value and returns the number of bytes required 
JAUS_EXPORT int jausMinMaxDefaultSizeBytes(JausByte typeCodeEnum);
JAUS_EXPORT int jausCommandValueSizeBytes(JausCommandInterface commandInterface);
JAUS_EXPORT int jausInformationValueSizeBytes(JausInformationInterface informationInterface);

// determines how to pack fields that have a JausTypeCode data type
JAUS_EXPORT int jausMinMaxDefaultToBuffer(JausTypeCode field, unsigned char* buffer, unsigned int bufferSizeBytes, JausByte typeCodeEnum);
JAUS_EXPORT int jausInformationValueToBuffer(JausInformationInterface informationInterface, unsigned char* buffer, unsigned int bufferSizeBytes);
JAUS_EXPORT int jausCommandValueToBuffer(JausCommandInterface commandInterface, unsigned char* buffer, unsigned int bufferSizeBytes);

// determines how to unpack fields that have a JausTypeCode data type
JAUS_EXPORT JausBoolean jausMinMaxDefaultFromBuffer(JausTypeCode *field, unsigned char* buffer, unsigned int bufferSizeBytes, JausByte typeCodeEnum);
JAUS_EXPORT JausBoolean jausInformationValueFromBuffer(JausInformationInterface informationInterface, unsigned char* buffer, unsigned int bufferSizeBytes);
JAUS_EXPORT JausBoolean jausCommandValueFromBuffer(JausCommandInterface commandInterface, unsigned char* buffer, unsigned int bufferSizeBytes);

#endif