Axeda demo software for u-blox C027 (GSM)

Dependencies:   mbed

Committer:
AxedaCorp
Date:
Mon Aug 11 19:02:42 2014 +0000
Revision:
0:a725e8eab383
1st commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AxedaCorp 0:a725e8eab383 1 /************************************************************************************/
AxedaCorp 0:a725e8eab383 2 /* axDomain.c */
AxedaCorp 0:a725e8eab383 3 /* �2013 Axeda Corporation */
AxedaCorp 0:a725e8eab383 4 /* */
AxedaCorp 0:a725e8eab383 5 /* Defines methods for creation and interaction with Axeda domain constructs. This */
AxedaCorp 0:a725e8eab383 6 /* is a device independent implementation which can be applied to any device that */
AxedaCorp 0:a725e8eab383 7 /* supports ANSI C. */
AxedaCorp 0:a725e8eab383 8 /************************************************************************************/
AxedaCorp 0:a725e8eab383 9 #include "axDomain.h"
AxedaCorp 0:a725e8eab383 10 #include "string.h"
AxedaCorp 0:a725e8eab383 11 #include "axSettings.h"
AxedaCorp 0:a725e8eab383 12 #include <stdlib.h>
AxedaCorp 0:a725e8eab383 13 #include <stdio.h>
AxedaCorp 0:a725e8eab383 14
AxedaCorp 0:a725e8eab383 15
AxedaCorp 0:a725e8eab383 16
AxedaCorp 0:a725e8eab383 17 /************************************************************************************/
AxedaCorp 0:a725e8eab383 18 /* createAlarm() */
AxedaCorp 0:a725e8eab383 19 /* */
AxedaCorp 0:a725e8eab383 20 /* Stores the supplied values into the structure pointed to by alm. */
AxedaCorp 0:a725e8eab383 21 /* */
AxedaCorp 0:a725e8eab383 22 /* alm(required) : a pointer to an empty alarm structure */
AxedaCorp 0:a725e8eab383 23 /* name(required) : the name of the alarm */
AxedaCorp 0:a725e8eab383 24 /* description(required) : a more detailed account of the alarm */
AxedaCorp 0:a725e8eab383 25 /* severity(required) : a numerical value from 0-1000, with 1000 being the highest */
AxedaCorp 0:a725e8eab383 26 /* dataItem(optional) : a pointer to a dataItem structure containing the data item */
AxedaCorp 0:a725e8eab383 27 /* that triggered this alarm. Use NULL for a generic alarm. */
AxedaCorp 0:a725e8eab383 28 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARG_NULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 29 /************************************************************************************/
AxedaCorp 0:a725e8eab383 30 int ax_data_createAlarm(ax_alarm *alm, char *alName, char *alDescription, int alSeverity, char *cause, char *reason, int timeOccured, int priority)
AxedaCorp 0:a725e8eab383 31 {
AxedaCorp 0:a725e8eab383 32 int retVal=AX_OK;
AxedaCorp 0:a725e8eab383 33 if((alSeverity <0)||(alSeverity>1000))
AxedaCorp 0:a725e8eab383 34 {
AxedaCorp 0:a725e8eab383 35 return AX_OUT_OF_RANGE;
AxedaCorp 0:a725e8eab383 36 }
AxedaCorp 0:a725e8eab383 37 if((!alm)||(!alName)||(!alDescription))
AxedaCorp 0:a725e8eab383 38 {
AxedaCorp 0:a725e8eab383 39 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 40 }
AxedaCorp 0:a725e8eab383 41 if(strlen(alName)<=0) {
AxedaCorp 0:a725e8eab383 42 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 43 }
AxedaCorp 0:a725e8eab383 44
AxedaCorp 0:a725e8eab383 45 snprintf(alm->alarmName, AX_ALM_NAME_S, alName);
AxedaCorp 0:a725e8eab383 46 if(strlen(alName)>AX_ALM_NAME_S){
AxedaCorp 0:a725e8eab383 47 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 48 }
AxedaCorp 0:a725e8eab383 49
AxedaCorp 0:a725e8eab383 50 snprintf(alm->alarmDescription, AX_ALM_DESC_S, alDescription);
AxedaCorp 0:a725e8eab383 51 if(strlen(alDescription)> AX_ALM_DESC_S) {
AxedaCorp 0:a725e8eab383 52 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 53 }
AxedaCorp 0:a725e8eab383 54
AxedaCorp 0:a725e8eab383 55 snprintf(alm->alarmCause, AX_ALM_CAUSE_S, cause);
AxedaCorp 0:a725e8eab383 56 if(strlen(cause)>AX_ALM_CAUSE_S) {
AxedaCorp 0:a725e8eab383 57 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 58 }
AxedaCorp 0:a725e8eab383 59
AxedaCorp 0:a725e8eab383 60 snprintf(alm->alarmReason, AX_ALM_REAS_S, reason);
AxedaCorp 0:a725e8eab383 61 if(strlen(reason)>AX_ALM_REAS_S){
AxedaCorp 0:a725e8eab383 62 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 63 }
AxedaCorp 0:a725e8eab383 64
AxedaCorp 0:a725e8eab383 65 alm->alarmSeverity=alSeverity;
AxedaCorp 0:a725e8eab383 66 alm->dateAcquired=timeOccured;
AxedaCorp 0:a725e8eab383 67 alm->priority=priority;
AxedaCorp 0:a725e8eab383 68
AxedaCorp 0:a725e8eab383 69 return retVal;
AxedaCorp 0:a725e8eab383 70 }
AxedaCorp 0:a725e8eab383 71
AxedaCorp 0:a725e8eab383 72 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 73 /* createDataItem() */
AxedaCorp 0:a725e8eab383 74 /* */
AxedaCorp 0:a725e8eab383 75 /* This function will store information about a dataItem into a structure supplied */
AxedaCorp 0:a725e8eab383 76 /* by the calling method. There are traditionally 3 types of data Items, analog, */
AxedaCorp 0:a725e8eab383 77 /* string and digital. */
AxedaCorp 0:a725e8eab383 78 /* */
AxedaCorp 0:a725e8eab383 79 /* destDI(required) : A pointer to the structure where the data will be stored */
AxedaCorp 0:a725e8eab383 80 /* diName(required) : A character array containing the name of the data item */
AxedaCorp 0:a725e8eab383 81 /* diType(required) : A integer value indicating the data Item type. Can be */
AxedaCorp 0:a725e8eab383 82 /* AX_STRING, AX_DIGITAL, AX_ANALOG */
AxedaCorp 0:a725e8eab383 83 /* stringValue(optional): If the type is AX_STRING, this value MUST be populated or */
AxedaCorp 0:a725e8eab383 84 /* an error will be returned. This is the value of the */
AxedaCorp 0:a725e8eab383 85 /* dataItem. If it is a String use zero for the numericValue */
AxedaCorp 0:a725e8eab383 86 /* numericValue(optional): If the type is AX_ANALOG or AX_DIGITAL this value MUST be */
AxedaCorp 0:a725e8eab383 87 /* provided or an error will be returned. For AX_ANALOG di's */
AxedaCorp 0:a725e8eab383 88 /* this value can be any numeric value within language */
AxedaCorp 0:a725e8eab383 89 /* constraints. For AX_DIGITAL, this value must be 1 or 0. */
AxedaCorp 0:a725e8eab383 90 /* 1 will be considered true and 0 will be considered false. */
AxedaCorp 0:a725e8eab383 91 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 92 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */
AxedaCorp 0:a725e8eab383 93 /************************************************************************************/
AxedaCorp 0:a725e8eab383 94 int ax_data_createDataItem(ax_dataSet *destDI, char *diName, int diType, char *stringValue, double numericValue, int timeAcquired, int priority) {
AxedaCorp 0:a725e8eab383 95 int retVal=AX_UNKNOWN;
AxedaCorp 0:a725e8eab383 96 if(!destDI) { return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 97 if(!diName) {return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 98 if((diType>3)&&(diType<1)) {return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 99 if(timeAcquired<0) {return AX_OUT_OF_RANGE; }
AxedaCorp 0:a725e8eab383 100 if((priority<-1)||(priority>100)) { return AX_OUT_OF_RANGE; }
AxedaCorp 0:a725e8eab383 101 if(destDI->created!=AX_TRUE) {
AxedaCorp 0:a725e8eab383 102 retVal=ax_data_createSet(destDI, timeAcquired, priority);
AxedaCorp 0:a725e8eab383 103 if(retVal!=AX_OK) { return retVal; }
AxedaCorp 0:a725e8eab383 104 }
AxedaCorp 0:a725e8eab383 105
AxedaCorp 0:a725e8eab383 106 retVal=ax_data_addToSet(destDI, diName, diType, stringValue, numericValue);
AxedaCorp 0:a725e8eab383 107
AxedaCorp 0:a725e8eab383 108 return retVal;
AxedaCorp 0:a725e8eab383 109 }
AxedaCorp 0:a725e8eab383 110 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 111 /* createAnalogDataItem() */
AxedaCorp 0:a725e8eab383 112 /* */
AxedaCorp 0:a725e8eab383 113 /* This function will store information about a dataItem into a structure supplied */
AxedaCorp 0:a725e8eab383 114 /* by the calling method. This is a special case of the ax_data_createDataItem() call*/
AxedaCorp 0:a725e8eab383 115 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 116 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */
AxedaCorp 0:a725e8eab383 117 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 118 int ax_data_createAnalogDataItem(ax_dataSet *destDI, char *diName, double value, int timeAcquired, int priority) {
AxedaCorp 0:a725e8eab383 119 return ax_data_createDataItem(destDI, diName, AX_ANALOG, NULL, value, timeAcquired, priority);
AxedaCorp 0:a725e8eab383 120 }
AxedaCorp 0:a725e8eab383 121
AxedaCorp 0:a725e8eab383 122 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 123 /* createDigitalDataItem() */
AxedaCorp 0:a725e8eab383 124 /* */
AxedaCorp 0:a725e8eab383 125 /* This function will store information about a dataItem into a structure supplied */
AxedaCorp 0:a725e8eab383 126 /* by the calling method. There are traditionally 3 types of data Items, analog, */
AxedaCorp 0:a725e8eab383 127 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 128 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */
AxedaCorp 0:a725e8eab383 129 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 130 int ax_data_createDigitalDataItem(ax_dataSet *destDI, char *diName, double value, int timeAcquired, int priority) {
AxedaCorp 0:a725e8eab383 131 return ax_data_createDataItem(destDI, diName, AX_DIGITAL, NULL, value, timeAcquired, priority);
AxedaCorp 0:a725e8eab383 132 }
AxedaCorp 0:a725e8eab383 133
AxedaCorp 0:a725e8eab383 134 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 135 /* createDataItem() */
AxedaCorp 0:a725e8eab383 136 /* */
AxedaCorp 0:a725e8eab383 137 /* This function will store information about a dataItem into a structure supplied */
AxedaCorp 0:a725e8eab383 138 /* by the calling method. There are traditionally 3 types of data Items, analog, */
AxedaCorp 0:a725e8eab383 139 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 140 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */
AxedaCorp 0:a725e8eab383 141 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 142 int ax_data_createStringDataItem(ax_dataSet *destDI, char *diName, char *value, int timeAcquired, int priority) {
AxedaCorp 0:a725e8eab383 143 return ax_data_createDataItem(destDI, diName, AX_STRING, value, -1, timeAcquired, priority);
AxedaCorp 0:a725e8eab383 144 }
AxedaCorp 0:a725e8eab383 145
AxedaCorp 0:a725e8eab383 146 /************************************************************************************/
AxedaCorp 0:a725e8eab383 147 /*ax_data_createSet() */
AxedaCorp 0:a725e8eab383 148 /* */
AxedaCorp 0:a725e8eab383 149 /*Creates and populates a dataSet struct pointed to by the *set parameter. A dataSet*/
AxedaCorp 0:a725e8eab383 150 /*can have multiple data items added by the ax_data_addToSet() method. */
AxedaCorp 0:a725e8eab383 151 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 152 /************************************************************************************/
AxedaCorp 0:a725e8eab383 153 int ax_data_createSet(ax_dataSet *set, int acquisitionTime, int priority) {
AxedaCorp 0:a725e8eab383 154
AxedaCorp 0:a725e8eab383 155 if(!set) { return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 156 if((priority<-1)||(priority>100)) { return AX_OUT_OF_RANGE; }
AxedaCorp 0:a725e8eab383 157 if(acquisitionTime<0) {return AX_OUT_OF_RANGE; }
AxedaCorp 0:a725e8eab383 158 set->dataNode_ct=0;
AxedaCorp 0:a725e8eab383 159 set->data_first=NULL;
AxedaCorp 0:a725e8eab383 160 set->data_last=NULL;
AxedaCorp 0:a725e8eab383 161
AxedaCorp 0:a725e8eab383 162 if(acquisitionTime >=0) {
AxedaCorp 0:a725e8eab383 163 set->acquisitionTime=acquisitionTime;
AxedaCorp 0:a725e8eab383 164 }
AxedaCorp 0:a725e8eab383 165 else {
AxedaCorp 0:a725e8eab383 166 set->acquisitionTime=-1;
AxedaCorp 0:a725e8eab383 167 }
AxedaCorp 0:a725e8eab383 168 if((priority >=1)&&(priority<=100)) {
AxedaCorp 0:a725e8eab383 169 set->priority=priority;
AxedaCorp 0:a725e8eab383 170 }
AxedaCorp 0:a725e8eab383 171 else {
AxedaCorp 0:a725e8eab383 172 set->priority=AX_NO_PRIORITY;
AxedaCorp 0:a725e8eab383 173 }
AxedaCorp 0:a725e8eab383 174
AxedaCorp 0:a725e8eab383 175 set->created=AX_TRUE;
AxedaCorp 0:a725e8eab383 176 return AX_OK;
AxedaCorp 0:a725e8eab383 177 }
AxedaCorp 0:a725e8eab383 178 /************************************************************************************/
AxedaCorp 0:a725e8eab383 179 /*ax_data_addToSet() */
AxedaCorp 0:a725e8eab383 180 /* */
AxedaCorp 0:a725e8eab383 181 /*Adds data to a preExisting data set. Data is represented as a linked list and */
AxedaCorp 0:a725e8eab383 182 /*pointed to by a dataSet structure. Adding data to with this method will cause the */
AxedaCorp 0:a725e8eab383 183 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/
AxedaCorp 0:a725e8eab383 184 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */
AxedaCorp 0:a725e8eab383 185 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 186 /* AX_DI_UNKNOWN_TYPE */
AxedaCorp 0:a725e8eab383 187 /************************************************************************************/
AxedaCorp 0:a725e8eab383 188 int ax_data_addToSet(ax_dataSet *set, char *diName, int diType, char *stringValue, double numericValue){
AxedaCorp 0:a725e8eab383 189 ax_dataNode *newNode, *temp=NULL;
AxedaCorp 0:a725e8eab383 190 int retVal=AX_UNKNOWN;
AxedaCorp 0:a725e8eab383 191
AxedaCorp 0:a725e8eab383 192 if((diType<1)||(diType>3)){
AxedaCorp 0:a725e8eab383 193 return AX_DI_UNKNOWN_TYPE;
AxedaCorp 0:a725e8eab383 194 }
AxedaCorp 0:a725e8eab383 195
AxedaCorp 0:a725e8eab383 196 if((!set)||(!diName)){
AxedaCorp 0:a725e8eab383 197 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 198 }
AxedaCorp 0:a725e8eab383 199
AxedaCorp 0:a725e8eab383 200 if((diType==AX_STRING)&&(!stringValue)){
AxedaCorp 0:a725e8eab383 201 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 202 }
AxedaCorp 0:a725e8eab383 203 if((diType==AX_DIGITAL)&&((numericValue<0)||(numericValue>1))){
AxedaCorp 0:a725e8eab383 204 return AX_OUT_OF_RANGE;
AxedaCorp 0:a725e8eab383 205 }
AxedaCorp 0:a725e8eab383 206 //if you didn't create the data set with the function this will make sure the linked list values are set. It MAY overwrite the time and priority if they are already set.
AxedaCorp 0:a725e8eab383 207 if(set->created!=AX_TRUE) { ax_data_createSet(set, 0, AX_NO_PRIORITY); }
AxedaCorp 0:a725e8eab383 208
AxedaCorp 0:a725e8eab383 209 newNode=(ax_dataNode*)malloc(sizeof(ax_dataNode));
AxedaCorp 0:a725e8eab383 210
AxedaCorp 0:a725e8eab383 211 retVal=AX_OK;
AxedaCorp 0:a725e8eab383 212 snprintf(newNode->name, AX_DN_NAME_S, diName);
AxedaCorp 0:a725e8eab383 213 if(strlen(diName)>AX_DN_NAME_S) {
AxedaCorp 0:a725e8eab383 214 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 215 }
AxedaCorp 0:a725e8eab383 216
AxedaCorp 0:a725e8eab383 217 newNode->next=NULL;
AxedaCorp 0:a725e8eab383 218 newNode->type=diType;
AxedaCorp 0:a725e8eab383 219 if(diType==AX_STRING) {
AxedaCorp 0:a725e8eab383 220 snprintf(newNode->sValue, AX_DN_SV_S, stringValue);
AxedaCorp 0:a725e8eab383 221 if(strlen(stringValue)>AX_DN_SV_S) {
AxedaCorp 0:a725e8eab383 222 retVal=AX_GEN_STR_TRUNC; // if the requested value was too large, set a warning to let us know it was truncated
AxedaCorp 0:a725e8eab383 223 }
AxedaCorp 0:a725e8eab383 224 }
AxedaCorp 0:a725e8eab383 225 else {
AxedaCorp 0:a725e8eab383 226 newNode->dValue=numericValue;
AxedaCorp 0:a725e8eab383 227 }
AxedaCorp 0:a725e8eab383 228
AxedaCorp 0:a725e8eab383 229 if(set->data_first==NULL) {
AxedaCorp 0:a725e8eab383 230 set->data_first=newNode;
AxedaCorp 0:a725e8eab383 231 }
AxedaCorp 0:a725e8eab383 232
AxedaCorp 0:a725e8eab383 233 if(set->data_last!=NULL) {
AxedaCorp 0:a725e8eab383 234 temp=set->data_last;
AxedaCorp 0:a725e8eab383 235 temp->next=(ax_dataNode *)newNode;
AxedaCorp 0:a725e8eab383 236 }
AxedaCorp 0:a725e8eab383 237
AxedaCorp 0:a725e8eab383 238
AxedaCorp 0:a725e8eab383 239 set->data_last=newNode;
AxedaCorp 0:a725e8eab383 240 int nodect=set->dataNode_ct;
AxedaCorp 0:a725e8eab383 241 nodect++;
AxedaCorp 0:a725e8eab383 242 set->dataNode_ct=nodect;
AxedaCorp 0:a725e8eab383 243
AxedaCorp 0:a725e8eab383 244 return retVal;
AxedaCorp 0:a725e8eab383 245 }
AxedaCorp 0:a725e8eab383 246 /************************************************************************************/
AxedaCorp 0:a725e8eab383 247 /*ax_data_addStringToSet() */
AxedaCorp 0:a725e8eab383 248 /* */
AxedaCorp 0:a725e8eab383 249 /*Adds data to a preExisting data set. Data is represented as a linked list and */
AxedaCorp 0:a725e8eab383 250 /*pointed to by a dataSet structure. Adding data to with this method will cause the */
AxedaCorp 0:a725e8eab383 251 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/
AxedaCorp 0:a725e8eab383 252 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */
AxedaCorp 0:a725e8eab383 253 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 254 /************************************************************************************/
AxedaCorp 0:a725e8eab383 255 int ax_data_addStringToSet(ax_dataSet *set, char *diName, char *value) {
AxedaCorp 0:a725e8eab383 256 return ax_data_addToSet(set, diName, AX_STRING, value, -1);
AxedaCorp 0:a725e8eab383 257 }
AxedaCorp 0:a725e8eab383 258 /************************************************************************************/
AxedaCorp 0:a725e8eab383 259 /*ax_data_addAnalogToSet() */
AxedaCorp 0:a725e8eab383 260 /* */
AxedaCorp 0:a725e8eab383 261 /*Adds data to a preExisting data set. Data is represented as a linked list and */
AxedaCorp 0:a725e8eab383 262 /*pointed to by a dataSet structure. Adding data to with this method will cause the */
AxedaCorp 0:a725e8eab383 263 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/
AxedaCorp 0:a725e8eab383 264 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */
AxedaCorp 0:a725e8eab383 265 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_OK */
AxedaCorp 0:a725e8eab383 266 /************************************************************************************/
AxedaCorp 0:a725e8eab383 267 int ax_data_addAnalogToSet(ax_dataSet *set, char *diName, double value){
AxedaCorp 0:a725e8eab383 268 return ax_data_addToSet(set, diName, AX_ANALOG, NULL, value);
AxedaCorp 0:a725e8eab383 269 }
AxedaCorp 0:a725e8eab383 270 /************************************************************************************/
AxedaCorp 0:a725e8eab383 271 /*ax_data_addDigitalToSet() */
AxedaCorp 0:a725e8eab383 272 /* */
AxedaCorp 0:a725e8eab383 273 /*Adds data to a preExisting data set. Data is represented as a linked list and */
AxedaCorp 0:a725e8eab383 274 /*pointed to by a dataSet structure. Adding data to with this method will cause the */
AxedaCorp 0:a725e8eab383 275 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/
AxedaCorp 0:a725e8eab383 276 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */
AxedaCorp 0:a725e8eab383 277 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_OK */
AxedaCorp 0:a725e8eab383 278 /************************************************************************************/
AxedaCorp 0:a725e8eab383 279 int ax_data_addDigitalToSet(ax_dataSet *set, char *diName, double value) {
AxedaCorp 0:a725e8eab383 280 return ax_data_addToSet(set, diName, AX_DIGITAL, NULL, value);
AxedaCorp 0:a725e8eab383 281 }
AxedaCorp 0:a725e8eab383 282
AxedaCorp 0:a725e8eab383 283
AxedaCorp 0:a725e8eab383 284 /************************************************************************************/
AxedaCorp 0:a725e8eab383 285 /*ax_data_destroySet() */
AxedaCorp 0:a725e8eab383 286 /* */
AxedaCorp 0:a725e8eab383 287 /*Iterates through all data items in a dataset and frees them. This assumes all nodes*/
AxedaCorp 0:a725e8eab383 288 /*have been allocated by malloc.If the addToSet() function was being used then that */
AxedaCorp 0:a725e8eab383 289 /*will be true. */
AxedaCorp 0:a725e8eab383 290 /*Possible Return Codes: AX_OK AX_ARGNULL */
AxedaCorp 0:a725e8eab383 291 /************************************************************************************/
AxedaCorp 0:a725e8eab383 292 int ax_data_destroySet(ax_dataSet *set) {
AxedaCorp 0:a725e8eab383 293
AxedaCorp 0:a725e8eab383 294 if(set!=NULL) {
AxedaCorp 0:a725e8eab383 295 ax_dataNode *curr=set->data_first, *next;
AxedaCorp 0:a725e8eab383 296 int ctr;
AxedaCorp 0:a725e8eab383 297 for(ctr=0; ctr<set->dataNode_ct; ctr++)
AxedaCorp 0:a725e8eab383 298 {
AxedaCorp 0:a725e8eab383 299 next=(ax_dataNode *)curr->next;
AxedaCorp 0:a725e8eab383 300 free(curr);
AxedaCorp 0:a725e8eab383 301 curr=next;
AxedaCorp 0:a725e8eab383 302 next=NULL; // CYA'ing here
AxedaCorp 0:a725e8eab383 303 }
AxedaCorp 0:a725e8eab383 304 set->data_first=NULL;
AxedaCorp 0:a725e8eab383 305 set->data_last=NULL;
AxedaCorp 0:a725e8eab383 306 }
AxedaCorp 0:a725e8eab383 307 else {
AxedaCorp 0:a725e8eab383 308 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 309 }
AxedaCorp 0:a725e8eab383 310
AxedaCorp 0:a725e8eab383 311 return AX_OK;
AxedaCorp 0:a725e8eab383 312 }
AxedaCorp 0:a725e8eab383 313
AxedaCorp 0:a725e8eab383 314
AxedaCorp 0:a725e8eab383 315 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 316 /* createEvent() */
AxedaCorp 0:a725e8eab383 317 /* */
AxedaCorp 0:a725e8eab383 318 /* This function will populate an event structure and check the values to ensure they*/
AxedaCorp 0:a725e8eab383 319 /* are within protocol limit */
AxedaCorp 0:a725e8eab383 320 /* Possible Return Codes: AX_ARGNULL, AX_GEN_STR_TRUNC */
AxedaCorp 0:a725e8eab383 321 /************************************************************************************/
AxedaCorp 0:a725e8eab383 322 int ax_data_createEvent(ax_event *evt, char *name, char *description, int timeOccured, int priority)
AxedaCorp 0:a725e8eab383 323 {
AxedaCorp 0:a725e8eab383 324 int retVal=AX_OK;
AxedaCorp 0:a725e8eab383 325 if((!evt)||(!name)||(!description)){
AxedaCorp 0:a725e8eab383 326 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 327 }
AxedaCorp 0:a725e8eab383 328 if((priority<-1)||(priority>100)) {return AX_OUT_OF_RANGE; }
AxedaCorp 0:a725e8eab383 329
AxedaCorp 0:a725e8eab383 330 snprintf(evt->name,AX_EVT_NAME_S, name);
AxedaCorp 0:a725e8eab383 331 if(strlen(name)>AX_EVT_NAME_S) {
AxedaCorp 0:a725e8eab383 332 retVal= AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 333 }
AxedaCorp 0:a725e8eab383 334
AxedaCorp 0:a725e8eab383 335 snprintf(evt->description, AX_EVT_DESC_S, description);
AxedaCorp 0:a725e8eab383 336 if(strlen(description)>AX_EVT_DESC_S) {
AxedaCorp 0:a725e8eab383 337 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 338 }
AxedaCorp 0:a725e8eab383 339
AxedaCorp 0:a725e8eab383 340 evt->dateAcquired=timeOccured;
AxedaCorp 0:a725e8eab383 341 evt->priority=priority;
AxedaCorp 0:a725e8eab383 342 return retVal;
AxedaCorp 0:a725e8eab383 343 }
AxedaCorp 0:a725e8eab383 344
AxedaCorp 0:a725e8eab383 345
AxedaCorp 0:a725e8eab383 346
AxedaCorp 0:a725e8eab383 347
AxedaCorp 0:a725e8eab383 348 /************************************************************************************/
AxedaCorp 0:a725e8eab383 349 /* createLocation() */
AxedaCorp 0:a725e8eab383 350 /* */
AxedaCorp 0:a725e8eab383 351 /* This function will populate a location structure storing the current location */
AxedaCorp 0:a725e8eab383 352 /* */
AxedaCorp 0:a725e8eab383 353 /* loc (required) : A structure that will be populated with the data */
AxedaCorp 0:a725e8eab383 354 /* lat (required) : A number between 90 and -90 representing the degrees latitude. */
AxedaCorp 0:a725e8eab383 355 /* lon (required) : A number between 180 and -180 representing the degrees longitude*/
AxedaCorp 0:a725e8eab383 356 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_OK */
AxedaCorp 0:a725e8eab383 357 /************************************************************************************/
AxedaCorp 0:a725e8eab383 358 int ax_data_createLocation(ax_location *loc, double lat, double lon, double alt, int timeAcquired, int priority){
AxedaCorp 0:a725e8eab383 359 if(!loc){
AxedaCorp 0:a725e8eab383 360 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 361 }
AxedaCorp 0:a725e8eab383 362
AxedaCorp 0:a725e8eab383 363 if((lat>90)||(lat<-90)){
AxedaCorp 0:a725e8eab383 364 return AX_OUT_OF_RANGE;
AxedaCorp 0:a725e8eab383 365 }
AxedaCorp 0:a725e8eab383 366
AxedaCorp 0:a725e8eab383 367 if((lon>180)||(lon<-180)){
AxedaCorp 0:a725e8eab383 368 return AX_OUT_OF_RANGE;
AxedaCorp 0:a725e8eab383 369 }
AxedaCorp 0:a725e8eab383 370
AxedaCorp 0:a725e8eab383 371
AxedaCorp 0:a725e8eab383 372 loc->latitude=lat;
AxedaCorp 0:a725e8eab383 373 loc->longitude=lon;
AxedaCorp 0:a725e8eab383 374 loc->altitude=alt;
AxedaCorp 0:a725e8eab383 375
AxedaCorp 0:a725e8eab383 376 loc->dateAcquired=timeAcquired;
AxedaCorp 0:a725e8eab383 377 loc->priority=priority;
AxedaCorp 0:a725e8eab383 378 return AX_OK;
AxedaCorp 0:a725e8eab383 379 }
AxedaCorp 0:a725e8eab383 380
AxedaCorp 0:a725e8eab383 381 /************************************************************************************/
AxedaCorp 0:a725e8eab383 382 /* createModelSerialDeviceId() */
AxedaCorp 0:a725e8eab383 383 /* */
AxedaCorp 0:a725e8eab383 384 /* This function will populate a structure that stores data about the device's iden-*/
AxedaCorp 0:a725e8eab383 385 /* tification. The Axeda platform allows for multiple ways of identifying a device. */
AxedaCorp 0:a725e8eab383 386 /* */
AxedaCorp 0:a725e8eab383 387 /* device(required) : a pointer to a structure where the data will be stored */
AxedaCorp 0:a725e8eab383 388 /* model (required) : A model number that describes a particular family of device. */
AxedaCorp 0:a725e8eab383 389 /* If this were describing a car it could be a Ford_Mustang */
AxedaCorp 0:a725e8eab383 390 /* serial (required) : A unique Identifier for the device. If it was a car it would */
AxedaCorp 0:a725e8eab383 391 /* be analagous to the VIN number. */
AxedaCorp 0:a725e8eab383 392 /* tenant (optional) : The identifier of the Axeda tenant instance. Not currently */
AxedaCorp 0:a725e8eab383 393 /* used and should always default to zero. */
AxedaCorp 0:a725e8eab383 394 /* Possible Return Codes: AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 395 /************************************************************************************/
AxedaCorp 0:a725e8eab383 396
AxedaCorp 0:a725e8eab383 397 int ax_data_createModelSerialDeviceId(ax_deviceID *device, char *model, char *serial, char *tenant) {
AxedaCorp 0:a725e8eab383 398 int retVal=AX_OK;
AxedaCorp 0:a725e8eab383 399 if((!device)||(!model)||(!serial)){
AxedaCorp 0:a725e8eab383 400 return AX_ARGNULL;
AxedaCorp 0:a725e8eab383 401 }
AxedaCorp 0:a725e8eab383 402 snprintf(device->model, AX_MSID_MDL_S, model);
AxedaCorp 0:a725e8eab383 403 if(strlen(model)> AX_MSID_MDL_S) {
AxedaCorp 0:a725e8eab383 404 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 405 }
AxedaCorp 0:a725e8eab383 406
AxedaCorp 0:a725e8eab383 407 snprintf(device->serial, AX_MSID_SER_S, serial);
AxedaCorp 0:a725e8eab383 408 if(strlen(serial)>AX_MSID_SER_S) {
AxedaCorp 0:a725e8eab383 409 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 410 }
AxedaCorp 0:a725e8eab383 411
AxedaCorp 0:a725e8eab383 412 memset(device->tenant, '\0', AX_MSID_TEN_S);
AxedaCorp 0:a725e8eab383 413 if(tenant!=NULL) {
AxedaCorp 0:a725e8eab383 414 snprintf(device->tenant, AX_MSID_TEN_S, "%s", tenant);
AxedaCorp 0:a725e8eab383 415 if(strlen(tenant)>AX_MSID_TEN_S) { retVal=AX_GEN_STR_TRUNC; }
AxedaCorp 0:a725e8eab383 416 }
AxedaCorp 0:a725e8eab383 417
AxedaCorp 0:a725e8eab383 418 return retVal;
AxedaCorp 0:a725e8eab383 419 }
AxedaCorp 0:a725e8eab383 420 /************************************************************************************/
AxedaCorp 0:a725e8eab383 421 /*ax_createPlatform() */
AxedaCorp 0:a725e8eab383 422 /* */
AxedaCorp 0:a725e8eab383 423 /*Populates the ax_platform struct pointed to by axedaCloud It will add the hostname*/
AxedaCorp 0:a725e8eab383 424 /*ip and port. Other parts of the ax_platform structure can be populated at will */
AxedaCorp 0:a725e8eab383 425 /* */
AxedaCorp 0:a725e8eab383 426 /* */
AxedaCorp 0:a725e8eab383 427 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARG_NULL, AX_GEN_STR_TRUNC, AX_OK */
AxedaCorp 0:a725e8eab383 428 /************************************************************************************/
AxedaCorp 0:a725e8eab383 429 int ax_createPlatform(ax_platform *axedaCloud, const char *hostname, int ip[], int port)
AxedaCorp 0:a725e8eab383 430 {
AxedaCorp 0:a725e8eab383 431 int retVal=AX_OK;
AxedaCorp 0:a725e8eab383 432 //Check that there's an IP or Hostname.
AxedaCorp 0:a725e8eab383 433 if((!ip)&&(!hostname))
AxedaCorp 0:a725e8eab383 434 { return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 435 if(!axedaCloud) {return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 436 //Check the port is in bounds of known ports
AxedaCorp 0:a725e8eab383 437 if((port<0)||(port>65536)) {
AxedaCorp 0:a725e8eab383 438 return AX_OUT_OF_RANGE;
AxedaCorp 0:a725e8eab383 439 }
AxedaCorp 0:a725e8eab383 440 if((hostname)&&(strlen(hostname)>0))
AxedaCorp 0:a725e8eab383 441 {
AxedaCorp 0:a725e8eab383 442 snprintf(axedaCloud->hostname, AX_PLAT_HOST_S, hostname);
AxedaCorp 0:a725e8eab383 443 if(strlen(hostname)>AX_PLAT_HOST_S) {
AxedaCorp 0:a725e8eab383 444 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 445 }
AxedaCorp 0:a725e8eab383 446 }
AxedaCorp 0:a725e8eab383 447 else {
AxedaCorp 0:a725e8eab383 448 return AX_ARG_EMPTY;
AxedaCorp 0:a725e8eab383 449 }
AxedaCorp 0:a725e8eab383 450
AxedaCorp 0:a725e8eab383 451 if(ip)
AxedaCorp 0:a725e8eab383 452 {
AxedaCorp 0:a725e8eab383 453 int i=0;
AxedaCorp 0:a725e8eab383 454 for(i=0; i<4; i++) { if((ip[i]>255)||(ip[i]<0)) return AX_OUT_OF_RANGE; }
AxedaCorp 0:a725e8eab383 455 axedaCloud->ip[0]=ip[0];
AxedaCorp 0:a725e8eab383 456 axedaCloud->ip[1]=ip[1];
AxedaCorp 0:a725e8eab383 457 axedaCloud->ip[2]=ip[2];
AxedaCorp 0:a725e8eab383 458 axedaCloud->ip[3]=ip[3];
AxedaCorp 0:a725e8eab383 459
AxedaCorp 0:a725e8eab383 460 }
AxedaCorp 0:a725e8eab383 461 axedaCloud->port=port;
AxedaCorp 0:a725e8eab383 462 return retVal;
AxedaCorp 0:a725e8eab383 463 }
AxedaCorp 0:a725e8eab383 464 /************************************************************************************/
AxedaCorp 0:a725e8eab383 465 /* ax_createFile() */
AxedaCorp 0:a725e8eab383 466 /* */
AxedaCorp 0:a725e8eab383 467 /* Populates a file structure with the necessary info and checks the arguments to */
AxedaCorp 0:a725e8eab383 468 /* ensure compliance with the protocol */
AxedaCorp 0:a725e8eab383 469 /* Possible Return Codes: AX_UNKNOWN, AX_GEN_STR_TRUNC, AX_OK, AX_ARGNULL */
AxedaCorp 0:a725e8eab383 470 /* */
AxedaCorp 0:a725e8eab383 471 /*file (required): A pointer to an already existing ax_file structure to store data */
AxedaCorp 0:a725e8eab383 472 /*name (required): A name for the file, this can be any arbitrary string. It will */
AxedaCorp 0:a725e8eab383 473 /* appear on the platform after upload */
AxedaCorp 0:a725e8eab383 474 /*hint (optional): A string that allows for easy retrieval on the platform */
AxedaCorp 0:a725e8eab383 475 /*size (required): The size of the file to send. The end of the file would occur at */
AxedaCorp 0:a725e8eab383 476 /* data+size */
AxedaCorp 0:a725e8eab383 477 /*data (required): A pointer to the starting address of data to send, it can be the */
AxedaCorp 0:a725e8eab383 478 /* first cell in an array or any location in memory. */
AxedaCorp 0:a725e8eab383 479 /************************************************************************************/
AxedaCorp 0:a725e8eab383 480 int ax_createFile(ax_file *file, char *name, char *hint, int size, unsigned char *data)
AxedaCorp 0:a725e8eab383 481 {
AxedaCorp 0:a725e8eab383 482 int retVal=AX_OK;
AxedaCorp 0:a725e8eab383 483 //ARG Checks
AxedaCorp 0:a725e8eab383 484 if(size<=0) { return AX_OUT_OF_RANGE; }
AxedaCorp 0:a725e8eab383 485 if(file==NULL) { return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 486 if(name==NULL) { return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 487 if(data==NULL) { return AX_ARGNULL; }
AxedaCorp 0:a725e8eab383 488 //Store the data into the structure
AxedaCorp 0:a725e8eab383 489 snprintf(file->name, AX_FILE_NAME_S, name);
AxedaCorp 0:a725e8eab383 490 if(strlen(name)>AX_FILE_NAME_S){
AxedaCorp 0:a725e8eab383 491 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 492 }
AxedaCorp 0:a725e8eab383 493
AxedaCorp 0:a725e8eab383 494 if(hint!=NULL) {
AxedaCorp 0:a725e8eab383 495 snprintf(file->hint, AX_FILE_HINT_S, hint);
AxedaCorp 0:a725e8eab383 496 if(strlen(hint)>AX_FILE_HINT_S) {
AxedaCorp 0:a725e8eab383 497 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 498 }
AxedaCorp 0:a725e8eab383 499 }
AxedaCorp 0:a725e8eab383 500
AxedaCorp 0:a725e8eab383 501 file->size=size;
AxedaCorp 0:a725e8eab383 502 file->data=data;
AxedaCorp 0:a725e8eab383 503
AxedaCorp 0:a725e8eab383 504 return retVal;
AxedaCorp 0:a725e8eab383 505 }
AxedaCorp 0:a725e8eab383 506
AxedaCorp 0:a725e8eab383 507 /************************************************************************************/
AxedaCorp 0:a725e8eab383 508 /*ax_createPackageInstruction() */
AxedaCorp 0:a725e8eab383 509 /* */
AxedaCorp 0:a725e8eab383 510 /*populates an ax_package_instruction structre passed in. This should never need to */
AxedaCorp 0:a725e8eab383 511 /*be called by a library implementor. It will only be used for egress notifications */
AxedaCorp 0:a725e8eab383 512 /* */
AxedaCorp 0:a725e8eab383 513 /* */
AxedaCorp 0:a725e8eab383 514 /************************************************************************************/
AxedaCorp 0:a725e8eab383 515 int ax_pkg_createPackageInstruction(ax_package_instruction *inst, int instruction_type, char *file_id, char *path, char *filename){
AxedaCorp 0:a725e8eab383 516 int retVal=AX_OK;
AxedaCorp 0:a725e8eab383 517
AxedaCorp 0:a725e8eab383 518 inst->instruction_type=instruction_type;
AxedaCorp 0:a725e8eab383 519 int fdSZ=snprintf(inst->file_id, AX_PKGI_FID_S, file_id);
AxedaCorp 0:a725e8eab383 520 if(strlen(file_id)>fdSZ) {
AxedaCorp 0:a725e8eab383 521 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 522 }
AxedaCorp 0:a725e8eab383 523
AxedaCorp 0:a725e8eab383 524 int pathSZ=snprintf(inst->path, AX_PKGI_PATH_S, path);
AxedaCorp 0:a725e8eab383 525 if(strlen(path)>pathSZ) {
AxedaCorp 0:a725e8eab383 526 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 527 }
AxedaCorp 0:a725e8eab383 528
AxedaCorp 0:a725e8eab383 529
AxedaCorp 0:a725e8eab383 530 int fnSZ=snprintf(inst->filename, AX_PKGI_FNAME_S, filename);
AxedaCorp 0:a725e8eab383 531 if(strlen(filename)>fnSZ) {
AxedaCorp 0:a725e8eab383 532 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 533 }
AxedaCorp 0:a725e8eab383 534 inst->next=NULL;
AxedaCorp 0:a725e8eab383 535
AxedaCorp 0:a725e8eab383 536 return retVal;
AxedaCorp 0:a725e8eab383 537 }
AxedaCorp 0:a725e8eab383 538
AxedaCorp 0:a725e8eab383 539 /************************************************************************************/
AxedaCorp 0:a725e8eab383 540 /*ax_createPackage() */
AxedaCorp 0:a725e8eab383 541 /* */
AxedaCorp 0:a725e8eab383 542 /*populates an ax_package structre passed in. This should never need to be called by*/
AxedaCorp 0:a725e8eab383 543 /*a library implementor. It will only be used for egress notifications */
AxedaCorp 0:a725e8eab383 544 /* */
AxedaCorp 0:a725e8eab383 545 /* */
AxedaCorp 0:a725e8eab383 546 /************************************************************************************/
AxedaCorp 0:a725e8eab383 547 int ax_pkg_createPackage(ax_package *package, char *pkgID, int time, int priority) {
AxedaCorp 0:a725e8eab383 548 int retVal=AX_OK;
AxedaCorp 0:a725e8eab383 549
AxedaCorp 0:a725e8eab383 550 int nmsz=snprintf(package->packageID, AX_PKG_ID_S, pkgID);
AxedaCorp 0:a725e8eab383 551 if(strlen(pkgID)> nmsz) {
AxedaCorp 0:a725e8eab383 552 retVal=AX_GEN_STR_TRUNC;
AxedaCorp 0:a725e8eab383 553 }
AxedaCorp 0:a725e8eab383 554 package->time=time;
AxedaCorp 0:a725e8eab383 555 package->priority=priority;
AxedaCorp 0:a725e8eab383 556 package->instructions=NULL;
AxedaCorp 0:a725e8eab383 557
AxedaCorp 0:a725e8eab383 558
AxedaCorp 0:a725e8eab383 559 return retVal;
AxedaCorp 0:a725e8eab383 560 }
AxedaCorp 0:a725e8eab383 561 /************************************************************************************/
AxedaCorp 0:a725e8eab383 562 /*ax_pkg_addDLInstruction() */
AxedaCorp 0:a725e8eab383 563 /* */
AxedaCorp 0:a725e8eab383 564 /*Adds a file download package to an already existing package. This function will */
AxedaCorp 0:a725e8eab383 565 /*dynamically allocate memory for each instruction. That memory will need to be freed*/
AxedaCorp 0:a725e8eab383 566 /*When the status is complete */
AxedaCorp 0:a725e8eab383 567 /* */
AxedaCorp 0:a725e8eab383 568 /************************************************************************************/
AxedaCorp 0:a725e8eab383 569 int ax_pkg_addDLInstruction(ax_package *pkg, char *file_id, char *path, char *filename) {
AxedaCorp 0:a725e8eab383 570 int retVal=AX_UNKNOWN;
AxedaCorp 0:a725e8eab383 571 ax_package_instruction *curr=NULL;
AxedaCorp 0:a725e8eab383 572 ax_package_instruction *newInst=NULL;
AxedaCorp 0:a725e8eab383 573
AxedaCorp 0:a725e8eab383 574 newInst=(ax_package_instruction *)calloc(1, sizeof(ax_package_instruction));
AxedaCorp 0:a725e8eab383 575 retVal=ax_pkg_createPackageInstruction(newInst, AX_PKG_DOWNLOAD, file_id, path, filename);
AxedaCorp 0:a725e8eab383 576
AxedaCorp 0:a725e8eab383 577 if(pkg->instructions!=NULL) {
AxedaCorp 0:a725e8eab383 578 curr=pkg->instructions;
AxedaCorp 0:a725e8eab383 579 //Go to the end of the list
AxedaCorp 0:a725e8eab383 580 while(curr->next!=NULL) {
AxedaCorp 0:a725e8eab383 581 curr=curr->next;
AxedaCorp 0:a725e8eab383 582 }
AxedaCorp 0:a725e8eab383 583 curr->next=newInst;
AxedaCorp 0:a725e8eab383 584 }
AxedaCorp 0:a725e8eab383 585
AxedaCorp 0:a725e8eab383 586 else {
AxedaCorp 0:a725e8eab383 587 pkg->instructions=newInst;
AxedaCorp 0:a725e8eab383 588 }
AxedaCorp 0:a725e8eab383 589
AxedaCorp 0:a725e8eab383 590
AxedaCorp 0:a725e8eab383 591 return retVal;
AxedaCorp 0:a725e8eab383 592 }
AxedaCorp 0:a725e8eab383 593 /*************************************************************************************/
AxedaCorp 0:a725e8eab383 594 /*ax_pkg_destroyPackage() */
AxedaCorp 0:a725e8eab383 595 /* */
AxedaCorp 0:a725e8eab383 596 /*Free's lined package Instructions when created by the ax_pkg_add*() function. Be */
AxedaCorp 0:a725e8eab383 597 /*careful not to use this on a package with instructions that were manually declared */
AxedaCorp 0:a725e8eab383 598 /*This does not attempt to free the package itself as it may have been declared and */
AxedaCorp 0:a725e8eab383 599 /*not dynamically allocated. */
AxedaCorp 0:a725e8eab383 600 /************************************************************************************/
AxedaCorp 0:a725e8eab383 601 int ax_pkg_destroyPackage(ax_package *pkg) {
AxedaCorp 0:a725e8eab383 602 ax_package_instruction *curr=NULL;
AxedaCorp 0:a725e8eab383 603 ax_package_instruction *target=NULL;
AxedaCorp 0:a725e8eab383 604 curr=pkg->instructions;
AxedaCorp 0:a725e8eab383 605 while(curr!=NULL) {
AxedaCorp 0:a725e8eab383 606 target=curr; //We'll aim at the current node
AxedaCorp 0:a725e8eab383 607 curr=curr->next; //store the value for the next node
AxedaCorp 0:a725e8eab383 608 free(target); //kill the target node
AxedaCorp 0:a725e8eab383 609 }
AxedaCorp 0:a725e8eab383 610 return AX_OK;
AxedaCorp 0:a725e8eab383 611 }
AxedaCorp 0:a725e8eab383 612