//-------------------------------------------------------------------------------------------------- static void test(void* context) { // Init the test case / test suite data structures CU_TestInfo smstest[] = { { "Test le_sms_SetGetSmsCenterAddress()", Testle_sms_SetGetSmsCenterAddress }, { "Test le_sms_SetGetText()", Testle_sms_SetGetText }, { "Test le_sms_SetGetBinary()", Testle_sms_SetGetBinary }, { "Test le_sms_SetGetPDU()", Testle_sms_SetGetPDU }, { "Test le_sms_ReceivedList()", Testle_sms_ReceivedList }, { "Test le_sms_SendBinary()", Testle_sms_SendBinary }, { "Test le_sms_SendText()", Testle_sms_SendText }, #if 0 { "Test le_sms_SendPdu()", Testle_sms_SendPdu }, #endif CU_TEST_INFO_NULL, }; CU_SuiteInfo suites[] = { { "SMS tests", NULL, NULL, smstest }, CU_SUITE_INFO_NULL, }; fprintf(stderr, "Please ensure that there is enough space on SIM to receive new SMS messages!\n"); #ifndef AUTOMATIC GetTel(); #endif // Initialize the CUnit test registry and register the test suite if (CUE_SUCCESS != CU_initialize_registry()) exit(CU_get_error()); if ( CUE_SUCCESS != CU_register_suites(suites)) { CU_cleanup_registry(); exit(CU_get_error()); } CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); // Output summary of failures, if there were any if ( CU_get_number_of_failures() > 0 ) { fprintf(stdout,"\n [START]List of Failure :\n"); CU_basic_show_failures(CU_get_failure_list()); fprintf(stdout,"\n [STOP]List of Failure\n"); } }
int CheckGoTo(double desRA, double desDec, int pmodel) { double telra1, teldec1; double errorRA, errorDec, nowRA, nowDec; double tolra, toldec; /* Is the telescope slewing? */ if ( GetSlewStatus() == 1 ) { /* One or more axes remain in motion */ /* Try again later */ return(0); } /* Was this a two-phase slew? */ if ( slewphase == 2 ) { /* Reset the slew phase and continue to the destination */ slewphase = 0; /* Go to the original destination */ /* GoToCoords will change slewphase to 1 */ GoToCoords(desRA, desDec, pmodel); /* Return a flag indicating a new goto operation is in progress */ return(0); } else if ( slewphase == 1 ) { /* No axes are moving. Insure that tracking is started again. */ StartTrack(); /* Where are we now? */ GetTel(&nowRA, &nowDec, pmodel); /* Compare to destination with pre-defined tolerances */ telra1 = desRA; teldec1 = desDec; /* RA slew tolerance in hours */ tolra = SLEWTOLRA; /* Dec slew tolerance in degrees */ toldec = SLEWTOLDEC; /* What is the absolute value of the pointing error? */ /* Magnitude of RA pointing error in hours */ errorRA = fabs(nowRA - telra1); /* Magnitude of Dec pointing error in degrees */ errorDec = fabs(nowDec - teldec1); /* Compare and notify whether we are within tolerance */ if( ( errorRA > tolra ) || ( errorDec > toldec ) ) { /* Result of slew is outside acceptable tolerance */ /* Signal the calling routine that another goto may be needed */ slewphase = 0; return(2); } } else { /* Unexpected slew phase */ /* Reset and return success without a test */ /* This should clear errors and enable another slew request from the UI */ /* Better would be to flag an error but that might have unintended consequences */ slewphase = 0; } return(1); }
void ConnectTel(void) { struct termios tty; /* Packet to request version of azimuth motor driver */ char sendstr[] = { 0x50, 0x01, 0x10, 0xfe, 0x00, 0x00, 0x00, 0x02 }; /* Packet format: */ /* preamble */ /* packet length */ /* destination */ /* message id */ /* three message bytes */ /* number of response bytes */ char returnstr[32]; /* Packet format: */ /* response bytes if any */ /* # */ int numRead; int limits, flag; if(TelConnectFlag != FALSE) { return; } /* Make the connection */ /* TelPortFD = open("/dev/ttyS0",O_RDWR); */ TelPortFD = open(telserial,O_RDWR); if(TelPortFD == -1) { fprintf(stderr,"Serial port not available ... \n"); return; } tcgetattr(TelPortFD,&tty); cfsetospeed(&tty, (speed_t) B9600); cfsetispeed(&tty, (speed_t) B9600); tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; tty.c_iflag = IGNBRK; tty.c_lflag = 0; tty.c_oflag = 0; tty.c_cflag |= CLOCAL | CREAD; tty.c_cc[VMIN] = 1; tty.c_cc[VTIME] = 5; tty.c_iflag &= ~(IXON|IXOFF|IXANY); tty.c_cflag &= ~(PARENB | PARODD); tcsetattr(TelPortFD, TCSANOW, &tty); /* Flush the input (read) buffer */ tcflush(TelPortFD,TCIOFLUSH); /* Test connection by asking for version of azimuth motor */ writen(TelPortFD,sendstr,8); numRead=readn(TelPortFD,returnstr,3,2); if (numRead == 3) { fprintf(stderr,"RA/Azimuth "); fprintf(stderr,"controller version %d.%d ", returnstr[0], returnstr[1]); fprintf(stderr,"connected \n"); } else { fprintf(stderr,"RA/Azimuth drive not responding ...\n"); return; } /* Test connection by asking for version of altitude motor */ sendstr[2] = 0x11; /* Flush the input buffer */ tcflush(TelPortFD,TCIOFLUSH); /* Send the request */ writen(TelPortFD,sendstr,8); numRead=readn(TelPortFD,returnstr,3,2); /* Add null terminator to simplify handling the return data */ returnstr[numRead] = '\0'; if (numRead == 3) { fprintf(stderr,"Declination/Altitude "); fprintf(stderr,"controller version %d.%d ", returnstr[0], returnstr[1]); fprintf(stderr,"connected\n"); TelConnectFlag = TRUE; } else { fprintf(stderr,"Declination/altitude drive not responding ...\n"); return; } /* Perform startup tests */ flag = GetLimits(&limits); usleep(500000); limits = FALSE; flag = SetLimits(limits); usleep(500000); flag = GetLimits(&limits); /* Set global switch angles for a GEM OTA over the pier pointing at pole */ /* They correspond to ha ~ -6 hr and dec ~ +90 deg for northern telescope */ /* They correspond to ha ~ +6 hr and dec ~ -90 deg for southern telescope */ /* Non-zero values work better in goto routines on nexstar */ switchaz = 1.; switchalt = -1.0; /* Hardcoded defaults for homeha and homedec are overridden by prefs */ /* GEM: over the pier pointing at the pole */ /* EQFORK: pointing at the equator on the meridian */ /* ALTAZ: level and pointing north */ if ( homenow != TRUE ) { if (telmount == GEM) { if (SiteLatitude < 0.) { homedec = -89.9999; homeha = 6.; } else { homedec = 89.9999; homeha = -6.; } } else if (telmount == EQFORK) { if (SiteLatitude < 0.) { homedec = 0.; homeha = 0.; } else { homedec = 0.; homeha = 0.; } } else if (telmount == ALTAZ) { /* Set azimuth */ homeha = 0.; /* Set altitude */ homedec = 0.; } else { fprintf(stderr,"Telescope mounting must be GEM, EQFORK, or ALTAZ\n"); return; } } fprintf(stderr, "Using initial HA: %lf\n", homeha); fprintf(stderr, "Using initial Dec: %lf\n",homedec); flag = SetTelEncoders(homeha, homedec); if (flag != TRUE) { fprintf(stderr,"Initial telescope pointing request was out of range ... \n"); return; } /* Read encoders and confirm pointing */ GetTel(&homera, &homedec, RAW); fprintf(stderr, "Local latitude: %lf\n", SiteLatitude); fprintf(stderr, "Local longitude: %lf\n", SiteLongitude); fprintf(stderr, "Local sidereal time: %lf\n", LSTNow()); fprintf(stderr, "Mount type: %d\n", telmount); fprintf(stderr, "Mount now reading RA: %lf\n", homera); fprintf(stderr, "Mount now reading Dec: %lf\n", homedec); fprintf(stderr, "The telescope is running ...\n\n"); /* Flush the input buffer in case there is something left from startup */ tcflush(TelPortFD,TCIOFLUSH); }
int GoToCoords(double newra, double newdec, int pmodel) { char sendstr[] = { 0x50, 0x04, 0x10, 0x17, 0x00, 0x00, 0x00, 0x00 }; char returnstr[32]; int azcount, azcount0, azcount1, azcount2; int altcount, altcount0, altcount1, altcount2; int numread; double newha, newalt, newaz; double newha0, newalt0, newaz0; double newra0, newdec0; double newra1, newdec1; double nowha0, nowra0, nowdec0; double encoderalt = 0.; double encoderaz = 0.; /* Select fast slew command if needed */ /* Note: may place large inertial load on the gear train */ if( SLEWFAST ) { sendstr[3] = 0x02; } newha = LSTNow() - newra; newha = Map12(newha); /* Convert HA and Dec to Alt and Az */ /* Test for visibility */ EquatorialToHorizontal(newha, newdec, &newaz, &newalt); /* Check altitude limit */ if (newalt < MINTARGETALT) { fprintf(stderr,"Target is below the telescope horizon\n"); slewphase = 0; return(0); } /* Target request is valid */ /* Find the best path to target */ /* Mount coordinates for the target */ newra1 = newra; newdec1 = newdec; PointingToTel(&newra0,&newdec0,newra1,newdec1,pmodel); newha0 = LSTNow() - newra0; newha0 = Map12(newha0); EquatorialToHorizontal(newha0, newdec0, &newaz0, &newalt0); /* Stop all mount motion in preparation for a slew */ FullStop(); /* Get current mount coordinates */ GetTel(&nowra0, &nowdec0, RAW); nowha0 = LSTNow() - nowra0; nowha0 = Map12(nowha0); /* Prepare encoder counts for a new slew */ /* German equatorial */ if (telmount == GEM) { /* Flip signs for the southern sky */ if (SiteLatitude < 0.) { newdec0 = -1.*newdec0; newha0 = -1.*newha0; } if ((newha0 >= -12.) && ( newha0 < -6.)) { slewphase = 1; encoderaz = newha0*15. + 180.; encoderalt = newdec0; } else if ((newha0 >= -6.) && ( newha0 <= 0.)) { slewphase = 1; encoderaz = newha0*15. + 180.; encoderalt = newdec0; } else if ((newha0 > 0.) && ( newha0 <= 6.)) { slewphase = 1; encoderaz = newha0*15.; encoderalt = 180. - newdec0; } else if ((newha0 > 6.) && ( newha0 <= 12.)) { slewphase = 1; encoderaz = newha0*15.; encoderalt = 180. - newdec0; } else { fprintf(stderr,"German equatorial slew request error\n"); return(0); } if (newha0 == 0.) { /* OTA looking at meridian */ /* This is ambiguous unless we know which side of the pier it is on */ /* Assume telescope was on the west side looking east */ /* and was moved to point to the meridian with the OTA west of pier */ slewphase = 1; fprintf(stderr,"Warning: assuming OTA is west of pier.\n"); encoderaz = 90.; encoderalt = newdec0 - 90.; } else if (newha0 == -6.) { /* OTA looking east */ slewphase = 1; encoderaz = 0.; encoderalt = newdec0 - 90.; } else if (newha0 == 6.) { /* OTA looking west */ slewphase = 1; encoderaz = 0.; encoderalt = 90. - newdec0; } else if ((newha0 > -12.) && ( newha0 < -6.)) { /* OTA east of pier looking below the pole */ slewphase = 1; encoderaz = newha0*15. + 90.; encoderalt = newdec0 - 90.; } else if ((newha0 > -6.) && ( newha0 < 0.)) { /* OTA west of pier looking east */ slewphase = 1; encoderaz = newha0*15. + 90.; encoderalt = newdec0 - 90.; } else if ((newha0 > 0.) && ( newha0 <= 6.)) { /*OTA east of pier looking west */ slewphase = 1; encoderaz = newha0*15. - 90.; encoderalt = 90. - newdec0; } else if ((newha0 > 6.) && ( newha0 < 12.)) { /* OTA west of pier looking below the pole */ slewphase = 1; encoderaz = newha0*15. - 90.; encoderalt = 90. - newdec0; } else { fprintf(stderr,"German equatorial slew request outside limits\n"); return(0); } /* Tests for safe slew based on encoder readings would go here */ /* Test need for two-segment slew for changes of more than 90 degrees */ if ((fabs(telencoderalt - encoderalt) > 90.1) || (fabs(telencoderaz - encoderaz) > 90.1)) { /* Slew request of more than 90 degrees on one axis */ if ( fabs(telencoderalt) > 10. ) { /* Telescope currently more than 10 degrees from the pole in dec */ /* Set new target to switch position */ encoderalt = switchalt; encoderaz = switchaz; slewphase = 2; } } encoderalt = encoderalt*altcountperdeg; encoderaz = encoderaz*azcountperdeg; } /* Equatorial fork */ if (telmount == EQFORK) { slewphase = 1; encoderaz = newha0*15.; encoderalt = newdec0; /* Tests for safe slew based on encoder readings would go here */ encoderalt = encoderalt*altcountperdeg; encoderaz = encoderaz*azcountperdeg; } /* Alt-az fork */ if (telmount == ALTAZ) { slewphase = 1; encoderaz = newaz0; encoderalt = newalt0; /* Tests for safe slew based on encoder readings would go here */ encoderaz = encoderaz*azcountperdeg; encoderalt = encoderalt*altcountperdeg; } /* Convert encoder angle readings to encoder counter readings */ azcount = encoderaz; if (azcount < 0) { azcount = 16777217 + azcount; } altcount = encoderalt; if (altcount < 0) { altcount = 16777217 + altcount; } /* Prepare NexStar commands */ /* Parse each of the 3 bytes of the counters */ azcount0 = azcount / 65536; azcount = azcount % 65536; azcount1 = azcount / 256; azcount2 = azcount % 256; altcount0 = altcount / 65536; altcount = altcount % 65536; altcount1 = altcount / 256; altcount2 = altcount % 256; /* Send command to go to new RA/Azimuth */ sendstr[1] = 0x04; sendstr[2] = 0x10; sendstr[3] = 0x17; sendstr[4] = (unsigned short) azcount0; sendstr[5] = (unsigned short) azcount1; sendstr[6] = (unsigned short) azcount2; tcflush(TelPortFD,TCIOFLUSH); writen(TelPortFD,sendstr,8); numread=readn(TelPortFD,returnstr,1,2); /* Send command to go to new Dec/Altitude */ sendstr[1] = 0x04; sendstr[2] = 0x11; sendstr[3] = 0x17; sendstr[4] = (unsigned short) altcount0; sendstr[5] = (unsigned short) altcount1; sendstr[6] = (unsigned short) altcount2; tcflush(TelPortFD,TCIOFLUSH); writen(TelPortFD,sendstr,8); numread=readn(TelPortFD,returnstr,1,2); tcflush(TelPortFD,TCIOFLUSH); /* A slew is in progress */ return(1); }