You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectSensorsEnumirator.h"
  2. objectSensorsEnumirator * objectSensorsEnumirator::_instance = 0;
  3. /**
  4. * Returns the single instance of the object.
  5. */
  6. objectSensorsEnumirator * objectSensorsEnumirator::getInstance()
  7. {
  8. // check if the instance has been created yet
  9. if (0 == _instance)
  10. {
  11. // if not, then create it
  12. _instance = new objectSensorsEnumirator;
  13. }
  14. // return the single instance
  15. return _instance;
  16. }
  17. // Constructor implementation
  18. objectSensorsEnumirator::objectSensorsEnumirator()
  19. {
  20. m_pLog = basicLogCollection::getInstance();
  21. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "SENSORS_MANAGER");
  22. loadDefinedSensors();
  23. }
  24. // Destructor implementation
  25. objectSensorsEnumirator::~objectSensorsEnumirator() {}
  26. objectLGS * objectSensorsEnumirator::getSensor(int index)
  27. {
  28. objectLGS * RetVal = NULL;
  29. if (index < m_vSensors.size())
  30. {
  31. RetVal = m_vSensors.at(index);
  32. };
  33. return RetVal;
  34. }
  35. bool objectSensorsEnumirator::loadDefinedSensors(void)
  36. {
  37. int index, count, tType, tSType;
  38. config_setting_t * tRec;
  39. config_setting_t * ttRec;
  40. count = config_setting_length(m_pSettings);
  41. if (count)
  42. {
  43. for (index = 0; index < count; index++)
  44. {
  45. ttRec = config_setting_get_elem(m_pSettings, index);
  46. if (ttRec != NULL)
  47. {
  48. // ttRec = config_setting_get_elem(tRec, 0);
  49. // config_setting_get_member(tRec, "SENSOR" );
  50. if (! config_setting_lookup_int(ttRec, BSI_TAG_SENSOR_TYPE, &tType))
  51. {
  52. continue;
  53. }
  54. if (! config_setting_lookup_int(ttRec, BSI_TAG_CONNECTION_TYPE, &tSType))
  55. {
  56. continue;
  57. }
  58. switch (tType)
  59. {
  60. default:
  61. {
  62. objectLGS * tSensor;
  63. tSensor = new objectLGS(ttRec);
  64. if (tSensor != NULL)
  65. {
  66. // Init will be done at Control binding
  67. // if( tSensor->create() ){
  68. m_vSensors.push_back(tSensor);
  69. //} else {
  70. // delete( tSensor );
  71. //};
  72. };
  73. break;
  74. };
  75. };
  76. };
  77. };
  78. };
  79. return true;
  80. }
  81. objectLGS * objectSensorsEnumirator::addSensor(SENSOR_INFO * SRC)
  82. {
  83. objectLGS * RetVal = NULL;
  84. if (SRC != NULL)
  85. {
  86. char Buffer[64];
  87. config_setting_t * tSettingsNode;
  88. objectLGS * ttSensor = NULL;
  89. sprintf(Buffer, "LRF_SENSOR_%d", m_vSensors.size());
  90. tSettingsNode = basicSettingsProvider::getInstance()->getSubNode(m_pSettings, Buffer);
  91. if (tSettingsNode != NULL)
  92. {
  93. config_setting_t * pSetting;
  94. pSetting = config_setting_add(tSettingsNode, BSI_TAG_SENSOR_TYPE, CONFIG_TYPE_INT);
  95. config_setting_set_int(pSetting, SRC->deviceType);
  96. pSetting = config_setting_add(tSettingsNode, BSI_TAG_CONNECTION_TYPE, CONFIG_TYPE_INT);
  97. config_setting_set_int(pSetting, SRC->deviceType);
  98. switch (SRC->deviceType)
  99. {
  100. default:
  101. {
  102. objectLGS * tSensor;
  103. tSensor = new objectLGS(tSettingsNode);
  104. if (tSensor != NULL)
  105. {
  106. // Init will be done at Control binding
  107. // if( tSensor->create() ){
  108. ttSensor = tSensor;
  109. //} else {
  110. // delete( tSensor );
  111. //};
  112. };
  113. break;
  114. };
  115. };
  116. };
  117. if (ttSensor != NULL)
  118. {
  119. m_vSensors.push_back(ttSensor);
  120. RetVal = ttSensor;
  121. // ToDo: Make Metod to abadon added config node in case camera failure
  122. basicSettingsProvider::getInstance()->compromise();
  123. };
  124. };
  125. basicSettingsProvider::getInstance()->validate();
  126. return RetVal;
  127. }
  128. size_t objectSensorsEnumirator::getCount(void)
  129. {
  130. return m_vSensors.size();
  131. }