Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem
Fork of AxedaGo-Freescal_FRDM-KL46Z by
axDomain.c
00001 /************************************************************************************/ 00002 /* axDomain.c */ 00003 /* �2013 Axeda Corporation */ 00004 /* */ 00005 /* Defines methods for creation and interaction with Axeda domain constructs. This */ 00006 /* is a device independent implementation which can be applied to any device that */ 00007 /* supports ANSI C. */ 00008 /************************************************************************************/ 00009 #include "axDomain.h" 00010 #include "string.h" 00011 #include "axSettings.h" 00012 #include <stdlib.h> 00013 #include <stdio.h> 00014 00015 00016 00017 /************************************************************************************/ 00018 /* createAlarm() */ 00019 /* */ 00020 /* Stores the supplied values into the structure pointed to by alm. */ 00021 /* */ 00022 /* alm(required) : a pointer to an empty alarm structure */ 00023 /* name(required) : the name of the alarm */ 00024 /* description(required) : a more detailed account of the alarm */ 00025 /* severity(required) : a numerical value from 0-1000, with 1000 being the highest */ 00026 /* dataItem(optional) : a pointer to a dataItem structure containing the data item */ 00027 /* that triggered this alarm. Use NULL for a generic alarm. */ 00028 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARG_NULL, AX_GEN_STR_TRUNC, AX_OK */ 00029 /************************************************************************************/ 00030 int ax_data_createAlarm(ax_alarm *alm, char *alName, char *alDescription, int alSeverity, char *cause, char *reason, int timeOccured, int priority) 00031 { 00032 int retVal=AX_OK; 00033 if((alSeverity <0)||(alSeverity>1000)) 00034 { 00035 return AX_OUT_OF_RANGE; 00036 } 00037 if((!alm)||(!alName)||(!alDescription)) 00038 { 00039 return AX_ARGNULL; 00040 } 00041 if(strlen(alName)<=0) { 00042 return AX_ARGNULL; 00043 } 00044 00045 snprintf(alm->alarmName, AX_ALM_NAME_S, alName); 00046 if(strlen(alName)>AX_ALM_NAME_S){ 00047 retVal=AX_GEN_STR_TRUNC; 00048 } 00049 00050 snprintf(alm->alarmDescription, AX_ALM_DESC_S, alDescription); 00051 if(strlen(alDescription)> AX_ALM_DESC_S) { 00052 retVal=AX_GEN_STR_TRUNC; 00053 } 00054 00055 snprintf(alm->alarmCause, AX_ALM_CAUSE_S, cause); 00056 if(strlen(cause)>AX_ALM_CAUSE_S) { 00057 retVal=AX_GEN_STR_TRUNC; 00058 } 00059 00060 snprintf(alm->alarmReason, AX_ALM_REAS_S, reason); 00061 if(strlen(reason)>AX_ALM_REAS_S){ 00062 retVal=AX_GEN_STR_TRUNC; 00063 } 00064 00065 alm->alarmSeverity=alSeverity; 00066 alm->dateAcquired=timeOccured; 00067 alm->priority=priority; 00068 00069 return retVal; 00070 } 00071 00072 /*************************************************************************************/ 00073 /* createDataItem() */ 00074 /* */ 00075 /* This function will store information about a dataItem into a structure supplied */ 00076 /* by the calling method. There are traditionally 3 types of data Items, analog, */ 00077 /* string and digital. */ 00078 /* */ 00079 /* destDI(required) : A pointer to the structure where the data will be stored */ 00080 /* diName(required) : A character array containing the name of the data item */ 00081 /* diType(required) : A integer value indicating the data Item type. Can be */ 00082 /* AX_STRING, AX_DIGITAL, AX_ANALOG */ 00083 /* stringValue(optional): If the type is AX_STRING, this value MUST be populated or */ 00084 /* an error will be returned. This is the value of the */ 00085 /* dataItem. If it is a String use zero for the numericValue */ 00086 /* numericValue(optional): If the type is AX_ANALOG or AX_DIGITAL this value MUST be */ 00087 /* provided or an error will be returned. For AX_ANALOG di's */ 00088 /* this value can be any numeric value within language */ 00089 /* constraints. For AX_DIGITAL, this value must be 1 or 0. */ 00090 /* 1 will be considered true and 0 will be considered false. */ 00091 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00092 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */ 00093 /************************************************************************************/ 00094 int ax_data_createDataItem(ax_dataSet *destDI, char *diName, int diType, char *stringValue, double numericValue, int timeAcquired, int priority) { 00095 int retVal=AX_UNKNOWN; 00096 if(!destDI) { return AX_ARGNULL; } 00097 if(!diName) {return AX_ARGNULL; } 00098 if((diType>3)&&(diType<1)) {return AX_ARGNULL; } 00099 if(timeAcquired<0) {return AX_OUT_OF_RANGE; } 00100 if((priority<-1)||(priority>100)) { return AX_OUT_OF_RANGE; } 00101 if(destDI->created!=AX_TRUE) { 00102 retVal=ax_data_createSet(destDI, timeAcquired, priority); 00103 if(retVal!=AX_OK) { return retVal; } 00104 } 00105 00106 retVal=ax_data_addToSet(destDI, diName, diType, stringValue, numericValue); 00107 00108 return retVal; 00109 } 00110 /*************************************************************************************/ 00111 /* createAnalogDataItem() */ 00112 /* */ 00113 /* This function will store information about a dataItem into a structure supplied */ 00114 /* by the calling method. This is a special case of the ax_data_createDataItem() call*/ 00115 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00116 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */ 00117 /*************************************************************************************/ 00118 int ax_data_createAnalogDataItem(ax_dataSet *destDI, char *diName, double value, int timeAcquired, int priority) { 00119 return ax_data_createDataItem(destDI, diName, AX_ANALOG, NULL, value, timeAcquired, priority); 00120 } 00121 00122 /*************************************************************************************/ 00123 /* createDigitalDataItem() */ 00124 /* */ 00125 /* This function will store information about a dataItem into a structure supplied */ 00126 /* by the calling method. There are traditionally 3 types of data Items, analog, */ 00127 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00128 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */ 00129 /*************************************************************************************/ 00130 int ax_data_createDigitalDataItem(ax_dataSet *destDI, char *diName, double value, int timeAcquired, int priority) { 00131 return ax_data_createDataItem(destDI, diName, AX_DIGITAL, NULL, value, timeAcquired, priority); 00132 } 00133 00134 /*************************************************************************************/ 00135 /* createDataItem() */ 00136 /* */ 00137 /* This function will store information about a dataItem into a structure supplied */ 00138 /* by the calling method. There are traditionally 3 types of data Items, analog, */ 00139 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00140 /* AX_DI_UNKNOWN_TYPE, AX_UNKNOWN */ 00141 /*************************************************************************************/ 00142 int ax_data_createStringDataItem(ax_dataSet *destDI, char *diName, char *value, int timeAcquired, int priority) { 00143 return ax_data_createDataItem(destDI, diName, AX_STRING, value, -1, timeAcquired, priority); 00144 } 00145 00146 /************************************************************************************/ 00147 /*ax_data_createSet() */ 00148 /* */ 00149 /*Creates and populates a dataSet struct pointed to by the *set parameter. A dataSet*/ 00150 /*can have multiple data items added by the ax_data_addToSet() method. */ 00151 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00152 /************************************************************************************/ 00153 int ax_data_createSet(ax_dataSet *set, int acquisitionTime, int priority) { 00154 00155 if(!set) { return AX_ARGNULL; } 00156 if((priority<-1)||(priority>100)) { return AX_OUT_OF_RANGE; } 00157 if(acquisitionTime<0) {return AX_OUT_OF_RANGE; } 00158 set->dataNode_ct=0; 00159 set->data_first=NULL; 00160 set->data_last=NULL; 00161 00162 if(acquisitionTime >=0) { 00163 set->acquisitionTime=acquisitionTime; 00164 } 00165 else { 00166 set->acquisitionTime=-1; 00167 } 00168 if((priority >=1)&&(priority<=100)) { 00169 set->priority=priority; 00170 } 00171 else { 00172 set->priority=AX_NO_PRIORITY; 00173 } 00174 00175 set->created=AX_TRUE; 00176 return AX_OK; 00177 } 00178 /************************************************************************************/ 00179 /*ax_data_addToSet() */ 00180 /* */ 00181 /*Adds data to a preExisting data set. Data is represented as a linked list and */ 00182 /*pointed to by a dataSet structure. Adding data to with this method will cause the */ 00183 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/ 00184 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */ 00185 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00186 /* AX_DI_UNKNOWN_TYPE */ 00187 /************************************************************************************/ 00188 int ax_data_addToSet(ax_dataSet *set, char *diName, int diType, char *stringValue, double numericValue){ 00189 ax_dataNode *newNode, *temp=NULL; 00190 int retVal=AX_UNKNOWN; 00191 00192 if((diType<1)||(diType>3)){ 00193 return AX_DI_UNKNOWN_TYPE; 00194 } 00195 00196 if((!set)||(!diName)){ 00197 return AX_ARGNULL; 00198 } 00199 00200 if((diType==AX_STRING)&&(!stringValue)){ 00201 return AX_ARGNULL; 00202 } 00203 if((diType==AX_DIGITAL)&&((numericValue<0)||(numericValue>1))){ 00204 return AX_OUT_OF_RANGE; 00205 } 00206 //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. 00207 if(set->created!=AX_TRUE) { ax_data_createSet(set, 0, AX_NO_PRIORITY); } 00208 00209 newNode=(ax_dataNode*)malloc(sizeof(ax_dataNode)); 00210 00211 retVal=AX_OK; 00212 snprintf(newNode->name, AX_DN_NAME_S, diName); 00213 if(strlen(diName)>AX_DN_NAME_S) { 00214 retVal=AX_GEN_STR_TRUNC; 00215 } 00216 00217 newNode->next=NULL; 00218 newNode->type=diType; 00219 if(diType==AX_STRING) { 00220 snprintf(newNode->sValue, AX_DN_SV_S, stringValue); 00221 if(strlen(stringValue)>AX_DN_SV_S) { 00222 retVal=AX_GEN_STR_TRUNC; // if the requested value was too large, set a warning to let us know it was truncated 00223 } 00224 } 00225 else { 00226 newNode->dValue=numericValue; 00227 } 00228 00229 if(set->data_first==NULL) { 00230 set->data_first=newNode; 00231 } 00232 00233 if(set->data_last!=NULL) { 00234 temp=set->data_last; 00235 temp->next=(ax_dataNode *)newNode; 00236 } 00237 00238 00239 set->data_last=newNode; 00240 int nodect=set->dataNode_ct; 00241 nodect++; 00242 set->dataNode_ct=nodect; 00243 00244 return retVal; 00245 } 00246 /************************************************************************************/ 00247 /*ax_data_addStringToSet() */ 00248 /* */ 00249 /*Adds data to a preExisting data set. Data is represented as a linked list and */ 00250 /*pointed to by a dataSet structure. Adding data to with this method will cause the */ 00251 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/ 00252 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */ 00253 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00254 /************************************************************************************/ 00255 int ax_data_addStringToSet(ax_dataSet *set, char *diName, char *value) { 00256 return ax_data_addToSet(set, diName, AX_STRING, value, -1); 00257 } 00258 /************************************************************************************/ 00259 /*ax_data_addAnalogToSet() */ 00260 /* */ 00261 /*Adds data to a preExisting data set. Data is represented as a linked list and */ 00262 /*pointed to by a dataSet structure. Adding data to with this method will cause the */ 00263 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/ 00264 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */ 00265 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_OK */ 00266 /************************************************************************************/ 00267 int ax_data_addAnalogToSet(ax_dataSet *set, char *diName, double value){ 00268 return ax_data_addToSet(set, diName, AX_ANALOG, NULL, value); 00269 } 00270 /************************************************************************************/ 00271 /*ax_data_addDigitalToSet() */ 00272 /* */ 00273 /*Adds data to a preExisting data set. Data is represented as a linked list and */ 00274 /*pointed to by a dataSet structure. Adding data to with this method will cause the */ 00275 /*memory to be malloc'd for each data item you set. To remove all data correctly use*/ 00276 /*the ax_data_destroySet() function call. You will get memory leaks if you do not. */ 00277 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_OK */ 00278 /************************************************************************************/ 00279 int ax_data_addDigitalToSet(ax_dataSet *set, char *diName, double value) { 00280 return ax_data_addToSet(set, diName, AX_DIGITAL, NULL, value); 00281 } 00282 00283 00284 /************************************************************************************/ 00285 /*ax_data_destroySet() */ 00286 /* */ 00287 /*Iterates through all data items in a dataset and frees them. This assumes all nodes*/ 00288 /*have been allocated by malloc.If the addToSet() function was being used then that */ 00289 /*will be true. */ 00290 /*Possible Return Codes: AX_OK AX_ARGNULL */ 00291 /************************************************************************************/ 00292 int ax_data_destroySet(ax_dataSet *set) { 00293 00294 if(set!=NULL) { 00295 ax_dataNode *curr=set->data_first, *next; 00296 int ctr; 00297 for(ctr=0; ctr<set->dataNode_ct; ctr++) 00298 { 00299 next=(ax_dataNode *)curr->next; 00300 free(curr); 00301 curr=next; 00302 next=NULL; // CYA'ing here 00303 } 00304 set->data_first=NULL; 00305 set->data_last=NULL; 00306 } 00307 else { 00308 return AX_ARGNULL; 00309 } 00310 00311 return AX_OK; 00312 } 00313 00314 00315 /*************************************************************************************/ 00316 /* createEvent() */ 00317 /* */ 00318 /* This function will populate an event structure and check the values to ensure they*/ 00319 /* are within protocol limit */ 00320 /* Possible Return Codes: AX_ARGNULL, AX_GEN_STR_TRUNC */ 00321 /************************************************************************************/ 00322 int ax_data_createEvent(ax_event *evt, char *name, char *description, int timeOccured, int priority) 00323 { 00324 int retVal=AX_OK; 00325 if((!evt)||(!name)||(!description)){ 00326 return AX_ARGNULL; 00327 } 00328 if((priority<-1)||(priority>100)) {return AX_OUT_OF_RANGE; } 00329 00330 snprintf(evt->name,AX_EVT_NAME_S, name); 00331 if(strlen(name)>AX_EVT_NAME_S) { 00332 retVal= AX_GEN_STR_TRUNC; 00333 } 00334 00335 snprintf(evt->description, AX_EVT_DESC_S, description); 00336 if(strlen(description)>AX_EVT_DESC_S) { 00337 retVal=AX_GEN_STR_TRUNC; 00338 } 00339 00340 evt->dateAcquired=timeOccured; 00341 evt->priority=priority; 00342 return retVal; 00343 } 00344 00345 00346 00347 00348 /************************************************************************************/ 00349 /* createLocation() */ 00350 /* */ 00351 /* This function will populate a location structure storing the current location */ 00352 /* */ 00353 /* loc (required) : A structure that will be populated with the data */ 00354 /* lat (required) : A number between 90 and -90 representing the degrees latitude. */ 00355 /* lon (required) : A number between 180 and -180 representing the degrees longitude*/ 00356 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARGNULL, AX_OK */ 00357 /************************************************************************************/ 00358 int ax_data_createLocation(ax_location *loc, double lat, double lon, double alt, int timeAcquired, int priority){ 00359 if(!loc){ 00360 return AX_ARGNULL; 00361 } 00362 00363 if((lat>90)||(lat<-90)){ 00364 return AX_OUT_OF_RANGE; 00365 } 00366 00367 if((lon>180)||(lon<-180)){ 00368 return AX_OUT_OF_RANGE; 00369 } 00370 00371 00372 loc->latitude=lat; 00373 loc->longitude=lon; 00374 loc->altitude=alt; 00375 00376 loc->dateAcquired=timeAcquired; 00377 loc->priority=priority; 00378 return AX_OK; 00379 } 00380 00381 /************************************************************************************/ 00382 /* createModelSerialDeviceId() */ 00383 /* */ 00384 /* This function will populate a structure that stores data about the device's iden-*/ 00385 /* tification. The Axeda platform allows for multiple ways of identifying a device. */ 00386 /* */ 00387 /* device(required) : a pointer to a structure where the data will be stored */ 00388 /* model (required) : A model number that describes a particular family of device. */ 00389 /* If this were describing a car it could be a Ford_Mustang */ 00390 /* serial (required) : A unique Identifier for the device. If it was a car it would */ 00391 /* be analagous to the VIN number. */ 00392 /* tenant (optional) : The identifier of the Axeda tenant instance. Not currently */ 00393 /* used and should always default to zero. */ 00394 /* Possible Return Codes: AX_ARGNULL, AX_GEN_STR_TRUNC, AX_OK */ 00395 /************************************************************************************/ 00396 00397 int ax_data_createModelSerialDeviceId(ax_deviceID *device, char *model, char *serial, char *tenant) { 00398 int retVal=AX_OK; 00399 if((!device)||(!model)||(!serial)){ 00400 return AX_ARGNULL; 00401 } 00402 snprintf(device->model, AX_MSID_MDL_S, model); 00403 if(strlen(model)> AX_MSID_MDL_S) { 00404 retVal=AX_GEN_STR_TRUNC; 00405 } 00406 00407 snprintf(device->serial, AX_MSID_SER_S, serial); 00408 if(strlen(serial)>AX_MSID_SER_S) { 00409 retVal=AX_GEN_STR_TRUNC; 00410 } 00411 00412 memset(device->tenant, '\0', AX_MSID_TEN_S); 00413 if(tenant!=NULL) { 00414 snprintf(device->tenant, AX_MSID_TEN_S, "%s", tenant); 00415 if(strlen(tenant)>AX_MSID_TEN_S) { retVal=AX_GEN_STR_TRUNC; } 00416 } 00417 00418 return retVal; 00419 } 00420 /************************************************************************************/ 00421 /*ax_createPlatform() */ 00422 /* */ 00423 /*Populates the ax_platform struct pointed to by axedaCloud It will add the hostname*/ 00424 /*ip and port. Other parts of the ax_platform structure can be populated at will */ 00425 /* */ 00426 /* */ 00427 /* Possible Return Codes: AX_OUT_OF_RANGE, AX_ARG_NULL, AX_GEN_STR_TRUNC, AX_OK */ 00428 /************************************************************************************/ 00429 int ax_createPlatform(ax_platform *axedaCloud, char *hostname, int ip[], int port) 00430 { 00431 int retVal=AX_OK; 00432 //Check that there's an IP or Hostname. 00433 if((!ip)&&(!hostname)) 00434 { return AX_ARGNULL; } 00435 if(!axedaCloud) {return AX_ARGNULL; } 00436 //Check the port is in bounds of known ports 00437 if((port<0)||(port>65536)) { 00438 return AX_OUT_OF_RANGE; 00439 } 00440 if((hostname)&&(strlen(hostname)>0)) 00441 { 00442 snprintf(axedaCloud->hostname, AX_PLAT_HOST_S, hostname); 00443 if(strlen(hostname)>AX_PLAT_HOST_S) { 00444 retVal=AX_GEN_STR_TRUNC; 00445 } 00446 } 00447 else { 00448 return AX_ARG_EMPTY; 00449 } 00450 00451 if(ip) 00452 { 00453 int i=0; 00454 for(i=0; i<4; i++) { if((ip[i]>255)||(ip[i]<0)) return AX_OUT_OF_RANGE; } 00455 axedaCloud->ip[0]=ip[0]; 00456 axedaCloud->ip[1]=ip[1]; 00457 axedaCloud->ip[2]=ip[2]; 00458 axedaCloud->ip[3]=ip[3]; 00459 00460 } 00461 axedaCloud->port=port; 00462 return retVal; 00463 } 00464 /************************************************************************************/ 00465 /* ax_createFile() */ 00466 /* */ 00467 /* Populates a file structure with the necessary info and checks the arguments to */ 00468 /* ensure compliance with the protocol */ 00469 /* Possible Return Codes: AX_UNKNOWN, AX_GEN_STR_TRUNC, AX_OK, AX_ARGNULL */ 00470 /* */ 00471 /*file (required): A pointer to an already existing ax_file structure to store data */ 00472 /*name (required): A name for the file, this can be any arbitrary string. It will */ 00473 /* appear on the platform after upload */ 00474 /*hint (optional): A string that allows for easy retrieval on the platform */ 00475 /*size (required): The size of the file to send. The end of the file would occur at */ 00476 /* data+size */ 00477 /*data (required): A pointer to the starting address of data to send, it can be the */ 00478 /* first cell in an array or any location in memory. */ 00479 /************************************************************************************/ 00480 int ax_createFile(ax_file *file, char *name, char *hint, int size, unsigned char *data) 00481 { 00482 int retVal=AX_OK; 00483 //ARG Checks 00484 if(size<=0) { return AX_OUT_OF_RANGE; } 00485 if(file==NULL) { return AX_ARGNULL; } 00486 if(name==NULL) { return AX_ARGNULL; } 00487 if(data==NULL) { return AX_ARGNULL; } 00488 //Store the data into the structure 00489 snprintf(file->name, AX_FILE_NAME_S, name); 00490 if(strlen(name)>AX_FILE_NAME_S){ 00491 retVal=AX_GEN_STR_TRUNC; 00492 } 00493 00494 if(hint!=NULL) { 00495 snprintf(file->hint, AX_FILE_HINT_S, hint); 00496 if(strlen(hint)>AX_FILE_HINT_S) { 00497 retVal=AX_GEN_STR_TRUNC; 00498 } 00499 } 00500 00501 file->size=size; 00502 file->data=data; 00503 00504 return retVal; 00505 } 00506 00507 /************************************************************************************/ 00508 /*ax_createPackageInstruction() */ 00509 /* */ 00510 /*populates an ax_package_instruction structre passed in. This should never need to */ 00511 /*be called by a library implementor. It will only be used for egress notifications */ 00512 /* */ 00513 /* */ 00514 /************************************************************************************/ 00515 int ax_pkg_createPackageInstruction(ax_package_instruction *inst, int instruction_type, char *file_id, char *path, char *filename){ 00516 int retVal=AX_OK; 00517 00518 inst->instruction_type=instruction_type; 00519 int fdSZ=snprintf(inst->file_id, AX_PKGI_FID_S, file_id); 00520 if(strlen(file_id)>fdSZ) { 00521 retVal=AX_GEN_STR_TRUNC; 00522 } 00523 00524 int pathSZ=snprintf(inst->path, AX_PKGI_PATH_S, path); 00525 if(strlen(path)>pathSZ) { 00526 retVal=AX_GEN_STR_TRUNC; 00527 } 00528 00529 00530 int fnSZ=snprintf(inst->filename, AX_PKGI_FNAME_S, filename); 00531 if(strlen(filename)>fnSZ) { 00532 retVal=AX_GEN_STR_TRUNC; 00533 } 00534 inst->next=NULL; 00535 00536 return retVal; 00537 } 00538 00539 /************************************************************************************/ 00540 /*ax_createPackage() */ 00541 /* */ 00542 /*populates an ax_package structre passed in. This should never need to be called by*/ 00543 /*a library implementor. It will only be used for egress notifications */ 00544 /* */ 00545 /* */ 00546 /************************************************************************************/ 00547 int ax_pkg_createPackage(ax_package *package, char *pkgID, int time, int priority) { 00548 int retVal=AX_OK; 00549 00550 int nmsz=snprintf(package->packageID, AX_PKG_ID_S, pkgID); 00551 if(strlen(pkgID)> nmsz) { 00552 retVal=AX_GEN_STR_TRUNC; 00553 } 00554 package->time=time; 00555 package->priority=priority; 00556 package->instructions=NULL; 00557 00558 00559 return retVal; 00560 } 00561 /************************************************************************************/ 00562 /*ax_pkg_addDLInstruction() */ 00563 /* */ 00564 /*Adds a file download package to an already existing package. This function will */ 00565 /*dynamically allocate memory for each instruction. That memory will need to be freed*/ 00566 /*When the status is complete */ 00567 /* */ 00568 /************************************************************************************/ 00569 int ax_pkg_addDLInstruction(ax_package *pkg, char *file_id, char *path, char *filename) { 00570 int retVal=AX_UNKNOWN; 00571 ax_package_instruction *curr=NULL; 00572 ax_package_instruction *newInst=NULL; 00573 00574 newInst=(ax_package_instruction *)calloc(1, sizeof(ax_package_instruction)); 00575 retVal=ax_pkg_createPackageInstruction(newInst, AX_PKG_DOWNLOAD, file_id, path, filename); 00576 00577 if(pkg->instructions!=NULL) { 00578 curr=pkg->instructions; 00579 //Go to the end of the list 00580 while(curr->next!=NULL) { 00581 curr=curr->next; 00582 } 00583 curr->next=newInst; 00584 } 00585 00586 else { 00587 pkg->instructions=newInst; 00588 } 00589 00590 00591 return retVal; 00592 } 00593 /*************************************************************************************/ 00594 /*ax_pkg_destroyPackage() */ 00595 /* */ 00596 /*Free's lined package Instructions when created by the ax_pkg_add*() function. Be */ 00597 /*careful not to use this on a package with instructions that were manually declared */ 00598 /*This does not attempt to free the package itself as it may have been declared and */ 00599 /*not dynamically allocated. */ 00600 /************************************************************************************/ 00601 int ax_pkg_destroyPackage(ax_package *pkg) { 00602 ax_package_instruction *curr=NULL; 00603 ax_package_instruction *target=NULL; 00604 curr=pkg->instructions; 00605 while(curr!=NULL) { 00606 target=curr; //We'll aim at the current node 00607 curr=curr->next; //store the value for the next node 00608 free(target); //kill the target node 00609 } 00610 return AX_OK; 00611 } 00612
Generated on Wed Jul 13 2022 03:01:22 by
