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.

2725 lines
91 KiB

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