Exemple #1
0
static void save_handler(struct rtgui_widget* widget, rtgui_event_t* event)
{
    extern void brightness_set(unsigned int value);

    rt_uint32_t vol, bri;
    vol = rtgui_slider_get_value(slider_volume);
    bri = rtgui_slider_get_value(slider_brightness);

    //更新背光
    brightness_set(bri);

    //更新音量
    {
        rt_device_t dev = RT_NULL;
        dev = rt_device_find("snd");
        dev->control(dev, CODEC_CMD_VOLUME, &vol);
    }

    //保存配置
    radio_setup.default_volume = vol;
    radio_setup.lcd_brightness = bri;
    save_setup();

    //保存完毕,销毁本界面
    {
        rtgui_view_t* view;
        rtgui_workbench_t* workbench;

        /* remove view in workbench */
        view = RTGUI_VIEW(widget->parent);
        workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
        rtgui_workbench_remove_view(workbench, view);
        rtgui_view_destroy(view);
    }
}
Exemple #2
0
void
save_setup_cmd (void)
{
    save_setup ();
    sync_profiles ();
    
    message (0, _(" Setup "), _(" Setup saved to ~/%s"), PROFILE_NAME);
}
Exemple #3
0
void
save_setup_cmd (void)
{
    char *str;
    
    save_setup ();
    sync_profiles ();
    str = g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME, (char *) NULL);
    
    message (0, _(" Setup "), str);
    g_free (str);
}
Exemple #4
0
void load_default(void)
{
    rt_kprintf("load_default!\r\n");
    radio_setup.default_volume = 25;
    radio_setup.lcd_brightness = 50;

    radio_setup.touch_min_x = 194;
    radio_setup.touch_max_x = 1810;
    radio_setup.touch_min_y = 147;
    radio_setup.touch_max_y = 1850;

    save_setup();
}
Exemple #5
0
void
save_setup_cmd (void)
{
    char *d1;
    const char *d2;

    d1 = mc_config_get_full_path (MC_CONFIG_FILE);
    d2 = strip_home_and_password (d1);
    g_free (d1);

    if (save_setup (TRUE, TRUE))
        message (D_NORMAL, _("Setup"), _("Setup saved to %s"), d2);
    else
        message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), d2);
}
Exemple #6
0
void
save_setup_cmd (void)
{
    vfs_path_t *vpath;
    const char *path;

    vpath = vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME);
    path = vfs_path_as_str (vpath);

    if (save_setup (TRUE, TRUE))
        message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
    else
        message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);

    vfs_path_free (vpath);
}
Exemple #7
0
int
job_or_resv_save_fs(void *pobj, int updatetype, int objtype)
{
	int	fds;
	int	openflags;
	int	redo;
	char	*filename;
	char	namebuf1[MAXPATHLEN+1];
	char	namebuf2[MAXPATHLEN+1];

	char		*path = (char*)0;
	char		*err_msg = (char*)0;
	char		*err_msgl = (char*)0;
	char		*prefix = (char*)0;
	char		*suffix = (char*)0;
	char		*cpsuffix = (char*)0;

	char		*p_oid = (char*)0;
	long		*p_mtime = (long*)0;
	int		*p_modified = (int*)0;
	void		*pfixed = (void*)0;
	ssize_t		i;
	size_t		fixed_size;
	attribute_def	*p_attr_def = (attribute_def*)0;
	attribute	*wattr = (attribute*)0;
	int		final_attr;
	int		eventclass;
	int		pmode;

#ifdef WIN32
	pmode = _S_IWRITE | _S_IREAD;
#else
	pmode = 0600;
#endif

	if (objtype == RESC_RESV_OBJECT || objtype == RESV_JOB_OBJECT) {
#ifndef PBS_MOM	/* MOM knows not of resc_resv structs */
		resc_resv  *presv;
		presv = (resc_resv *)pobj;
		err_msg = "reservation_save";
		err_msgl = "Link in reservation_save failed";
		path = path_resvs;
		prefix = presv->ri_qs.ri_fileprefix;
		suffix = RESV_FILE_SUFFIX;
		cpsuffix = RESV_FILE_COPY;
		p_modified = &presv->ri_modified;
		pfixed = (void *)&presv->ri_qs;
		fixed_size = sizeof(struct resvfix);
		p_attr_def = resv_attr_def;
		wattr = presv->ri_wattr;
		final_attr = RESV_ATR_LAST;
		p_mtime = &presv->ri_wattr[RESV_ATR_mtime].at_val.at_long;
		p_oid = presv->ri_qs.ri_resvID;
		eventclass = PBS_EVENTCLASS_RESV;
#else	/* PBS_MOM only: Execution will never come here for MOM */
		return (-1);
#endif
	}
	else if (objtype == JOB_OBJECT) {
		job   *pj = (job *)pobj;

#ifndef PBS_MOM	/*MOM knows not of resc_resv structs*/
		if (pj->ji_resvp) {
			int	rc = 0;

			if (updatetype == SAVEJOB_QUICK)
				rc = job_or_resv_save((void *)pj->ji_resvp,
					SAVERESV_QUICK,
					RESC_RESV_OBJECT);
			else if ((updatetype == SAVEJOB_FULL) ||
				(updatetype == SAVEJOB_FULLFORCE)  ||
				(updatetype == SAVEJOB_NEW))
				rc = job_or_resv_save((void *)pj->ji_resvp,
					SAVERESV_FULL,
					RESC_RESV_OBJECT);
			if (rc)
				return (rc);
		}
#endif
		err_msg = "job_save";
		err_msgl = "Link in job_save failed";
		path = path_jobs;
		if (*pj->ji_qs.ji_fileprefix != '\0')
			prefix = pj->ji_qs.ji_fileprefix;
		else
			prefix = pj->ji_qs.ji_jobid;
		suffix = JOB_FILE_SUFFIX;
		cpsuffix = JOB_FILE_COPY;
		p_modified = &pj->ji_modified;
		pfixed = (void *)&pj->ji_qs;
		fixed_size = sizeof(struct jobfix);
		p_attr_def = job_attr_def;
		wattr = pj->ji_wattr;
		final_attr = JOB_ATR_LAST;
		p_mtime = &pj->ji_wattr[JOB_ATR_mtime].at_val.at_long;
		p_oid = pj->ji_qs.ji_jobid;
		eventclass = PBS_EVENTCLASS_JOB;
		return (job_save_fs(pj, updatetype));
	} else {
		/*Don't expect to get here; incorrect object type*/
		return (-1);
	}

	(void)strcpy(namebuf1, path);		/* directory path */
	(void)strcat(namebuf1, prefix);
	(void)strcpy(namebuf2, namebuf1);	/* setup for later */
	(void)strcat(namebuf1, suffix);

	/*if an attribute changed (modified==1) update mtime*/

	if (*p_modified) {
		*p_mtime = time_now;
	}

	if (updatetype == SAVEJOB_QUICK || updatetype == SAVERESV_QUICK) {

		openflags =  O_WRONLY | O_Sync;
		fds = open(namebuf1, openflags, pmode);
		if (fds < 0) {
			log_err(errno, err_msg, "error on open");
			return (-1);
		}
#ifdef WIN32
		secure_file(namebuf1, "Administrators",
			READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
		setmode(fds, O_BINARY);
#endif
		/* just write the "critical" base structure to the file */

		while ((i = write(fds, (char *)pfixed, fixed_size)) !=
			fixed_size) {
			if ((i < 0) && (errno == EINTR)) {
				/* retry the write */
				if (lseek(fds, (off_t)0, SEEK_SET) < 0) {
					log_err(errno, err_msg, "lseek");
					(void)close(fds);
					return (-1);
				}
				continue;
			} else {
				log_err(errno, err_msg, "quickwrite");
				(void)close(fds);
				return (-1);
			}
		}
#ifdef WIN32
		if (_commit(fds) != 0) {
			log_err(errno, err_msg,
				"flushing job file to disk failed!");
			(void)close(fds);
			return (-1);
		}
#endif
		(void)close(fds);

	} else {

		/*
		 * write the whole structure to the file.
		 * For a update, this is done to a new file to protect the
		 * old against crashs.
		 * The file is written in four parts:
		 * (1) the job (resc_resv) structure,
		 * (2) the attributes in "encoded" form,
		 * (3) the attributes in the "external" form, and last
		 * (4) the dependency list.
		 */

		(void)strcat(namebuf2, cpsuffix);
		openflags =  O_CREAT | O_WRONLY | O_Sync;
#ifdef WIN32
		fix_perms2(namebuf2, namebuf1);
#endif
		if (updatetype == SAVEJOB_NEW || updatetype == SAVERESV_NEW)
			filename = namebuf1;
		else
			filename = namebuf2;

		fds = open(filename, openflags, pmode);
		if (fds < 0) {
			log_err(errno, err_msg, "open for full save");
			return (-1);
		}

#ifdef WIN32
		secure_file(filename, "Administrators",
			READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
		setmode(fds, O_BINARY);
#endif

		redo = 0;	/* try to save twice */
		do {
			save_setup(fds);
			if (save_struct((char *)pfixed, fixed_size) != 0) {
				redo++;
			} else if (save_attr_fs(p_attr_def, wattr, final_attr) != 0) {
				redo++;
			} else if (save_flush() != 0) {
				redo++;
			}
			if (redo != 0) {
				if (lseek(fds, (off_t)0, SEEK_SET) < 0) {
					log_err(errno, err_msg, "full lseek");
					redo++;
				}
			}
		} while (redo == 1);

#ifdef WIN32
		if (_commit(fds) != 0) {
			log_err(errno, err_msg,
				"flush job file to disk failed!");
			close(fds);
			return (-1);
		}
#endif

		(void)close(fds);
		if (redo > 1) {
			if (updatetype == SAVEJOB_FULL ||
				updatetype == SAVEJOB_FULLFORCE ||
				updatetype == SAVERESV_FULL)
				(void)unlink(namebuf2);
			return (-1);
		}

		if (updatetype == SAVEJOB_FULL ||
			updatetype == SAVEJOB_FULLFORCE ||
			updatetype == SAVERESV_FULL) {

#ifdef WIN32
			if (MoveFileEx(namebuf2, namebuf1,
				MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH) ==
				0) {
				errno = GetLastError();
				sprintf(log_buffer, "MoveFileEx(%s,%s) failed!",
					namebuf2, namebuf1);
				log_err(errno, err_msg, log_buffer);
			}
			secure_file(namebuf1, "Administrators",
				READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
#else
			if (rename(namebuf2, namebuf1) == -1) {
				log_event(PBSEVENT_ERROR|PBSEVENT_SECURITY,
					eventclass, LOG_ERR, p_oid, err_msgl);
			}
#endif
		}
		*p_modified = 0;
	}
	return (0);
}
Exemple #8
0
int
job_save_fs(job *pjob, int updatetype)
{
#ifndef	PBS_MOM
	int	isarray = 0;
#endif	/* PBS_MOM */
	int	fds;
	int	i;
	char	*filename;
	char	namebuf1[MAXPATHLEN+1];
	char	namebuf2[MAXPATHLEN+1];
	int	openflags;
	int	redo;
	int	pmode;

#ifdef WIN32
	pmode = _S_IWRITE | _S_IREAD;
#else
	pmode = 0600;
#endif

	(void)strcpy(namebuf1, path_jobs);	/* job directory path */
	if (*pjob->ji_qs.ji_fileprefix != '\0')
		(void)strcat(namebuf1, pjob->ji_qs.ji_fileprefix);
	else
		(void)strcat(namebuf1, pjob->ji_qs.ji_jobid);
	(void)strcpy(namebuf2, namebuf1);	/* setup for later */
	(void)strcat(namebuf1, JOB_FILE_SUFFIX);

	/* if ji_modified is set, ie an attribute changed, then update mtime */

	if (pjob->ji_modified) {
		pjob->ji_wattr[JOB_ATR_mtime].at_val.at_long = time_now;
		pjob->ji_wattr[JOB_ATR_mtime].at_flags |= ATR_VFLAG_MODCACHE;

	}

	/* don't save if SubJob unless FULLFORCE.  This is done by Windows    */
	/* Server when ready to run job since separate send_job program needs */
	/* needs to be able to read up job structure from disk, not sharing   */
	/* the memory structures                                              */
	if ((pjob->ji_qs.ji_svrflags & JOB_SVFLG_SubJob) &&
		(updatetype != SAVEJOB_FULLFORCE)) {
		pjob->ji_modified = 0;
		return 0;	/* don't save subjob */
	}

	if (pjob->ji_qs.ji_jsversion != JSVERSION) {
		/* version of job structure changed, force full write */
		pjob->ji_qs.ji_jsversion = JSVERSION;
		updatetype = SAVEJOB_FULLFORCE;
	}

	if (updatetype == SAVEJOB_QUICK) {

		openflags =  O_WRONLY | O_Sync;
		fds = open(namebuf1, openflags, pmode);
		if (fds < 0) {
			log_err(errno, "job_save", "error on open");
			return (-1);
		}
#ifdef WIN32
		secure_file(namebuf1, "Administrators",
			READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
		setmode(fds, O_BINARY);
#endif

		/* just write the "critical" base structure to the file */

		save_setup(fds);
		if ((save_struct((char *)&pjob->ji_qs, fixedsize) == 0) &&
			(save_struct((char *)&pjob->ji_extended, extndsize) == 0) &&
			(save_flush() == 0)) {
#ifdef WIN32
			/* since the open() POSIX call provided does not */
			/* have O_Sync for synchronous writes, the following */
			/* will force flushing things onto disk */
			if (_commit(fds) != 0) {
				log_err(errno, "job_save",
					"flushing file to disk failed!");
				(void)close(fds);
				return (-1);
			}
#endif
			(void)close(fds);
		} else {
			log_err(errno, "job_save", "error quickwrite");
			(void)close(fds);
			return (-1);
		}

	} else {

		/*
		 * write the whole structure to the file.
		 * For a update, this is done to a new file to protect the
		 * old against crashs.
		 * The file is written in four parts:
		 * (1) the job structure,
		 * (2) the extended area,
		 * (3) if a Array Job, the index tracking table
		 * (4) the attributes in the "encoded "external form, and last
		 * (5) the dependency list.
		 */
#ifndef PBS_MOM
		/*
		 * For an Array Job, we only update it to disk periodically,
		 * otherwise we would be spending way too much time writting.
		 */

		isarray = (pjob->ji_qs.ji_svrflags & JOB_SVFLG_ArrayJob);
		if (isarray) {
			if ((pjob->ji_modifyct > 0) &&
				(updatetype != SAVEJOB_FULLFORCE)) {
				pjob->ji_modifyct--;
				return 0;
			} else {
				/* reset count and do write this time */
				pjob->ji_modifyct = 600;
			}
		}
#endif

		(void)strcat(namebuf2, JOB_FILE_COPY);
		openflags =  O_CREAT | O_WRONLY | O_Sync;

#ifdef WIN32
		fix_perms2(namebuf2, namebuf1);
#endif

		if (updatetype == SAVEJOB_NEW)
			filename = namebuf1;
		else
			filename = namebuf2;

		fds = open(filename, openflags, pmode);
		if (fds < 0) {
			log_err(errno, "job_save",
				"error opening for full save");
			return (-1);
		}

#ifdef WIN32
		secure_file(filename, "Administrators",
			READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
		setmode(fds, O_BINARY);
#endif

		for (i=0; i<MAX_SAVE_TRIES; ++i) {
			redo = 0;	/* try to save twice */
			save_setup(fds);
			if (save_struct((char *)&pjob->ji_qs, fixedsize)
				!= 0) {
				redo++;
			} else if (save_struct((char *)&pjob->ji_extended,
				extndsize) != 0) {
				redo++;
#ifndef PBS_MOM
			} else if (isarray &&
				(save_struct((char *)pjob->ji_ajtrk,
				pjob->ji_ajtrk->tkm_size) != 0)) {
				redo++;
#endif
			} else if (save_attr_fs(job_attr_def, pjob->ji_wattr,
				(int)JOB_ATR_LAST) != 0) {
				redo++;
			} else if (save_flush() != 0) {
				redo++;
			}
			if (redo != 0) {
				if (lseek(fds, (off_t)0, SEEK_SET) < 0) {
					log_err(errno, "job_save", "error lseek");
				}
			} else
				break;
		}

#ifdef WIN32
		if (_commit(fds) != 0) {
			log_err(errno, "job_save",
				"flushing file to disk failed!");
			(void)close(fds);
			return (-1);
		}
#endif

		(void)close(fds);
		if (i >= MAX_SAVE_TRIES) {
			if ((updatetype == SAVEJOB_FULL) ||
				(updatetype == SAVEJOB_FULLFORCE))
				(void)unlink(namebuf2);
			return (-1);
		}

		if ((updatetype == SAVEJOB_FULL) ||
			(updatetype == SAVEJOB_FULLFORCE)) {
#ifdef WIN32
			if (MoveFileEx(namebuf2, namebuf1,
				MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH) == 0) {

				errno = GetLastError();
				sprintf(log_buffer, "MoveFileEx(%s,%s) failed!",
					namebuf2, namebuf1);
				log_err(errno, "job_save", log_buffer);
			}
			secure_file(namebuf1, "Administrators",
				READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
#else
			if (rename(namebuf2, namebuf1) == -1) {
				log_event(PBSEVENT_ERROR|PBSEVENT_SECURITY,
					PBS_EVENTCLASS_JOB, LOG_ERR,
					pjob->ji_qs.ji_jobid,
					"rename in job_save failed");
			}
#endif
		}
		pjob->ji_modified = 0;
	}
	return (0);
}
Exemple #9
0
int job_save(

  job *pjob,  /* pointer to job structure */
  int  updatetype) /* 0=quick, 1=full     */

  {
  int fds;
  int i;
  char namebuf1[MAXPATHLEN];
  char namebuf2[MAXPATHLEN];
  int openflags;
  int redo;

  strcpy(namebuf1, path_jobs); /* job directory path */
  strcat(namebuf1, pjob->ji_qs.ji_fileprefix);
  strcpy(namebuf2, namebuf1); /* setup for later */

#ifdef PBS_MOM
  strcat(namebuf1, JOB_FILE_SUFFIX);
#else

  if (pjob->ji_isparent == TRUE)
    {
    strcat(namebuf1, JOB_FILE_TMP_SUFFIX);
    }
  else
    {
    strcat(namebuf1, JOB_FILE_SUFFIX);
    }

#endif

  /* if ji_modified is set, ie an attribute changed, then update mtime */

  if (pjob->ji_modified)
    {
    pjob->ji_wattr[JOB_ATR_mtime].at_val.at_long = time_now;
    }

  if (updatetype == SAVEJOB_QUICK)
    {
    openflags = O_WRONLY | O_Sync;

    /* NOTE:  open, do not create */

    fds = open(namebuf1, openflags, 0600);

    if (fds < 0)
      {
      char tmpLine[1024];

      snprintf(tmpLine, sizeof(tmpLine), "cannot open file '%s' for job %s in state %s (%s)",
               namebuf1,
               pjob->ji_qs.ji_jobid,
               PJobSubState[MAX(0,pjob->ji_qs.ji_substate)],
               (updatetype == 0) ? "quick" : "full");

      log_err(errno, "job_save", tmpLine);

      /* FAILURE */

      return(-1);
      }

    /* just write the "critical" base structure to the file */

    while ((i = write(fds, (char *) & pjob->ji_qs, quicksize)) != (ssize_t)quicksize)
      {
      if ((i < 0) && (errno == EINTR))
        {
        /* retry the write */

        if (lseek(fds, (off_t)0, SEEK_SET) < 0)
          {
          log_err(errno, "job_save", "lseek");

          fsync(fds);
          close(fds);

          return(-1);
          }

        continue;
        }
      else
        {
        log_err(errno, "job_save", "quickwrite");

        fsync(fds);
        close(fds);

        /* FAILURE */

        return(-1);
        }
      }

    fsync(fds);
    close(fds);
    }
  else /* SAVEJOB_FULL, SAVEJOB_NEW, SAVEJOB_ARY */
    {
    /*
     * write the whole structure to the file.
     * For a update, this is done to a new file to protect the
     * old against crashs.
     * The file is written in four parts:
     * (1) the job structure,
     * (2) the attribtes in "encoded" form,
     * (3) the attributes in the "external" form, and last
     * (4) the dependency list.
     */

    strcat(namebuf2, JOB_FILE_COPY);

    openflags = O_CREAT | O_WRONLY | O_Sync;

    /* NOTE:  create file if required */

    if (updatetype == SAVEJOB_NEW)
      fds = open(namebuf1, openflags, 0600);
    else
      fds = open(namebuf2, openflags, 0600);

    if (fds < 0)
      {
      log_err(errno, "job_save", "open for full save");

      return(-1);
      }

    for (i = 0;i < MAX_SAVE_TRIES;++i)
      {
      redo = 0; /* try to save twice */

      save_setup(fds);

      if (save_struct((char *)&pjob->ji_qs, (size_t)quicksize) != 0)
        {
        redo++;
        }
      else if (save_attr(job_attr_def, pjob->ji_wattr, (int)JOB_ATR_LAST) != 0)
        {
        redo++;
        }

#ifdef PBS_MOM
      else if (save_tmsock(pjob) != 0)
        {
        redo++;
        }
      else if (save_roottask(pjob) != 0)
        {
        redo++;
        }
      else if (save_jobflags(pjob) != 0)
        {
        redo++;
        }

#endif  /* PBS_MOM */
      else if (save_flush() != 0)
        {
        redo++;
        }

      if (redo != 0)
        {
        if (lseek(fds, (off_t)0, SEEK_SET) < 0)
          {
          log_err(errno, "job_save", "full lseek");
          }
        }
      else
        {
        break;
        }
      }  /* END for (i) */

    fsync(fds);
    close(fds);

    if (i >= MAX_SAVE_TRIES)
      {
      if (updatetype == SAVEJOB_FULL)
        unlink(namebuf2);

      return(-1);
      }

    if (updatetype == SAVEJOB_FULL)
      {
      unlink(namebuf1);

      if (rename(namebuf2,namebuf1) != 0)
        {
        LOG_EVENT(
          PBSEVENT_ERROR | PBSEVENT_SECURITY,
          PBS_EVENTCLASS_JOB,
          pjob->ji_qs.ji_jobid,
          "Link in job_save failed");
        }
      }

    pjob->ji_modified = 0;
    }  /* END (updatetype == SAVEJOB_QUICK) */

  return(0);
  }  /* END job_save() */
Exemple #10
0
void process_serial_buffer()
{
//	int i;

//	printf("processing serial buffer\r\n");
//	for ( i=0; i < 15; i++ )
//	{
//		if ( rxbuff[i] )
//			printf("%02X ",rxbuff[i] & 0xff);
//		else
//		{
//			printf("\r\n");
//			break;
//		}
//	}

	switch( rxbuff[0] )
	{
	case 'b':
		if (rxbuff[1])
		{
			pid.deadband = atof(&rxbuff[1]);
			save_setup();
		}
		print_tuning();
		break;		

	case 'p':
		if (rxbuff[1])
		{
			pid.pgain = atof(&rxbuff[1]);
			save_setup();
		}
		print_tuning();
		break;		
	case 'i':
		if (rxbuff[1])
		{
			pid.igain = atof(&rxbuff[1]);
			pid.error_i = 0.0;	//reset integrator
			save_setup();
		}
		print_tuning();
		break;		
	case 'd':
		if (rxbuff[1])
		{
			pid.dgain = atof(&rxbuff[1]);
			save_setup();
		}
		print_tuning();
		break;		
	case '0':
		if (rxbuff[1])
		{
			pid.ff0gain = atof(&rxbuff[1]);
			save_setup();
		}
		print_tuning();
		break;		
	case '1':
		if (rxbuff[1])
		{
			pid.ff1gain = atof(&rxbuff[1]);
			save_setup();
		}
		print_tuning();
		break;		
	case 'm':
		if (rxbuff[1])
		{
			pid.maxoutput = atof(&rxbuff[1]);
			save_setup();
		}
		print_tuning();
		break;		

	case 'f':
		if (rxbuff[1])
		{
			pid.maxerror = atof(&rxbuff[1]);
			save_setup();
		}
		print_tuning();
		break;		

	case 'x':
		if (rxbuff[1])
		{
			pid.multiplier = (short)atof(&rxbuff[1]);
			if ( pid.multiplier < 1 ) pid.multiplier = 1;
			if ( pid.multiplier > 16 ) pid.multiplier = 16;
			save_setup();
		}
		print_tuning();
		break;		

    case 't':
		if (rxbuff[1])
		{
			pid.ticksperservo = (short)atof(&rxbuff[1]);
			if ( pid.ticksperservo < 2 ) pid.ticksperservo = 2;		// 200us/servo calc
			if ( pid.ticksperservo > 100 ) pid.ticksperservo = 100; // .1 sec/servo calc
			save_setup();
		}
		print_tuning();
		break;		


	case 'e':
		printf("\rencoder = 0x%04X = %d\r\n",POSCNT, POSCNT & 0xffff);
		break;	

	case 'l':
		print_tuning();
		break;

	case 's':
		printf("\rServo Loop Internal Calcs:\r\n");
		printf("command: %ld\r\n",pid.command);
		printf("feedback: %ld\r\n",pid.feedback);
		printf("error: %f\r\n",(double)pid.error);
		printf("error_i: %f\r\n",(double)pid.error_i);
		printf("error_d: %f\r\n",(double)pid.error_d);
		printf("output: %f\r\n",(double)pid.output);
		printf("limit_state: %d\r\n",(int)pid.limit_state);
		break;

	default:
		printf("\r\nUSAGE:\r\n");
		printf("p x.x set proportional gain\r\n");
        printf("i x.x set integral gain\r\n"); 
		printf("d x.x set differential gain\r\n"); 
        printf("0 x.x set FF0 gain\r\n"); 
		printf("1 x.x set FF1 gain\r\n"); 
		printf("b x.x set deadband\r\n");
		printf("m x.x set max output current(amps)\r\n"); 
		printf("f x.x set max error before drive faults(counts)\r\n");
		printf("x n   set pc command multiplier (1-16)\r\n");
        printf("t n   set # of 100us ticks/per servo calc(2-100)\r\n");
		printf("e print current encoder count\r\n"); 
		printf("l print current loop tuning values\r\n"); 
        printf("s print internal loop components\r\n");
		printf("? print this help\r\n");
	}


	// reset input buffer state
	rxrdy = 0;
	rxbuff[0] = 0;
	rxbuffptr = &rxbuff[0];
	putchar('>');
}
Exemple #11
0
int
job_save_fs(job *pjob, int updatetype)
{
	int	fds;
	int	i;
	char	*filename;
	char	namebuf1[MAXPATHLEN+1];
	char	namebuf2[MAXPATHLEN+1];
	int	openflags;
	int	redo;
	int	pmode;

#ifdef WIN32
	pmode = _S_IWRITE | _S_IREAD;
#else
	pmode = 0600;
#endif

	(void)strcpy(namebuf1, path_jobs);	/* job directory path */
	if (*pjob->ji_qs.ji_fileprefix != '\0')
		(void)strcat(namebuf1, pjob->ji_qs.ji_fileprefix);
	else
		(void)strcat(namebuf1, pjob->ji_qs.ji_jobid);
	(void)strcpy(namebuf2, namebuf1);	/* setup for later */
	(void)strcat(namebuf1, JOB_FILE_SUFFIX);

	/* if ji_modified is set, ie an attribute changed, then update mtime */

	if (pjob->ji_modified) {
		pjob->ji_wattr[JOB_ATR_mtime].at_val.at_long = time_now;
		pjob->ji_wattr[JOB_ATR_mtime].at_flags |= ATR_VFLAG_MODCACHE;

	}

	if (pjob->ji_qs.ji_jsversion != JSVERSION) {
		/* version of job structure changed, force full write */
		pjob->ji_qs.ji_jsversion = JSVERSION;
		updatetype = SAVEJOB_FULLFORCE;
	}

	if (updatetype == SAVEJOB_QUICK) {

		openflags =  O_WRONLY;
		fds = open(namebuf1, openflags, pmode);
		if (fds < 0) {
			log_err(errno, "job_save", "error on open");
			return (-1);
		}
#ifdef WIN32
		secure_file(namebuf1, "Administrators",
			READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
		setmode(fds, O_BINARY);
#endif

		/* just write the "critical" base structure to the file */

		save_setup(fds);
		if ((save_struct((char *)&pjob->ji_qs, fixedsize) == 0) &&
			(save_struct((char *)&pjob->ji_extended, extndsize) == 0) &&
			(save_flush() == 0)) {
			(void)close(fds);
		} else {
			log_err(errno, "job_save", "error quickwrite");
			(void)close(fds);
			return (-1);
		}

	} else {

		/*
		 * write the whole structure to the file.
		 * For a update, this is done to a new file to protect the
		 * old against crashs.
		 * The file is written in four parts:
		 * (1) the job structure,
		 * (2) the extended area,
		 * (3) if a Array Job, the index tracking table
		 * (4) the attributes in the "encoded "external form, and last
		 * (5) the dependency list.
		 */

		(void)strcat(namebuf2, JOB_FILE_COPY);
		openflags =  O_CREAT | O_WRONLY;

#ifdef WIN32
		fix_perms2(namebuf2, namebuf1);
#endif

		if (updatetype == SAVEJOB_NEW)
			filename = namebuf1;
		else
			filename = namebuf2;

		fds = open(filename, openflags, pmode);
		if (fds < 0) {
			log_err(errno, "job_save",
				"error opening for full save");
			return (-1);
		}

#ifdef WIN32
		secure_file(filename, "Administrators",
			READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
		setmode(fds, O_BINARY);
#endif

		for (i=0; i<MAX_SAVE_TRIES; ++i) {
			redo = 0;	/* try to save twice */
			save_setup(fds);
			if (save_struct((char *)&pjob->ji_qs, fixedsize)
				!= 0) {
				redo++;
			} else if (save_struct((char *)&pjob->ji_extended,
				extndsize) != 0) {
				redo++;
#ifndef PBS_MOM
			} else if ((pjob->ji_qs.ji_svrflags & JOB_SVFLG_ArrayJob) &&
				(save_struct((char *)pjob->ji_ajtrk,
				pjob->ji_ajtrk->tkm_size) != 0)) {
				redo++;
#endif
			} else if (save_attr_fs(job_attr_def, pjob->ji_wattr,
				(int)JOB_ATR_LAST) != 0) {
				redo++;
			} else if (save_flush() != 0) {
				redo++;
			}
			if (redo != 0) {
				if (lseek(fds, (off_t)0, SEEK_SET) < 0) {
					log_err(errno, "job_save", "error lseek");
				}
			} else
				break;
		}


		(void)close(fds);
		if (i >= MAX_SAVE_TRIES) {
			if ((updatetype == SAVEJOB_FULL) ||
				(updatetype == SAVEJOB_FULLFORCE))
				(void)unlink(namebuf2);
			return (-1);
		}

		if ((updatetype == SAVEJOB_FULL) ||
			(updatetype == SAVEJOB_FULLFORCE)) {
#ifdef WIN32
			if (MoveFileEx(namebuf2, namebuf1,
				MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH) == 0) {

				errno = GetLastError();
				sprintf(log_buffer, "MoveFileEx(%s,%s) failed!",
					namebuf2, namebuf1);
				log_err(errno, "job_save", log_buffer);
			}
			secure_file(namebuf1, "Administrators",
				READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
#else
			if (rename(namebuf2, namebuf1) == -1) {
				log_event(PBSEVENT_ERROR|PBSEVENT_SECURITY,
					PBS_EVENTCLASS_JOB, LOG_ERR,
					pjob->ji_qs.ji_jobid,
					"rename in job_save failed");
			}
#endif
		}
		pjob->ji_modified = 0;
	}
	return (0);
}
Exemple #12
0
void
sig_alrm (int notUsed)
{
	alarmed = 1;
	alarm (AIL);
	check_dbtimers ();			/* timers :) */
	AIL8 += AIL;

	if (quiz_halt == 1)
	{
		AIL13++;
		if (AIL13 >= QUIZ_REPEAT_TIMER)
		{
			AIL13 = 0;
			quiz_halt = 0;
		}
	}

	if (quiz_answer == 1 && quiz_halt == 0)
	{
		if (quiz_timer >= QUIZ_TIMER)
		{
			quiz_answer = 0;
			quiz_timer = 0;
			quiz_halt = 1;
			run_quiz_answer ();
		}
		else
			quiz_timer++;
	}
	if (AIL8 >= SEND_DELAY)
	{
		AIL8 = 0;
		Send ();
	}
	LastInput += AIL;
	if (LastInput >= 500)
	{
		LastInput = 0;
#if CHECK_STONED == 1
		L088 (BS);
#ifdef	WIN32
		printf ("\nNo response from %s in 5 mins, reconnecting...\n", BS);
#endif
		prepare_bot ();
		register_bot ();
#endif
	}
	AIL10 += AIL;
	if (AIL10 >= 900)
	{							/* 15 mins */
		AIL10 = 0;
		if (MARK_CHANGE == 1)
		{
			MARK_CHANGE = 0;
			save_setup ();		/* save settings */
		}
	}
	AIL666 += AIL;
	if (AIL666 >= 60)
	{							/* 60 sec timer */
		AIL666 = 0;
		S ("PING :%s\n", BS);

	}
	AIL9 += AIL;
	if (AIL9 >= 30)
	{
		AIL9 = 0;
		if (stricmp (s_Mynick, Mynick) != 0)
		{
			S ("NICK %s\n", s_Mynick);
			strncpy (Mynick, s_Mynick, sizeof (Mynick));
			snprintf (NICK_COMMA, sizeof (NICK_COMMA), "%s,", Mynick);
			snprintf (COLON_NICK, sizeof (COLON_NICK), "%s:", Mynick);
			snprintf (BCOLON_NICK, sizeof (BCOLON_NICK), "%s\2:\2", Mynick);
		}
	}
	if (Sleep_Toggle == 1)
	{
		AIL4 += AIL;
		if (AIL4 >= Sleep_Time)
		{
			Sleep_Toggle = 0;
			AIL4 = 0;
			L089 (sleep_chan);
		}
	}
	AIL2 += AIL;
	AIL3 += AIL;
#ifdef	RANDOM_STUFF
	Rand_Idle++;
	if (RAND_IDLE <= Rand_Idle)
	{
		Rand_Idle = 0;
		do_random_stuff ();
		get_rand_stuff_time ();
	}
	Rand_Stuff -= AIL;
	if (Rand_Stuff <= 0)
	{
		if (Sleep_Toggle != 1)
			do_random_stuff ();
		get_rand_stuff_time ();
	}
#endif
	if (AIL3 >= AUTOTOPIC_TIME)
	{
		AIL3 = 0;
		do_autotopics ();
	}
	AIL5 += AIL;
	if (AIL5 >= 600)
	{
#ifdef	ANTI_IDLE
		S ("PRIVMSG ! :\2\n");
#endif
		AIL5 = 0;
	}
	if (AIL2 >= 300)
	{
		AIL2 = 0;
#if STATUS == 1
		S ("LUSERS\n");
#endif
		S ("MODE %s %s\n", Mynick, DEFAULT_UMODE);
		S ("JOIN %s\n", CHAN);
		reset_ ();
		save_changes ();

#if PERFORM_TIMER == 1
                run_perform ();
#endif

	}
}
Exemple #13
0
int
que_save_fs(pbs_queue	*pque)
{
	int	fds;
	int	i;
	char	namebuf1[MAXPATHLEN];
	char	namebuf2[MAXPATHLEN];

	(void)strcpy(namebuf1, path_queues);
	(void)strcat(namebuf1, pque->qu_qs.qu_name);
	(void)strcpy(namebuf2, namebuf1);
	(void)strcat(namebuf2, ".new");

#ifdef WIN32
	fix_perms2(namebuf2, namebuf1);
#endif

	fds = open(namebuf2, O_CREAT | O_WRONLY | O_Sync, 0600);
	if (fds < 0) {
		sprintf(log_buffer, "error opening %s", namebuf2);
		log_err(errno, __func__, log_buffer);
		return (-1);
	}
#ifdef WIN32
	secure_file(namebuf2, "Administrators", READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
	setmode(fds, O_BINARY);
#endif

	/* set up save buffering system */

	save_setup(fds);

	/* save basic queue structure (fixed length stuff) */

	if (save_struct((char *)&pque->qu_qs, sizeof(struct queuefix)) != 0) {
		log_err(-1, __func__, "save_struct failed");
		(void)close(fds);
		return (-1);
	}

	/* save queue attributes  */

	if (save_attr_fs(que_attr_def, pque->qu_attr, (int)QA_ATR_LAST) != 0) {
		log_err(-1, __func__, "save_attr failed");
		(void)close(fds);
		return (-1);
	}

	if (save_flush() != 0) {	/* flush the save buffer */
		log_err(-1, __func__, "save_flush failed");
		(void)close(fds);
		return (-1);
	}

#ifdef WIN32
	if (_commit(fds) != 0) {
		log_err(errno, __func__, "flush queue file to disk failed!");
		close(fds);
		return (-1);
	}
#endif
	(void)close(fds);

#ifdef WIN32
	if (MoveFileEx(namebuf2, namebuf1,
		MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) == 0) {

		errno = GetLastError();
		sprintf(log_buffer, "MoveFileEx(%s, %s) failed!",
			namebuf2, namebuf1);
		log_err(errno, __func__, log_buffer);
	}
	secure_file(namebuf1, "Administrators",
		READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
#else
	if (rename(namebuf2, namebuf1) < 0)
		log_err(errno, __func__, "unable to rename queue name");
#endif

	/*
	 * now search queue's attributes for access control lists,
	 * they are saved separately in their own file:
	 * ../priv/(attr name)/(queue name)
	 */

	for (i=0; i < (int)QA_ATR_LAST; i++) {
		if (pque->qu_attr[i].at_type == ATR_TYPE_ACL) {
			save_acl(&pque->qu_attr[i], &que_attr_def[i],
				que_attr_def[i].at_name, pque->qu_qs.qu_name);
		}
	}

	return (0);
}
Exemple #14
0
int svr_save(

  struct server *ps,
  int            mode)

  {
#ifndef SERVER_XML
  static char *this_function_name = "svr_save";
  int i;
  int sdb;
  int save_acl(attribute *, attribute_def *, char *, char *);
#endif /* ndef SERVER_XML */

  /* save the server in xml only if configured */
#ifdef SERVER_XML
      return(svr_save_xml(ps,mode));
#endif /* def SERVER_XML */

#ifndef SERVER_XML
  if (mode == SVR_SAVE_QUICK)
    {
    sdb = open(path_svrdb, O_WRONLY | O_CREAT | O_Sync, 0600);

    if (sdb < 0)
      {
      log_err(errno, this_function_name, msg_svdbopen);

      return(-1);
      }

    while ((i = write(
                  sdb,
                  &ps->sv_qs,
                  sizeof(struct server_qs))) != sizeof(struct server_qs))
      {
      if ((i == -1) && (errno == EINTR))
        continue;

      log_err(errno, this_function_name, msg_svdbnosv);

      return(-1);
      }

    close(sdb);
    }
  else
    {
    /* SVR_SAVE_FULL Save */

    sdb = open(path_svrdb_new, O_WRONLY | O_CREAT | O_Sync, 0600);

    if (sdb < 0)
      {
      log_err(errno, this_function_name, msg_svdbopen);

      return(-1);
      }

    ps->sv_qs.sv_savetm = time_now;

    save_setup(sdb);

    if (save_struct((char *)&ps->sv_qs, sizeof(struct server_qs)) != 0)
      {
      snprintf(log_buffer, 1024, "cannot save data into server db, errno=%d (%s)",
               errno,
               pbs_strerror(errno));

      log_err(errno, this_function_name, log_buffer);

      close(sdb);

      return(-1);
      }

    if (save_attr(svr_attr_def, ps->sv_attr, (int)SRV_ATR_LAST) != 0)
      {
      close(sdb);

      return(-1);
      }

    if (save_flush() != 0)
      {
      close(sdb);

      return(-1);
      }

    /* new db successfully created, remove original db */

    close(sdb);

    unlink(path_svrdb);

    if (link(path_svrdb_new, path_svrdb) == -1)
      {
      snprintf(log_buffer, 1024, "cannot move new database to default database location, errno=%d (%s)",
               errno,
               pbs_strerror(errno));

      log_err(errno, this_function_name, log_buffer);
      }
    else
      {
      unlink(path_svrdb_new);
      }

    /* save the server acls to their own files: */
    /*  priv/svracl/(attr name)   */

    for (i = 0;i < SRV_ATR_LAST;i++)
      {
      if (ps->sv_attr[i].at_type == ATR_TYPE_ACL)
        save_acl(&ps->sv_attr[i], &svr_attr_def[i],
                 PBS_SVRACL, svr_attr_def[i].at_name);
      }
    }    /* END else (mode == SVR_SAVE_QUICK) */

  return(0);
#endif /* ndef SERVER_XML */
  }  /* END svr_save() */