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.

118 lines
3.4 KiB

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