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.

2718 lines
91 KiB

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