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.

2374 lines
78 KiB

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