forked from indigo-astronomy/indigo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
indigo_rotator_simulator: created rotator simulator
- Loading branch information
Showing
5 changed files
with
310 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Field Rotator Simulator driver | ||
|
||
## Supported devices | ||
|
||
* Fileld Rotator Simulator | ||
|
||
Single device is present on startup. | ||
|
||
## Supported platforms | ||
|
||
This driver is platform independent. | ||
|
||
## License | ||
|
||
INDIGO Astronomy open-source license. | ||
|
||
## Use | ||
|
||
indigo_server indigo_rotator_simulator | ||
|
||
or | ||
|
||
indigo_server -s | ||
|
||
## Status: Under Development |
193 changes: 193 additions & 0 deletions
193
indigo_drivers/rotator_simulator/indigo_rotator_simulator.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
// Copyright (c) 2020 Rumen G.Bogdanovski | ||
// All rights reserved. | ||
// | ||
// You can use this software under the terms of 'INDIGO Astronomy | ||
// open-source license' (see LICENSE.md). | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS 'AS IS' AND ANY EXPRESS | ||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
// version history | ||
// 2.0 by Rumen G.Bogdanovski <[email protected]> | ||
|
||
/** INDIGO Field Rotator Simulator driver | ||
\file indigo_rotator_simulator.c | ||
*/ | ||
|
||
#define DRIVER_VERSION 0x0001 | ||
#define DRIVER_NAME "indigo_rotator_simulator" | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <math.h> | ||
#include <assert.h> | ||
#include <pthread.h> | ||
|
||
#include <indigo/indigo_driver_xml.h> | ||
|
||
#include "indigo_rotator_simulator.h" | ||
|
||
#define PRIVATE_DATA ((simulator_private_data *)device->private_data) | ||
|
||
#define ROTATOR_SPEED 0.9 | ||
|
||
typedef struct { | ||
double target_position, current_position; | ||
indigo_timer *rotator_timer; | ||
} simulator_private_data; | ||
|
||
// -------------------------------------------------------------------------------- INDIGO rotator device implementation | ||
|
||
static void rotator_timer_callback(indigo_device *device) { | ||
if (ROTATOR_POSITION_PROPERTY->state == INDIGO_ALERT_STATE) { | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->target_position = PRIVATE_DATA->current_position; | ||
indigo_update_property(device, ROTATOR_POSITION_PROPERTY, NULL); | ||
} else { | ||
if (PRIVATE_DATA->current_position < PRIVATE_DATA->target_position) { | ||
ROTATOR_POSITION_PROPERTY->state = INDIGO_BUSY_STATE; | ||
if (PRIVATE_DATA->target_position - PRIVATE_DATA->current_position > ROTATOR_SPEED) | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->current_position = (PRIVATE_DATA->current_position + ROTATOR_SPEED); | ||
else | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->current_position = PRIVATE_DATA->target_position; | ||
indigo_update_property(device, ROTATOR_POSITION_PROPERTY, NULL); | ||
indigo_reschedule_timer(device, 0.2, &PRIVATE_DATA->rotator_timer); | ||
} else if (PRIVATE_DATA->current_position > PRIVATE_DATA->target_position){ | ||
ROTATOR_POSITION_PROPERTY->state = INDIGO_BUSY_STATE; | ||
if (PRIVATE_DATA->current_position - PRIVATE_DATA->target_position > ROTATOR_SPEED) | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->current_position = (PRIVATE_DATA->current_position - ROTATOR_SPEED); | ||
else | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->current_position = PRIVATE_DATA->target_position; | ||
indigo_update_property(device, ROTATOR_POSITION_PROPERTY, NULL); | ||
indigo_reschedule_timer(device, 0.2, &PRIVATE_DATA->rotator_timer); | ||
} else { | ||
ROTATOR_POSITION_PROPERTY->state = INDIGO_OK_STATE; | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->current_position; | ||
indigo_update_property(device, ROTATOR_POSITION_PROPERTY, NULL); | ||
} | ||
} | ||
} | ||
|
||
static indigo_result rotator_attach(indigo_device *device) { | ||
assert(device != NULL); | ||
assert(PRIVATE_DATA != NULL); | ||
if (indigo_rotator_attach(device, DRIVER_VERSION) == INDIGO_OK) { | ||
// -------------------------------------------------------------------------------- | ||
INDIGO_DEVICE_ATTACH_LOG(DRIVER_NAME, device->name); | ||
return indigo_rotator_enumerate_properties(device, NULL, NULL); | ||
} | ||
return INDIGO_FAILED; | ||
} | ||
|
||
static indigo_result rotator_change_property(indigo_device *device, indigo_client *client, indigo_property *property) { | ||
assert(device != NULL); | ||
assert(DEVICE_CONTEXT != NULL); | ||
assert(property != NULL); | ||
if (indigo_property_match(CONNECTION_PROPERTY, property)) { | ||
// -------------------------------------------------------------------------------- CONNECTION | ||
indigo_property_copy_values(CONNECTION_PROPERTY, property, false); | ||
CONNECTION_PROPERTY->state = INDIGO_OK_STATE; | ||
} else if (indigo_property_match(ROTATOR_POSITION_PROPERTY, property)) { | ||
// -------------------------------------------------------------------------------- ROTATOR_POSITION | ||
indigo_property_copy_values(ROTATOR_POSITION_PROPERTY, property, false); | ||
if (ROTATOR_ON_POSITION_SET_SYNC_ITEM->sw.value) { | ||
ROTATOR_POSITION_PROPERTY->state = INDIGO_OK_STATE; | ||
PRIVATE_DATA->target_position = ROTATOR_POSITION_ITEM->number.target; | ||
PRIVATE_DATA->current_position = ROTATOR_POSITION_ITEM->number.value; | ||
indigo_update_property(device, ROTATOR_POSITION_PROPERTY, NULL); | ||
} else { | ||
ROTATOR_POSITION_PROPERTY->state = INDIGO_BUSY_STATE; | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->current_position; | ||
PRIVATE_DATA->target_position = ROTATOR_POSITION_ITEM->number.target; | ||
indigo_update_property(device, ROTATOR_POSITION_PROPERTY, NULL); | ||
PRIVATE_DATA->rotator_timer = indigo_set_timer(device, 0.2, rotator_timer_callback); | ||
} | ||
return INDIGO_OK; | ||
} else if (indigo_property_match(ROTATOR_ABORT_MOTION_PROPERTY, property)) { | ||
// -------------------------------------------------------------------------------- ROTATOR_ABORT_MOTION | ||
indigo_property_copy_values(ROTATOR_ABORT_MOTION_PROPERTY, property, false); | ||
if (ROTATOR_ABORT_MOTION_ITEM->sw.value && ROTATOR_POSITION_PROPERTY->state == INDIGO_BUSY_STATE) { | ||
ROTATOR_POSITION_PROPERTY->state = INDIGO_ALERT_STATE; | ||
ROTATOR_POSITION_ITEM->number.value = PRIVATE_DATA->current_position; | ||
indigo_update_property(device, ROTATOR_POSITION_PROPERTY, NULL); | ||
} | ||
ROTATOR_ABORT_MOTION_PROPERTY->state = INDIGO_OK_STATE; | ||
ROTATOR_ABORT_MOTION_ITEM->sw.value = false; | ||
indigo_update_property(device, ROTATOR_ABORT_MOTION_PROPERTY, NULL); | ||
return INDIGO_OK; | ||
// -------------------------------------------------------------------------------- | ||
} | ||
return indigo_rotator_change_property(device, client, property); | ||
} | ||
|
||
static indigo_result rotator_detach(indigo_device *device) { | ||
assert(device != NULL); | ||
if (CONNECTION_CONNECTED_ITEM->sw.value) | ||
indigo_device_disconnect(NULL, device->name); | ||
INDIGO_DEVICE_DETACH_LOG(DRIVER_NAME, device->name); | ||
return indigo_rotator_detach(device); | ||
} | ||
|
||
// -------------------------------------------------------------------------------- | ||
|
||
static simulator_private_data *private_data = NULL; | ||
static indigo_device *imager_focuser = NULL; | ||
|
||
indigo_result indigo_rotator_simulator(indigo_driver_action action, indigo_driver_info *info) { | ||
static indigo_device imager_rotator_template = INDIGO_DEVICE_INITIALIZER( | ||
SIMULATOR_ROTATOR_NAME, | ||
rotator_attach, | ||
indigo_rotator_enumerate_properties, | ||
rotator_change_property, | ||
NULL, | ||
rotator_detach | ||
); | ||
|
||
static indigo_driver_action last_action = INDIGO_DRIVER_SHUTDOWN; | ||
|
||
SET_DRIVER_INFO(info, "Field Rotator Simulator", __FUNCTION__, DRIVER_VERSION, true, last_action); | ||
|
||
if (action == last_action) | ||
return INDIGO_OK; | ||
|
||
switch(action) { | ||
case INDIGO_DRIVER_INIT: | ||
last_action = action; | ||
private_data = malloc(sizeof(simulator_private_data)); | ||
assert(private_data != NULL); | ||
memset(private_data, 0, sizeof(simulator_private_data)); | ||
imager_focuser = malloc(sizeof(indigo_device)); | ||
assert(imager_focuser != NULL); | ||
memcpy(imager_focuser, &imager_rotator_template, sizeof(indigo_device)); | ||
imager_focuser->private_data = private_data; | ||
indigo_attach_device(imager_focuser); | ||
break; | ||
|
||
case INDIGO_DRIVER_SHUTDOWN: | ||
last_action = action; | ||
if (imager_focuser != NULL) { | ||
if (private_data) indigo_cancel_timer(imager_focuser, &private_data->rotator_timer); | ||
indigo_detach_device(imager_focuser); | ||
free(imager_focuser); | ||
imager_focuser = NULL; | ||
} | ||
if (private_data != NULL) { | ||
free(private_data); | ||
private_data = NULL; | ||
} | ||
break; | ||
|
||
case INDIGO_DRIVER_INFO: | ||
break; | ||
} | ||
return INDIGO_OK; | ||
} |
47 changes: 47 additions & 0 deletions
47
indigo_drivers/rotator_simulator/indigo_rotator_simulator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2020 Rumen G.Bogdanovki | ||
// All rights reserved. | ||
// | ||
// You can use this software under the terms of 'INDIGO Astronomy | ||
// open-source license' (see LICENSE.md). | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS 'AS IS' AND ANY EXPRESS | ||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
// version history | ||
// 2.0 by Rumen G.Bogdanovski <[email protected]> | ||
|
||
/** INDIGO Field Rotator Simulator driver | ||
\file indigo_rotator_simulator.h | ||
*/ | ||
|
||
#ifndef rotator_simulator_h | ||
#define rotator_simulator_h | ||
|
||
#include <indigo/indigo_driver.h> | ||
#include <indigo/indigo_rotator_driver.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define SIMULATOR_ROTATOR_NAME "Field Rotator Simulator" | ||
|
||
/** Create Field Rotator Simulator device instance | ||
*/ | ||
|
||
extern indigo_result indigo_rotator_simulator(indigo_driver_action action, indigo_driver_info *info); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* rotator_simulator_h */ |
44 changes: 44 additions & 0 deletions
44
indigo_drivers/rotator_simulator/indigo_rotator_simulator_main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2020 Rumen G.Bogdanovski | ||
// All rights reserved. | ||
// | ||
// You can use this software under the terms of 'INDIGO Astronomy | ||
// open-source license' (see LICENSE.md). | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS 'AS IS' AND ANY EXPRESS | ||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
// version history | ||
// 2.0 by Rumen G.Bogdanovski <[email protected]> | ||
|
||
/** INDIGO Field Rotator Simulator driver main | ||
\file indigo_rotator_simulator_main.c | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <indigo/indigo_driver_xml.h> | ||
#include "indigo_rotator_simulator.h" | ||
|
||
int main(int argc, const char * argv[]) { | ||
indigo_main_argc = argc; | ||
indigo_main_argv = argv; | ||
indigo_client *protocol_adapter = indigo_xml_device_adapter(0, 1); | ||
indigo_start(); | ||
indigo_rotator_simulator(INDIGO_DRIVER_INIT, NULL); | ||
indigo_attach_client(protocol_adapter); | ||
indigo_xml_parse(NULL, protocol_adapter); | ||
indigo_rotator_simulator(INDIGO_DRIVER_SHUTDOWN, NULL); | ||
indigo_stop(); | ||
return 0; | ||
} |