Commit fb6590f7 authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

andor-test-4 is now andor-features

parent fffba02f
......@@ -2,6 +2,16 @@
## Versions 0.8
* New utility program `andor-features`.
* New naming conventions. Most functions are named following the template
`tao_$TYPE_$VERB` or `tao_$TYPE_$VERB_$NOUN` with `$TYPE` the type of the
main argument, `$VERB` a verb indication the action, and `$NOUN` a noun.
This follows conventions in many large C libraries and helps to quickly
figure out the methods associated with a given object type (there are almost
500 functions in the main TAO library and almost 700 functions in all TAO
libraries).
* Simplify and speed-up error management. In the previous versions, error
stack almost never had a depth greater than one which means that it would be
sufficient to have each thread just memorize its last error. The information
......@@ -13,7 +23,7 @@
- Implementation is much more simple.
- No needs to perform any cleanup on exit and no risk or memory leaks.
- No needs to perform any cleanup on exit and no risks of memory leaks.
- Bindings are much easier to write.
......
......@@ -63,15 +63,20 @@ libtao_andor_la_LDFLAGS = -version-info @version_info@
TESTS = \
andor-test-1 \
andor-test-2 \
andor-test-3 \
andor-test-4
andor-test-3
if USE_CFITSIO
TESTS += andor-test-5
endif
bin_PROGRAMS = andor-server $(TESTS)
#noinst_PROGRAMS = $(TESTS)
bin_PROGRAMS = \
andor-features \
andor-server
noinst_PROGRAMS = $(TESTS)
andor_features_SOURCES = andor-features.c
andor_features_LDADD = $(COMMON_LIBS)
andor_server_SOURCES = andor-server.c
andor_server_CPPFLAGS = $(XPA_DEFS) $(COMMON_DEFS)
......@@ -86,9 +91,6 @@ andor_test_2_LDADD = $(COMMON_LIBS)
andor_test_3_SOURCES = andor-test-3.c
andor_test_3_LDADD = $(COMMON_LIBS)
andor_test_4_SOURCES = andor-test-4.c
andor_test_4_LDADD = $(COMMON_LIBS)
andor_test_5_SOURCES = andor-test-5.c
andor_test_5_CPPFLAGS = $(CFITSIO_DEFS) $(COMMON_DEFS)
andor_test_5_LDADD = $(TAO_FITS_LIBS) $(COMMON_LIBS)
......@@ -111,8 +113,8 @@ test2: andor-test-2
test3: andor-test-3
LD_LIBRARY_PATH="$(ANDOR_LIBDIR)" ./andor-test-3
test4: andor-test-4
LD_LIBRARY_PATH="$(ANDOR_LIBDIR)" ./andor-test-4
test4: andor-features
LD_LIBRARY_PATH="$(ANDOR_LIBDIR)" ./andor-features
test5: andor-test-5
LD_LIBRARY_PATH="$(ANDOR_LIBDIR)" ./andor-test-5
// andor-test-4.c -
// andor-features.c -
//
// Tests for Andor cameras library: list all known features and their values.
// Utility program for Andor cameras: list all known features and their values.
//
//-----------------------------------------------------------------------------
//
......@@ -102,7 +102,7 @@ static void ambiguous_type(
const char* file,
int line)
{
fprintf(stderr, "ambiguous type [%d] for \"%ls\" in %s, line %d\n",
fprintf(stderr, "Ambiguous type [%d] for \"%ls\" in %s, line %d\n",
type, name, file, line);
exit(EXIT_FAILURE);
}
......@@ -137,7 +137,7 @@ static void debug_feature(
unsigned int mode;
const int wstrlen = 1024;
wchar_t wstr[wstrlen];
AT_H handle = camera->handle;
AT_H handle = (camera == NULL ? AT_HANDLE_SYSTEM : camera->handle);
// Check that AT_IsImplemented, AT_IsReadable, AT_IsWritable, and
// AT_IsReadOnly yield consistent results.
......@@ -250,7 +250,7 @@ static void debug_feature(
}
type = ANDOR_FEATURE_ENUMERATED;
PRINT_FEATURE_3(
output, name, "%s enumerated = %d / \"%ls\"\n",
output, name, "%s enumerated = %d => \"%ls\"\n",
rwflags(mode), idx, wstr);
} else if (code == AT_SUCCESS &&
type != ANDOR_FEATURE_NOT_IMPLEMENTED) {
......@@ -324,7 +324,7 @@ static void print_feature(
exit(EXIT_FAILURE);
}
PRINT_FEATURE_3(
output, name, "%s enumerated = %d / \"%ls\"\n",
output, name, "%s enumerated = %d => \"%ls\"\n",
rwflags(info.mode), index, wstr);
break;
case ANDOR_FEATURE_STRING:
......@@ -358,61 +358,93 @@ int main(
tao_report_error();
return EXIT_FAILURE;
}
fprintf(stderr, "Found connected %ld Andor device(s)\n", ndevices);
// Parse arguments.
FILE* output;
const char* progname = tao_basename(argv[0]);
bool debug = false;
long devnum = 0;
bool help = false;
long devfirst = -1;
long devlast = ndevices - 1;
int nargs = 0; // number of positional arguments
for (int i = 1; i < argc; ++i) {
if (nargs == 0 && argv[i][0] == '-') {
if (strcmp(argv[i], "-debug") == 0) {
if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--debug") == 0) {
debug = true;
continue;
}
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
help = true;
goto usage;
}
if (strcmp(argv[i], "--") == 0) {
continue;
}
}
if (nargs == 0) {
long devnum;
if (tao_parse_long(argv[i], &devnum, 0) != TAO_OK ||
devnum < 0 || devnum >= ndevices) {
devnum < -1 || devnum >= ndevices) {
fprintf(stderr, "%s: Invalid device number %s\n",
progname, argv[i]);
return EXIT_FAILURE;
}
devfirst = devlast = devnum;
++nargs;
} else {
fprintf(stderr, "Usage: %s [-debug] [--] [dev]\n", progname);
return EXIT_FAILURE;
usage:
output = (help ? stdout : stderr);
fprintf(
output, "Usage: %s [-h|--help] [-d|--debug] [--] [dev]\n",
progname);
if (help) {
fprintf(
output, "\n%s\n",
"List Andor features of connected devices or just of "
"device `dev` if\nspecified (set `dev` to -1 for the "
"system).\n"
"\n"
"Options:\n"
" -d, --debug Also check assumptions.\n"
" -h, --help Print this help.\n");
}
return (help ? EXIT_SUCCESS : EXIT_FAILURE);
}
}
// Open camera.
andor_camera* camera = (andor_camera*)andor_open_camera(devnum);
if (camera == NULL) {
tao_report_error();
return EXIT_FAILURE;
}
// List features.
// List of known features.
const andor_feature_definition* defs =
andor_feature_get_known_definitions();
printf("Features of Andor device %ld:\n", devnum);
for (int i = 0; defs[i].wide_name != NULL; ++i) {
if (debug) {
debug_feature(stdout, camera, defs[i].wide_name, defs[i].type);
// List features for devices.
fprintf(stderr, "Found %ld connected Andor device(s).\n", ndevices);
for (long devnum = devfirst; devnum <= devlast; ++devnum) {
andor_camera* camera = NULL;
if (devnum >= 0) {
printf("\nFeatures of Andor device %ld:\n", devnum);
camera = (andor_camera*)andor_open_camera(devnum);
if (camera == NULL) {
tao_report_error();
return EXIT_FAILURE;
}
} else {
print_feature(stdout, camera, defs[i].wide_name, defs[i].type);
printf("\nFeatures of Andor system:\n");
}
for (int i = 0; defs[i].wide_name != NULL; ++i) {
if (debug) {
debug_feature(stdout, camera, defs[i].wide_name, defs[i].type);
} else {
print_feature(stdout, camera, defs[i].wide_name, defs[i].type);
}
}
if (camera != NULL) {
tao_camera_destroy((tao_camera*)camera);
}
if (tao_any_errors(NULL)) {
tao_report_error();
return EXIT_FAILURE;
}
}
// Destroy camera.
tao_camera_destroy((tao_camera*)camera);
if (tao_any_errors(NULL)) {
tao_report_error();
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment