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.

179 lines
6.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "motorWindow.h"
  2. motorWindow::motorWindow() : WindowCLI(NULL){
  3. m_pSOC = classSOC::getInstance();
  4. resetStat();
  5. m_x = 1;
  6. m_y = 18;
  7. m_w = 80;
  8. m_h = 17;
  9. #ifdef NEWT_CLI
  10. m_t1 = newtTextbox( 2, 1, 60, 1, 0 );
  11. m_t2 = newtTextbox( 2, 2, 60, 1, 0 );
  12. m_t3 = newtTextbox( 2, 3, 60, 1, 0 );
  13. m_t4 = newtTextbox( 2, 4, 60, 1, 0 );
  14. m_t5 = newtTextbox( 2, 5, 60, 1, 0 );
  15. m_t6 = newtTextbox( 2, 6, 60, 1, 0 );
  16. m_t7 = newtTextbox( 2, 7, 60, 1, 0 );
  17. m_t8 = newtTextbox( 2, 8, 60, 1, 0 );
  18. newtFormAddComponents( m_oForm, m_t1, m_t2, m_t3, m_t4, m_t5,
  19. m_t6, m_t7, m_t8, NULL );
  20. #else
  21. //create( 41, 18, 80, 17 );
  22. create( 1, 18, 80, 17 );
  23. #endif
  24. };
  25. motorWindow::~motorWindow(){
  26. newtPopWindow();
  27. };
  28. void motorWindow::paint( void ){
  29. char tBuffer[245];
  30. volatile structTUPUS *tTUPUS;
  31. tTUPUS = m_pSOC->getTUPUS( 0 , 1 );
  32. #ifdef NEWT_CLI
  33. newtCenteredWindow( m_w, m_h, "Motor Info" );
  34. if( tTUPUS != NULL ) {
  35. tTUPUS->HOST_status = 0;
  36. int cnt = 100;
  37. while( cnt-- && !tTUPUS->HOST_status) usleep( 20 );
  38. cur_P2P_HM = tTUPUS->HOST_data;
  39. if( cur_P2P_HM < min_P2P_HM ) min_P2P_HM = cur_P2P_HM;
  40. if( cur_P2P_HM > max_P2P_HM ) max_P2P_HM = cur_P2P_HM;
  41. cur_P2P_VM = tTUPUS->PRU_data;
  42. if( cur_P2P_VM < min_P2P_VM ) min_P2P_VM = cur_P2P_VM;
  43. if( cur_P2P_VM > max_P2P_VM ) max_P2P_VM = cur_P2P_VM;
  44. sprintf( tBuffer, "Signature:\t0x%08x", tTUPUS->PRU_id );
  45. newtTextboxSetText( m_t1, tBuffer );
  46. sprintf( tBuffer, "Host status:\t0x%08x", tTUPUS->HOST_status );
  47. newtTextboxSetText( m_t2, tBuffer );
  48. sprintf( tBuffer, "Host cmd:\t0x%08x", tTUPUS->HOST_command );
  49. newtTextboxSetText( m_t3, tBuffer );
  50. sprintf( tBuffer, "Motor Status: %s", (( tTUPUS->PRU_status & 0xFF000000)?"Synced":"Not Synced"));
  51. newtTextboxSetText( m_t4, tBuffer );
  52. sprintf( tBuffer, "Vertical Pulses per Rotation:\t%08d", tTUPUS->PRU_address );
  53. newtTextboxSetText( m_t5, tBuffer );
  54. sprintf( tBuffer, "Horizontal Pulses per Rotation:\t%08d", tTUPUS->HOST_address );
  55. newtTextboxSetText( m_t6, tBuffer );
  56. sprintf( tBuffer, "Horizontal Freq:\t%.2f kHz. Max: %.2f Min: %.2f",
  57. 1000000.0/( cur_P2P_HM * 5.0 ),
  58. 1000000.0/( min_P2P_HM * 5.0 ),
  59. 1000000.0/( max_P2P_HM * 5.0 )
  60. );
  61. newtTextboxSetText( m_t7, tBuffer );
  62. sprintf( tBuffer, "Vertical Freq:\t%.2f kHz. Max: %.2f Min: %.2f",
  63. 1000000.0/( cur_P2P_VM * 5.0 ),
  64. 1000000.0/( min_P2P_VM * 5.0 ),
  65. 1000000.0/( max_P2P_VM * 5.0 )
  66. );
  67. newtTextboxSetText( m_t8, tBuffer );
  68. } else {
  69. sprintf( tBuffer, "Not Initialized");
  70. newtTextboxSetText( m_t1, tBuffer );
  71. };
  72. newtDrawForm( m_oForm );
  73. newtRefresh();
  74. #else
  75. createBox( true );
  76. uint32_t KAKA = findInterleave();
  77. mvwprintw( m_pWND, 2,2,"--- MOTOR STATUS ---" );
  78. if( tTUPUS != NULL ) {
  79. cur_P2P_HM = tTUPUS->HOST_data;
  80. if( cur_P2P_HM < min_P2P_HM ) min_P2P_HM = cur_P2P_HM;
  81. if( cur_P2P_HM > max_P2P_HM ) max_P2P_HM = cur_P2P_HM;
  82. cur_P2P_VM = tTUPUS->PRU_data;
  83. if( cur_P2P_VM < min_P2P_VM ) min_P2P_VM = cur_P2P_VM;
  84. if( cur_P2P_VM > max_P2P_VM ) max_P2P_VM = cur_P2P_VM;
  85. mvwprintw( m_pWND, 3,2,"Signature:\t0x%08x", tTUPUS->PRU_id );
  86. mvwprintw( m_pWND, 4,2,"Host status:\t0x%08x Interleave:%d", tTUPUS->HOST_status, KAKA );
  87. mvwprintw( m_pWND, 5,2,"Host cmd:\t0x%08x", tTUPUS->HOST_command );
  88. mvwprintw( m_pWND, 6,2,"Motor Status: %s", (( tTUPUS->PRU_status & 0xFF000000)?"Synced":"Not Synced"));
  89. mvwprintw( m_pWND, 7,2,"Vertical Pulses per Rotation:\t%08d", tTUPUS->PRU_address );
  90. mvwprintw( m_pWND, 8,2,"Horizontal Pulses per Rotation:\t%08d", tTUPUS->HOST_address );
  91. mvwprintw( m_pWND, 9,2,"Horizontal Freq:\t%.2f kHz. Max: %.2f Min: %.2f",
  92. 1000000.0/( cur_P2P_HM * 5.0 ),
  93. 1000000.0/( min_P2P_HM * 5.0 ),
  94. 1000000.0/( max_P2P_HM * 5.0 )
  95. );
  96. mvwprintw( m_pWND, 10,2,"Vertical Freq:\t%.2f kHz. Max: %.2f Min: %.2f",
  97. 1000000.0/( cur_P2P_VM * 5.0 ),
  98. 1000000.0/( min_P2P_VM * 5.0 ),
  99. 1000000.0/( max_P2P_VM * 5.0 )
  100. );
  101. mvwprintw( m_pWND, 12,2,"Stat File:\tNot Started Yet" );
  102. mvwprintw( m_pWND, 13,2,"Harvesting Stat:\tNot Started Yet" );
  103. mvwprintw( m_pWND, 14,2,"Harvesting Status:\t\t\t." );
  104. tTUPUS->HOST_status = 0;
  105. } else {
  106. mvwprintw( m_pWND, 3,2,"Not Initialized");
  107. };
  108. wrefresh( m_pWND );
  109. #endif
  110. };
  111. void motorWindow::resetStat( void ){
  112. cur_P2P_HM = 0;
  113. min_P2P_HM = 0x7FFFFFFF;
  114. max_P2P_HM = 0;
  115. cur_P2P_VM = 0;
  116. min_P2P_VM = 0x7FFFFFFF;
  117. max_P2P_VM = 0;
  118. };
  119. void motorWindow::saveStatToFile( char *FileName ){
  120. FILE *fd;
  121. int baseCounter = 0;
  122. char Buffer[21];
  123. volatile structTUPUS *tTUPUS;
  124. tTUPUS = m_pSOC->getTUPUS( 0 , 1 );
  125. memset( Buffer,32,20);
  126. Buffer[20]=(char)0;
  127. if( FileName != NULL ) {
  128. #ifdef NEWT_CLI
  129. #else
  130. mvwprintw( m_pWND, 12,2,"Stat File:\t%s", FileName );
  131. #endif
  132. fd = fopen( FileName, "w+" );
  133. if(fd!=NULL){
  134. #ifdef NEWT_CLI
  135. #else
  136. mvwprintw( m_pWND, 14,2,"Harvesting Status:\tStarted." );
  137. wrefresh( m_pWND );
  138. #endif
  139. //fprintf( fd,"Base Rotation ID, Time ticks between Pulses of Mirror Block, Time ticks between Pulses of Base, Pulses per Revolution of Mirror Block, Pulses per Revolution of Base, Mirror Block Pulses per Base Pulse, Motors are Synced\r\n");
  140. fprintf( fd,"Base Rotation ID, Time ticks between Pulses of Mirror Block, Pulses per Revolution of Mirror Block, Mirror Block Revolutions per Base Revolution, Motors are in Sync\r\n");
  141. while( baseCounter< 20 ) {
  142. tTUPUS->HOST_status = 0;
  143. while( tTUPUS->HOST_status == 0 ) usleep(10);
  144. fprintf( fd,"%d,%d,%d,%d,%s\r\n",
  145. baseCounter,
  146. tTUPUS->PRU_data,
  147. //tTUPUS->HOST_data,
  148. tTUPUS->PRU_address,
  149. //tTUPUS->HOST_address,
  150. tTUPUS->HOST_command,
  151. ((tTUPUS->PRU_status & 0xFF000000 )?"YES":"NO")
  152. );
  153. if( tTUPUS->PRU_status & 0xFF0000 ){// Base Rotation Complete
  154. Buffer[baseCounter]='*';
  155. baseCounter++; //?
  156. #ifdef NEWT_CLI
  157. #else
  158. mvwprintw( m_pWND, 13,2,"Harvesting Stat:\t[%s]", Buffer );
  159. wrefresh( m_pWND );
  160. #endif
  161. tTUPUS->PRU_status &=0xFF00FFFF;
  162. };
  163. };
  164. #ifdef NEWT_CLI
  165. #else
  166. mvwprintw( m_pWND, 14,2,"Harvesting Status:\t\tDone." );
  167. wrefresh( m_pWND );
  168. #endif
  169. fclose(fd);
  170. chmod( FileName, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH );
  171. };
  172. };
  173. };