#include "motorWindow.h" motorWindow::motorWindow() : WindowCLI(NULL){ m_pSOC = classSOC::getInstance(); resetStat(); m_x = 1; m_y = 18; m_w = 80; m_h = 17; #ifdef NEWT_CLI m_t1 = newtTextbox( 2, 1, 60, 1, 0 ); m_t2 = newtTextbox( 2, 2, 60, 1, 0 ); m_t3 = newtTextbox( 2, 3, 60, 1, 0 ); m_t4 = newtTextbox( 2, 4, 60, 1, 0 ); m_t5 = newtTextbox( 2, 5, 60, 1, 0 ); m_t6 = newtTextbox( 2, 6, 60, 1, 0 ); m_t7 = newtTextbox( 2, 7, 60, 1, 0 ); m_t8 = newtTextbox( 2, 8, 60, 1, 0 ); newtFormAddComponents( m_oForm, m_t1, m_t2, m_t3, m_t4, m_t5, m_t6, m_t7, m_t8, NULL ); #else //create( 41, 18, 80, 17 ); create( 1, 18, 80, 17 ); #endif }; motorWindow::~motorWindow(){ newtPopWindow(); }; void motorWindow::paint( void ){ char tBuffer[245]; volatile structTUPUS *tTUPUS; tTUPUS = m_pSOC->getTUPUS( 0 , 1 ); #ifdef NEWT_CLI newtCenteredWindow( m_w, m_h, "Motor Info" ); if( tTUPUS != NULL ) { tTUPUS->HOST_status = 0; int cnt = 100; while( cnt-- && !tTUPUS->HOST_status) usleep( 20 ); cur_P2P_HM = tTUPUS->HOST_data; if( cur_P2P_HM < min_P2P_HM ) min_P2P_HM = cur_P2P_HM; if( cur_P2P_HM > max_P2P_HM ) max_P2P_HM = cur_P2P_HM; cur_P2P_VM = tTUPUS->PRU_data; if( cur_P2P_VM < min_P2P_VM ) min_P2P_VM = cur_P2P_VM; if( cur_P2P_VM > max_P2P_VM ) max_P2P_VM = cur_P2P_VM; sprintf( tBuffer, "Signature:\t0x%08x", tTUPUS->PRU_id ); newtTextboxSetText( m_t1, tBuffer ); sprintf( tBuffer, "Host status:\t0x%08x", tTUPUS->HOST_status ); newtTextboxSetText( m_t2, tBuffer ); sprintf( tBuffer, "Host cmd:\t0x%08x", tTUPUS->HOST_command ); newtTextboxSetText( m_t3, tBuffer ); sprintf( tBuffer, "Motor Status: %s", (( tTUPUS->PRU_status & 0xFF000000)?"Synced":"Not Synced")); newtTextboxSetText( m_t4, tBuffer ); sprintf( tBuffer, "Vertical Pulses per Rotation:\t%08d", tTUPUS->PRU_address ); newtTextboxSetText( m_t5, tBuffer ); sprintf( tBuffer, "Horizontal Pulses per Rotation:\t%08d", tTUPUS->HOST_address ); newtTextboxSetText( m_t6, tBuffer ); sprintf( tBuffer, "Horizontal Freq:\t%.2f kHz. Max: %.2f Min: %.2f", 1000000.0/( cur_P2P_HM * 5.0 ), 1000000.0/( min_P2P_HM * 5.0 ), 1000000.0/( max_P2P_HM * 5.0 ) ); newtTextboxSetText( m_t7, tBuffer ); sprintf( tBuffer, "Vertical Freq:\t%.2f kHz. Max: %.2f Min: %.2f", 1000000.0/( cur_P2P_VM * 5.0 ), 1000000.0/( min_P2P_VM * 5.0 ), 1000000.0/( max_P2P_VM * 5.0 ) ); newtTextboxSetText( m_t8, tBuffer ); } else { sprintf( tBuffer, "Not Initialized"); newtTextboxSetText( m_t1, tBuffer ); }; newtDrawForm( m_oForm ); newtRefresh(); #else createBox( true ); uint32_t KAKA = findInterleave(); mvwprintw( m_pWND, 2,2,"--- MOTOR STATUS ---" ); if( tTUPUS != NULL ) { cur_P2P_HM = tTUPUS->HOST_data; if( cur_P2P_HM < min_P2P_HM ) min_P2P_HM = cur_P2P_HM; if( cur_P2P_HM > max_P2P_HM ) max_P2P_HM = cur_P2P_HM; cur_P2P_VM = tTUPUS->PRU_data; if( cur_P2P_VM < min_P2P_VM ) min_P2P_VM = cur_P2P_VM; if( cur_P2P_VM > max_P2P_VM ) max_P2P_VM = cur_P2P_VM; mvwprintw( m_pWND, 3,2,"Signature:\t0x%08x", tTUPUS->PRU_id ); mvwprintw( m_pWND, 4,2,"Host status:\t0x%08x Interleave:%d", tTUPUS->HOST_status, KAKA ); mvwprintw( m_pWND, 5,2,"Host cmd:\t0x%08x", tTUPUS->HOST_command ); mvwprintw( m_pWND, 6,2,"Motor Status: %s", (( tTUPUS->PRU_status & 0xFF000000)?"Synced":"Not Synced")); mvwprintw( m_pWND, 7,2,"Vertical Pulses per Rotation:\t%08d", tTUPUS->PRU_address ); mvwprintw( m_pWND, 8,2,"Horizontal Pulses per Rotation:\t%08d", tTUPUS->HOST_address ); mvwprintw( m_pWND, 9,2,"Horizontal Freq:\t%.2f kHz. Max: %.2f Min: %.2f", 1000000.0/( cur_P2P_HM * 5.0 ), 1000000.0/( min_P2P_HM * 5.0 ), 1000000.0/( max_P2P_HM * 5.0 ) ); mvwprintw( m_pWND, 10,2,"Vertical Freq:\t%.2f kHz. Max: %.2f Min: %.2f", 1000000.0/( cur_P2P_VM * 5.0 ), 1000000.0/( min_P2P_VM * 5.0 ), 1000000.0/( max_P2P_VM * 5.0 ) ); mvwprintw( m_pWND, 12,2,"Stat File:\tNot Started Yet" ); mvwprintw( m_pWND, 13,2,"Harvesting Stat:\tNot Started Yet" ); mvwprintw( m_pWND, 14,2,"Harvesting Status:\t\t\t." ); tTUPUS->HOST_status = 0; } else { mvwprintw( m_pWND, 3,2,"Not Initialized"); }; wrefresh( m_pWND ); #endif }; void motorWindow::resetStat( void ){ cur_P2P_HM = 0; min_P2P_HM = 0x7FFFFFFF; max_P2P_HM = 0; cur_P2P_VM = 0; min_P2P_VM = 0x7FFFFFFF; max_P2P_VM = 0; }; void motorWindow::saveStatToFile( char *FileName ){ FILE *fd; int baseCounter = 0; char Buffer[21]; volatile structTUPUS *tTUPUS; tTUPUS = m_pSOC->getTUPUS( 0 , 1 ); memset( Buffer,32,20); Buffer[20]=(char)0; if( FileName != NULL ) { #ifdef NEWT_CLI #else mvwprintw( m_pWND, 12,2,"Stat File:\t%s", FileName ); #endif fd = fopen( FileName, "w+" ); if(fd!=NULL){ #ifdef NEWT_CLI #else mvwprintw( m_pWND, 14,2,"Harvesting Status:\tStarted." ); wrefresh( m_pWND ); #endif //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"); 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"); while( baseCounter< 20 ) { tTUPUS->HOST_status = 0; while( tTUPUS->HOST_status == 0 ) usleep(10); fprintf( fd,"%d,%d,%d,%d,%s\r\n", baseCounter, tTUPUS->PRU_data, //tTUPUS->HOST_data, tTUPUS->PRU_address, //tTUPUS->HOST_address, tTUPUS->HOST_command, ((tTUPUS->PRU_status & 0xFF000000 )?"YES":"NO") ); if( tTUPUS->PRU_status & 0xFF0000 ){// Base Rotation Complete Buffer[baseCounter]='*'; baseCounter++; //? #ifdef NEWT_CLI #else mvwprintw( m_pWND, 13,2,"Harvesting Stat:\t[%s]", Buffer ); wrefresh( m_pWND ); #endif tTUPUS->PRU_status &=0xFF00FFFF; }; }; #ifdef NEWT_CLI #else mvwprintw( m_pWND, 14,2,"Harvesting Status:\t\tDone." ); wrefresh( m_pWND ); #endif fclose(fd); chmod( FileName, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH ); }; }; };