diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-10-02 15:35:47 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-10-02 15:35:47 +0000 |
commit | 0e55f18cd6fd05262b82cafce6ab53dad275c148 (patch) | |
tree | 6c265611439ec3d77a7da6f561012d3c50962ad6 /src/dirax.c | |
parent | 49b0bf4c38f7b2ecdb25b138abc8aa5ff06267c4 (diff) |
DirAx improvements
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@140 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/dirax.c')
-rw-r--r-- | src/dirax.c | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/src/dirax.c b/src/dirax.c index 4f4d135..4834ba3 100644 --- a/src/dirax.c +++ b/src/dirax.c @@ -46,8 +46,8 @@ static void dirax_parseline(const char *line, ControlContext *ctx) { copy = strdup(line); for ( i=0; i<strlen(copy); i++ ) { - if ( copy[i] == '\r' ) copy[i]='r'; - if ( copy[i] == '\n' ) copy[i]='n'; + if ( copy[i] == '\r' ) copy[i]=' '; + if ( copy[i] == '\n' ) copy[i]='\0'; } printf("DX: DirAx: %s\n", copy); free(copy); @@ -73,23 +73,23 @@ static void dirax_parseline(const char *line, ControlContext *ctx) { /* Parse unit cell vectors as appropriate */ if ( ctx->dirax_read_cell == 1 ) { /* First row of unit cell values */ - float x, y, z; - sscanf(line, "%f %f %f", &x, &y, &z); - ctx->cell->a.x = x*1e10; ctx->cell->a.y = y*1e10; ctx->cell->a.z = z*1e10; + float x1, x2, x3; + sscanf(line, "%f %f %f", &x1, &x2, &x3); + ctx->cell->a.x = x1*1e10; ctx->cell->b.x = x2*1e10; ctx->cell->c.x = x3*1e10; ctx->dirax_read_cell++; return; } else if ( ctx->dirax_read_cell == 2 ) { /* First row of unit cell values */ - float x, y, z; - sscanf(line, "%f %f %f", &x, &y, &z); - ctx->cell->b.x = x*1e10; ctx->cell->b.y = y*1e10; ctx->cell->b.z = z*1e10; + float y1, y2, y3; + sscanf(line, "%f %f %f", &y1, &y2, &y3); + ctx->cell->a.y = y1*1e10; ctx->cell->b.y = y2*1e10; ctx->cell->c.y = y3*1e10; ctx->dirax_read_cell++; return; } else if ( ctx->dirax_read_cell == 3 ) { /* First row of unit cell values */ - float x, y, z; - sscanf(line, "%f %f %f", &x, &y, &z); - ctx->cell->c.x = x*1e10; ctx->cell->c.y = y*1e10; ctx->cell->c.z = z*1e10; + float z1, z2, z3; + sscanf(line, "%f %f %f", &z1, &z2, &z3); + ctx->cell->a.z = z1*1e10; ctx->cell->b.z = z2*1e10; ctx->cell->c.z = z3*1e10; printf("DX: Read a reciprocal unit cell\n"); displaywindow_update(ctx->dw); ctx->dirax_read_cell = 0; @@ -128,12 +128,30 @@ static void dirax_send_next(ControlContext *ctx) { } case 1 : { - dirax_sendline("go\n", ctx); + dirax_sendline("dmax 50\n", ctx); ctx->dirax_step++; break; } case 2 : { + dirax_sendline("indexfit 2\n", ctx); + ctx->dirax_step++; + break; + } + + case 3 : { + dirax_sendline("levelfit 300\n", ctx); + ctx->dirax_step++; + break; + } + + case 4 : { + dirax_sendline("go\n", ctx); + ctx->dirax_step++; + break; + } + + case 5 : { dirax_sendline("cell\n", ctx); ctx->dirax_step++; break; @@ -158,6 +176,7 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition, Contro if ( (rval == -1) || (rval == 0) ) { printf("DX: Lost connection to DirAx\n"); + waitpid(ctx->dirax_pid, NULL, 0); g_io_channel_shutdown(ctx->dirax, FALSE, NULL); ctx->dirax = NULL; return FALSE; @@ -272,9 +291,13 @@ void dirax_invoke(ControlContext *ctx) { FILE *fh; Reflection *ref; - int pty; unsigned int opts; - pid_t dirax_pid; + struct termios tty; + + if ( ctx->dirax ) { + printf("DX: DirAx is already running.\n"); + return; + } printf("DX: Starting DirAx...\n"); @@ -291,18 +314,17 @@ void dirax_invoke(ControlContext *ctx) { } fclose(fh); - struct termios tty; if ( ioctl(0, TCGETS, &tty) ) { printf("DX: Failed to read pty attributes\n"); return; } tty.c_lflag &= ~ECHO; - dirax_pid = forkpty(&pty, NULL, &tty, NULL); - if ( dirax_pid == -1 ) { + ctx->dirax_pid = forkpty(&ctx->dirax_pty, NULL, &tty, NULL); + if ( ctx->dirax_pid == -1 ) { printf("DX: Failed to fork.\n"); return; } - if ( dirax_pid == 0 ) { + if ( ctx->dirax_pid == 0 ) { /* Child process: invoke DirAx */ execlp("dirax", "", (char *)NULL); @@ -311,18 +333,17 @@ void dirax_invoke(ControlContext *ctx) { } - ctx->dirax_pty = pty; ctx->dirax_rbuffer = malloc(256); ctx->dirax_rbuflen = 256; ctx->dirax_rbufpos = 0; /* Set non-blocking */ - opts = fcntl(pty, F_GETFL); - fcntl(pty, F_SETFL, opts | O_NONBLOCK); + opts = fcntl(ctx->dirax_pty, F_GETFL); + fcntl(ctx->dirax_pty, F_SETFL, opts | O_NONBLOCK); ctx->dirax_step = 0; ctx->dirax_read_cell = 0; - ctx->dirax = g_io_channel_unix_new(pty); + ctx->dirax = g_io_channel_unix_new(ctx->dirax_pty); g_io_add_watch(ctx->dirax, G_IO_IN | G_IO_HUP, (GIOFunc)dirax_readable, ctx); return; |