main.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #include "../common/common.hpp"
  2. #include <fstream>
  3. void dumpFeature(TY_DEV_HANDLE handle, TY_COMPONENT_ID compID, TY_FEATURE_ID featID, const char* name)
  4. {
  5. TY_FEATURE_INFO featInfo;
  6. if (TYGetFeatureInfo(handle, compID, featID, &featInfo) != TY_STATUS_OK) {
  7. return;
  8. }
  9. if(featInfo.isValid && (featInfo.accessMode&TY_ACCESS_READABLE)){
  10. LOGD("=== %s: comp(0x%x) feat(0x%x) name(%s) access(%d) bindComponent(0x%x) bindFeature(0x%x)"
  11. , name, featInfo.componentID, featInfo.featureID, featInfo.name
  12. , featInfo.accessMode, featInfo.bindComponentID, featInfo.bindFeatureID);
  13. if(TYFeatureType(featID) == TY_FEATURE_INT){
  14. int32_t n;
  15. ASSERT_OK(TYGetInt(handle, compID, featID, &n));
  16. LOGD("=== %14s: %d", "", n);
  17. }
  18. if(TYFeatureType(featID) == TY_FEATURE_FLOAT){
  19. float v;
  20. ASSERT_OK(TYGetFloat(handle, compID, featID, &v));
  21. LOGD("=== %14s: %f", "", v);
  22. }
  23. if(TYFeatureType(featID) == TY_FEATURE_ENUM){
  24. uint32_t n;
  25. ASSERT_OK(TYGetEnumEntryCount(handle, compID, featID, &n));
  26. LOGD("=== %14s: entry count %d", "", n);
  27. if(n > 0){
  28. std::vector<TY_ENUM_ENTRY> entry(n);
  29. ASSERT_OK(TYGetEnumEntryInfo(handle, compID, featID, &entry[0], n, &n));
  30. for(uint32_t i = 0; i < n; i++){
  31. LOGD("=== %14s: value(%d), desc(%s)", "", entry[i].value, entry[i].description);
  32. }
  33. }
  34. }
  35. if(TYFeatureType(featID) == TY_FEATURE_BOOL){
  36. bool v;
  37. ASSERT_OK(TYGetBool(handle, compID, featID, &v));
  38. LOGD("=== %14s: %d", "", v);
  39. }
  40. if(TYFeatureType(featID) == TY_FEATURE_STRING){
  41. uint32_t n;
  42. ASSERT_OK(TYGetStringLength(handle, compID, featID, &n));
  43. LOGD("=== %14s: length(%d)", "", n);
  44. std::vector<char> str(n);
  45. ASSERT_OK(TYGetString(handle, compID, featID, &str[0], str.size()));
  46. LOGD("=== %14s: content(%s)", "", &str[0]);
  47. }
  48. if(TYFeatureType(featID) == TY_FEATURE_STRUCT){
  49. switch(featID){
  50. case TY_STRUCT_CAM_INTRINSIC:{
  51. TY_CAMERA_INTRINSIC intri;
  52. ASSERT_OK(TYGetStruct(handle, compID, featID, &intri
  53. , sizeof(TY_CAMERA_INTRINSIC)));
  54. LOGD("===%23s%f %f %f", "", intri.data[0], intri.data[1], intri.data[2]);
  55. LOGD("===%23s%f %f %f", "", intri.data[3], intri.data[4], intri.data[5]);
  56. LOGD("===%23s%f %f %f", "", intri.data[6], intri.data[7], intri.data[8]);
  57. return;
  58. }
  59. case TY_STRUCT_EXTRINSIC_TO_DEPTH: {
  60. TY_CAMERA_EXTRINSIC extri;
  61. ASSERT_OK(TYGetStruct(handle, compID, featID, &extri
  62. , sizeof(TY_CAMERA_EXTRINSIC)));
  63. LOGD("===%23s%f %f %f %f", "", extri.data[0], extri.data[1], extri.data[2], extri.data[3]);
  64. LOGD("===%23s%f %f %f %f", "", extri.data[4], extri.data[5], extri.data[6], extri.data[7]);
  65. LOGD("===%23s%f %f %f %f", "", extri.data[8], extri.data[9], extri.data[10], extri.data[11]);
  66. LOGD("===%23s%f %f %f %f", "", extri.data[12], extri.data[13], extri.data[14], extri.data[15]);
  67. return;
  68. }
  69. case TY_STRUCT_CAM_DISTORTION:{
  70. TY_CAMERA_DISTORTION dist;
  71. ASSERT_OK(TYGetStruct(handle, compID, featID, &dist
  72. , sizeof(TY_CAMERA_DISTORTION)));
  73. LOGD("===%23s%f %f %f %f", "", dist.data[0], dist.data[1], dist.data[2], dist.data[3]);
  74. LOGD("===%23s%f %f %f %f", "", dist.data[4], dist.data[5], dist.data[6], dist.data[7]);
  75. LOGD("===%23s%f %f %f %f", "", dist.data[8], dist.data[9], dist.data[10], dist.data[11]);
  76. return;
  77. }
  78. default:
  79. LOGD("=== %s: Unknown struct", name);
  80. return;
  81. }
  82. }
  83. }
  84. }
  85. #define DUMP_FEATURE(handle, compid, feature) dumpFeature( (handle), (compid), (feature) , #feature );
  86. void dumpComponentFeatures(TY_DEV_HANDLE handle, TY_COMPONENT_ID compID)
  87. {
  88. DUMP_FEATURE(handle, compID, TY_STRUCT_CAM_INTRINSIC );
  89. DUMP_FEATURE(handle, compID, TY_STRUCT_EXTRINSIC_TO_DEPTH);
  90. DUMP_FEATURE(handle, compID, TY_STRUCT_CAM_DISTORTION);
  91. DUMP_FEATURE(handle, compID, TY_INT_PERSISTENT_IP);
  92. DUMP_FEATURE(handle, compID, TY_INT_PERSISTENT_SUBMASK);
  93. DUMP_FEATURE(handle, compID, TY_INT_PERSISTENT_GATEWAY);
  94. DUMP_FEATURE(handle, compID, TY_BOOL_GVSP_RESEND);
  95. DUMP_FEATURE(handle, compID, TY_INT_PACKET_DELAY);
  96. DUMP_FEATURE(handle, compID, TY_INT_WIDTH_MAX);
  97. DUMP_FEATURE(handle, compID, TY_INT_HEIGHT_MAX);
  98. DUMP_FEATURE(handle, compID, TY_INT_OFFSET_X);
  99. DUMP_FEATURE(handle, compID, TY_INT_OFFSET_Y);
  100. DUMP_FEATURE(handle, compID, TY_INT_WIDTH);
  101. DUMP_FEATURE(handle, compID, TY_INT_HEIGHT);
  102. DUMP_FEATURE(handle, compID, TY_ENUM_IMAGE_MODE);
  103. DUMP_FEATURE(handle, compID, TY_ENUM_TRIGGER_POL);
  104. DUMP_FEATURE(handle, compID, TY_INT_FRAME_PER_TRIGGER);
  105. DUMP_FEATURE(handle, compID, TY_BOOL_KEEP_ALIVE_ONOFF);
  106. DUMP_FEATURE(handle, compID, TY_INT_KEEP_ALIVE_TIMEOUT);
  107. DUMP_FEATURE(handle, compID, TY_BOOL_AUTO_EXPOSURE);
  108. DUMP_FEATURE(handle, compID, TY_INT_EXPOSURE_TIME);
  109. DUMP_FEATURE(handle, compID, TY_BOOL_AUTO_GAIN);
  110. DUMP_FEATURE(handle, compID, TY_INT_GAIN);
  111. DUMP_FEATURE(handle, compID, TY_BOOL_AUTO_AWB);
  112. DUMP_FEATURE(handle, compID, TY_INT_LASER_POWER);
  113. DUMP_FEATURE(handle, compID, TY_BOOL_LASER_AUTO_CTRL);
  114. DUMP_FEATURE(handle, compID, TY_BOOL_UNDISTORTION);
  115. DUMP_FEATURE(handle, compID, TY_BOOL_BRIGHTNESS_HISTOGRAM);
  116. DUMP_FEATURE(handle, compID, TY_BOOL_DEPTH_POSTPROC);
  117. DUMP_FEATURE(handle, compID, TY_INT_R_GAIN);
  118. DUMP_FEATURE(handle, compID, TY_INT_G_GAIN);
  119. DUMP_FEATURE(handle, compID, TY_INT_B_GAIN);
  120. DUMP_FEATURE(handle, compID, TY_INT_ANALOG_GAIN);
  121. DUMP_FEATURE(handle, compID, TY_INT_ACCEPTABLE_PERCENT);
  122. DUMP_FEATURE(handle, compID, TY_INT_NTP_SERVER_IP);
  123. DUMP_FEATURE(handle, compID, TY_INT_SGBM_IMAGE_NUM);
  124. DUMP_FEATURE(handle, compID, TY_INT_SGBM_DISPARITY_NUM);
  125. DUMP_FEATURE(handle, compID, TY_INT_SGBM_DISPARITY_OFFSET);
  126. DUMP_FEATURE(handle, compID, TY_INT_SGBM_MATCH_WIN_HEIGHT);
  127. DUMP_FEATURE(handle, compID, TY_INT_SGBM_SEMI_PARAM_P1);
  128. DUMP_FEATURE(handle, compID, TY_INT_SGBM_SEMI_PARAM_P2);
  129. DUMP_FEATURE(handle, compID, TY_INT_SGBM_UNIQUE_FACTOR);
  130. DUMP_FEATURE(handle, compID, TY_INT_SGBM_UNIQUE_ABSDIFF);
  131. //Cost Param not impl in hw yet
  132. //DUMP_FEATURE(handle, compID, TY_INT_SGBM_COST_PARAM);
  133. DUMP_FEATURE(handle, compID, TY_BOOL_SGBM_HFILTER_HALF_WIN);
  134. DUMP_FEATURE(handle, compID, TY_INT_SGBM_MATCH_WIN_WIDTH);
  135. DUMP_FEATURE(handle, compID, TY_BOOL_SGBM_MEDFILTER);
  136. DUMP_FEATURE(handle, compID, TY_BOOL_SGBM_LRC);
  137. DUMP_FEATURE(handle, compID, TY_INT_SGBM_LRC_DIFF);
  138. DUMP_FEATURE(handle, compID, TY_INT_SGBM_MEDFILTER_THRESH);
  139. DUMP_FEATURE(handle, compID, TY_INT_SGBM_SEMI_PARAM_P1_SCALE);
  140. DUMP_FEATURE(handle, compID, TY_FLOAT_SCALE_UNIT);
  141. }
  142. #define DUMP_COMPONENT(handle,compIds,id) \
  143. do{\
  144. if(compIds & id){\
  145. LOGD("=== %s:",#id);\
  146. dumpComponentFeatures(handle, id);\
  147. }\
  148. }while(0)
  149. void dumpAllComponentFeatures(TY_DEV_HANDLE handle, int32_t compIDs)
  150. {
  151. LOGD("=== Dump all components and features:");
  152. DUMP_COMPONENT(handle, compIDs, TY_COMPONENT_DEVICE);
  153. DUMP_COMPONENT(handle, compIDs, TY_COMPONENT_DEPTH_CAM);
  154. DUMP_COMPONENT(handle, compIDs, TY_COMPONENT_IR_CAM_LEFT);
  155. DUMP_COMPONENT(handle, compIDs, TY_COMPONENT_IR_CAM_RIGHT);
  156. DUMP_COMPONENT(handle, compIDs, TY_COMPONENT_RGB_CAM_LEFT);
  157. DUMP_COMPONENT(handle, compIDs, TY_COMPONENT_RGB_CAM_RIGHT);
  158. DUMP_COMPONENT(handle, compIDs, TY_COMPONENT_LASER);
  159. }
  160. int main(int argc, char* argv[])
  161. {
  162. bool dumpConfig = false;
  163. std::string ID, IP;
  164. TY_INTERFACE_HANDLE hIface;
  165. TY_DEV_HANDLE handle;
  166. int i = 0;
  167. for(i = 1; i < argc; i++){
  168. if(strcmp(argv[i], "-id") == 0){
  169. ID = argv[++i];
  170. } else if(strcmp(argv[i], "-ip") == 0) {
  171. IP = argv[++i];
  172. }else if(strcmp(argv[i], "-d") == 0){
  173. dumpConfig = true;
  174. }else if(strcmp(argv[i], "-h") == 0){
  175. LOGI("Usage: DumpAllFeatures [-h] [-id <ID>]");
  176. return 0;
  177. }
  178. }
  179. if (dumpConfig) {
  180. std::ofstream fout("fetch_config.xml");
  181. if (fout) {
  182. LOGD("Create fetch_config.xml successfully");
  183. } else {
  184. LOGD("Create fetch_config.xml failed");
  185. }
  186. }
  187. // Init lib
  188. ASSERT_OK(TYInitLib());
  189. TY_VERSION_INFO ver;
  190. ASSERT_OK( TYLibVersion(&ver) );
  191. LOGD("=== lib version: %d.%d.%d", ver.major, ver.minor, ver.patch);
  192. std::vector<TY_DEVICE_BASE_INFO> selected;
  193. ASSERT_OK( selectDevice(TY_INTERFACE_ALL, ID, IP, 1, selected) );
  194. ASSERT(selected.size() > 0);
  195. TY_DEVICE_BASE_INFO& selectedDev = selected[0];
  196. ASSERT_OK( TYOpenInterface(selectedDev.iface.id, &hIface) );
  197. ASSERT_OK( TYOpenDevice(hIface, selectedDev.id, &handle) );
  198. ASSERT_OK( TYGetDeviceInfo(handle, &selectedDev) );
  199. {
  200. LOGD("=== selected interface %s:", selectedDev.iface.id);
  201. LOGD("=== selected device %s:", selectedDev.id);
  202. LOGD("=== vendor : %s", selectedDev.vendorName);
  203. LOGD("=== model : %s", selectedDev.modelName);
  204. LOGD("=== HW version : %d.%d.%d"
  205. , selectedDev.hardwareVersion.major
  206. , selectedDev.hardwareVersion.minor
  207. , selectedDev.hardwareVersion.patch
  208. );
  209. LOGD("=== FW version : %d.%d.%d"
  210. , selectedDev.firmwareVersion.major
  211. , selectedDev.firmwareVersion.minor
  212. , selectedDev.firmwareVersion.patch
  213. );
  214. if (TYIsNetworkInterface(selectedDev.iface.type)) {
  215. LOGD("=== device MAC : %s", selectedDev.netInfo.mac);
  216. LOGD("=== device IP : %s", selectedDev.netInfo.ip);
  217. }
  218. }
  219. {
  220. // List all components
  221. TY_COMPONENT_ID compIDs;
  222. std::string compNames;
  223. ASSERT_OK(TYGetComponentIDs(handle, &compIDs));
  224. dumpAllComponentFeatures(handle, compIDs);
  225. }
  226. LOGD("=== Close device");
  227. ASSERT_OK(TYCloseDevice(handle));
  228. ASSERT_OK(TYCloseInterface(hIface));
  229. ASSERT_OK(TYDeinitLib());
  230. LOGD("Done!");
  231. return 0;
  232. }