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.

2701 lines
90 KiB

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