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.

2748 lines
92 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
7 years ago
​
6 years ago
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
6 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
6 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
7 years ago
​
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
​
6 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
6 years ago
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
7 years ago
​
6 years ago
​
7 years ago
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
7 years ago
​
​
7 years ago
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
7 years ago
​
​
7 years ago
7 years ago
​
​
7 years ago
​
​
7 years ago
7 years ago
7 years ago
7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Dr.Frucht Systems Ltd.
  3. // Copyright � 2000-2017. All Rights Reserved.
  4. // Version 2.0 7/20/2017
  5. // Last modification: 7/20/2017
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LRF_HardwareManager.cpp
  9. // AUTHOR: gagua
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of LRF_HardwareManager.cpp
  13. //----------------------------------------------------------------------------
  14. //
  15. #include "LRF_HardwareManager.h"
  16. #define LOG( X ) m_pLog->Log( "HW Manager", this, X )
  17. #define LOG_ERROR( X ) m_pLog->Log( "HW Manager", this, _LOG_ERROR, X )
  18. // Constructor implementation
  19. LRF_HardwareManager::LRF_HardwareManager( config_setting_t *SNode ){
  20. m_pLog = basicLogCollection::getInstance();
  21. m_pSettingsProvider = basicSettingsProvider::getInstance();
  22. if( m_pSettingsProvider ) {
  23. m_pSettings = m_pSettingsProvider->getSubNode( SNode, "HARDWARE_MANAGER" );
  24. if( m_pSettingsProvider->isCompromised() ) {
  25. m_pSettingsProvider->validate();
  26. };
  27. } else {
  28. m_pSettings = NULL;
  29. };
  30. m_bInitOK = false;
  31. m_bDumpMemoryToDisk = false;
  32. m_nFlipEnaFLags = 0;
  33. m_nDetectionFilter = 0;
  34. m_eSOC = SOC_UNKNOWN;
  35. #ifdef IGNORE_PRU_FLIP
  36. m_bStudyCompleteFlag = 0;
  37. m_bDataFilledTH = 0;
  38. #endif
  39. #ifdef THREADED_FLIP
  40. m_pFlipThreadHandler = NULL;
  41. m_bWaitFirstFlip = true;
  42. m_bFlipUnlockRequested = false;
  43. m_pFlipMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
  44. if( m_pFlipMutex != NULL ) {
  45. memset( m_pFlipMutex, 0, sizeof(pthread_mutex_t));
  46. pthread_mutexattr_t attrib;
  47. pthread_mutexattr_settype( &attrib, PTHREAD_MUTEX_ERRORCHECK );
  48. if( 0 != pthread_mutex_init( m_pFlipMutex, &attrib ) ){
  49. free( m_pFlipMutex );
  50. m_pFlipMutex = NULL;
  51. LOG_ERROR("Cannot Create Flip Protector Mutex!");
  52. } else {
  53. m_pFlipThreadHandler = (pthread_t *) malloc(sizeof(pthread_t));
  54. if( m_pFlipThreadHandler != NULL ) {
  55. memset( m_pFlipThreadHandler, 0, sizeof(pthread_t));
  56. } else {
  57. pthread_mutex_destroy(m_pFlipMutex);
  58. free(m_pFlipMutex);
  59. m_pFlipMutex = NULL;
  60. LOG_ERROR("Cannot Allocate Flip Thread!");
  61. };
  62. };
  63. } else {
  64. LOG_ERROR("Cannot Allocate Flip Protector Mutex!");
  65. };
  66. #endif
  67. #ifndef PRU_SLAVE
  68. #ifndef ONPC_TOTTAL_SIMULATOR
  69. #ifdef THREADED_MOTORS_START
  70. m_pMotorCtrlThreadHandler = NULL;
  71. m_pMotorCtrlMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
  72. if( m_pMotorCtrlMutex != NULL ) {
  73. memset( m_pMotorCtrlMutex, 0, sizeof(pthread_mutex_t));
  74. pthread_mutexattr_t attrib;
  75. pthread_mutexattr_settype( &attrib, PTHREAD_MUTEX_ERRORCHECK );
  76. if( 0 != pthread_mutex_init( m_pMotorCtrlMutex, &attrib ) ){
  77. free( m_pMotorCtrlMutex );
  78. m_pMotorCtrlMutex = NULL;
  79. LOG_ERROR("Cannot Create Motor Ctrl Protector Mutex!");
  80. } else {
  81. m_pMotorCtrlThreadHandler = (pthread_t *) malloc(sizeof(pthread_t));
  82. if( m_pMotorCtrlThreadHandler != NULL ) {
  83. memset( m_pMotorCtrlThreadHandler, 0, sizeof(pthread_t));
  84. } else {
  85. pthread_mutex_destroy(m_pMotorCtrlMutex);
  86. free(m_pMotorCtrlMutex);
  87. m_pMotorCtrlMutex = NULL;
  88. LOG_ERROR("Cannot Allocate Motor Ctrl Thread!");
  89. };
  90. };
  91. } else {
  92. LOG_ERROR("Cannot Allocate Motor Ctrl Protector Mutex!");
  93. };
  94. #endif
  95. #else
  96. LOG("Motors are disabled by Build - TOTTAL SIMULATION BUILD!");
  97. #endif
  98. //m_bMotorsViaTGZ = false;
  99. m_pCanBus = NULL;
  100. m_pTGZdevice = NULL;
  101. #else
  102. LOG("Motors are disabled by Build - SLAVE LRF BUILD!");
  103. #endif
  104. memset( &m_sPARAMETERS, 0 ,sizeof( LGS_3D_PARAMETERS ));
  105. m_sPARAMETERS.flags.BaseScanCount = BASE_SCAN_COUNT;
  106. m_sPARAMETERS.flags.DetectorsCount = KERNEL_COUNT;
  107. m_sPARAMETERS.flags.MirrorScanCount = Q_SCAN_COUNT;
  108. m_sPARAMETERS.flags.MirrorsCount = Q_MIRROR_COUNT;
  109. m_vMemoryBlock[0] = NULL;
  110. m_vMemoryBlock[1] = NULL;
  111. m_vMemoryBlock[2] = NULL;
  112. m_vMemoryBlock[3] = NULL;
  113. #ifndef ONPC_TOTTAL_SIMULATOR
  114. m_pSOC = classSOC::getInstance();
  115. if( m_pSOC!= NULL ) {
  116. m_bInitOK = readPercs();
  117. } else {
  118. LOG_ERROR( "SOC Control module failure!" );
  119. };
  120. if( m_bInitOK && m_pSettings!= NULL ){
  121. m_bInitOK = create( m_pSettings );
  122. };
  123. #endif
  124. };
  125. // Destructor implementation
  126. LRF_HardwareManager::~LRF_HardwareManager(){
  127. endService();
  128. if( m_vMemoryBlock[0]!=NULL )free( m_vMemoryBlock[0]);
  129. if( m_vMemoryBlock[1]!=NULL )free( m_vMemoryBlock[1]);
  130. if( m_vMemoryBlock[2]!=NULL )free( m_vMemoryBlock[2]);
  131. if( m_vMemoryBlock[3]!=NULL )free( m_vMemoryBlock[3]);
  132. #ifndef PRU_SLAVE
  133. if( m_pTGZdevice ){
  134. LOG( "Deleting TGZ device");
  135. delete( m_pTGZdevice );
  136. };
  137. //ToDo: Check CAN Bus Destructor - Hangs
  138. //ToDo: Delete Threads Mem
  139. if( m_pCanBus ){
  140. LOG( "Deleting CAN bus");
  141. delete( m_pCanBus );
  142. };
  143. #endif
  144. LOG( "HW manager - DONE!");
  145. };
  146. bool LRF_HardwareManager::readPercs( void ){
  147. int MEM_FD;
  148. void *PERC_MMAP;
  149. char Buffer[256];
  150. LOG("Reading SOC Percs");
  151. MEM_FD = open( "/dev/mem", O_RDWR | O_SYNC );
  152. if( MEM_FD == -1 ) {
  153. sprintf( Buffer, "Memory File Open Failed Error: %s", strerror(errno));
  154. LOG_ERROR( Buffer );
  155. return false;
  156. };
  157. PERC_MMAP = mmap( NULL,
  158. 0x2000,
  159. PROT_READ | PROT_WRITE,
  160. MAP_SHARED | MAP_LOCKED,
  161. MEM_FD,
  162. AM437X_SIGN_ZONE );
  163. close( MEM_FD );
  164. if( PERC_MMAP == MAP_FAILED ) {
  165. sprintf( Buffer, "Memory Region Map Failed Error: %s\n", strerror(errno));
  166. LOG_ERROR( Buffer );
  167. return false;
  168. };
  169. if( (*((uint32_t *)PERC_MMAP))== AM437X_SIGN_VAL ) {
  170. LOG( "Detected AM437x SOC Machine");
  171. m_eSOC = SOC_AM437X;
  172. munmap( PERC_MMAP, 0x2000 );
  173. return true;
  174. };
  175. munmap( PERC_MMAP, 0x2000 );
  176. MEM_FD = open( "/dev/mem", O_RDWR | O_SYNC );
  177. if( MEM_FD == -1 ) {
  178. sprintf( Buffer, "Memory File Open Failed Error: %s", strerror(errno));
  179. LOG_ERROR( Buffer );
  180. return false;
  181. };
  182. PERC_MMAP = mmap( NULL,
  183. 0x2000,
  184. PROT_READ | PROT_WRITE,
  185. MAP_SHARED | MAP_LOCKED,
  186. MEM_FD,
  187. AM355X_SIGN_ZONE );
  188. close( MEM_FD );
  189. if( PERC_MMAP == MAP_FAILED ) {
  190. sprintf( Buffer, "Memory Region Map Failed Error: %s\n", strerror(errno));
  191. LOG_ERROR( Buffer );
  192. return false;
  193. };
  194. if( (*((volatile uint32_t *)PERC_MMAP))== AM355X_SIGN_VAL ) {
  195. LOG( "Detected AM355x SOC Machine");
  196. m_eSOC = SOC_AM335X;
  197. munmap( PERC_MMAP, 0x2000 );
  198. return true;
  199. };
  200. munmap( PERC_MMAP, 0x2000 );
  201. LOG( "Cannot detect SOC type");
  202. return false;
  203. };
  204. bool LRF_HardwareManager::create( config_setting_t *Settings ){
  205. config_setting_t *pSetting;
  206. int tVal;
  207. char tBuffer[256];
  208. if( Settings != NULL ) {
  209. LOG("HW Getting Settings ...");
  210. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_TH_DUMP, &tVal ) ){
  211. tVal = m_bDumpMemoryToDisk = false;
  212. pSetting = config_setting_add( Settings, HWM_SETTINGS_TH_DUMP, CONFIG_TYPE_BOOL );
  213. config_setting_set_bool( pSetting, tVal );
  214. m_pSettingsProvider->compromise();
  215. LOG("No TH Memory Dumping defined");
  216. } else {
  217. m_bDumpMemoryToDisk = (bool)tVal;
  218. sprintf( tBuffer, "TH Memory Dumping Read From Settings: %d", tVal );
  219. LOG( tBuffer );
  220. };
  221. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_ROLE, &tVal ) ){
  222. tVal = m_sPARAMETERS.flags.isMaster = true;
  223. pSetting = config_setting_add( Settings, HWM_SETTINGS_ROLE, CONFIG_TYPE_BOOL );
  224. config_setting_set_bool( pSetting, tVal );
  225. m_pSettingsProvider->compromise();
  226. LOG("No role defined");
  227. } else {
  228. m_sPARAMETERS.flags.isMaster = (bool)tVal;
  229. sprintf( tBuffer, "Role Read From Settings: %d", tVal );
  230. LOG( tBuffer );
  231. };
  232. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_SUNBIT, &tVal ) ){
  233. tVal = m_sPARAMETERS.flags.Sunbit_filter = false;
  234. pSetting = config_setting_add( Settings, HWM_SETTINGS_SUNBIT, CONFIG_TYPE_BOOL );
  235. config_setting_set_bool( pSetting, tVal );
  236. m_pSettingsProvider->compromise();
  237. LOG("No SUNBIT action defined - Disabling!");
  238. } else {
  239. m_sPARAMETERS.flags.Sunbit_filter = (bool)tVal;
  240. sprintf( tBuffer, "SUNBIT Action Read From Settings: %d", tVal );
  241. LOG( tBuffer );
  242. };
  243. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_LRF_ENABLED, &tVal ) ){
  244. tVal = m_sPARAMETERS.flags.LaserPulsesOn = true;
  245. pSetting = config_setting_add( Settings, HWM_SETTINGS_LRF_ENABLED, CONFIG_TYPE_BOOL );
  246. config_setting_set_bool( pSetting, tVal );
  247. m_pSettingsProvider->compromise();
  248. LOG("No LRF Enabled");
  249. } else {
  250. m_sPARAMETERS.flags.LaserPulsesOn = (bool)tVal;
  251. sprintf( tBuffer, "LRF ENA Read From Settings: %d", tVal );
  252. LOG( tBuffer );
  253. };
  254. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_SIG_SYMULATOR, &tVal ) ){
  255. tVal = m_sPARAMETERS.flags.SignalSimulator = false;
  256. pSetting = config_setting_add( Settings, HWM_SETTINGS_SIG_SYMULATOR, CONFIG_TYPE_BOOL );
  257. config_setting_set_bool( pSetting, tVal );
  258. m_pSettingsProvider->compromise();
  259. LOG("No Sig Symulator Settings");
  260. } else {
  261. m_sPARAMETERS.flags.SignalSimulator = (bool)tVal;
  262. sprintf( tBuffer, "Sig Sym Read From Settings: %d", tVal );
  263. LOG( tBuffer );
  264. };
  265. if( !m_sPARAMETERS.flags.SignalSimulator ) {
  266. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_AUTOSTART_ENABLED, &tVal ) ){
  267. tVal = m_sPARAMETERS.flags.AutostartMotors = false;
  268. pSetting = config_setting_add( Settings, HWM_SETTINGS_AUTOSTART_ENABLED, CONFIG_TYPE_BOOL );
  269. config_setting_set_bool( pSetting, tVal );
  270. m_pSettingsProvider->compromise();
  271. LOG("No Motor Autostart Settings");
  272. } else {
  273. m_sPARAMETERS.flags.AutostartMotors = (bool)tVal;
  274. if( m_sPARAMETERS.flags.AutostartMotors ) {
  275. m_sPARAMETERS.flags.VerticalMotorOn = true;
  276. m_sPARAMETERS.flags.HorizontalMotorOn = true;
  277. };
  278. sprintf( tBuffer, "AutoStart Read From Settings: %d", tVal );
  279. LOG( tBuffer );
  280. };
  281. if( !m_sPARAMETERS.flags.AutostartMotors ) {
  282. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CTRL_V_MOTOR, &tVal ) ){
  283. tVal = m_sPARAMETERS.flags.VerticalMotorOn = false;
  284. pSetting = config_setting_add( Settings, HWM_SETTINGS_CTRL_V_MOTOR, CONFIG_TYPE_BOOL );
  285. config_setting_set_bool( pSetting, tVal );
  286. m_pSettingsProvider->compromise();
  287. LOG("No Vertical Controll");
  288. } else {
  289. m_sPARAMETERS.flags.VerticalMotorOn = (bool)tVal;
  290. sprintf( tBuffer, "V-M Ctrl Read From Settings: %d", tVal );
  291. LOG( tBuffer );
  292. };
  293. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CTRL_H_MOTOR, &tVal ) ){
  294. tVal = m_sPARAMETERS.flags.HorizontalMotorOn = false;
  295. pSetting = config_setting_add( Settings, HWM_SETTINGS_CTRL_H_MOTOR, CONFIG_TYPE_BOOL );
  296. config_setting_set_bool( pSetting, tVal );
  297. m_pSettingsProvider->compromise();
  298. LOG("No Horizontal Controll");
  299. } else {
  300. m_sPARAMETERS.flags.HorizontalMotorOn = (bool)tVal;
  301. sprintf( tBuffer, "H-M Ctrl Read From Settings: %d", tVal );
  302. LOG( tBuffer );
  303. };
  304. };
  305. }
  306. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_V_MOTOR_SETPOINT, &tVal )){
  307. tVal = m_sPARAMETERS.flags.VerticalFreq = Q_WORK_FREQ;
  308. pSetting = config_setting_add(Settings, HWM_SETTINGS_V_MOTOR_SETPOINT, CONFIG_TYPE_INT);
  309. config_setting_set_int(pSetting, tVal );
  310. m_pSettingsProvider->compromise();
  311. LOG("No Mirror Block Freq");
  312. } else {
  313. m_sPARAMETERS.flags.VerticalFreq = tVal;
  314. sprintf( tBuffer, "V-M Setpoint Read From Settings: %d", tVal );
  315. LOG( tBuffer );
  316. };
  317. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_H_MOTOR_SETPOINT, &tVal )){
  318. tVal = m_sPARAMETERS.flags.HorizontalFreq = B_WORK_FREQ;
  319. pSetting = config_setting_add(Settings, HWM_SETTINGS_H_MOTOR_SETPOINT, CONFIG_TYPE_INT);
  320. config_setting_set_int(pSetting, tVal );
  321. m_pSettingsProvider->compromise();
  322. LOG("No Base Block Freq");
  323. } else {
  324. m_sPARAMETERS.flags.HorizontalFreq = tVal;
  325. sprintf( tBuffer, "H-M Setpoint Read From Settings: %d", tVal );
  326. LOG( tBuffer );
  327. };
  328. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_V_PULSES_INTERLEAVE, &tVal )){
  329. tVal = m_sPARAMETERS.flags.QQinterlace = Q_P_INTERLEAVE;
  330. pSetting = config_setting_add(Settings, HWM_SETTINGS_V_PULSES_INTERLEAVE, CONFIG_TYPE_INT);
  331. config_setting_set_int(pSetting, tVal );
  332. m_pSettingsProvider->compromise();
  333. LOG("No Q Pulses per LRF pulse Setting");
  334. } else {
  335. m_sPARAMETERS.flags.QQinterlace = tVal;
  336. sprintf( tBuffer, "Q-Pulses per LRF pulse Read From Settings: %d", tVal );
  337. LOG( tBuffer );
  338. };
  339. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_OFFSET, &tVal )){
  340. tVal = m_sPARAMETERS.nOffset = SIGNAL_OFFSET;
  341. pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_OFFSET, CONFIG_TYPE_INT);
  342. config_setting_set_int(pSetting, tVal );
  343. m_pSettingsProvider->compromise();
  344. LOG("No TH Offset Setting");
  345. } else {
  346. m_sPARAMETERS.nOffset = tVal;
  347. sprintf( tBuffer, "TH Offset Read From Settings: %d", tVal );
  348. LOG( tBuffer );
  349. };
  350. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_ORDER, &tVal )){
  351. tVal = m_sPARAMETERS.nOrder = SIGNAL_ORDER;
  352. pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_ORDER, CONFIG_TYPE_INT);
  353. config_setting_set_int(pSetting, tVal );
  354. m_pSettingsProvider->compromise();
  355. LOG("No TH Order Setting");
  356. } else {
  357. m_sPARAMETERS.nOrder = tVal;
  358. #if defined( STRONG_STAT ) || !defined( THREADED_FLIP )
  359. if( m_sPARAMETERS.nOrder > 7 ) m_sPARAMETERS.nOrder = 7;
  360. #endif
  361. sprintf( tBuffer, "TH Order Read From Settings: %d", m_sPARAMETERS.nOrder );
  362. LOG( tBuffer );
  363. };
  364. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_DELTA, &tVal )){
  365. tVal = m_sPARAMETERS.nDelta = SIGNAL_DELTA;
  366. pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_DELTA, CONFIG_TYPE_INT);
  367. config_setting_set_int(pSetting, tVal );
  368. m_pSettingsProvider->compromise();
  369. LOG("No TH Delta Setting");
  370. } else {
  371. m_sPARAMETERS.nDelta = tVal;
  372. #if !defined( THREADED_FLIP )
  373. if( m_sPARAMETERS.nDelta > 127 ) m_sPARAMETERS.nDelta = 127;
  374. #endif
  375. sprintf( tBuffer, "TH Delta Read From Settings: %d", m_sPARAMETERS.nDelta );
  376. LOG( tBuffer );
  377. };
  378. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_FLIP_SIZE, &tVal )){
  379. tVal = m_sPARAMETERS.nFlip = SCANS_TO_FLIP;
  380. pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_FLIP_SIZE, CONFIG_TYPE_INT);
  381. config_setting_set_int(pSetting, tVal );
  382. m_pSettingsProvider->compromise();
  383. LOG("No TH Flip Size Setting");
  384. } else {
  385. m_sPARAMETERS.nFlip = tVal;
  386. sprintf( tBuffer, "Flip Size Read From Settings: %d", tVal );
  387. LOG( tBuffer );
  388. };
  389. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_GOOD_POINTS, &tVal )){
  390. tVal = m_sPARAMETERS.nGPointSamples = TH_POINT_GOOD;
  391. pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_GOOD_POINTS, CONFIG_TYPE_INT);
  392. config_setting_set_int(pSetting, tVal );
  393. m_pSettingsProvider->compromise();
  394. LOG("No TH Good Points Setting");
  395. } else {
  396. m_sPARAMETERS.nGPointSamples = tVal;
  397. #if defined( STRONG_STAT ) || !defined( THREADED_FLIP )
  398. if( m_sPARAMETERS.nGPointSamples > 15 ) m_sPARAMETERS.nGPointSamples = 15;
  399. #endif
  400. sprintf( tBuffer, "TH Good Points Read From Settings: %d", m_sPARAMETERS.nGPointSamples );
  401. LOG( tBuffer );
  402. };
  403. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_AUTO_TH_GENERATE, &tVal ) ){
  404. tVal = m_sPARAMETERS.flags.BuildThByCore = true;
  405. pSetting = config_setting_add( Settings, HWM_SETTINGS_AUTO_TH_GENERATE, CONFIG_TYPE_BOOL );
  406. config_setting_set_bool( pSetting, tVal );
  407. m_pSettingsProvider->compromise();
  408. LOG("No TH Build By Core Setting");
  409. } else {
  410. m_sPARAMETERS.flags.BuildThByCore = (bool)tVal;
  411. sprintf( tBuffer, "TH Build by Core Read From Settings: %d", tVal );
  412. LOG( tBuffer );
  413. };
  414. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_SPIKE_SIZE, &tVal )){
  415. tVal = m_sPARAMETERS.flags.Spike_TH = 1;
  416. pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_SPIKE_SIZE, CONFIG_TYPE_INT);
  417. config_setting_set_int(pSetting, tVal );
  418. m_pSettingsProvider->compromise();
  419. LOG("No Spike Threshold Setting");
  420. } else {
  421. m_sPARAMETERS.flags.Spike_TH = tVal;
  422. sprintf( tBuffer, "Spike Threshold Read From Settings: %d", tVal );
  423. LOG( tBuffer );
  424. };
  425. if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CAN_CONTROL_ENABLE, &tVal ) ){
  426. tVal = m_sPARAMETERS.flags.TGZ_canENA = false;
  427. pSetting = config_setting_add( Settings, HWM_SETTINGS_CAN_CONTROL_ENABLE, CONFIG_TYPE_BOOL );
  428. config_setting_set_bool( pSetting, tVal );
  429. m_pSettingsProvider->compromise();
  430. LOG("No CAN Enable Setting");
  431. } else {
  432. m_sPARAMETERS.flags.TGZ_canENA = (bool)tVal;
  433. sprintf( tBuffer, "CAN ENA Read From Settings: %d", tVal );
  434. LOG( tBuffer );
  435. };
  436. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_BUS_ID, &tVal )){
  437. tVal = m_sPARAMETERS.flags.TGZ_canBus = 1;
  438. pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_BUS_ID, CONFIG_TYPE_INT);
  439. config_setting_set_int(pSetting, tVal );
  440. m_pSettingsProvider->compromise();
  441. LOG("No CAN Bus ID Setting");
  442. } else {
  443. m_sPARAMETERS.flags.TGZ_canBus = tVal;
  444. sprintf( tBuffer, "CAN Bus ID Read From Settings: %d", tVal );
  445. LOG( tBuffer );
  446. };
  447. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_MY_ID, &tVal )){
  448. #ifndef TGD_VERSION_2
  449. tVal = m_sPARAMETERS.flags.TGZ_canSRC = 0x200;
  450. #else
  451. tVal = m_sPARAMETERS.flags.TGZ_canSRC = 0x300;
  452. #endif
  453. pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_MY_ID, CONFIG_TYPE_INT);
  454. config_setting_set_int(pSetting, tVal );
  455. m_pSettingsProvider->compromise();
  456. LOG("No CAN My ID Setting");
  457. } else {
  458. m_sPARAMETERS.flags.TGZ_canSRC = tVal;
  459. sprintf( tBuffer, "CAN My ID Read From Settings: 0x%X", tVal );
  460. LOG( tBuffer );
  461. };
  462. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_TGZ_ID, &tVal )){
  463. #ifndef TGD_VERSION_2
  464. tVal = m_sPARAMETERS.flags.TGZ_canDST = 0x201;
  465. #else
  466. tVal = m_sPARAMETERS.flags.TGZ_canDST = 0x301;
  467. #endif
  468. pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_TGZ_ID, CONFIG_TYPE_INT);
  469. config_setting_set_int(pSetting, tVal );
  470. m_pSettingsProvider->compromise();
  471. LOG("No CAN TGZ ID Setting");
  472. } else {
  473. m_sPARAMETERS.flags.TGZ_canDST = tVal;
  474. sprintf( tBuffer, "CAN TGZ ID Read From Settings: 0x%X", tVal );
  475. LOG( tBuffer );
  476. };
  477. #ifndef TGD_VERSION_2
  478. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_DIVIDER, &tVal )){
  479. tVal = m_sPARAMETERS.flags.TGZ_divider = 1;
  480. pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_DIVIDER, CONFIG_TYPE_INT);
  481. config_setting_set_int(pSetting, tVal );
  482. m_pSettingsProvider->compromise();
  483. LOG("No TGZ Divider Setting");
  484. } else {
  485. m_sPARAMETERS.flags.TGZ_divider = tVal;
  486. sprintf( tBuffer, "TGZ Div Read From Settings: %d", tVal );
  487. LOG( tBuffer );
  488. };
  489. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_PRF, &tVal )){
  490. tVal = m_sPARAMETERS.flags.TGZ_ParamQ = 35; // 35000 kHz
  491. pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_PRF, CONFIG_TYPE_INT);
  492. config_setting_set_int(pSetting, tVal );
  493. m_pSettingsProvider->compromise();
  494. LOG("No TGZ PRF Setting");
  495. } else {
  496. m_sPARAMETERS.flags.TGZ_ParamQ = tVal;
  497. sprintf( tBuffer, "TGZ PRF Read From Settings: %d", tVal );
  498. LOG( tBuffer );
  499. };
  500. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_RATIO, &tVal )){
  501. tVal = m_sPARAMETERS.flags.TGZ_ParamB = 64;
  502. pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_RATIO, CONFIG_TYPE_INT);
  503. config_setting_set_int(pSetting, tVal );
  504. m_pSettingsProvider->compromise();
  505. LOG("No TGZ Ratio Setting");
  506. } else {
  507. m_sPARAMETERS.flags.TGZ_ParamB = tVal;
  508. sprintf( tBuffer, "TGZ Ratio Read From Settings: %d", tVal );
  509. LOG( tBuffer );
  510. };
  511. #else
  512. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_MIRROR_SPEED, &tVal )){
  513. tVal = m_sPARAMETERS.flags.TGZ_ParamQ = ( Q_WORK_FREQ >> 2 );
  514. pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_MIRROR_SPEED, CONFIG_TYPE_INT);
  515. config_setting_set_int(pSetting, tVal );
  516. m_pSettingsProvider->compromise();
  517. LOG("No TGZ Mirror Block Speed");
  518. } else {
  519. m_sPARAMETERS.flags.TGZ_ParamQ = tVal;
  520. sprintf( tBuffer, "TGZ Mirror Block Speed Read From Settings: %d", tVal );
  521. LOG( tBuffer );
  522. };
  523. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_BASE_SPEED, &tVal )){
  524. tVal = m_sPARAMETERS.flags.TGZ_ParamB = ( B_WORK_FREQ >> 4 );
  525. pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_BASE_SPEED, CONFIG_TYPE_INT);
  526. config_setting_set_int(pSetting, tVal );
  527. m_pSettingsProvider->compromise();
  528. LOG("No TGZ Base Motor Speed");
  529. } else {
  530. m_sPARAMETERS.flags.TGZ_ParamB = tVal;
  531. sprintf( tBuffer, "TGZ Base Motor Speed Read From Settings: %d", tVal );
  532. LOG( tBuffer );
  533. };
  534. #endif
  535. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_B_SHIFT, &tVal )){
  536. tVal = m_sPARAMETERS.flags.B_shift = 0;
  537. pSetting = config_setting_add(Settings, HWM_SETTINGS_B_SHIFT, CONFIG_TYPE_INT);
  538. config_setting_set_int(pSetting, tVal );
  539. m_pSettingsProvider->compromise();
  540. LOG("No Base Shift Specified");
  541. } else {
  542. m_sPARAMETERS.flags.B_shift = tVal;
  543. sprintf( tBuffer, "Base Shift Read From Settings: %d", tVal );
  544. LOG( tBuffer );
  545. };
  546. if (!config_setting_lookup_int(Settings, HWM_SETTINGS_Q_SHIFT, &tVal )){
  547. tVal = m_sPARAMETERS.flags.Q_shift = 0;
  548. pSetting = config_setting_add(Settings, HWM_SETTINGS_Q_SHIFT, CONFIG_TYPE_INT);
  549. config_setting_set_int(pSetting, tVal );
  550. m_pSettingsProvider->compromise();
  551. LOG("No Mirror Shift Specified");
  552. } else {
  553. m_sPARAMETERS.flags.Q_shift = tVal;
  554. sprintf( tBuffer, "Mirror Shift Read From Settings: %d", tVal );
  555. LOG( tBuffer );
  556. };
  557. if( m_pSettingsProvider->isCompromised() ) {
  558. LOG("Save Settings");
  559. m_pSettingsProvider->validate();
  560. };
  561. LOG("HW Create(1) Started");
  562. beginService();
  563. LOG("HW Create(1) Done");
  564. };
  565. return m_bInitOK;
  566. };
  567. bool LRF_HardwareManager::getHardwareParams( HW_PARAMS &Params ){
  568. memcpy( &Params, &m_sPARAMETERS.flags, sizeof(HW_PARAMS) );
  569. return true;
  570. };
  571. bool LRF_HardwareManager::setHardwareParams( PHW_PARAMS Params ){
  572. memcpy( &m_sPARAMETERS.flags, &Params, sizeof(HW_PARAMS) );
  573. return true;
  574. };
  575. bool LRF_HardwareManager::getParams( LGS_3D_PARAMETERS &Params ){
  576. memcpy( &Params, &m_sPARAMETERS, sizeof(LGS_3D_PARAMETERS) );
  577. return true;
  578. };
  579. bool LRF_HardwareManager::create( HW_PARAMS &HS ){
  580. LOG("HW Create(2) Started");
  581. m_sPARAMETERS.flags.isMaster = HS.isMaster;
  582. beginService();
  583. LOG("HW Create(2) Done");
  584. return m_bInitOK;
  585. };
  586. void LRF_HardwareManager::beginService( void ){
  587. m_bInitOK = false;
  588. #ifndef ONPC_TOTTAL_SIMULATOR
  589. if( m_pSOC != NULL ) {
  590. LOG("Begin HW init process");
  591. LOG("Stoping all PRU Cores");
  592. if(!m_pSOC->pru_stop(0,0)){
  593. LOG_ERROR("Error Stoping PRU 0 0 Core");
  594. };
  595. if(!m_pSOC->pru_sreset(0,0)){
  596. LOG_ERROR("Error Resetting PRU 0 0 Core");
  597. };
  598. if(!m_pSOC->pru_disable(0,0)){
  599. LOG_ERROR("Error Disabling PRU 0 0 Core");
  600. };
  601. LOG("PRU 0 0 stoped");
  602. if(!m_pSOC->pru_stop(0,1)){
  603. LOG_ERROR("Error Stoping PRU 0 1 Core");
  604. };
  605. if(!m_pSOC->pru_sreset(0,1)){
  606. LOG_ERROR("Error Resetting PRU 0 1 Core");
  607. };
  608. if(!m_pSOC->pru_disable(0,1)){
  609. LOG_ERROR("Error Disabling PRU 0 1 Core");
  610. };
  611. LOG("PRU 0 1 stoped");
  612. if(!m_pSOC->pru_stop(1,0)){
  613. LOG_ERROR("Error Stoping PRU 1 0 Core");
  614. };
  615. if(!m_pSOC->pru_sreset(1,0)){
  616. LOG_ERROR("Error Resetting PRU 1 0 Core");
  617. };
  618. if(!m_pSOC->pru_disable(1,0)){
  619. LOG_ERROR("Error Disabling PRU 1 0 Core");
  620. };
  621. LOG("PRU 1 0 stoped");
  622. if(!m_pSOC->pru_stop(1,1)){
  623. LOG_ERROR("Error Stoping PRU 1 1 Core");
  624. };
  625. if(!m_pSOC->pru_sreset(1,1)){
  626. LOG_ERROR("Error Resetting PRU 1 1 Core");
  627. };
  628. if(!m_pSOC->pru_disable(1,1)){
  629. LOG_ERROR("Error Disabling PRU 1 1 Core");
  630. };
  631. LOG("PRU 1 1 stoped");
  632. #ifndef PRU_SLAVE
  633. if( m_sPARAMETERS.flags.isMaster ) {
  634. // If enable TGZ CAN connection
  635. if( m_sPARAMETERS.flags.TGZ_canENA ) {
  636. // Init TGZ connection
  637. char tBuf[16];
  638. sprintf( tBuf, "can%d", m_sPARAMETERS.flags.TGZ_canBus );
  639. m_pCanBus = new canBus( tBuf,
  640. m_sPARAMETERS.flags.TGZ_canSRC,
  641. m_sPARAMETERS.flags.TGZ_canDST );
  642. if( m_pCanBus != NULL ) {
  643. LOG("CAN Bus creation success");
  644. m_pTGZdevice = new protocolTGZ( m_pCanBus );
  645. if( m_pTGZdevice == NULL ) {
  646. LOG_ERROR("TGZ protocol creation failure");
  647. delete( m_pCanBus );
  648. m_pCanBus = NULL;
  649. }else{
  650. LOG("TGZ protocol creation success");
  651. };
  652. } else {
  653. LOG_ERROR("CAN Bus creation failure");;
  654. };
  655. };
  656. if( m_sPARAMETERS.flags.AutostartMotors ) {
  657. #ifndef NO_MOTORS
  658. LOG("Startup Motors");
  659. startMotors();
  660. #else
  661. LOG("Startup Motors Disabled by Compilation");
  662. #endif
  663. } else {
  664. LOG("No Auto Startup Motors");
  665. };
  666. LOG("Loading MASTER set of PRU Modules");
  667. /*
  668. The Order of cores to be loadedd is crucial.
  669. The first to load - last to function (Data Acq) that depends on others
  670. */
  671. if( !m_pSOC->pru_load( 1, 1, "PRU_1_1.bin", false ) ){
  672. LOG_ERROR("PRU 1 1 Load - FAILURE");
  673. return;
  674. };
  675. if( !m_pSOC->pru_load( 1, 0, "PRU_1_0.bin", false ) ){
  676. LOG_ERROR("PRU 1 0 Load - FAILURE");
  677. return;
  678. };
  679. if( !m_pSOC->pru_load( 0, 1, "PRU_0_1.bin", true ) ){
  680. LOG_ERROR("PRU 0 1 Load - FAILURE");
  681. return;
  682. };
  683. #ifdef NO_MOTORS
  684. LOG("Loading simulation of Motors");
  685. if( !m_pSOC->pru_load( 0, 0, "CORE0_NOMO.bin", true ) ){
  686. LOG_ERROR("PRU 0 0 Load - FAILURE");
  687. return;
  688. };
  689. #else
  690. if( !m_pSOC->pru_load( 0, 0, "PRU_0_0.bin", true ) ){
  691. LOG_ERROR("PRU 0 0 Load - FAILURE");
  692. return;
  693. };
  694. #endif
  695. // Make Handshake with cores
  696. if( !m_pSOC->setCoreOnLine(3) ){
  697. LOG_ERROR("Core 3 Startup Failure");
  698. m_bInitOK = false;
  699. return;
  700. };
  701. if( !m_pSOC->setCoreOnLine(2) ){
  702. LOG_ERROR("Core 2 Startup Failure");
  703. m_bInitOK = false;
  704. return;
  705. };
  706. if( !m_pSOC->setCoreOnLine(1) ){
  707. LOG_ERROR("Core 1 Startup Failure");
  708. m_bInitOK = false;
  709. return;
  710. };
  711. if( !m_pSOC->setCoreOnLine(0) ){
  712. LOG_ERROR("Core 0 Startup Failure");
  713. m_bInitOK = false;
  714. return;
  715. };
  716. // Fill Software Info
  717. //
  718. if( NULL != m_pSOC ){
  719. gsSOFT_INFO.FW_CORE1_VER = m_pSOC->getPRU_ID(0);
  720. gsSOFT_INFO.FW_CORE1_TYP = m_pSOC->getPRU_TYPE(0);
  721. gsSOFT_INFO.FW_CORE2_VER = m_pSOC->getPRU_ID(1);
  722. gsSOFT_INFO.FW_CORE2_TYP = m_pSOC->getPRU_TYPE(1);
  723. gsSOFT_INFO.FW_CORE3_VER = m_pSOC->getPRU_ID(2);
  724. gsSOFT_INFO.FW_CORE3_TYP = m_pSOC->getPRU_TYPE(2);
  725. gsSOFT_INFO.FW_CORE4_VER = m_pSOC->getPRU_ID(3);
  726. gsSOFT_INFO.FW_CORE4_TYP = m_pSOC->getPRU_TYPE(3);
  727. gsSOFT_INFO.DATA_VALID = true;
  728. };
  729. // Configure Cores to current Config
  730. // Core 0
  731. if( !m_pSOC->setSunbitMode( m_sPARAMETERS.flags.Sunbit_filter ) ){
  732. LOG_ERROR("Set SUNBIT Mode Failure");
  733. m_bInitOK = false;
  734. return;
  735. };
  736. if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){
  737. LOG_ERROR("Set Motor's Monitor Mode Failure");
  738. m_bInitOK = false;
  739. return;
  740. };
  741. if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) {
  742. LOG_ERROR("Set Motor's Interleave Mode Failure");
  743. m_bInitOK = false;
  744. return;
  745. };
  746. if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) {
  747. LOG_ERROR("Set Motor's Setpoints Failure");
  748. m_bInitOK = false;
  749. return;
  750. };
  751. if( !m_pSOC->setLrfPulseMode( m_sPARAMETERS.flags.LaserPulsesOn ) ) {
  752. LOG_ERROR("Set LRF Pulses Mode Failure");
  753. m_bInitOK = false;
  754. return;
  755. };
  756. if( !m_pSOC->setSimulationMode( m_sPARAMETERS.flags.SignalSimulator ) ) {
  757. LOG_ERROR("Set LRF Simulation Mode Failure");
  758. m_bInitOK = false;
  759. return;
  760. };
  761. // Core 2
  762. // Set Shifts
  763. if( !m_pSOC->setShifts( m_sPARAMETERS.flags.B_shift, m_sPARAMETERS.flags.Q_shift ) ) {
  764. LOG_ERROR("Set B-Q Shifts Failure");
  765. m_bInitOK = false;
  766. return;
  767. };
  768. // Core 3
  769. m_sCP_Detector.delta = m_sPARAMETERS.nDelta;
  770. m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip;
  771. m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples;
  772. m_sCP_Detector.offset = m_sPARAMETERS.nOffset;
  773. m_sCP_Detector.order = m_sPARAMETERS.nOrder;
  774. m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore;
  775. m_sCP_Detector.master = m_sPARAMETERS.flags.isMaster;
  776. #ifdef DEBUG
  777. char Buffer[256];
  778. sprintf( Buffer, "Detector[%s] Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]",
  779. ((m_sCP_Detector.master)?"M":"S"),
  780. m_sCP_Detector.delta,
  781. m_sCP_Detector.flip_size,
  782. m_sCP_Detector.good_points,
  783. m_sCP_Detector.order,
  784. m_sCP_Detector.offset,
  785. m_sCP_Detector.self_build_ena
  786. );
  787. LOG( Buffer );
  788. #endif
  789. if( !m_pSOC->setThCoreParams( &m_sCP_Detector )){
  790. LOG_ERROR("Detection Core Set Params Failure");
  791. m_bInitOK = false;
  792. return;
  793. };
  794. m_sCS_Detector.h_dencity = 2;
  795. m_sCS_Detector.mode = 0;
  796. m_sCS_Detector.online = 0;
  797. m_sCS_Detector.param_err = 0;
  798. m_sCS_Detector.req = 0;
  799. m_sCS_Detector.spike_th = m_sPARAMETERS.flags.Spike_TH;
  800. m_sCS_Detector.v_dencity = 2;
  801. m_sCS_Detector.work_en = 0;
  802. #ifdef DEBUG
  803. sprintf( Buffer, "Detector Status: Mode[%d] Spike_TH[%d] V_dencity[%d] H_dencity[%d]",
  804. m_sCS_Detector.mode,
  805. m_sCS_Detector.spike_th,
  806. m_sCS_Detector.v_dencity,
  807. m_sCS_Detector.h_dencity
  808. );
  809. LOG( Buffer );
  810. #endif
  811. if( !m_pSOC->setThCoreStatus( &m_sCS_Detector )){
  812. LOG_ERROR("Detection Core Set Statuses Failure");
  813. m_bInitOK = false;
  814. return;
  815. };
  816. // If Work is Enabled Enable Detection Work
  817. if( !m_pSOC->setToWork( m_sPARAMETERS.flags.LaserPulsesOn ) ) {
  818. LOG_ERROR("Detection Core Enabling Failure");
  819. m_bInitOK = false;
  820. return;
  821. };
  822. m_bInitOK = true;
  823. } else { // Slave Mode
  824. #else // PRU_SLAVE
  825. {
  826. #endif
  827. LOG_ERROR("Motors control Disabled by Slave Mode!");
  828. LOG("Loading SLAVE set of PRU Modules");
  829. /*
  830. The Order of cores to be loadedd is crucial.
  831. The first to load - last to function (Data Acq) that depends on others
  832. */
  833. if( !m_pSOC->pru_load( 1, 1, "PRU_1_1.bin", false ) ){
  834. LOG_ERROR("PRU 1 1 Load - FAILURE");
  835. return;
  836. };
  837. if( !m_pSOC->pru_load( 1, 0, "PRU_1_0.bin", false ) ){
  838. LOG_ERROR("PRU 1 0 Load - FAILURE");
  839. return;
  840. };
  841. if( !m_pSOC->pru_load( 0, 1, "PRU_0_1.bin", true ) ){
  842. LOG_ERROR("PRU 0 1 Load - FAILURE");
  843. return;
  844. };
  845. if( !m_pSOC->pru_load( 0, 0, "PRU_0_0.bin", true ) ){
  846. LOG_ERROR("PRU 0 0 Load - FAILURE");
  847. return;
  848. };
  849. // Make Handshake with cores
  850. if( !m_pSOC->setCoreOnLine(3) ){
  851. LOG_ERROR("Core 3 Startup Failure");
  852. m_bInitOK = false;
  853. return;
  854. };
  855. if( !m_pSOC->setCoreOnLine(2) ){
  856. LOG_ERROR("Core 2 Startup Failure");
  857. m_bInitOK = false;
  858. return;
  859. };
  860. if( !m_pSOC->setCoreOnLine(1) ){
  861. LOG_ERROR("Core 1 Startup Failure");
  862. m_bInitOK = false;
  863. return;
  864. };
  865. if( !m_pSOC->setCoreOnLine(0) ){
  866. LOG_ERROR("Core 0 Startup Failure");
  867. m_bInitOK = false;
  868. return;
  869. };
  870. // Fill Software Info
  871. //
  872. if( NULL != m_pSOC ){
  873. gsSOFT_INFO.FW_CORE1_VER = m_pSOC->getPRU_ID(0);
  874. gsSOFT_INFO.FW_CORE2_VER = m_pSOC->getPRU_ID(1);
  875. gsSOFT_INFO.FW_CORE3_VER = m_pSOC->getPRU_ID(2);
  876. gsSOFT_INFO.FW_CORE4_VER = m_pSOC->getPRU_ID(3);
  877. gsSOFT_INFO.DATA_VALID = true;
  878. };
  879. // Configure Cores to current Config
  880. // Core 0
  881. if( !m_pSOC->setSunbitMode( m_sPARAMETERS.flags.Sunbit_filter ) ){
  882. LOG_ERROR("Set SUNBIT Mode Failure");
  883. m_bInitOK = false;
  884. return;
  885. };
  886. if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){
  887. LOG_ERROR("Set Motor's Monitor Mode Failure");
  888. m_bInitOK = false;
  889. return;
  890. };
  891. if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) {
  892. LOG_ERROR("Set Motor's Interleave Mode Failure");
  893. m_bInitOK = false;
  894. return;
  895. };
  896. if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) {
  897. LOG_ERROR("Set Motor's Setpoints Failure");
  898. m_bInitOK = false;
  899. return;
  900. };
  901. if( !m_pSOC->setLrfPulseMode( m_sPARAMETERS.flags.LaserPulsesOn ) ) {
  902. LOG_ERROR("Set LRF Pulses Mode Failure");
  903. m_bInitOK = false;
  904. return;
  905. };
  906. if( !m_pSOC->setSimulationMode( m_sPARAMETERS.flags.SignalSimulator ) ) {
  907. LOG_ERROR("Set LRF Simulation Mode Failure");
  908. m_bInitOK = false;
  909. return;
  910. };
  911. // Core 2
  912. // Set Shifts
  913. if( !m_pSOC->setShifts( m_sPARAMETERS.flags.B_shift, m_sPARAMETERS.flags.Q_shift ) ) {
  914. LOG_ERROR("Set B-Q Shifts Failure");
  915. m_bInitOK = false;
  916. return;
  917. };
  918. // Core 3
  919. m_sCP_Detector.delta = m_sPARAMETERS.nDelta;
  920. m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip;
  921. m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples;
  922. m_sCP_Detector.offset = m_sPARAMETERS.nOffset;
  923. m_sCP_Detector.order = m_sPARAMETERS.nOrder;
  924. m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore;
  925. #ifdef DEBUG
  926. char Buffer[256];
  927. sprintf( Buffer, "Detector Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]",
  928. m_sCP_Detector.delta,
  929. m_sCP_Detector.flip_size,
  930. m_sCP_Detector.good_points,
  931. m_sCP_Detector.order,
  932. m_sCP_Detector.offset,
  933. m_sCP_Detector.self_build_ena
  934. );
  935. LOG( Buffer );
  936. #endif
  937. if( !m_pSOC->setThCoreParams( &m_sCP_Detector )){
  938. LOG_ERROR("Detection Core Set Params Failure");
  939. m_bInitOK = false;
  940. return;
  941. };
  942. m_sCS_Detector.h_dencity = 2;
  943. m_sCS_Detector.mode = 0;
  944. m_sCS_Detector.online = 0;
  945. m_sCS_Detector.param_err = 0;
  946. m_sCS_Detector.req = 0;
  947. m_sCS_Detector.spike_th = m_sPARAMETERS.flags.Spike_TH;
  948. m_sCS_Detector.v_dencity = 2;
  949. m_sCS_Detector.work_en = 0;
  950. #ifdef DEBUG
  951. sprintf( Buffer, "Detector Status: Mode[%d] Spike_TH[%d] V_dencity[%d] H_dencity[%d]",
  952. m_sCS_Detector.mode,
  953. m_sCS_Detector.spike_th,
  954. m_sCS_Detector.v_dencity,
  955. m_sCS_Detector.h_dencity
  956. );
  957. LOG( Buffer );
  958. #endif
  959. if( !m_pSOC->setThCoreStatus( &m_sCS_Detector )){
  960. LOG_ERROR("Detection Core Set Statuses Failure");
  961. m_bInitOK = false;
  962. return;
  963. };
  964. // If Work is Enabled Enable Detection Work
  965. if( !m_pSOC->setToWork( m_sPARAMETERS.flags.LaserPulsesOn ) ) {
  966. LOG_ERROR("Detection Core Enabling Failure");
  967. m_bInitOK = false;
  968. return;
  969. };
  970. memset( m_bTHSteadyCounter, ( m_sCP_Detector.flip_size && 0xFF ), KERNEL_COUNT);
  971. m_bInitOK = true;
  972. };
  973. };
  974. #else //#ifndef ONPC_TOTTAL_SIMULATOR
  975. LOG("Dummy Init of Hardware");
  976. m_bInitOK = true;
  977. #endif //#ifndef ONPC_TOTTAL_SIMULATOR
  978. };
  979. void LRF_HardwareManager::endService( void ){
  980. #ifndef ONPC_TOTTAL_SIMULATOR
  981. if( m_pSOC!=NULL ){
  982. #ifndef PRU_SLAVE
  983. if( m_sPARAMETERS.flags.isMaster ) {
  984. #ifndef NO_MOTORS
  985. stopMotors();
  986. #endif
  987. } else {
  988. };
  989. #endif
  990. LOG("Stoping all PRU Cores");
  991. if(!m_pSOC->pru_stop(0,0)){
  992. LOG_ERROR("Error Stoping PRU 0 0 Core");
  993. };
  994. if(!m_pSOC->pru_sreset(0,0)){
  995. LOG_ERROR("Error Resetting PRU 0 0 Core");
  996. };
  997. if(!m_pSOC->pru_disable(0,0)){
  998. LOG_ERROR("Error Disabling PRU 0 0 Core");
  999. };
  1000. LOG("PRU 0 0 stoped");
  1001. if(!m_pSOC->pru_stop(0,1)){
  1002. LOG_ERROR("Error Stoping PRU 0 1 Core");
  1003. };
  1004. if(!m_pSOC->pru_sreset(0,1)){
  1005. LOG_ERROR("Error Resetting PRU 0 1 Core");
  1006. };
  1007. if(!m_pSOC->pru_disable(0,1)){
  1008. LOG_ERROR("Error Disabling PRU 0 1 Core");
  1009. };
  1010. LOG("PRU 0 1 stoped");
  1011. if(!m_pSOC->pru_stop(1,0)){
  1012. LOG_ERROR("Error Stoping PRU 1 0 Core");
  1013. };
  1014. if(!m_pSOC->pru_sreset(1,0)){
  1015. LOG_ERROR("Error Resetting PRU 1 0 Core");
  1016. };
  1017. if(!m_pSOC->pru_disable(1,0)){
  1018. LOG_ERROR("Error Disabling PRU 1 0 Core");
  1019. };
  1020. LOG("PRU 1 0 stoped");
  1021. if(!m_pSOC->pru_stop(1,1)){
  1022. LOG_ERROR("Error Stoping PRU 1 1 Core");
  1023. };
  1024. if(!m_pSOC->pru_sreset(1,1)){
  1025. LOG_ERROR("Error Resetting PRU 1 1 Core");
  1026. };
  1027. if(!m_pSOC->pru_disable(1,1)){
  1028. LOG_ERROR("Error Disabling PRU 1 1 Core");
  1029. };
  1030. LOG("PRU 1 1 stoped");
  1031. if( !m_pSOC->pru_load( 0, 0, "halt.bin" ) ){
  1032. LOG_ERROR("PRU 0 0 HALT - FAILURE");
  1033. };
  1034. if( !m_pSOC->pru_load( 0, 1, "halt.bin" ) ){
  1035. LOG_ERROR("PRU 0 1 HALT - FAILURE");
  1036. };
  1037. if( !m_pSOC->pru_load( 1, 0, "halt.bin" ) ){
  1038. LOG_ERROR("PRU 1 0 HALT - FAILURE");
  1039. };
  1040. if( !m_pSOC->pru_load( 1, 1, "halt.bin" ) ){
  1041. LOG_ERROR("PRU 1 1 HALT - FAILURE");
  1042. };
  1043. };
  1044. #else //#ifndef ONPC_TOTTAL_SIMULATOR
  1045. LOG("Dummy Shutdown Hardware");
  1046. #endif //#ifndef ONPC_TOTTAL_SIMULATOR
  1047. };
  1048. #ifndef PRU_SLAVE
  1049. #ifndef ONPC_TOTTAL_SIMULATOR
  1050. #ifdef THREADED_MOTORS_START
  1051. void LRF_HardwareManager::performStartMotors( void ){
  1052. if( m_sPARAMETERS.flags.TGZ_canENA ) {
  1053. LOG("Starting TGZ device");
  1054. if( m_pTGZdevice!= NULL ) {
  1055. #ifndef TGD_VERSION_2
  1056. m_pTGZdevice->setDivider( m_sPARAMETERS.flags.TGZ_divider );
  1057. m_pTGZdevice->setPrfMode( m_sPARAMETERS.flags.TGZ_ParamQ );
  1058. m_pTGZdevice->setRatio( m_sPARAMETERS.flags.TGZ_ParamB );
  1059. #else //TGD_VERSION_2
  1060. m_pTGZdevice->setSpeeds( m_sPARAMETERS.flags.TGZ_ParamQ,
  1061. m_sPARAMETERS.flags.TGZ_ParamB );
  1062. #endif //TGD_VERSION_2
  1063. m_pTGZdevice->setRunMode( true );
  1064. m_pTGZdevice->setErrorMode( true );
  1065. m_pTGZdevice->startDeviceStateInquiry();
  1066. //ToDo: Wait for TGD starts Motors!
  1067. //LOG( "Wait Startup TGZ");
  1068. //SLEEP(30000); // 30 seconds
  1069. //LOG( "Done");
  1070. } else {
  1071. LOG_ERROR("Error TGZ Device object!" );
  1072. };
  1073. } else {
  1074. volatile sysPwmss *mV_PWMSS = NULL;
  1075. volatile sysPwmss *mH_PWMSS = NULL;
  1076. LOG("StartMotorsProcedure");
  1077. if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){
  1078. mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 );
  1079. mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 );
  1080. if( mV_PWMSS!=NULL && mH_PWMSS!=NULL ){
  1081. // Disable PWM;
  1082. LOG("Disable Motors PWMs");
  1083. mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1084. mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1085. while( mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 || mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 )usleep(5);
  1086. LOG("Disable Motors PWMs - Done");
  1087. // Polarity
  1088. mV_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE;
  1089. mH_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE;
  1090. LOG("Set Motors PWMs Config");
  1091. // Set PWM Period
  1092. mV_PWMSS->ECAP_CAP3 = VM_WORK_PERIOD;
  1093. mH_PWMSS->ECAP_CAP3 = HM_WORK_PERIOD;
  1094. mV_PWMSS->ECAP_CAP1 = VM_WORK_PERIOD;
  1095. mH_PWMSS->ECAP_CAP1 = HM_WORK_PERIOD;
  1096. LOG("Set Motors PWMs Period");
  1097. // Set Intitial Zeroes DC
  1098. mV_PWMSS->ECAP_CAP4 = 1;
  1099. mH_PWMSS->ECAP_CAP4 = 1;
  1100. mV_PWMSS->ECAP_CAP2 = 1;
  1101. mH_PWMSS->ECAP_CAP2 = 1;
  1102. LOG("Set Motors PWMs DC");
  1103. // Config Timer
  1104. // Running
  1105. //ECCTL1: 0x00008000
  1106. //ECCTL2: 0x000006D6
  1107. // Stoped
  1108. //ECCTL1: 0x00008000
  1109. //ECCTL2: 0x000004C6
  1110. mV_PWMSS->ECAP_ECCTL1 = 0;
  1111. mV_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2;
  1112. mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1113. mH_PWMSS->ECAP_ECCTL1 = 0;
  1114. mH_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2;
  1115. mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1116. // Set APWM mode
  1117. mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1;
  1118. mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1;
  1119. // Set module enable
  1120. mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1;
  1121. mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1;
  1122. LOG("Set Motors PWMs Enabled");
  1123. uint32_t index = 0;
  1124. LOG("Start Motors PWMs Spin Up");
  1125. while( index < VM_WORK_DUTY_CYCLE || index < HM_WORK_DUTY_CYCLE ){
  1126. if( index < VM_WORK_DUTY_CYCLE ){
  1127. mV_PWMSS->ECAP_CAP4 = index;
  1128. while( mV_PWMSS->ECAP_CAP2 != index )usleep(5);
  1129. };
  1130. if( index < HM_WORK_DUTY_CYCLE ){
  1131. mH_PWMSS->ECAP_CAP4 = index;
  1132. while( mH_PWMSS->ECAP_CAP2 != index )usleep(5);
  1133. };
  1134. usleep( 700 ); //700 microseconds;
  1135. index++;
  1136. };
  1137. LOG("Motors PWMs Spin Up Done");
  1138. // Set PRU to controll
  1139. if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){
  1140. LOG_ERROR("Set Motor's Monitor Mode Failure");
  1141. return;
  1142. };
  1143. if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) {
  1144. LOG_ERROR("Set Motor's Interleave Mode Failure");
  1145. return;
  1146. };
  1147. if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) {
  1148. LOG_ERROR("Set Motor's Setpoints Failure");
  1149. return;
  1150. };
  1151. } else {
  1152. LOG_ERROR("Cannot get access to PWMSS module");
  1153. }
  1154. };
  1155. };
  1156. };
  1157. void LRF_HardwareManager::performStopMotors( void ){
  1158. if( m_sPARAMETERS.flags.TGZ_canENA ) {
  1159. LOG("Stoping TGZ device");
  1160. if( m_pTGZdevice != NULL ) {
  1161. m_pTGZdevice->setRunMode( false );
  1162. m_pTGZdevice->setErrorMode( true );
  1163. m_pTGZdevice->startDeviceStateInquiry();
  1164. } else {
  1165. LOG_ERROR("Error TGZ Device object!" );
  1166. };
  1167. } else {
  1168. if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){
  1169. //if( m_sPARAMETERS.flags.HorizontalMotorOn )
  1170. {
  1171. volatile sysPwmss *mH_PWMSS = NULL;
  1172. LOG("Stop Horizontal Motor's PWM");
  1173. mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 );
  1174. if( mH_PWMSS!=NULL ){
  1175. // Set PWM to 0 timeout 10 msec.
  1176. int to = 2000;
  1177. mH_PWMSS->ECAP_CAP4 = 1;
  1178. while( ( to-- ) && ( mH_PWMSS->ECAP_CAP2 != 1 ) ) usleep(5);
  1179. // Turn Off Timer
  1180. mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1181. // For Security switch Mode to eCap
  1182. mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0;
  1183. // Disable PWM;
  1184. mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1185. LOG("Horizontal Motor's PWM Stoped");
  1186. } else {
  1187. LOG_ERROR("Can not Stop Motors PWMs");
  1188. return;
  1189. };
  1190. //m_sPARAMETERS.flags.HorizontalMotorOn = 0;
  1191. };
  1192. //if( m_sPARAMETERS.flags.VerticalMotorOn )
  1193. {
  1194. volatile sysPwmss *mV_PWMSS = NULL;
  1195. LOG("Stop Vertical Motor's PWM");
  1196. mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 );
  1197. if( mV_PWMSS!=NULL ){
  1198. // Set PWM to 0 timeout 10 msec.
  1199. int to = 2000;
  1200. mV_PWMSS->ECAP_CAP4 = 1;
  1201. while( ( to-- ) && ( mV_PWMSS->ECAP_CAP2 != 1 ) )usleep(5);
  1202. // Turn Off Timer
  1203. mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1204. // For Security switch Mode to eCap
  1205. mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0;
  1206. // Disable PWM;
  1207. mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1208. LOG("Vertical Motor's PWM Stoped");
  1209. } else {
  1210. LOG_ERROR("Can not Stop Motors PWMs");
  1211. return;
  1212. };
  1213. //m_sPARAMETERS.flags.VerticalMotorOn = 0;
  1214. };
  1215. } else {
  1216. LOG_ERROR("Slave Device Can not Stop Motors PWMs");
  1217. return;
  1218. };
  1219. }; // TGZ - PWM
  1220. };
  1221. #endif
  1222. bool LRF_HardwareManager::startMotors( bool Auto ){
  1223. #ifdef THREADED_MOTORS_START
  1224. if( m_sPARAMETERS.flags.TGZ_canENA ) {
  1225. if( !Auto ) {
  1226. if( m_sPARAMETERS.flags.AutostartMotors == 0 ) {
  1227. m_sPARAMETERS.flags.AutostartMotors = 1;
  1228. saveCurrentParameters();
  1229. };
  1230. };
  1231. } else {
  1232. if( !Auto ) {
  1233. if( m_sPARAMETERS.flags.AutostartMotors == 0 || m_sPARAMETERS.flags.VerticalMotorOn == 0 || m_sPARAMETERS.flags.HorizontalMotorOn == 0 ) {
  1234. m_sPARAMETERS.flags.VerticalMotorOn = 1;
  1235. m_sPARAMETERS.flags.HorizontalMotorOn = 1;
  1236. m_sPARAMETERS.flags.AutostartMotors = 1;
  1237. saveCurrentParameters();
  1238. };
  1239. };
  1240. };
  1241. if( m_pMotorCtrlMutex != NULL ) {
  1242. if( 0 == pthread_mutex_trylock( m_pMotorCtrlMutex ) ){
  1243. if( 0 != pthread_detach( *m_pMotorCtrlThreadHandler ) ){
  1244. LOG_ERROR("Thread Detach Failed!");
  1245. pthread_mutex_unlock( m_pMotorCtrlMutex );
  1246. };
  1247. if( 0 != pthread_create( m_pMotorCtrlThreadHandler, NULL, m_fMotorStartThreadFunction, ( void * ) this ) ) {
  1248. LOG_ERROR("Thread Creation Faled.");
  1249. pthread_mutex_unlock( m_pMotorCtrlMutex );
  1250. };
  1251. #ifdef DEBUG
  1252. // LOG("TH Flip Thread Started");
  1253. #endif
  1254. } else {
  1255. #ifdef DEBUG
  1256. // LOG("TH Flip Request Overlapped!");
  1257. #endif
  1258. };
  1259. };
  1260. #else //THREADED_MOTORS_START
  1261. if( m_sPARAMETERS.flags.TGZ_canENA ) {
  1262. LOG("Starting TGZ device");
  1263. if( m_pTGZdevice!= NULL ) {
  1264. if( !Auto ) {
  1265. if( m_sPARAMETERS.flags.AutostartMotors == 0 ) {
  1266. m_sPARAMETERS.flags.AutostartMotors = 1;
  1267. saveCurrentParameters();
  1268. };
  1269. };
  1270. #ifndef TGD_VERSION_2
  1271. m_pTGZdevice->setDivider( m_sPARAMETERS.flags.TGZ_divider );
  1272. m_pTGZdevice->setPrfMode( m_sPARAMETERS.flags.TGZ_ParamQ );
  1273. m_pTGZdevice->setRatio( m_sPARAMETERS.flags.TGZ_ParamB );
  1274. #else //TGD_VERSION_2
  1275. m_pTGZdevice->setSpeeds( m_sPARAMETERS.flags.TGZ_ParamQ,
  1276. m_sPARAMETERS.flags.TGZ_ParamB );
  1277. #endif //TGD_VERSION_2
  1278. m_pTGZdevice->setRunMode( true );
  1279. m_pTGZdevice->setErrorMode( true );
  1280. m_pTGZdevice->startDeviceStateInquiry();
  1281. //ToDo: Wait for TGD starts Motors!
  1282. //LOG( "Wait Startup TGZ");
  1283. //SLEEP(30000); // 30 seconds
  1284. //LOG( "Done");
  1285. } else {
  1286. LOG_ERROR("Error TGZ Device object!" );
  1287. };
  1288. } else {
  1289. volatile sysPwmss *mV_PWMSS = NULL;
  1290. volatile sysPwmss *mH_PWMSS = NULL;
  1291. LOG("StartMotorsProcedure");
  1292. if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){
  1293. mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 );
  1294. mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 );
  1295. if( mV_PWMSS!=NULL && mH_PWMSS!=NULL ){
  1296. // Disable PWM;
  1297. LOG("Disable Motors PWMs");
  1298. mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1299. mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1300. while( mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 || mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 )usleep(5);
  1301. LOG("Disable Motors PWMs - Done");
  1302. // Polarity
  1303. mV_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE;
  1304. mH_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE;
  1305. LOG("Set Motors PWMs Config");
  1306. // Set PWM Period
  1307. mV_PWMSS->ECAP_CAP3 = VM_WORK_PERIOD;
  1308. mH_PWMSS->ECAP_CAP3 = HM_WORK_PERIOD;
  1309. mV_PWMSS->ECAP_CAP1 = VM_WORK_PERIOD;
  1310. mH_PWMSS->ECAP_CAP1 = HM_WORK_PERIOD;
  1311. LOG("Set Motors PWMs Period");
  1312. // Set Intitial Zeroes DC
  1313. mV_PWMSS->ECAP_CAP4 = 1;
  1314. mH_PWMSS->ECAP_CAP4 = 1;
  1315. mV_PWMSS->ECAP_CAP2 = 1;
  1316. mH_PWMSS->ECAP_CAP2 = 1;
  1317. LOG("Set Motors PWMs DC");
  1318. // Config Timer
  1319. // Running
  1320. //ECCTL1: 0x00008000
  1321. //ECCTL2: 0x000006D6
  1322. // Stoped
  1323. //ECCTL1: 0x00008000
  1324. //ECCTL2: 0x000004C6
  1325. mV_PWMSS->ECAP_ECCTL1 = 0;
  1326. mV_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2;
  1327. mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1328. mH_PWMSS->ECAP_ECCTL1 = 0;
  1329. mH_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2;
  1330. mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1331. // Set APWM mode
  1332. mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1;
  1333. mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1;
  1334. // Set module enable
  1335. mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1;
  1336. mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1;
  1337. LOG("Set Motors PWMs Enabled");
  1338. uint32_t index = 0;
  1339. LOG("Start Motors PWMs Spin Up");
  1340. while( index < VM_WORK_DUTY_CYCLE || index < HM_WORK_DUTY_CYCLE ){
  1341. if( index < VM_WORK_DUTY_CYCLE ){
  1342. mV_PWMSS->ECAP_CAP4 = index;
  1343. while( mV_PWMSS->ECAP_CAP2 != index )usleep(5);
  1344. };
  1345. if( index < HM_WORK_DUTY_CYCLE ){
  1346. mH_PWMSS->ECAP_CAP4 = index;
  1347. while( mH_PWMSS->ECAP_CAP2 != index )usleep(5);
  1348. };
  1349. usleep( 700 ); //700 microseconds;
  1350. index++;
  1351. };
  1352. LOG("Motors PWMs Spin Up Done");
  1353. // Set PRU to controll
  1354. if( !Auto ) {
  1355. if( m_sPARAMETERS.flags.AutostartMotors == 0 || m_sPARAMETERS.flags.VerticalMotorOn == 0 || m_sPARAMETERS.flags.HorizontalMotorOn == 0 ) {
  1356. m_sPARAMETERS.flags.VerticalMotorOn = 1;
  1357. m_sPARAMETERS.flags.HorizontalMotorOn = 1;
  1358. m_sPARAMETERS.flags.AutostartMotors = 1;
  1359. saveCurrentParameters();
  1360. };
  1361. };
  1362. if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){
  1363. LOG_ERROR("Set Motor's Monitor Mode Failure");
  1364. return false;
  1365. };
  1366. if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) {
  1367. LOG_ERROR("Set Motor's Interleave Mode Failure");
  1368. return false;
  1369. };
  1370. if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) {
  1371. LOG_ERROR("Set Motor's Setpoints Failure");
  1372. return false;
  1373. };
  1374. } else {
  1375. LOG_ERROR("Cannot get access to PWMSS module");
  1376. }
  1377. };
  1378. };
  1379. #endif //THREADED_MOTORS_START
  1380. return true;
  1381. };
  1382. bool LRF_HardwareManager::stopMotors( bool Auto ){
  1383. #ifdef THREADED_MOTORS_START
  1384. if( m_sPARAMETERS.flags.TGZ_canENA ) {
  1385. if( !Auto ) {
  1386. if( m_sPARAMETERS.flags.AutostartMotors == 1 ) {
  1387. m_sPARAMETERS.flags.AutostartMotors = 0;
  1388. saveCurrentParameters();
  1389. };
  1390. };
  1391. } else {
  1392. if( !Auto ) {
  1393. if( m_sPARAMETERS.flags.AutostartMotors == 1 || m_sPARAMETERS.flags.VerticalMotorOn == 1 || m_sPARAMETERS.flags.HorizontalMotorOn == 1 ) {
  1394. m_sPARAMETERS.flags.VerticalMotorOn = 0;
  1395. m_sPARAMETERS.flags.HorizontalMotorOn = 0;
  1396. m_sPARAMETERS.flags.AutostartMotors = 0;
  1397. saveCurrentParameters();
  1398. };
  1399. };
  1400. };
  1401. if( m_pMotorCtrlMutex != NULL ) {
  1402. if( 0 == pthread_mutex_trylock( m_pMotorCtrlMutex ) ){
  1403. if( 0 != pthread_detach( *m_pMotorCtrlThreadHandler ) ){
  1404. LOG_ERROR("Thread Detach Failed!");
  1405. pthread_mutex_unlock( m_pMotorCtrlMutex );
  1406. };
  1407. if( 0 != pthread_create( m_pMotorCtrlThreadHandler, NULL, m_fMotorStopThreadFunction, ( void * ) this ) ) {
  1408. LOG_ERROR("Thread Creation Faled.");
  1409. pthread_mutex_unlock( m_pMotorCtrlMutex );
  1410. };
  1411. #ifdef DEBUG
  1412. // LOG("TH Flip Thread Started");
  1413. #endif
  1414. } else {
  1415. #ifdef DEBUG
  1416. // LOG("TH Flip Request Overlapped!");
  1417. #endif
  1418. };
  1419. };
  1420. #else //THREADED_MOTORS_START
  1421. if( m_sPARAMETERS.flags.TGZ_canENA ) {
  1422. LOG("Stoping TGZ device");
  1423. if( m_pTGZdevice != NULL ) {
  1424. if( !Auto ) {
  1425. if( m_sPARAMETERS.flags.AutostartMotors == 1 ) {
  1426. m_sPARAMETERS.flags.AutostartMotors = 0;
  1427. saveCurrentParameters();
  1428. };
  1429. };
  1430. m_pTGZdevice->setRunMode( false );
  1431. m_pTGZdevice->setErrorMode( true );
  1432. m_pTGZdevice->startDeviceStateInquiry();
  1433. } else {
  1434. LOG_ERROR("Error TGZ Device object!" );
  1435. };
  1436. } else {
  1437. if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){
  1438. if( m_sPARAMETERS.flags.HorizontalMotorOn ) {
  1439. volatile sysPwmss *mH_PWMSS = NULL;
  1440. LOG("Stop Horizontal Motor's PWM");
  1441. mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 );
  1442. if( mH_PWMSS!=NULL ){
  1443. // Set PWM to 0 timeout 10 msec.
  1444. int to = 2000;
  1445. mH_PWMSS->ECAP_CAP4 = 1;
  1446. while( ( to-- ) && ( mH_PWMSS->ECAP_CAP2 != 1 ) ) usleep(5);
  1447. // Turn Off Timer
  1448. mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1449. // For Security switch Mode to eCap
  1450. mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0;
  1451. // Disable PWM;
  1452. mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1453. LOG("Horizontal Motor's PWM Stoped");
  1454. } else {
  1455. LOG_ERROR("Can not Stop Motors PWMs");
  1456. return false;
  1457. };
  1458. };
  1459. if( m_sPARAMETERS.flags.VerticalMotorOn ) {
  1460. volatile sysPwmss *mV_PWMSS = NULL;
  1461. LOG("Stop Vertical Motor's PWM");
  1462. mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 );
  1463. if( mV_PWMSS!=NULL ){
  1464. if( !Auto ) {
  1465. if( m_sPARAMETERS.flags.AutostartMotors == 1 || m_sPARAMETERS.flags.VerticalMotorOn == 1 || m_sPARAMETERS.flags.HorizontalMotorOn == 1 ) {
  1466. m_sPARAMETERS.flags.VerticalMotorOn = 0;
  1467. m_sPARAMETERS.flags.HorizontalMotorOn = 0;
  1468. m_sPARAMETERS.flags.AutostartMotors = 0;
  1469. saveCurrentParameters();
  1470. };
  1471. };
  1472. // Set PWM to 0 timeout 10 msec.
  1473. int to = 2000;
  1474. mV_PWMSS->ECAP_CAP4 = 1;
  1475. while( ( to-- ) && ( mV_PWMSS->ECAP_CAP2 != 1 ) )usleep(5);
  1476. // Turn Off Timer
  1477. mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1;
  1478. // For Security switch Mode to eCap
  1479. mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0;
  1480. // Disable PWM;
  1481. mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0;
  1482. LOG("Vertical Motor's PWM Stoped");
  1483. } else {
  1484. LOG_ERROR("Can not Stop Motors PWMs");
  1485. return false;
  1486. };
  1487. };
  1488. } else {
  1489. LOG_ERROR("Slave Device Can not Stop Motors PWMs");
  1490. return false;
  1491. };
  1492. }; // TGZ <-> PWM
  1493. #endif // THREADED_MOTORS_START
  1494. return true;
  1495. };
  1496. #endif //#ifndef ONPC_TOTTAL_SIMULATOR
  1497. #endif // PRU_SLAVE
  1498. static uint32_t nMemoryDumpID = 0;
  1499. #ifdef ONPC_TOTTAL_SIMULATOR
  1500. static thresholdNode * DUMMY_TH_MEMORY = NULL;
  1501. #endif
  1502. thresholdNode *LRF_HardwareManager::getWorkingMemory( void ){
  1503. #ifndef ONPC_TOTTAL_SIMULATOR
  1504. if( m_pSOC!= NULL ){
  1505. thresholdNode *tNode;
  1506. thresholdNode *rNode;
  1507. rNode = tNode = (thresholdNode *) m_pSOC->getTH_MEMORY();
  1508. if( m_bDumpMemoryToDisk ) {
  1509. if( tNode != NULL ) {
  1510. LOG( "Save Memory Dump!");
  1511. FILE *fd;
  1512. char tName[64];
  1513. for( int index = 0; index < KERNEL_COUNT; index++ ) {
  1514. sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index );
  1515. fd = fopen(tName, "wb+");
  1516. if( fd != NULL ) {
  1517. uint32_t tSize;
  1518. tSize = TH_SIZE_NODES;
  1519. fwrite( &tSize, sizeof(uint32_t), 1, fd );
  1520. fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd );
  1521. fclose(fd);
  1522. } else {
  1523. LOG_ERROR( "Mem Dump Failure!");
  1524. };
  1525. tNode += TH_SIZE_NODES;
  1526. };
  1527. nMemoryDumpID++;
  1528. };
  1529. };
  1530. return rNode;
  1531. };
  1532. return NULL;
  1533. #else
  1534. if( DUMMY_TH_MEMORY == NULL ) {
  1535. LOG("Allocate Dummy buffer for TH memories");
  1536. DUMMY_TH_MEMORY = (thresholdNode *)malloc( 2 * KERNEL_COUNT * TH_SIZE_NODES * sizeof(thresholdNode));
  1537. };
  1538. return DUMMY_TH_MEMORY;
  1539. #endif
  1540. };
  1541. int LRF_HardwareManager::getWorkingMemoryID( void ){
  1542. return ( nMemoryDumpID - 1 );
  1543. };
  1544. uint32_t *LRF_HardwareManager::getEventMemory( void ){
  1545. #ifndef ONPC_TOTTAL_SIMULATOR
  1546. if( m_pSOC!= NULL ){
  1547. return m_pSOC->getEVT_MEMORY();
  1548. };
  1549. #endif
  1550. return NULL;
  1551. };
  1552. bool LRF_HardwareManager::getDetectionStatus( DT_STATUS &Status ){
  1553. #ifndef ONPC_TOTTAL_SIMULATOR
  1554. if( m_pSOC!=NULL ){
  1555. *((uint32_t*)&m_sCS_Detector) = m_pSOC->getThCoreStatus();
  1556. Status = m_sCS_Detector;
  1557. if( Status.online ) return true;
  1558. };
  1559. return false;
  1560. #else
  1561. return true;
  1562. #endif
  1563. };
  1564. bool LRF_HardwareManager::getDetectionParams( TH_PARAMS &Params ){
  1565. #ifndef ONPC_TOTTAL_SIMULATOR
  1566. if( m_pSOC!=NULL ){
  1567. *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams();
  1568. Params = m_sCP_Detector;
  1569. if( m_sCP_Detector.self_build_ena ) {
  1570. m_nDetectionFilter = 0xFF;
  1571. };
  1572. return true;
  1573. };
  1574. return false;
  1575. #else
  1576. return true;
  1577. #endif
  1578. };
  1579. bool LRF_HardwareManager::setParams( LGS_3D_PARAMETERS *Params ){
  1580. if(Params == NULL) return false;
  1581. if(m_pSOC == NULL ) return false;
  1582. memcpy( &m_sPARAMETERS, Params, sizeof(LGS_3D_PARAMETERS) );
  1583. // Save into settings
  1584. m_sCP_Detector.delta = m_sPARAMETERS.nDelta;
  1585. m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip;
  1586. m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples;
  1587. m_sCP_Detector.offset = m_sPARAMETERS.nOffset;
  1588. m_sCP_Detector.order = m_sPARAMETERS.nOrder;
  1589. m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore;
  1590. m_sCP_Detector.master = m_sPARAMETERS.flags.isMaster;
  1591. #ifdef DEBUG
  1592. char Buffer[256];
  1593. sprintf( Buffer, "Detector[%s] NEW Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]",
  1594. ((m_sCP_Detector.master)?"M":"S"),
  1595. m_sCP_Detector.delta,
  1596. m_sCP_Detector.flip_size,
  1597. m_sCP_Detector.good_points,
  1598. m_sCP_Detector.order,
  1599. m_sCP_Detector.offset,
  1600. m_sCP_Detector.self_build_ena
  1601. );
  1602. LOG( Buffer );
  1603. #endif
  1604. // Apply new Parameters
  1605. if(!m_pSOC->setThCoreParams( &m_sCP_Detector )){
  1606. LOG_ERROR("Detection Core Set NEW Params Failure");
  1607. return false;
  1608. };
  1609. *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams();
  1610. saveCurrentParameters();
  1611. return true;
  1612. };
  1613. bool LRF_HardwareManager::setDetectionParams( TH_PARAMS *Params ){
  1614. if( Params == NULL) return false;
  1615. if( m_pSOC == NULL ) return false;
  1616. memcpy( &m_sCP_Detector, Params, sizeof(TH_PARAMS) );
  1617. #ifndef ONPC_TOTTAL_SIMULATOR
  1618. #ifdef DEBUG
  1619. char Buffer[256];
  1620. sprintf( Buffer, "Detector[%s] NEW Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]",
  1621. ((m_sCP_Detector.master)?"M":"S"),
  1622. m_sCP_Detector.delta,
  1623. m_sCP_Detector.flip_size,
  1624. m_sCP_Detector.good_points,
  1625. m_sCP_Detector.order,
  1626. m_sCP_Detector.offset,
  1627. m_sCP_Detector.self_build_ena
  1628. );
  1629. LOG( Buffer );
  1630. #endif
  1631. // Apply new Parameters
  1632. if(!m_pSOC->setThCoreParams( &m_sCP_Detector )){
  1633. LOG_ERROR("Detection Core Set NEW Params Failure");
  1634. return false;
  1635. };
  1636. *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams();
  1637. saveCurrentParameters();
  1638. #else
  1639. return true;
  1640. #endif
  1641. };
  1642. #ifdef SIMULATE_FLIPS
  1643. static uint32_t pips_counter = 1;
  1644. #endif
  1645. //static uint32_t stam = 0;
  1646. bool LRF_HardwareManager::validateCores( void ){
  1647. #ifdef SIMULATE_FLIPS
  1648. pips_counter++;
  1649. #endif
  1650. #ifndef ONPC_TOTTAL_SIMULATOR
  1651. if( !m_bInitOK ) return false;
  1652. if( m_pSOC != NULL ){
  1653. #ifndef PRU_SLAVE
  1654. *((uint32_t*)&m_sCS_Motors) = m_pSOC->getMotorStatus();
  1655. if( m_sCS_Motors.online ){
  1656. bool tErrors = false;
  1657. if( m_sCS_Motors.param_err ) {
  1658. LOG_ERROR("Motor Parameter Error!");
  1659. tErrors = true;
  1660. };
  1661. if( m_sCS_Motors.h_motor_en && !m_sCS_Motors.h_motor_ok ) {
  1662. LOG_ERROR("Basis Motor Error!");
  1663. tErrors = true;
  1664. };
  1665. if( m_sCS_Motors.v_motor_en && !m_sCS_Motors.v_motor_ok ) {
  1666. LOG_ERROR("Mirror Block Motor Error!");
  1667. tErrors = true;
  1668. };
  1669. if( tErrors )return false;
  1670. };
  1671. #endif
  1672. *((uint32_t*)&m_sCS_Detector) = m_pSOC->getThCoreStatus();
  1673. *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams();
  1674. if( m_sCP_Detector.self_build_ena ) {
  1675. m_nDetectionFilter = 0xFF;
  1676. };
  1677. if( m_sCS_Detector.online ) {
  1678. #ifdef SIMULATE_FLIPS
  1679. if( ( pips_counter % 100 ) == 0 ){
  1680. LOG("INJECT Flip Request!");
  1681. m_pSOC->injectThCoreRequest( CORE3_REQ_FLIP_TH );
  1682. };
  1683. #endif
  1684. #ifdef THREADED_FLIP
  1685. if( m_bFlipUnlockRequested ){
  1686. #ifdef DEBUG
  1687. LOG("Unlocking Flip protecting Mutex");
  1688. #endif
  1689. if( m_pFlipMutex != NULL ){
  1690. if( 0 != pthread_mutex_unlock( m_pFlipMutex ) ){
  1691. LOG_ERROR("Error Unlocking Flip protecting Mutex!");
  1692. };
  1693. };
  1694. m_bFlipUnlockRequested = false;
  1695. };
  1696. #endif
  1697. if( m_sCS_Detector.req ) {
  1698. #ifdef DEBUG
  1699. //LOG("Detector CORE REQ");
  1700. #endif
  1701. uint32_t mCoreReq;
  1702. mCoreReq = m_pSOC->getThCoreRequest();
  1703. switch( mCoreReq ) {
  1704. #ifndef IGNORE_PRU_FLIP___
  1705. case CORE3_REQ_FLIP_TH:{
  1706. #ifdef THREADED_FLIP
  1707. if( m_pFlipMutex != NULL ) {
  1708. if( 0 == pthread_mutex_trylock( m_pFlipMutex ) ){
  1709. if( !m_bWaitFirstFlip ) {
  1710. if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){
  1711. LOG_ERROR("Thread Detach Failed!");
  1712. pthread_mutex_unlock( m_pFlipMutex );
  1713. };
  1714. } else m_bWaitFirstFlip = false;
  1715. #ifdef DEBUG
  1716. LOG("Build Working Threshold Memories MT Mode!");
  1717. #endif
  1718. if( 0 != pthread_create( m_pFlipThreadHandler, NULL, m_fFlipThreadFunction, ( void * ) this ) ) {
  1719. LOG_ERROR("Thread Creation Faled.");
  1720. pthread_mutex_unlock( m_pFlipMutex );
  1721. };
  1722. #ifdef DEBUG
  1723. LOG("TH Flip Thread Started");
  1724. #endif
  1725. } else {
  1726. #ifdef DEBUG
  1727. //LOG("TH Flip Request Overlapped!");
  1728. #endif
  1729. };
  1730. }
  1731. #else //!THREADED_FLIP
  1732. #ifdef DEBUG
  1733. LOG("Build Working Threshold Memories NT Mode!");
  1734. #endif
  1735. if( performFlip() ){
  1736. #ifdef DEBUG
  1737. LOG("CORE REQ Done.");
  1738. #endif
  1739. } else {
  1740. LOG_ERROR("Building Detector's TH Error!");
  1741. };
  1742. #endif//!THREADED_FLIP
  1743. break;
  1744. };
  1745. case CORE3_REQ_CLEAR_TH:{
  1746. #ifdef DEBUG
  1747. LOG("Clear Threshold Memories");
  1748. #endif
  1749. if( cleanTH(0) ){
  1750. #ifdef DEBUG
  1751. //LOG("CORE REQ Done.");
  1752. #endif
  1753. } else {
  1754. LOG_ERROR("Cleanup Detector's TH Error!");
  1755. }
  1756. break;
  1757. };
  1758. #endif //!IGNORE_PRU_FLIP
  1759. default:{
  1760. LOG_ERROR("Unrecognized Core Request!");
  1761. };
  1762. };
  1763. m_pSOC->clearThCoreRequest();
  1764. };
  1765. if( m_sCS_Detector.param_err ) {
  1766. LOG_ERROR("Detector Parameter Error!");
  1767. return false;
  1768. };
  1769. };
  1770. return true;
  1771. } else {
  1772. LOG_ERROR( "SOC Not Defined!");
  1773. };
  1774. return false;
  1775. #else //#ifndef ONPC_TOTTAL_SIMULATOR
  1776. return true;
  1777. #endif //#ifndef ONPC_TOTTAL_SIMULATOR
  1778. };
  1779. void LRF_HardwareManager::restartService( void ){
  1780. m_nFlipEnaFLags = 0;
  1781. m_nDetectionFilter = 0;
  1782. };
  1783. bool LRF_HardwareManager::reset( bool Hard ){
  1784. uint8_t lrfID;
  1785. m_nFlipEnaFLags = 0;
  1786. m_nDetectionFilter = 0;
  1787. if( Hard ){
  1788. #ifdef DEBUG
  1789. LOG("Waiting Till Flip Process is Done");
  1790. #endif
  1791. if( 0 == pthread_mutex_lock( m_pFlipMutex ) ){
  1792. if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){
  1793. LOG_ERROR("Thread Detach Failed!");
  1794. };
  1795. };
  1796. #ifdef DEBUG
  1797. LOG("Stoping Cores!");
  1798. #endif
  1799. endService();
  1800. #ifdef DEBUG
  1801. LOG("Begin Reset TH Mems");
  1802. #endif
  1803. // Clear TH + Working TH
  1804. for( lrfID = 0; lrfID < ( KERNEL_COUNT << 1 ); lrfID++ ){
  1805. #ifdef DEBUG
  1806. LOG("Cleanup TH");
  1807. #endif
  1808. cleanTH( lrfID );
  1809. #ifdef DEBUG
  1810. LOG("Done Cleanup TH");
  1811. #endif
  1812. };
  1813. #ifdef DEBUG
  1814. LOG("Starting Cores!");
  1815. #endif
  1816. beginService();
  1817. #ifdef DEBUG
  1818. LOG("Core Startup is Done!");
  1819. #endif
  1820. pthread_mutex_unlock( m_pFlipMutex );
  1821. #ifdef DEBUG
  1822. LOG("TH Reset is Done!");
  1823. #endif
  1824. } else {
  1825. #ifdef DEBUG
  1826. LOG("Waiting Till Flip Process is Done");
  1827. #endif
  1828. if( 0 == pthread_mutex_lock( m_pFlipMutex ) ){
  1829. if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){
  1830. LOG_ERROR("Thread Detach Failed!");
  1831. };
  1832. };
  1833. #ifdef DEBUG
  1834. LOG("Begin Reset TH Mems");
  1835. #endif
  1836. // Clean Only TH
  1837. for( lrfID = 0; lrfID < KERNEL_COUNT; lrfID++ ){
  1838. #ifdef DEBUG
  1839. LOG("Cleanup TH");
  1840. #endif
  1841. cleanTH( lrfID );
  1842. #ifdef DEBUG
  1843. LOG("Done Cleanup TH");
  1844. #endif
  1845. };
  1846. pthread_mutex_unlock( m_pFlipMutex );
  1847. #ifdef DEBUG
  1848. LOG("TH Reset is Done!");
  1849. #endif
  1850. };
  1851. return true;
  1852. };
  1853. #ifndef PRU_SLAVE
  1854. #ifndef ONPC_TOTTAL_SIMULATOR
  1855. #ifdef THREADED_MOTORS_START
  1856. void *LRF_HardwareManager::m_fMotorStartThreadFunction( void *ptr ){
  1857. LRF_HardwareManager *me;
  1858. me = (LRF_HardwareManager*)ptr;
  1859. me->performStartMotors();
  1860. pthread_exit( NULL );
  1861. return NULL;
  1862. };
  1863. void *LRF_HardwareManager::m_fMotorStopThreadFunction( void *ptr ){
  1864. LRF_HardwareManager *me;
  1865. me = (LRF_HardwareManager*)ptr;
  1866. me->performStopMotors();
  1867. pthread_exit( NULL );
  1868. return NULL;
  1869. };
  1870. #endif //THREADED_MOTORS_START
  1871. #endif //#ifndef ONPC_TOTTAL_SIMULATOR
  1872. #endif //PRU_SLAVE
  1873. #ifdef THREADED_FLIP
  1874. void *LRF_HardwareManager::m_fFlipThreadFunction( void *ptr ){
  1875. LRF_HardwareManager *me;
  1876. me = (LRF_HardwareManager*)ptr;
  1877. me->performFlip();
  1878. me->m_bFlipUnlockRequested = true;
  1879. pthread_exit( NULL );
  1880. return NULL;
  1881. };
  1882. #endif
  1883. static uint32_t m_sgnFlipCounter = 0;
  1884. #ifdef TH_NEW_FLIP_FUNC
  1885. bool LRF_HardwareManager::performFlip( void ){
  1886. if( !m_bInitOK ) return false;
  1887. #ifndef ONPC_TOTTAL_SIMULATOR
  1888. if( m_pSOC != NULL ){
  1889. char Buffer[256];//Used also in Event!!
  1890. volatile thresholdNode * th_node[16];
  1891. uint32_t LBA_ID;
  1892. uint8_t LRF_ID;
  1893. uint32_t cMax;
  1894. uint32_t cMin;
  1895. thresholdNode tTN;
  1896. int32_t cNodeID;
  1897. int32_t sNodeID; // Start point
  1898. bool QAreaOK;
  1899. th_node[0] = (volatile thresholdNode *) m_pSOC->getTH_MEMORY();
  1900. #ifdef DEBUG
  1901. sprintf( Buffer, "NF TH pointer is: %p", th_node );
  1902. LOG( Buffer );
  1903. #endif
  1904. if( th_node[0] != NULL ){
  1905. th_node[1] = th_node[0]+ TH_SIZE_NODES;
  1906. th_node[2] = th_node[1]+ TH_SIZE_NODES;
  1907. th_node[3] = th_node[2]+ TH_SIZE_NODES;
  1908. th_node[4] = th_node[3]+ TH_SIZE_NODES;
  1909. th_node[5] = th_node[4]+ TH_SIZE_NODES;
  1910. th_node[6] = th_node[5]+ TH_SIZE_NODES;
  1911. th_node[7] = th_node[6]+ TH_SIZE_NODES;
  1912. th_node[8] = th_node[7]+ TH_SIZE_NODES;
  1913. th_node[9] = th_node[8]+ TH_SIZE_NODES;
  1914. th_node[10] = th_node[9]+ TH_SIZE_NODES;
  1915. th_node[11] = th_node[10]+ TH_SIZE_NODES;
  1916. th_node[12] = th_node[11]+ TH_SIZE_NODES;
  1917. th_node[13] = th_node[12]+ TH_SIZE_NODES;
  1918. th_node[14] = th_node[13]+ TH_SIZE_NODES;
  1919. th_node[15] = th_node[14]+ TH_SIZE_NODES;
  1920. // Set All TH as full of Good Points
  1921. m_nGPointsFlags = m_nKernelFilter; //0xFF
  1922. for( LRF_ID = 0; LRF_ID<KERNEL_COUNT; LRF_ID++ ){
  1923. //Filter Disabled Kernels
  1924. if( ((1 << LRF_ID ) & m_nKernelFilter ) == 0 ) continue;
  1925. // Begin Scan Threshold
  1926. #ifdef DEBUG
  1927. sprintf( Buffer, "Building WTH for %dth Kernel", LRF_ID );
  1928. LOG( Buffer );
  1929. #endif
  1930. for( LBA_ID = 0; LBA_ID < TH_SIZE_NODES; LBA_ID++ ){
  1931. uint32_t LocalStrideX = LBA_ID % TH_LINE_NODES;
  1932. uint32_t LocalStrideY = LBA_ID / TH_LINE_NODES;
  1933. // Get Central TH Point
  1934. tTN.data = th_node[LRF_ID][LBA_ID].data;
  1935. // if point was blocked by SunBit
  1936. if( tTN.values.sbit ) {
  1937. tTN.values.sbit = 0;
  1938. tTN.values.cnt = 0;
  1939. tTN.values.min = 0;
  1940. tTN.values.max = 4095;
  1941. for( int x = -m_sPARAMETERS.nOrder; x < (m_sPARAMETERS.nOrder+1); x++ ) {
  1942. for( int y = -m_sPARAMETERS.nOrder; y < (m_sPARAMETERS.nOrder+1); y++ ) {
  1943. int LocalX = LocalStrideX+x;
  1944. int LocalY = LocalStrideY+y;
  1945. if( LocalY < 0 ) LocalY += Q_SCAN_COUNT;
  1946. if( LocalY >= Q_SCAN_COUNT ) LocalY -= Q_SCAN_COUNT;
  1947. if( LocalX < 0 ) LocalX += M_SCAN_POINTS;
  1948. if( LocalX >= TH_LINE_NODES ) LocalX -= TH_LINE_NODES;
  1949. uint32_t CleanID = ( LocalY * TH_LINE_NODES ) + LocalX;
  1950. th_node[8|LRF_ID][CleanID].data = tTN.data;
  1951. };
  1952. };
  1953. continue;
  1954. };
  1955. // if point was measured
  1956. #ifdef STRONG_STAT
  1957. if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){
  1958. #else
  1959. if( tTN.values.cnt ){
  1960. #endif
  1961. cMax = 0;
  1962. cMin = 4095;
  1963. QAreaOK = true;
  1964. for( int x = -m_sPARAMETERS.nOrder; x < (m_sPARAMETERS.nOrder+1); x++ ) {
  1965. for( int y = -m_sPARAMETERS.nOrder; y < (m_sPARAMETERS.nOrder+1); y++ ) {
  1966. int LocalX = LocalStrideX+x;
  1967. int LocalY = LocalStrideY+y;
  1968. if( LocalY < 0 ) LocalY += Q_SCAN_COUNT;
  1969. if( LocalY >= Q_SCAN_COUNT ) LocalY -= Q_SCAN_COUNT;
  1970. if( LocalX < 0 ) LocalX += M_SCAN_POINTS;
  1971. if( LocalX >= TH_LINE_NODES ) LocalX -= TH_LINE_NODES;
  1972. uint32_t TestID = ( LocalY * TH_LINE_NODES ) + LocalX;
  1973. tTN.data = th_node[LRF_ID][TestID].data;
  1974. #ifdef STRONG_STAT
  1975. if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){
  1976. #else
  1977. if( tTN.values.cnt ){
  1978. #endif
  1979. if( cMax < tTN.values.max ) cMax = tTN.values.max;
  1980. if( cMin > tTN.values.min ) cMin = tTN.values.min;
  1981. } else {
  1982. QAreaOK = false;
  1983. break;
  1984. };
  1985. };
  1986. if( !QAreaOK ) break;
  1987. };
  1988. if( QAreaOK ){
  1989. tTN.values.cnt = 0x0F;
  1990. tTN.values.min =(cMin>m_sCP_Detector.offset)?cMin-m_sCP_Detector.offset:0;
  1991. tTN.values.max =(cMax<(4095-m_sCP_Detector.offset))?cMax+m_sCP_Detector.offset:4095;
  1992. } else {
  1993. // disable detection of that point
  1994. tTN.values.cnt = 0;
  1995. tTN.values.min = 0;
  1996. tTN.values.max = 4095;
  1997. #ifdef STRONG_STAT
  1998. // Clear GoodPoint Flags at not complete TH Measurement
  1999. // Turn off TH Clean
  2000. m_nGPointsFlags &= ~( 1 << LRF_ID );
  2001. #endif
  2002. };
  2003. } else {
  2004. // Not Enought points in values.cnt
  2005. // disable detection of that point
  2006. tTN.values.cnt = 0;
  2007. #ifndef TH_JUST_UPDATE_WORKING
  2008. tTN.values.min = 0;
  2009. tTN.values.max = 4095;
  2010. #endif
  2011. // Clear GoodPoint Flags at not measured point
  2012. // Turn off TH Clean
  2013. m_nGPointsFlags &= ~( 1 << LRF_ID );
  2014. };
  2015. #ifdef TH_JUST_UPDATE_WORKING
  2016. // Just Update - Without Remove TH Old Info
  2017. if( tTN.values.cnt ){
  2018. th_node[8|LRF_ID][LBA_ID].data = tTN.data;
  2019. };
  2020. #else
  2021. th_node[8|LRF_ID][LBA_ID].data = tTN.data;
  2022. #endif
  2023. };
  2024. };
  2025. #ifdef DEBUG
  2026. LOG("Finish Cycle");
  2027. #endif
  2028. #ifdef TH_FORCED_BOOM_CLEAN
  2029. for( LRF_ID = 0; LRF_ID < KERNEL_COUNT; LRF_ID++ ){
  2030. if( m_nFlipEnaFLags & (1<<LRF_ID) ){
  2031. if( m_bTHSteadyCounter[LRF_ID] ){
  2032. m_bTHSteadyCounter[LRF_ID] --;
  2033. } else {
  2034. #ifdef DEBUG
  2035. sprintf( Buffer, "Cleanup TH%d", LRF_ID );
  2036. LOG(Buffer);
  2037. #endif
  2038. cleanTH( LRF_ID );
  2039. #ifdef DEBUG
  2040. sprintf( Buffer, "Done Cleanup TH%d", LRF_ID );
  2041. LOG( Buffer );
  2042. #endif
  2043. m_bTHSteadyCounter[LRF_ID] = m_sCP_Detector.good_points;
  2044. };
  2045. };
  2046. };
  2047. #endif //TH_FORCED_BOOM_CLEAN
  2048. // To perform cleaning of Threshold next time
  2049. m_nFlipEnaFLags = m_nGPointsFlags;
  2050. // To Enable Detection
  2051. m_nDetectionFilter |= m_nGPointsFlags;
  2052. m_sgnFlipCounter++;
  2053. sprintf( Buffer, "Flip#%d is Done: 0x%X", m_sgnFlipCounter, m_nFlipEnaFLags );
  2054. #ifdef DEBUG
  2055. LOG( Buffer );
  2056. #endif
  2057. if( m_bDumpMemoryToDisk && ( ( m_sgnFlipCounter % 6 ) == 0 ) ) {
  2058. thresholdNode *tNode;
  2059. thresholdNode *rNode;
  2060. rNode = tNode = (thresholdNode *) m_pSOC->getTH_MEMORY();
  2061. if( tNode != NULL ) {
  2062. LOG( "Save Memory Dump!");
  2063. FILE *fd;
  2064. char tName[64];
  2065. for( int index = 0; index < KERNEL_COUNT; index++ ) {
  2066. sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index );
  2067. fd = fopen(tName, "wb+");
  2068. if( fd != NULL ) {
  2069. uint32_t tSize;
  2070. tSize = TH_SIZE_NODES;
  2071. fwrite( &tSize, sizeof(uint32_t), 1, fd );
  2072. fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd );
  2073. fclose(fd);
  2074. } else {
  2075. LOG_ERROR( "Mem Dump Failure!");
  2076. };
  2077. tNode += TH_SIZE_NODES;
  2078. };
  2079. nMemoryDumpID++;
  2080. };
  2081. };
  2082. EVENT_CONTAINER *tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_FLIP, Buffer, NULL );
  2083. if( tEvt != NULL ){
  2084. basicEventHeap::getInstance()->broadcast( tEvt );
  2085. // Evt utilisation done by EventHeap thread
  2086. tEvt = NULL;
  2087. };
  2088. #ifdef HIBERNATE_ENABLE
  2089. return saveHibernatedTH();
  2090. #else
  2091. return true;
  2092. #endif
  2093. } else {
  2094. LOG_ERROR("Cannot access TH Memory!");
  2095. };
  2096. } else {
  2097. LOG_ERROR("No SOC Object!");
  2098. };
  2099. return false;
  2100. #else //#ifndef ONPC_TOTTAL_SIMULATOR
  2101. return true;
  2102. #endif //#ifndef ONPC_TOTTAL_SIMULATOR
  2103. };
  2104. #else // TH_NEW_FLIP_FUNC == 0
  2105. bool LRF_HardwareManager::performFlip( void ){
  2106. if( !m_bInitOK ) return false;
  2107. if( m_pSOC != NULL ){
  2108. char Buffer[256];
  2109. #ifdef TH_PER_MIRROR
  2110. volatile thresholdNode *th_node[40];
  2111. #else
  2112. volatile thresholdNode *th_node[16];
  2113. #endif
  2114. uint32_t sampleID;
  2115. uint8_t lrfID;
  2116. uint32_t cMax;
  2117. uint32_t cMin;
  2118. thresholdNode tTN;
  2119. int32_t cNodeID;
  2120. int32_t sNodeID; // Start point
  2121. uint8_t QAreaOK;
  2122. uint8_t i,j;
  2123. th_node[0] = (volatile thresholdNode *) m_pSOC->getTH_MEMORY();
  2124. th_node[1] = th_node[0]+ TH_SIZE_NODES;
  2125. th_node[2] = th_node[1]+ TH_SIZE_NODES;
  2126. th_node[3] = th_node[2]+ TH_SIZE_NODES;
  2127. th_node[4] = th_node[3]+ TH_SIZE_NODES;
  2128. th_node[5] = th_node[4]+ TH_SIZE_NODES;
  2129. th_node[6] = th_node[5]+ TH_SIZE_NODES;
  2130. th_node[7] = th_node[6]+ TH_SIZE_NODES;
  2131. th_node[8] = th_node[7]+ TH_SIZE_NODES;
  2132. th_node[9] = th_node[8]+ TH_SIZE_NODES;
  2133. th_node[10] = th_node[9]+ TH_SIZE_NODES;
  2134. th_node[11] = th_node[10]+ TH_SIZE_NODES;
  2135. th_node[12] = th_node[11]+ TH_SIZE_NODES;
  2136. th_node[13] = th_node[12]+ TH_SIZE_NODES;
  2137. th_node[14] = th_node[13]+ TH_SIZE_NODES;
  2138. th_node[15] = th_node[14]+ TH_SIZE_NODES;
  2139. #ifdef TH_PER_MIRROR
  2140. th_node[16] = th_node[15]+ TH_SIZE_NODES;
  2141. th_node[17] = th_node[16]+ TH_SIZE_NODES;
  2142. th_node[18] = th_node[17]+ TH_SIZE_NODES;
  2143. th_node[19] = th_node[18]+ TH_SIZE_NODES;
  2144. th_node[20] = th_node[19]+ TH_SIZE_NODES;
  2145. th_node[21] = th_node[20]+ TH_SIZE_NODES;
  2146. th_node[22] = th_node[21]+ TH_SIZE_NODES;
  2147. th_node[23] = th_node[22]+ TH_SIZE_NODES;
  2148. th_node[24] = th_node[23]+ TH_SIZE_NODES;
  2149. th_node[25] = th_node[24]+ TH_SIZE_NODES;
  2150. th_node[26] = th_node[25]+ TH_SIZE_NODES;
  2151. th_node[27] = th_node[26]+ TH_SIZE_NODES;
  2152. th_node[28] = th_node[27]+ TH_SIZE_NODES;
  2153. th_node[29] = th_node[28]+ TH_SIZE_NODES;
  2154. th_node[30] = th_node[29]+ TH_SIZE_NODES;
  2155. th_node[31] = th_node[30]+ TH_SIZE_NODES;
  2156. th_node[32] = th_node[31]+ TH_SIZE_NODES;
  2157. th_node[33] = th_node[32]+ TH_SIZE_NODES;
  2158. th_node[34] = th_node[33]+ TH_SIZE_NODES;
  2159. th_node[35] = th_node[34]+ TH_SIZE_NODES;
  2160. th_node[36] = th_node[35]+ TH_SIZE_NODES;
  2161. th_node[37] = th_node[36]+ TH_SIZE_NODES;
  2162. th_node[38] = th_node[37]+ TH_SIZE_NODES;
  2163. th_node[39] = th_node[38]+ TH_SIZE_NODES;
  2164. #endif
  2165. sprintf( Buffer, "OF TH pointer is: %p", th_node );
  2166. LOG( Buffer );
  2167. m_nGPointsFlags = 0xFF;
  2168. #ifdef DEBUG
  2169. //LOG("Performing FLIP in HOST SOC");
  2170. #endif
  2171. if( th_node != NULL ){
  2172. #ifdef DEBUG
  2173. char tBuffer[128];
  2174. sprintf(tBuffer, "Start Cycle order: %d Good Points: %d", m_sPARAMETERS.nOrder, m_sPARAMETERS.nGPointSamples );
  2175. LOG( tBuffer );
  2176. #endif
  2177. for( sampleID=0; sampleID < TH_SIZE_NODES; sampleID++ ){
  2178. sNodeID = sampleID - ( TH_LINE_NODES + 1 ) * m_sCP_Detector.order;
  2179. #ifdef TH_PER_MIRROR
  2180. for( lrfID = 0; lrfID < KERNEL_COUNT * Q_MIRROR_COUNT; lrfID++ ){
  2181. #else
  2182. for( lrfID = 0; lrfID < KERNEL_COUNT; lrfID++ ){
  2183. #endif
  2184. //Filter Kernel
  2185. if( ((1 << lrfID ) & m_nKernelFilter ) == 0 ) continue;
  2186. // Get Central TH Point
  2187. tTN.data = th_node[lrfID][sampleID].data;
  2188. // if point was measured
  2189. //if( tTN.values.cnt >= m_sCP_Detector.good_points ){
  2190. #ifdef STRONG_STAT
  2191. if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){
  2192. #else
  2193. if( tTN.values.cnt ){
  2194. #endif
  2195. cMax = 0;
  2196. cMin = 4095;
  2197. QAreaOK = 1;
  2198. //for( i = 0; i < (( m_sCP_Detector.order << 1 ) + 1 ); i++ ){
  2199. for( i = 0; i < (( m_sPARAMETERS.nOrder << 1 ) + 1 ); i++ ){
  2200. cNodeID = sNodeID + ( i * TH_LINE_NODES );
  2201. //for( j = 0; j < (( m_sCP_Detector.order << 1 ) + 1 ); j++ ){
  2202. for( j = 0; j < (( m_sPARAMETERS.nOrder << 1 ) + 1 ); j++ ){
  2203. cNodeID ++;
  2204. if( cNodeID < 0 ) continue;
  2205. if( cNodeID < TH_SIZE_NODES ){
  2206. tTN.data = th_node[lrfID][cNodeID].data;
  2207. #ifdef STRONG_STAT
  2208. if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){
  2209. #else
  2210. if( tTN.values.cnt ){
  2211. #endif
  2212. if( cMax < tTN.values.max ) cMax = tTN.values.max;
  2213. if( cMin > tTN.values.min ) cMin = tTN.values.min;
  2214. } else {
  2215. QAreaOK = 0;
  2216. break;
  2217. };
  2218. };
  2219. };
  2220. if( QAreaOK == 0 ) break;
  2221. };
  2222. if( QAreaOK == 0 ){
  2223. // disable detection of that point
  2224. tTN.values.cnt = 0;
  2225. tTN.values.min = 0;
  2226. tTN.values.max = 4095;
  2227. } else {
  2228. tTN.values.cnt = 0x0F;
  2229. tTN.values.min =(cMin>m_sCP_Detector.offset)?cMin-m_sCP_Detector.offset:0;
  2230. tTN.values.max =(cMax<(4095-m_sCP_Detector.offset))?cMax+m_sCP_Detector.offset:4095;
  2231. };
  2232. } else { // Not Enought points in values.cnt
  2233. // disable detection of that point
  2234. tTN.values.cnt = 0;
  2235. #ifndef TH_JUST_UPDATE_WORKING
  2236. tTN.values.min = 0;
  2237. tTN.values.max = 4095;
  2238. #endif
  2239. // Clear GoodPoint Flags at not measured point
  2240. m_nGPointsFlags &=~(1<<lrfID);
  2241. };
  2242. #ifdef TH_JUST_UPDATE_WORKING
  2243. // Just Update - Without Remove TH Old Info
  2244. if( tTN.values.cnt ){
  2245. #endif
  2246. #ifdef TH_PER_MIRROR
  2247. th_node[20|( lrfID >> 2 )][sampleID].data = tTN.data;
  2248. #else
  2249. th_node[8|lrfID][sampleID].data = tTN.data;
  2250. #endif
  2251. #ifdef TH_JUST_UPDATE_WORKING
  2252. };
  2253. #endif
  2254. };
  2255. };
  2256. #ifdef DEBUG
  2257. //LOG("Finish Cycle");
  2258. #endif
  2259. #ifdef TH_FORCED_BOOM_CLEAN
  2260. for( lrfID = 0; lrfID < KERNEL_COUNT; lrfID++ ){
  2261. if( m_nFlipEnaFLags & (1<<lrfID) ){
  2262. #ifdef DEBUG
  2263. sprintf( Buffer, "Cleanup TH%d", lrfID );
  2264. LOG(Buffer);
  2265. #endif
  2266. cleanTH( lrfID );
  2267. #ifdef DEBUG
  2268. sprintf( Buffer, "Done Cleanup TH%d", lrfID );
  2269. LOG( Buffer );
  2270. #endif
  2271. };
  2272. };
  2273. #endif //TH_FORCED_BOOM_CLEAN
  2274. // To perform cleaning of Threshold next time
  2275. m_nFlipEnaFLags = m_nGPointsFlags;
  2276. // To Enable Detection
  2277. m_nDetectionFilter |= m_nGPointsFlags;
  2278. m_sgnFlipCounter++;
  2279. sprintf( Buffer, "Flip#%d is Done: 0x%X", m_sgnFlipCounter, m_nFlipEnaFLags );
  2280. #ifdef DEBUG
  2281. LOG( Buffer );
  2282. #endif
  2283. if( m_bDumpMemoryToDisk && ( ( m_sgnFlipCounter % 6 ) == 0 ) ) {
  2284. thresholdNode *tNode;
  2285. thresholdNode *rNode;
  2286. rNode = tNode = (thresholdNode *) m_pSOC->getTH_MEMORY();
  2287. if( tNode != NULL ) {
  2288. LOG( "Save Memory Dump!");
  2289. FILE *fd;
  2290. char tName[64];
  2291. for( int index = 0; index < KERNEL_COUNT; index++ ) {
  2292. sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index );
  2293. fd = fopen(tName, "wb+");
  2294. if( fd != NULL ) {
  2295. uint32_t tSize;
  2296. tSize = TH_SIZE_NODES;
  2297. fwrite( &tSize, sizeof(uint32_t), 1, fd );
  2298. fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd );
  2299. fclose(fd);
  2300. } else {
  2301. LOG_ERROR( "Mem Dump Failure!");
  2302. };
  2303. tNode += TH_SIZE_NODES;
  2304. };
  2305. nMemoryDumpID++;
  2306. };
  2307. };
  2308. basicEvent *tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR, EVT_FLIP, Buffer, NULL );
  2309. if( tEvt != NULL ){
  2310. basicEventHeap::getInstance()->broadcast( tEvt );
  2311. // Evt utilisation done by EventHeap thread
  2312. tEvt = NULL;
  2313. };
  2314. #ifdef HIBERNATE_ENABLE
  2315. return saveHibernatedTH();
  2316. #else
  2317. return true;
  2318. #endif
  2319. } else {
  2320. LOG_ERROR("Cannot access TH Memory!");
  2321. };
  2322. };
  2323. return false;
  2324. };
  2325. #endif //TH_NEW_FLIP_FUNC
  2326. #ifdef HIBERNATE_ENABLE
  2327. bool LRF_HardwareManager::saveHibernatedTH( CSTR fname ){
  2328. FILE *fd;
  2329. fd = fopen( fname, "wb+" );
  2330. if( fd!= NULL) {
  2331. uint32_t *mem;
  2332. uint32_t size;
  2333. mem = m_pSOC->getTH_MEMORY();
  2334. if(mem!= NULL) {
  2335. size = TH_SIZE_NODES << 4;
  2336. fwrite( &mem, sizeof(mem), 1, fd ); // origin
  2337. fwrite( &size, sizeof(size), 1, fd ); // size
  2338. fwrite( mem, sizeof(size), size, fd ); // content
  2339. } else {
  2340. LOG_ERROR("Can not access to TH memories during save Hibernate!");
  2341. return false;
  2342. };
  2343. fclose( fd );
  2344. } else {
  2345. LOG_ERROR("Can not create Hibernate File!");
  2346. return false;
  2347. };
  2348. return true;
  2349. };
  2350. bool LRF_HardwareManager::loadHibernatedTH( CSTR fname ){
  2351. FILE *fd;
  2352. fd = fopen( fname, "wb+" );
  2353. if( fd!= NULL) {
  2354. uint32_t *mem;
  2355. uint32_t *pem;
  2356. uint32_t size;
  2357. mem = m_pSOC->getTH_MEMORY();
  2358. if(mem!= NULL) {
  2359. fread( &pem, sizeof(mem), 1, fd ); // origin
  2360. fread( &size, sizeof(size), 1, fd ); // size
  2361. fread( mem, sizeof(size), size, fd ); // content
  2362. } else {
  2363. LOG_ERROR("Can not access to TH memories during load Hibernate!");
  2364. return false;
  2365. };
  2366. fclose( fd );
  2367. } else {
  2368. LOG_ERROR("Can not read Hibernate File!");
  2369. return false;
  2370. };
  2371. return true;
  2372. };
  2373. #endif
  2374. bool LRF_HardwareManager::cleanTH( uint8_t tID ){
  2375. #ifndef ONPC_TOTTAL_SIMULATOR
  2376. if( m_pSOC != NULL ) {
  2377. uint32_t *thPtr;
  2378. thPtr = m_pSOC->getTH_MEMORY();
  2379. if( thPtr ){
  2380. thPtr += ( tID & 0x0F ) * TH_SIZE_NODES;
  2381. int index = 0; // fl|Max|Min
  2382. for(; index < TH_SIZE_NODES; thPtr++, index++ ) *thPtr = 0x00000FFF;
  2383. return true;
  2384. };
  2385. };
  2386. return false;
  2387. #else //#ifndef ONPC_TOTTAL_SIMULATOR
  2388. return true;
  2389. #endif //#ifndef ONPC_TOTTAL_SIMULATOR
  2390. };
  2391. void LRF_HardwareManager::saveCurrentParameters( void ){
  2392. if( m_pSettings != NULL ) {
  2393. config_setting_t *pSetting;
  2394. int tVal;
  2395. char tBuffer[256];
  2396. LOG("HW Saving Settings ...");
  2397. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_DUMP ) ){
  2398. tVal = m_bDumpMemoryToDisk;
  2399. config_setting_set_bool( pSetting, tVal );
  2400. m_pSettingsProvider->compromise();
  2401. } else {
  2402. LOG_ERROR( "Error Saving Settings!" );
  2403. return;
  2404. };
  2405. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_ROLE ) ){
  2406. tVal = m_sPARAMETERS.flags.isMaster;
  2407. config_setting_set_bool( pSetting, tVal );
  2408. m_pSettingsProvider->compromise();
  2409. LOG("No role defined");
  2410. } else {
  2411. LOG_ERROR( "Error Saving Settings!" );
  2412. return;
  2413. };
  2414. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_SUNBIT ) ){
  2415. tVal = m_sPARAMETERS.flags.Sunbit_filter;
  2416. config_setting_set_bool( pSetting, tVal );
  2417. m_pSettingsProvider->compromise();
  2418. LOG("No SUNBIT action defined - Disabling!");
  2419. } else {
  2420. LOG_ERROR( "Error Saving Settings!" );
  2421. return;
  2422. };
  2423. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_LRF_ENABLED ) ){
  2424. tVal = m_sPARAMETERS.flags.LaserPulsesOn;
  2425. config_setting_set_bool( pSetting, tVal );
  2426. m_pSettingsProvider->compromise();
  2427. LOG("No LRF Enabled");
  2428. } else {
  2429. LOG_ERROR( "Error Saving Settings!" );
  2430. return;
  2431. };
  2432. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_SIG_SYMULATOR ) ){
  2433. tVal = m_sPARAMETERS.flags.SignalSimulator;
  2434. config_setting_set_bool( pSetting, tVal );
  2435. m_pSettingsProvider->compromise();
  2436. LOG("No Sig Symulator Settings");
  2437. } else {
  2438. LOG_ERROR( "Error Saving Settings!" );
  2439. return;
  2440. };
  2441. if( !m_sPARAMETERS.flags.SignalSimulator ) {
  2442. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_AUTOSTART_ENABLED ) ){
  2443. tVal = m_sPARAMETERS.flags.AutostartMotors;
  2444. config_setting_set_bool( pSetting, tVal );
  2445. m_pSettingsProvider->compromise();
  2446. LOG("No Motor Autostart Settings");
  2447. } else {
  2448. LOG_ERROR( "Error Saving Settings!" );
  2449. return;
  2450. };
  2451. if( !m_sPARAMETERS.flags.AutostartMotors ) {
  2452. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CTRL_V_MOTOR ) ){
  2453. tVal = m_sPARAMETERS.flags.VerticalMotorOn;
  2454. config_setting_set_bool( pSetting, tVal );
  2455. m_pSettingsProvider->compromise();
  2456. LOG("No Vertical Controll");
  2457. } else {
  2458. LOG_ERROR( "Error Saving Settings!" );
  2459. return;
  2460. };
  2461. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CTRL_H_MOTOR ) ){
  2462. tVal = m_sPARAMETERS.flags.HorizontalMotorOn;
  2463. config_setting_set_bool( pSetting, tVal );
  2464. m_pSettingsProvider->compromise();
  2465. LOG("No Horizontal Controll");
  2466. } else {
  2467. LOG_ERROR( "Error Saving Settings!" );
  2468. return;
  2469. };
  2470. };
  2471. }
  2472. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_V_MOTOR_SETPOINT ) ){
  2473. tVal = m_sPARAMETERS.flags.VerticalFreq;
  2474. config_setting_set_int(pSetting, tVal );
  2475. m_pSettingsProvider->compromise();
  2476. LOG("No Mirror Block Freq");
  2477. } else {
  2478. LOG_ERROR( "Error Saving Settings!" );
  2479. return;
  2480. };
  2481. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_H_MOTOR_SETPOINT ) ){
  2482. tVal = m_sPARAMETERS.flags.HorizontalFreq;
  2483. config_setting_set_int(pSetting, tVal );
  2484. m_pSettingsProvider->compromise();
  2485. LOG("No Base Block Freq");
  2486. } else {
  2487. LOG_ERROR( "Error Saving Settings!" );
  2488. return;
  2489. };
  2490. if ( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_V_PULSES_INTERLEAVE ) ){
  2491. tVal = m_sPARAMETERS.flags.QQinterlace;
  2492. config_setting_set_int(pSetting, tVal );
  2493. m_pSettingsProvider->compromise();
  2494. LOG("No Q Pulses per LRF pulse Setting");
  2495. } else {
  2496. LOG_ERROR( "Error Saving Settings!" );
  2497. return;
  2498. };
  2499. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_OFFSET ) ){
  2500. tVal = m_sPARAMETERS.nOffset;
  2501. config_setting_set_int(pSetting, tVal );
  2502. m_pSettingsProvider->compromise();
  2503. LOG("No TH Offset Setting");
  2504. } else {
  2505. LOG_ERROR( "Error Saving Settings!" );
  2506. return;
  2507. };
  2508. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_ORDER ) ){
  2509. tVal = m_sPARAMETERS.nOrder;
  2510. config_setting_set_int(pSetting, tVal );
  2511. m_pSettingsProvider->compromise();
  2512. LOG("No TH Order Setting");
  2513. } else {
  2514. LOG_ERROR( "Error Saving Settings!" );
  2515. return;
  2516. };
  2517. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_DELTA ) ){
  2518. tVal = m_sPARAMETERS.nDelta;
  2519. config_setting_set_int(pSetting, tVal );
  2520. m_pSettingsProvider->compromise();
  2521. LOG("No TH Delta Setting");
  2522. } else {
  2523. LOG_ERROR( "Error Saving Settings!" );
  2524. return;
  2525. };
  2526. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_FLIP_SIZE ) ){
  2527. tVal = m_sPARAMETERS.nFlip;
  2528. config_setting_set_int(pSetting, tVal );
  2529. m_pSettingsProvider->compromise();
  2530. LOG("No TH Flip Size Setting");
  2531. } else {
  2532. LOG_ERROR( "Error Saving Settings!" );
  2533. return;
  2534. };
  2535. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_GOOD_POINTS ) ){
  2536. tVal = m_sPARAMETERS.nGPointSamples;
  2537. config_setting_set_int(pSetting, tVal );
  2538. m_pSettingsProvider->compromise();
  2539. LOG("No TH Good Points Setting");
  2540. } else {
  2541. LOG_ERROR( "Error Saving Settings!" );
  2542. return;
  2543. };
  2544. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_AUTO_TH_GENERATE ) ){
  2545. tVal = m_sPARAMETERS.flags.BuildThByCore;
  2546. config_setting_set_bool( pSetting, tVal );
  2547. m_pSettingsProvider->compromise();
  2548. LOG("No TH Build By Core Setting");
  2549. } else {
  2550. LOG_ERROR( "Error Saving Settings!" );
  2551. return;
  2552. };
  2553. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_SPIKE_SIZE ) ){
  2554. tVal = m_sPARAMETERS.flags.Spike_TH;
  2555. config_setting_set_int(pSetting, tVal );
  2556. m_pSettingsProvider->compromise();
  2557. LOG("No Spike Threshold Setting");
  2558. } else {
  2559. LOG_ERROR( "Error Saving Settings!" );
  2560. return;
  2561. };
  2562. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_CONTROL_ENABLE ) ){
  2563. tVal = m_sPARAMETERS.flags.TGZ_canENA;
  2564. config_setting_set_bool( pSetting, tVal );
  2565. m_pSettingsProvider->compromise();
  2566. LOG("No CAN Enable Setting");
  2567. } else {
  2568. LOG_ERROR( "Error Saving Settings!" );
  2569. return;
  2570. };
  2571. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_BUS_ID ) ){
  2572. tVal = m_sPARAMETERS.flags.TGZ_canBus;
  2573. config_setting_set_int(pSetting, tVal );
  2574. m_pSettingsProvider->compromise();
  2575. LOG("No CAN Bus ID Setting");
  2576. } else {
  2577. LOG_ERROR( "Error Saving Settings!" );
  2578. return;
  2579. };
  2580. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_MY_ID ) ){
  2581. tVal = m_sPARAMETERS.flags.TGZ_canSRC;
  2582. config_setting_set_int(pSetting, tVal );
  2583. m_pSettingsProvider->compromise();
  2584. LOG("No CAN My ID Setting");
  2585. } else {
  2586. LOG_ERROR( "Error Saving Settings!" );
  2587. return;
  2588. };
  2589. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_TGZ_ID ) ){
  2590. tVal = m_sPARAMETERS.flags.TGZ_canDST;
  2591. config_setting_set_int(pSetting, tVal );
  2592. m_pSettingsProvider->compromise();
  2593. LOG("No CAN TGZ ID Setting");
  2594. } else {
  2595. LOG_ERROR( "Error Saving Settings!" );
  2596. return;
  2597. };
  2598. #ifndef TGD_VERSION_2
  2599. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_DIVIDER ) ){
  2600. tVal = m_sPARAMETERS.flags.TGZ_divider;
  2601. config_setting_set_int(pSetting, tVal );
  2602. m_pSettingsProvider->compromise();
  2603. LOG("No TGZ Divider Setting");
  2604. } else {
  2605. LOG_ERROR( "Error Saving Settings!" );
  2606. return;
  2607. };
  2608. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_PRF ) ){
  2609. tVal = m_sPARAMETERS.flags.TGZ_ParamQ;
  2610. config_setting_set_int(pSetting, tVal );
  2611. m_pSettingsProvider->compromise();
  2612. LOG("No TGZ PRF Setting");
  2613. } else {
  2614. LOG_ERROR( "Error Saving Settings!" );
  2615. return;
  2616. };
  2617. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_RATIO ) ){
  2618. tVal = m_sPARAMETERS.flags.TGZ_ParamB;
  2619. config_setting_set_int(pSetting, tVal );
  2620. m_pSettingsProvider->compromise();
  2621. LOG("No TGZ Ratio Setting");
  2622. } else {
  2623. LOG_ERROR( "Error Saving Settings!" );
  2624. return;
  2625. };
  2626. #else
  2627. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_MIRROR_SPEED ) ){
  2628. tVal = m_sPARAMETERS.flags.TGZ_ParamQ;
  2629. config_setting_set_int(pSetting, tVal );
  2630. m_pSettingsProvider->compromise();
  2631. LOG("No TGZ Mirror Block Speed");
  2632. } else {
  2633. LOG_ERROR( "Error Saving Settings!" );
  2634. return;
  2635. };
  2636. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_BASE_SPEED ) ){
  2637. tVal = m_sPARAMETERS.flags.TGZ_ParamB;
  2638. config_setting_set_int(pSetting, tVal );
  2639. m_pSettingsProvider->compromise();
  2640. LOG("No TGZ Base Motor Speed");
  2641. } else {
  2642. LOG_ERROR( "Error Saving Settings!" );
  2643. return;
  2644. };
  2645. #endif
  2646. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_B_SHIFT ) ){
  2647. tVal = m_sPARAMETERS.flags.B_shift;
  2648. config_setting_set_int(pSetting, tVal );
  2649. m_pSettingsProvider->compromise();
  2650. LOG("No Base Shift");
  2651. } else {
  2652. LOG_ERROR( "Error Saving Settings!" );
  2653. return;
  2654. };
  2655. if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_Q_SHIFT ) ){
  2656. tVal = m_sPARAMETERS.flags.Q_shift;
  2657. config_setting_set_int(pSetting, tVal );
  2658. m_pSettingsProvider->compromise();
  2659. LOG("No Mirror Shift");
  2660. } else {
  2661. LOG_ERROR( "Error Saving Settings!" );
  2662. return;
  2663. };
  2664. if( m_pSettingsProvider->isCompromised() ) {
  2665. LOG("Save Settings");
  2666. m_pSettingsProvider->validate();
  2667. };
  2668. };
  2669. };
  2670. #undef LOG
  2671. #undef LOG_ERROR