Programación

Content

GENERAL INFORMATION

  • Underlying
  • Important
  • SPS Objects

AVAILABLE FUNKTIONS

  • C Library Functions
  • Mathematical Functions
  • Extended C Library Functions
  • SPS Functions
  • File Functions
  • HTTP Functions
  • Stream-Funktionen

DESCRIPTION OF EXTENDED C LIBRARY FUNCTIONS

  • atoi
  • batof
  • strstrskip
  • index
  • lineno
  • getxmlvalue
  • getcpuinfo
  • getheapusage
  • getmaxheap
  • getspsstatus
  • localwebservice

DESCRIPTION OF SPS FUNCTIONS

  • setlogtext
  • getio
  • setio
  • getinputevent
  • getinput
  • getinputtext
  • setoutput
  • setoutputtext

DESCRIPTION OF TIME FUNCTIONS

  • sleep
  • sleeps
  • getcurrenttime
  • getyear
  • getmonth
  • getday
  • gethour
  • getminute
  • getsecond
  • gettimeval
  • convertutc2local
  • convertlocal2utc

DESCRIPTION OF FILE FUNCTIONS

  • fseek

DESCRIPTION OF HTTP FUNCTIONS

  • httpget

DESCRIPTION OF STREAM FUNCTIONS

  • stream_create
  • stream_printf
  • stream_write
  • stream_flush
  • stream_read
  • stream_readline
  • stream_close

EXAMPLES

  • Computing
  • website download per tcp stream
  • Connecting to an APC USV, if apcupsd is used on the PC
  • Read from RS232 Extension via RS232 stream

 

General information

This documentation describes how a customized object can be programmed.

info_smallYou need LoxoneConfig 2.1 onwards for using PicoC-Scripts in the configuration-software. Please check out our newest beta-releases for using the scripts.

 

UNDERLYING

