CelestronMount::CelestronMount(const std::string& devicename)
	: Mount(devicename), Serial(getserialname(devicename)) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "creating Celestron mount on %s",
		serialdevice().c_str());

	// check communication
	write("Kx");
	std::string	k = read(1);
	getprompt();
	if (k != std::string("X")) {
		std::runtime_error("no echo received");
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "mount has responded to echo request");
	// ask for version
	write("V");
	std::string	v = readto('#');
	v = v.substr(0, 2);
	debug(LOG_DEBUG, DEBUG_LOG, 0, "version = '%s' (%d bytes, %02X%02X)",
		v.c_str(), v.size(), v[0], v[1]);
	version = 0;
	if (v.size() >= 2) {
		try {
			version = 100 * v[0] + v[1];
		} catch (const std::exception& x) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "cannot convert: %s",
				x.what());
		}
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "version: %d", version);
}
Example #2
0
STATIC void
setprompt(int which)
{
	whichprompt = which;

#ifndef NO_HISTORY
	if (!el)
#endif /* !NO_HISTORY */
		out2str(getprompt(NULL));
}
void	CelestronMount::Goto(const RaDec& radec) {
	std::string	cmd;
	if (version > 106) {
		cmd = stringprintf("r%08X,%08X",
			angle32(radec.ra()), angle32(radec.dec()));
	} else {
		cmd = stringprintf("R%04X,%04X",
			angle16(radec.ra()), angle16(radec.dec()));
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "command sent: %s", cmd.c_str());
	write(cmd);
	getprompt();
}
void	CelestronMount::Goto(const AzmAlt& azmalt) {
	std::string	cmd;
	if (version > 202) {
		cmd = stringprintf("b%08X,%08X",
			angle32(azmalt.azm()), angle32(azmalt.alt()));
	} else {
		cmd = stringprintf("B%04X,%04X",
			angle16(azmalt.azm()), angle16(azmalt.alt()));
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "command sent: %s", cmd.c_str());
	write(cmd);
	getprompt();
}
Example #5
0
int main(int argc, char *argv[])
{
  int count, i, tmp, j;
  int builtin_f;
  int hist_expand_status;
  cmd **cmds;
  char *hist_tmp;
  sh_init();
  using_history();
  while (buf = readline(getprompt())) {
    if (buf[0] == '!') { // history expand
      hist_expand_status = history_expand(buf, &hist_tmp);
      if (hist_expand_status == 1) {
        buf = realloc(buf, (strlen(hist_tmp)+1) * sizeof(char));
        strcpy(buf, hist_tmp);
      } else {
        fprintf(stderr, "shell: %s: event not found\n", buf);
        free(buf);
        continue;
      }
    }
    if (*buf)
      add_history(buf);
    
    cmds = malloc(INIT_SIZE * sizeof(cmd *));
    cmds_init(cmds, INIT_SIZE);
    tmp = strlen(buf);
    buf = realloc(buf, (tmp + 2) * sizeof(char));
    buf[tmp] = '\n'; buf[tmp+1] = '\0';
    count = parse(buf, cmds, INIT_SIZE);
    buf[tmp] = '\0';
    //print(cmds, count);
    if (count != -1)
      for (i = 0; i < count; ++i) {
        builtin_f = 0;
        for (j = 0; j < BUILTIN_N; ++j)
          if (strcmp(cmds[i]->argv[0], builtin_list[j]) == 0) {
            (*builtins[j])(cmds[i]);
            builtin_f = 1;
            break;
          }
        if (!builtin_f)
          exec_cmd(cmds[i]);
      }
    jobctl_print_msgs();
    for (i = 0; i < count; ++i)
      cmd_dealloc(cmds[i]);
    free(buf);
  }
  return 0;
}
Example #6
0
STATIC void
setprompt(int which)
{
	whichprompt = which;

#ifndef NO_HISTORY
#ifdef EDITLINE
	if (!editable)
#else
	if (!el)
#endif /* EDITLINE */
#endif /* !NO_HISTORY */
		out2str(getprompt(NULL));
}
void	CelestronMount::cancel() {
	write("M");
	getprompt();
}
Example #8
0
static int
preadfd(void)
{
	int nr;
	parsenextc = parsefile->buf;

#if !defined(NO_HISTORY) && !defined(EDITLINE)
	if (el != NULL && gotwinch) {
		gotwinch = 0;
		el_resize(el);
	}
#endif
retry:
#ifndef NO_HISTORY
#ifdef EDITLINE
	if (parsefile->fd == 0 && editable) {
		static const char *rl_cp= NULL;
		static size_t rl_off= 0;

		if (!rl_cp)
		{
			rl_cp = readline(getprompt(NULL));
			if (rl_cp == NULL)
				nr = 0;
		}
		if (rl_cp)
		{
			nr= strlen(rl_cp+rl_off);
			if (nr >= BUFSIZ-1)
			{
				nr= BUFSIZ-1;
				(void) memcpy(parsenextc, rl_cp+rl_off, nr);
				rl_off += nr;
			}
			else
			{
				(void) memcpy(parsenextc, rl_cp+rl_off, nr);
				parsenextc[nr++]= '\n';
				free(rl_cp);
				rl_cp= NULL;
				rl_off= 0;
			}
		}
	} else
#else /* !EDITLINE */
	if (parsefile->fd == 0 && el) {
		const char *rl_cp;

		rl_cp = el_gets(el, &nr);
		if (rl_cp == NULL)
			nr = 0;
		else {
			/* XXX - BUFSIZE should redesign so not necessary */
			(void) strcpy(parsenextc, rl_cp);
		}
	} else
#endif /* !EDITLINE */
#endif
		nr = read(parsefile->fd, parsenextc, BUFSIZ - 1);

	if (nr <= 0) {
                if (nr < 0) {
                        if (errno == EINTR)
                                goto retry;
#ifdef EWOULDBLOCK
                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
                                int flags = fcntl(0, F_GETFL, 0);
                                if (flags >= 0 && flags & O_NONBLOCK) {
                                        flags &=~ O_NONBLOCK;
                                        if (fcntl(0, F_SETFL, flags) >= 0) {
						out2str("sh: turning off NDELAY mode\n");
                                                goto retry;
                                        }
                                }
                        }
#endif /* EWOULDBLOCK */
                }
                nr = -1;
	}
	return nr;
}
Example #9
0
static int
preadfd(void)
{
	int nr;
	char *buf =  parsefile->buf;
	parsefile->nextc = buf;
	const char* prompt = NULL;

retry:
#ifdef USE_LINENOISE
	if (parsefile->fd == 0 && iflag) {
		if (pending_line == NULL) {
			// linenoise stashs the prompt buffer away for
			// the duration of its edit cycle. Because
			// some edit functionality (in particular, tab
			// completion allocates the parts of PATH from
			// dash's stack-based allocator), we need to
			// properly save the string and then free it,
			// or it will be clobbered.
			prompt = savestr(getprompt(NULL));
			pending_line = linenoise(prompt);
			if (pending_line) {
				pending_line_index = 0u;
				pending_line_length = strlen(pending_line);
				pending_line[pending_line_length] = '\n';
				pending_line_length += 1;
			}
		}
		if (pending_line == NULL)
			nr = 0;
		else {
			nr = pending_line_length - pending_line_index;
			if (nr > IBUFSIZ - 1)
				nr = IBUFSIZ - 1;
			memcpy(buf, pending_line + pending_line_index, nr);
			pending_line_index += nr;
			if (pending_line_index == pending_line_length) {
				linenoiseFree(pending_line);
				free(prompt);
				pending_line = NULL;
				pending_line_index = 0u;
				pending_line_length = 0u;
			}
		}
	} else
#endif
		nr = read(parsefile->fd, buf, IBUFSIZ - 1);


	if (nr < 0) {
		if (errno == EINTR)
			goto retry;
		if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
			int flags = fcntl(0, F_GETFL, 0);
			if (flags >= 0 && flags & O_NONBLOCK) {
				flags &=~ O_NONBLOCK;
				if (fcntl(0, F_SETFL, flags) >= 0) {
					out2str("sh: turning off NDELAY mode\n");
					goto retry;
				}
			}
		}
	}
	return nr;
}