Added the small support driver for the picoscope
Added a deploysics script The Tcl data and time functions were moved to the SICS kernel
This commit is contained in:
2
make_gen
2
make_gen
@ -24,7 +24,7 @@ OBJ=psi.o buffer.o ruli.o sps.o pimotor.o \
|
|||||||
ritastorage.o poldizug.o el737hpdrivsps.o \
|
ritastorage.o poldizug.o el737hpdrivsps.o \
|
||||||
rebin.o sanslirebin.o lmd200.o slsvme.o julprot.o sinqhttpprot.o \
|
rebin.o sanslirebin.o lmd200.o slsvme.o julprot.o sinqhttpprot.o \
|
||||||
pfeifferprot.o termprot.o phytron.o autowin.o eigera2.o \
|
pfeifferprot.o termprot.o phytron.o autowin.o eigera2.o \
|
||||||
tclClock.o tclDate.o tclUnixTime.o jvlprot.o \
|
jvlprot.o \
|
||||||
eigermono.o sputterprot.o zwickroll.o astriumnet.o poldifold.o \
|
eigermono.o sputterprot.o zwickroll.o astriumnet.o poldifold.o \
|
||||||
epicsadapter.o
|
epicsadapter.o
|
||||||
|
|
||||||
|
2
pardef.c
2
pardef.c
@ -387,7 +387,7 @@ static int ParOutError(SConnection * con, ParData * o)
|
|||||||
o->name, ctx->thisPar);
|
o->name, ctx->thisPar);
|
||||||
break;
|
break;
|
||||||
case ILLNUM:
|
case ILLNUM:
|
||||||
SCPrintf(con, eError, "ERROR: illegal value", o->name, ctx->valueArg);
|
SCPrintf(con, eError, "ERROR: illegal value %s %s", o->name, ctx->valueArg);
|
||||||
break;
|
break;
|
||||||
case ILLARGC:
|
case ILLARGC:
|
||||||
SCPrintf(con, eError, "ERROR: illegal number of arguments for %s %s",
|
SCPrintf(con, eError, "ERROR: illegal number of arguments for %s %s",
|
||||||
|
410
tclClock.c
410
tclClock.c
@ -1,410 +0,0 @@
|
|||||||
/*
|
|
||||||
* tclClock.c --
|
|
||||||
*
|
|
||||||
* Contains the time and date related commands. This code
|
|
||||||
* is derived from the time and date facilities of TclX,
|
|
||||||
* by Mark Diekhans and Karl Lehenbauer.
|
|
||||||
*
|
|
||||||
* Copyright 1991-1995 Karl Lehenbauer and Mark Diekhans.
|
|
||||||
* Copyright (c) 1995 Sun Microsystems, Inc.
|
|
||||||
*
|
|
||||||
* See the file "license.terms" for information on usage and redistribution
|
|
||||||
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
||||||
*
|
|
||||||
* RCS: @(#) $Id: tclClock.c,v 1.1 2012/03/29 08:45:52 koennecke Exp $
|
|
||||||
*
|
|
||||||
* Slightly modified for inclusion into SICS, Mark Koennecke, February 2012
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <tcl.h>
|
|
||||||
#include <tcl-private/generic/tclInt.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <tcl-private/generic/tclPort.h>
|
|
||||||
|
|
||||||
typedef long TIMEZONE_t;
|
|
||||||
/*
|
|
||||||
* from tclDate.c
|
|
||||||
*/
|
|
||||||
int TclGetDate(char *p, Tcl_WideInt now, long zone, Tcl_WideInt *timePtr);
|
|
||||||
/*
|
|
||||||
* from tclUnixDate.c
|
|
||||||
*/
|
|
||||||
size_t TclpStrftime(char *s, size_t maxsize, CONST char *format, CONST struct tm *t, int useGMT);
|
|
||||||
struct tm * TclppGetDate(time_t time, int useGMT);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The date parsing stuff uses lexx and has tons o statics.
|
|
||||||
*/
|
|
||||||
|
|
||||||
TCL_DECLARE_MUTEX(clockMutex)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Function prototypes for local procedures in this file:
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int FormatClock _ANSI_ARGS_((Tcl_Interp *interp,
|
|
||||||
Tcl_WideInt clockVal, int useGMT,
|
|
||||||
char *format));
|
|
||||||
|
|
||||||
/*
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Tcl_ClockObjCmd --
|
|
||||||
*
|
|
||||||
* This procedure is invoked to process the "clock" Tcl command.
|
|
||||||
* See the user documentation for details on what it does.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* A standard Tcl result.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* See the user documentation.
|
|
||||||
*
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
int
|
|
||||||
Tcl_ClockObjCmd (client, interp, objc, objv)
|
|
||||||
ClientData client; /* Not used. */
|
|
||||||
Tcl_Interp *interp; /* Current interpreter. */
|
|
||||||
int objc; /* Number of arguments. */
|
|
||||||
Tcl_Obj *CONST objv[]; /* Argument values. */
|
|
||||||
{
|
|
||||||
Tcl_Obj *resultPtr;
|
|
||||||
int index;
|
|
||||||
Tcl_Obj *CONST *objPtr;
|
|
||||||
int useGMT = 0;
|
|
||||||
char *format = "%a %b %d %X %Z %Y";
|
|
||||||
int dummy;
|
|
||||||
Tcl_WideInt baseClock, clockVal;
|
|
||||||
long zone;
|
|
||||||
Tcl_Obj *baseObjPtr = NULL;
|
|
||||||
char *scanStr;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
static CONST char *switches[] =
|
|
||||||
{"clicks", "format", "scan", "seconds", (char *) NULL};
|
|
||||||
enum command { COMMAND_CLICKS, COMMAND_FORMAT, COMMAND_SCAN,
|
|
||||||
COMMAND_SECONDS
|
|
||||||
};
|
|
||||||
static CONST char *formatSwitches[] = {"-format", "-gmt", (char *) NULL};
|
|
||||||
static CONST char *scanSwitches[] = {"-base", "-gmt", (char *) NULL};
|
|
||||||
|
|
||||||
resultPtr = Tcl_GetObjResult(interp);
|
|
||||||
if (objc < 2) {
|
|
||||||
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Tcl_GetIndexFromObj(interp, objv[1], switches, "option", 0, &index)
|
|
||||||
!= TCL_OK) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
switch ((enum command) index) {
|
|
||||||
case COMMAND_CLICKS: { /* clicks */
|
|
||||||
int forceMilli = 0;
|
|
||||||
|
|
||||||
if (objc == 3) {
|
|
||||||
format = Tcl_GetStringFromObj(objv[2], &n);
|
|
||||||
if ( ( n >= 2 )
|
|
||||||
&& ( strncmp( format, "-milliseconds",
|
|
||||||
(unsigned int) n) == 0 ) ) {
|
|
||||||
forceMilli = 1;
|
|
||||||
} else {
|
|
||||||
Tcl_AppendStringsToObj(resultPtr,
|
|
||||||
"bad switch \"", format,
|
|
||||||
"\": must be -milliseconds", (char *) NULL);
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
} else if (objc != 2) {
|
|
||||||
Tcl_WrongNumArgs(interp, 2, objv, "?-milliseconds?");
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
if (forceMilli) {
|
|
||||||
/*
|
|
||||||
* We can enforce at least millisecond granularity
|
|
||||||
*/
|
|
||||||
Tcl_Time time;
|
|
||||||
Tcl_GetTime(&time);
|
|
||||||
Tcl_SetLongObj(resultPtr,
|
|
||||||
(long) (time.sec*1000 + time.usec/1000));
|
|
||||||
} else {
|
|
||||||
Tcl_SetLongObj(resultPtr, (long) TclpGetClicks());
|
|
||||||
}
|
|
||||||
return TCL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
case COMMAND_FORMAT: /* format */
|
|
||||||
if ((objc < 3) || (objc > 7)) {
|
|
||||||
wrongFmtArgs:
|
|
||||||
Tcl_WrongNumArgs(interp, 2, objv,
|
|
||||||
"clockval ?-format string? ?-gmt boolean?");
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Tcl_GetWideIntFromObj(interp, objv[2], &clockVal)
|
|
||||||
!= TCL_OK) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
objPtr = objv+3;
|
|
||||||
objc -= 3;
|
|
||||||
while (objc > 1) {
|
|
||||||
if (Tcl_GetIndexFromObj(interp, objPtr[0], formatSwitches,
|
|
||||||
"switch", 0, &index) != TCL_OK) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
switch (index) {
|
|
||||||
case 0: /* -format */
|
|
||||||
format = Tcl_GetStringFromObj(objPtr[1], &dummy);
|
|
||||||
break;
|
|
||||||
case 1: /* -gmt */
|
|
||||||
if (Tcl_GetBooleanFromObj(interp, objPtr[1],
|
|
||||||
&useGMT) != TCL_OK) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
objPtr += 2;
|
|
||||||
objc -= 2;
|
|
||||||
}
|
|
||||||
if (objc != 0) {
|
|
||||||
goto wrongFmtArgs;
|
|
||||||
}
|
|
||||||
return FormatClock(interp, clockVal, useGMT,
|
|
||||||
format);
|
|
||||||
|
|
||||||
case COMMAND_SCAN: /* scan */
|
|
||||||
if ((objc < 3) || (objc > 7)) {
|
|
||||||
wrongScanArgs:
|
|
||||||
Tcl_WrongNumArgs(interp, 2, objv,
|
|
||||||
"dateString ?-base clockValue? ?-gmt boolean?");
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
objPtr = objv+3;
|
|
||||||
objc -= 3;
|
|
||||||
while (objc > 1) {
|
|
||||||
if (Tcl_GetIndexFromObj(interp, objPtr[0], scanSwitches,
|
|
||||||
"switch", 0, &index) != TCL_OK) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
switch (index) {
|
|
||||||
case 0: /* -base */
|
|
||||||
baseObjPtr = objPtr[1];
|
|
||||||
break;
|
|
||||||
case 1: /* -gmt */
|
|
||||||
if (Tcl_GetBooleanFromObj(interp, objPtr[1],
|
|
||||||
&useGMT) != TCL_OK) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
objPtr += 2;
|
|
||||||
objc -= 2;
|
|
||||||
}
|
|
||||||
if (objc != 0) {
|
|
||||||
goto wrongScanArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (baseObjPtr != NULL) {
|
|
||||||
if (Tcl_GetWideIntFromObj(interp, baseObjPtr,
|
|
||||||
&baseClock) != TCL_OK) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
baseClock = TclpGetSeconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useGMT) {
|
|
||||||
zone = -50000; /* Force GMT */
|
|
||||||
} else {
|
|
||||||
zone = TclpGetTimeZone(baseClock);
|
|
||||||
}
|
|
||||||
|
|
||||||
scanStr = Tcl_GetStringFromObj(objv[2], &dummy);
|
|
||||||
Tcl_MutexLock(&clockMutex);
|
|
||||||
if (TclGetDate(scanStr, baseClock, zone,
|
|
||||||
&clockVal) < 0) {
|
|
||||||
Tcl_MutexUnlock(&clockMutex);
|
|
||||||
Tcl_AppendStringsToObj(resultPtr,
|
|
||||||
"unable to convert date-time string \"",
|
|
||||||
scanStr, "\"", (char *) NULL);
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
Tcl_MutexUnlock(&clockMutex);
|
|
||||||
|
|
||||||
Tcl_SetWideIntObj(resultPtr, clockVal);
|
|
||||||
return TCL_OK;
|
|
||||||
|
|
||||||
case COMMAND_SECONDS: /* seconds */
|
|
||||||
if (objc != 2) {
|
|
||||||
Tcl_WrongNumArgs(interp, 2, objv, NULL);
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
Tcl_SetLongObj(resultPtr, (long) TclpGetSeconds());
|
|
||||||
return TCL_OK;
|
|
||||||
default:
|
|
||||||
return TCL_ERROR; /* Should never be reached. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*-----------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* FormatClock --
|
|
||||||
*
|
|
||||||
* Formats a time value based on seconds into a human readable
|
|
||||||
* string.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* Standard Tcl result.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
*-----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int
|
|
||||||
FormatClock(interp, clockVal, useGMT, format)
|
|
||||||
Tcl_Interp *interp; /* Current interpreter. */
|
|
||||||
Tcl_WideInt clockVal; /* Time in seconds. */
|
|
||||||
int useGMT; /* Boolean */
|
|
||||||
char *format; /* Format string */
|
|
||||||
{
|
|
||||||
struct tm *timeDataPtr;
|
|
||||||
Tcl_DString buffer, uniBuffer;
|
|
||||||
int bufSize;
|
|
||||||
char *p;
|
|
||||||
int result;
|
|
||||||
time_t tclockVal;
|
|
||||||
#if !defined(HAVE_TM_ZONE) && !defined(WIN32)
|
|
||||||
TIMEZONE_t savedTimeZone = 0; /* lint. */
|
|
||||||
char *savedTZEnv = NULL; /* lint. */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_TZSET
|
|
||||||
/*
|
|
||||||
* Some systems forgot to call tzset in localtime, make sure its done.
|
|
||||||
*/
|
|
||||||
static int calledTzset = 0;
|
|
||||||
|
|
||||||
Tcl_MutexLock(&clockMutex);
|
|
||||||
if (!calledTzset) {
|
|
||||||
tzset();
|
|
||||||
calledTzset = 1;
|
|
||||||
}
|
|
||||||
Tcl_MutexUnlock(&clockMutex);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the user gave us -format "", just return now
|
|
||||||
*/
|
|
||||||
if (*format == '\0') {
|
|
||||||
return TCL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined(HAVE_TM_ZONE) && !defined(WIN32)
|
|
||||||
/*
|
|
||||||
* This is a kludge for systems not having the timezone string in
|
|
||||||
* struct tm. No matter what was specified, they use the local
|
|
||||||
* timezone string. Since this kludge requires fiddling with the
|
|
||||||
* TZ environment variable, it will mess up if done on multiple
|
|
||||||
* threads at once. Protect it with a the clock mutex.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Tcl_MutexLock( &clockMutex );
|
|
||||||
if (useGMT) {
|
|
||||||
CONST char *varValue;
|
|
||||||
|
|
||||||
varValue = Tcl_GetVar2(interp, "env", "TZ", TCL_GLOBAL_ONLY);
|
|
||||||
if (varValue != NULL) {
|
|
||||||
savedTZEnv = strcpy(ckalloc(strlen(varValue) + 1), varValue);
|
|
||||||
} else {
|
|
||||||
savedTZEnv = NULL;
|
|
||||||
}
|
|
||||||
Tcl_SetVar2(interp, "env", "TZ", "GMT0", TCL_GLOBAL_ONLY);
|
|
||||||
savedTimeZone = timezone;
|
|
||||||
timezone = 0;
|
|
||||||
tzset();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
tclockVal = (time_t) clockVal;
|
|
||||||
timeDataPtr = TclppGetDate(tclockVal, useGMT);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Make a guess at the upper limit on the substituted string size
|
|
||||||
* based on the number of percents in the string.
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (bufSize = 1, p = format; *p != '\0'; p++) {
|
|
||||||
if (*p == '%') {
|
|
||||||
bufSize += 40;
|
|
||||||
if (p[1] == 'c') {
|
|
||||||
bufSize += 226;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bufSize++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Tcl_DStringInit(&uniBuffer);
|
|
||||||
Tcl_UtfToExternalDString(NULL, format, -1, &uniBuffer);
|
|
||||||
Tcl_DStringInit(&buffer);
|
|
||||||
Tcl_DStringSetLength(&buffer, bufSize);
|
|
||||||
|
|
||||||
/* If we haven't locked the clock mutex up above, lock it now. */
|
|
||||||
|
|
||||||
#if defined(HAVE_TM_ZONE) || defined(WIN32)
|
|
||||||
Tcl_MutexLock(&clockMutex);
|
|
||||||
#endif
|
|
||||||
result = TclpStrftime(buffer.string, (unsigned int) bufSize,
|
|
||||||
Tcl_DStringValue(&uniBuffer), timeDataPtr, useGMT);
|
|
||||||
#if defined(HAVE_TM_ZONE) || defined(WIN32)
|
|
||||||
Tcl_MutexUnlock(&clockMutex);
|
|
||||||
#endif
|
|
||||||
Tcl_DStringFree(&uniBuffer);
|
|
||||||
|
|
||||||
#if !defined(HAVE_TM_ZONE) && !defined(WIN32)
|
|
||||||
if (useGMT) {
|
|
||||||
if (savedTZEnv != NULL) {
|
|
||||||
Tcl_SetVar2(interp, "env", "TZ", savedTZEnv, TCL_GLOBAL_ONLY);
|
|
||||||
ckfree(savedTZEnv);
|
|
||||||
} else {
|
|
||||||
Tcl_UnsetVar2(interp, "env", "TZ", TCL_GLOBAL_ONLY);
|
|
||||||
}
|
|
||||||
timezone = savedTimeZone;
|
|
||||||
tzset();
|
|
||||||
}
|
|
||||||
Tcl_MutexUnlock( &clockMutex );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
/*
|
|
||||||
* A zero return is the error case (can also mean the strftime
|
|
||||||
* didn't get enough space to write into). We know it doesn't
|
|
||||||
* mean that we wrote zero chars because the check for an empty
|
|
||||||
* format string is above.
|
|
||||||
*/
|
|
||||||
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
|
|
||||||
"bad format string \"", format, "\"", (char *) NULL);
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert the time to UTF from external encoding [Bug: 3345]
|
|
||||||
*/
|
|
||||||
Tcl_DStringInit(&uniBuffer);
|
|
||||||
Tcl_ExternalToUtfDString(NULL, buffer.string, -1, &uniBuffer);
|
|
||||||
|
|
||||||
Tcl_SetStringObj(Tcl_GetObjResult(interp), uniBuffer.string, -1);
|
|
||||||
|
|
||||||
Tcl_DStringFree(&uniBuffer);
|
|
||||||
Tcl_DStringFree(&buffer);
|
|
||||||
return TCL_OK;
|
|
||||||
}
|
|
||||||
|
|
493
tclUnixTime.c
493
tclUnixTime.c
@ -1,493 +0,0 @@
|
|||||||
/*
|
|
||||||
* tclUnixTime.c --
|
|
||||||
*
|
|
||||||
* Contains Unix specific versions of Tcl functions that
|
|
||||||
* obtain time values from the operating system.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1995 Sun Microsystems, Inc.
|
|
||||||
*
|
|
||||||
* See the file "license.terms" for information on usage and redistribution
|
|
||||||
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
||||||
*
|
|
||||||
* RCS: @(#) $Id: tclUnixTime.c,v 1.1 2012/03/29 08:45:52 koennecke Exp $
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <tcl-private/generic/tclInt.h>
|
|
||||||
#include <tcl-private/generic/tclPort.h>
|
|
||||||
#include <locale.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#define TM_YEAR_BASE 1900
|
|
||||||
#define IsLeapYear(x) ((x % 4 == 0) && (x % 100 != 0 || x % 400 == 0))
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TclpGetDate is coded to return a pointer to a 'struct tm'. For
|
|
||||||
* thread safety, this structure must be in thread-specific data.
|
|
||||||
* The 'tmKey' variable is the key to this buffer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static Tcl_ThreadDataKey tmKey;
|
|
||||||
typedef struct ThreadSpecificData {
|
|
||||||
struct tm gmtime_buf;
|
|
||||||
struct tm localtime_buf;
|
|
||||||
} ThreadSpecificData;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If we fall back on the thread-unsafe versions of gmtime and localtime,
|
|
||||||
* use this mutex to try to protect them.
|
|
||||||
*/
|
|
||||||
|
|
||||||
TCL_DECLARE_MUTEX(tmMutex)
|
|
||||||
|
|
||||||
static char* lastTZ = NULL; /* Holds the last setting of the
|
|
||||||
* TZ environment variable, or an
|
|
||||||
* empty string if the variable was
|
|
||||||
* not set. */
|
|
||||||
|
|
||||||
/* Static functions declared in this file */
|
|
||||||
|
|
||||||
static void SetTZIfNecessary _ANSI_ARGS_((void));
|
|
||||||
static void CleanupMemory _ANSI_ARGS_((ClientData));
|
|
||||||
|
|
||||||
/*
|
|
||||||
*-----------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* TclpGetSeconds --
|
|
||||||
*
|
|
||||||
* This procedure returns the number of seconds from the epoch. On
|
|
||||||
* most Unix systems the epoch is Midnight Jan 1, 1970 GMT.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* Number of seconds from the epoch.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
*-----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned long
|
|
||||||
TclpGetSeconds()
|
|
||||||
{
|
|
||||||
return time((time_t *) NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*-----------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* TclpGetClicks --
|
|
||||||
*
|
|
||||||
* This procedure returns a value that represents the highest resolution
|
|
||||||
* clock available on the system. There are no garantees on what the
|
|
||||||
* resolution will be. In Tcl we will call this value a "click". The
|
|
||||||
* start time is also system dependant.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* Number of clicks from some start time.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
*-----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned long
|
|
||||||
TclpGetClicks()
|
|
||||||
{
|
|
||||||
unsigned long now;
|
|
||||||
#ifdef NO_GETTOD
|
|
||||||
struct tms dummy;
|
|
||||||
#else
|
|
||||||
struct timeval date;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef NO_GETTOD
|
|
||||||
now = (unsigned long) times(&dummy);
|
|
||||||
#else
|
|
||||||
gettimeofday(&date, NULL);
|
|
||||||
now = date.tv_sec*1000000 + date.tv_usec;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return now;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* TclpGetTimeZone --
|
|
||||||
*
|
|
||||||
* Determines the current timezone. The method varies wildly
|
|
||||||
* between different platform implementations, so its hidden in
|
|
||||||
* this function.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* The return value is the local time zone, measured in
|
|
||||||
* minutes away from GMT (-ve for east, +ve for west).
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
int
|
|
||||||
TclpGetTimeZone (currentTime)
|
|
||||||
unsigned long currentTime;
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* We prefer first to use the time zone in "struct tm" if the
|
|
||||||
* structure contains such a member. Following that, we try
|
|
||||||
* to locate the external 'timezone' variable and use its value.
|
|
||||||
* If both of those methods fail, we attempt to convert a known
|
|
||||||
* time to local time and use the difference from UTC as the local
|
|
||||||
* time zone. In all cases, we need to undo any Daylight Saving Time
|
|
||||||
* adjustment.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(HAVE_TM_TZADJ)
|
|
||||||
# define TCL_GOT_TIMEZONE
|
|
||||||
|
|
||||||
/* Struct tm contains tm_tzadj - that value may be used. */
|
|
||||||
|
|
||||||
time_t curTime = (time_t) currentTime;
|
|
||||||
struct tm *timeDataPtr = TclpLocaltime((time_t *) &curTime);
|
|
||||||
int timeZone;
|
|
||||||
|
|
||||||
timeZone = timeDataPtr->tm_tzadj / 60;
|
|
||||||
if (timeDataPtr->tm_isdst) {
|
|
||||||
timeZone += 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
return timeZone;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_TM_GMTOFF) && !defined (TCL_GOT_TIMEZONE)
|
|
||||||
# define TCL_GOT_TIMEZONE
|
|
||||||
|
|
||||||
/* Struct tm contains tm_gmtoff - that value may be used. */
|
|
||||||
|
|
||||||
time_t curTime = (time_t) currentTime;
|
|
||||||
struct tm *timeDataPtr = TclpLocaltime((time_t *) &curTime);
|
|
||||||
int timeZone;
|
|
||||||
|
|
||||||
timeZone = -(timeDataPtr->tm_gmtoff / 60);
|
|
||||||
if (timeDataPtr->tm_isdst) {
|
|
||||||
timeZone += 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
return timeZone;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_TIMEZONE_VAR) && !defined(TCL_GOT_TIMEZONE) && !defined(USE_DELTA_FOR_TZ)
|
|
||||||
# define TCL_GOT_TIMEZONE
|
|
||||||
|
|
||||||
int timeZone;
|
|
||||||
|
|
||||||
/* The 'timezone' external var is present and may be used. */
|
|
||||||
|
|
||||||
SetTZIfNecessary();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note: this is not a typo in "timezone" below! See tzset
|
|
||||||
* documentation for details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
timeZone = timezone / 60;
|
|
||||||
return timeZone;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(TCL_GOT_TIMEZONE)
|
|
||||||
#define TCL_GOT_TIMEZONE 1
|
|
||||||
/*
|
|
||||||
* Fallback - determine time zone with a known reference time.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int timeZone;
|
|
||||||
time_t tt;
|
|
||||||
struct tm *stm;
|
|
||||||
tt = 849268800L; /* 1996-11-29 12:00:00 GMT */
|
|
||||||
stm = TclpLocaltime((time_t *) &tt); /* eg 1996-11-29 6:00:00 CST6CDT */
|
|
||||||
/* The calculation below assumes a max of +12 or -12 hours from GMT */
|
|
||||||
timeZone = (12 - stm->tm_hour)*60 + (0 - stm->tm_min);
|
|
||||||
if ( stm -> tm_isdst ) {
|
|
||||||
timeZone += 60;
|
|
||||||
}
|
|
||||||
return timeZone; /* eg +360 for CST6CDT */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef TCL_GOT_TIMEZONE
|
|
||||||
/*
|
|
||||||
* Cause compile error, we don't know how to get timezone.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#error autoconf did not figure out how to determine the timezone.
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Tcl_GetTime --
|
|
||||||
*
|
|
||||||
* Gets the current system time in seconds and microseconds
|
|
||||||
* since the beginning of the epoch: 00:00 UCT, January 1, 1970.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* Returns the current time in timePtr.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
|
||||||
Tcl_GetTime(timePtr)
|
|
||||||
Tcl_Time *timePtr; /* Location to store time information. */
|
|
||||||
{
|
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
(void) gettimeofday(&tv, NULL);
|
|
||||||
timePtr->sec = tv.tv_sec;
|
|
||||||
timePtr->usec = tv.tv_usec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* TclpGetDate --
|
|
||||||
*
|
|
||||||
* This function converts between seconds and struct tm. If
|
|
||||||
* useGMT is true, then the returned date will be in Greenwich
|
|
||||||
* Mean Time (GMT). Otherwise, it will be in the local time zone.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* Returns a static tm structure.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct tm *
|
|
||||||
TclppGetDate(time, useGMT)
|
|
||||||
time_t time;
|
|
||||||
int useGMT;
|
|
||||||
{
|
|
||||||
time_t mtime = time;
|
|
||||||
if (useGMT) {
|
|
||||||
return TclpGmtime(&mtime);
|
|
||||||
} else {
|
|
||||||
return TclpLocaltime(&mtime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* TclpStrftime --
|
|
||||||
*
|
|
||||||
* On Unix, we can safely call the native strftime implementation,
|
|
||||||
* and also ignore the useGMT parameter.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* The normal strftime result.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
size_t
|
|
||||||
TclpStrftime(s, maxsize, format, t, useGMT)
|
|
||||||
char *s;
|
|
||||||
size_t maxsize;
|
|
||||||
CONST char *format;
|
|
||||||
CONST struct tm *t;
|
|
||||||
int useGMT;
|
|
||||||
{
|
|
||||||
if (format[0] == '%' && format[1] == 'Q') {
|
|
||||||
/* Format as a stardate */
|
|
||||||
sprintf(s, "Stardate %2d%03d.%01d",
|
|
||||||
(((t->tm_year + TM_YEAR_BASE) + 377) - 2323),
|
|
||||||
(((t->tm_yday + 1) * 1000) /
|
|
||||||
(365 + IsLeapYear((t->tm_year + TM_YEAR_BASE)))),
|
|
||||||
(((t->tm_hour * 60) + t->tm_min)/144));
|
|
||||||
return(strlen(s));
|
|
||||||
}
|
|
||||||
setlocale(LC_TIME, "");
|
|
||||||
return strftime(s, maxsize, format, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* TclpGmtime --
|
|
||||||
*
|
|
||||||
* Wrapper around the 'gmtime' library function to make it thread
|
|
||||||
* safe.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* Returns a pointer to a 'struct tm' in thread-specific data.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* Invokes gmtime or gmtime_r as appropriate.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct tm *
|
|
||||||
TclpGmtime( tt )
|
|
||||||
CONST time_t *tt;
|
|
||||||
{
|
|
||||||
CONST time_t *timePtr = (CONST time_t *) tt;
|
|
||||||
/* Pointer to the number of seconds
|
|
||||||
* since the local system's epoch */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get a thread-local buffer to hold the returned time.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ThreadSpecificData *tsdPtr = TCL_TSD_INIT( &tmKey );
|
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
gmtime_r(timePtr, &( tsdPtr->gmtime_buf ));
|
|
||||||
#else
|
|
||||||
Tcl_MutexLock( &tmMutex );
|
|
||||||
memcpy( (VOID *) &( tsdPtr->gmtime_buf ),
|
|
||||||
(VOID *) gmtime( timePtr ),
|
|
||||||
sizeof( struct tm ) );
|
|
||||||
Tcl_MutexUnlock( &tmMutex );
|
|
||||||
#endif
|
|
||||||
return &( tsdPtr->gmtime_buf );
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Forwarder for obsolete item in Stubs
|
|
||||||
*/
|
|
||||||
struct tm*
|
|
||||||
TclpGmtime_unix( timePtr )
|
|
||||||
CONST time_t *timePtr;
|
|
||||||
{
|
|
||||||
return TclpGmtime( timePtr );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* TclpLocaltime --
|
|
||||||
*
|
|
||||||
* Wrapper around the 'localtime' library function to make it thread
|
|
||||||
* safe.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* Returns a pointer to a 'struct tm' in thread-specific data.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* Invokes localtime or localtime_r as appropriate.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct tm *
|
|
||||||
TclpLocaltime( tt )
|
|
||||||
CONST time_t *tt;
|
|
||||||
{
|
|
||||||
CONST time_t *timePtr = (CONST time_t *) tt;
|
|
||||||
/* Pointer to the number of seconds
|
|
||||||
* since the local system's epoch */
|
|
||||||
/*
|
|
||||||
* Get a thread-local buffer to hold the returned time.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ThreadSpecificData *tsdPtr = TCL_TSD_INIT( &tmKey );
|
|
||||||
SetTZIfNecessary();
|
|
||||||
#ifdef HAVE_LOCALTIME_R
|
|
||||||
localtime_r( timePtr, &( tsdPtr->localtime_buf ) );
|
|
||||||
#else
|
|
||||||
Tcl_MutexLock( &tmMutex );
|
|
||||||
memcpy( (VOID *) &( tsdPtr -> localtime_buf ),
|
|
||||||
(VOID *) localtime( timePtr ),
|
|
||||||
sizeof( struct tm ) );
|
|
||||||
Tcl_MutexUnlock( &tmMutex );
|
|
||||||
#endif
|
|
||||||
return &( tsdPtr->localtime_buf );
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Forwarder for obsolete item in Stubs
|
|
||||||
*/
|
|
||||||
struct tm*
|
|
||||||
TclpLocaltime_unix( timePtr )
|
|
||||||
CONST time_t *timePtr;
|
|
||||||
{
|
|
||||||
return TclpLocaltime( timePtr );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* SetTZIfNecessary --
|
|
||||||
*
|
|
||||||
* Determines whether a call to 'tzset' is needed prior to the
|
|
||||||
* next call to 'localtime' or examination of the 'timezone' variable.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* If 'tzset' has never been called in the current process, or if
|
|
||||||
* the value of the environment variable TZ has changed since the
|
|
||||||
* last call to 'tzset', then 'tzset' is called again.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
SetTZIfNecessary() {
|
|
||||||
|
|
||||||
CONST char* newTZ = getenv( "TZ" );
|
|
||||||
Tcl_MutexLock(&tmMutex);
|
|
||||||
if ( newTZ == NULL ) {
|
|
||||||
newTZ = "";
|
|
||||||
}
|
|
||||||
if ( lastTZ == NULL || strcmp( lastTZ, newTZ ) ) {
|
|
||||||
tzset();
|
|
||||||
if ( lastTZ == NULL ) {
|
|
||||||
Tcl_CreateExitHandler( CleanupMemory, (ClientData) NULL );
|
|
||||||
} else {
|
|
||||||
Tcl_Free( lastTZ );
|
|
||||||
}
|
|
||||||
lastTZ = ckalloc( strlen( newTZ ) + 1 );
|
|
||||||
strcpy( lastTZ, newTZ );
|
|
||||||
}
|
|
||||||
Tcl_MutexUnlock(&tmMutex);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* CleanupMemory --
|
|
||||||
*
|
|
||||||
* Releases the private copy of the TZ environment variable
|
|
||||||
* upon exit from Tcl.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* Frees allocated memory.
|
|
||||||
*
|
|
||||||
*----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
CleanupMemory( ClientData ignored )
|
|
||||||
{
|
|
||||||
ckfree( lastTZ );
|
|
||||||
}
|
|
45
utils/deploysics
Executable file
45
utils/deploysics
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/tclsh
|
||||||
|
#----------------------------------------------------------
|
||||||
|
# A script for deploying SICS servers easily
|
||||||
|
#
|
||||||
|
# Mark Koennecke, April 2015
|
||||||
|
#----------------------------------------------------------
|
||||||
|
|
||||||
|
set instlist [list amor boa dmc eiger focus hrpt mars \
|
||||||
|
morpheus narziss orion poldi rita2 sans sans2 tasp trics]
|
||||||
|
|
||||||
|
|
||||||
|
proc execCommand {command} {
|
||||||
|
puts stdout "Doing $command"
|
||||||
|
set status [catch {eval exec $command} msg]
|
||||||
|
if {$status != 0} {
|
||||||
|
puts stdout "ERROR: $msg "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#-----------------------------------------------------------
|
||||||
|
proc replaceServer {inst} {
|
||||||
|
execCommand "ssh ${inst}@${inst} monit stop sicsserver"
|
||||||
|
execCommand "ssh ${inst}@${inst} monit stop simserver"
|
||||||
|
execCommand "scp ./SICServer ${inst}@${inst}:${inst}_sics"
|
||||||
|
execCommand "ssh ${inst}@${inst} updatesicscommon"
|
||||||
|
execCommand "ssh ${inst}@${inst} monit start sicsserver"
|
||||||
|
execCommand "ssh ${inst}@${inst} monit start simserver"
|
||||||
|
}
|
||||||
|
|
||||||
|
if {[llength $argv] < 1} {
|
||||||
|
puts stdout "usage:\n\tdeploysics instname| all"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
set inst [lindex $argv]
|
||||||
|
|
||||||
|
if {[string compare $inst all] == 0} {
|
||||||
|
foreach inst $instlist {
|
||||||
|
replaceServer $inst
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
replaceServer $inst
|
||||||
|
}
|
||||||
|
|
||||||
|
puts stdout "Done"
|
||||||
|
|
17
utils/picoscope/Makefile
Normal file
17
utils/picoscope/Makefile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#--------------------------------------------------------------
|
||||||
|
# This requires the picoscope software to be installed under
|
||||||
|
# /opt
|
||||||
|
#
|
||||||
|
# Mark Koennecke, May 2015
|
||||||
|
#--------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
picocontrol: picocontrol.o
|
||||||
|
gcc -g -o picocontrol picocontrol.o -L/opt/picoscope/lib -lps2000a
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
gcc -g -c -I/opt/picoscope/include $*.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
- rm picocontrol picocontrol.o
|
||||||
|
|
17
utils/picoscope/Makefile.osx
Executable file
17
utils/picoscope/Makefile.osx
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#--------------------------------------------------------------
|
||||||
|
# This requires the picoscope software to be installed under
|
||||||
|
# /opt
|
||||||
|
#
|
||||||
|
# Mark Koennecke, May 2015
|
||||||
|
#--------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
picocontrol: picocontrol.o
|
||||||
|
gcc -g -o picocontrol picocontrol.o -L/Applications/PicoScope6.app/Contents/Resources/lib -lps2000a
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
gcc -g -c -I/Applications/PicoScope6.app/Contents/Resources/include $*.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
- rm picocontrol picocontrol.o
|
||||||
|
|
2472
utils/picoscope/PS2000Acon.c
Normal file
2472
utils/picoscope/PS2000Acon.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
utils/picoscope/picocontrol
Executable file
BIN
utils/picoscope/picocontrol
Executable file
Binary file not shown.
127
utils/picoscope/picocontrol.c
Normal file
127
utils/picoscope/picocontrol.c
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/**
|
||||||
|
This is a little CLI program to control the picoscope frequency
|
||||||
|
generator coming with the Pico Labs Picoscope 2206a oscilloscope
|
||||||
|
|
||||||
|
Mark Koennecke, May 2015
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <libps2000a-1.1/ps2000aApi.h>
|
||||||
|
#ifndef PICO_STATUS
|
||||||
|
#include <libps2000a-1.1/PicoStatus.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static short handle;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------*/
|
||||||
|
static void StopPico(void)
|
||||||
|
{
|
||||||
|
ps2000aCloseUnit(handle);
|
||||||
|
}
|
||||||
|
/*--------------------------------------------------------------*/
|
||||||
|
static void SetGenerator(long freq, float ampl)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if(freq == 0){
|
||||||
|
status = ps2000aSetSigGenBuiltIn(handle,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
PS2000A_DC_VOLTAGE,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
} else {
|
||||||
|
status = ps2000aSetSigGenBuiltIn(handle,
|
||||||
|
0,
|
||||||
|
(unsigned long)ampl,
|
||||||
|
PS2000A_SINE,
|
||||||
|
(float)freq,
|
||||||
|
(float)freq,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
if(status != PICO_OK){
|
||||||
|
printf("Failed to configure signal generator with %d\n", status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*----------------------------------------------------------------------*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
long int freq = 1000;
|
||||||
|
float mult = 1000000, ampl = 1.*mult, tmp;
|
||||||
|
char line[80], token[80];
|
||||||
|
|
||||||
|
status = ps2000aOpenUnit(&handle, NULL);
|
||||||
|
if(status != PICO_OK){
|
||||||
|
printf("Failed to open picoscope with %d\n", status);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
atexit(StopPico);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
memset(line,0,sizeof(line));
|
||||||
|
fgets(line,sizeof(line),stdin);
|
||||||
|
|
||||||
|
if(strstr(line,"freq") != NULL){
|
||||||
|
status = sscanf(line,"%s %f",token, &tmp);
|
||||||
|
if(status == 2){
|
||||||
|
freq = (unsigned int) tmp;
|
||||||
|
SetGenerator(freq,ampl);
|
||||||
|
printf("OK\n");
|
||||||
|
} else {
|
||||||
|
printf("freq %ld\n", freq);
|
||||||
|
}
|
||||||
|
} else if(strstr(line,"ampl") != NULL){
|
||||||
|
status = sscanf(line,"%s %f",token, &tmp);
|
||||||
|
if(status == 2){
|
||||||
|
ampl = tmp*mult;
|
||||||
|
SetGenerator(freq,ampl);
|
||||||
|
printf("OK\n");
|
||||||
|
} else {
|
||||||
|
printf("ampl %f\n", ampl/mult);
|
||||||
|
}
|
||||||
|
} else if(strstr(line,"on") != NULL){
|
||||||
|
SetGenerator(freq,ampl);
|
||||||
|
printf("OK\n");
|
||||||
|
}else if(strstr(line,"off") != NULL){
|
||||||
|
SetGenerator(0,0);
|
||||||
|
printf("OK\n");
|
||||||
|
}else if(strstr(line,"exit") != NULL){
|
||||||
|
ps2000aCloseUnit(handle);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
printf("Parameter commands: freq (hz), ampl( V), on, off\n");
|
||||||
|
}
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
41
utils/picoscope/picocontrol.plist
Normal file
41
utils/picoscope/picocontrol.plist
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>Disabled</key>
|
||||||
|
<true/>
|
||||||
|
<key>Label</key>
|
||||||
|
<string>picocontrol</string>
|
||||||
|
<key>Program</key>
|
||||||
|
<string>/Users/sinquser/src/picoscope/picocontrol</string>
|
||||||
|
<key>EnvironmentVariables</key>
|
||||||
|
<dict>
|
||||||
|
<key>DYLD_LIBRARY_PATH</key>
|
||||||
|
<string>/Applications/PicoScope6.app/Contents/Resources/lib</string>
|
||||||
|
</dict>
|
||||||
|
<key>Sockets</key>
|
||||||
|
<dict>
|
||||||
|
<key>Listeners</key>
|
||||||
|
<dict>
|
||||||
|
<key>SockServiceName</key>
|
||||||
|
<string>ssh</string>
|
||||||
|
<key>Bonjour</key>
|
||||||
|
<array>
|
||||||
|
<string>ssh</string>
|
||||||
|
<string>sftp-ssh</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>inetdCompatibility</key>
|
||||||
|
<dict>
|
||||||
|
<key>Wait</key>
|
||||||
|
<false/>
|
||||||
|
</dict>
|
||||||
|
<key>StandardErrorPath</key>
|
||||||
|
<string>/dev/null</string>
|
||||||
|
<key>SHAuthorizationRight</key>
|
||||||
|
<string>system.preferences</string>
|
||||||
|
<key>POSIXSpawnType</key>
|
||||||
|
<string>Interactive</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
12
utils/picoscope/picocontrol.xinetd
Executable file
12
utils/picoscope/picocontrol.xinetd
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
service picocontrol
|
||||||
|
{
|
||||||
|
socket_type = stream
|
||||||
|
protocol = tcp
|
||||||
|
port = 3030
|
||||||
|
type = UNLISTED
|
||||||
|
wait = no
|
||||||
|
user = root
|
||||||
|
server = /usr/bin/picocontrol
|
||||||
|
}
|
||||||
|
|
||||||
|
|
BIN
utils/picoscope/picosig
Executable file
BIN
utils/picoscope/picosig
Executable file
Binary file not shown.
69
utils/picoscope/picosig.c
Normal file
69
utils/picoscope/picosig.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/**
|
||||||
|
This is a little CLi program to control the picoscope frequency
|
||||||
|
generator coming with the Pico Labs Picoscope 2206a oscilloscope
|
||||||
|
|
||||||
|
Mark Koennecke, May 2015
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <libps2000a-1.1/ps2000aApi.h>
|
||||||
|
#ifndef PICO_STATUS
|
||||||
|
#include <libps2000a-1.1/PicoStatus.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int freq, ampl, status;
|
||||||
|
short handle;
|
||||||
|
|
||||||
|
if(argc < 3) {
|
||||||
|
printf("Usage:\n\tpicosig freq ampl\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
freq = atoi(argv[1]);
|
||||||
|
ampl = atoi(argv[2]);
|
||||||
|
|
||||||
|
printf("Found freq, ample = %d %d\n", freq, ampl);
|
||||||
|
|
||||||
|
status = ps2000aOpenUnit(&handle, NULL);
|
||||||
|
if(status != PICO_OK){
|
||||||
|
printf("Failed to open picoscope with %d\n", status);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = ps2000aSetSigGenBuiltIn(handle,
|
||||||
|
0,
|
||||||
|
(unsigned long)ampl,
|
||||||
|
PS2000A_SINE,
|
||||||
|
(float)freq,
|
||||||
|
(float)freq,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
if(status != PICO_OK){
|
||||||
|
printf("Failed to configure signal generator with %d\n", status);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
ps2000aCloseUnit(handle);
|
||||||
|
printf("Done\n");
|
||||||
|
}
|
Reference in New Issue
Block a user