| 1 |
/* |
| 2 |
* BresserExosIIGoToDriver.cpp |
| 3 |
* |
| 4 |
* Copyright 2020 Kevin Krüger <[email protected]> |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 |
* MA 02110-1301, USA. |
| 20 |
* |
| 21 |
* |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "BresserExosIIGoToDriver.hpp" |
| 25 |
|
| 26 |
#define COMMANDS_PER_SECOND (10) |
| 27 |
|
| 28 |
#define GUIDE_PULSE_TIMEOUT (6) |
| 29 |
|
| 30 |
#define GUIDE_TIMEOUT (20) |
| 31 |
|
| 32 |
//if the mount is not in a specific state after that time its, considered fault. |
| 33 |
#define DRIVER_WATCHDOG_TIMEOUT (10000) |
| 34 |
|
| 35 |
using namespace GoToDriver; |
| 36 |
using namespace SerialDeviceControl; |
| 37 |
|
| 38 |
static std::unique_ptr<BresserExosIIDriver> mount(new BresserExosIIDriver()); |
| 39 |
|
| 40 |
//default constructor. |
| 41 |
//sets the scope abilities, and default settings. |
| 42 |
BresserExosIIDriver::BresserExosIIDriver() : |
| 43 |
mInterfaceWrapper(), |
| 44 |
mMountControl(mInterfaceWrapper) |
| 45 |
{ |
| 46 |
setVersion(BresserExosIIGoToDriverForIndi_VERSION_MAJOR, BresserExosIIGoToDriverForIndi_VERSION_MINOR); |
| 47 |
|
| 48 |
DBG_SCOPE = INDI::Logger::getInstance().addDebugLevel("Scope Verbose", "SCOPE"); |
| 49 |
|
| 50 |
SetTelescopeCapability(TELESCOPE_CAN_PARK | TELESCOPE_CAN_GOTO | TELESCOPE_CAN_SYNC | TELESCOPE_CAN_ABORT | |
| 51 |
TELESCOPE_HAS_TIME | TELESCOPE_HAS_LOCATION, 0); |
| 52 |
|
| 53 |
mGuideStateNS.direction = SerialDeviceControl::SerialCommandID::NULL_COMMAND_ID; |
| 54 |
mGuideStateNS.remaining_messages = 0; |
| 55 |
|
| 56 |
mGuideStateEW.direction = SerialDeviceControl::SerialCommandID::NULL_COMMAND_ID; |
| 57 |
mGuideStateEW.remaining_messages = 0; |
| 58 |
|
| 59 |
setDefaultPollingPeriod(500); |
| 60 |
} |
| 61 |
|
| 62 |
//destructor, not much going on here. Since most of the memory is statically allocated, there is not much to clean up. |
| 63 |
BresserExosIIDriver::~BresserExosIIDriver() |
| 64 |
{ |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
//initialize the properties of the scope. |
| 69 |
bool BresserExosIIDriver::initProperties() |
| 70 |
{ |
| 71 |
INDI::Telescope::initProperties(); |
| 72 |
|
| 73 |
initGuiderProperties(getDeviceName(), MOTION_TAB); |
| 74 |
|
| 75 |
setTelescopeConnection(CONNECTION_SERIAL); |
| 76 |
|
| 77 |
addDebugControl(); |
| 78 |
|
| 79 |
IUFillText(&SourceCodeRepositoryURLT[0], "REPOSITORY_URL", "Code Repository", "https://github.com/kneo/indi-bresserexos2"); |
| 80 |
|
| 81 |
IUFillTextVector(&SourceCodeRepositoryURLTP, SourceCodeRepositoryURLT, 1, getDeviceName(), "REPOSITORY_URL", "Source Code", |
| 82 |
CONNECTION_TAB, IP_RO, 0, IPS_IDLE); |
| 83 |
|
| 84 |
defineProperty(&SourceCodeRepositoryURLTP); |
| 85 |
|
| 86 |
SetParkDataType(PARK_NONE); |
| 87 |
|
| 88 |
TrackState = SCOPE_IDLE; |
| 89 |
|
| 90 |
defineProperty(&GuideNSNP); |
| 91 |
defineProperty(&GuideWENP); |
| 92 |
|
| 93 |
addAuxControls(); |
| 94 |
|
| 95 |
setDriverInterface(getDriverInterface() | GUIDER_INTERFACE); |
| 96 |
|
| 97 |
return true; |
| 98 |
} |
| 99 |
|
| 100 |
//update the properties of the scope visible in the EKOS dialogs for instance. |
| 101 |
bool BresserExosIIDriver::updateProperties() |
| 102 |
{ |
| 103 |
bool rc = INDI::Telescope::updateProperties(); |
| 104 |
|
| 105 |
return rc; |
| 106 |
} |
| 107 |
|
| 108 |
//Connect to the scope, and ready everything for serial data exchange. |
| 109 |
bool BresserExosIIDriver::Connect() |
| 110 |
{ |
| 111 |
bool rc = INDI::Telescope::Connect(); |
| 112 |
|
| 113 |
LOGF_INFO("BresserExosIIDriver::Connect: Initializing ExosII GoTo on FD %d...", PortFD); |
| 114 |
|
| 115 |
//this message reports back the site location, also starts position reports, without changing anything on the scope. |
| 116 |
mMountControl.RequestSiteLocation(); |
| 117 |
|
| 118 |
IEAddTimer(DRIVER_WATCHDOG_TIMEOUT, DriverWatchDog, this); |
| 119 |
|
| 120 |
return rc; |
| 121 |
} |
| 122 |
|
| 123 |
//Start the serial receiver thread, so the mount can report its pointing coordinates. |
| 124 |
bool BresserExosIIDriver::Handshake() |
| 125 |
{ |
| 126 |
LOGF_INFO("BresserExosIIDriver::Handshake: Starting Receiver Thread on FD %d...", PortFD); |
| 127 |
|
| 128 |
mInterfaceWrapper.SetFD(PortFD); |
| 129 |
|
| 130 |
mMountControl.Start(); |
| 131 |
|
| 132 |
bool rc = INDI::Telescope::Handshake(); |
| 133 |
|
| 134 |
return rc; |
| 135 |
} |
| 136 |
|
| 137 |
//Disconnect from the mount, and disable serial transmission. |
| 138 |
bool BresserExosIIDriver::Disconnect() |
| 139 |
{ |
| 140 |
mMountControl.Stop(); |
| 141 |
|
| 142 |
LOG_INFO("BresserExosIIDriver::Disconnect: disabling pointing reporting, disconnected from scope. Bye!"); |
| 143 |
|
| 144 |
bool rc = INDI::Telescope::Disconnect(); |
| 145 |
|
| 146 |
return rc; |
| 147 |
} |
| 148 |
|
| 149 |
//Return the name of the device, displayed in the e.g. EKOS dialogs |
| 150 |
const char* BresserExosIIDriver::getDefaultName() |
| 151 |
{ |
| 152 |
return "BRESSER Messier EXOS-2 EQ GoTo"; |
| 153 |
} |
| 154 |
|
| 155 |
//Periodically polled function to update the state of the driver, and synchronize it with the mount. |
| 156 |
bool BresserExosIIDriver::ReadScopeStatus() |
| 157 |
{ |
| 158 |
SerialDeviceControl::EquatorialCoordinates currentCoordinates = mMountControl.GetPointingCoordinates(); |
| 159 |
NewRaDec(currentCoordinates.RightAscension, currentCoordinates.Declination); |
| 160 |
|
| 161 |
TelescopeMountControl::TelescopeMountState currentState = mMountControl.GetTelescopeState(); |
| 162 |
|
| 163 |
//Translate the mount state to driver state. |
| 164 |
switch(currentState) |
| 165 |
{ |
| 166 |
case TelescopeMountControl::TelescopeMountState::Disconnected: |
| 167 |
TrackState = SCOPE_IDLE; |
| 168 |
break; |
| 169 |
|
| 170 |
case TelescopeMountControl::TelescopeMountState::Unknown: |
| 171 |
TrackState = SCOPE_IDLE; |
| 172 |
break; |
| 173 |
|
| 174 |
case TelescopeMountControl::TelescopeMountState::ParkingIssued: |
| 175 |
TrackState = SCOPE_PARKING; |
| 176 |
break; |
| 177 |
|
| 178 |
case TelescopeMountControl::TelescopeMountState::Parked: |
| 179 |
TrackState = SCOPE_PARKED; |
| 180 |
break; |
| 181 |
|
| 182 |
case TelescopeMountControl::TelescopeMountState::Idle: |
| 183 |
TrackState = SCOPE_IDLE; |
| 184 |
break; |
| 185 |
|
| 186 |
case TelescopeMountControl::TelescopeMountState::Slewing: |
| 187 |
TrackState = SCOPE_SLEWING; |
| 188 |
break; |
| 189 |
|
| 190 |
case TelescopeMountControl::TelescopeMountState::Tracking: |
| 191 |
TrackState = SCOPE_TRACKING; |
| 192 |
break; |
| 193 |
|
| 194 |
case TelescopeMountControl::TelescopeMountState::MoveWhileTracking: |
| 195 |
TrackState = SCOPE_TRACKING; |
| 196 |
break; |
| 197 |
|
| 198 |
default: |
| 199 |
|
| 200 |
break; |
| 201 |
} |
| 202 |
|
| 203 |
return true; |
| 204 |
} |
| 205 |
|
| 206 |
bool BresserExosIIDriver::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) |
| 207 |
{ |
| 208 |
if (!strcmp(dev, getDeviceName())) |
| 209 |
{ |
| 210 |
if (!strcmp(name, GuideNSNP.name) || !strcmp(name, GuideWENP.name)) |
| 211 |
{ |
| 212 |
processGuiderProperties(name, values, names, n); |
| 213 |
return true; |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
return INDI::Telescope::ISNewNumber(dev, name, values, names, n); |
| 218 |
} |
| 219 |
|
| 220 |
bool BresserExosIIDriver::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) |
| 221 |
{ |
| 222 |
return INDI::Telescope::ISNewText(dev, name, texts, names, n); |
| 223 |
} |
| 224 |
|
| 225 |
//Park the telescope. This will slew the telescope to the parking position == home position. |
| 226 |
bool BresserExosIIDriver::Park() |
| 227 |
{ |
| 228 |
mMountControl.ParkPosition(); |
| 229 |
SetParked(true); |
| 230 |
|
| 231 |
return true; |
| 232 |
} |
| 233 |
|
| 234 |
//Set the state of the driver to unpark allowing the scope to be manipulated again. |
| 235 |
bool BresserExosIIDriver::UnPark() |
| 236 |
{ |
| 237 |
SetParked(false); |
| 238 |
|
| 239 |
return true; |
| 240 |
} |
| 241 |
|
| 242 |
//Sync the astro software and mount coordinates. |
| 243 |
bool BresserExosIIDriver::Sync(double ra, double dec) |
| 244 |
{ |
| 245 |
if(TrackState != SCOPE_TRACKING) |
| 246 |
{ |
| 247 |
LOG_INFO("BresserExosIIDriver::Sync: Unable to Synchronize! This function only works when tracking a sky object!"); |
| 248 |
return false; |
| 249 |
} |
| 250 |
|
| 251 |
LOGF_INFO("BresserExosIIDriver::Sync: Synchronizing to Right Ascension: %f Declination :%f...", ra, dec); |
| 252 |
|
| 253 |
return mMountControl.Sync((float)ra, (float)dec); |
| 254 |
} |
| 255 |
|
| 256 |
//Go to the coordinates in the sky, This automatically tracks the selected coordinates. |
| 257 |
bool BresserExosIIDriver::Goto(double ra, double dec) |
| 258 |
{ |
| 259 |
LOGF_INFO("BresserExosIIDriver::Goto: Going to Right Ascension: %f Declination :%f...", ra, dec); |
| 260 |
|
| 261 |
return mMountControl.GoTo((float)ra, (float)dec); |
| 262 |
} |
| 263 |
|
| 264 |
//Abort any motion of the telescope. This is state indipendent, and always possible when connected. |
| 265 |
bool BresserExosIIDriver::Abort() |
| 266 |
{ |
| 267 |
LOG_INFO("BresserExosIIDriver::Abort: motion stopped!"); |
| 268 |
|
| 269 |
if (GuideNSTID) |
| 270 |
{ |
| 271 |
IERmTimer(GuideNSTID); |
| 272 |
GuideNSTID = 0; |
| 273 |
} |
| 274 |
|
| 275 |
if (GuideWETID) |
| 276 |
{ |
| 277 |
IERmTimer(GuideWETID); |
| 278 |
GuideNSTID = 0; |
| 279 |
} |
| 280 |
|
| 281 |
IDSetNumber(&GuideNSNP, nullptr); |
| 282 |
IDSetNumber(&GuideWENP, nullptr); |
| 283 |
|
| 284 |
return mMountControl.StopMotion(); |
| 285 |
} |
| 286 |
|
| 287 |
//Set the tracking state of the scope, it either goes to the current coordinates or stops the scope motion. |
| 288 |
bool BresserExosIIDriver::SetTrackingEnabled(bool enabled) |
| 289 |
{ |
| 290 |
if(enabled) |
| 291 |
{ |
| 292 |
SerialDeviceControl::EquatorialCoordinates currentCoordinates = mMountControl.GetPointingCoordinates(); |
| 293 |
|
| 294 |
LOGF_INFO("BresserExosIIDriver::SetTrackingEnabled: Tracking to Right Ascension: %f Declination :%f...", |
| 295 |
currentCoordinates.RightAscension, currentCoordinates.Declination); |
| 296 |
|
| 297 |
return mMountControl.GoTo(currentCoordinates.RightAscension, currentCoordinates.Declination); |
| 298 |
} |
| 299 |
else |
| 300 |
{ |
| 301 |
return mMountControl.StopMotion(); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
//update the time of the scope. |
| 306 |
bool BresserExosIIDriver::updateTime(ln_date *utc, double utc_offset) |
| 307 |
{ |
| 308 |
// Bresser takes local time and DST but ln_zonedate doesn't have DST |
| 309 |
struct ln_zonedate local_date; |
| 310 |
ln_date_to_zonedate(utc, &local_date, static_cast<int>(utc_offset * 3600)); |
| 311 |
|
| 312 |
uint16_t years = (uint16_t)local_date.years; |
| 313 |
uint8_t months = (uint8_t)local_date.months; |
| 314 |
uint8_t days = (uint8_t)local_date.days; |
| 315 |
|
| 316 |
uint8_t hours = (uint8_t) local_date.hours; |
| 317 |
uint8_t minutes = (uint8_t) local_date.minutes; |
| 318 |
uint8_t seconds = (uint8_t) local_date.seconds; |
| 319 |
int8_t utc_off = (int8_t) utc_offset; |
| 320 |
|
| 321 |
LOGF_INFO("Date/Time updated (UTC Time): %d:%d:%d %d-%d-%d (%d)", utc->hours, utc->minutes, utc->seconds, utc->years, |
| 322 |
utc->months, utc->days, utc_off); |
| 323 |
LOGF_INFO("Date/Time updated (Local Time): %d:%d:%d %d-%d-%d (%d)", hours, minutes, seconds, years, months, days, utc_off); |
| 324 |
|
| 325 |
return mMountControl.SetDateTime(years, months, days, hours, minutes, seconds, utc_off); |
| 326 |
} |
| 327 |
|
| 328 |
//update the location of the scope. |
| 329 |
bool BresserExosIIDriver::updateLocation(double latitude, double longitude, double elevation) |
| 330 |
{ |
| 331 |
INDI_UNUSED(elevation); |
| 332 |
|
| 333 |
//orientation of the handbox is: |
| 334 |
//negative longitude is west of greenich |
| 335 |
//positive longitude is east of greenich |
| 336 |
//kstars sends 360 complements for negatives |
| 337 |
//this sole case needs to be corrected: |
| 338 |
double realLongitude = longitude; |
| 339 |
|
| 340 |
if(realLongitude > 180) |
| 341 |
{ |
| 342 |
realLongitude -= 360; |
| 343 |
} |
| 344 |
|
| 345 |
LOGF_INFO("Location updated: Longitude (%g) Latitude (%g)", realLongitude, latitude); |
| 346 |
|
| 347 |
return mMountControl.SetSiteLocation((float)latitude, (float) realLongitude); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
bool BresserExosIIDriver::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) |
| 352 |
{ |
| 353 |
if (TrackState != SCOPE_TRACKING) |
| 354 |
{ |
| 355 |
LOG_ERROR("this command only works while tracking."); |
| 356 |
return false; |
| 357 |
} |
| 358 |
|
| 359 |
SerialDeviceControl::SerialCommandID direction; |
| 360 |
|
| 361 |
switch(dir) |
| 362 |
{ |
| 363 |
case DIRECTION_NORTH: |
| 364 |
direction = SerialDeviceControl::SerialCommandID::MOVE_NORTH_COMMAND_ID; |
| 365 |
break; |
| 366 |
|
| 367 |
case DIRECTION_SOUTH: |
| 368 |
direction = SerialDeviceControl::SerialCommandID::MOVE_SOUTH_COMMAND_ID; |
| 369 |
break; |
| 370 |
|
| 371 |
default: |
| 372 |
LOG_ERROR("invalid direction value!"); |
| 373 |
return false; |
| 374 |
} |
| 375 |
|
| 376 |
switch(command) |
| 377 |
{ |
| 378 |
case MOTION_START: |
| 379 |
mMountControl.StartMotionToDirection(direction, COMMANDS_PER_SECOND); |
| 380 |
return true; |
| 381 |
|
| 382 |
case MOTION_STOP: |
| 383 |
mMountControl.StopMotionToDirection(); |
| 384 |
return true; |
| 385 |
|
| 386 |
default: |
| 387 |
|
| 388 |
break; |
| 389 |
} |
| 390 |
|
| 391 |
return false; |
| 392 |
} |
| 393 |
|
| 394 |
bool BresserExosIIDriver::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) |
| 395 |
{ |
| 396 |
if (TrackState != SCOPE_TRACKING) |
| 397 |
{ |
| 398 |
LOG_ERROR("this command only works while tracking."); |
| 399 |
return false; |
| 400 |
} |
| 401 |
|
| 402 |
SerialDeviceControl::SerialCommandID direction; |
| 403 |
|
| 404 |
switch(dir) |
| 405 |
{ |
| 406 |
case DIRECTION_EAST: |
| 407 |
direction = SerialDeviceControl::SerialCommandID::MOVE_EAST_COMMAND_ID; |
| 408 |
break; |
| 409 |
|
| 410 |
case DIRECTION_WEST: |
| 411 |
direction = SerialDeviceControl::SerialCommandID::MOVE_WEST_COMMAND_ID; |
| 412 |
break; |
| 413 |
|
| 414 |
default: |
| 415 |
LOG_ERROR("invalid direction value!"); |
| 416 |
return false; |
| 417 |
} |
| 418 |
|
| 419 |
switch(command) |
| 420 |
{ |
| 421 |
case MOTION_START: |
| 422 |
mMountControl.StartMotionToDirection(direction, COMMANDS_PER_SECOND); |
| 423 |
return true; |
| 424 |
|
| 425 |
case MOTION_STOP: |
| 426 |
mMountControl.StopMotionToDirection(); |
| 427 |
return true; |
| 428 |
|
| 429 |
default: |
| 430 |
|
| 431 |
break; |
| 432 |
} |
| 433 |
|
| 434 |
return false; |
| 435 |
} |
| 436 |
|
| 437 |
//amount of degree change per "pulse command" -> tracking speeds can be set in the HBX, |
| 438 |
//it states 1x -> 0.125 * star speed (0.0041°/s ^= 15"/s) and goes up to 8x -> 1.00 * star speed, which would advance by on second, thus guiding speeds are user dependent. |
| 439 |
//amount of time necessary to transmit a message -> 12.1 ms |
| 440 |
//(9600 baud / 8 -> 1200, but deminished by the stop bit yielding a net data rate of around 1067 byte/s) |
| 441 |
//allows around 82 messages send to the mount per second. |
| 442 |
//Assume half if serial transmission is not full duplex capable. |
| 443 |
//roughtly tranlsates to 42*0.125*0.004 -> 0.0205 degrees per second at minimum setting |
| 444 |
//42*0.004 -> 0.164 degrees per second at maximum setting. |
| 445 |
//double these amounts if full duplex is possible. |
| 446 |
IPState BresserExosIIDriver::GuideNorth(uint32_t ms) |
| 447 |
{ |
| 448 |
//LOGF_INFO("BresserExosIIDriver::GuideNorth: guiding %d ms", ms); |
| 449 |
|
| 450 |
if(mMountControl.GetTelescopeState() == TelescopeMountControl::TelescopeMountState::MoveWhileTracking) |
| 451 |
{ |
| 452 |
LOG_INFO("BresserExosIIDriver::GuideNorth: motion while tracking stopped!"); |
| 453 |
mMountControl.StopMotionToDirection(); |
| 454 |
} |
| 455 |
|
| 456 |
uint32_t messages = ms / GUIDE_TIMEOUT; |
| 457 |
|
| 458 |
LOGF_INFO("BresserExosIIDriver::GuideNord: guiding %d ms (%d messages)", ms, messages); |
| 459 |
|
| 460 |
if (GuideNSTID) //reset timer if any. |
| 461 |
{ |
| 462 |
IERmTimer(GuideNSTID); |
| 463 |
GuideNSTID = 0; |
| 464 |
} |
| 465 |
|
| 466 |
if(messages > 0) |
| 467 |
{ |
| 468 |
mMountControl.GuideNorth(); // send one pulse |
| 469 |
messages--; |
| 470 |
|
| 471 |
mGuideStateNS.remaining_messages = messages; |
| 472 |
mGuideStateNS.direction = SerialDeviceControl::SerialCommandID::MOVE_NORTH_COMMAND_ID; |
| 473 |
|
| 474 |
GuideNSTID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperN, this); //wait for nex pulse if any. |
| 475 |
|
| 476 |
return IPS_BUSY; |
| 477 |
} |
| 478 |
|
| 479 |
return IPS_IDLE; |
| 480 |
} |
| 481 |
|
| 482 |
IPState BresserExosIIDriver::GuideSouth(uint32_t ms) |
| 483 |
{ |
| 484 |
//LOGF_INFO("BresserExosIIDriver::GuideSouth: guiding %d ms", ms); |
| 485 |
|
| 486 |
if(mMountControl.GetTelescopeState() == TelescopeMountControl::TelescopeMountState::MoveWhileTracking) |
| 487 |
{ |
| 488 |
LOG_INFO("BresserExosIIDriver::GuideNorth: motion while tracking stopped!"); |
| 489 |
mMountControl.StopMotionToDirection(); |
| 490 |
} |
| 491 |
|
| 492 |
uint32_t messages = ms / GUIDE_TIMEOUT; |
| 493 |
|
| 494 |
LOGF_INFO("BresserExosIIDriver::GuideSouth: guiding %d ms (%d messages)", ms, messages); |
| 495 |
|
| 496 |
if (GuideNSTID) //reset timer if any. |
| 497 |
{ |
| 498 |
IERmTimer(GuideNSTID); |
| 499 |
GuideNSTID = 0; |
| 500 |
} |
| 501 |
|
| 502 |
if(messages > 0) |
| 503 |
{ |
| 504 |
mMountControl.GuideSouth(); // send one pulse |
| 505 |
messages--; |
| 506 |
|
| 507 |
mGuideStateNS.remaining_messages = messages; |
| 508 |
mGuideStateNS.direction = SerialDeviceControl::SerialCommandID::MOVE_SOUTH_COMMAND_ID; |
| 509 |
|
| 510 |
GuideNSTID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperS, this); //wait for nex pulse if any. |
| 511 |
|
| 512 |
return IPS_BUSY; |
| 513 |
} |
| 514 |
|
| 515 |
return IPS_IDLE; |
| 516 |
} |
| 517 |
|
| 518 |
IPState BresserExosIIDriver::GuideEast(uint32_t ms) |
| 519 |
{ |
| 520 |
//LOGF_INFO("BresserExosIIDriver::GuideEast: guiding %d ms", ms); |
| 521 |
|
| 522 |
if(mMountControl.GetTelescopeState() == TelescopeMountControl::TelescopeMountState::MoveWhileTracking) |
| 523 |
{ |
| 524 |
LOG_INFO("BresserExosIIDriver::GuideNorth: motion while tracking stopped!"); |
| 525 |
mMountControl.StopMotionToDirection(); |
| 526 |
} |
| 527 |
|
| 528 |
uint32_t messages = ms / GUIDE_TIMEOUT; |
| 529 |
|
| 530 |
LOGF_INFO("BresserExosIIDriver::GuideEast: guiding %d ms (%d messages)", ms, messages); |
| 531 |
|
| 532 |
if (GuideWETID) //reset timer if any. |
| 533 |
{ |
| 534 |
IERmTimer(GuideWETID); |
| 535 |
GuideWETID = 0; |
| 536 |
} |
| 537 |
|
| 538 |
if(messages > 0) |
| 539 |
{ |
| 540 |
mMountControl.GuideEast(); // send one pulse |
| 541 |
|
| 542 |
messages--; |
| 543 |
|
| 544 |
mGuideStateEW.direction = SerialDeviceControl::SerialCommandID::MOVE_EAST_COMMAND_ID; |
| 545 |
mGuideStateEW.remaining_messages = messages; |
| 546 |
|
| 547 |
GuideWETID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperE, this); //wait for nex pulse if any. |
| 548 |
|
| 549 |
return IPS_BUSY; |
| 550 |
} |
| 551 |
|
| 552 |
return IPS_IDLE; |
| 553 |
} |
| 554 |
|
| 555 |
IPState BresserExosIIDriver::GuideWest(uint32_t ms) |
| 556 |
{ |
| 557 |
//LOGF_INFO("BresserExosIIDriver::GuideWest: guiding %d ms", ms); |
| 558 |
|
| 559 |
if(mMountControl.GetTelescopeState() == TelescopeMountControl::TelescopeMountState::MoveWhileTracking) |
| 560 |
{ |
| 561 |
LOG_INFO("BresserExosIIDriver::GuideNorth: motion while tracking stopped!"); |
| 562 |
mMountControl.StopMotionToDirection(); |
| 563 |
} |
| 564 |
|
| 565 |
uint32_t messages = ms / GUIDE_TIMEOUT; |
| 566 |
|
| 567 |
LOGF_INFO("BresserExosIIDriver::GuideWest: guiding %d ms (%d messages)", ms, messages); |
| 568 |
|
| 569 |
if (GuideWETID) //reset timer if any. |
| 570 |
{ |
| 571 |
IERmTimer(GuideWETID); |
| 572 |
GuideWETID = 0; |
| 573 |
} |
| 574 |
|
| 575 |
if(messages > 0) |
| 576 |
{ |
| 577 |
mMountControl.GuideWest(); |
| 578 |
|
| 579 |
messages--; |
| 580 |
mGuideStateEW.remaining_messages = messages; |
| 581 |
mGuideStateEW.direction = SerialDeviceControl::SerialCommandID::MOVE_WEST_COMMAND_ID; |
| 582 |
|
| 583 |
GuideWETID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperW, this); //wait for nex pulse if any. |
| 584 |
|
| 585 |
return IPS_BUSY; |
| 586 |
} |
| 587 |
|
| 588 |
return IPS_IDLE; |
| 589 |
} |
| 590 |
|
| 591 |
void BresserExosIIDriver::DriverWatchDog(void *p) |
| 592 |
{ |
| 593 |
BresserExosIIDriver* driverInstance = static_cast<BresserExosIIDriver*>(p); |
| 594 |
|
| 595 |
if(driverInstance == nullptr) |
| 596 |
{ |
| 597 |
return; |
| 598 |
} |
| 599 |
|
| 600 |
TelescopeMountControl::TelescopeMountState currentState = driverInstance->mMountControl.GetTelescopeState(); |
| 601 |
|
| 602 |
if(currentState == TelescopeMountControl::TelescopeMountState::Unknown) |
| 603 |
{ |
| 604 |
driverInstance->LogError("Watchdog Timeout without communication!"); |
| 605 |
driverInstance->LogError("Please make sure your serial device is correct, and communication is possible."); |
| 606 |
return; |
| 607 |
} |
| 608 |
driverInstance->LogInfo("INFO: Communication seems to be established!"); |
| 609 |
} |
| 610 |
|
| 611 |
void BresserExosIIDriver::guideTimeout(SerialDeviceControl::SerialCommandID direction) |
| 612 |
{ |
| 613 |
bool continuePulsing = false; |
| 614 |
switch(direction) |
| 615 |
{ |
| 616 |
case SerialDeviceControl::SerialCommandID::MOVE_NORTH_COMMAND_ID: |
| 617 |
continuePulsing = mGuideStateNS.remaining_messages > 0; |
| 618 |
|
| 619 |
if(continuePulsing) |
| 620 |
{ |
| 621 |
mGuideStateNS.remaining_messages--; |
| 622 |
mMountControl.GuideNorth(); |
| 623 |
GuideNSNP.s = IPS_BUSY; |
| 624 |
GuideNSTID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperN, this); |
| 625 |
} |
| 626 |
else |
| 627 |
{ |
| 628 |
GuideNSNP.s = IPS_IDLE; |
| 629 |
GuideNSTID = 0; |
| 630 |
mGuideStateNS.remaining_messages = 0; |
| 631 |
mGuideStateNS.direction = SerialDeviceControl::SerialCommandID::NULL_COMMAND_ID; |
| 632 |
IDSetNumber(&GuideNSNP, nullptr); |
| 633 |
} |
| 634 |
break; |
| 635 |
|
| 636 |
case SerialDeviceControl::SerialCommandID::MOVE_SOUTH_COMMAND_ID: |
| 637 |
continuePulsing = mGuideStateNS.remaining_messages > 0; |
| 638 |
|
| 639 |
if(continuePulsing) |
| 640 |
{ |
| 641 |
mGuideStateNS.remaining_messages--; |
| 642 |
mMountControl.GuideSouth(); |
| 643 |
GuideNSNP.s = IPS_BUSY; |
| 644 |
GuideNSTID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperS, this); |
| 645 |
} |
| 646 |
else |
| 647 |
{ |
| 648 |
GuideNSNP.s = IPS_IDLE; |
| 649 |
GuideNSTID = 0; |
| 650 |
mGuideStateNS.remaining_messages = 0; |
| 651 |
mGuideStateNS.direction = SerialDeviceControl::SerialCommandID::NULL_COMMAND_ID; |
| 652 |
IDSetNumber(&GuideNSNP, nullptr); |
| 653 |
} |
| 654 |
break; |
| 655 |
|
| 656 |
case SerialDeviceControl::SerialCommandID::MOVE_WEST_COMMAND_ID: |
| 657 |
continuePulsing = mGuideStateEW.remaining_messages > 0; |
| 658 |
|
| 659 |
if(continuePulsing) |
| 660 |
{ |
| 661 |
mGuideStateEW.remaining_messages--; |
| 662 |
mMountControl.GuideWest(); |
| 663 |
GuideWENP.s = IPS_BUSY; |
| 664 |
GuideNSTID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperW, this); |
| 665 |
} |
| 666 |
else |
| 667 |
{ |
| 668 |
GuideWENP.s = IPS_IDLE; |
| 669 |
GuideWETID = 0; |
| 670 |
mGuideStateEW.remaining_messages = 0; |
| 671 |
mGuideStateEW.direction = SerialDeviceControl::SerialCommandID::NULL_COMMAND_ID; |
| 672 |
IDSetNumber(&GuideWENP, nullptr); |
| 673 |
} |
| 674 |
break; |
| 675 |
|
| 676 |
case SerialDeviceControl::SerialCommandID::MOVE_EAST_COMMAND_ID: |
| 677 |
continuePulsing = mGuideStateEW.remaining_messages > 0; |
| 678 |
|
| 679 |
if(continuePulsing) |
| 680 |
{ |
| 681 |
mGuideStateEW.remaining_messages--; |
| 682 |
mMountControl.GuideEast(); |
| 683 |
GuideWENP.s = IPS_BUSY; |
| 684 |
GuideNSTID = IEAddTimer(GUIDE_TIMEOUT, guideTimeoutHelperE, this); |
| 685 |
} |
| 686 |
else |
| 687 |
{ |
| 688 |
GuideWENP.s = IPS_IDLE; |
| 689 |
GuideWETID = 0; |
| 690 |
mGuideStateEW.remaining_messages = 0; |
| 691 |
mGuideStateEW.direction = SerialDeviceControl::SerialCommandID::NULL_COMMAND_ID; |
| 692 |
IDSetNumber(&GuideWENP, nullptr); |
| 693 |
} |
| 694 |
break; |
| 695 |
|
| 696 |
default: |
| 697 |
GuideWENP.s = IPS_IDLE; |
| 698 |
GuideWETID = 0; |
| 699 |
IDSetNumber(&GuideWENP, nullptr); |
| 700 |
|
| 701 |
GuideNSNP.s = IPS_IDLE; |
| 702 |
GuideNSTID = 0; |
| 703 |
IDSetNumber(&GuideNSNP, nullptr); |
| 704 |
break; |
| 705 |
} |
| 706 |
} |
| 707 |
|
| 708 |
//GUIDE The timer helper functions. |
| 709 |
void BresserExosIIDriver::guideTimeoutHelperN(void *p) |
| 710 |
{ |
| 711 |
static_cast<BresserExosIIDriver*>(p)->guideTimeout(SerialDeviceControl::SerialCommandID::MOVE_NORTH_COMMAND_ID); |
| 712 |
} |
| 713 |
|
| 714 |
void BresserExosIIDriver::guideTimeoutHelperS(void *p) |
| 715 |
{ |
| 716 |
static_cast<BresserExosIIDriver*>(p)->guideTimeout(SerialDeviceControl::SerialCommandID::MOVE_SOUTH_COMMAND_ID); |
| 717 |
} |
| 718 |
|
| 719 |
void BresserExosIIDriver::guideTimeoutHelperW(void *p) |
| 720 |
{ |
| 721 |
static_cast<BresserExosIIDriver*>(p)->guideTimeout(SerialDeviceControl::SerialCommandID::MOVE_WEST_COMMAND_ID); |
| 722 |
} |
| 723 |
|
| 724 |
void BresserExosIIDriver::guideTimeoutHelperE(void *p) |
| 725 |
{ |
| 726 |
static_cast<BresserExosIIDriver*>(p)->guideTimeout(SerialDeviceControl::SerialCommandID::MOVE_EAST_COMMAND_ID); |
| 727 |
} |
| 728 |
|
| 729 |
void BresserExosIIDriver::LogError(const char* message) |
| 730 |
{ |
| 731 |
LOG_ERROR(message); |
| 732 |
} |
| 733 |
|
| 734 |
void BresserExosIIDriver::LogInfo(const char* message) |
| 735 |
{ |
| 736 |
LOG_INFO(message); |
| 737 |
} |