The programming language PicoC (http://code.google.com/p/picoc/) is used. PicoC is a very small C interpreter for scripting. It was originally written  for scripting a UAV’s on-board flight system and it’s also very suitable for  other robotic, embedded and non-embedded applications too.

PicoC Copyright

IMPORTANT

  • Note that the complete C specification can not be met!
  • The program code is interpreted. Therefore keep the code as low as possible. Avoid complex program structures.
  • Each program runs in a separate task, therefore, asynchronous to the SPS.
  • Outputs with printf will be written to the log window of Loxone Config.
  • Note also that with an own programming, the system can be lead to crash. Program your instructions carefully. In case of emergency an SD card must be created, so the system gets operational again.
  • If you want to run the program indefinitely, add in the program loops implicitly a sleep- function so that the program does not consume unnecessary CPU time.
  • An integer has 32 bits, little endian.
  • 128kB are available for heap and stack. Use memory thrifty; do not forget to release memory.
  • All functions which return a pointer must reallocate the memory with free (), unless the pointer was passed as a parameter.
  • Time values are indicated in seconds since 1.1.2009 0 UTC clock.
  • Strings are encoded in UTF-8.
  • Use mathematical function sparsely – the processor in the Miniserver has no mathematical hardware unit.

info_smallThe scripts only work in Liveview.

 

SPS OBJECTS

There are program objects with 1, 4, 8 and 16 inputs and outputs. You can insert a program-object by chosing it under “General” in the tab “Program”.

Each program also has an error output (TeQ), where eventual interpreter- error messages are released. This allows the detection of syntax errors.

The program code can be edited by double-clicking on the program- object.

 

Available functions

In the following chapters all available functions are listed and all Miniserver specific functions are described. For all standard C functions plenty of information can be found in appropriate literature (e.g. www.cplusplus.com/reference/clibrary/).

C LIBRARY FUNCTIONS

char *getprogramname();
void printf(char *format, …);
char *sprintf(char *ptr, char *format, …);
void exit();
void *malloc(int size);
void *calloc(int num,int size);
void *realloc(void *ptr,int size);
void free(void *ptr);
int atoi(char *str);
float atof(char *str);
void strcpy(char *dst,char *src);
void strncpy(char *dst,char *src,int len);
int strcmp(char *str1,char *str2);
int strncmp(char *str1,char *str2,int len);
void strcat(char *dst,char *src);
char *strdup(char *str);
char* strstr(char *str,char *strfind);
int strfind(char *str,char *strfind,int pos);
int strlen(char *str);
void memset(void *ptr,int val,int len);
void memcpy(void *dst,void *src,int len);
int memcmp(void *ptr1,void *ptr2,int len);
void errorprintf(char *format,…);

Print to standard error device. Only used in shell command.

MATHEMATICAL FUNCTIONS

float sin(float x);
Returns the sine of an angle of x radians.
float cos(float x);
Returns the cosine of an angle of x radians.
float tan(float x);
Returns the tangent of an angle of x radians.
float asin(float x);
Returns the principal value of the arc sine of x, expressed in radians. In trigonometrics, arc sine is the inverse operation of sine.
float acos(float x);
Returns the principal value of the arc cosine of x, expressed in radians. In trigonometrics, arc cosine is the inverse operation of cosine.
float atan(float x);
Returns the principal value of the arc tangent of x, expressed in radians. In trigonometrics, arc tangent is the inverse operation of tangent.
float sinh(float x);
Returns the hyperbolic sine of x.
float cosh(float x);
Returns the hyperbolic cosine of x.
float tanh(float x);
Returns the hyperbolic tangent of x.
float exp(float x);
Returns the base-e exponential function of x, which is the e number raised to the power x.
float fabs(float x);
Returns the absolute value of x
float log(float x);
Returns the natural logarithm of x.
float log10(float x);
Returns the common (base-10) logarithm of x.
float pow(float base,float exponent);
Returns base raised to the power exponent.
float sqrt(float x);
Returns the square root of x.
float round(float x);
Returns rounded value of x.
float ceil(float x);
Returns the smallest integral value that is not less than x.
float floor(float x);
Returns the largest integral value that is not greater than x.

EXTENDED C LIBRARY FUNCTIONS

int batoi(char *str);
float batof(char *str);
char* strstrskip(char *str,char *strfind);
char *index(char *,int);
int lineno();

SPS FUNCTIONS

Following Functions are available:

void setlogtext(char *str);
float getio(char *str);
int setio(char *str,float value);
int getinputevent();
float getinput(int input);
char *getinputtext(int input);
void setoutput(int output,float value);
void setoutputtext(int output,char *str);
char *getweatherserveraddress();
int setweatherdata(int type,unsigned int time,float value);
float getweatherdata(int type,unsigned int time);
void saveweatherdata();

FILE FUNCTIONS

FILE *fopen(char *filename,char *mode);
int fclose(FILE *f);
int fprintf(FILE *f,char *format, … );
int fputc(int character,FILE *f);
int fputs(char *str, FILE *f);
int fflush(FILE *f);
int fwrite (void *ptr,int size,int count,FILE *f);
int fgetc(FILE *f);
char *fgets(char *str,int num,FILE *f);
int fread(void *,int size,int count,FILE *f);
int fseek(FILE *f,long offset,int origin);
int remove(char *filename);
int rename(char *oldname,char *newname);
FILE* tmpfile();
char *tmpnam(char* str);

HTTP FUNCTIONS

char*httpget(char*address,char*page);

STREAM-FUNKTIONEN

STREAM *stream_create(char* filename,int read,int append);
void stream_printf(STREAM* stream,char *format, …);
int stream_write(STREAM* stream,void* ptr,int size);
void stream_flush(STREAM* stream);
int stream_read(STREAM* stream,void* ptr,int size,int timeout);
int stream_readline(STREAM* stream,void* ptr,int maxsize,int timeout);
void stream_close(STREAM* stream);

Description of extended C library functions

atoi

int batoi(char *str);

Works like the atoi standard C function with the exception that blanks at the
beginning of parameter str are allowed.
Example:

atoi(“ 21”); // return value = NULL
batoi(“ 21”); // return value = 21

batof

float batof(char *str);

Works like the atof standard C function with the exception that blanks at the beginning of parameter str are allowed. Example:

atof(“ 2.1”); // return value = NULL
batof(“ 2.1”); // return value = 2.1

strstrskip

char* strstrskip(char *str,char *strfind);

Works like the strstr standard C function with the exception that the length of parameter strfind is added to the result pointer.
Example:

strstr(“das ist ein test”,”ein ”); // return value = “ein test”

strstrskip(“das ist ein test”,”ein ”); // return value = “test”

index

char *index(char *str,int charfind);

Returns a pointer to the first occurrence of character charfind in str, or a null pointer if charfind is not part of str.
Example:

index(“0123456789”,0x32); // return value = “23456789”

lineno

int lineno();]

Returns the current line number in script.

getxmlvalue

char *getxmlvalue(char *str,int index,char* name);

Returns the value of name in str, or a null pointer if name is not part of str.

Parameters:
str: XML-String to parse
index: the index of occurence of name (first element is 0)
name: XML-Attribute name to get

The memory where the returned pointer points to must be deallocated with function free().
Example:

getxmlvalue(“”,0,”name”); // return value = “test”