rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #include "AudioParamParser.h" |
| 2 | #include "AudioParamParserPriv.h" |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | #define BUF_SIZE 1024 |
| 8 | |
| 9 | void showParamValue(Param *param) |
| 10 | { |
| 11 | switch (param->paramInfo->dataType) |
| 12 | { |
| 13 | case TYPE_STR: |
| 14 | { |
| 15 | char *value = (char *)param->data; |
| 16 | printf("param name = %s, value = %s (type = %s)\n", param->name, value, paramDataTypeToStr(param->paramInfo->dataType)); |
| 17 | break; |
| 18 | } |
| 19 | case TYPE_INT: |
| 20 | { |
| 21 | int value = *(int *) param->data; |
| 22 | printf("param name = %s, value = %d (type = %s)\n", param->name, value, paramDataTypeToStr(param->paramInfo->dataType)); |
| 23 | break; |
| 24 | } |
| 25 | case TYPE_UINT: |
| 26 | { |
| 27 | unsigned int value = *(unsigned int *) param->data; |
| 28 | printf("param name = %s, value = %d (type = %s)\n", param->name, value, paramDataTypeToStr(param->paramInfo->dataType)); |
| 29 | break; |
| 30 | } |
| 31 | case TYPE_FLOAT: |
| 32 | { |
| 33 | float value = *(float *) param->data; |
| 34 | /* JH's platform cannot show the float type, wei chiu could show the value by %f*/ |
| 35 | printf("param name = %s, value = %d (type = %s)\n", param->name, (int)value, paramDataTypeToStr(param->paramInfo->dataType)); |
| 36 | break; |
| 37 | } |
| 38 | case TYPE_BYTE_ARRAY: |
| 39 | { |
| 40 | char *byteArray = (char *)param->data; |
| 41 | int arraySize = param->arraySize; |
| 42 | int i = 0; |
| 43 | printf("param name = %s (type = %s, size = %d)\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize); |
| 44 | for (i = 0; i < arraySize; i++) |
| 45 | { |
| 46 | printf("\tarray[%d] %d\n", i, byteArray[i]); |
| 47 | } |
| 48 | break; |
| 49 | } |
| 50 | case TYPE_UBYTE_ARRAY: |
| 51 | { |
| 52 | unsigned char *ubyteArray = (unsigned char *)param->data; |
| 53 | int arraySize = param->arraySize; |
| 54 | int i = 0; |
| 55 | printf("param name = %s (type = %s, size = %d)\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize); |
| 56 | for (i = 0; i < arraySize; i++) |
| 57 | { |
| 58 | printf("\tarray[%d] 0x%x\n", i, ubyteArray[i]); |
| 59 | } |
| 60 | break; |
| 61 | } |
| 62 | case TYPE_SHORT_ARRAY: |
| 63 | { |
| 64 | short *shortArray = (short *)param->data; |
| 65 | int arraySize = param->arraySize; |
| 66 | int i = 0; |
| 67 | printf("param name = %s (type = %s, size = %d)\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize); |
| 68 | for (i = 0; i < arraySize; i++) |
| 69 | { |
| 70 | printf("\tarray[%d] %d\n", i, shortArray[i]); |
| 71 | } |
| 72 | break; |
| 73 | } |
| 74 | case TYPE_USHORT_ARRAY: |
| 75 | { |
| 76 | unsigned short *ushortArray = (unsigned short *)param->data; |
| 77 | int arraySize = param->arraySize; |
| 78 | int i = 0; |
| 79 | printf("param name = %s (type = %s, size = %d)\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize); |
| 80 | for (i = 0; i < arraySize; i++) |
| 81 | { |
| 82 | printf("\tarray[%d] 0x%x\n", i, ushortArray[i]); |
| 83 | } |
| 84 | break; |
| 85 | } |
| 86 | case TYPE_INT_ARRAY: |
| 87 | { |
| 88 | int *intArray = (int *)param->data; |
| 89 | int arraySize = param->arraySize; |
| 90 | int i = 0; |
| 91 | printf("param name = %s (type = %s, size = %d)\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize); |
| 92 | for (i = 0; i < arraySize; i++) |
| 93 | { |
| 94 | printf("\tarray[%d] %d\n", i, intArray[i]); |
| 95 | } |
| 96 | break; |
| 97 | } |
| 98 | case TYPE_UINT_ARRAY: |
| 99 | { |
| 100 | unsigned int *uintArray = (unsigned int *)param->data; |
| 101 | int arraySize = param->arraySize; |
| 102 | int i = 0; |
| 103 | printf("param name = %s (type = %s, size = %d)\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize); |
| 104 | for (i = 0; i < arraySize; i++) |
| 105 | { |
| 106 | printf("\tarray[%d] 0x%x\n", i, uintArray[i]); |
| 107 | } |
| 108 | break; |
| 109 | } |
| 110 | case TYPE_DOUBLE_ARRAY: |
| 111 | { |
| 112 | double *doubleArray = (double *)param->data; |
| 113 | int arraySize = param->arraySize; |
| 114 | int i = 0; |
| 115 | printf("param name = %s (type = %s, size = %d)\n", param->name, paramDataTypeToStr(param->paramInfo->dataType), arraySize); |
| 116 | for (i = 0; i < arraySize; i++) |
| 117 | { |
| 118 | printf("\tarray[%d] %f\n", i, doubleArray[i]); |
| 119 | } |
| 120 | break; |
| 121 | } |
| 122 | default: |
| 123 | printf("param name = %s, value = 0x%p (type = %s)\n", param->name, param->data, paramDataTypeToStr(param->paramInfo->dataType)); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void showFieldValueOfParam(Param *param) |
| 128 | { |
| 129 | // Enum all field value |
| 130 | size_t i; |
| 131 | ParamInfo *paramInfo = audioTypeGetParamInfoByName(param->paramUnit->audioType, param->name); |
| 132 | unsigned int val; |
| 133 | size_t numOfFieldInfo; |
| 134 | |
| 135 | printf("\t---------------------\n"); |
| 136 | numOfFieldInfo = paramInfoGetNumOfFieldInfo(paramInfo); |
| 137 | for (i = 0; i < numOfFieldInfo; i++) |
| 138 | { |
| 139 | |
| 140 | FieldInfo *fieldInfo = paramInfoGetFieldInfoByIndex(paramInfo, i); |
| 141 | if (paramGetFieldVal(param, fieldInfo, &val) == APP_ERROR) |
| 142 | { |
| 143 | printf("Cannot get field value. (param name=%s, field name=%s)\n", param->name, fieldInfo->name); |
| 144 | continue; |
| 145 | } |
| 146 | |
| 147 | printf("\tfield[%lu] name = %s, value = 0x%u.\n", i, fieldInfo->name, val); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void showFieldInfo(FieldInfo *fieldInfo) |
| 152 | { |
| 153 | if (!fieldInfo) |
| 154 | { |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | printf("FieldInfo name = %s, array_index = %lu, bit[%d,%d], check_list = %s\n", fieldInfo->name, fieldInfo->arrayIndex, fieldInfo->startBit, fieldInfo->endBit, fieldInfo->checkListStr); |
| 159 | } |
| 160 | |
| 161 | void showParamInfo(ParamInfo *paramInfo) |
| 162 | { |
| 163 | size_t i; |
| 164 | size_t numOfFieldInfo = paramInfoGetNumOfFieldInfo(paramInfo); |
| 165 | |
| 166 | printf("ParamInfo name = %s, type = %s\n", paramInfo->name, paramDataTypeToStr(paramInfo->dataType)); |
| 167 | for (i = 0; i < numOfFieldInfo; i++) |
| 168 | { |
| 169 | FieldInfo *fieldInfo = paramInfoGetFieldInfoByIndex(paramInfo, i); |
| 170 | if (fieldInfo) |
| 171 | { |
| 172 | printf("\t[%lu] ", i); |
| 173 | showFieldInfo(fieldInfo); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | #if 0 |
| 179 | void showCategoryTypeList(AudioType *audioType) |
| 180 | { |
| 181 | xmlNode *categoryTypeListNode, *categoryTypeNode, *categoryNode, *subCategoryNode; |
| 182 | |
| 183 | printf("\n====Dump \"%s\" AudioType CategoryList Info====\n", audioType->name); |
| 184 | categoryTypeListNode = audioTypeGetCategoryTypeListNode(audioType); |
| 185 | if (!categoryTypeListNode) |
| 186 | { |
| 187 | printf("No category type list node!\n"); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | categoryTypeNode = categoryTypeListNode->children; |
| 192 | |
| 193 | while ((categoryTypeNode = findXmlNodeByElemName(categoryTypeNode->next, ELEM_CATEGORY_TYPE))) |
| 194 | { |
| 195 | printf("CategoryType, wording = %s, name = %s\n", xmlNodeGetWording(categoryTypeNode), xmlNodeGetProp(categoryTypeNode, ATTRI_NAME)); |
| 196 | |
| 197 | categoryNode = categoryTypeNode->children; |
| 198 | for (categoryNode = categoryTypeNode->children; categoryNode; categoryNode = categoryNode->next) |
| 199 | { |
| 200 | if (!strcmp((char *)categoryNode->name, ELEM_CATEGORY)) |
| 201 | { |
| 202 | // Show Category |
| 203 | printf("\t%s wording = %s (name = %s)\n", categoryNode->name, xmlNodeGetWording(categoryNode), xmlNodeGetProp(categoryNode, ATTRI_NAME)); |
| 204 | } |
| 205 | else if (!strcmp((char *)categoryNode->name, ELEM_CATEGORY_GROUP)) |
| 206 | { |
| 207 | // Show CategoryGroup |
| 208 | printf("\t%s wording = %s (name = %s)\n", categoryNode->name, xmlNodeGetWording(categoryNode), xmlNodeGetProp(categoryNode, ATTRI_NAME)); |
| 209 | |
| 210 | // Show Category's sub category |
| 211 | for (subCategoryNode = categoryNode->children; subCategoryNode; subCategoryNode = subCategoryNode->next) |
| 212 | { |
| 213 | if (!strcmp((char *)subCategoryNode->name, ELEM_CATEGORY)) |
| 214 | { |
| 215 | printf("\t\t%s wording = %s (name = %s)\n", subCategoryNode->name, xmlNodeGetWording(subCategoryNode), xmlNodeGetProp(subCategoryNode, ATTRI_NAME)); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | #else |
| 223 | void showCategoryTypeList(AudioType *audioType) |
| 224 | { |
| 225 | size_t i, j, k; |
| 226 | size_t numOfCategory; |
| 227 | size_t numOfCategoryType = audioTypeGetNumOfCategoryType(audioType); |
| 228 | |
| 229 | printf("\n====%s AudioType's Category====\n\n", audioType->name); |
| 230 | for (i = 0; i < numOfCategoryType; i++) |
| 231 | { |
| 232 | CategoryType *categoryType = audioTypeGetCategoryTypeByIndex(audioType, i); |
| 233 | |
| 234 | /* Show CategoryGroup part */ |
| 235 | size_t numOfCategoryGroup = categoryTypeGetNumOfCategoryGroup(categoryType); |
| 236 | printf("CategoryType[%zu] name = %s wording = %s %s\n", i, categoryType->name, categoryType->wording, categoryType->visible ? "" : "visible = 0"); |
| 237 | for (j = 0; j < numOfCategoryGroup; j++) |
| 238 | { |
| 239 | /* Show CategoryGroup's category */ |
| 240 | CategoryGroup *categoryGroup = categoryTypeGetCategoryGroupByIndex(categoryType, j); |
| 241 | size_t numOfCategory = categoryGroupGetNumOfCategory(categoryGroup); |
| 242 | printf("\tCategoryGroup[%zu] name = %s wording = %s %s\n", j, categoryGroup->name, categoryGroup->wording, categoryGroup->visible ? "" : "visible = 0"); |
| 243 | for (k = 0; k < numOfCategory; k++) |
| 244 | { |
| 245 | Category *category = categoryGroupGetCategoryByIndex(categoryGroup, k); |
| 246 | printf("\t\tCategory[%zu] name = %s wording = %s %s\n", k , category->name, category->wording, category->visible ? "" : "visible = 0"); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /* Show CategoryType's category */ |
| 251 | numOfCategory = categoryTypeGetNumOfCategory(categoryType); |
| 252 | for (k = 0; k < numOfCategory; k++) |
| 253 | { |
| 254 | Category *category = categoryTypeGetCategoryByIndex(categoryType, k); |
| 255 | printf("\tCategory[%zu] name = %s wording = %s %s\n", k , category->name, category->wording, category->visible ? "" : "visible = 0"); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | #endif |
| 260 | |
| 261 | void showParamFieldInfo(AudioType *audioType) |
| 262 | { |
| 263 | int i; |
| 264 | int numOfParamInfo; |
| 265 | ParamInfo *paramInfo; |
| 266 | |
| 267 | /* Enum all param & it's field information */ |
| 268 | numOfParamInfo = audioTypeGetNumOfParamInfo(audioType); |
| 269 | printf("\n====%s AudioType's param field info====\n\n", audioType->name); |
| 270 | for (i = 0; i < numOfParamInfo; i++) |
| 271 | { |
| 272 | paramInfo = audioTypeGetParamInfoByIndex(audioType, i); |
| 273 | printf("[%d] ", i); |
| 274 | showParamInfo(paramInfo); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | void showParamTreeViewInfo(AudioType *audioType) |
| 279 | { |
| 280 | printf("\n====%s AudioType's param tree view info====\n\n", audioType->name); |
| 281 | if (!audioType->paramTreeView) |
| 282 | { |
| 283 | printf("No definition!\n"); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | printf("ParamTreeView version(%d.%d)\n", audioType->paramTreeView->verMaj, audioType->paramTreeView->verMin); |
| 288 | if (audioType->paramTreeView->treeRootHash) |
| 289 | { |
| 290 | TreeRoot *treeRoot; |
| 291 | Feature *feature; |
| 292 | FeatureField *featureField; |
| 293 | CategoryPath *categoryPath; |
| 294 | size_t i = 0; |
| 295 | /* Enum all TreeRoot */ |
| 296 | for (treeRoot = audioType->paramTreeView->treeRootHash; treeRoot ; treeRoot = treeRoot->hh.next) |
| 297 | { |
| 298 | |
| 299 | printf("+TreeRoot[%d] name = %s\n", i++, treeRoot->name); |
| 300 | if (treeRoot->switchFieldInfo) |
| 301 | { |
| 302 | printf(" +switch (audio_type = %s, param = %s, field = %s)\n", |
| 303 | treeRoot->switchFieldInfo ? treeRoot->switchFieldInfo->paramInfo->audioType->name : "", |
| 304 | treeRoot->switchFieldInfo ? treeRoot->switchFieldInfo->paramInfo->name : "", |
| 305 | treeRoot->switchFieldInfo ? treeRoot->switchFieldInfo->name : ""); |
| 306 | } |
| 307 | else |
| 308 | { |
| 309 | printf(" +no switch\n"); |
| 310 | } |
| 311 | |
| 312 | /* Enum all Feature */ |
| 313 | for (feature = treeRoot->featureHash; feature ; feature = feature->hh.next) |
| 314 | { |
| 315 | printf(" +Feature name = %s, feature_option = %s(val = %s), switch (audio_type = %s, param = %s, field = %s)\n", feature->name, |
| 316 | feature->featureOption, |
| 317 | appHandleGetFeatureOptionValue(audioType->appHandle, feature->featureOption), |
| 318 | feature->switchFieldInfo ? feature->switchFieldInfo->paramInfo->audioType->name : "null", |
| 319 | feature->switchFieldInfo ? feature->switchFieldInfo->paramInfo->name : "null", |
| 320 | feature->switchFieldInfo ? feature->switchFieldInfo->name : "null"); |
| 321 | |
| 322 | /* Enum all field */ |
| 323 | for (featureField = feature->featureFieldHash; featureField ; featureField = featureField->hh.next) |
| 324 | { |
| 325 | printf(" +Field audio_type = %s, param = %s, name = %s\n", |
| 326 | featureField->fieldInfo->paramInfo->audioType->name, |
| 327 | featureField->fieldInfo->paramInfo->name, |
| 328 | featureField->fieldInfo->name); |
| 329 | } |
| 330 | |
| 331 | /* Enum all category path */ |
| 332 | for (categoryPath = feature->categoryPathHash; categoryPath ; categoryPath = categoryPath->hh.next) |
| 333 | { |
| 334 | printf(" +CategoryPath path = %s\n", categoryPath->path); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | void showParamUnit(AudioType *audioType, const char *categoryPath) |
| 342 | { |
| 343 | int i; |
| 344 | int numOfParam; |
| 345 | Param *param; |
| 346 | ParamUnit *paramUnit = audioTypeGetParamUnit(audioType, categoryPath); |
| 347 | if (paramUnit == NULL) |
| 348 | { |
| 349 | printf("Cannot find ParamUnit.\n"); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | /* Example: provide retrieve all param ways */ |
| 355 | numOfParam = paramUnitGetNumOfParam(paramUnit); |
| 356 | printf("\n\n====Query all param unit's param (param unit id = %d)====\n", paramUnit->paramId); |
| 357 | for (i = 0; i < numOfParam; i++) |
| 358 | { |
| 359 | /* Show param info */ |
| 360 | param = paramUnitGetParamByIndex(paramUnit, i); |
| 361 | printf("[%d] ", i); |
| 362 | showParamValue(param); |
| 363 | |
| 364 | /* Show field info */ |
| 365 | showFieldValueOfParam(param); |
| 366 | } |
| 367 | |
| 368 | /* Example: retrieve param by name */ |
| 369 | printf("\n\n====Query specific param (name = %s)====\n", "speech_mode_para"); |
| 370 | param = paramUnitGetParamByName(paramUnit, "speech_mode_para"); |
| 371 | if (param) |
| 372 | { |
| 373 | showParamValue(param); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | void showAllAudioType(AppHandle *appHandle) |
| 378 | { |
| 379 | size_t i; |
| 380 | printf("\n==== List All Audio Type ===\n\n"); |
| 381 | for (i = 0; i < appHandleGetNumOfAudioType(appHandle); i++) |
| 382 | { |
| 383 | AudioType *audioType = appHandleGetAudioTypeByIndex(appHandle, i); |
| 384 | |
| 385 | /* XML Version check for AudioTuningTool */ |
| 386 | if (!audioTypeIsTuningToolSupportedXmlVer(audioType)) |
| 387 | { |
| 388 | printf("Error: %s AudioType's XML version is newer than tuning tool supported ver. (ParamUnitDesc ver (%d,%d), AudioParam ver (%d,%d))\n", audioType->name, audioType->paramUnitDescVerMaj, audioType->paramUnitDescVerMin, audioType->audioParamVerMaj, audioType->audioParamVerMin); |
| 389 | continue; |
| 390 | } |
| 391 | |
| 392 | // Tuning tool support backward compatible, need to know the XML version |
| 393 | printf("AudioType[%lu] : %s (tab name = %s, ParamUnitDesc ver = %d.%d, AudioParam ver = %d.%d)\n", i, audioType->name, audioType->tabName, audioType->paramUnitDescVerMaj, audioType->paramUnitDescVerMin, audioType->audioParamVerMaj, audioType->audioParamVerMin); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | void showAllCategoryInformation(AppHandle *appHandle) |
| 398 | { |
| 399 | size_t i; |
| 400 | for (i = 0; i < appHandleGetNumOfAudioType(appHandle); i++) |
| 401 | { |
| 402 | AudioType *audioType = appHandleGetAudioTypeByIndex(appHandle, i); |
| 403 | |
| 404 | /* Example to retrieve category info */ |
| 405 | showCategoryTypeList(audioType); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | void showAllParamFieldInformation(AppHandle *appHandle) |
| 410 | { |
| 411 | size_t i; |
| 412 | for (i = 0; i < appHandleGetNumOfAudioType(appHandle); i++) |
| 413 | { |
| 414 | AudioType *audioType = appHandleGetAudioTypeByIndex(appHandle, i); |
| 415 | |
| 416 | /* Example to retrieve ParamInfo */ |
| 417 | showParamFieldInfo(audioType); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | void showAllParamTreeInformation(AppHandle *appHandle) |
| 422 | { |
| 423 | size_t i; |
| 424 | for (i = 0; i < appHandleGetNumOfAudioType(appHandle); i++) |
| 425 | { |
| 426 | AudioType *audioType = appHandleGetAudioTypeByIndex(appHandle, i); |
| 427 | |
| 428 | /* Example to retrieve ParamInfo */ |
| 429 | showParamTreeViewInfo(audioType); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | void showFeatureOptions(AppHandle *appHandle) |
| 434 | { |
| 435 | size_t i; |
| 436 | printf("\n===== Feature Option =====\n"); |
| 437 | for (i = 0; i < appHandleGetNumOfFeatureOption(appHandle); i++) |
| 438 | { |
| 439 | FeatureOption *featureOption = appHandleGetFeatureOptionByIndex(appHandle, i); |
| 440 | printf("[%lu] %s = \"%s\" (enabled = %d)\n", i, featureOption->name, featureOption->value, appHandleIsFeatureOptionEnabled(appHandle, featureOption->name)); |
| 441 | } |
| 442 | printf("============================\n"); |
| 443 | } |
| 444 | |
| 445 | void processTreeRootNode(xmlNode *node, int level, TreeRoot *treeRoot, const char *categoryPath) |
| 446 | { |
| 447 | int isFeatureNode = 0; |
| 448 | |
| 449 | if (!node) |
| 450 | { |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | if (node->type == XML_ELEMENT_NODE) |
| 455 | { |
| 456 | /* Show indent first */ |
| 457 | int i = 0; |
| 458 | for (i = 0; i < level; i++) |
| 459 | { |
| 460 | printf(" "); |
| 461 | } |
| 462 | |
| 463 | /* Process each element */ |
| 464 | if (!strcmp(node->name, ELEM_TREE_ROOT)) |
| 465 | { |
| 466 | printf("+<TreeRoot name = %s>\n", xmlNodeGetProp(node, ATTRI_NAME)); |
| 467 | } |
| 468 | else if (!strcmp(node->name, ELEM_SHEET)) |
| 469 | { |
| 470 | /* Show sheet node */ |
| 471 | if (treeRoot->switchFieldInfo) |
| 472 | { |
| 473 | int fieldVal = 0; |
| 474 | int onVal = 0; |
| 475 | |
| 476 | ParamUnit *paramUnit = audioTypeGetParamUnit(treeRoot->paramTreeView->audioType, categoryPath); |
| 477 | paramUnitGetFieldVal(paramUnit, treeRoot->switchFieldInfo->paramInfo->name, treeRoot->switchFieldInfo->name, &fieldVal); |
| 478 | |
| 479 | if ((fieldInfoGetCheckListValue(treeRoot->switchFieldInfo, "on", &onVal) == APP_NO_ERROR) |
| 480 | && onVal == fieldVal) |
| 481 | { |
| 482 | printf("+<\"check\" Sheet %s>\n", categoryPath); // checkbox checked |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | printf("+<\"uncheck\" Sheet %s>\n", categoryPath); // checkbox unchecked |
| 487 | } |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | printf("+<Sheet %s>\n", categoryPath); // no checkbox |
| 492 | } |
| 493 | } |
| 494 | else if (!strcmp(node->name, ELEM_FEATURE)) |
| 495 | { |
| 496 | /* Get Feature obj by name */ |
| 497 | FeatureField *featureField; |
| 498 | int ignore = 0; |
| 499 | Feature *feature = treeRootGetFeatureByName(treeRoot, xmlNodeGetProp(node, ATTRI_NAME)); |
| 500 | isFeatureNode = 1; |
| 501 | |
| 502 | /* Check feature option */ |
| 503 | if (feature->featureOption && !appHandleIsFeatureOptionEnabled(treeRoot->paramTreeView->audioType->appHandle, feature->featureOption)) |
| 504 | { |
| 505 | //printf ("Feature %s unsupport (%s is disabled)\n", feature->name, feature->featureOption); |
| 506 | ignore = 1; |
| 507 | } |
| 508 | |
| 509 | /* Check category path */ |
| 510 | if (!ignore && !featureIsCategoryPathSupport(feature, categoryPath)) |
| 511 | { |
| 512 | //printf ("Feature %s unsupport (%s is not valid category path)\n", feature->name, categoryPath); |
| 513 | ignore = 1; |
| 514 | } |
| 515 | |
| 516 | if (ignore == 0) |
| 517 | { |
| 518 | ParamUnit *paramUnit = audioTypeGetParamUnit(treeRoot->paramTreeView->audioType, categoryPath); |
| 519 | |
| 520 | if (feature->switchFieldInfo) |
| 521 | { |
| 522 | int fieldVal = 0; |
| 523 | int onVal = 0; |
| 524 | |
| 525 | ParamUnit *switchParamUnit = audioTypeGetParamUnit(feature->switchFieldInfo->paramInfo->audioType, categoryPath); |
| 526 | paramUnitGetFieldVal(switchParamUnit, feature->switchFieldInfo->paramInfo->name, feature->switchFieldInfo->name, &fieldVal); |
| 527 | |
| 528 | if ((fieldInfoGetCheckListValue(feature->switchFieldInfo, "on", &onVal) == APP_NO_ERROR) |
| 529 | && onVal == fieldVal) |
| 530 | { |
| 531 | printf("+<\"check\" Feature name = %s>\n", feature->name); // checkbox checked |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | printf("+<\"uncheck\" Feature name = %s>\n", feature->name); // checkbox unchecked |
| 536 | } |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | printf("+<Feature name = %s>\n", feature->name); // no checkbox |
| 541 | } |
| 542 | |
| 543 | for (featureField = feature->featureFieldHash; featureField; featureField = featureField->hh.next) |
| 544 | { |
| 545 | unsigned int fieldVal = 0; |
| 546 | paramUnitGetFieldVal(paramUnit, |
| 547 | featureField->fieldInfo->paramInfo->name, |
| 548 | featureField->fieldInfo->name, |
| 549 | &fieldVal); |
| 550 | |
| 551 | printf(" <Field name = %s, val = %d, check_list=%s>\n", |
| 552 | featureField->fieldInfo->name, |
| 553 | fieldVal, |
| 554 | featureField->fieldInfo->checkListStr); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | else |
| 559 | { |
| 560 | printf("+<%s>\n", node->name); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if (level && node->next) |
| 565 | { |
| 566 | processTreeRootNode(node->next, level, treeRoot, categoryPath); |
| 567 | } |
| 568 | |
| 569 | if (!isFeatureNode && node->children) |
| 570 | { |
| 571 | processTreeRootNode(node->children, level + 1, treeRoot, categoryPath); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | /* Notice: it's just example, the num of categoryType may be 4, 5... you have to get the category path more flexible */ |
| 576 | char *queryCategoryPathByWording(AppHandle *appHandle, const char *audioTypeName, const char *categoryType1Wording, const char *category1Wording, const char *categoryType2Wording, const char *categoryGroup2Wording, const char *category2Wording, const char *categoryType3Wording, const char *categoryGroup3Wording, const char *category3Wording) |
| 577 | { |
| 578 | char *result; |
| 579 | UT_string *searchPath = NULL; |
| 580 | CategoryType *categoryType = NULL; |
| 581 | CategoryGroup *categoryGroup = NULL; |
| 582 | Category *category = NULL; |
| 583 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName); |
| 584 | |
| 585 | /* If user select a category path, just like "NarrowBand / Normal of Handset / Level0" */ |
| 586 | utstring_new(searchPath); |
| 587 | |
| 588 | /* Query first category type name & category name */ |
| 589 | if (audioType) |
| 590 | { |
| 591 | categoryType = audioTypeGetCategoryTypeByName(audioType, categoryType1Wording); |
| 592 | } |
| 593 | if (categoryType) |
| 594 | { |
| 595 | category = categoryTypeGetCategoryByWording(categoryType, category1Wording); |
| 596 | utstring_printf(searchPath, "%s,%s,", categoryType->name, category->name); |
| 597 | } |
| 598 | |
| 599 | /* Query 2nd category type name & category name (include category group)*/ |
| 600 | categoryGroup = NULL; |
| 601 | categoryGroup = NULL; |
| 602 | |
| 603 | if (audioType) |
| 604 | { |
| 605 | categoryType = audioTypeGetCategoryTypeByName(audioType, categoryType2Wording); |
| 606 | } |
| 607 | if (audioType) |
| 608 | { |
| 609 | categoryGroup = categoryTypeGetCategoryGroupByWording(categoryType, categoryGroup2Wording); |
| 610 | } |
| 611 | if (categoryGroup) |
| 612 | { |
| 613 | category = categoryGroupGetCategoryByWording(categoryGroup, category2Wording); |
| 614 | if (category) |
| 615 | { |
| 616 | utstring_printf(searchPath, "%s,%s,", categoryType->name, category->name); |
| 617 | } |
| 618 | else |
| 619 | { |
| 620 | printf("Error: Cannot find \"%s\" category from \"%s\" category group.\n", category2Wording, categoryGroup->name); |
| 621 | utstring_free(searchPath); |
| 622 | return NULL; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | /* Query 3nd category type name & category name */ |
| 627 | categoryGroup = NULL; |
| 628 | categoryGroup = NULL; |
| 629 | |
| 630 | if (audioType) |
| 631 | { |
| 632 | categoryType = audioTypeGetCategoryTypeByWording(audioType, categoryType3Wording); |
| 633 | } |
| 634 | if (categoryType) |
| 635 | { |
| 636 | categoryGroup = categoryTypeGetCategoryGroupByWording(categoryType, categoryGroup3Wording); |
| 637 | } |
| 638 | if (categoryGroup) |
| 639 | { |
| 640 | category = categoryGroupGetCategoryByWording(categoryGroup, category3Wording); |
| 641 | utstring_printf(searchPath, "%s,%s", categoryType->name, category->name); |
| 642 | } |
| 643 | |
| 644 | if (searchPath) |
| 645 | { |
| 646 | result = strdup(utstring_body(searchPath)); |
| 647 | //printf("==> The param unit search path = %s\n", result); |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | printf("Error: cannot get the category path\n"); |
| 652 | } |
| 653 | |
| 654 | utstring_free(searchPath); |
| 655 | |
| 656 | return result; |
| 657 | } |
| 658 | |
| 659 | void queryFieldValue(AppHandle *appHandle, const char *targetAudioTypeName, const char *categoryPath, const char *paramName, const char *fieldName) |
| 660 | { |
| 661 | unsigned int fieldValue; |
| 662 | ParamUnit *paramUnit; |
| 663 | |
| 664 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, targetAudioTypeName); |
| 665 | |
| 666 | /* Query the ParamUnit */ |
| 667 | paramUnit = audioTypeGetParamUnit(audioType, categoryPath); |
| 668 | |
| 669 | /* Query the field value */ |
| 670 | if (paramUnitGetFieldVal(paramUnit, paramName, fieldName, &fieldValue) == APP_ERROR) |
| 671 | { |
| 672 | printf("Error: Cannot query field value successfully!!\n"); |
| 673 | } |
| 674 | else |
| 675 | { |
| 676 | printf("Field value = 0x%x (%s/%s)\n", fieldValue, paramName, fieldName); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | void simpleFieldQuery(AppHandle *appHandle) |
| 681 | { |
| 682 | unsigned int fieldValue; |
| 683 | ParamUnit *paramUnit; |
| 684 | Param *param; |
| 685 | FieldInfo *fieldInfo; |
| 686 | |
| 687 | const char *targetAudioTypeName = "Speech"; |
| 688 | const char *targetParamName = "speech_mode_para"; |
| 689 | const char *targetFieldName = "DL Digital Gain"; |
| 690 | |
| 691 | /* Example of category combination */ |
| 692 | const char *categoryType1Wording = "Bandwidth"; |
| 693 | const char *category1Wording = "Narrow Band"; |
| 694 | |
| 695 | const char *categoryType2Wording = "Profile"; |
| 696 | const char *categoryGroup2Wording = "Handset"; |
| 697 | const char *category2Wording = "Handset"; |
| 698 | |
| 699 | const char *categoryType3Wording = "Volume"; |
| 700 | const char *categoryGroup3Wording = "Index"; |
| 701 | const char *category3Wording = "Level0"; |
| 702 | |
| 703 | /* Query category path */ |
| 704 | char *categoryPath = queryCategoryPathByWording(appHandle, targetAudioTypeName, categoryType1Wording, category1Wording, categoryType2Wording, categoryGroup2Wording, category2Wording, categoryType3Wording, categoryGroup3Wording, category3Wording); |
| 705 | |
| 706 | /* Query AudioType */ |
| 707 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, targetAudioTypeName); |
| 708 | if (!audioType) |
| 709 | { |
| 710 | free(categoryPath); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | /* Read lock */ |
| 715 | audioTypeReadLock(audioType, __FUNCTION__); |
| 716 | |
| 717 | /* Query the ParamUnit */ |
| 718 | paramUnit = audioTypeGetParamUnit(audioType, categoryPath); |
| 719 | if (!paramUnit) |
| 720 | { |
| 721 | free(categoryPath); |
| 722 | audioTypeUnlock(audioType); |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | printf("\n\n==== Simple Test Query ====\n"); |
| 727 | printf("AudioType/Param/Field = %s / %s / %s\n", targetAudioTypeName, targetParamName, targetFieldName); |
| 728 | printf("Category path = %s\n", categoryPath); |
| 729 | |
| 730 | /* Query the param value */ |
| 731 | param = paramUnitGetParamByName(paramUnit, "speech_mode_para"); |
| 732 | if (!param) |
| 733 | { |
| 734 | printf("Error: Cannot query param value!\n"); |
| 735 | free(categoryPath); |
| 736 | audioTypeUnlock(audioType); |
| 737 | return; |
| 738 | } |
| 739 | showParamValue(param); |
| 740 | |
| 741 | /* Query the field value */ |
| 742 | if (paramUnitGetFieldVal(paramUnit, targetParamName, targetFieldName, &fieldValue) == APP_ERROR) |
| 743 | { |
| 744 | printf("Error: Cannot query field value!!\n"); |
| 745 | free(categoryPath); |
| 746 | audioTypeUnlock(audioType); |
| 747 | return; |
| 748 | } |
| 749 | |
| 750 | /* Query the field's check list */ |
| 751 | fieldInfo = paramInfoGetFieldInfoByName(param->paramInfo, targetFieldName); |
| 752 | if (fieldInfo) |
| 753 | { |
| 754 | printf("==> Field val = %x (check_list = %s)\n", fieldValue, fieldInfo->checkListStr); |
| 755 | } |
| 756 | else |
| 757 | { |
| 758 | printf("Error: Cannot find the fieldInfo!\n"); |
| 759 | } |
| 760 | |
| 761 | free(categoryPath); |
| 762 | |
| 763 | /* Unlock */ |
| 764 | audioTypeUnlock(audioType); |
| 765 | } |
| 766 | |
| 767 | void simpleParamQuery(AppHandle *appHandle) |
| 768 | { |
| 769 | /* Query category path */ |
| 770 | char *audioTypeName = "Speech"; |
| 771 | char *categoryPath = "Band,NB,Profile,4_pole_Headset,VolIndex,3"; |
| 772 | char *paramName = "speech_mode_para"; |
| 773 | ParamUnit *paramUnit; |
| 774 | Param *param; |
| 775 | |
| 776 | /* Query AudioType */ |
| 777 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName); |
| 778 | if (!audioType) |
| 779 | { |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | /* Read Lock */ |
| 784 | audioTypeReadLock(audioType, __FUNCTION__); |
| 785 | |
| 786 | /* Query the ParamUnit */ |
| 787 | paramUnit = audioTypeGetParamUnit(audioType, categoryPath); |
| 788 | if (!paramUnit) |
| 789 | { |
| 790 | return; |
| 791 | } |
| 792 | |
| 793 | printf("\n\n==== Simple Test Query ====\n"); |
| 794 | printf("AudioType/Param/Field = %s / %s\n", audioTypeName, paramName); |
| 795 | printf("Category path = %s\n", categoryPath); |
| 796 | |
| 797 | /* Query the param value */ |
| 798 | param = paramUnitGetParamByName(paramUnit, paramName); |
| 799 | if (!param) |
| 800 | { |
| 801 | printf("Error: Cannot query param value!\n"); |
| 802 | return; |
| 803 | } |
| 804 | showParamValue(param); |
| 805 | |
| 806 | /* Read unlock */ |
| 807 | audioTypeUnlock(audioType); |
| 808 | } |
| 809 | |
| 810 | void simpleParamUpdate(AppHandle *appHandle) |
| 811 | { |
| 812 | unsigned short shortArray[] = {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888, 0x9999, 0x0000}; |
| 813 | int arraySize = 10; |
| 814 | |
| 815 | /* You should cache follow object in somewhere without query again */ |
| 816 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, "Speech"); |
| 817 | ParamInfo *paramInfo = audioTypeGetParamInfoByName(audioType, "sph_in_fir"); |
| 818 | |
| 819 | /* The sph_in_fir param is short array type */ |
| 820 | if (audioTypeSetParamData(audioType, "Band,NB,Profile,HAC,VolIndex,3,Network,GSM", paramInfo, (void *)shortArray, arraySize) == APP_ERROR) |
| 821 | { |
| 822 | printf("Cannot update the param data!!\n"); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | void simpleFieldUpdate(AppHandle *appHandle) |
| 827 | { |
| 828 | unsigned int fieldVal = 0xff; |
| 829 | |
| 830 | /* You should cache follow object in somewhere without query again */ |
| 831 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, "Speech"); |
| 832 | ParamInfo *paramInfo = audioTypeGetParamInfoByName(audioType, "speech_mode_para"); |
| 833 | FieldInfo *fieldInfo = paramInfoGetFieldInfoByName(paramInfo, "DL Digital Gain"); |
| 834 | |
| 835 | /* Update the fieldInfo for specific categoryPath */ |
| 836 | if (audioTypeSetFieldData(audioType, "Band,NB,Profile,HAC,VolIndex,3,Network,GSM", fieldInfo, fieldVal) == APP_ERROR) |
| 837 | { |
| 838 | printf("Cannot update the field data!!\n"); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | void applyParamUnitToCategory(AppHandle *appHandle) |
| 843 | { |
| 844 | const char *srcCategoryPath = "Band,NB,Profile,HAC,VolIndex,3,Network,GSM"; |
| 845 | const char *dstCategoryPath = "Band,NB,Profile,HAC,VolIndex,4,Network,GSM"; |
| 846 | |
| 847 | /* Query AudioType */ |
| 848 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, "Speech"); |
| 849 | |
| 850 | /* Apply the ParamUnit */ |
| 851 | audioTypeParamUnitCopy(audioType, srcCategoryPath, dstCategoryPath); |
| 852 | } |
| 853 | |
| 854 | void saveModifiedAudioParamXml(AppHandle *appHandle, const char *folder) |
| 855 | { |
| 856 | size_t i; |
| 857 | for (i = 0; i < appHandleGetNumOfAudioType(appHandle); i++) |
| 858 | { |
| 859 | AudioType *audioType = appHandleGetAudioTypeByIndex(appHandle, i); |
| 860 | |
| 861 | /* Read lock */ |
| 862 | audioTypeReadLock(audioType, __FUNCTION__); |
| 863 | |
| 864 | if (audioType->dirty && audioTypeSaveAudioParamXml(audioType, folder, 1) == APP_ERROR) |
| 865 | { |
| 866 | printf("Error: cannot save audio param XML to %s dir\n", folder); |
| 867 | } |
| 868 | |
| 869 | /* Unlock */ |
| 870 | audioTypeUnlock(audioType); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | void xmlChangedCallback(AppHandle *appHandle, const char *audioTypeName) |
| 875 | { |
| 876 | printf("XML file changed. (cus folder = %s, audioType = %s)\n", appHandle->xmlCusDir, audioTypeName); |
| 877 | |
| 878 | // reload XML file |
| 879 | if (appHandleReloadAudioType(appHandle, audioTypeName) == APP_ERROR) |
| 880 | { |
| 881 | printf("Reload xml fail! (audioType = %s)\n", audioTypeName); |
| 882 | } |
| 883 | else |
| 884 | { |
| 885 | #if 0 |
| 886 | AudioType *audioType; |
| 887 | ParamUnit *paramUnit; |
| 888 | Param *param; |
| 889 | |
| 890 | printf("Reload XML done. (audioType = %s)\n", audioTypeName); |
| 891 | |
| 892 | /* Query AudioType */ |
| 893 | audioType = appHandleGetAudioTypeByName(appHandle, audioTypeName); |
| 894 | if (!audioType) |
| 895 | { |
| 896 | printf("Cannot find %s audio type\n", audioTypeName); |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | /* Query the ParamUnit */ |
| 901 | paramUnit = audioTypeGetParamUnit(audioType, "Band,NB,Profile,Normal,VolIndex,0,Network,GSM"); |
| 902 | if (!paramUnit) |
| 903 | { |
| 904 | printf("Cannot find paramUnit\n"); |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | /* Query the param value */ |
| 909 | param = paramUnitGetParamByName(paramUnit, "speech_mode_para"); |
| 910 | if (!param) |
| 911 | { |
| 912 | printf("Error: Cannot query param value!\n"); |
| 913 | return; |
| 914 | } |
| 915 | showParamValue(param); |
| 916 | #else |
| 917 | printf("Reload XML done. (audioType = %s)\n", audioTypeName); |
| 918 | utilUsleep(2000000); |
| 919 | printf("Sleep 2 sec done...\n"); |
| 920 | #endif |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | int showDynamicTest(AppHandle *appHandle) |
| 925 | { |
| 926 | AudioType *audioType = NULL; |
| 927 | char *categoryPath = NULL; |
| 928 | char *paramName = NULL; |
| 929 | ParamUnit *paramUnit = NULL; |
| 930 | ParamInfo *paramInfo = NULL; |
| 931 | FieldInfo *fieldInfo = NULL; |
| 932 | Param *param = NULL; |
| 933 | void *paramData = NULL; |
| 934 | size_t arraySize = 0; |
| 935 | char tmp[BUF_SIZE]; |
| 936 | char *input; |
| 937 | unsigned int fieldValue = 0; |
| 938 | |
| 939 | printf("\n\n====== Dynamic Test =====\n"); |
| 940 | printf("[0] Back to main menu\n"); |
| 941 | printf("[1] Get param value\n"); |
| 942 | printf("[2] Set param value\n"); |
| 943 | printf("[3] Get field value\n"); |
| 944 | printf("[4] Set field value\n"); |
| 945 | printf("[5] ParamUnit copy\n"); |
| 946 | printf("[6] Save xml\n"); |
| 947 | printf("[7] Show param tree view\n"); |
| 948 | printf("[8] Set switchField on/off \n"); |
| 949 | printf("[9] Compress files\n"); |
| 950 | printf("[10] UnCompress file\n"); |
| 951 | printf("==========================\n"); |
| 952 | printf("Please enter the selection: "); |
| 953 | input = utilGetStdin(tmp, BUF_SIZE); |
| 954 | |
| 955 | if (!strcmp(input, "0")) |
| 956 | { |
| 957 | return 0; |
| 958 | } |
| 959 | else if (!strcmp(input, "1")) |
| 960 | { |
| 961 | printf("Enter audio type name (eg. Speech):"); |
| 962 | input = utilGetStdin(tmp, BUF_SIZE); |
| 963 | |
| 964 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 965 | if (audioType) |
| 966 | { |
| 967 | printf("Enter category path (eg. Band,NB,Profile,4_pole_Headset,VolIndex,3,Network,GSM):"); |
| 968 | input = utilGetStdin(tmp, BUF_SIZE); |
| 969 | |
| 970 | /* Read lock */ |
| 971 | audioTypeReadLock(audioType, __FUNCTION__); |
| 972 | |
| 973 | paramUnit = audioTypeGetParamUnit(audioType, input); |
| 974 | if (paramUnit) |
| 975 | { |
| 976 | printf("Enter param name (eg. speech_mode_para):"); |
| 977 | input = utilGetStdin(tmp, BUF_SIZE); |
| 978 | |
| 979 | param = paramUnitGetParamByName(paramUnit, input); |
| 980 | if (param) |
| 981 | { |
| 982 | showParamValue(param); |
| 983 | } |
| 984 | else |
| 985 | { |
| 986 | printf("Error: Cannot find the param!\n"); |
| 987 | } |
| 988 | } |
| 989 | else |
| 990 | { |
| 991 | printf("Error: Cannot find the param unit!\n"); |
| 992 | } |
| 993 | |
| 994 | /* Unlock */ |
| 995 | audioTypeUnlock(audioType); |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | printf("Error: no such audio type\n"); |
| 1000 | } |
| 1001 | } |
| 1002 | else if (!strcmp(input, "2")) |
| 1003 | { |
| 1004 | printf("Enter audio type name (eg. Speech):"); |
| 1005 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1006 | |
| 1007 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 1008 | if (audioType) |
| 1009 | { |
| 1010 | printf("Enter param name (eg. speech_mode_para):"); |
| 1011 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1012 | |
| 1013 | paramInfo = audioTypeGetParamInfoByName(audioType, input); |
| 1014 | if (paramInfo) |
| 1015 | { |
| 1016 | printf("Enter category path (eg. Band,NB,Profile,4_pole_Headset,VolIndex,3,Network,GSM):"); |
| 1017 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1018 | |
| 1019 | categoryPath = strdup(input); |
| 1020 | |
| 1021 | printf("Enter param value (type:%s):", paramDataTypeToStr(paramInfo->dataType)); |
| 1022 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1023 | |
| 1024 | if (utilConvDataStringToNative(paramInfo->dataType, input, ¶mData, &arraySize) == APP_NO_ERROR) |
| 1025 | { |
| 1026 | /* The sph_in_fir param is short array type */ |
| 1027 | if (audioTypeSetParamData(audioType, categoryPath, paramInfo, (void *)paramData, arraySize) == APP_ERROR) |
| 1028 | { |
| 1029 | printf("Cannot update the param data!!\n"); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | free(categoryPath); |
| 1034 | } |
| 1035 | else |
| 1036 | { |
| 1037 | printf("Error: cannot find the param!\n"); |
| 1038 | } |
| 1039 | } |
| 1040 | else |
| 1041 | { |
| 1042 | printf("Error: no such audio type\n"); |
| 1043 | } |
| 1044 | } |
| 1045 | else if (!strcmp(input, "3")) |
| 1046 | { |
| 1047 | printf("Enter audio type name (eg. Speech):"); |
| 1048 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1049 | |
| 1050 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 1051 | if (audioType) |
| 1052 | { |
| 1053 | printf("Enter category path (eg. Band,NB,Profile,4_pole_Headset,VolIndex,3,Network,GSM):"); |
| 1054 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1055 | |
| 1056 | /* Read lock */ |
| 1057 | audioTypeReadLock(audioType, __FUNCTION__); |
| 1058 | |
| 1059 | paramUnit = audioTypeGetParamUnit(audioType, input); |
| 1060 | if (paramUnit) |
| 1061 | { |
| 1062 | printf("Enter param name (eg. speech_mode_para):"); |
| 1063 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1064 | |
| 1065 | paramInfo = audioTypeGetParamInfoByName(audioType, input); |
| 1066 | if (paramInfo) |
| 1067 | { |
| 1068 | printf("Enter field name (eg. DL Digital Gain):"); |
| 1069 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1070 | |
| 1071 | if (paramUnitGetFieldVal(paramUnit, paramInfo->name, input, &fieldValue) == APP_ERROR) |
| 1072 | { |
| 1073 | printf("Error: Cannot query field value!\n"); |
| 1074 | } |
| 1075 | else |
| 1076 | { |
| 1077 | printf("Field value = 0x%x\n", fieldValue); |
| 1078 | } |
| 1079 | } |
| 1080 | else |
| 1081 | { |
| 1082 | printf("Error: Cannot find the param!\n"); |
| 1083 | } |
| 1084 | } |
| 1085 | else |
| 1086 | { |
| 1087 | printf("Error: Cannot find the param unit!\n"); |
| 1088 | } |
| 1089 | |
| 1090 | /* Unlock */ |
| 1091 | audioTypeUnlock(audioType); |
| 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | printf("Error: no such audio type\n"); |
| 1096 | } |
| 1097 | } |
| 1098 | else if (!strcmp(input, "4")) |
| 1099 | { |
| 1100 | printf("Enter audio type name (eg. Speech):"); |
| 1101 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1102 | |
| 1103 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 1104 | if (audioType) |
| 1105 | { |
| 1106 | printf("Enter category path (eg. Band,NB,Profile,4_pole_Headset,VolIndex,3,Network,GSM):"); |
| 1107 | categoryPath = strdup(utilGetStdin(tmp, BUF_SIZE)); |
| 1108 | |
| 1109 | printf("Enter param name (eg. speech_mode_para):"); |
| 1110 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1111 | |
| 1112 | paramInfo = audioTypeGetParamInfoByName(audioType, input); |
| 1113 | if (paramInfo) |
| 1114 | { |
| 1115 | printf("Enter field name (eg. DL Digital Gain):"); |
| 1116 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1117 | |
| 1118 | fieldInfo = paramInfoGetFieldInfoByName(paramInfo, input); |
| 1119 | if (fieldInfo) |
| 1120 | { |
| 1121 | printf("Enter field value:"); |
| 1122 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1123 | |
| 1124 | if (audioTypeSetFieldData(audioType, categoryPath, fieldInfo, strtoul(input, NULL, 0)) == APP_NO_ERROR) |
| 1125 | { |
| 1126 | printf("Set field value = 0x%zx\n", strtoul(input, NULL, 0)); |
| 1127 | } |
| 1128 | else |
| 1129 | { |
| 1130 | printf("Error: Cannot set field value!\n"); |
| 1131 | } |
| 1132 | } |
| 1133 | else |
| 1134 | { |
| 1135 | printf("Error: Cannot find the field!\n"); |
| 1136 | } |
| 1137 | } |
| 1138 | else |
| 1139 | { |
| 1140 | printf("Error: Cannot find the param!\n"); |
| 1141 | } |
| 1142 | |
| 1143 | free(categoryPath); |
| 1144 | } |
| 1145 | else |
| 1146 | { |
| 1147 | printf("Error: no such audio type\n"); |
| 1148 | } |
| 1149 | } |
| 1150 | else if (!strcmp(input, "5")) |
| 1151 | { |
| 1152 | printf("Enter audio type name (eg. Speech):"); |
| 1153 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1154 | |
| 1155 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 1156 | if (audioType) |
| 1157 | { |
| 1158 | char *src = NULL; |
| 1159 | printf("Enter src category path (eg. Band,NB,Profile,HAC,VolIndex,3,Network,GSM):"); |
| 1160 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1161 | src = strdup(input); |
| 1162 | |
| 1163 | printf("Enter dst category path (eg. Band,NB,Profile,HAC,VolIndex,4,Network,GSM):"); |
| 1164 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1165 | |
| 1166 | if (audioTypeParamUnitCopy(audioType, src, input)) |
| 1167 | { |
| 1168 | printf("ParamUnit copied\n"); |
| 1169 | } |
| 1170 | else |
| 1171 | { |
| 1172 | printf("Error: Cannot copy paramUnit!\n"); |
| 1173 | } |
| 1174 | |
| 1175 | free(src); |
| 1176 | } |
| 1177 | else |
| 1178 | { |
| 1179 | printf("Error: no such audio type\n"); |
| 1180 | } |
| 1181 | } |
| 1182 | else if (!strcmp(input, "6")) |
| 1183 | { |
| 1184 | printf("Enter audio type name (eg. Speech):"); |
| 1185 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1186 | |
| 1187 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 1188 | if (audioType) |
| 1189 | { |
| 1190 | |
| 1191 | #ifdef WIN32 |
| 1192 | printf("Enter folder to save XML (eg. .\\cus):"); |
| 1193 | #else |
| 1194 | printf("Enter folder to save XML (eg. /sdcard/.audio_param/):"); |
| 1195 | #endif |
| 1196 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1197 | |
| 1198 | /* Read lock */ |
| 1199 | audioTypeReadLock(audioType, __FUNCTION__); |
| 1200 | |
| 1201 | /* Save changed AudioType to XML */ |
| 1202 | audioTypeSaveAudioParamXml(audioType, input, 1); |
| 1203 | |
| 1204 | /* Unlock */ |
| 1205 | audioTypeUnlock(audioType); |
| 1206 | } |
| 1207 | else |
| 1208 | { |
| 1209 | printf("Error: no such audio type\n"); |
| 1210 | } |
| 1211 | } |
| 1212 | else if (!strcmp(input, "7")) |
| 1213 | { |
| 1214 | char *treeRootName; |
| 1215 | AudioType *audioType; |
| 1216 | |
| 1217 | printf("Enter audio type name (eg. Speech):"); |
| 1218 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1219 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 1220 | if (audioType) |
| 1221 | { |
| 1222 | TreeRoot *treeRoot; |
| 1223 | printf("Enter tree root name (eg. NREC):"); |
| 1224 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1225 | treeRootName = strdup(input); |
| 1226 | treeRoot = audioTypeGetTreeRoot(audioType, treeRootName); |
| 1227 | if (treeRoot) |
| 1228 | { |
| 1229 | printf("Enter category path (eg. Band,NB,Profile,HAC,VolIndex,3,Network,GSM):"); |
| 1230 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1231 | |
| 1232 | /* Show tree root */ |
| 1233 | processTreeRootNode(treeRoot->treeRootNode, 0, treeRoot, input); |
| 1234 | } |
| 1235 | else |
| 1236 | { |
| 1237 | printf("Error: Cannot find the %s tree root!\n", treeRootName); |
| 1238 | } |
| 1239 | free(treeRootName); |
| 1240 | } |
| 1241 | else |
| 1242 | { |
| 1243 | printf("Error: Cannot find %s audio type!\n", input); |
| 1244 | } |
| 1245 | } |
| 1246 | else if (!strcmp(input, "8")) |
| 1247 | { |
| 1248 | printf("Enter audio type name (eg. Speech):"); |
| 1249 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1250 | |
| 1251 | audioType = appHandleGetAudioTypeByName(appHandle, input); |
| 1252 | if (audioType) |
| 1253 | { |
| 1254 | printf("Enter category path (eg. Band,NB,Profile,4_pole_Headset,VolIndex,3,Network,GSM):"); |
| 1255 | categoryPath = strdup(utilGetStdin(tmp, BUF_SIZE)); |
| 1256 | |
| 1257 | printf("Enter param name (eg. speech_mode_para):"); |
| 1258 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1259 | |
| 1260 | paramInfo = audioTypeGetParamInfoByName(audioType, input); |
| 1261 | if (paramInfo) |
| 1262 | { |
| 1263 | FieldInfo *switchFieldInfo; |
| 1264 | printf("Enter field name (eg. switch):"); |
| 1265 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1266 | |
| 1267 | switchFieldInfo = paramInfoGetFieldInfoByName(paramInfo, input); |
| 1268 | |
| 1269 | /* For parameter tree, you can get the fieldInfo by treeRoot->switchFieldInfo & feature-> switchFieldInfo*/ |
| 1270 | if (switchFieldInfo) |
| 1271 | { |
| 1272 | printf("Enter switch on/off (1/0):"); |
| 1273 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1274 | |
| 1275 | if (!strcmp(input, "1")) |
| 1276 | { |
| 1277 | /* Get the check list on's value */ |
| 1278 | unsigned int onValue; |
| 1279 | if (fieldInfoGetCheckListValue(switchFieldInfo, "on", &onValue) == APP_ERROR) |
| 1280 | { |
| 1281 | printf("Error: Cannot get the check list's on value! (XML should define the on's value)\n"); |
| 1282 | } |
| 1283 | else |
| 1284 | { |
| 1285 | /* Set the field with on's value */ |
| 1286 | if (audioTypeSetFieldData(switchFieldInfo->paramInfo->audioType, categoryPath, switchFieldInfo, onValue) == APP_ERROR) |
| 1287 | { |
| 1288 | printf("Cannot set the filed data successfully!\n"); |
| 1289 | } |
| 1290 | else |
| 1291 | { |
| 1292 | printf("Set the field data successfully!\n"); |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | else |
| 1297 | { |
| 1298 | /* Get the check list off's value */ |
| 1299 | unsigned int offValue; |
| 1300 | if (fieldInfoGetCheckListValue(switchFieldInfo, "off", &offValue) == APP_ERROR) |
| 1301 | { |
| 1302 | printf("Error: Cannot get the check list's off value! (XML should define the off's value)\n"); |
| 1303 | } |
| 1304 | else |
| 1305 | { |
| 1306 | /* Set the field with off's value */ |
| 1307 | if (audioTypeSetFieldData(switchFieldInfo->paramInfo->audioType, categoryPath, switchFieldInfo, offValue) == APP_ERROR) |
| 1308 | { |
| 1309 | printf("Cannot set the filed data successfully!\n"); |
| 1310 | } |
| 1311 | else |
| 1312 | { |
| 1313 | printf("Set the field data successfully!\n"); |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | } |
| 1318 | else |
| 1319 | { |
| 1320 | printf("Error: Cannot find the field!\n"); |
| 1321 | } |
| 1322 | } |
| 1323 | else |
| 1324 | { |
| 1325 | printf("Error: No fieldInfo found!\n"); |
| 1326 | } |
| 1327 | |
| 1328 | free(categoryPath); |
| 1329 | } |
| 1330 | else |
| 1331 | { |
| 1332 | printf("Error: no such audio type\n"); |
| 1333 | } |
| 1334 | } |
| 1335 | else if (!strcmp(input, "9")) |
| 1336 | { |
| 1337 | char* srcDir; |
| 1338 | char* dstFile; |
| 1339 | printf("Enter compress folder full path: "); |
| 1340 | srcDir = strdup(utilGetStdin(tmp, BUF_SIZE)); |
| 1341 | |
| 1342 | printf("Enter target file full path: "); |
| 1343 | dstFile = strdup(utilGetStdin(tmp, BUF_SIZE)); |
| 1344 | |
| 1345 | if (appHandleCompressFiles(srcDir, dstFile) == APP_ERROR) |
| 1346 | { |
| 1347 | printf("File compress fail\n"); |
| 1348 | } else { |
| 1349 | printf("File compress done\n"); |
| 1350 | } |
| 1351 | free(srcDir); |
| 1352 | free(dstFile); |
| 1353 | } |
| 1354 | else if (!strcmp(input, "10")) |
| 1355 | { |
| 1356 | char* srcFile; |
| 1357 | char* dstDir; |
| 1358 | printf("Enter src file full path: "); |
| 1359 | srcFile = strdup(utilGetStdin(tmp, BUF_SIZE)); |
| 1360 | |
| 1361 | printf("Enter target dir full path: "); |
| 1362 | dstDir = strdup(utilGetStdin(tmp, BUF_SIZE)); |
| 1363 | |
| 1364 | if (appHandleUncompressFile(srcFile, dstDir) == APP_ERROR) |
| 1365 | { |
| 1366 | printf("File uncompress fail\n"); |
| 1367 | } else { |
| 1368 | printf("File uncompress done\n"); |
| 1369 | } |
| 1370 | free(srcFile); |
| 1371 | free(dstDir); |
| 1372 | } |
| 1373 | return 1; |
| 1374 | } |
| 1375 | |
| 1376 | void testAppLibAPIs() |
| 1377 | { |
| 1378 | AppHandle *appHandle = appHandleGetInstance(); |
| 1379 | int oldDebugLevel = appGetDebugLevel(); |
| 1380 | AudioType *audioType = appHandleGetAudioTypeByName(appHandle, "Speech"); |
| 1381 | ParamInfo *paramInfo = audioTypeGetParamInfoByName(audioType, "speech_mode_para"); |
| 1382 | FieldInfo *fieldInfo = paramInfoGetFieldInfoByName(paramInfo, "AEC"); |
| 1383 | |
| 1384 | /* Change level to debug */ |
| 1385 | appSetDebugLevel(DEBUG_LEVEL); |
| 1386 | |
| 1387 | /* Set AEC field */ |
| 1388 | audioTypeSetFieldData(audioType, "Band,NB,Profile,Normal,VolIndex,3,Network,GSM", fieldInfo, 0xbd); |
| 1389 | |
| 1390 | /* Copy ParamUnit src = dst */ |
| 1391 | audioTypeParamUnitCopy(audioType, "Band,NB,Profile,Normal,VolIndex,3,Network,GSM", "Band,NB,Profile,Normal,VolIndex,3,Network,GSM"); |
| 1392 | |
| 1393 | /* Copy ParamUnit src != dst */ |
| 1394 | audioTypeParamUnitCopy(audioType, "Band,NB,Profile,Normal,VolIndex,3,Network,GSM", "Band,NB,Profile,HAC,VolIndex,3,Network,GSM"); |
| 1395 | |
| 1396 | /* Query param */ |
| 1397 | simpleParamQuery(appHandle); |
| 1398 | |
| 1399 | /* Retrieve specific audio type's param & field information */ |
| 1400 | simpleFieldQuery(appHandle); |
| 1401 | |
| 1402 | /* Query non-exist ParamUnit, it shouldn't crash */ |
| 1403 | audioTypeGetParamUnit(audioType, "aaa,bbb"); |
| 1404 | |
| 1405 | /* Update param value */ |
| 1406 | simpleParamUpdate(appHandle); |
| 1407 | |
| 1408 | /* Update field value */ |
| 1409 | simpleFieldUpdate(appHandle); |
| 1410 | |
| 1411 | /* Apply param to other category */ |
| 1412 | applyParamUnitToCategory(appHandle); |
| 1413 | |
| 1414 | #ifndef WIN32 |
| 1415 | /* Save changed AudioType to XML */ |
| 1416 | saveModifiedAudioParamXml(appHandle, XML_CUS_FOLDER_ON_DEVICE); |
| 1417 | #else |
| 1418 | /* Save changed AudioType to XML */ |
| 1419 | saveModifiedAudioParamXml(appHandle, XML_CUS_FOLDER_ON_TUNING_TOOL); |
| 1420 | #endif |
| 1421 | appSetDebugLevel(oldDebugLevel); |
| 1422 | } |
| 1423 | |
| 1424 | void testUtilNativeAPIs() |
| 1425 | { |
| 1426 | APP_STATUS status; |
| 1427 | unsigned int fieldResult = 0; |
| 1428 | char *strResult; |
| 1429 | |
| 1430 | /* Get category string */ |
| 1431 | strResult = utilNativeGetCategory("Speech", "Band"); |
| 1432 | printf("Category result = %s\n", strResult); |
| 1433 | #ifndef WIN32 |
| 1434 | free(strResult); |
| 1435 | #else |
| 1436 | printf("Cannot free the memory allocated by APP on WIN32, just for testing\n"); |
| 1437 | #endif |
| 1438 | |
| 1439 | /* Set param */ |
| 1440 | status = utilNativeSetParam("SpeechGeneral", "CategoryLayer,Common", "speech_common_para", "0x1,0xDABD,0x7918,0x2A00,0x8001,0x0,0x0,0x0,0x0,0x0,0x0,0x0"); |
| 1441 | if (status == APP_ERROR) |
| 1442 | { |
| 1443 | printf("utilNativeSetParam fail!\n"); |
| 1444 | exit(1); |
| 1445 | } |
| 1446 | |
| 1447 | /* Get param */ |
| 1448 | strResult = utilNativeGetParam("SpeechGeneral", "CategoryLayer,Common", "speech_common_para"); |
| 1449 | printf("Param = %s\n", strResult); |
| 1450 | #ifndef WIN32 |
| 1451 | free(strResult); |
| 1452 | #else |
| 1453 | printf("Cannot free the memory allocated by APP on WIN32, just for testing\n"); |
| 1454 | #endif |
| 1455 | |
| 1456 | /* Set field */ |
| 1457 | status = utilNativeSetField("Speech", "Band,NB,Profile,Normal", "speech_mode_para", "AEC", "252"); |
| 1458 | if (status == APP_ERROR) |
| 1459 | { |
| 1460 | printf("utilNativeSetField fail!\n"); |
| 1461 | exit(1); |
| 1462 | } |
| 1463 | |
| 1464 | /* Get field */ |
| 1465 | fieldResult = utilNativeGetField("Speech", "Band,NB,Profile,Normal", "speech_mode_para", "AEC"); |
| 1466 | printf("Field = 0x%x\n", fieldResult); |
| 1467 | |
| 1468 | /* Get check list */ |
| 1469 | strResult = utilNativeGetChecklist("Speech", "speech_mode_para", "AEC"); |
| 1470 | printf("Check list = %s\n", strResult); |
| 1471 | |
| 1472 | /* Save parameter */ |
| 1473 | status = utilNativeSaveXml("Speech"); |
| 1474 | if (status == APP_ERROR) |
| 1475 | { |
| 1476 | printf("utilNativeSaveXml fail!\n"); |
| 1477 | exit(1); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | int showXmlInfo(AppHandle *appHandle) |
| 1482 | { |
| 1483 | AudioType *audioType = NULL; |
| 1484 | char *categoryPath = NULL; |
| 1485 | char *paramName = NULL; |
| 1486 | ParamUnit *paramUnit = NULL; |
| 1487 | ParamInfo *paramInfo = NULL; |
| 1488 | FieldInfo *fieldInfo = NULL; |
| 1489 | Param *param = NULL; |
| 1490 | void *paramData = NULL; |
| 1491 | size_t arraySize = 0; |
| 1492 | char tmp[BUF_SIZE]; |
| 1493 | char *input; |
| 1494 | unsigned int fieldValue = 0; |
| 1495 | |
| 1496 | printf("\n\n====== Show XML Information =====\n"); |
| 1497 | printf("[0] Back to main menu\n"); |
| 1498 | printf("[1] Show all audio type info\n"); |
| 1499 | printf("[2] Show all category info\n"); |
| 1500 | printf("[3] Show all param/field info\n"); |
| 1501 | printf("[4] Show all param tree view info\n"); |
| 1502 | printf("[5] Show feature options\n"); |
| 1503 | printf("==========================\n"); |
| 1504 | printf("Please enter the selection: "); |
| 1505 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1506 | |
| 1507 | if (!strcmp(input, "0")) |
| 1508 | { |
| 1509 | return 0; |
| 1510 | } |
| 1511 | else if (!strcmp(input, "1")) |
| 1512 | { |
| 1513 | showAllAudioType(appHandle); |
| 1514 | } |
| 1515 | else if (!strcmp(input, "2")) |
| 1516 | { |
| 1517 | showAllCategoryInformation(appHandle); |
| 1518 | } |
| 1519 | else if (!strcmp(input, "3")) |
| 1520 | { |
| 1521 | showAllParamFieldInformation(appHandle); |
| 1522 | } |
| 1523 | else if (!strcmp(input, "4")) |
| 1524 | { |
| 1525 | showAllParamTreeInformation(appHandle); |
| 1526 | } |
| 1527 | else if (!strcmp(input, "5")) |
| 1528 | { |
| 1529 | showFeatureOptions(appHandle); |
| 1530 | } |
| 1531 | return 1; |
| 1532 | } |
| 1533 | |
| 1534 | int showMainMenu(AppHandle *appHandle) |
| 1535 | { |
| 1536 | char tmp[BUF_SIZE]; |
| 1537 | char *input; |
| 1538 | printf("\n\n======= Main Menu =======\n"); |
| 1539 | printf("[0] Exit\n"); |
| 1540 | printf("[1] Unit test\n"); |
| 1541 | printf("[2] Show XML information (AudioType/Category/ParamInfo/FieldInfo)\n"); |
| 1542 | printf("[3] Test formal Speech audio type xml. (Fixed test pattern)\n"); |
| 1543 | printf("[4] File changed callback test (only support on android version)\n"); |
| 1544 | printf("[5] Dynamic operation test\n"); |
| 1545 | printf("[6] Set debug level\n"); |
| 1546 | printf("[7] Show log to console\n"); |
| 1547 | printf("[8] Show app lib build timestamp\n"); |
| 1548 | printf("==========================\n"); |
| 1549 | printf("Please enter the selection: "); |
| 1550 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1551 | |
| 1552 | if (!strcmp(input, "0")) |
| 1553 | { |
| 1554 | return 0; |
| 1555 | } |
| 1556 | else if (!strcmp(input, "1")) |
| 1557 | { |
| 1558 | /* APP Parser internal unit test */ |
| 1559 | if (unitTest(appHandle) == APP_ERROR) |
| 1560 | { |
| 1561 | printf("Unit test failure!\n"); |
| 1562 | } |
| 1563 | else |
| 1564 | { |
| 1565 | printf("Unit test pass!\n"); |
| 1566 | } |
| 1567 | } |
| 1568 | else if (!strcmp(input, "2")) |
| 1569 | { |
| 1570 | while (1) |
| 1571 | { |
| 1572 | if (showXmlInfo(appHandle) == 0) |
| 1573 | { |
| 1574 | break; |
| 1575 | } |
| 1576 | } |
| 1577 | } |
| 1578 | else if (!strcmp(input, "3")) |
| 1579 | { |
| 1580 | testAppLibAPIs(); |
| 1581 | |
| 1582 | printf("Press enter to continuous next test:"); |
| 1583 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1584 | |
| 1585 | /* Test 2 */ |
| 1586 | testUtilNativeAPIs(); |
| 1587 | } |
| 1588 | else if (!strcmp(input, "4")) |
| 1589 | { |
| 1590 | #ifndef WIN32 |
| 1591 | /* XML changed callback process example for audio driver */ |
| 1592 | appHandleRegXmlChangedCb(appHandle, xmlChangedCallback); |
| 1593 | printf("Please push AudioParam xml to %s folder to test the xml changed callback\n", XML_CUS_FOLDER_ON_DEVICE); |
| 1594 | printf("You can press any key to continue!\n");; |
| 1595 | getchar(); // waiting inotify thead loop |
| 1596 | #else |
| 1597 | printf("Not support windows version\n"); |
| 1598 | #endif |
| 1599 | } |
| 1600 | else if (!strcmp(input, "5")) |
| 1601 | { |
| 1602 | while (1) |
| 1603 | { |
| 1604 | if (showDynamicTest(appHandle) == 0) |
| 1605 | { |
| 1606 | break; |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | else if (!strcmp(input, "6")) |
| 1611 | { |
| 1612 | int level; |
| 1613 | printf("Enter debug level (eg. 0:DEBUG, 1:INFO, 2:WARN, 3:ERR):"); |
| 1614 | input = utilGetStdin(tmp, BUF_SIZE); |
| 1615 | |
| 1616 | level = (int)strtoul(input, NULL, 0); |
| 1617 | if (level < 0 || level > ERR_LEVEL) |
| 1618 | { |
| 1619 | printf("Invalid level value. (%d)\n", level); |
| 1620 | } |
| 1621 | else |
| 1622 | { |
| 1623 | appSetDebugLevel(level); |
| 1624 | printf("Set debug level = %d\n", level); |
| 1625 | } |
| 1626 | } |
| 1627 | else if (!strcmp(input, "7")) |
| 1628 | { |
| 1629 | appHandleRedirectIOToConsole(); |
| 1630 | } |
| 1631 | else if (!strcmp(input, "8")) |
| 1632 | { |
| 1633 | printf("APP lib building time stamp: %s\n", appHandleGetBuildTimeStamp()); |
| 1634 | } |
| 1635 | return 1; |
| 1636 | } |
| 1637 | |
| 1638 | int main() |
| 1639 | { |
| 1640 | |
| 1641 | AppHandle *appHandle = NULL; |
| 1642 | |
| 1643 | #ifdef WIN32 |
| 1644 | AppHandle Handle; |
| 1645 | /* For Tuning Tool debug usage, used to show the APP lib message to the console */ |
| 1646 | appHandleRedirectIOToConsole(); |
| 1647 | |
| 1648 | /* Init app handle */ |
| 1649 | appHandleInit(&Handle); |
| 1650 | appHandle = &Handle; |
| 1651 | |
| 1652 | /* Parse the xml in default and cus folder, |
| 1653 | if cus folder has the same name of XML file, |
| 1654 | parser will load the cus folder xml instead of default xml folder */ |
| 1655 | appHandleParseXml(appHandle, XML_FOLDER_ON_TUNING_TOOL, XML_CUS_FOLDER_ON_TUNING_TOOL); |
| 1656 | #else |
| 1657 | /* Get AppHandle global instance, this API will parse xml automatically */ |
| 1658 | appHandle = appHandleGetInstance(); |
| 1659 | #endif |
| 1660 | |
| 1661 | /* Set the debug level, default is INFO_LEVEL */ |
| 1662 | appSetDebugLevel(WARN_LEVEL); |
| 1663 | |
| 1664 | while (1) |
| 1665 | { |
| 1666 | if (showMainMenu(appHandle) == 0) |
| 1667 | { |
| 1668 | break; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | /* Release appHandle resources */ |
| 1673 | appHandleUninit(appHandle); |
| 1674 | |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |