├── .gitignore ├── sdk ├── .gitignore ├── samples │ └── sample1 │ │ ├── devices │ │ └── README │ │ ├── yasdi.ini │ │ └── sample1.c ├── projects │ ├── generic-cmake │ │ ├── devices │ │ │ └── README │ │ ├── yasdi-windows.ini │ │ ├── incprj │ │ │ ├── project.h │ │ │ └── project.h.in │ │ └── yasdi-posix.ini │ └── README ├── core │ ├── router.c │ ├── byteorder.c │ ├── defractionizer.c │ ├── queue.h │ ├── minqueue.h │ ├── minmap.h │ ├── fractionizer.h │ ├── iorequest.c │ ├── timer.h │ ├── byteorder.h │ ├── queue.c │ ├── defractionizer.h │ ├── repository.h │ ├── timer.c │ ├── minqueue.c │ ├── statistic_writer.h │ ├── smadata_cmd.h │ ├── tools.h │ ├── protocol.h │ ├── router.h │ ├── mempool.h │ ├── scheduler.h │ ├── prot_layer.h │ ├── driver_layer.h │ ├── mempool.c │ ├── iorequest.h │ ├── netpacket.h │ └── minmap.c ├── include │ ├── lists.h │ ├── packet.h │ ├── copyright.h │ ├── version.h │ ├── version.h.in │ ├── frame_listener.h │ ├── yasdi_version.rc │ ├── osswitch.h │ ├── chandef.h │ ├── compiler.h │ ├── events.h │ ├── device.h │ ├── debug.h │ └── os.h ├── smalib │ ├── getini.c │ ├── getini.h │ └── smadef.h ├── master │ ├── ysecurity.c │ ├── statereadchan.c │ ├── statewritechan.h │ ├── statereadchan.h │ ├── stateident.h │ ├── ysecurity.h │ ├── statedetection.h │ ├── busevents.h │ ├── objman.h │ ├── stateconfig.h │ ├── plant.h │ ├── chanvalrepo.h │ ├── netchannel.h │ ├── master.h │ ├── stateident.c │ ├── mastercmd.h │ ├── busevents.c │ ├── statewritechan.c │ └── chanvalrepo.c ├── driver │ ├── serial_posix.c │ ├── serial_windows.c │ ├── serial_posix.h │ ├── README │ ├── serial_windows.h │ └── ip_generic.h ├── shell │ └── CommonShellUIMain.c ├── COPYRIGHT ├── os │ ├── os_windows.h │ ├── os_darwin.h │ └── os_linux.h ├── protocol │ ├── sunnynet.h │ └── smanet.h ├── libs │ ├── libyasdimaster.def │ └── libyasdi.def ├── README └── CHANGES ├── docs └── YASDI-10NE1106.pdf ├── .github └── workflows │ └── release.yaml ├── container ├── debian.Containerfile └── alpine.Containerfile └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | build -------------------------------------------------------------------------------- /sdk/.gitignore: -------------------------------------------------------------------------------- 1 | projects/generic-cmake/cmake-build-debug/ -------------------------------------------------------------------------------- /sdk/samples/sample1/devices/README: -------------------------------------------------------------------------------- 1 | channel list cache... 2 | -------------------------------------------------------------------------------- /sdk/projects/generic-cmake/devices/README: -------------------------------------------------------------------------------- 1 | Cache space for channel lists... 2 | 3 | -------------------------------------------------------------------------------- /sdk/core/router.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/core/router.c -------------------------------------------------------------------------------- /sdk/core/byteorder.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/core/byteorder.c -------------------------------------------------------------------------------- /sdk/include/lists.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/include/lists.h -------------------------------------------------------------------------------- /sdk/include/packet.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/include/packet.h -------------------------------------------------------------------------------- /sdk/smalib/getini.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/smalib/getini.c -------------------------------------------------------------------------------- /sdk/smalib/getini.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/smalib/getini.h -------------------------------------------------------------------------------- /sdk/master/ysecurity.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/master/ysecurity.c -------------------------------------------------------------------------------- /docs/YASDI-10NE1106.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/docs/YASDI-10NE1106.pdf -------------------------------------------------------------------------------- /sdk/core/defractionizer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/core/defractionizer.c -------------------------------------------------------------------------------- /sdk/driver/serial_posix.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/driver/serial_posix.c -------------------------------------------------------------------------------- /sdk/driver/serial_windows.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/driver/serial_windows.c -------------------------------------------------------------------------------- /sdk/master/statereadchan.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/master/statereadchan.c -------------------------------------------------------------------------------- /sdk/shell/CommonShellUIMain.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/konstantinblaesi/yasdi/HEAD/sdk/shell/CommonShellUIMain.c -------------------------------------------------------------------------------- /sdk/include/copyright.h: -------------------------------------------------------------------------------- 1 | #ifndef __COPYRIGHT__H 2 | #define __COPYRIGHT__H 3 | 4 | #define SMA_COPYRIGHT_SHORT "2001-2010 SMA Solar Technology AG" 5 | #define SMA_COPYRIGHT "Copyright (c) " SMA_COPYRIGHT_SHORT 6 | 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /sdk/projects/README: -------------------------------------------------------------------------------- 1 | Project Description 2 | --------------------------------- 3 | 4 | generic_cmake An port for Mac + Linux + Windows using the CMake build system 5 | (see www.cmake.org) 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sdk/samples/sample1/yasdi.ini: -------------------------------------------------------------------------------- 1 | [DriverModules] 2 | Driver0=yasdi_drv_ip 3 | Driver1=yasdi_drv_serial 4 | 5 | [COM1] 6 | Device=/dev/ttyS0 7 | Media=RS232 8 | Baudrate=1200 9 | Protocol=SMANet 10 | 11 | [IP1] 12 | Protocol=SMANet 13 | Device0=192.168.18.103 14 | 15 | [Misc] 16 | #DebugOutput=/dev/stderr 17 | 18 | -------------------------------------------------------------------------------- /sdk/include/version.h: -------------------------------------------------------------------------------- 1 | #ifndef __VERSION__H 2 | #define __VERSION__H 3 | 4 | //Version of the yasdi library 5 | 6 | //must be preprocessed with cmake! 7 | 8 | #define LIB_YASDI_VER1 1 9 | #define LIB_YASDI_VER2 8 10 | #define LIB_YASDI_VER3 3 11 | #define LIB_YASDI_VER4 0 12 | 13 | #define LIB_YASDI_VERSION "1.8.3" 14 | #define LIB_YASDI_VERSION_FULL "1.8.3Build0" 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /sdk/include/version.h.in: -------------------------------------------------------------------------------- 1 | #ifndef __VERSION__H 2 | #define __VERSION__H 3 | 4 | //Version of the yasdi library 5 | 6 | //must be preprocessed with cmake! 7 | 8 | #define LIB_YASDI_VER1 @LIB_YASDI_VER1@ 9 | #define LIB_YASDI_VER2 @LIB_YASDI_VER2@ 10 | #define LIB_YASDI_VER3 @LIB_YASDI_VER3@ 11 | #define LIB_YASDI_VER4 @LIB_YASDI_VER4@ 12 | 13 | #define LIB_YASDI_VERSION "@YASDI_VERSION@" 14 | #define LIB_YASDI_VERSION_FULL "@YASDI_VERSION_FULL@" 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /sdk/include/frame_listener.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAME_LISTENER_H 2 | #define FRAME_LISTENER_H 3 | 4 | #include "netpacket.h" 5 | 6 | /** 7 | * With this structure you can listen for specific protcol traffic on 8 | * the yasdi protocol layer... 9 | * 10 | */ 11 | typedef struct 12 | { 13 | /* for linking to list */ 14 | TMinNode Node; 15 | 16 | /** listening for an specific protocol only (SMADATA1, SMADATA2, SSP,...) */ 17 | WORD ProtocolID; 18 | 19 | /** Callback when an packet of that protocolID was received */ 20 | void (*OnPacketReceived)(struct TNetPacket * packet); 21 | 22 | } TFrameListener; 23 | 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /sdk/projects/generic-cmake/yasdi-windows.ini: -------------------------------------------------------------------------------- 1 | # 2 | # YASDI example Configuration file (for Windows) 3 | # 4 | 5 | [DriverModules] 6 | Driver0=yasdi_drv_serial 7 | Driver1=yasdi_drv_ip 8 | 9 | 10 | # Configs for serial port 1 11 | [COM1] 12 | Device=COM1 13 | Media=RS485 14 | Baudrate=1200 15 | Protocol=SMANet 16 | 17 | 18 | # Configs for serial port 2 19 | [COM2] 20 | Device=COM2 21 | Media=RS232 22 | Baudrate=19200 23 | Protocol=SMANet 24 | 25 | 26 | # Configs for serial port X 27 | #[COMX] 28 | #Device=COMX2 29 | #Media=RS232 30 | #Baudrate=1200 31 | #Protocol=SMANet 32 | 33 | 34 | # Configs for communiation over Ethernet/UDP 35 | # Replace 127.0.0.1 with the real IP address of your device 36 | [IP1] 37 | Protocol=SMANet 38 | Device0=127.0.0.1 39 | 40 | 41 | [Misc] 42 | #DebugOutput=stderr 43 | 44 | 45 | -------------------------------------------------------------------------------- /sdk/projects/generic-cmake/incprj/project.h: -------------------------------------------------------------------------------- 1 | #ifndef PROJECT_H 2 | #define PROJECT_H 3 | 4 | //This file must be processed with CMAKE. 5 | 6 | #if 0 7 | //with debug output... 8 | #define DEBUG 1 9 | #endif 10 | 11 | 12 | /*define the debug level I want to see on debug*/ 13 | #define DEBUGLEV ( \ 14 | VERBOSE_MASTER | \ 15 | VERBOSE_LIBRARY | \ 16 | VERBOSE_ROUTER | \ 17 | VERBOSE_REPOSITORY | \ 18 | VERBOSE_PACKETS | \ 19 | VERBOSE_HWL | \ 20 | VERBOSE_PROTLAYER | \ 21 | VERBOSE_CHANNELLIST | \ 22 | VERBOSE_BUFMANAGEMENT | \ 23 | VERBOSE_SMADATALIB | \ 24 | VERBOSE_BCN | \ 25 | VERBOSE_PACKETS \ 26 | ) 27 | #endif 28 | -------------------------------------------------------------------------------- /sdk/projects/generic-cmake/yasdi-posix.ini: -------------------------------------------------------------------------------- 1 | # 2 | # YASDI example Configuration file (for "POSIX" systems like Linux, MacOSX, Solaris, BSD, ...) 3 | # 4 | 5 | [DriverModules] 6 | Driver0=yasdi_drv_serial 7 | Driver1=yasdi_drv_ip 8 | 9 | 10 | # Configs for serial port 1 11 | [COM1] 12 | Device=/dev/ttyS0 13 | Media=RS485 14 | Baudrate=1200 15 | Protocol=SMANet 16 | 17 | 18 | # Configs for serial port 2 19 | [COM2] 20 | Device=/dev/ttyS1 21 | Media=RS232 22 | Baudrate=19200 23 | Protocol=SMANet 24 | 25 | 26 | # Configs for serial port X 27 | #[COMX] 28 | #Device=COMX2 29 | #Media=Powerline 30 | #Baudrate=1200 31 | #Protocol=SunnyNet 32 | 33 | 34 | # Configs for communiation over Ethernet/UDP 35 | # Replace 127.0.0.1 with the real IP address of your device 36 | [IP1] 37 | Protocol=SMANet 38 | Device0=127.0.0.1 39 | 40 | 41 | [Misc] 42 | #DebugOutput=stdout 43 | 44 | -------------------------------------------------------------------------------- /sdk/projects/generic-cmake/incprj/project.h.in: -------------------------------------------------------------------------------- 1 | #ifndef PROJECT_H 2 | #define PROJECT_H 3 | 4 | //This file must be processed with CMAKE. 5 | 6 | #if @YASDI_DEBUG_OUTPUT@ 7 | //with debug output... 8 | #define DEBUG 1 9 | #endif 10 | 11 | 12 | /*define the debug level I want to see on debug*/ 13 | #define DEBUGLEV ( \ 14 | VERBOSE_MASTER | \ 15 | VERBOSE_LIBRARY | \ 16 | VERBOSE_ROUTER | \ 17 | VERBOSE_REPOSITORY | \ 18 | VERBOSE_PACKETS | \ 19 | VERBOSE_HWL | \ 20 | VERBOSE_PROTLAYER | \ 21 | VERBOSE_CHANNELLIST | \ 22 | VERBOSE_BUFMANAGEMENT | \ 23 | VERBOSE_SMADATALIB | \ 24 | VERBOSE_BCN | \ 25 | VERBOSE_PACKETS \ 26 | ) 27 | #endif 28 | -------------------------------------------------------------------------------- /sdk/include/yasdi_version.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "version.h" /* YASDI's version file */ 3 | #include "copyright.h" 4 | 5 | #define VERSIONINFO_1 1 6 | VERSIONINFO_1 VERSIONINFO 7 | 8 | FILEVERSION LIB_YASDI_VER1, LIB_YASDI_VER2, LIB_YASDI_VER3, LIB_YASDI_VER4 9 | PRODUCTVERSION LIB_YASDI_VER1, LIB_YASDI_VER2, LIB_YASDI_VER3, LIB_YASDI_VER4 10 | 11 | FILEOS VOS_NT_WINDOWS32 12 | FILETYPE VFT_DLL 13 | { 14 | BLOCK "StringFileInfo" 15 | { 16 | BLOCK "040704E4" 17 | { 18 | VALUE "CompanyName", "SMA Solar Technology AG\000\000" 19 | VALUE "FileDescription", "YASDI (Yet Another SMAData Implementation)\000" 20 | VALUE "FileVersion", LIB_YASDI_VERSION 21 | VALUE "ProductName", "YASDI\000" 22 | VALUE "ProductVersion", LIB_YASDI_VERSION 23 | VALUE "LegalCopyright", SMA_COPYRIGHT_SHORT "\000\000" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sdk/driver/serial_posix.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIAL_POSIX_H 2 | #define SERIAL_POSIX_H 3 | 4 | 5 | //experimental: Using Posix AIO API to speedup sending... 6 | #define USING_POSIX_AIO 0 7 | 8 | 9 | 10 | //the serial bus driver media types 11 | typedef enum {SERMT_RS232, SERMT_RS485, SERMT_POWERLINE} TSerialMedia; 12 | 13 | /* unit structure (Instance of class) */ 14 | struct TSerialPosixPriv 15 | { 16 | int fd; /* serial port file descriptor */ 17 | char cPort[30]; /* the serial port name ("/dev/ttyS0") */ 18 | TSerialMedia media; /* Media (RS232,RS485,Powerline) */ 19 | DWORD dBaudrate; /* Bit / sec. */ 20 | DWORD dBytesSendTotal; /* total bytes send */ 21 | 22 | //for async IO 23 | #if 1 == USING_POSIX_AIO 24 | struct aiocb *aiocbp; //Posix Async IO request block 25 | struct TNetPacket * sendframe; //the current frame that must be send async.... 26 | #endif 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /sdk/include/osswitch.h: -------------------------------------------------------------------------------- 1 | #ifndef OSSWITCH_H 2 | #define OSSWITCH_H 3 | 4 | //Here ist the place to include your operating system specific include file... 5 | 6 | 7 | //include System dep. files here... 8 | #if defined ( linux ) 9 | #include "os_linux.h" //Linux 10 | #elif defined( _WIN32_WCE ) 11 | #include "os_WinCE.h" //Windows CE 12 | #elif defined( __WIN32__ ) 13 | #include "os_windows.h" //Windows 32 14 | #elif defined( WIN32 ) 15 | #include "os_windows.h" //Windows 32 16 | #elif defined( amiga ) 17 | #include "os_amiga.h" //AmigaOS 18 | #elif defined( __APPLE__ ) 19 | #include "os_darwin.h" //Darwin/MacOSX ( Apple Macintosh ) 20 | #elif defined ( OS_M16 ) 21 | #include "os_m16.h" //M16C 22 | #elif defined ( OS_ETHERNUT ) 23 | #include "os_ethernut.h" //Nut/Os 24 | #elif defined ( __PARADIGM__ ) //PARADIM C++ compiler for Beck IPC Chip 25 | #include "os_rtos_beck.h" 26 | #else 27 | #error unsupported operating system! Please port me....; 28 | #endif 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /sdk/COPYRIGHT: -------------------------------------------------------------------------------- 1 | YASDI 2 | ----- 3 | 4 | 1. COPYRIGHT 5 | 6 | The software YASDI is property of SMA Solar Technology AG. 7 | 8 | 9 | 2. LICENSE 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation; either 14 | version 2.1 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library in the file COPYING.LIB; 23 | if not, write to the Free Software Foundation, Inc., 24 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 25 | 26 | 27 | 3. SUPPORT 28 | 29 | SMA Solar Technology AG will give NO support in any kind for the 30 | source and the binary compilations. 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /sdk/master/statewritechan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef STATEWRITECHAN_H 23 | #define STATEWRITECHAN_H 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /sdk/master/statereadchan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef STATEREADCHAN_H 23 | #define STATEREADCHAN_H 24 | 25 | //currently nothing 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /sdk/master/stateident.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef STATEIDENT_H 23 | #define STATEIDENT_H 24 | 25 | TMasterState * TStateIdent_GetInstance( void ); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /sdk/master/ysecurity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef __securityH__ 23 | #define __securityH__ 24 | 25 | #include "chandef.h" 26 | 27 | BOOL TSecurity_SetNewAccessLevel(char * user, char * passwd); 28 | TLevel TSecurity_getCurLev( void ); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /sdk/driver/README: -------------------------------------------------------------------------------- 1 | This directory contains all YASDI bus drivers (as modules) which are 2 | currently available. Most drivers are platform specific. These drivers 3 | are plugins, compiled as library (DLL, SO,...) and loaded during YASDI starts. 4 | Of course it's also possible to "embedd" these driver into an static compiled 5 | YASDI... 6 | 7 | 8 | Driver Description 9 | ------------------------------------------------------------------------- 10 | serial_darwin.c/h serial driver for Apple MacOSX 11 | serial_linux.c/h serial driver for Linux 12 | serial_windows.c/h serial driver for windows32 13 | serial_windowsCE.c/h serial driver for windowsCE 14 | serial_bsp.c/h serial driver for "Board support packages" (SMA internal) 15 | serial_ethernut.c/h serial driver for "Ethernut" (an embedded device) 16 | ip_generic.c/h IP (UDP) driver for "SMA Ethernet PiggyBacks", 17 | works on Linux/MacOSX/Windows 18 | ip_linux.c/h (DEPRECATED) IP (UDP) driver for POSIX 19 | systems only (Linux/MacOSX), don't use it anymore 20 | ip_windows.c/h (DEPRECATED) IP (UDP) driver for Windows32 system , 21 | don't use it anymore 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sdk/master/statedetection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef STATEDETECTION_H 23 | #define STATEDETECTION_H 24 | 25 | TMasterState * TStateDetect_GetInstance( void ); 26 | 27 | /* 28 | struct _TMasterCmdReqDetection 29 | { 30 | //super 31 | struct _TMasterCmdReq super; 32 | 33 | //local structures for detection Master Command 34 | 35 | } TMasterCmdReqDetection; 36 | */ 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /sdk/master/busevents.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | // 23 | // Bus Events 24 | // 25 | void TSMADataMaster_OnBusEvent(TGenDriverEvent * event); 26 | void TSMADataMaster_OnEventPeerAdded(TGenDriverEvent * event); 27 | void TSMADataMaster_OnEventPeerRemoved(TGenDriverEvent * event); 28 | void TSMADataMaster_OnEventBusConnected(TGenDriverEvent * event); 29 | void TSMADataMaster_OnEventMasterCmdEnded( struct _TMasterCmdReq * mc); 30 | int TSMADataMaster_GetCountBusEvents(void); 31 | 32 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Build and publish container images 2 | on: 3 | release: 4 | types: [published] 5 | 6 | env: 7 | REGISTRY_REPOSITORY: ghcr.io/konstantinblaesi 8 | REGISTRY_IMAGE: yasdi 9 | 10 | jobs: 11 | build-and-publish: 12 | name: Build and publish container image 13 | strategy: 14 | matrix: 15 | arch: [amd64, arm64] 16 | containerFile: [alpine, debian] 17 | runs-on: ubuntu-latest 18 | environment: github 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | 23 | - name: Install qemu 24 | if: ${{ matrix.arch == 'arm64' }} 25 | run: | 26 | sudo apt-get update 27 | sudo apt-get install -y qemu-user-static 28 | 29 | - name: Build image 30 | id: build-image 31 | uses: redhat-actions/buildah-build@v2 32 | with: 33 | image: ${{ env.REGISTRY_IMAGE }} 34 | tags: ${{ matrix.containerFile }}-latest ${{ matrix.containerFile }}-${{ github.ref_name }} 35 | archs: ${{ matrix.arch }} 36 | containerfiles: | 37 | ./container/${{ matrix.containerFile }}.Containerfile 38 | 39 | - name: Publish image 40 | uses: redhat-actions/push-to-registry@v2 41 | with: 42 | image: ${{ steps.build-image.outputs.image }} 43 | tags: ${{ steps.build-image.outputs.tags }} 44 | registry: ${{ env.REGISTRY_REPOSITORY }} 45 | username: ${{ secrets.GH_USER }} 46 | password: ${{ secrets.GH_TOKEN }} 47 | -------------------------------------------------------------------------------- /sdk/include/chandef.h: -------------------------------------------------------------------------------- 1 | #ifndef SCHANDEF_H 2 | #define SCHANDEF_H 3 | 4 | 5 | /*********************************************************** 6 | Bit pattern of channel type ("CType") 7 | ***********************************************************/ 8 | #define CH_ANALOG 0x0001 9 | #define CH_DIGITAL 0x0002 10 | #define CH_COUNTER 0x0004 11 | #define CH_STATUS 0x0008 12 | #define CH_ALL 0x000f 13 | 14 | #define CH_IN 0x0100 15 | #define CH_OUT 0x0200 16 | #define CH_PARA 0x0400 17 | #define CH_SPOT 0x0800 18 | #define CH_MEAN 0x1000 19 | #define CH_TEST 0x2000 20 | 21 | #define CH_ANA_IN (CH_ANALOG | CH_IN) 22 | #define CH_DIG_IN (CH_DIGITAL | CH_IN) 23 | #define CH_CNT_IN (CH_COUNTER | CH_IN) 24 | #define CH_STA_IN (CH_STATUS | CH_IN) 25 | 26 | #define CH_PARA_ALL (CH_PARA | CH_ALL) 27 | #define CH_SPOT_ALL (CH_SPOT | CH_ALL) 28 | #define CH_MEAN_ALL (CH_MEAN | CH_ALL) 29 | #define CH_TEST_ALL (CH_SPOT | CH_IN | CH_ALL | CH_TEST) 30 | 31 | 32 | /*********************************************************** 33 | Bit pattern data (numeric) format (NType) 34 | ***********************************************************/ 35 | 36 | #define CH_BYTE 0x0000 37 | #define CH_WORD 0x0001 38 | #define CH_DWORD 0x0002 39 | #define CH_FLOAT4 0x0004 40 | #define CH_ARRAY 0x0008 41 | 42 | #define CH_FORM 0x000f 43 | 44 | 45 | typedef enum _TLevel 46 | { 47 | LEV_1 = 1, 48 | LEV_2, 49 | LEV_3, 50 | LEV_IGNORE 51 | } TLevel; 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | #endif 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /container/debian.Containerfile: -------------------------------------------------------------------------------- 1 | ARG BASE_IMAGE=docker.io/debian:stable-slim 2 | FROM $BASE_IMAGE as build 3 | 4 | ENV YASDI_SRC /yasdi 5 | 6 | # install build dependencies 7 | RUN apt update && apt upgrade -y 8 | RUN apt install -y build-essential cmake 9 | 10 | RUN mkdir $YASDI_SRC 11 | COPY ./sdk $YASDI_SRC 12 | 13 | # build and install yasdi 14 | RUN mkdir -p $YASDI_SRC/build 15 | WORKDIR $YASDI_SRC/build 16 | RUN cmake -D CMAKE_INSTALL_PREFIX=/usr -D YASDI_DEBUG_OUTPUT=0 $YASDI_SRC/projects/generic-cmake 17 | RUN make -j$(getconf _NPROCESSORS_ONLN) 18 | RUN make install 19 | 20 | FROM $BASE_IMAGE as publish 21 | LABEL maintainer="Konstantin Bläsi " 22 | LABEL org.opencontainers.image.source https://github.com/konstantinblaesi/yasdi 23 | LABEL org.opencontainers.image.description YASDI image containing yasdishell and the library 24 | 25 | COPY --from=build /usr/bin/yasdishell /usr/bin/ 26 | 27 | COPY --from=build \ 28 | /usr/lib/libyasdi.so.1.8.3 \ 29 | /usr/lib/libyasdi_drv_ip.so.1.8.3 \ 30 | /usr/lib/libyasdi_drv_serial.so.1.8.3 \ 31 | /usr/lib/libyasdimaster.so.1.8.3 /usr/lib/ 32 | 33 | RUN ln -s libyasdi.so.1.8.3 /usr/lib/libyasdi.so.1 34 | RUN ln -s libyasdi.so.1 /usr/lib/libyasdi.so 35 | 36 | RUN ln -s libyasdi_drv_ip.so.1.8.3 /usr/lib/libyasdi_drv_ip.so.1 37 | RUN ln -s libyasdi_drv_ip.so.1 /usr/lib/libyasdi_drv_ip.so 38 | 39 | RUN ln -s libyasdi_drv_serial.so.1.8.3 /usr/lib/libyasdi_drv_serial.so.1 40 | RUN ln -s libyasdi_drv_serial.so.1 /usr/lib/libyasdi_drv_serial.so 41 | 42 | RUN ln -s libyasdimaster.so.1.8.3 /usr/lib/libyasdimaster.so.1 43 | RUN ln -s libyasdimaster.so.1 /usr/lib/libyasdimaster.so 44 | -------------------------------------------------------------------------------- /container/alpine.Containerfile: -------------------------------------------------------------------------------- 1 | ARG BASE_IMAGE=docker.io/alpine:3.15.4 2 | FROM $BASE_IMAGE as build 3 | 4 | ENV YASDI_SRC /yasdi 5 | 6 | RUN apk update && apk upgrade 7 | # install build dependencies 8 | RUN apk update && apk add --no-cache binutils cmake make musl-dev gcc 9 | 10 | RUN mkdir $YASDI_SRC 11 | COPY ./sdk $YASDI_SRC 12 | 13 | # build and install yasdi 14 | RUN mkdir -p $YASDI_SRC/build 15 | WORKDIR $YASDI_SRC/build 16 | RUN cmake -D CMAKE_INSTALL_PREFIX=/usr -D CMAKE_C_FLAGS="-DLIBC_MUSL" -D YASDI_DEBUG_OUTPUT=0 $YASDI_SRC/projects/generic-cmake 17 | RUN make -j$(getconf _NPROCESSORS_ONLN) 18 | RUN make install 19 | 20 | 21 | FROM $BASE_IMAGE as publish 22 | 23 | LABEL maintainer="Konstantin Bläsi " 24 | LABEL org.opencontainers.image.source https://github.com/konstantinblaesi/yasdi 25 | LABEL org.opencontainers.image.description YASDI image containing yasdishell and the library 26 | 27 | COPY --from=build /usr/bin/yasdishell /usr/bin/ 28 | 29 | COPY --from=build \ 30 | /usr/lib/libyasdi.so.1.8.3 \ 31 | /usr/lib/libyasdi_drv_ip.so.1.8.3 \ 32 | /usr/lib/libyasdi_drv_serial.so.1.8.3 \ 33 | /usr/lib/libyasdimaster.so.1.8.3 /usr/lib/ 34 | 35 | RUN ln -s libyasdi.so.1.8.3 /usr/lib/libyasdi.so.1 36 | RUN ln -s libyasdi.so.1 /usr/lib/libyasdi.so 37 | 38 | RUN ln -s libyasdi_drv_ip.so.1.8.3 /usr/lib/libyasdi_drv_ip.so.1 39 | RUN ln -s libyasdi_drv_ip.so.1 /usr/lib/libyasdi_drv_ip.so 40 | 41 | RUN ln -s libyasdi_drv_serial.so.1.8.3 /usr/lib/libyasdi_drv_serial.so.1 42 | RUN ln -s libyasdi_drv_serial.so.1 /usr/lib/libyasdi_drv_serial.so 43 | 44 | RUN ln -s libyasdimaster.so.1.8.3 /usr/lib/libyasdimaster.so.1 45 | RUN ln -s libyasdimaster.so.1 /usr/lib/libyasdimaster.so 46 | -------------------------------------------------------------------------------- /sdk/core/queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2007 SMA Technologie AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "lists.h" 23 | #include "scheduler.h" 24 | #include "timer.h" 25 | 26 | //!An "message queue" 27 | typedef struct _TQueue 28 | { 29 | TList messageQueue; //the real queue to store the messages 30 | TTask * waitingTask; //optional: the (only one) task who waits for new messages in the queue 31 | TTimer * waitingTimer; //optional: timer to signal (timer is called) 32 | } TQueue; 33 | 34 | SHARED_FUNCTION void TQueue_Init (TQueue * queue); 35 | SHARED_FUNCTION void TQueue_AddMsg (TQueue * queue,TNode * node); 36 | SHARED_FUNCTION TNode * TQueue_GetMsg (TQueue * queue); 37 | SHARED_FUNCTION void TQueue_AddListenerTask(TQueue * queue, TTask * t); 38 | SHARED_FUNCTION void TQueue_AddListenerTimer(TQueue * queue, TTimer * t); 39 | SHARED_FUNCTION void TQueue_RemoveAll(TQueue * queue); 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /sdk/master/objman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef OBJMAN_H 23 | #define OBJMAN_H 24 | 25 | #define INVALID_HANDLE 0 26 | #define UNKNOWN_HANDLE 0 27 | 28 | typedef DWORD TObjectHandle; 29 | 30 | typedef struct 31 | { 32 | TObjectHandle Handle; 33 | void * RefPtr; 34 | 35 | } TObjMapEntry; 36 | 37 | 38 | 39 | /* public */ 40 | void TObjManager_Constructor( void ); 41 | void TObjManager_Destructor( void ); 42 | TObjectHandle TObjManager_CreateHandle(void * ObjPtr); 43 | void TObjManager_FreeHandle( TObjectHandle ); 44 | void * TObjManager_GetRef( TObjectHandle ); 45 | 46 | /* private */ 47 | void TObjManager_AddHandle(TObjectHandle h, void * Ref ); 48 | void TObjManager_RemHandle(TObjectHandle h, void * Ref ); 49 | TObjMapEntry * TObjManager_FindEntry( TObjectHandle h ); 50 | void TObjManager_CheckMapSize( DWORD dwAddCnt ); 51 | 52 | #ifdef DEBUG 53 | void TObjManager_Test(void); 54 | #endif 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /sdk/core/minqueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "lists.h" 23 | #include "scheduler.h" 24 | #include "timer.h" 25 | 26 | //!An "message queue" 27 | typedef struct _TMinQueue 28 | { 29 | TMinList messageQueue; //the real queue to store the messages 30 | TTask * waitingTask; //optional: the (only one) task who waits for new messages in the queue 31 | TMinTimer * waitingTimer; //optional: timer to signal (timer is called) 32 | } TMinQueue; 33 | 34 | SHARED_FUNCTION void TMinQueue_Init (TMinQueue * queue); 35 | SHARED_FUNCTION void TMinQueue_AddMsg (TMinQueue * queue,TMinNode * node); 36 | SHARED_FUNCTION TMinNode * TMinQueue_GetMsg (TMinQueue * queue); 37 | SHARED_FUNCTION void TMinQueue_AddListenerTask(TMinQueue * queue, TTask * t); 38 | SHARED_FUNCTION void TMinQueue_AddListenerTimer(TMinQueue * queue, TMinTimer * t); 39 | SHARED_FUNCTION void TMinQueue_RemoveAll(TMinQueue * queue); 40 | SHARED_FUNCTION int TMinList_Length(TMinList * queue); 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /sdk/os/os_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef OS_WINDOWS_H 23 | #define OS_WINDOWS_H 24 | 25 | 26 | //Windows Systems... 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | 38 | //Currently the windows implementation don't use Mutexes 39 | //so we set this to something... 40 | #define T_MUTEX HANDLE 41 | 42 | //Type for DLL (or "shared objects" in Unix) handle 43 | #define DLLHANDLE HMODULE 44 | 45 | //Type for a Thread handle.... 46 | #define THREAD_HANDLE HANDLE 47 | 48 | //Inline functions 49 | #define INLINE __inline 50 | 51 | //Default Delay time for YASDI scheduler (time delay while checking for next job) 52 | enum { YASDI_SCHEDULER_DELAY_TIME = 30 }; 53 | 54 | #define PATH_DELIM '\\' 55 | 56 | //reference an symbol (this could be in an external module...) 57 | #define os_GetSymbolRef(handle, ident ) os_FindLibrarySymbol( handle, #ident ) 58 | 59 | 60 | #define FORM_U32 "%u" 61 | 62 | 63 | #endif 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /sdk/driver/serial_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef SERIAL_WINDOWS_H 23 | #define SERIAL_WINDOWS_H 24 | 25 | 26 | typedef enum {SERMT_RS232, SERMT_RS485, SERMT_POWERLINE} TSerialMedia; 27 | 28 | /* unit structure (Instance of class) */ 29 | struct TSerialWindowsPriv 30 | { 31 | HANDLE fd; /* filedestriptor of serial port */ 32 | OVERLAPPED osReader; /* overlapped structure for read operations */ 33 | 34 | char cPort[30]; /* SerialPort e.g. ("/dev/ttyS0") */ 35 | TSerialMedia media; /* Medium (RS232,RS485,Powerline) */ 36 | DWORD dBaudrate; /* Bit / sec.*/ 37 | DWORD dBytesSendTotal; /* total bytes send */ 38 | }; 39 | 40 | 41 | BOOL serial_open (TDevice * dev); 42 | DWORD serial_read (TDevice * dev, BYTE * DestBuffer, DWORD dBufferSize, 43 | DWORD * DriverDevHandle); 44 | void serial_write(TDevice * dev, struct TNetPacket * frame, 45 | DWORD DriverDeviceHandle, TDriverSendFlags flags); 46 | void serial_close(TDevice * dev); 47 | TDriverEvent serial_GetSupportedEvents(TDevice * dev); 48 | 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /sdk/master/stateconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef STATECONFIG_H 23 | #define STATECONFIG_H 24 | 25 | #include "smadef.h" 26 | #include "master.h" 27 | 28 | struct _TOnReceiveInfo; 29 | 30 | /************************************************************************************ 31 | **************** Klasse TStateConfig ************************************************ 32 | ************************************************************************************/ 33 | 34 | /* 35 | ** Implementiert den Master - Zustand "Configuration" 36 | */ 37 | TMasterState * TStateConfig_GetInstance( void ); 38 | void TStateConfig_OnEnter( TMasterCmdReq * mc ); 39 | void TStateConfig_OnIOReqEnd( TMasterCmdReq * mc, 40 | struct _TIORequest * req ); 41 | int TStateConfig_GetStateIndex(TMasterCmdReq * mc); 42 | void TStateConfig_OnIOReqPktRcv( TMasterCmdReq * mc, 43 | struct _TIORequest * req, 44 | struct _TOnReceiveInfo * rcvInfo); 45 | 46 | /* private */ 47 | void TStateConfig_CheckNextDevice( TMasterCmdReq * mc ); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /sdk/core/minmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef _MAP_H_ 23 | #define _MAP_H_ 24 | 25 | typedef struct 26 | { 27 | BYTE * mapfield; 28 | int size_Of_Key, size_Of_Value, maxElementCount; 29 | int curCountElements; 30 | int (*compFunc)(const void*, const void*); 31 | }TMap; 32 | 33 | SHARED_FUNCTION void TMap_Init ( TMap * me, int sizeOfKey, int sizeOfValue, int depotElementCount, int (*compFunc)(const void*, const void*) ); 34 | SHARED_FUNCTION void TMap_Init2( TMap * me, int (*compFunc)(void* a, void* b)); //later... 35 | SHARED_FUNCTION void TMap_Free( TMap * me ); 36 | 37 | SHARED_FUNCTION TMap * TMap_Constructor( int sizeOfKey, int sizeOfValue, int depotElementCount, int (*compFunc)(const void*, const void*) ); 38 | SHARED_FUNCTION void TMap_Destructor( TMap * ); 39 | 40 | //! Adds an new entry... 41 | SHARED_FUNCTION void TMap_Add ( TMap * me, void * key, void * value ); 42 | 43 | //! Remove an entry... 44 | SHARED_FUNCTION void TMap_Remove(TMap * me, void * key); 45 | 46 | //! finds an entry 47 | SHARED_FUNCTION void * TMap_Find( TMap * me, void * key); 48 | 49 | 50 | #endif //_MAP_H_ 51 | -------------------------------------------------------------------------------- /sdk/core/fractionizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef FRACTIONIZER_H 23 | #define FRACTIONIZER_H 24 | 25 | /* private structures */ 26 | typedef struct 27 | { 28 | //PRIVATE 29 | TMinNode Node; /* zum Verketten */ 30 | 31 | //PUBLIC 32 | TMinTimer Timer; /* Timer fuer Folgepaketanforderung */ 33 | struct TSMADataHead smadata; /* Kopf des originalen SMAData-Paketes */ 34 | BYTE * Buffer; /* Pufferinhalt des original Pakets */ 35 | DWORD BufferSize; /* Size of buffer content */ 36 | DWORD DriverID; /* Device, von dem die Folgepakete empfangen werden */ 37 | } TFracPktEntry; 38 | 39 | TFracPktEntry * TFrag_FindQueuedPacket( struct TSMADataHead * SmaDataHead ); 40 | BOOL TFrag_ReceivePaket( struct TSMADataHead * SmaDataHead ); 41 | void TFrag_Constructor(void); 42 | void TFrag_Destructor(void); 43 | BOOL TFrag_MustBeFractionized(WORD DestAddr, DWORD PacketSize); 44 | void TFrag_SendPacketFractionized(WORD Dest, 45 | WORD Source, 46 | BYTE Cmd, 47 | BYTE * Data, WORD Size, 48 | DWORD Flags); 49 | 50 | //Private: 51 | void TFrag_OnTimer( TFracPktEntry * queue ); 52 | 53 | 54 | 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /sdk/core/iorequest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "os.h" 23 | #include "iorequest.h" 24 | #include "driver_layer.h" 25 | #include 26 | 27 | 28 | SHARED_FUNCTION TIORequest * TIORequest_Constructor() 29 | { 30 | TIORequest * req = os_malloc( sizeof(TIORequest) ); 31 | return req; 32 | 33 | } 34 | 35 | SHARED_FUNCTION void TIORequest_Destructor(TIORequest * req) 36 | { 37 | assert( req ); 38 | os_free( req ); 39 | } 40 | 41 | SHARED_FUNCTION TReqStatus TIORequest_GetStatus( TIORequest * req ) 42 | { 43 | assert( req ); 44 | return req->Status; 45 | } 46 | 47 | SHARED_FUNCTION void TIORequest_SetOnReceive( TIORequest * req, TIORequestOnReceiveFkt fkt ) 48 | { 49 | assert( req ); 50 | req->OnReceived = fkt; 51 | } 52 | 53 | SHARED_FUNCTION void TIORequest_SetOnEnd( TIORequest * req, TIORequestOnEndFkt fkt ) 54 | { 55 | assert( req ); 56 | req->OnEnd = fkt; 57 | } 58 | 59 | SHARED_FUNCTION void TIORequest_SetOnTransfer( TIORequest * req, TIORequestOnTransferFkt fkt ) 60 | { 61 | assert( req ); 62 | req->OnTransfer = fkt; 63 | } 64 | 65 | SHARED_FUNCTION void TIORequest_SetOnStarting( TIORequest * req, TIORequestOnStarting fkt) 66 | { 67 | assert( req ); 68 | req->OnStarting = fkt; 69 | } 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /sdk/include/compiler.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPILER_H 2 | #define __COMPILER_H 3 | 4 | 5 | 6 | //----------------------------------------------------------------------------- 7 | // 8 | //Windows Compiler specific section: This should be extracted to the 9 | //SMAlib system for compiler specific definitions. But first do it here.... 10 | // 11 | //----------------------------------------------------------------------------- 12 | 13 | 14 | //##### Microsoft Compiler specific ##### 15 | #if defined ( _MSC_VER ) || defined ( MSVCPP ) 16 | 17 | //to reduce some define stuff... 18 | #define USING_MICROSOFT_COMPILER 19 | 20 | //don't ask.... 21 | #if defined(_DLL) || defined (_WINDLL) 22 | #define __DLL__ 1 23 | #endif 24 | 25 | //building an DLL? => Mark functions with "export" 26 | //building host => Mark functions with "import" 27 | #ifdef __DLL__ 28 | #define SHARED_FUNCTION __declspec(dllexport) 29 | #else 30 | #define SHARED_FUNCTION __declspec(dllimport) 31 | #endif 32 | 33 | //disable all deprecation warnings, 34 | #if (_MSC_VER >= 1400) // VC8+ 35 | #pragma warning(disable : 4996) 36 | #endif 37 | 38 | //define it for the rest.... 39 | #ifndef __WIN32__ 40 | #define __WIN32__ 1 41 | #endif 42 | 43 | //tztzt Microsoft seams not to support C99 standards... 44 | // __func__ is C99 45 | #define __func__ __FUNCTION__ 46 | 47 | #endif 48 | 49 | 50 | //##### Borland C++Builder specific ##### 51 | #ifdef __BORLANDC__ 52 | 53 | //building an DLL? => Mark functions with "export" 54 | //building host => Mark functions with "import" 55 | #ifdef __DLL__ 56 | #define SHARED_FUNCTION __declspec(dllexport) 57 | #else 58 | #define SHARED_FUNCTION __declspec(dllimport) 59 | #endif 60 | 61 | //for precompield head with borland compilers...stop caching here... 62 | #pragma hdrstop 63 | 64 | #endif 65 | 66 | 67 | //##### GNU C compiler specific Windows ##### 68 | #ifdef __GNUC__ 69 | #ifdef _WIN32 70 | //__cdecl or winapi 71 | #define SHARED_FUNCTION __cdecl 72 | #else 73 | /* U*nix: Linux/NetBSD/MacOSX/SOLARIS/... */ 74 | #define SHARED_FUNCTION 75 | #endif 76 | 77 | #endif 78 | 79 | 80 | 81 | #endif /*__COMPILER_H*/ 82 | 83 | 84 | -------------------------------------------------------------------------------- /sdk/protocol/sunnynet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef SUNNYNET_H 23 | #define SUNNYNET_H 24 | 25 | /* Groesse des Empfangszwischenpuffers */ 26 | #define SIZE_PKTBUFFER_SUNNYNET 0x1000 27 | 28 | struct TProtocol * TSunnyNet_Constructor( void ); 29 | void TSunnyNet_Destructor(struct TProtocol * prot); 30 | 31 | void TSunnyNet_Encapsulate(struct TProtocol * prot, struct TNetPacket * frame, WORD protid); 32 | void TSunnyNet_ScanInput (struct TProtocol * prot, TDevice * dev, BYTE * Buffer, DWORD size, DWORD DriverDeviceHandel ); 33 | DWORD TSunnyNet_GetMTU( void ); 34 | 35 | struct TSunnyNetHead 36 | { 37 | BYTE Start1; 38 | BYTE Len1; 39 | BYTE Len2; 40 | BYTE Start2; 41 | }; 42 | 43 | struct TSunnyNetTail 44 | { 45 | WORD CS; 46 | BYTE Stop; 47 | }; 48 | 49 | struct TSunnyNetPriv 50 | { 51 | BOOL bWaitSync; /* Warten auf SOT im Telegram? */ 52 | BOOL bPktHeaderOk; /* Paketkopf ok? */ 53 | BYTE PktBuffer[SIZE_PKTBUFFER_SUNNYNET]; /* Empfangszwischenpuffer */ 54 | DWORD dSyncPos; /* Start-Position des Pakets */ 55 | WORD PktRecTotal; /* ??? */ 56 | DWORD PktBytesExpected; 57 | DWORD dWritePos; /* Schreibposition im Puffer */ 58 | }; 59 | 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /sdk/include/events.h: -------------------------------------------------------------------------------- 1 | #ifndef _YASDI_EVENTS_H 2 | #define _YASDI_EVENTS_H 3 | 4 | #include "lists.h" 5 | 6 | struct _TDevice; 7 | 8 | /* 9 | ** Driver Events: 10 | ** The supported Driver events 11 | ** All these events are completely optional and may not be supported by an 12 | ** device driver 13 | */ 14 | typedef WORD TDriverEvent; 15 | 16 | /* Event Bis mask */ 17 | enum 18 | { 19 | DRE_NO_EVENTS = 0, /* "PseudoEvent": No Events at all */ 20 | DRE_NEW_INPUT = 1, /* Event when new characters are available for */ 21 | /* reading from bus driver */ 22 | DRE_PEER_ADDED = 2, /* Event when an new peer is connected to the bus. */ 23 | /* (Not all drivers support this event) */ 24 | DRE_PEER_REMOVED = 4, /* Event when an peer was removed */ 25 | DRE_BUS_CONNECTED = 8, /* the bus was connected */ 26 | }; 27 | 28 | enum 29 | { 30 | INVALID_DRIVER_DEVICE_HANDLE = 0 //an invalid "Driver Device Handle", 31 | //see next structure in "DriverDeviceHandle" 32 | }; 33 | 34 | 35 | /* Driver Event for all available events types (I need OO, please...:-) ) */ 36 | typedef struct 37 | { 38 | TMinNode Node; //for linking 39 | TDriverEvent eventType; /* Event typ: DRE_PEER_ADDED or 40 | DRE_PEER_REMOVED or 41 | DRE_NEW_INPUT */ 42 | //Absender des Events ("Bus Treiber ID") 43 | DWORD DriverID; 44 | 45 | union uEventData 46 | { 47 | /* DRE_BUS_CONNECTED: */ 48 | /* DRE_PEER_ADDED: 49 | DRE_PEER_REMOVED: */ 50 | /* Event: An new peer was added to the bus. Info about the internal driver 51 | device handle of the new device */ 52 | /* Event: An devices was removed from the bus */ 53 | DWORD DriverDeviceHandle; 54 | 55 | /* DRE_NEW_INPUT: */ 56 | /* Event: New Input is available to read from driver...(with xxx_read(...) call */ 57 | int bytesAvailable; 58 | 59 | } EventData; 60 | } TGenDriverEvent; 61 | 62 | /* Callbackfunction for events */ 63 | SHARED_FUNCTION typedef void (*TOnDriverEvent)(struct _TDevice * newdev, TGenDriverEvent * event); 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /sdk/core/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef TIMER_H 23 | #define TIMER_H 24 | 25 | #include "lists.h" 26 | 27 | typedef void (*TMinTimerCallBackFunc)(void *); 28 | typedef void (*VoidFunc)(void *); 29 | 30 | 31 | typedef struct 32 | { 33 | //private 34 | TMinNode Node; /* Zum Verketten */ 35 | 36 | //public 37 | DWORD dStartTime; /* Startzeitpunkt des Timers in Sekunden (UNIX-Time, Systemzeit)*/ 38 | DWORD dStartTimeMilli; // milli seconds of start time 39 | DWORD dRunTime; /* Die Zeit in Sekunden, die der Timer laufen soll (im Bezug auf "dStartTime") */ 40 | void * UserVal; /* Wert, der der "Alarmfunktion" als Parameter �bergeben wird */ 41 | void (*AlarmFunc)(void *); /* die Funktion , die beim Ablauf des Timers aufgerufen wird */ 42 | } TMinTimer; 43 | 44 | SHARED_FUNCTION void TMinTimer_SetTime (TMinTimer * me, DWORD sec); 45 | SHARED_FUNCTION void TMinTimer_SetAlarmFunc(TMinTimer * me, TMinTimerCallBackFunc callback, void * data); 46 | SHARED_FUNCTION void TMinTimer_Start (TMinTimer * me); 47 | SHARED_FUNCTION void TMinTimer_Stop (TMinTimer * me); 48 | SHARED_FUNCTION void TMinTimer_Restart (TMinTimer * me); 49 | SHARED_FUNCTION void TMinTimer_Signal (TMinTimer * me); 50 | SHARED_FUNCTION BOOL TMinTimer_IsExpired (TMinTimer * me, DWORD seconds, DWORD milliseconds); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /sdk/include/device.h: -------------------------------------------------------------------------------- 1 | #ifndef DEVICE_H 2 | #define DEVICE_H 3 | 4 | 5 | 6 | /* Bus driver device states */ 7 | typedef enum {DS_OFFLINE, DS_ONLINE} TDeviceState; 8 | 9 | /* Flags for sending packet on Bus device */ 10 | typedef enum 11 | { 12 | DSF_MONOCAST = 0, /* send to one peer only */ 13 | DSF_BROADCAST_ALLKNOWN = 1, /* send to all known peers */ 14 | DSF_BROADCAST = 2 /* send to all known and unknown peers 15 | (real broadcast) */ 16 | } TDriverSendFlags; 17 | 18 | 19 | #include "events.h" 20 | #include "lists.h" 21 | 22 | struct TNetPacket; 23 | 24 | enum 25 | { 26 | IOCTRL_UNKNOWN_CMD = -1 //invalid command for driver "ioctrl" 27 | }; 28 | 29 | 30 | /** 31 | * Interface of an YASDI Bus Driver Device 32 | */ 33 | 34 | struct _TDevice 35 | { 36 | /*private:*/ 37 | TMinNode Node; /* List element */ 38 | 39 | /*public:*/ 40 | char cName[50]; /* Driver name */ 41 | void * priv; /* Private area of device */ 42 | TDeviceState DeviceState; /* driver state */ 43 | DWORD DriverID; /* unique driver ID */ 44 | BOOL (*Open) (struct _TDevice * device); /* open driver */ 45 | void (*Close) (struct _TDevice * device); /* close driver */ 46 | DWORD (*Read) (struct _TDevice * device, /* read from media */ 47 | BYTE * data, 48 | DWORD len, 49 | DWORD * DriverDeviceHandle); 50 | void (*Write) (struct _TDevice * device, /* write to media */ 51 | struct TNetPacket * data, 52 | DWORD DriverDeviceHandle, 53 | TDriverSendFlags flags); 54 | int (*GetMTU)(struct _TDevice * device); /* get "maximum transmit unit" */ 55 | 56 | TDriverEvent (*GetSupportedEvents) /* Get all Events which are */ 57 | (struct _TDevice * device); /* supported by */ 58 | /* the device driver (bit mask)*/ 59 | int (*IoCtrl)(struct _TDevice * device, // specific driver IO Control function 60 | int cmd, 61 | BYTE * params); 62 | 63 | }; 64 | typedef struct _TDevice TDevice; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /sdk/samples/sample1/sample1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sample1.c 3 | * 4 | * To compile sample use: 5 | * 6 | * gcc sample1.c -I../../include/ -I../../smalib -I../../libs -o sample1 -lyasdimaster 7 | * 8 | * or 9 | * 10 | * gcc sample1.c -Isdk/inc -o sample1 -lyasdimaster 11 | */ 12 | #include "libyasdimaster.h" 13 | 14 | int main(void) 15 | { 16 | int i; 17 | DWORD channelHandle=0; /* channel handle */ 18 | DWORD SerNr=0; /* Serial number of 1. Device */ 19 | DWORD DeviceHandle[10]; /* place for 10 device ID's */ 20 | int ires=0; /* result code */ 21 | DWORD dwBDC=0; /* BusDriverCount */ 22 | double value; /* Channel value */ 23 | char valuetext[17]; /* channel text value */ 24 | char cPacName[]="Pac"; /* The name of the Pac channel (current power AC) */ 25 | 26 | printf("Init yasdi master...\n"); 27 | yasdiMasterInitialize("./yasdi.ini",&dwBDC); 28 | 29 | printf("Set all available YASDI bus drivers online...\n"); 30 | for(i=0; i < dwBDC; i++) 31 | yasdiMasterSetDriverOnline( i ); 32 | if (0==dwBDC) 33 | printf("Warning: No YASDI driver was found."); 34 | 35 | printf("Start an device detection (searching 1 device)...\n"); 36 | ires = DoStartDeviceDetection(1, true); 37 | 38 | printf("Get all available devices...\n"); 39 | ires = GetDeviceHandles(DeviceHandle, 10 ); 40 | 41 | printf("Searching for channel '%s'...\n", cPacName); 42 | channelHandle = FindChannelName(DeviceHandle[0], cPacName); 43 | 44 | printf("Get channel value from '%s'...\n", cPacName); 45 | ires = GetChannelValue(channelHandle, /* chan. handle */ 46 | DeviceHandle[0], /* first device handle */ 47 | &value, /* value */ 48 | valuetext, /* text value */ 49 | 16, /* text value size */ 50 | 5 ); /* max. value age */ 51 | 52 | printf("Current Value of '%s' is '%lf'\n", cPacName, value); 53 | 54 | /* go ahead with requesting other channel values... */ 55 | 56 | printf("Shutting down YASDI...\n"); 57 | yasdiMasterShutdown( ); 58 | 59 | return (0); 60 | } /* main */ 61 | 62 | 63 | -------------------------------------------------------------------------------- /sdk/os/os_darwin.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * S M A Regelsysteme GmbH, 34266 Niestetal, Germany 3 | *************************************************************************** 4 | * Project : YASDI 5 | *************************************************************************** 6 | * Project-no. : 7 | *************************************************************************** 8 | * Filename : os_darwin.h 9 | *************************************************************************** 10 | * Description : file with operation system spezific definitions 11 | * for Apple Mac (MacOSX) alias Darwin 12 | * 13 | * Nearly the same as on Linux... 14 | *************************************************************************** 15 | * Preconditions : GNU-C-Compiler, GNU-Tools 16 | *************************************************************************** 17 | * Changes : Author, Date, Version, Reason 18 | * ********************************************************* 19 | * Pruessing, 01.03.2005, Created 20 | ***************************************************************************/ 21 | #ifndef OS_DARWIN_H 22 | #define OS_DARWIN_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | //network include for ip driver 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | 43 | #define strnicmp strncmp 44 | #define stricmp strcasecmp 45 | #define filelength os_filelength 46 | #define O_BINARY 0 47 | 48 | //Mutexes are in the pthread lib... 49 | #define T_MUTEX pthread_mutex_t 50 | 51 | 52 | //Defines type for DLL (or "shared objects" in Unix) handles 53 | #define DLLHANDLE void* 54 | 55 | //Type for a Thread handle.... 56 | #define THREAD_HANDLE pthread_t 57 | 58 | //Inline-Funktionen 59 | #define INLINE inline 60 | 61 | //Time to delay while scheduling 62 | #define YASDI_SCHEDULER_DELAY_TIME 30 63 | 64 | //The OS String identivier 65 | #define OS_ID_STRING "MacOSX" 66 | 67 | //Path separator 68 | #define PATH_DELIM '/' 69 | 70 | //Shared Library extension 71 | #define SHAREDLIB_EXT ".dylib" 72 | #define SHAREDLIB_PREFIX "lib" 73 | 74 | 75 | 76 | #endif 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /sdk/protocol/smanet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef SMANET_H 23 | #define SMANET_H 24 | 25 | /* Some consts */ 26 | enum 27 | { 28 | /* HDLC (PPP) frame specific consts */ 29 | HDLC_SYNC = 0x7e, 30 | HDLC_ESC = 0x7d, 31 | HDLC_ADR_BROADCAST = 0xff, 32 | ACCM_XOFF = 0x00040000L, /* Bit 19 ACCM */ 33 | ACCM_XON = 0x00010000L, /* Bit 17 ACCM */ 34 | ACCM_BIT0 = 0x00000001L, /* Bit 0*/ 35 | SIZE_PKTBUFFER_SMANET = 0x1000, /* internal RX buffer size */ 36 | }; 37 | 38 | 39 | struct TProtocol * TSMANet_constructor( void ); 40 | void TSMANet_destructor(struct TProtocol * prot); 41 | 42 | void TSMANet_encapsulate(struct TProtocol * prot, struct TNetPacket * frame, WORD protid); 43 | void TSMANet_scan_input (struct TProtocol * prot, TDevice * dev, BYTE * Buffer, DWORD len, DWORD DriverDeviceHandel ); 44 | 45 | DWORD TSMANet_GetMTU( void ); 46 | 47 | WORD TSMANet_CalcFCS(WORD fcs, BYTE* pCh, WORD wLen); 48 | WORD TSMANet_CalcFCSRaw(WORD fcs, BYTE* pCh, WORD wLen); 49 | 50 | typedef struct 51 | { 52 | BYTE Addr; 53 | BYTE Ctrl; 54 | WORD ProtId; 55 | } THDLCHead; 56 | 57 | 58 | 59 | 60 | struct TSMANetPriv 61 | { 62 | BOOL bEscRcv; /* Ist ein HDLC-Startzeichen empfangen worden? */ 63 | WORD FCS_In; /* Zwischenwert der Checksummenberechung */ 64 | BYTE PktBuffer[SIZE_PKTBUFFER_SMANET]; /* Empfangszwischenpuffer */ 65 | DWORD dWritePos; /* aktuelle Schreibposition im Puffer */ 66 | }; 67 | 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /sdk/core/byteorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef _CPU_BYTEORDER_H 23 | #define _CPU_BYTEORDER_H 24 | 25 | 26 | /* functions to convert from little edian byte order to the host cpu and 27 | vise versa */ 28 | /* (These functions works now cpu independent) */ 29 | 30 | SHARED_FUNCTION WORD le16ToHost ( BYTE * src ); 31 | SHARED_FUNCTION DWORD le32ToHost ( BYTE * src ); 32 | SHARED_FUNCTION float le32fToHost( BYTE * src ); 33 | SHARED_FUNCTION void hostToLe16 ( WORD val, BYTE * dst); 34 | SHARED_FUNCTION void hostToLe32 ( DWORD val, BYTE * dst); 35 | SHARED_FUNCTION void hostToLe32f( float fVal, BYTE * dst); 36 | SHARED_FUNCTION void hostToBe16 ( WORD val, BYTE * dst); 37 | SHARED_FUNCTION void hostToBe32 ( WORD val, BYTE * dst); 38 | 39 | SHARED_FUNCTION WORD be16ToHost ( BYTE * src ); 40 | SHARED_FUNCTION DWORD be32ToHost ( BYTE * src ); 41 | 42 | 43 | //Functions to move values (DWORD, WORD, float). 44 | //No convertions. Needed for for moving values on odd pointer alignments. 45 | #define MoveWORD(dst,src) os_memcpy((BYTE*)(dst), (BYTE*)(src), 2) 46 | #define MoveDWORD(dst,src) os_memcpy((BYTE*)(dst), (BYTE*)(src), 4) 47 | #define MoveFLOAT(dst,src) os_memcpy((BYTE*)(dst), (BYTE*)(src), 4) 48 | SHARED_FUNCTION void WriteWORD (BYTE * ptr, WORD val); 49 | SHARED_FUNCTION void WriteDWORD(BYTE * ptr, DWORD val); 50 | SHARED_FUNCTION void WriteFLOAT(BYTE * ptr, float val); 51 | SHARED_FUNCTION WORD GetWORD(const void * ptr); 52 | SHARED_FUNCTION DWORD GetDWORD(const void * ptr); 53 | 54 | 55 | 56 | 57 | 58 | #endif /* _CPU_BYTEORDER_H */ 59 | -------------------------------------------------------------------------------- /sdk/core/queue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2007 SMA Technologie AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "queue.h" 23 | 24 | SHARED_FUNCTION void TQueue_Init(TQueue * queue) 25 | { 26 | INITLIST( &queue->messageQueue ); 27 | queue->waitingTask = NULL; 28 | } 29 | 30 | SHARED_FUNCTION void TQueue_AddMsg (TQueue * queue, TNode * node) 31 | { 32 | /* insert element in list only thread save... */ 33 | os_thread_MutexLock( &queue->messageQueue.Mutex ); 34 | ADDTAIL( &queue->messageQueue, node ); 35 | os_thread_MutexUnlock( &queue->messageQueue.Mutex ); 36 | //if an yasdi task want's to be signaled do it now 37 | if (queue->waitingTask) 38 | { 39 | TTask_Signal( queue->waitingTask ); 40 | } 41 | if (queue->waitingTimer) 42 | { 43 | TTimer_Signal(queue->waitingTimer); 44 | } 45 | 46 | } 47 | 48 | SHARED_FUNCTION TNode * TQueue_GetMsg (TQueue * queue) 49 | { 50 | TNode * node = NULL; 51 | //enter critical section: Get first element and remove it from list (not free it) 52 | os_thread_MutexLock( &queue->messageQueue.Mutex ); 53 | if (!ISLISTEMPTY(&queue->messageQueue)) 54 | { 55 | node = (TNode*)GETFIRST(&queue->messageQueue); 56 | REMOVE(node); 57 | } 58 | os_thread_MutexUnlock( &queue->messageQueue.Mutex ); 59 | return node; 60 | } 61 | 62 | SHARED_FUNCTION void TQueue_AddListenerTask(TQueue * queue, TTask * t) 63 | { 64 | queue->waitingTask = t; 65 | }; 66 | 67 | SHARED_FUNCTION void TQueue_AddListenerTimer(TQueue * queue, TTimer * t) 68 | { 69 | queue->waitingTimer = t; 70 | }; 71 | 72 | SHARED_FUNCTION void TQueue_RemoveAll(TQueue * queue) 73 | { 74 | CLEARLIST(&queue->messageQueue); 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /sdk/core/defractionizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef DEFRACTIONIZER_H 23 | #define DEFRACTIONIZER_H 24 | 25 | #include "smadef.h" 26 | #include "timer.h" 27 | 28 | /* private structures */ 29 | typedef struct 30 | { 31 | //PRIVATE 32 | TMinNode Node; /* zum Verketten */ 33 | 34 | //PUBLIC 35 | TMinTimer Timer; /* Timer fuer Folgepaketanforderung */ 36 | struct TSMADataHead smadata; /* Kopf des "gequeueten" SMAData-Paketes */ 37 | WORD LastReqPkt; /* Nummer des zuletzt angeforderten Folgepakets (brauche WORD wegen gewollten Ueberlauf!!!!) */ 38 | BYTE ReqCount; /* Die Anzahl der Versuche, ein FolgePaket anzufornern */ 39 | DWORD LastTxFlags; /* Sendeflags fuers Anfordern von weiteren Folgepaketen (aus IORequest) */ 40 | BYTE BusDriverID; /* Device, von dem die Folgepakete empfangen werden */ 41 | struct TNetPacket * BufferList; /* Queue aller Fragmente */ 42 | BYTE MaxPktCnt; /* Zahl der Pakete, die insgesamt uebertragen werden muessen */ 43 | DWORD BusDriverDevHandle; // for internal routing of bus drivers... 44 | } TFragQueue; 45 | 46 | 47 | /* private Function */ 48 | TFragQueue * TDeFrag_FindFragQueue( struct TSMADataHead * smadata ); 49 | 50 | 51 | 52 | 53 | 54 | /* Public functions */ 55 | void TDefrag_Constructor( void ); 56 | void TDefrag_Destructor( void ); 57 | struct TNetPacket * TDeFrag_Defrag(struct TSMADataHead * smadata, 58 | struct TNetPacket * frame, 59 | DWORD Flags, 60 | BYTE * prozent ); 61 | void TDeFrag_OnTimer( TFragQueue * ); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /sdk/os/os_linux.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * S M A Regelsysteme GmbH, 34266 Niestetal, Germany 3 | *************************************************************************** 4 | * Project : Yasdi (Yet another SMA Data Implementation) 5 | *************************************************************************** 6 | * Project-no. : 7 | *************************************************************************** 8 | * Filename : os_linux.h 9 | *************************************************************************** 10 | * Description : file with operation system spezific definitions 11 | *************************************************************************** 12 | * Preconditions : GNU-C-Compiler, GNU-Tools 13 | *************************************************************************** 14 | * Changes : Author, Date, Version, Reason 15 | * ********************************************************* 16 | * Pruessing, 25.11.2001, Createt 17 | ***************************************************************************/ 18 | #ifndef OS_LINUX_H 19 | #define OS_LINUX_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #ifndef LIBC_MUSL 28 | # include 29 | #else 30 | # include 31 | # include 32 | #endif 33 | #include 34 | #include 35 | 36 | //network include for ip driver 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "smadef.h" 44 | 45 | 46 | #ifndef min 47 | #define min(a,b) ((a)>(b)?(b):(a)) 48 | #endif 49 | 50 | #ifndef max 51 | #define max(a,b) ((a)>(b)?(a):(b)) 52 | #endif 53 | 54 | #define strnicmp strncmp 55 | #define stricmp strcasecmp 56 | #define filelength os_filelength 57 | #define O_BINARY 0 58 | 59 | #define LOBYTE(a) ((a) & 0xff) 60 | #define HIBYTE(a) (((a) >> 8) & 0xff) 61 | 62 | //Mutexes are in the pthread lib... 63 | #define T_MUTEX pthread_mutex_t 64 | 65 | 66 | //Defines type for DLL (or "shared objects" in Unix) handles 67 | #define DLLHANDLE void* 68 | 69 | //Type for a Thread handle.... 70 | #define THREAD_HANDLE pthread_t 71 | 72 | //Inline-Funktionen 73 | #define INLINE inline 74 | 75 | //The delay time for the scheduler 76 | #define YASDI_SCHEDULER_DELAY_TIME 30 77 | 78 | #define OS_ID_STRING "Linux" 79 | 80 | //path separator character 81 | #define PATH_DELIM '/' 82 | 83 | //the native extension for an shared library 84 | #define SHAREDLIB_EXT ".so" 85 | #define SHAREDLIB_PREFIX "lib" 86 | 87 | 88 | #endif 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /sdk/core/repository.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef REPOSITORY_H 23 | #define REPOSITORY_H 24 | 25 | #include "smadef.h" 26 | 27 | 28 | /* 29 | * The following types are for an "virtual ini file in memory". 30 | * see "repository_memory_ext.c" 31 | */ 32 | //Entry Type of an virtual ini file... 33 | typedef enum { VIRT_ENTRY_END = 0, 34 | VIRT_ENTRY_SECTIONNAME, 35 | VIRT_ENTRY_INT, 36 | VIRT_ENTRY_STR } TVirtINIEntryType; 37 | 38 | //! An Entry of an virtual ini file... 39 | typedef struct 40 | { 41 | TVirtINIEntryType type; 42 | char * key; 43 | void * val; //int or char* 44 | } TVirtINIFileEntry; 45 | 46 | 47 | //if someone use not the "file repository" define this with Zero or near zero... 48 | #ifndef YASDI_PROGRAM_PATH 49 | #define YASDI_PROGRAM_PATH 255 50 | #endif 51 | 52 | //export the Program Path to all who include this h file... 53 | extern char ProgPath[YASDI_PROGRAM_PATH]; 54 | 55 | 56 | SHARED_FUNCTION void TRepository_Init( void ); 57 | SHARED_FUNCTION void TRepository_Destroy( void ); 58 | SHARED_FUNCTION void TRepository_GetElementStr (char * key, 59 | char * _default, 60 | char * RetBuf, 61 | int RetBufSize); 62 | SHARED_FUNCTION int TRepository_GetElementInt (char * key, int _default); 63 | SHARED_FUNCTION BOOL TRepository_GetIsElementExist (char * key ); 64 | SHARED_FUNCTION int TRepository_StoreChanList (char * DevType, BYTE * Buffer, DWORD BufferSize); 65 | SHARED_FUNCTION int TRepository_LoadChannelList (char * cDevType, BYTE ** ChanListStruct, 66 | int * BufferSize); 67 | 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /sdk/core/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "os.h" 23 | 24 | #include "timer.h" 25 | #include "scheduler.h" 26 | #include "assert.h" 27 | #include "timer.h" 28 | #include "iorequest.h" 29 | #include "debug.h" 30 | 31 | 32 | SHARED_FUNCTION void TMinTimer_SetTime(TMinTimer * me, DWORD sec) 33 | { 34 | me->dRunTime = sec; 35 | } 36 | 37 | SHARED_FUNCTION void TMinTimer_SetAlarmFunc(TMinTimer * me, void (*CallBack)(void*), void * data) 38 | { 39 | assert(me); 40 | me->AlarmFunc = CallBack; 41 | me->UserVal = data; 42 | } 43 | 44 | SHARED_FUNCTION void TMinTimer_Restart(TMinTimer * me) 45 | { 46 | assert(me); 47 | TMinTimer_Start( me ); 48 | } 49 | 50 | SHARED_FUNCTION void TMinTimer_Start(TMinTimer * me) 51 | { 52 | assert(me); 53 | me->dStartTime = os_GetSystemTime(&me->dStartTimeMilli); /* Timer l�uft...*/ 54 | TSchedule_AddTimer( me ); 55 | if (me->dRunTime > 1) 56 | { 57 | YASDI_DEBUG((VERBOSE_SCHEDULER, "Timer started (%d seconds)...\n", me->dRunTime )); 58 | } 59 | } 60 | 61 | SHARED_FUNCTION void TMinTimer_Stop(TMinTimer * me) 62 | { 63 | assert(me); 64 | me->dStartTime = 0; /* wird dadurch niemals mehr ausgel�st */ 65 | TSchedule_RemTimer( me ); 66 | } 67 | 68 | SHARED_FUNCTION void TMinTimer_Signal(TMinTimer * me) 69 | { 70 | TMinTimer_SetTime(me,0); //set time to wait to zero: Timer is now expired... 71 | me->dStartTimeMilli = 0; 72 | } 73 | 74 | //Has timer expired? True => expired False => not expired... 75 | SHARED_FUNCTION BOOL TMinTimer_IsExpired(TMinTimer * me, DWORD CurSeconds, DWORD CurMSec) 76 | { 77 | DWORD endTimeSec = me->dStartTime + me->dRunTime; 78 | if (CurSeconds < endTimeSec) return FALSE; //definitiv nicht abgelaufen... 79 | if (CurSeconds > endTimeSec) return TRUE; //definitiv abgelaufen... 80 | 81 | //we are in the right second. Check the milli seconds only now... 82 | return CurMSec >= me->dStartTimeMilli; 83 | } 84 | 85 | 86 | -------------------------------------------------------------------------------- /sdk/core/minqueue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "minqueue.h" 23 | 24 | SHARED_FUNCTION void TMinQueue_Init(TMinQueue * queue) 25 | { 26 | INITLIST( &queue->messageQueue ); 27 | queue->waitingTask = NULL; 28 | } 29 | 30 | SHARED_FUNCTION void TMinQueue_AddMsg (TMinQueue * queue, TMinNode * node) 31 | { 32 | /* insert element in list only thread save... */ 33 | os_thread_MutexLock( &queue->messageQueue.Mutex ); 34 | ADDTAIL( &queue->messageQueue, node ); 35 | os_thread_MutexUnlock( &queue->messageQueue.Mutex ); 36 | //if an yasdi task want's to be signaled do it now 37 | if (queue->waitingTask) 38 | { 39 | TTask_Signal( queue->waitingTask ); 40 | } 41 | if (queue->waitingTimer) 42 | { 43 | TMinTimer_Signal(queue->waitingTimer); 44 | } 45 | 46 | } 47 | 48 | SHARED_FUNCTION TMinNode * TMinQueue_GetMsg (TMinQueue * queue) 49 | { 50 | TMinNode * node = NULL; 51 | //enter critical section: Get first element and remove it from list (not free it) 52 | os_thread_MutexLock( &queue->messageQueue.Mutex ); 53 | if (!ISLISTEMPTY(&queue->messageQueue)) 54 | { 55 | node = (TMinNode*)GETFIRST(&queue->messageQueue); 56 | REMOVE(node); 57 | } 58 | os_thread_MutexUnlock( &queue->messageQueue.Mutex ); 59 | return node; 60 | } 61 | 62 | SHARED_FUNCTION void TMinQueue_AddListenerTask(TMinQueue * queue, TTask * t) 63 | { 64 | queue->waitingTask = t; 65 | }; 66 | 67 | SHARED_FUNCTION void TMinQueue_AddListenerTimer(TMinQueue * queue, TMinTimer * t) 68 | { 69 | queue->waitingTimer = t; 70 | }; 71 | 72 | SHARED_FUNCTION void TMinQueue_RemoveAll(TMinQueue * queue) 73 | { 74 | CLEARLIST(&queue->messageQueue); 75 | } 76 | 77 | 78 | //get the list length... 79 | SHARED_FUNCTION int TMinList_Length(TMinList * queue) 80 | { 81 | TMinList * req; 82 | int i=0; 83 | foreach_f( queue, req ) 84 | { 85 | i++; 86 | } 87 | return i; 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /sdk/core/statistic_writer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | /************************************************************************** 23 | * SMA Technologie AG, 34266 Niestetal, Germany 24 | *************************************************************************** 25 | * Project : YASDI 26 | *************************************************************************** 27 | * Project-no. : 28 | *************************************************************************** 29 | * Filename : statistic_writer.c 30 | *************************************************************************** 31 | * Description : Objekt zum Ermitteln von statistischen Werten von Yasdi 32 | * Prim�r zum Debuggen. Schreibt in zyklischen Abst�nden 33 | * statistische Informationen in eine (XML)Datei... 34 | *************************************************************************** 35 | * Preconditions : --- 36 | *************************************************************************** 37 | * Changes : Author, Date, Version, Reason 38 | * ********************************************************* 39 | * Pr�ssing, 06.10.2002, Created 40 | ***************************************************************************/ 41 | #ifndef statistic_writerH 42 | #define statistic_writerH 43 | 44 | //default is to write statistics...can be overridden from "project.h" 45 | #ifndef SUPPORT_STATISTICS 46 | #define SUPPORT_STATISTICS 1 47 | #endif 48 | 49 | #if (SUPPORT_STATISTICS == 1) 50 | void TStatisticWriter_Constructor( void ); 51 | void TStatisticWriter_Destructor( void ); 52 | SHARED_FUNCTION void TStatisticWriter_AddNewStatistic(char * statisticName, char * unit, int (*getValFunc)(void) ); 53 | #else 54 | //ok, ignore all statistics... 55 | #define TStatisticWriter_Constructor() 56 | #define TStatisticWriter_Destructor() 57 | #define TStatisticWriter_AddNewStatistic(char_p_statisticName, getValFunc ) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /sdk/core/smadata_cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2007 SMA Technologie AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | //--------------------------------------------------------------------------- 23 | #ifndef SMADATA_CMD_H 24 | #define SMADATA_CMD_H 25 | //--------------------------------------------------------------------------- 26 | 27 | //************************************************************** 28 | // SWR KOMMANDOS 29 | // 30 | #define CMD_GET_NET 1 // (Broadcast) Sunny Net Konfiguration anfordern 31 | #define CMD_SEARCH_DEV 2 // (Broadcast) SWR suchen 32 | #define CMD_CFG_NETADR 3 // (Broadcast) SWR Adresse vergeben 33 | 34 | //************************************************************** 35 | // GRUPPEN KOMMANDOS 36 | // 37 | #define CMD_SET_GRPADR 4 // Gruppenadresse vergeben 38 | #define CMD_DEL_GRPADR 5 // Gruppenadresse loeschen 39 | #define CMD_GET_NET_START 6 // (siehe CMD_GET_NET) neu 23.08.96 40 | 41 | 42 | //************************************************************** 43 | // GERAETE KONFIGURATIONS KOMMANDOS 44 | // 45 | #define CMD_GET_CINFO 9 // Geraetekonfiguration anfordern 46 | #define CMD_GET_SINFO 13 // Geraete-Storage-Information anfordern 47 | 48 | //************************************************************** 49 | // KOMMANDOS ZUR DATENERFASSUNG 50 | // 51 | #define CMD_SYN_ONLINE 10 // SWR Online Daten synchronisieren 52 | #define CMD_GET_DATA 11 // Messdaten / Parameter abrufen 53 | #define CMD_SET_DATA 12 // Daten / Parameter zum Gersste senden 54 | 55 | //*************************************************************** 56 | // KOMMANDOS ZUR MESSKANALAUFZEICHNUNG 57 | // 58 | #define CMD_GET_MTIME 20 // Abfrage, welche Kanaele aufgezeichnet werden 59 | #define CMD_SET_MTIME 21 // Einstellen, welche -"- 60 | 61 | 62 | //*************************************************************** 63 | // Commands to request binary infos 64 | // 65 | #define CMD_GET_BINFO 30 // Abfrage der Binaerinfo 66 | #define CMD_GET_BIN 31 // Abfrage der eigentlichen Binaerbereiche... 67 | 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /sdk/include/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef DEBUG_H 23 | 24 | #include 25 | #include 26 | #include "os.h" 27 | 28 | /* all software parts should be modules */ 29 | #define MODULE 30 | 31 | /* Debug Levels to switch some parts on */ 32 | #define VERBOSE_WARNING (1L) /* general warnings: every time visible */ 33 | #define VERBOSE_MESSAGE (1L<<1) /* general message : every time visible */ 34 | #define VERBOSE_ERROR (1L<<2) /* general error : every time visible */ 35 | 36 | #define VERBOSE_MISC (1L<<3) /* Misc debugs */ 37 | #define VERBOSE_HWL (1L<<4) /* Driver Layer ( Hardware Layer ) */ 38 | #define VERBOSE_SMADATALIB (1L<<5) /* SMAData Layer Object Debug */ 39 | #define VERBOSE_ROUTER (1L<<6) /* Router Object Debug */ 40 | #define VERBOSE_MASTER (1L<<7) /* SMAData-Master Debug */ 41 | #define VERBOSE_CHANNELLIST (1L<<8) /* Channellist debug */ 42 | #define VERBOSE_LIBRARY (1L<<9) /* Shared Library Debug */ 43 | #define VERBOSE_REPOSITORY (1L<<10) /* Repository (Data Access) debug */ 44 | #define VERBOSE_FRACIONIZER (1L<<11) /* Fractionizer Debug Messages*/ 45 | 46 | #define VERBOSE_BUGFINDER (1L<<12) /* special debug finder */ 47 | #define VERBOSE_PACKETS (1L<<13) /* viewing sendet packets */ 48 | #define VERBOSE_PROTLAYER (1L<<14) /* debug protocol layer... */ 49 | #define VERBOSE_BUFMANAGEMENT (1L<<15) /* debugging buffer management */ 50 | 51 | #define VERBOSE_IOREQUEST (1<<16) /* IORequests... */ 52 | #define VERBOSE_MEMMANAGEMENT (1<<17) // Memory Management 53 | #define VERBOSE_SCHEDULER (1<<18) //Scheduler/timer debugs 54 | #define VERBOSE_BCN (1<<19) //debugging bluetooth 55 | 56 | #define VERBOSE_BCNECU VERBOSE_BCN 57 | 58 | //include the project definitions for the current YASDI port... 59 | #include "project.h" 60 | 61 | #ifdef DEBUG 62 | #define YASDI_DEBUG(x) os_Debug x 63 | #define LOG(x) os_Debug x 64 | #else 65 | #define YASDI_DEBUG(x) 66 | #define LOG(x) 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /sdk/libs/libyasdimaster.def: -------------------------------------------------------------------------------- 1 | LIBRARY yasdimaster.dll 2 | 3 | EXPORTS 4 | FindDeviceSN 5 | _FindDeviceSN=FindDeviceSN 6 | DoStartDeviceDetection 7 | _DoStartDeviceDetection=DoStartDeviceDetection 8 | DoStopDeviceDetection 9 | _DoStopDeviceDetection=DoStopDeviceDetection 10 | DoFreeze 11 | _DoFreeze=DoFreeze 12 | DoMasterCmd 13 | _DoMasterCmd=DoMasterCmd 14 | FindChannelName 15 | _FindChannelName=FindChannelName 16 | GetChannelAccessRights 17 | _GetChannelAccessRights=GetChannelAccessRights 18 | GetChannelHandles 19 | _GetChannelHandles=GetChannelHandles 20 | GetChannelHandlesEx 21 | _GetChannelHandlesEx=GetChannelHandlesEx 22 | GetChannelMask 23 | _GetChannelMask=GetChannelMask 24 | GetChannelName 25 | _GetChannelName=GetChannelName 26 | GetChannelStatText 27 | _GetChannelStatText=GetChannelStatText 28 | GetChannelStatTextCnt 29 | _GetChannelStatTextCnt=GetChannelStatTextCnt 30 | GetChannelUnit 31 | _GetChannelUnit=GetChannelUnit 32 | GetChannelValRange 33 | _GetChannelValRange=GetChannelValRange 34 | GetChannelValue 35 | _GetChannelValue=GetChannelValue 36 | GetChannelValueAsync 37 | _GetChannelValueAsync=GetChannelValueAsync 38 | GetChannelValueTimeStamp 39 | _GetChannelValueTimeStamp=GetChannelValueTimeStamp 40 | GetDeviceHandles 41 | _GetDeviceHandles=GetDeviceHandles 42 | GetDeviceName 43 | _GetDeviceName=GetDeviceName 44 | GetDeviceSN 45 | _GetDeviceSN=GetDeviceSN 46 | GetDeviceType 47 | _GetDeviceType=GetDeviceType 48 | GetMasterStateIndex 49 | _GetMasterStateIndex=GetMasterStateIndex 50 | GetMasterStateText 51 | _GetMasterStateText=GetMasterStateText 52 | RemoveDevice 53 | _RemoveDevice=RemoveDevice 54 | SetChannelValue 55 | _SetChannelValue=SetChannelValue 56 | SetChannelValueString 57 | _SetChannelValueString=SetChannelValueString 58 | yasdiDoMasterCmdEx 59 | _yasdiDoMasterCmdEx=yasdiDoMasterCmdEx 60 | yasdiMasterGetDriver 61 | _yasdiMasterGetDriver=yasdiMasterGetDriver 62 | yasdiMasterGetDriverName 63 | _yasdiMasterGetDriverName=yasdiMasterGetDriverName 64 | yasdiMasterInitialize 65 | _yasdiMasterInitialize=yasdiMasterInitialize 66 | yasdiMasterSetDriverOffline 67 | _yasdiMasterSetDriverOffline=yasdiMasterSetDriverOffline 68 | yasdiMasterSetDriverOnline 69 | _yasdiMasterSetDriverOnline=yasdiMasterSetDriverOnline 70 | yasdiMasterShutdown 71 | _yasdiMasterShutdown=yasdiMasterShutdown 72 | yasdiReset 73 | _yasdiReset=yasdiReset 74 | yasdiMasterSetAccessLevel 75 | _yasdiMasterSetAccessLevel=yasdiMasterSetAccessLevel 76 | yasdiMasterGetChannelPropertyDouble 77 | _yasdiMasterGetChannelPropertyDouble=yasdiMasterGetChannelPropertyDouble 78 | yasdiMasterAddEventListener 79 | _yasdiMasterAddEventListener=yasdiMasterAddEventListener 80 | yasdiMasterRemEventListener 81 | _yasdiMasterRemEventListener=yasdiMasterRemEventListener 82 | yasdiMasterGetVersion 83 | _yasdiMasterGetVersion=yasdiMasterGetVersion 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /sdk/master/plant.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef PLANT_H 23 | #define PLANT_H 24 | 25 | 26 | /************************************************************************** 27 | ********************** Klasse TPlant (PV-Anlage) ************************** 28 | **************************************************************************/ 29 | 30 | /******* Eine Instanz des Objektes gibt es nur einmal. Daher wird der ***** 31 | ******* Instanzzeiger nicht bei jeder Memberfunktion durchgereicht *******/ 32 | 33 | typedef struct 34 | { 35 | /* public */ 36 | TDeviceList * DevList; /* Liste aller Geraete */ 37 | 38 | /* private */ 39 | char Name[30]; /* Anlagenname */ 40 | } TPlant; 41 | 42 | extern TPlant Plant; 43 | 44 | 45 | void TPlant_Constructor( void ); 46 | void TPlant_Destructor( void ); 47 | void TPlantName_SetName(char *); 48 | char * TPlantName_GetName( void ); 49 | TNetDevice * TPlant_FindSN(DWORD sn); 50 | TNetDevice * TPlant_FindDevAddr(WORD NetAddr); 51 | DWORD TPlant_GetCount( void ); 52 | void TPlant_AddDevice( TPlant * plant, TNetDevice * parent, TNetDevice * NewDev ); 53 | void TPlant_RemDevice( TPlant * plant, TNetDevice * RemDev); 54 | void TPlant_Clear( void ); 55 | 56 | TNetDevice * TPlant_ScanGetNetBuf( TPlant * me, 57 | BYTE * buf, 58 | DWORD dBytes, 59 | WORD wNetAddr, 60 | DWORD rxflags, 61 | BOOL * isNew, 62 | DWORD BusDriverDeviceHandle); 63 | 64 | BOOL TPlant_CheckNetAddrCollision( TPlant * me, TNetDevice * dev ); 65 | WORD TPlant_GetUniqueNetAddr( TPlant * me, TNetDevice * dev, WORD RangeLow, WORD RangeHigh ); 66 | int TPlant_StoreChanList( BYTE * Buffer, DWORD BufferSize, char * DevType); 67 | int TPlant_CreateChannels(TNetDevice * dev); 68 | THandleList * TPlant_GetDeviceList( void ); 69 | 70 | /* private */ 71 | int TPlant_ScanChanInfoBuf(BYTE * Buffer, DWORD BufferSize, TChanList * ChanList); 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /sdk/master/chanvalrepo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef _CHANVALREPO_H_ 23 | #define _CHANVALREPO_H_ 24 | 25 | #include "netdevice.h" 26 | #include "objman.h" 27 | #include "minmap.h" 28 | 29 | 30 | 31 | /* 32 | * Funktionsweise: "Speicherung von Kanalwerten" 33 | * 34 | * Es wird eine "Map" verwendet, bei der der "Key" das Kanalhandle ist und 35 | * "Value" ein ByteOffsetwert in den Bloc der Kanalwerte ist. 36 | * Im hoechsten Bit des Kanalhandles (bit 31) wird vermert, ob der Kanalwert 37 | * gueltig ist. 38 | * 39 | * Der Zeitstempel des Kanalwertes wird ausserhalb vermerkt, da er gruppenweise 40 | * identisch ist (jeweils fuer Parameter, Momentan und Testkanal) 41 | * 42 | * 43 | * 44 | * 45 | * 46 | */ 47 | 48 | struct TChanList; 49 | 50 | 51 | //! This class buffers all online channel values of an devices 52 | typedef struct _TChanValRepo 53 | { 54 | TMap map; //the map that holds Channelhandle and byteoffset of channelvalue... 55 | WORD sizeOfBlock; 56 | BYTE * chanvalueblock; //the memory block with all values 57 | 58 | //the channel time values... 59 | DWORD timeOnlineChannels; 60 | DWORD timeParamChannels; 61 | DWORD timeTestChannels; 62 | 63 | } TChanValRepo; 64 | 65 | DWORD TChanValRepo_GetTimeStamp(TChanValRepo * this, TChannel * chan); 66 | void TChanValRepo_SetTimeStamp(TChanValRepo * this, TChannel * chan, DWORD time); 67 | 68 | 69 | 70 | //!Constructs an new repo... 71 | TChanValRepo * TChanValRepo_Constructor(TChanList * chanList); 72 | 73 | //!Frees all cached channel values... 74 | void TChanValRepo_Destructor(struct _TChanValRepo * this); 75 | 76 | 77 | //!is Value valid? 78 | BOOL TChanValRepo_IsValueValid(TChanValRepo * this, TObjectHandle chanHandle ); 79 | 80 | void TChanValRepo_SetValueValid(TChanValRepo * this, TObjectHandle chanHandle, BOOL val ); 81 | 82 | 83 | //! get the value pointer to the memory of the value 84 | void * TChanValRepo_GetValuePtr(TChanValRepo * this, TObjectHandle chanHandle); 85 | 86 | 87 | 88 | #endif //_CHANVALREPO_H_ 89 | -------------------------------------------------------------------------------- /sdk/core/tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef TOOLS_H 23 | #define TOOLS_H 24 | 25 | SHARED_FUNCTION char * Trim( char * str, int iStrLen ); 26 | SHARED_FUNCTION int Tools_GetFileSize(void * fd); 27 | SHARED_FUNCTION BOOL Tools_StartsWith (const char *sz, const char *key); 28 | 29 | //Path functions... 30 | SHARED_FUNCTION void Tools_PathAdd(char * Dst, char * Src); 31 | SHARED_FUNCTION BOOL Tools_PathIsRelativ(char * str); 32 | SHARED_FUNCTION int Tools_PathExtractPath(char * cPathFile, char * DestString, int MaxStrSize); 33 | SHARED_FUNCTION int Tools_PathExtractFile(char * cPathFile, char * DestString, int MaxStrSize); 34 | SHARED_FUNCTION BOOL Tools_FileExists( char * file ); 35 | SHARED_FUNCTION int Tools_mkdir_recursive(char * dirname); 36 | 37 | 38 | 39 | 40 | // 41 | //functions and structures for SMAData packet memory transfers... 42 | // 43 | 44 | //an virtual (memory) buffer 45 | typedef struct 46 | { 47 | union 48 | { 49 | BYTE *b; 50 | WORD *w; 51 | DWORD *dw; 52 | float *f; 53 | } buffer; 54 | int size; //size of buffer in bytes! 55 | } TVirtBuffer; 56 | 57 | //type of memory... 58 | typedef enum 59 | { 60 | BYTE_VALUES, 61 | WORD_VALUES, 62 | DWORD_VALUES, 63 | FLOAT_VALUES 64 | } TValueType; 65 | 66 | //!count= count of values (NOT size on bytes) 67 | SHARED_FUNCTION int Tools_CopyValuesFromSMADataBuffer(TVirtBuffer * dst, 68 | TVirtBuffer * src, 69 | TValueType valtyp, 70 | int valCount); 71 | 72 | SHARED_FUNCTION int Tools_CopyValuesToSMADataBuffer(TVirtBuffer * dst, 73 | TVirtBuffer * src, 74 | TValueType valtyp, 75 | int valCount); 76 | 77 | //check for even pointer. Needed for cpu's who are unable to deal with odd pointers... 78 | //#define POINTER_MUST_EVEN(ptr) assert(((DWORD)ptr & 3) == 0) 79 | #define POINTER_MUST_EVEN(ptr) 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /sdk/core/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2007 SMA Technologie AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | /************************************************************************** 23 | * S M A Regelsysteme GmbH, 34266 Niestetal, Germany 24 | *************************************************************************** 25 | * Project : YASDI 26 | *************************************************************************** 27 | * Project-no. : 28 | *************************************************************************** 29 | * Filename : protocol.h 30 | *************************************************************************** 31 | * Description : Interface Protokol 32 | *************************************************************************** 33 | * Preconditions : GNU-C-Compiler, GNU-Tools 34 | *************************************************************************** 35 | * Changes : Author, Date, Version, Reason 36 | * ********************************************************* 37 | * Pruessing, 20.04.2001, Created 38 | ***************************************************************************/ 39 | #ifndef PROTOCOL_H 40 | #define PROTOCOL_H 41 | 42 | struct TProtocol; 43 | 44 | //!Interface to an transport protocol (SunnyNet oder SMANet currently) 45 | struct TProtocol 46 | { 47 | char cName[30]; /* name of this protocol */ 48 | void (*encapsulate)(struct TProtocol * prot, /* Paket in Protokoll verpacken */ 49 | struct TNetPacket * frame, 50 | WORD protid); 51 | void (*Scan)(struct TProtocol * prot, /* liest von der Schnittstelle */ 52 | TDevice * dev, 53 | BYTE * Buffer, 54 | DWORD len, 55 | DWORD DriverDeviceHandel ); 56 | DWORD (*GetMTU)( void ); /* liefert die "Maximum Transmit Unit" */ 57 | struct TProtocol * next; /* Zur verkettung mehrerer Protokolle */ 58 | WORD TransportProtID; /* the transport protocol ID of this protocol */ 59 | void * priv; /* Zeiger auf private Daten der Instanz */ 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /sdk/core/router.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef ROUTER_H 23 | #define ROUTER_H 24 | 25 | #include "lists.h" 26 | #include "netpacket.h" 27 | 28 | //#define HOST_ADDR_MASK 0xffff 29 | 30 | #define ROUTER_TASK_TIME (5*60+1) /* Die Zeit, die der RouterServiceTask aufgerufen wird */ 31 | #define MAX_TAB_ENTRIES 200 /* Maximale Anzahl von Routen in der Routingliste */ 32 | #define MAX_TIME_ROUTE (5*60) /* die Zeit, die ein unbenutzter Routingeintrag in 33 | der Tabelle hoechstens verweilt... */ 34 | 35 | 36 | typedef enum { RT_DYNAMIC, RT_STATIC } /* Routentyp */ 37 | TRouteType; 38 | 39 | typedef struct 40 | { 41 | TMinNode Node; // for linking 42 | WORD Addr; // SMAData1 network address 43 | BYTE BusDriverID; // the YASDI bus driver ("adapter") => destination 44 | DWORD BusDriverPeer; // the YASDI handle of the peer of the device driver (optional) 45 | DWORD Time; // the time of last access of this route 46 | TRouteType RouteType; // static or dynamic route? 47 | } TRouteTabEntry; 48 | 49 | 50 | /* PUBLIC: */ 51 | void TRouter_constructor( void ); 52 | void TRouter_destructor( void ); 53 | BOOL TRouter_DoTxRoute(TSMAData * smadata, struct TNetPacket * frame); 54 | void TRouter_AddRoute (WORD Addr, TRouteType type, BYTE bBusDriverID, DWORD dwBusDriverPeer); 55 | void TRouter_TaskEntryPoint( void ); 56 | SHARED_FUNCTION void TRouter_RemoveRoute(WORD Addr); 57 | SHARED_FUNCTION void TRouter_ClearTable( void ); 58 | 59 | /* private: */ 60 | TRouteTabEntry * TRoute_FindRouteEntry(WORD Addr); 61 | BOOL TRoute_FindRoute(WORD Addr, DWORD * DriverID, DWORD * dwBusDriverPeer); 62 | 63 | TRouteTabEntry * TRouteTabEntry_constructor(WORD Addr, 64 | TRouteType type, 65 | BYTE bBusDriverID, 66 | DWORD dwBusDriverPeer, 67 | DWORD time 68 | ); 69 | void TRouteTabEntry_destructor( TRouteTabEntry * ); 70 | SHARED_FUNCTION BOOL TRoute_FindAddrByDriverDevicePeer(DWORD dwBusDriver, DWORD dwBusDriverPeer, WORD * sd1addr); 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /sdk/smalib/smadef.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * S M A Technologie AG, 34266 Niestetal 3 | *************************************************************************** 4 | * 5 | * Include SMADEF.H defines basic data types used by SMA software 6 | * 7 | *************************************************************************** 8 | * PREFIX : - 9 | *************************************************************************** 10 | * STATUS : rfc 11 | *************************************************************************** 12 | * REMARKS: MUST be used for all new files 13 | *************************************************************************** 14 | * 15 | * HISTORY: 16 | * 17 | * XXX DD.MM.JJ DESCRIPTION 18 | * ------------------------------------------------------------------------ 19 | * CA 09.04.98 Created 20 | * CA 27.04.98 change define from _SMADEFINES to _SMADEFINE_98 to seperate 21 | * from old smadefs.h 22 | * 23 | *************************************************************************** 24 | * 25 | * TODO: - 26 | * 27 | ***************************************************************************/ 28 | 29 | #ifndef _SMADEFINES_98 30 | #define _SMADEFINES_98 31 | 32 | 33 | /************************************************************************** 34 | * C O N S T A N T S / D E F I N E S 35 | ***************************************************************************/ 36 | 37 | /* Globale Konstanten ****************************************************/ 38 | 39 | #ifndef TRUE 40 | #define TRUE (1 == 1) 41 | #define FALSE (1 == 0) 42 | #endif 43 | 44 | #ifndef false 45 | #define false FALSE 46 | #endif 47 | 48 | #ifndef true 49 | #define true TRUE 50 | #endif 51 | 52 | /* Types *****************************************************************/ 53 | 54 | //Already defined on windows systems 55 | #ifndef WIN32 56 | typedef int BOOL; 57 | typedef unsigned int BIT; /* Prefix bit */ 58 | typedef char CHAR; /* Prefix c, 8 bit signed */ 59 | typedef unsigned char BYTE; /* Prefix b, 8 bit unsigned */ 60 | typedef short SHORT; /* Prefix s, 16 bit signed */ 61 | typedef unsigned short WORD; /* Prefix w, 16 bit unsigned */ 62 | typedef long LONG; /* Prefix l, 32 bit signed */ 63 | typedef float FLOAT; /* Prefix f, 32 bit */ 64 | typedef double DOUBLE; /* Prefix dbl, 64bit */ 65 | 66 | // Windows defines DWORD as unsigned long (in "windef.h") 67 | // Because of 64 bit systems (UNIX), this must be "unsigned int" 68 | typedef unsigned int DWORD; /* 32 bit unsigned */ 69 | #endif 70 | 71 | typedef void* XPOINT; 72 | 73 | /************************************************************************** 74 | * M A C R O D E F I N I T I O N S 75 | ***************************************************************************/ 76 | 77 | /************************************************************************** 78 | * Mark not used variables -> eliminates compiler warning 79 | ***************************************************************************/ 80 | #define UNUSED_VAR(var) (var) = (var) 81 | 82 | 83 | 84 | #endif /* ... ifdef _SMADEFINES */ 85 | 86 | /*EOF*/ 87 | 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## YASDI SDK for SMA Inverters 2 | 3 | ### Disclaimer 4 | 5 | This repository is mostly meant to be a mirror for the [SDK sources provided by SMA](https://www.sma.de/en/products/apps-software/yasdi.html) found in the [sdk](sdk) 6 | directory of this repository to make things more convenient and definitely not actively developed by me. 7 | 8 | ### Building 9 | 10 | Assuming you have the needed build tools like gcc, cmake, make, etc. installed: 11 | 12 | ``` 13 | mkdir build && cd build 14 | cmake ../sdk/projects/generic-cmake 15 | make -j$(getconf _NPROCESSORS_ONLN) 16 | ``` 17 | 18 | Or refer to the build instructions provided by the [authors of this SDK](sdk/README) 19 | 20 | ### Example YASDI configuration file 21 | 22 | ``` 23 | [DriverModules] 24 | Driver0=libyasdi_drv_serial 25 | 26 | [COM1] 27 | Device=/dev/ttyUSB0 28 | Media=RS485 29 | Baudrate=1200 30 | Protocol=SMANet 31 | 32 | [Misc] 33 | DebugOutput=/dev/stderr 34 | ``` 35 | 36 | #### Running 37 | 38 | Create a file yasdi.ini in the build directory (where yasdishell is) with the 39 | [contents from the example](#example-yasdi-configuration-file) 40 | 41 | This configuration file assumes 42 | * RS485: you used cabling topology (daisy chained inverters) for the RS485 protocol 43 | * /dev/ttyUSB0: YASDI communicates with your inverters via this serial to usb converter 44 | 45 | When yasdishell is started it tries to load the shared libraries libyasdi* files from the system directories. 46 | This will not work unless you installed YASDi using `make install`. 47 | 48 | If you didn't `make install` YASDI and want yasdishell to use the libyasdi* library from the build directory 49 | you need to set LD_LIBRARY_PATH: 50 | 51 | ``` 52 | # assuming you are in the build directory: 53 | export LD_LIBRARY_PATH=$(pwd) 54 | ``` 55 | 56 | If sma.ini and yasdishell are in the same directory run using `./yasdishell` 57 | 58 | If sma.ini is in a different place run using `./yasdishell /path/to/sma.ini` 59 | 60 | ### Building the container image 61 | 62 | From the root of the repository: 63 | 64 | `podman build -t yasdi -f container/alpine.Containerfile .` 65 | 66 | (If you you docker, replace 'podman' with 'docker') 67 | 68 | ### Running the container image 69 | 70 | Create a configuration file `/yasdi/yasdi.ini` on the host adapting [the example](#example-yasdi-configuration-file) to your needs 71 | 72 | Run the container image mounting the configuration file's directory 73 | 74 | `podman run --rm -it --name yasdi -v /yasdi/yasdi.ini:/yasdi/yasdi.ini:rw yasdi yasdishell` 75 | 76 | ### Using images built and published by githubs CI/CD 77 | 78 | Install from the command line: 79 | 80 | `podman pull ghcr.io/konstantinblaesi/yasdi:latest` 81 | 82 | (replace 'podman' with 'docker' when using docker) 83 | 84 | Use as base image in Dockerfile: 85 | `FROM ghcr.io/konstantinblaesi/yasdi:latest` 86 | 87 | See the [github container registry](https://github.com/konstantinblaesi/yasdi/pkgs/container/yasdi) for all the available tags 88 | 89 | ### Common issues 90 | 91 | Some error messages produced by the YASDI SDK when running yasdishell are confusing because they do not necessarily identify the root cause. 92 | 93 | Error message 94 | >ERROR: YASDI ini file was not found or is unreadable! 95 | 96 | Possible Causes: 97 | * YASDI ini file unavailable (missing, permission issues) 98 | * The YASDI SDK failed to initialize because libyasdi* library files could not be loaded -------------------------------------------------------------------------------- /sdk/core/mempool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef MEMPOOL_H 23 | #define MEMPOOL_H 24 | 25 | /** @defgroup mempool TMemPool 26 | * This is an easy to use memory pool using an fixed size of memory elements. 27 | * @{ 28 | */ 29 | 30 | //! Flags for allocating an new element 31 | enum { 32 | //MP_INFINITE_COUNT = 0xffff, //!< unlimited count of allocating elements... 33 | MP_CLEAR=1, //!< clear the memory 34 | MP_NOFLAGS=0 //!< dummy flag for "no flags"... 35 | }; 36 | #define MP_INFINITE_COUNT 0xffffL //!< unlimited count of allocating elements... 37 | 38 | typedef struct 39 | { 40 | TMinList poolList; //list of unsed memory pieces 41 | BYTE * preAllocElems; //mem area of pre allocated elements (as one block) 42 | int mincount; //count of elements which are allocated in the beginning... 43 | int maxcount; //the maximum count of elements 44 | int currcount; //current count of used elements 45 | int elementsize; //the size of an element... 46 | BOOL threading; //Make the pool threadsave 47 | 48 | } TMemPool; 49 | 50 | 51 | /** Allocates an new (dynamic) memory pool 52 | * @param mincount minimal count of elements 53 | * @param maxcount maximal count of elements (currently not used) 54 | * @param elementsize size of one element 55 | * @param threadSave must be threadsave? 56 | * @return An new allocated and init memory pool structure... 57 | */ 58 | SHARED_FUNCTION TMemPool * TMemPool_Constructor(int mincount, 59 | int maxcount, 60 | int elementsize, 61 | BOOL threadSave); 62 | /** Init an memory pool (static) 63 | * 64 | * parameter @see TMemPool_Constructor 65 | */ 66 | SHARED_FUNCTION void TMemPool_Init(TMemPool * me, 67 | int mincount, 68 | int maxcount, 69 | int elementsize, 70 | BOOL threadSave); 71 | SHARED_FUNCTION void TMemPool_Destructor(TMemPool * me); 72 | SHARED_FUNCTION void TMemPool_Free(TMemPool * me); 73 | 74 | SHARED_FUNCTION void * TMemPool_AllocElem( TMemPool * me, BYTE flags ); 75 | SHARED_FUNCTION void TMemPool_FreeElem(TMemPool * me, void * elem ); 76 | 77 | /** @} */ // end of mempool 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /sdk/core/scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef SCHEDULE_H 23 | #define SCHEDULE_H 24 | 25 | #include "timer.h" 26 | 27 | //Task Flags 28 | enum { 29 | TF_INTERVAL_ETERNITY = 0xffffffff //Task will not be schedules periodic 30 | //will only be waken up when signaled... 31 | }; 32 | 33 | 34 | struct _TTask 35 | { 36 | //private 37 | TMinNode node; 38 | struct _TTask * next; 39 | DWORD dwLastActivate; /* letzte Aktivierung (Systemzeit) */ 40 | DWORD dwTimeInterval; /* Zeit in Sekunden im Bezug auf "dwLastActivate", 41 | wann naechste Aktivierung stattfinden soll 42 | "0" bedeutet, so schnell wie moeglich... */ 43 | void * UserVal; /* Der Wert wird als 1. Parameter der Taskfunktion 44 | uebergeben */ 45 | //public 46 | void (*TaskFunc)(void * UserVal); 47 | DWORD dFlags; 48 | BOOL signaled; //Is Thread signaled? 49 | }; 50 | typedef struct _TTask TTask; 51 | 52 | /* public */ 53 | SHARED_FUNCTION void TTask_Init (TTask * me); 54 | void TTask_SetLastActivate (TTask * me, DWORD time); 55 | SHARED_FUNCTION void TTask_SetTimeInterval (TTask * me, DWORD time); 56 | SHARED_FUNCTION void TTask_SetEntryPoint (TTask * me, void * TaskFunc, void * UserVal); 57 | DWORD TTask_GetLastActivate(TTask * me); 58 | SHARED_FUNCTION DWORD TTask_GetTimeInterval(TTask * me); 59 | void TTask_Signal (TTask * me); 60 | SHARED_FUNCTION void TTask_Init2(TTask * me, 61 | void * TaskFunction, 62 | DWORD intervaltime); 63 | 64 | 65 | 66 | 67 | 68 | /* public */ 69 | SHARED_FUNCTION void TSchedule_Constructor( void ); 70 | SHARED_FUNCTION void TSchedule_Destructor( void ); 71 | SHARED_FUNCTION void TSchedule_DoScheduling( void ); 72 | SHARED_FUNCTION void TSchedule_StopScheduling( void ); 73 | SHARED_FUNCTION BOOL TSchedule_IsScheduling( void ); 74 | SHARED_FUNCTION BOOL TSchedule_AddTask( TTask * ); 75 | SHARED_FUNCTION void TSchedule_RemTask( TTask * ); 76 | SHARED_FUNCTION void TSchedule_AddTimer( TMinTimer * ); 77 | SHARED_FUNCTION void TSchedule_RemTimer( TMinTimer * ); 78 | SHARED_FUNCTION BOOL TSchedule_Freeze(BOOL bval); 79 | SHARED_FUNCTION BOOL TSchedule_IsFreeze( void ); 80 | 81 | 82 | 83 | 84 | /* private */ 85 | SHARED_FUNCTION void TSchedule_MainExecute( void); 86 | void TSchedule_CheckForRecFrames( void ); 87 | void TSchedule_ReceiverThreadMain( void ); 88 | int CheckNextTimer( void ); 89 | 90 | 91 | 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /sdk/core/prot_layer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | /************************************************************************** 23 | * Project : YASDI 24 | *************************************************************************** 25 | * Project-no. : 26 | *************************************************************************** 27 | * Filename : prot_layer.h 28 | *************************************************************************** 29 | * Description : Protokollschicht (Layer 2) 30 | *************************************************************************** 31 | * Preconditions : GNU-C-Compiler, GNU-Tools 32 | *************************************************************************** 33 | * Changes : Author, Date, Version, Reason 34 | * ********************************************************* 35 | * Pruessing, 20.04.2001, Created 36 | ***************************************************************************/ 37 | #ifndef PROTLAYER_H 38 | #define PROTLAYER_H 39 | 40 | #include "frame_listener.h" 41 | #include "device.h" 42 | #include "sunnynet.h" 43 | #include "smanet.h" 44 | 45 | /* The internal transport protocol ID, defines for each transport protocol. 46 | ** Currently SMANet and SunnyNet or "AllAvailable" 47 | */ 48 | typedef WORD TProtID; 49 | 50 | 51 | /* all available transport protocols */ 52 | enum 53 | { 54 | PROT_SMANET = 8, /* internal protcol ID of the SMANet */ 55 | PROT_SUNNYNET = 16,/* internal protcol ID of the SunnyNet */ 56 | PROT_ALL_AVAILABLE = PROT_SMANET | PROT_SUNNYNET, /* Flag: Means all available prots (SUNNYNET and SMANET) */ 57 | }; 58 | 59 | 60 | 61 | /* 62 | ** Abbildung von Protokollnamen auf deren Konstruktoren.... 63 | */ 64 | struct TProtocolTable 65 | { 66 | TProtID prodid; /* the protocol ID of this protcol */ 67 | char * ProtName; 68 | struct TProtocol * (*Constructor)(void); 69 | void (*Destructor)(struct TProtocol *); 70 | }; 71 | 72 | 73 | 74 | /* public prototyps */ 75 | SHARED_FUNCTION void TProtLayer_WriteFrame(struct TNetPacket * frame, WORD protid); 76 | SHARED_FUNCTION void TProtLayer_AddFrameListener(TFrameListener *); 77 | SHARED_FUNCTION WORD TProtLayer_GetAllProtocols( void ); 78 | 79 | void TProtLayer_Constructor(TMinList * DeviceList); 80 | void TProtLayer_Destructor( void ); 81 | int TProtLayer_RegisterProtocol(struct TProtocol * newdev); 82 | BOOL TProtLayer_ScanInput(TDevice * dev); 83 | void TProtLayer_NotifyFrameListener(struct TNetPacket * frame, WORD protid); 84 | SHARED_FUNCTION DWORD TProtLayer_GetMTU( DWORD DriverID ); 85 | 86 | 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /sdk/README: -------------------------------------------------------------------------------- 1 | YASDI 2 | ----- 3 | 4 | 1) Introduction 5 | 6 | YASDI is an implementation library for communication with 7 | SMA String Inverters (aka "Sunny Boys"). The name "YASDI" stands for 8 | "(Y)et (A)nother (S)MA (D)ata (I)mplementation" and means the implementation 9 | of the communication protocol "SMAData" via "SunnyNet" and "SMANet". 10 | 11 | Functioning as a driver system without its own graphical interface, 12 | the software implements the communication over serial port and ethernet/UDP 13 | connections. 14 | 15 | The software has been designed in such a way that it can be easily adapted 16 | to other environments (operating systems). At the time of this document's 17 | release, there exist adaptations for 18 | 19 | - Windows32 20 | - WindowsCE 21 | - Linux (BE + LE: x86, ARM, XScale, M68k, PowerPC, ...) 22 | - MacOSX (Darwin) 23 | - Solaris 24 | - RTOS/RTKernel32 25 | - AmigaOS ;-) 26 | 27 | All system-dependent functions are abstracted from the operating system 28 | via an interface. The software is written in "C", and allows maximum possible 29 | portability to other possible target platforms. Although an object-oriented 30 | language is not used, there is nevertheless an attempt made to realize an 31 | object-oriented structure with the "C" language. The implementations for 32 | Windows and Linux are executed as libraries (Windows: DLL, Linux: SO). 33 | Another utilization, for example as part of a "monolithic" program, is also 34 | possible. YASDI primarily implements the master functionality of the 35 | SMA Data Protocol. Slave functions can also be easily implemented by utilizing 36 | the rudimentary functions for sending and receiving packets. 37 | 38 | You will find the complete description of the API in an separate document. 39 | 40 | 41 | 42 | 2) Building YASDI from source with CMake 43 | 44 | YASDI can be built with CMake. See www.cmake.org for more details... 45 | 46 | 47 | 2.1) Windows 48 | 49 | 2.1.1) MinGW 50 | 51 | To create MinGW makefiles: 52 | 53 | $> cd 54 | $> cd projects/generic-cmake 55 | $> mkdir build-mingw 56 | $> cd build-mingw 57 | $> cmake -G "MSYS Makefiles" .. 58 | $> make 59 | 60 | 61 | 62 | 2.1.2) Microsoft Visual Studio 63 | 64 | If you want to create Visual studio project files enter the following after a DOS command prompt: 65 | 66 | DOS> cd 67 | DOS> cd projects/generic-cmake 68 | DOS> mkdir build-vcpp 69 | DOS> cd build-build-vcpp 70 | DOS> cmake -G "Visual Studio 8 2005" . 71 | 72 | Now open "ALL_BUILD.vcproj" with visual c++ and compile it. 73 | 74 | 75 | 76 | 2.2) Linux and MacOSX (for GCC compiler systems) 77 | 78 | Building GNU makefiles with Linux or MacOSX: 79 | 80 | $Bash> cd 81 | $Bash> cd projects/generic-cmake 82 | $Bash> mkdir build-gcc 83 | $Bash> cd build-gcc 84 | $Bash> cmake .. 85 | $Bash> make 86 | $Bash> sudo make install 87 | 88 | 89 | 3) Running 90 | 91 | It is possible to use a simple shell tool for the YASDI with 92 | "yasdishell yasdi.ini" on all systems. This tool is not YASDI itself, but only an 93 | very simple demo program testing communication with devices with 94 | YASDI shared libs... 95 | 96 | The file "yasdi.ini" contains some configurations for the 97 | environment you use. It is possibly required to adjust some entries to fit your 98 | environment (e.g. COM/TTY interfaces...). 99 | 100 | 101 | -------------------------------------------------------------------------------- /sdk/driver/ip_generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef IP_LINUX_H 23 | #define IP_LINUX_H 24 | 25 | /* 26 | ** Because this driver is NOT part of the core YASDI framework ( :-) ) 27 | ** we can use here compiler macros to adjust the differences between 28 | ** some systems. This makes this driver "generic" possible... 29 | */ 30 | 31 | //POSIX systems (Linux, Mac....) 32 | #if defined(__APPLE__) || defined( linux ) 33 | #define SOCKET_ERROR -1 34 | #define INVALID_SOCKET -1 35 | #define WSAECONNRESET -1 /* gibt's nicht... */ 36 | #define GET_IP_ADDR_AS_DWORD(addr) ((DWORD)addr->sin_addr.s_addr) 37 | #define closesocket(a) close(a) 38 | #define ioctlsocket(a,b,c) ioctl(a,b,c) 39 | #define WSAGetLastError() errno 40 | #endif 41 | //for windows32 systems... 42 | #if defined(__WIN32__) 43 | #define GET_IP_ADDR_AS_DWORD(addr) ((DWORD)addr->sin_addr.S_un.S_addr) 44 | #endif 45 | 46 | 47 | 48 | enum 49 | { 50 | RECVBUFFERSIZE = 1500, /* Size of the send and receive packet buffer */ 51 | DEFAULT_SMADATAPORT = 24272, /* official SMAData over IP port */ 52 | }; 53 | 54 | 55 | /* List entry to store all communication partners ("peers") */ 56 | typedef struct 57 | { 58 | TMinNode Node; 59 | struct sockaddr_in addr; 60 | } TPeerListEntry; 61 | 62 | 63 | /* Private driver area */ 64 | typedef struct 65 | { 66 | int fd; /* filedestriptor of the UDP-Socket */ 67 | DWORD dBytesSendTotal; /* total bytes send */ 68 | struct sockaddr_in ClientAddr; /* */ 69 | struct sockaddr_in lastRcvPkt; /* letztes empfangenes Paket am von hier */ 70 | int LocalPort; /* local communication port number */ 71 | int dBytesinRecvBuffer; /* size of bytes in receive buffer */ 72 | BYTE recvBuffer[RECVBUFFERSIZE]; /* Receive Buffer */ 73 | BYTE SendBuffer[RECVBUFFERSIZE]; /* Sendepuffer */ 74 | TMinList comPeerList; /* List of all communication partner */ 75 | } TIPPrivate; 76 | 77 | 78 | /* public */ 79 | BOOL ip_Open (TDevice *dev); 80 | DWORD ip_Read (TDevice *dev, BYTE * DestBuffer, DWORD dBufferSize, 81 | DWORD * DriverDeviceHandle); 82 | void ip_Write(TDevice *dev, struct TNetPacket *frame, 83 | DWORD DriverDeviceHandle, TDriverSendFlags flags); 84 | void ip_Close(TDevice *dev); 85 | TDriverEvent ip_GetSupportedEvents(TDevice * dev); 86 | 87 | /* private: */ 88 | void ip_addNewPeer(TDevice *dev, struct sockaddr_in * addr ); 89 | void ip_SendToPeer(TDevice *dev, 90 | DWORD DriverDeviceHandle, 91 | TDriverSendFlags flags, 92 | BYTE * buffer, 93 | int buffersize ); 94 | 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /sdk/core/driver_layer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | /************************************************************************** 23 | * SMA Technologie AG, 34266 Niestetal, Germany 24 | *************************************************************************** 25 | * Project : YASDI 26 | *************************************************************************** 27 | * Project-no. : 28 | *************************************************************************** 29 | * Filename : TDriverLayer_layer.h 30 | *************************************************************************** 31 | * Description : Header-File der "physical Layer" 32 | *************************************************************************** 33 | * Preconditions : 34 | *************************************************************************** 35 | * Changes : Author, Date, Version, Reason 36 | * ********************************************************* 37 | * Pruessing, 29.03.2001, Created 38 | * Pruessing, 18.04.2001, ... 39 | ***************************************************************************/ 40 | 41 | #ifndef DRIVER_LAYER_H 42 | #define DRIVER_LAYER_H 43 | 44 | #include "netpacket.h" 45 | 46 | /* 47 | ** Fehlercodes der Funktion "TDriverLayer_register_driver" 48 | */ 49 | enum 50 | { 51 | PHY_OK = 0, /* Alles OK */ 52 | PHY_ERROR_DEV_TWICE = 1, /* Treiber mit diesem Namen bereits angemeldet */ 53 | }; 54 | 55 | //invalid or unknown BusDriver ID (Adapter ID) 56 | #define INVALID_DRIVER_ID 0xFFFFL 57 | 58 | 59 | /* 60 | ** ein Element der Liste aller geladenen Treiber-Module... 61 | */ 62 | typedef struct 63 | { 64 | TMinNode Node; 65 | DLLHANDLE Handle; 66 | } TSharedLibElem; 67 | 68 | 69 | 70 | /* 71 | ** Oeffentliche Prototypen ("public") 72 | */ 73 | void TDriverLayer_Constructor(void); 74 | void TDriverLayer_Destructor(void); 75 | 76 | int TDriverLayer_RegisterDevice(TDevice * newdev); 77 | void TDriverLayer_UnregisterDevice(TDevice * dev); 78 | TDevice * TDriverLayer_FindDriverName(char * cDevName); 79 | void TDriverLayer_write(struct TNetPacket * Frame ); 80 | DWORD TDriverLayer_read( TDevice * dev, 81 | BYTE * Buffer, 82 | DWORD dBufferSize, 83 | DWORD * DriverDeviceHandle ); 84 | int TDriverLayer_ioctrl(DWORD driverID, int cmd, BYTE * params ); 85 | SHARED_FUNCTION char * TDriverLayer_DriverID2String( DWORD DriverID ); 86 | TDevice * TDriverLayer_FindDriverID(DWORD DriverID); 87 | DWORD TDriverLayer_GetDriverCount( void ); 88 | SHARED_FUNCTION char * TDriverLayer_GetDriverName(DWORD DriverID); 89 | void TDriverLayer_SetDriverOffline(DWORD DriverID); 90 | BOOL TDriverLayer_SetDriverOnline(DWORD DriverID); 91 | SHARED_FUNCTION TMinList * TDriverLayer_GetDeviceList( void ); 92 | void TDriverLayer_SetAllDriversOnline( void ); 93 | void TDriverLayer_SetAllDriversOffline( void ); 94 | 95 | void TDriverLayer_OnNewEvent( TDevice * newdev, 96 | TGenDriverEvent * event ); 97 | 98 | #define TDriverLayer_GetDriverName2(BusDriver) (BusDriver)->cName 99 | 100 | 101 | 102 | 103 | 104 | //DWORD TDriverLayer_GetDriverMTU(DWORD DriverID); 105 | 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /sdk/include/os.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef OS_H 23 | #define OS_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "project.h" 33 | #include "smadef.h" 34 | 35 | //include System dep. files here... 36 | #include "osswitch.h" 37 | 38 | //include compiler specific definitions here.... 39 | #include "compiler.h" 40 | 41 | #include "byteorder.h" 42 | 43 | 44 | 45 | #ifndef NULL 46 | #define NULL (0l) 47 | #endif 48 | 49 | //LOWBYTE and HIBYTE is not defined on every system... 50 | #ifndef LOBYTE 51 | # define LOBYTE(a) ((a) & 0xff) 52 | #endif 53 | #ifndef HIBYTE 54 | # define HIBYTE(a) (((a) >> 8) & 0xff) 55 | #endif 56 | 57 | //min and max are also not defines on every system... 58 | #ifndef min 59 | #define min(a,b) ((a)>(b)?(b):(a)) 60 | #endif 61 | 62 | #ifndef max 63 | #define max(a,b) ((a)>(b)?(a):(b)) 64 | #endif 65 | 66 | //Misc functions 67 | SHARED_FUNCTION void os_cleanup( void ); 68 | 69 | 70 | //system debug interface 71 | SHARED_FUNCTION void os_setDebugOutputHandle(FILE * handle); 72 | SHARED_FUNCTION void os_Debug(DWORD debugLevel, char * format, ...); 73 | 74 | //Thread functions interface 75 | typedef void (*THREADSTARTFUNC)( DWORD param ); //Entry point of an Thread 76 | SHARED_FUNCTION THREAD_HANDLE os_thread_create( THREADSTARTFUNC, XPOINT userData ); 77 | SHARED_FUNCTION void os_thread_WaitFor( THREAD_HANDLE handle ); 78 | SHARED_FUNCTION void os_thread_sleep(int iMillisec); 79 | SHARED_FUNCTION void os_thread_MutexInit( T_MUTEX * mutex ); 80 | SHARED_FUNCTION void os_thread_MutexDestroy( T_MUTEX * mutex ); 81 | SHARED_FUNCTION void os_thread_MutexLock( T_MUTEX * mutex ); 82 | SHARED_FUNCTION void os_thread_MutexUnlock( T_MUTEX * mutex ); 83 | 84 | 85 | //Memory functions interface 86 | SHARED_FUNCTION void * os_malloc(DWORD size); 87 | SHARED_FUNCTION void os_free(void *); 88 | SHARED_FUNCTION DWORD os_GetUsedMem( void ); 89 | 90 | //Misc System (OS) functions 91 | SHARED_FUNCTION const char * os_GetOSIdentifier( void ); 92 | SHARED_FUNCTION DWORD os_rand(DWORD start, DWORD end); 93 | SHARED_FUNCTION DWORD os_GetSystemTime( DWORD * milliseconds ); 94 | SHARED_FUNCTION struct tm* os_GetSystemTimeTm(DWORD * milliseconds); 95 | SHARED_FUNCTION void os_memset(void *, BYTE value, DWORD size); 96 | 97 | //Path file functions... 98 | SHARED_FUNCTION int os_GetUserHomeDir(char * destbuffer, int maxlen); 99 | SHARED_FUNCTION int os_mkdir(char * directoryname); 100 | 101 | //Library functions (for dynamic and static libraries) 102 | SHARED_FUNCTION DLLHANDLE os_LoadLibrary(char * file); 103 | SHARED_FUNCTION void os_UnloadLibrary(DLLHANDLE handle); 104 | SHARED_FUNCTION void * os_FindLibrarySymbol(DLLHANDLE handle, char * ident); 105 | //reference an symbol (this could be in an external module...) 106 | #define os_GetSymbolRef(handle, ident ) os_FindLibrarySymbol( handle, #ident ) 107 | 108 | //Sort and search functions... 109 | SHARED_FUNCTION void * os_bsearch(const void * key, const void * base, size_t nelem, 110 | size_t width, int (*fcmp)(const void *, const void *)); 111 | SHARED_FUNCTION void os_qsort(void *base, size_t nelem, size_t width, 112 | int (*fcmp)(const void *, const void *)); 113 | 114 | #define os_memmove(src, dst, size) memmove(src, dst, size) 115 | #define os_memcpy( src, dst, size) memcpy (src, dst, size) 116 | 117 | 118 | 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /sdk/CHANGES: -------------------------------------------------------------------------------- 1 | YASDI Changelog 2 | --------------- 3 | 4 | 5 | 23.02.2010, V1.8.1: 6 | * reworked router functions 7 | * adjustments for using CMake version 2.6 8 | * new config: Misc.ChannelListDir for channel list cache 9 | * fixed bug in router when using device with net address "0000" 10 | * fixed shutdown problem in master API library 11 | * fixed memory problem in master API function "GetChannelName()" 12 | * added mutexes while access to YASDI bus drivers 13 | * added new master function "yasdiMasterGetVersion()" 14 | * added POSIX AIO support for serial driver (experimental) 15 | * added mutex destroy in "os_thread_MutexDestroy()" in POSIX layer 16 | * changed version to "1.8.1 Build 9" 17 | * removed Borland C++ Builder 5 Port (generic-cmake is now the only port) 18 | * fixed bug in INI file support 19 | * Linux serial support: Better checking for port availability 20 | 21 | 22 | 01.09.2007, 23 | 15.04.2008, V1.8.0: 24 | * Fixed some bugs while trimming status texts 25 | * CMake crossbuild system used. (see "www.cmake.org" for more details) 26 | Older systems built (under "projects") are removed and not supported 27 | anymore... 28 | * New asynchronous API functions reading channel values overlapped 29 | (see function "GetChannelValueAsync" in "libs/yasdimaster.h") 30 | * Many changes in SMAData Master to process channel values 31 | asynchronously 32 | * New event system added (for API and backend bus drivers) 33 | (see function "yasdiMasterAddEventListener" in libs/yasdimaster.h) 34 | * Automatically create directory "devices" for channel list cache if 35 | not available 36 | * Removed bug on Windows port. "[Misc] DebugOutput=..." in config file 37 | was not properly functioning 38 | * Bug removed when parsing channel names with full lenght 39 | 40 | 41 | 01.02.2007, V1.7.2: 42 | * Changed Licence from "SMA" to LGPL 43 | * Minor changes... 44 | 45 | 46 | 30.12.2006, V1.7.1: (not public) 47 | * Sharing channel list structures, saving space 48 | * New packet buffer management 49 | * New channel list and device list iterators with much 50 | smaller memory usage 51 | 52 | 53 | 12.11.2006, V1.7.0: (not public) 54 | * Some speed optimizations 55 | * New generic IP (Ethernet) driver for all systems 56 | * Added new time system using milli seconds speedup delay 57 | * Added container for new SMAData2 protocol 58 | * Added new message queues 59 | * Added needed waiting of 1 seconds after sending CMD_SYNC_ONLINE 60 | (optional deselectable) 61 | * Added function to change security level via API function 62 | "yasdiMasterSetAccessLevel()" 63 | * Added functions for getting SMAData1 specific informations: 64 | "yasdiMasterGetChannelPropertyInt()" 65 | "yasdiMasterGetChannelPropertyDouble()": 66 | * Enhanced Bus Driver API with events: 67 | DRE_PEER_ADDED, 68 | DRE_PEER_REMOVED, 69 | DRE_NEW_INPUT 70 | * New optional language mapping: "C++" for YASDI Master C-API 71 | * New Master-API-Function for async events 72 | "yasdiMasterAddEventListener" 73 | "yasdiMasterRemEventListener" 74 | 75 | 76 | 26.06.2006, V1.6.0: (not public) 77 | * Invalid channel lists are now accepted (default is rejected) with config: 78 | [Misc] 79 | acceptInvalidChannelLists=1 80 | * reworked CPU specific functions (big endian, little endian). 81 | Now auto converting... 82 | * pass thru functions for Bus Drivers in the Master Library: 83 | "yasdiMasterGetDriver(); 84 | "yasdiMasterGetDriverName()" 85 | "yasdiMasterSetDriverOffline()" 86 | "yasdiMasterSetDriverOnline()" 87 | 88 | 89 | 90 | 19.05.2006, V1.5.0 (not public) 91 | * Added "mingw" support for YASDI ("Minimalistic GNU on Windows" ) 92 | * Optional cheching of parameter value range (now default) 93 | Can be switched of with 94 | --- cut --- 95 | [Misc] 96 | checkValueRange=0 97 | --- cut --- 98 | 99 | 100 | 04.03.2005, V1.4.0 (not public) 101 | * Added new support for "MacOSX" (Darwin) 102 | * New API function removing device from currently list of known devices 103 | "RemoveDevice()".. 104 | * New support for WindowsCE 105 | 106 | 107 | 01.12.2002, V1.3.0 (public) 108 | * New API function yasdiDoMasterCmdEx() 109 | * Fixed bug scanning sunnynet packet 110 | 111 | 112 | 01.04.2001: V1.0.0 (not public) 113 | * Project started, first version 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /sdk/core/mempool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "os.h" 23 | #include "lists.h" 24 | #include "mempool.h" 25 | 26 | /* 27 | TMemPool * TMemPool_Constructor(int mincount, 28 | int maxcount, 29 | int elementsize, 30 | BOOL threading) 31 | { 32 | TMemPool * me = os_malloc(sizeof(TMemPool)); 33 | assert(me); 34 | TMemPool_Init(me, mincount, maxcount, elementsize, threading); 35 | return me; 36 | } 37 | */ 38 | 39 | void TMemPool_Init(TMemPool * me, 40 | int mincount, 41 | int maxcount, 42 | int elementsize, 43 | BOOL threading) 44 | { 45 | int i; 46 | 47 | //all elements must be aligned to 4 bytes boundary to be save... 48 | //the smalest size is now 4 bytes... 49 | if ((elementsize & 0x3)) 50 | { 51 | elementsize = (elementsize & 0x03)+4; 52 | } 53 | 54 | me->mincount = mincount; 55 | me->maxcount = maxcount; 56 | me->elementsize = elementsize; 57 | me->threading = threading; 58 | me->currcount = 0; 59 | INITLIST(&me->poolList); 60 | 61 | //allocate the minimum selements whiche were only freed when destructing 62 | //...as one block.... 63 | me->preAllocElems = NULL; 64 | if (mincount) 65 | { 66 | me->preAllocElems = os_malloc(mincount * elementsize); 67 | assert(me->preAllocElems); 68 | 69 | //add it as some small pieces to the list of unused elements... 70 | for(i=0;i < mincount; i++) 71 | { 72 | ADDHEAD(&me->poolList, (TMinNode*)(me->preAllocElems + (i * elementsize) )); 73 | } 74 | } 75 | } 76 | 77 | 78 | void TMemPool_Free(TMemPool * me) 79 | { 80 | //used to find out if element is one of the pre allocated elements 81 | //which are not freed at once... 82 | size_t lowptr = (size_t)me->preAllocElems; 83 | size_t highptr = (size_t)(me->preAllocElems + (me->mincount * me->elementsize)); 84 | 85 | 86 | //Free all memory from list of unsed elements... 87 | TMinNode * n = (TMinNode*)GETFIRST(&me->poolList ); 88 | while( ISELEMENTVALID ( n = (TMinNode*)GETFIRST(&me->poolList ) ) ) 89 | { 90 | //remove from list 91 | REMOVE(n); 92 | 93 | //is it part of the pre allocated elements? if not delete it... 94 | if ((size_t)n < lowptr || (size_t)n >= highptr) 95 | { 96 | //free element... 97 | os_free(n); 98 | } 99 | } 100 | 101 | //Free the bloc of pre allocated elements... 102 | os_free( me->preAllocElems ); 103 | } 104 | 105 | /* 106 | void TMemPool_Destructor(TMemPool * me) 107 | { 108 | assert(me); 109 | TMemPool_Free(me); 110 | os_free( me ); 111 | } 112 | */ 113 | 114 | 115 | 116 | void * TMemPool_AllocElem( TMemPool * me, BYTE flags ) 117 | { 118 | void * e; 119 | //too much elements in use? 120 | if (me->currcount >= me->maxcount) 121 | return NULL; 122 | me->currcount++; 123 | 124 | //something in unsed elements list? 125 | e = GETFIRST(&me->poolList); 126 | if (ISELEMENTVALID(e) ) 127 | { 128 | REMOVE((TMinNode*)e); 129 | 130 | if (flags == MP_CLEAR) 131 | memset(e, me->elementsize, 0); 132 | } 133 | else 134 | { 135 | //alloc an new element... 136 | e = os_malloc(me->elementsize); 137 | assert(e); 138 | } 139 | return e; 140 | } 141 | 142 | void TMemPool_FreeElem(TMemPool * me, void * elem ) 143 | { 144 | //lay it back to list... 145 | ADDHEAD(&me->poolList, ((TMinNode*)elem)); 146 | me->currcount--; 147 | } 148 | 149 | -------------------------------------------------------------------------------- /sdk/core/iorequest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef IOREQUEST_H 23 | #define IOREQUEST_H 24 | 25 | #include "lists.h" 26 | #include "timer.h" 27 | 28 | /* Status eines IORequests */ 29 | typedef enum 30 | { 31 | RS_SUCCESS = 0, /* IORequest erfolgreich beendet evtl. Antwort erhalten */ 32 | RS_WORKING, /* IORequest in Bearbeitung (warten auf Antwort) */ 33 | RS_TIMEOUT, /* IORequest ist in Timeout gelaufen (keine Antwort) */ 34 | RS_QUEUED /* IORequest is queued in waiting list */ 35 | } TReqStatus; 36 | 37 | /* Requesttyp */ 38 | typedef enum 39 | { 40 | RT_MONORCV = 0, /* Es wird auf nur EINE Antwort gewartet (z.B. CMD_GET_DATA) */ 41 | RT_MULTIRCV, /* Es wird auf MEHRERE Antworten gewartet (z.B. CMD_GET_NET) */ 42 | RT_NORCV /* Es wird auf keine Antwort gewartet (z.B. CMD_SYN_ONLINE) */ 43 | } TReqType; 44 | 45 | 46 | 47 | //structure with all infos about the received message... 48 | typedef struct _TOnReceiveInfo 49 | { 50 | WORD SourceAddr; // Absender der Antwort/Anfrage 51 | BYTE * Buffer; // Verweiss auf empfangene Antwort/Anfrage 52 | DWORD BufferSize; // Groesse der empfangenen Antwort/Anfrage 53 | DWORD RxFlags; 54 | DWORD BusDriverDevHandle; 55 | } TOnReceiveInfo; 56 | 57 | 58 | struct _TIORequest; 59 | 60 | typedef void (*TIORequestOnReceiveFkt)( 61 | struct _TIORequest * req, /* Pointer to IORequest */ 62 | TOnReceiveInfo * rcvInfo //All infos about the receive 63 | ); 64 | 65 | typedef void (*TIORequestOnEndFkt )( 66 | struct _TIORequest * req ); 67 | 68 | typedef void (*TIORequestOnTransferFkt)( 69 | struct _TIORequest * req, BYTE prozent ); /* Datenuebbertragung laeuft */ 70 | 71 | //The IORequest is starting now (bevor anything is done) 72 | typedef void (*TIORequestOnStarting)(struct _TIORequest * req); 73 | 74 | 75 | 76 | typedef struct _TIORequest 77 | { 78 | //private 79 | TMinNode Node; /* Zum Verketten mehrerer IORequests */ 80 | TMinTimer Timer; /* Timer fuer den Empfang der Antwort(en); 81 | bei Folgepaketen die Zeit fuerr das ERSTE Paket! */ 82 | //public 83 | /* verschiedenes */ 84 | TReqStatus Status; /* Status des IORequests: RS_FINISH, RS_BUSY, RS_TIMEOUT */ 85 | TReqType Type; /* Typ des Requests: RT_MONORCV, RT_MULTIRCV */ 86 | BYTE Cmd; /* das SMAData(1)-Kommando */ 87 | 88 | /* Sendebereich */ 89 | WORD DestAddr; /* Zieladresse des Netzteilnehmers (Empfaenger) */ 90 | WORD SourceAddr; /* Die Netzadresse der eigenen Station (Absender) */ 91 | BYTE * TxData; /* Datenbereich, der verschickt werden soll */ 92 | DWORD TxLength; /* Datenbereichsgroessee */ 93 | DWORD TxFlags; /* Sendeflags: 94 | "TS_BROADCAST" oder 95 | "TS_STRING_FILTER" oder 96 | "TS_ANSER" oder 97 | PROT_SMANET oder 98 | PROT_SUNNYNET 99 | */ 100 | 101 | /* Empfangsbereich */ 102 | DWORD TimeOut; /* Timeout fuer das Empfangen der Antwort */ 103 | DWORD Repeats; /* Sendewiederholgungen bei Empfangstimeout */ 104 | 105 | 106 | /* Ereignishandler ( callback handler ) */ 107 | void (*OnReceived)( struct _TIORequest * req, TOnReceiveInfo * rcvInfo ); /* Callback Packet received */ 108 | void (*OnEnd )( struct _TIORequest * req ); /* Callback IORequest ends */ 109 | void (*OnTransfer)( struct _TIORequest * req, BYTE prozent ); /* Callback Data Transfer */ 110 | void (*OnStarting)( struct _TIORequest * req); //IORequest is starting now... 111 | 112 | } TIORequest; 113 | 114 | 115 | SHARED_FUNCTION TIORequest * TIORequest_Constructor( void ); 116 | SHARED_FUNCTION void TIORequest_Destructor(TIORequest * req); 117 | SHARED_FUNCTION TReqStatus TIORequest_GetStatus( TIORequest * req ); 118 | SHARED_FUNCTION void TIORequest_SetOnReceive( TIORequest * req, TIORequestOnReceiveFkt fkt ); 119 | SHARED_FUNCTION void TIORequest_SetOnEnd( TIORequest * req, TIORequestOnEndFkt fkt ); 120 | SHARED_FUNCTION void TIORequest_SetOnTransfer( TIORequest * req, TIORequestOnTransferFkt fkt ); 121 | SHARED_FUNCTION void TIORequest_SetOnStarting( TIORequest * req, TIORequestOnStarting fkt); 122 | 123 | 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /sdk/libs/libyasdi.def: -------------------------------------------------------------------------------- 1 | LIBRARY yasdi.dll 2 | 3 | EXPORTS 4 | GetPrivateProfileCheck 5 | _GetPrivateProfileCheck=GetPrivateProfileCheck 6 | GetPrivateProfileHex 7 | _GetPrivateProfileHex=GetPrivateProfileHex 8 | GetPrivateProfileInt_ 9 | _GetPrivateProfileInt_=GetPrivateProfileInt_ 10 | GetPrivateProfileLong 11 | _GetPrivateProfileLong=GetPrivateProfileLong 12 | GetPrivateProfileLongHex 13 | _GetPrivateProfileLongHex=GetPrivateProfileLongHex 14 | GetPrivateProfileString_ 15 | _GetPrivateProfileString_=GetPrivateProfileString_ 16 | TNetPacket_AddHead 17 | TNetPacket_AddTail 18 | TNetPacket_Clear 19 | TNetPacket_Constructor 20 | TNetPacket_Copy 21 | TNetPacket_CopyFromBuffer 22 | TNetPacket_Destructor 23 | TNetPacket_GetFrameLength 24 | TNetPacket_Print 25 | TNetPacket_RemHead 26 | TNetPacket_GetNextFragment 27 | TProtLayer_GetAllProtocols 28 | TRepository_GetElementInt 29 | TRepository_GetElementStr 30 | TRepository_GetIsElementExist 31 | TRepository_LoadChannelList 32 | TRepository_StoreChanList 33 | TRouter_RemoveRoute 34 | TRouter_ClearTable 35 | TRoute_FindAddrByDriverDevicePeer 36 | TSMAData_AddEventListener 37 | TSMAData_AddIORequest 38 | TSMAData_AddPaketListener 39 | TSMAData_DecodeCmd 40 | TSMAData_FindIORequest 41 | TSMAData_InitReqCfgNetAddr 42 | TSMAData_InitReqGetChanInfo 43 | TSMAData_InitReqGetNet 44 | TSMAData_InitReqGetOnlineChannels 45 | TSMAData_InitReqGetParamChannels 46 | TSMAData_InitReqGetTestChannels 47 | TSMAData_InitReqSendSyncOnline 48 | TSMAData_InitReqSetChannel 49 | TSMAData_OnFrameReceived 50 | TSMAData_OnNewEvent 51 | TSMAData_OnReqTimeout 52 | TSMAData_ReceiverThreadExecute 53 | TSMAData_RemEventListener 54 | TSMAData_RemPaketListener 55 | TSMAData_SendPacket 56 | TSMAData_SendRawPacket 57 | TSMAData_SendRequest 58 | TSMAData_SendThreadExecute 59 | TSMAData_constructor 60 | TSMAData_destructor 61 | TSMAData_CheckIfSyncOnlineIsRunning 62 | TSchedule_AddTask 63 | TSchedule_AddTimer 64 | TSchedule_Constructor 65 | TSchedule_Destructor 66 | TSchedule_DoScheduling 67 | TSchedule_Freeze 68 | TSchedule_IsFreeze 69 | TSchedule_IsScheduling 70 | TSchedule_MainExecute 71 | TSchedule_RemTask 72 | TSchedule_RemTimer 73 | TSchedule_StopScheduling 74 | TTask_GetLastActivate 75 | TTask_GetTimeInterval 76 | TTask_Init 77 | TTask_SetEntryPoint 78 | TTask_SetLastActivate 79 | TTask_SetTimeInterval 80 | TMinTimer_Restart 81 | TMinTimer_SetAlarmFunc 82 | TMinTimer_SetTime 83 | TMinTimer_Start 84 | TMinTimer_Stop 85 | Tools_GetFileSize 86 | Tools_CopyValuesFromSMADataBuffer 87 | Tools_CopyValuesToSMADataBuffer 88 | _Tools_CopyValuesToSMADataBuffer=Tools_CopyValuesToSMADataBuffer 89 | Trim 90 | _Trim=Trim 91 | TMinQueue_AddListenerTask 92 | TMinQueue_AddListenerTimer 93 | TMinQueue_AddMsg 94 | TMinQueue_GetMsg 95 | TMinQueue_Init 96 | TMinQueue_RemoveAll 97 | WritePrivateProfileHex 98 | _WritePrivateProfileHex=WritePrivateProfileHex 99 | WritePrivateProfileInt 100 | _WritePrivateProfileInt=WritePrivateProfileInt 101 | WritePrivateProfileLong 102 | _WritePrivateProfileLong=WritePrivateProfileLong 103 | WritePrivateProfileLongHex 104 | _WritePrivateProfileLongHex=WritePrivateProfileLongHex 105 | WritePrivateProfileString_ 106 | _WritePrivateProfileString_=WritePrivateProfileString_ 107 | WriteString 108 | _WriteString=WriteString 109 | os_Debug 110 | _os_Debug=os_Debug 111 | yasdiInitialize 112 | _yasdiInitialize=yasdiInitialize 113 | yasdiShutdown 114 | _yasdiShutdown=yasdiShutdown 115 | hostToLe16 116 | hostToLe32 117 | hostToLe32f 118 | le16ToHost 119 | le32ToHost 120 | le32fToHost 121 | Tools_FileExists 122 | os_FindLibrarySymbol 123 | os_GetOSIdentifier 124 | _os_GetOSIdentifier=os_GetOSIdentifier 125 | os_GetSystemTime 126 | os_GetSystemTimeTm 127 | os_GetUsedMem 128 | os_GetUserHomeDir 129 | os_LoadLibrary 130 | Tools_PathAdd 131 | Tools_PathExtractFile 132 | Tools_PathExtractPath 133 | Tools_PathIsRelativ 134 | os_cleanup 135 | os_UnloadLibrary 136 | os_bsearch 137 | os_free 138 | os_malloc 139 | os_qsort 140 | os_rand 141 | os_setDebugOutputHandle 142 | os_thread_MutexDestroy 143 | os_thread_MutexInit 144 | os_thread_MutexLock 145 | os_thread_MutexUnlock 146 | os_thread_WaitFor 147 | os_thread_create 148 | os_thread_sleep 149 | yasdiAddIORequest 150 | _yasdiAddIORequest=yasdiAddIORequest 151 | yasdiAddPaketListener 152 | _yasdiAddPaketListener=yasdiAddPaketListener 153 | yasdiGetDriver 154 | _yasdiGetDriver=yasdiGetDriver 155 | yasdiGetDriverName 156 | _yasdiGetDriverName=yasdiGetDriverName 157 | yasdiInitialize 158 | _yasdiInitialize=yasdiInitialize 159 | yasdiSendPacket 160 | _yasdiSendPacket=yasdiSendPacket 161 | yasdiSetDriverOffline 162 | _yasdiSetDriverOffline=yasdiSetDriverOffline 163 | yasdiSetDriverOnline 164 | _yasdiSetDriverOnline=yasdiSetDriverOnline 165 | yasdiShutdown 166 | _yasdiShutdown=yasdiShutdown 167 | TIORequest_Constructor 168 | _TIORequest_Constructor=TIORequest_Constructor 169 | TIORequest_Destructor 170 | _TIORequest_Destructor=TIORequest_Destructor 171 | TIORequest_SetOnStarting 172 | 173 | 174 | TStatisticWriter_AddNewStatistic 175 | TMap_Init 176 | TMap_Free 177 | TMap_Constructor 178 | TMap_Find 179 | TMap_Add 180 | TMap_Remove 181 | Tools_StartsWith 182 | GetDWORD 183 | WriteDWORD 184 | yasdiDoDriverIoCtrl 185 | TMemPool_AllocElem 186 | TMemPool_Init 187 | 188 | -------------------------------------------------------------------------------- /sdk/master/netchannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef NETCHANNEL_H 23 | #define NETCHANNEL_H 24 | 25 | #include "chandef.h" 26 | #include "smadef.h" 27 | #include "objman.h" 28 | #include "netdevice.h" 29 | #include "netchannel.h" 30 | #include "tools.h" 31 | 32 | 33 | #define CHANVAL_INVALID -1 34 | 35 | struct _TNetDevice; 36 | 37 | //an counter for sharing... 38 | typedef WORD TRefCounter; 39 | 40 | 41 | typedef struct _TChannel 42 | { 43 | TRefCounter ref; //count of references to this channel 44 | 45 | //konstanter Teil... 46 | TObjectHandle Handle; /* YASDI channel handle */ 47 | WORD wCType; /* SMAData1 Kanaltyp */ 48 | WORD wNType; /* SMAData1 Datenformat */ 49 | WORD wLevel; /* SMAData1 Kanallevel*/ 50 | char * Name; /* SMAData1 Kanalname */ 51 | char * CUnit; /* SMAData1 Kanaleinheit */ 52 | BYTE bCIndex; /* SMAData1 Kanalindex */ 53 | float fGain; /* SMAData1 Verstaerkung */ 54 | float fOffset; /* SMAData1 Offset */ 55 | BYTE bStatTextCnt; /* Anzahl der nachfolgenden Kanaltexte (anzahl der texte!)*/ 56 | char * StatText; /* Statustexte (die einzelnen Texte sind 57 | jeweils NULL-Terminiert) */ 58 | 59 | } TChannel; 60 | 61 | TChannel * TChannel_Constructor(BYTE Index, WORD cType, WORD nType, 62 | WORD Level, char * name, char * unit, 63 | char * stattexts, int sizestattextblock); 64 | 65 | void TChannel_Destructor(TChannel * channel); 66 | //!compares channels with an other one... 67 | int TChannel_Compare(TChannel *me, TChannel *c2); 68 | 69 | 70 | #define TChannel_GetIndex( me ) ( (me)->bCIndex ) 71 | #define TChannel_GetCType( me ) ( (me)->wCType ) 72 | #define TChannel_GetNType( me ) ( (me)->wNType ) 73 | #define TChannel_GetLevel( me ) ( (me)->wLevel ) 74 | char * TChannel_GetUnit( struct _TChannel * me ); 75 | #define TChannel_GetStatTextCnt( me )( (me)->bStatTextCnt ) 76 | #define TChannel_GetGain( me ) ( (me)->fGain ) 77 | #define TChannel_GetOffset( me ) ( (me)->fOffset ) 78 | #define TChannel_GetName( me ) ((me)->Name) 79 | 80 | 81 | #define TChannel_SetOffset( me, offset ) (me)->fOffset = offset 82 | #define TChannel_SetGain( me, gain ) (me)->fGain = gain 83 | void TChannel_SetTimeStamp(struct _TChannel * me,struct _TNetDevice * dev, DWORD Time); 84 | DWORD TChannel_GetTimeStamp( struct _TChannel * me,struct _TNetDevice * dev); 85 | 86 | 87 | int TChannel_SetValueAsString(TChannel * me, 88 | struct _TNetDevice * dev, 89 | const char * stringvalue, 90 | BYTE * errorPos); 91 | 92 | #define TChannel_GetValArraySize( me ) ( ((me)->wNType & 0xff00) >> 8 ) 93 | BYTE TChannel_GetValueWidth(TChannel *me); 94 | 95 | 96 | char * TChannel_GetStatText( struct _TChannel * me, BYTE index ); 97 | void TChannel_AddStatTexts( struct _TChannel * me, char * StatText, WORD bArraySize); 98 | int TChannel_FindStatText( struct _TChannel * me, char * StatText ); 99 | 100 | typedef enum { CHECK_READ, CHECK_WRITE } TReadWriteCheck; 101 | BOOL TChannel_IsLevel(TChannel * me, TLevel Level, TReadWriteCheck readwrite); 102 | 103 | int TChannel_ScanUpdateValue(TChannel * me, struct _TNetDevice * dev, TVirtBuffer * srcbuffer); 104 | WORD TChannel_BuildSetDataPkt(TChannel * me, struct _TNetDevice * dev, BYTE * Data, WORD len); 105 | 106 | double TChannel_GetValue(TChannel * chan, struct _TNetDevice * dev, int iValIndex); 107 | int TChannel_GetValueText(struct _TChannel * me, struct _TNetDevice * dev, char * TextBuffer, int TextBufSize ); 108 | void TChannel_SetValue(struct _TChannel * me, struct _TNetDevice * dev, double value); 109 | void TChannel_SetIsValueValid(struct _TChannel * me, struct _TNetDevice * dev,BOOL bValid); 110 | BOOL TChannel_IsValueValid(struct _TChannel * me, struct _TNetDevice * dev ); 111 | int TChannel_GetGenericPropertyDouble(struct _TChannel * me, char * prop, double * result ); 112 | 113 | #define TChannel_GetValCnt(me) TChannel_GetValArraySize(me) 114 | 115 | /* private */ 116 | WORD TChannel_GetRawValue(TChannel * me, struct _TNetDevice * dev, BYTE * Data, WORD len); 117 | void TChannel_SetRawValue( struct _TChannel * me, struct _TNetDevice * dev, double value, int iValArrayPos ); 118 | int TChannel_GetStatTextIndex(TChannel * me, const char * texttosearch); 119 | 120 | 121 | 122 | //##### Channel Factory ####### 123 | 124 | void TChanFactory_Init( void ); 125 | TChannel * TChanFactory_GetChannel(BYTE Index, WORD cType, WORD nType, WORD Level, char * name, char * unit, char * pStatText, int sizestattext); 126 | void TChanFactory_FreeChannel(struct _TChannel * chan); 127 | 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /sdk/core/netpacket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | /************************************************************************** 23 | * Project : YASDI 24 | *************************************************************************** 25 | * Project-no. : 26 | *************************************************************************** 27 | * Filename : frame.h 28 | *************************************************************************** 29 | * Description : Beschreibung der Framestrukturen 30 | *************************************************************************** 31 | * Preconditions : GNU-C-Compiler, GNU-Tools 32 | *************************************************************************** 33 | * Changes : Author, Date, Version, Reason 34 | * ********************************************************* 35 | * Pruessing, 19.04.2001, Created 36 | ***************************************************************************/ 37 | #ifndef FRAME_H 38 | #define FRAME_H 39 | 40 | #include "lists.h" 41 | #include "device.h" 42 | #include "prot_layer.h" 43 | 44 | 45 | /* 46 | ** structure for NetBuffer fragments 47 | */ 48 | struct TNetPacketFrag 49 | { 50 | TMinNode Node; /* Zum Verketten von Pufferfragmente */ 51 | DWORD BufferSize; /* die Groesse des nachfolgenden Dateninhalts */ 52 | BYTE * Buffer; /* Zeiger auf den Start des Datenbereichs */ 53 | BYTE RealData[1]; /* der eigentliche Dateninhalt (variabel) */ 54 | }; 55 | 56 | 57 | 58 | 59 | /* 60 | * Routing infos for receiving or sending packets... 61 | */ 62 | typedef struct 63 | { 64 | //struct _TDevice * Device;/* PRIVATE! Bus Device which should send this frame or receive it */ 65 | DWORD BusDriverID; /* The same as "Device" but as ID, not as pointer... */ 66 | DWORD BusDriverPeer; /* Optional handle of the communication device which should 67 | receive the packet or is from. 68 | Only used in YASDI driver as an futher address field. 69 | YASDI core ignore the content of it... */ 70 | TDriverSendFlags Flags; /* The sending flags for the frame (Broadcast/Monocast) */ 71 | BYTE bTransProtID; /* The packet should be sended or received in this transport protocol */ 72 | } TNetPacketRouteInfo; 73 | 74 | 75 | /* 76 | ** A single NetBuffer... 77 | */ 78 | typedef struct TNetPacket TNetPacket; 79 | struct TNetPacket 80 | { 81 | TMinNode Node; /* Zum Verketten von mehreren Puffern in einer Liste */ 82 | TMinList( Fragments ); /* Liste der Pufferfragmente */ 83 | TNetPacketRouteInfo RouteInfo; /* Routing infos for the packet */ 84 | }; 85 | 86 | SHARED_FUNCTION void TNetPacketManagement_Init( void ); 87 | SHARED_FUNCTION void TNetPacketManagement_Destructor( void ); 88 | SHARED_FUNCTION struct TNetPacket * TNetPacketManagement_GetPacket( void ); 89 | SHARED_FUNCTION void TNetPacketManagement_FreeBuffer(struct TNetPacket * buf); 90 | SHARED_FUNCTION int TNetPacketManagement_GetFragmentCount( void ); 91 | 92 | 93 | SHARED_FUNCTION void TNetPacket_AddHead(struct TNetPacket * frame, BYTE * Buffer, WORD size); 94 | SHARED_FUNCTION void TNetPacket_AddTail(struct TNetPacket * frame, BYTE * Buffer, WORD size); 95 | SHARED_FUNCTION struct TNetPacket * TNetPacket_Constructor( void ); 96 | SHARED_FUNCTION void TNetPacket_Init(struct TNetPacket * frame); 97 | SHARED_FUNCTION void TNetPacket_Destructor(struct TNetPacket * frame); 98 | SHARED_FUNCTION int TNetPacket_GetFrameLength(struct TNetPacket * frame); 99 | SHARED_FUNCTION void TNetPacket_Print(struct TNetPacket *frame, WORD bVerboseMode); 100 | SHARED_FUNCTION void TNetPacket_PrintCounted(struct TNetPacket *frame, 101 | WORD count, 102 | WORD bVerboseMode); 103 | #ifdef DEBUG 104 | typedef void (*TDBGCBParseBuffer)(char * format, ...); 105 | SHARED_FUNCTION void TNetPacket_PrintCountedCB(TDBGCBParseBuffer out, 106 | struct TNetPacket *frame, 107 | WORD count); 108 | #endif 109 | SHARED_FUNCTION BOOL TNetPacket_RemHead(struct TNetPacket * frame, DWORD iCount , void * buffer); 110 | SHARED_FUNCTION void TNetPacket_Copy(struct TNetPacket * DestFrame, struct TNetPacket * SourceFrame ); 111 | SHARED_FUNCTION void TNetPacket_Clear(struct TNetPacket * ); 112 | SHARED_FUNCTION void TNetPacket_CopyFromBuffer( struct TNetPacket * frame, BYTE * Buffer ); 113 | 114 | 115 | SHARED_FUNCTION BYTE * TNetPacket_GetNextFragment( struct TNetPacket * frame, BYTE * lastDataBuffer, WORD * bufferSize ); 116 | 117 | //!Iterator over alle Data in the packet buffer.. 118 | #define FOREACH_IN_BUFFER(frame, resDataPointer, resDataPointerSize) \ 119 | resDataPointer = NULL; \ 120 | while( (resDataPointer = TNetPacket_GetNextFragment(frame, resDataPointer, resDataPointerSize)) != NULL ) 121 | 122 | 123 | 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /sdk/master/master.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef MASTER_H 23 | #define MASTER_H 24 | 25 | #include "os.h" 26 | #include "timer.h" 27 | #include "iorequest.h" 28 | #include "states.h" 29 | #include "scheduler.h" 30 | #include "mastercmd.h" 31 | #include "lists.h" 32 | #include "minqueue.h" 33 | #include "smadata_layer.h" 34 | #include "libyasdimaster.h" 35 | 36 | 37 | struct _TMasterCmdReq; 38 | 39 | 40 | /************************************************************************** 41 | ********** C O N S T ****************************************************** 42 | **************************************************************************/ 43 | 44 | enum 45 | { 46 | DETECT_ONE_MORE_DEV = -2, // Detection flag: Detect only one device more 47 | DETECTION_WAIT_FOR_ANSWER = 5 // During Detection: Wait X seconds for an answer 48 | }; 49 | 50 | 51 | 52 | 53 | /* 54 | ** Timeoutzeiten und Wiederholungen der einzelnen Gerteabfragen 55 | */ 56 | typedef struct _TMasterTimeouts 57 | { 58 | /* Setzen von Parameterkanaelen */ 59 | int iSetParamChanTimeout; 60 | int iSetParamChanRetry; 61 | 62 | /* Erfragen von Parameterkanaelen */ 63 | int iGetParamChanTimeout; 64 | int iGetParamChanRetry; 65 | 66 | /* Erfragen von Spotwertkanaelen/Testkanaele */ 67 | int iGetSpotChanTimeout; 68 | int iGetSpotChanRetry; 69 | 70 | /* Device Detection... */ 71 | int iWaitAfterDetection; //Time to wait after last answer was received during detection 72 | 73 | BYTE WaitSecAfterSyncOnline; //Wait time after Send "Sync Online" 74 | 75 | 76 | } TMasterTimeouts; 77 | 78 | /************************************************************************* 79 | ************************ Klasse SMADataMaster **************************** 80 | *************************************************************************/ 81 | 82 | /* 83 | ** Das Master-Objekt existiert nur einmal im System (nur eine Instanz) 84 | ** so dass auf das Durchreichen des Instanzpointers verzichtet wird! 85 | */ 86 | 87 | typedef struct _TSMADataMaster 88 | { 89 | WORD SrcAddr; /* SD1 Address if the SD1-Master */ 90 | 91 | BYTE DeviceAddrRangeLow; /* Bereich fuer vergebene Netzadressen (Geraet)*/ 92 | BYTE DeviceAddrRangeHigh; 93 | BYTE DeviceAddrBusRangeLow; /* Bereich fuer vergebene Busadressen (BusID) */ 94 | BYTE DeviceAddrBusRangeHigh; 95 | BYTE DeviceAddrStringRangeLow; /* Bereich fuer vergebene Strangadressen (StringID) */ 96 | BYTE DeviceAddrStringRangeHigh; 97 | 98 | 99 | TMinQueue MasterCmdQueue; /* Die Queue aller aktuellen Masterkommandos (unbearbeitet)*/ 100 | TMinList WorkingCmdQueue; /* queue of all currently working cmds */ 101 | 102 | TMasterTimeouts Timeouts; /* Die Timeoutzeiten der einzelnen Abfragen an die 103 | SMA-Data-Geraete... */ 104 | WORD iMaxCountOfMCinProgress; //the maximum count of parallel wored master commands... 105 | WORD iCurrMCinProgress; //the count of master commands currently in progress.. 106 | 107 | } TSMADataMaster; 108 | 109 | void TSMADataMaster_Constructor( void ); 110 | void TSMADataMaster_Destructor ( void ); 111 | TSMADataMaster * TSMADataMaster_GetInstance( void ); 112 | 113 | 114 | void TSMADataMaster_OnPktReceived( struct _TIORequest * req, 115 | TOnReceiveInfo * info ); 116 | 117 | void TSMADataMaster_OnReqEnd( struct _TIORequest * req ); 118 | void TSMADataMaster_OnTransfer(struct _TIORequest * req, BYTE percent); 119 | 120 | int TSMADataMaster_AddCmd( TMasterCmdReq * ); 121 | 122 | int TSMADataMaster_GetStateIndex(TSMADataMaster * me); 123 | char * TSMADataMaster_GetStateText(TSMADataMaster * me, int iStateIndex); 124 | 125 | void TSMADataMaster_DoMasterCmds( void ); 126 | void TSMADataMaster_CmdEnds(TMasterCmdReq * CurCmd, TMasterCmdResult state); 127 | void TSMADataMaster_Reset( void ); 128 | void TSMADataMaster_InitTimeouts(TSMADataMaster * master); 129 | 130 | void TSMADataMaster_AddAPIEventListener(void * callb, BYTE ucEventType); 131 | void TSMADataMaster_RemAPIEventListener(void * callb, BYTE ucEventType); 132 | 133 | void TSMADataMaster_FireAPIEventDeviceDetection(BYTE subcode, DWORD devHandle, DWORD miscParam); 134 | void TSMADataMaster_FireAPIEventNewChannelValue(DWORD dChannelHandle, 135 | DWORD dDeviceHandle, 136 | double dValue, 137 | char * textvalue, 138 | int erorrcode); 139 | 140 | int TStateChanReader_ScanUpdateValue(TNetDevice * me, BYTE * Buffer, DWORD nBytes); 141 | 142 | int TSMADataMaster_SubscribeChannels(DWORD DevHandle, DWORD * ChanHandleArray, WORD arraySize, int iPollInterval); 143 | int TSMADataMaster_UnsubscribeChannels(DWORD DevHandle, DWORD * ChanHandleArray, WORD arraySize); 144 | 145 | void TStateFinisher_OnEnter(TMasterCmdReq * mc ); 146 | struct _TMasterState * TStateFinisher_GetInstance( void ); 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /sdk/master/stateident.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | 23 | #include "os.h" 24 | #include "states.h" 25 | 26 | #include "stateconfig.h" 27 | #include "statereadchan.h" 28 | #include "statewritechan.h" 29 | //#include "statedetection.h" 30 | #include "stateident.h" 31 | 32 | #include "master.h" 33 | #include "debug.h" 34 | #include "smadata_layer.h" 35 | #include "netdevice.h" 36 | #include "plant.h" 37 | #include "mastercmd.h" 38 | #include "repository.h" 39 | 40 | extern TSMADataMaster Master; 41 | 42 | 43 | /************************************************************************** 44 | *************************************************************************** 45 | ******************* MASTER STATE CLASS : IDENTIFICATION ******************* 46 | *************************************************************************** 47 | **************************************************************************/ 48 | 49 | TMasterState * TStateIdent_GetInstance( void ) 50 | { 51 | static TMasterState TStateIdent_Instance; 52 | static TMasterState * _Instance = NULL; 53 | 54 | //YASDI_DEBUG(( VERBOSE_MASTER, "TStateIdent::GetInstance\n" )); 55 | 56 | if (!_Instance) 57 | { 58 | _Instance = &TStateIdent_Instance; 59 | _Instance->OnIOReqEnd = TStateIdent_OnIOReqEnd; 60 | _Instance->OnIOReqPktRcv = TStateIdent_OnIOReqPktRcv; 61 | _Instance->OnEnter = TStateIdent_OnEnter; 62 | _Instance->GetStateIndex = NULL; 63 | } 64 | 65 | return _Instance; 66 | } 67 | 68 | 69 | void TStateIdent_OnEnter( TMasterCmdReq * mc) 70 | { 71 | TNetDevice * founddev = NULL; 72 | BOOL bDevTypeFound; 73 | int i; 74 | 75 | YASDI_DEBUG((VERBOSE_MASTER, "TStateIdent::OnEnter()\n")); 76 | 77 | 78 | TDeviceList_Clear( mc->NewFoundDevList ); 79 | 80 | /* Erzeuge Liste der Geraete, dessen Kanalliste geholt werden muessen... */ 81 | /* Geraet suchen, dessen Kanalliste noch nicht existiert... */ 82 | FOREACH_DEVICE(i, TPlant_GetDeviceList(), founddev ) 83 | { 84 | /* Kanalliste zu diesem Geraet vorhanden? */ 85 | if (!TNetDevice_IsChanListPresent( founddev ) ) 86 | { 87 | /* 88 | ** Geraet hat keine Kanalliste: Schaue nach, ob 89 | ** ein Geraet mit dessen Kanaltyp schon in der (temp.) Geraeteliste 90 | ** darin enthalten ist! Denn eine Kanalliste eines Typs muss auch 91 | ** nur von EINEM dieser Geraet geholt werden 92 | */ 93 | int ii; 94 | TNetDevice * dev; 95 | bDevTypeFound = false; 96 | FOREACH_DEVICE(ii, mc->NewFoundDevList->DevList, dev ) 97 | { 98 | if (strcmp(TNetDevice_GetType( dev ), TNetDevice_GetType( founddev ) )== 0) 99 | { 100 | bDevTypeFound = true; 101 | break; 102 | } 103 | } 104 | 105 | if (!bDevTypeFound) 106 | { 107 | TDeviceList_Add( mc->NewFoundDevList, founddev ); 108 | } 109 | } 110 | } 111 | 112 | YASDI_DEBUG(( VERBOSE_MASTER, 113 | "TStateIdent::OnEnter(): Ask %ld device(s) for their channel list\n", 114 | TDeviceList_GetCount( mc->NewFoundDevList) )); 115 | 116 | mc->NewFoundDevListIter = 0; 117 | TStateIdent_CheckNextDev( mc ); 118 | } 119 | 120 | 121 | void TStateIdent_CheckNextDev( TMasterCmdReq * mc ) 122 | { 123 | TNetDevice * dev; 124 | 125 | /* was zum Iterieren? */ 126 | dev = GET_NEXT_DEVICE(mc->NewFoundDevListIter, mc->NewFoundDevList->DevList); 127 | if (dev) 128 | { 129 | TSMAData_InitReqGetChanInfo( 130 | mc->IOReq, 131 | Master.SrcAddr, /* eigene Netzadresse */ 132 | TNetDevice_GetNetAddr(dev), /* Zieladresse */ 133 | 4, /* Timeout */ 134 | 5 /* Repeat */ 135 | //TNetDevice_GetBusDriverDeviceHandle( dev ) 136 | ); 137 | 138 | mc->IOReq->TxFlags |= dev->prodID; //Das zu verwendene Transport-Protokoll einstellen 139 | 140 | TSMAData_AddIORequest( mc->IOReq ); 141 | YASDI_DEBUG(( VERBOSE_MASTER, 142 | "TStateIdent::CheckNextDev(): Request channel list from " 143 | "device '%s'...\n", 144 | TNetDevice_GetName( dev ) )); 145 | } 146 | else 147 | { 148 | YASDI_DEBUG(( VERBOSE_MASTER, 149 | "TStateIdent::CheckNextDev(): Finishing state. All done.\n" )); 150 | 151 | //the result of the current master command was set by detection state 152 | //I do not change the result here.. 153 | 154 | // finish this master command... 155 | TSMADataCmd_ChangeState(mc, TStateFinisher_GetInstance() ); 156 | } 157 | } 158 | 159 | 160 | void TStateIdent_OnIOReqEnd( TMasterCmdReq * mc, struct _TIORequest * req) 161 | { 162 | UNUSED_VAR ( req ); 163 | 164 | TStateIdent_CheckNextDev( mc ); 165 | } 166 | 167 | void TStateIdent_OnIOReqPktRcv( TMasterCmdReq * mc, 168 | struct _TIORequest * req, 169 | TOnReceiveInfo * rcvInfo) 170 | { 171 | TNetDevice * dev; 172 | 173 | UNUSED_VAR ( mc ); 174 | 175 | YASDI_DEBUG((VERBOSE_MASTER, "TStateIdent::OnIOReqPktRcv()\n" )); 176 | 177 | /* 178 | ** Kanalliste auf Datentraeger sichern... 179 | */ 180 | dev = TPlant_FindDevAddr( req->DestAddr ); 181 | if (dev) 182 | { 183 | TPlant_StoreChanList( rcvInfo->Buffer, rcvInfo->BufferSize, TNetDevice_GetType( dev ) ); 184 | } 185 | } 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /sdk/master/mastercmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #ifndef ___MASTERCMD_H___ 23 | #define ___MASTERCMD_H___ 24 | 25 | #include "os.h" 26 | #include "timer.h" 27 | #include "iorequest.h" 28 | #include "netdevice.h" 29 | #include "netchannel.h" 30 | #include "states.h" 31 | 32 | 33 | 34 | 35 | /* 36 | ** master command states (the result) 37 | */ 38 | typedef enum 39 | { 40 | MCS_NONE = 0, /* unbekannt */ 41 | MCS_WORKING, /* in Bearbeitung */ 42 | MCS_SUCCESS, /* Erfolgreich beendet */ 43 | MCS_TIMEOUT, /* mit Fehler "Zeitueberschreitung" beendet */ 44 | MCS_ABORT, /* Das Kommando wurde abgebrochen */ 45 | MCS_GENERAL_ERROR /* General error executing master command */ 46 | } TMasterCmdResult; 47 | 48 | 49 | /* 50 | ** all supported "Master Commands" 51 | */ 52 | typedef enum 53 | { 54 | MC_UNKNOWN=0, // default... 55 | MC_GET_PARAMCHANNELS, /* alle Parameter-Kanaele eines Geraetes lesen */ 56 | MC_GET_SPOTCHANNELS, /* explizites Lesen aller Spotwertkanaele */ 57 | MC_GET_TESTCHANNELS, /* explizites Lesen aller Testwertkanaele */ 58 | MC_SET_PARAMCHANNEL, /* einen bestimmten Parameter-Kanal setzen... */ 59 | MC_RESET, /* Vollstaendiger Reset, wie Neustart */ 60 | MC_DETECTION, /* Erfassung weiterer Geraete... */ 61 | MC_REMOVE_DEVICE, /* Remove device from current plant */ 62 | MC_GET_BIN_INFO, /* Reading Binary Info */ 63 | MC_GET_BIN, /* Reading Binary Area */ 64 | } TMasterCmdType; 65 | 66 | 67 | 68 | 69 | //!An "Master Command itelf" 70 | typedef struct _TMasterCmdReq 71 | { 72 | TMinNode Node; /* for linking ... */ 73 | TMasterCmdType CmdType; /* the command type */ 74 | TMasterCmdResult Result; /* the current result (status) of this command */ 75 | BOOL isResultValid; // mark the "result" as valid or not. Used when waiting for cmd... 76 | struct _TMasterState * State; /* the current state of this master command */ 77 | struct _TIORequest * IOReq; //the iorequest for this command 78 | 79 | struct 80 | { 81 | TObjectHandle DevHandle; // Device Parameter 82 | TObjectHandle ChanHandle; // Kanal Parameter 83 | DWORD dwValueAge; // Requesting channel values: Max Age of it... 84 | DWORD DriverID; /* OPTIONAL: Detection only to an special bus driver ???*/ 85 | DWORD DriverDeviceHandle; /* OPTIONAL: Detection only to an special device ID ??? */ 86 | WORD DetectionTransportProtID; /* make an detection only with these transport protocol in sequence */ 87 | } Param; 88 | 89 | /** Optional Callback function 90 | * Called when Master command was finished 91 | */ 92 | void (*OnEnd)(struct _TMasterCmdReq *); 93 | 94 | 95 | /* ###### Detection parameters....###### */ 96 | int NewFoundDevListIter; //Iterator fuer die "NewFoundDevList" 97 | WORD wDetectDevMax; /* Anzahl der Geraete, die bei der Erfassung 98 | gefunden werden muessen */ 99 | int iDetectMaxTrys; /* die maximalen Versuche, die 100 | angegebene Geraeteanzahl zu erfassen */ 101 | WORD wTransportProts; /* Bei der Erfassung: Mit welchem Transportokoll 102 | muss noch erfasst werden (SunnyNet, SMANet) */ 103 | struct _TDeviceList * NewFoundDevList; /* Die Geraeteliste, der gerade gefunden 104 | Geraete beim Erfassen */ 105 | BYTE bDetectionStart; /* Flag fuer Entscheidung: 106 | CMD_GET_NET oder 107 | CMD_GET_NET_START */ 108 | WORD lastUsedTransportProt; /* used for toggle the transportprot during 109 | an device detection */ 110 | 111 | /* ###### READ Channel value ######## */ 112 | BOOL synconlinesend; // was sync online send? 113 | 114 | // ###### Reading Binary info ###### 115 | TBinInfo * bininfo; //Array of all binary infos (CMD_GET_SBIN) 116 | BYTE bArrayCount; //The count of array elements in it... 117 | BYTE * bBinaryData; //The data of the binary area when requested... 118 | 119 | //#### writing parameter #### 120 | double dChanVal; //This channel value will be written when setting channel parameters 121 | 122 | } TMasterCmdReq; 123 | 124 | 125 | 126 | TMasterCmdReq * TMasterCmd_Constructor( TMasterCmdType cmd); 127 | void TMasterCmd_Destructor( TMasterCmdReq * me); 128 | TMasterCmdResult TMasterCmd_WaitFor( TMasterCmdReq * me ); 129 | 130 | //private... 131 | struct _TMasterState; 132 | void TSMADataCmd_ChangeState( TMasterCmdReq * me, struct _TMasterState * newstate ); 133 | 134 | 135 | void TMasterCmdFactory_Init( void ); 136 | void TMasterCmdFactory_Destroy( void ); 137 | TMasterCmdReq * TMasterCmdFactory_GetMasterCmd( TMasterCmdType cmd ); 138 | void TMasterCmdFactory_FreeMasterCmd( TMasterCmdReq * mc ); 139 | int TMasterCmdFactory_GetUnsedCmds(void ); 140 | 141 | extern int masterCmdCount; //count of all master commands... 142 | 143 | 144 | 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /sdk/core/minmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | #include "os.h" 23 | #include "minmap.h" 24 | 25 | //when resizing add 100 new elements... 26 | #define TMAP_ADD_ELEMENTS_STEP 100 27 | #define HANDLE_MASK 0x7fffffffL 28 | 29 | // ######################################## 30 | 31 | 32 | void TMap_Init ( TMap * me, int size_Of_Key, int size_Of_Value, int depotElementCount, int (*compFunc)(const void*, const void*) ) 33 | { 34 | //allocate enough space for the map... 35 | me->mapfield = os_malloc( (size_Of_Key + size_Of_Value) * depotElementCount); 36 | me->maxElementCount = depotElementCount; 37 | me->size_Of_Key = size_Of_Key; 38 | me->size_Of_Value = size_Of_Value; 39 | me->curCountElements = 0; 40 | me->compFunc = compFunc; 41 | } 42 | 43 | void TMap_Free( TMap * me ) 44 | { 45 | os_free( me->mapfield ); 46 | } 47 | 48 | void TMap_Resize(TMap * me, int newelements) 49 | { 50 | BYTE * newmapfiled = os_malloc( (me->size_Of_Key + me->size_Of_Value) * newelements ); 51 | os_memcpy(newmapfiled, me->mapfield, me->maxElementCount * (me->size_Of_Key + me->size_Of_Value) ); 52 | os_free( me->mapfield ); 53 | me->mapfield = newmapfiled; 54 | me->maxElementCount = newelements; 55 | } 56 | 57 | TMap * TMap_Constructor( int size_Of_Key, int size_Of_Value, int depotElementCount, int (*compFunc)(const void*, const void*) ) 58 | { 59 | TMap * me = os_malloc( sizeof(TMap) ); 60 | assert(me); 61 | TMap_Init( me, size_Of_Key, size_Of_Value, depotElementCount, compFunc); 62 | return me; 63 | } 64 | 65 | void TMap_Destructor( TMap * me) 66 | { 67 | assert(me); 68 | TMap_Free(me); 69 | os_free( me ); 70 | } 71 | 72 | void * TMap_GetElemAt(TMap * me, int index) 73 | { 74 | return me->mapfield + (me->size_Of_Key + me->size_Of_Value) * index; 75 | } 76 | 77 | //! Adds an new entry... 78 | void TMap_Add ( TMap * me, void * key, void * value ) 79 | { 80 | void * foundElem; 81 | if (me->curCountElements+1 > me->maxElementCount) 82 | { 83 | //Map is too small: Must be resized... 84 | TMap_Resize(me, me->maxElementCount + TMAP_ADD_ELEMENTS_STEP); 85 | } 86 | 87 | //search it... 88 | foundElem = TMap_Find(me, key ); 89 | if (!foundElem) 90 | { 91 | BYTE * ptr; 92 | //add an new entry at the end of the list... 93 | 94 | ptr = TMap_GetElemAt(me, me->curCountElements); 95 | //the first part is the key than the value... 96 | if (me->size_Of_Key) os_memcpy(ptr, key, me->size_Of_Key); 97 | if (me->size_Of_Value) os_memcpy(ptr+me->size_Of_Key, value, me->size_Of_Value); 98 | 99 | me->curCountElements++; 100 | 101 | //sort map... 102 | os_qsort(me->mapfield, me->curCountElements, 103 | me->size_Of_Key + me->size_Of_Value, 104 | me->compFunc); 105 | } 106 | else 107 | { 108 | //update value... 109 | os_memcpy(foundElem, value, me->size_Of_Value); 110 | } 111 | } 112 | 113 | //! finds an entry and returns an pointer to the value part of the entry... 114 | void * TMap_Find( TMap * me, void * key) 115 | { 116 | //search it... 117 | void * foundElem; 118 | foundElem = os_bsearch( key, me->mapfield, 119 | me->curCountElements, 120 | me->size_Of_Key + me->size_Of_Value, 121 | me->compFunc ); 122 | 123 | //return pointer to value part... 124 | if (foundElem) return ((BYTE*)foundElem) + me->size_Of_Key; 125 | return NULL; 126 | } 127 | 128 | //! removes an Entry from map... 129 | void TMap_Remove(TMap * me, void * key) 130 | { 131 | void * foundElem; 132 | BYTE * pToKey; 133 | int iPos; 134 | int memsize; 135 | 136 | foundElem = TMap_Find(me, key); 137 | if (!foundElem) return; //???? not in map!!! 138 | 139 | //one less 140 | me->curCountElements--; 141 | 142 | //pointer to key is sizelenkey before... 143 | pToKey = ((BYTE*)foundElem) - me->size_Of_Key; 144 | 145 | //calc the current position 146 | iPos = (pToKey - me->mapfield) / (me->size_Of_Key+ me->size_Of_Value); 147 | memsize = (me->curCountElements - iPos) * (me->size_Of_Key+ me->size_Of_Value); 148 | 149 | 150 | //copy all memory above to the current pos... 151 | os_memmove(pToKey, 152 | pToKey + me->size_Of_Key + me->size_Of_Value, 153 | memsize 154 | ); 155 | } 156 | 157 | 158 | 159 | #ifdef DEBUG 160 | //! compares two keys in th TMap 161 | int compare(const void * e1, const void * e2) 162 | { 163 | //compare only the lowest 31 bit, ignore the highest bit... 164 | DWORD v1, v2; 165 | v1 = *(DWORD*)e1 & HANDLE_MASK; 166 | v2 = *(DWORD*)e2 & HANDLE_MASK; 167 | if ( v1 == v2 ) return 0; 168 | else if (v1 < v2) return -1; 169 | else 170 | return 1; 171 | } 172 | 173 | void TMap_unitTest( void ) 174 | { 175 | DWORD l2; 176 | DWORD l3; 177 | void * foundEntry; 178 | TMap * map = TMap_Constructor(sizeof(DWORD), 179 | sizeof(WORD), 180 | 10, 181 | compare ); 182 | DWORD key = 18; 183 | WORD val = 1018; 184 | TMap_Add(map, &key, &val); 185 | val = 0x7777; 186 | TMap_Add(map, &key, &val); 187 | 188 | key --; 189 | val --; 190 | TMap_Add(map, &key, &val); 191 | 192 | key --; 193 | val --; 194 | TMap_Add(map, &key, &val); 195 | 196 | key --; 197 | val --; 198 | TMap_Add(map, &key, &val); 199 | 200 | l2 = 18; 201 | //void * t = map->mapfield; 202 | foundEntry = TMap_Find(map,&l2); 203 | printf("Unit Test: %d\n", *(WORD*)foundEntry); 204 | 205 | l3 = 15; 206 | TMap_Remove(map, &l3); 207 | 208 | TMap_Destructor( map ); 209 | } 210 | 211 | #endif 212 | 213 | 214 | -------------------------------------------------------------------------------- /sdk/master/busevents.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | 23 | #include "os.h" 24 | #include "debug.h" 25 | #include "smadata_layer.h" 26 | #include "master.h" 27 | #include "mastercmd.h" 28 | #include "busevents.h" 29 | #include "router.h" 30 | #include "plant.h" 31 | 32 | 33 | static int busevents=0; //count of all bus driver events... 34 | 35 | int TSMADataMaster_GetCountBusEvents(void) 36 | { 37 | return busevents; 38 | } 39 | 40 | 41 | /************************************************************************** 42 | * 43 | * NAME : 44 | * 45 | * DESCRIPTION : Bus Event dispatcher 46 | * An bus event has occurred... 47 | * 48 | * 49 | *************************************************************************** 50 | * 51 | * IN : --- 52 | * 53 | * OUT : --- 54 | * 55 | * RETURN : --- 56 | * 57 | * THROWS : --- 58 | * 59 | **************************************************************************/ 60 | void TSMADataMaster_OnBusEvent(TGenDriverEvent * event) 61 | { 62 | assert(event); 63 | YASDI_DEBUG((VERBOSE_MASTER, 64 | "TSMADataMaster_OnBusEvent(eventType=%d)...\n", 65 | (int)event->eventType )); 66 | busevents++; 67 | 68 | //dispatch events... 69 | switch(event->eventType) 70 | { 71 | case DRE_BUS_CONNECTED: TSMADataMaster_OnEventBusConnected(event); break; 72 | case DRE_PEER_ADDED: TSMADataMaster_OnEventPeerAdded(event); break; 73 | case DRE_PEER_REMOVED: TSMADataMaster_OnEventPeerRemoved(event); break; 74 | default: 75 | YASDI_DEBUG((VERBOSE_ERROR, 76 | "TSMADataMaster_OnBusEvent(): Unknown event...\n", 77 | (int)event->eventType )); 78 | } 79 | } 80 | 81 | 82 | /************************************************************************** 83 | * 84 | * NAME : 85 | * 86 | * DESCRIPTION : 87 | * 88 | * 89 | *************************************************************************** 90 | * 91 | * IN : --- 92 | * 93 | * OUT : --- 94 | * 95 | * RETURN : --- 96 | * 97 | * THROWS : --- 98 | * 99 | **************************************************************************/ 100 | void TSMADataMaster_OnEventBusConnected(TGenDriverEvent * event) 101 | { 102 | 103 | /* Master command to detect the new device...*/ 104 | TMasterCmdReq * mc = TMasterCmdFactory_GetMasterCmd( MC_DETECTION ); 105 | mc->OnEnd = TSMADataMaster_OnEventMasterCmdEnded; 106 | 107 | /* Detect one device more on an special Bus driver with 108 | an special driver device handle... 109 | Do not calculate the device count here because because the device 110 | count may be changed in the meantime... 111 | */ 112 | mc->wDetectDevMax = DETECT_ONE_MORE_DEV; // flag: one more than actual 113 | mc->iDetectMaxTrys = 6; //normal tries for broadband detection... 114 | mc->Param.DriverID = event->DriverID; // the bus driver ID 115 | mc->Param.DriverDeviceHandle = INVALID_DRIVER_DEVICE_HANDLE; //no special bus device: 116 | //Detect all available devices 117 | //sub to the bus driver.. 118 | 119 | /* Send master command (async)... */ 120 | TSMADataMaster_AddCmd( mc ); 121 | } 122 | 123 | 124 | 125 | //! Event: An new peer was added to the bus 126 | void TSMADataMaster_OnEventPeerAdded(TGenDriverEvent * event) 127 | { 128 | /* Master command to detect the new device...*/ 129 | TMasterCmdReq * mc = TMasterCmdFactory_GetMasterCmd( MC_DETECTION ); 130 | mc->OnEnd = TSMADataMaster_OnEventMasterCmdEnded; 131 | 132 | /* Detect one device more on an special Bus driver with 133 | an special Device-Handle...*/ 134 | mc->wDetectDevMax = DETECT_ONE_MORE_DEV; /* flag: one more than actual */ 135 | mc->iDetectMaxTrys = 2; /* only two tries (SMANet + SunnyNet) */ 136 | mc->Param.DriverID = event->DriverID; 137 | mc->Param.DriverDeviceHandle = event->EventData.DriverDeviceHandle; //direct it to that device... 138 | 139 | /* Send master command (async)... */ 140 | TSMADataMaster_AddCmd( mc ); 141 | } 142 | 143 | 144 | //! An Peer was removed. Remove this device from the current list of devices 145 | void TSMADataMaster_OnEventPeerRemoved(TGenDriverEvent * event) 146 | { 147 | TNetDevice * dev; 148 | WORD netaddr = 0; 149 | 150 | //try to resolve from "DriverDeviceHandle" to the right device pointer 151 | if (TRoute_FindAddrByDriverDevicePeer(event->DriverID, event->EventData.DriverDeviceHandle, &netaddr) && 152 | (dev = TPlant_FindDevAddr(netaddr)) != NULL) 153 | { 154 | /*Master command to detect the new device...*/ 155 | TMasterCmdReq * mc = TMasterCmdFactory_GetMasterCmd( MC_REMOVE_DEVICE ); 156 | mc->OnEnd = TSMADataMaster_OnEventMasterCmdEnded; 157 | mc->Param.DevHandle = TNetDevice_GetHandle( dev ); 158 | 159 | YASDI_DEBUG((VERBOSE_ERROR,"TSMADataMaster_OnEventPeerRemoved(): " 160 | "Removing Device '%s', DriverDevHandle=%d\n", 161 | TNetDevice_GetName( dev ), event->EventData.DriverDeviceHandle )); 162 | 163 | 164 | /*Send master command (async)...*/ 165 | TSMADataMaster_AddCmd( mc ); 166 | } 167 | else 168 | { 169 | YASDI_DEBUG((VERBOSE_ERROR,"TSMADataMaster_OnEventPeerRemoved(): " 170 | "Unknown device to remove, DriverDevHandle=0x%x...\n", 171 | event->EventData.DriverDeviceHandle)); 172 | } 173 | } 174 | 175 | 176 | //! Called when an master command ends which was self added by an bus event... 177 | void TSMADataMaster_OnEventMasterCmdEnded( struct _TMasterCmdReq * mc) 178 | { 179 | YASDI_DEBUG((VERBOSE_MESSAGE,"TSMADataMaster_OnEventMasterCmdEnded(): " 180 | " Event finished (type=%d)\n", 181 | mc->CmdType)); 182 | //only free the command. That's it... 183 | TMasterCmdFactory_FreeMasterCmd( mc ); 184 | } 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /sdk/master/statewritechan.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | 23 | #include "os.h" 24 | #include "states.h" 25 | #include "statewritechan.h" 26 | #include "master.h" 27 | #include "debug.h" 28 | #include "smadata_layer.h" 29 | #include "netdevice.h" 30 | #include "plant.h" 31 | #include "mastercmd.h" 32 | #include "repository.h" 33 | 34 | extern TSMADataMaster Master; 35 | 36 | 37 | 38 | /************************************************************************** 39 | *************************************************************************** 40 | ******************* MASTER STATE CLASS : ChanWriter *********************** 41 | *************************************************************************** 42 | **************************************************************************/ 43 | 44 | TMasterState * TStateChanWriter_GetInstance() 45 | { 46 | static TMasterState TStateChanWriter_Instance; 47 | static TMasterState * _Instance = NULL; 48 | 49 | //YASDI_DEBUG(( VERBOSE_MASTER, "TStateChanWriter::GetInstance\n" )); 50 | 51 | if (!_Instance) 52 | { 53 | _Instance = &TStateChanWriter_Instance; 54 | _Instance->OnIOReqEnd = TStateChanWriter_OnIOReqEnd; 55 | _Instance->OnIOReqPktRcv = TStateChanWriter_OnIOReqPktRcv; 56 | _Instance->OnEnter = TStateChanWriter_OnEnter; 57 | _Instance->GetStateIndex = NULL; 58 | } 59 | 60 | return _Instance; 61 | } 62 | 63 | 64 | void TStateChanWriter_OnEnter (TMasterCmdReq * mc) 65 | { 66 | TNetDevice * Device; 67 | TChannel * Channel; 68 | WORD maxValBufferSize; 69 | BYTE * ValBuffer; 70 | WORD ValBufferUse; /* Benutzte Buffergroesse */ 71 | 72 | #ifdef DEBUG 73 | double dChannelValue; 74 | char StatTextBuffer[20]; 75 | #endif 76 | 77 | 78 | YASDI_DEBUG(( VERBOSE_MASTER, "TStateChanWriter::OnEnter\n" )); 79 | 80 | Device = TObjManager_GetRef( mc->Param.DevHandle ); 81 | Channel = TObjManager_GetRef( mc->Param.ChanHandle ); 82 | if (!Device || !Channel) 83 | { 84 | //Handels invalid... 85 | YASDI_DEBUG(( VERBOSE_ERROR, "TStateChanWriter::OnEnter() Handle invalid..end\n" )); 86 | mc->Result = MCS_GENERAL_ERROR; 87 | TSMADataCmd_ChangeState( mc, TStateFinisher_GetInstance() ); 88 | return; 89 | } 90 | 91 | 92 | /* genuegend grossen Puffer fuer Kanalwert beschaffen */ 93 | maxValBufferSize = TChannel_GetValArraySize( Channel ) * sizeof(DWORD); 94 | ValBuffer = os_malloc( maxValBufferSize ); 95 | 96 | 97 | //set the channel value in the channel object 98 | TChannel_SetValue(Channel, Device, mc->dChanVal); 99 | 100 | /* Der gesetzte Kanalwert wird als veraltet markiert, damit der Kanalwert 101 | ** beim naechsten lesendenden Zugriff erneut vom Geraet abgefragt wird */ 102 | TChannel_SetTimeStamp(Channel, Device, 0); 103 | 104 | 105 | #ifdef DEBUG 106 | dChannelValue = TChannel_GetValue( Channel, Device, 0 ); 107 | 108 | //kein Kanaltext verfuegbar? 109 | if (TChannel_GetValueText( Channel, Device, 110 | StatTextBuffer, sizeof(StatTextBuffer)-1 ) == 0) 111 | { 112 | //Nur den numerischen Wert nehmen... 113 | sprintf(StatTextBuffer,"%2.2f", dChannelValue); 114 | } 115 | 116 | 117 | YASDI_DEBUG((VERBOSE_MASTER, 118 | "TStateChanWriter::OnEnter(): Setting parameter '%s' " 119 | "from device '%s' to value '%s' !" 120 | "...\n", 121 | TChannel_GetName( Channel ), 122 | TNetDevice_GetName( Device ), 123 | StatTextBuffer 124 | )); 125 | #endif 126 | 127 | /* Kanalwert in Puffer schreiben */ 128 | ValBufferUse = TChannel_GetRawValue( Channel, Device, ValBuffer, maxValBufferSize ); 129 | 130 | /* Paket zusammenbauen */ 131 | TSMAData_InitReqSetChannel( mc->IOReq, 132 | Master.SrcAddr, /* eigene Netzadresse */ 133 | TNetDevice_GetNetAddr( Device), /* the device */ 134 | TChannel_GetCType( Channel ), /* Maske des Kanals */ 135 | TChannel_GetIndex( Channel ), /* " */ 136 | ValBuffer, /* Pointer auf den Kanalwert */ 137 | ValBufferUse, /* Laenge des Kanalwertes in Bytes */ 138 | Master.Timeouts.iSetParamChanTimeout, /* Timeout */ 139 | Master.Timeouts.iSetParamChanRetry /* Wdh bei Timeout */ 140 | ); 141 | /* und abschicken */ 142 | //Das zu verwendene Protokoll einstellen 143 | mc->IOReq->TxFlags |= Device->prodID; 144 | 145 | //Wenn ein BusDriverDevHandle bekannt ist, setzen wir es im IORequest... 146 | //mc->IOReq->BusDriverDeviceHandle = TNetDevice_GetBusDriverDeviceHandle( Device ); 147 | 148 | //request absetzen (Dateninhalt wird kopiert)... 149 | TSMAData_AddIORequest( mc->IOReq ); 150 | 151 | /* markiere das Kommando, dass es gerade bearbeitet wird... */ 152 | mc->Result = MCS_WORKING; 153 | 154 | /* Free memory */ 155 | os_free( ValBuffer ); 156 | ValBuffer = NULL; 157 | } 158 | 159 | 160 | 161 | void TStateChanWriter_OnIOReqEnd( TMasterCmdReq * mc, 162 | struct _TIORequest * req) 163 | { 164 | YASDI_DEBUG(( VERBOSE_MASTER, "TStateChanWriter::OnIOReqEnd\n" )); 165 | 166 | //finished... 167 | mc->Result = (req->Status == RS_TIMEOUT) ? MCS_TIMEOUT : MCS_SUCCESS; 168 | TSMADataCmd_ChangeState(mc, TStateFinisher_GetInstance()); 169 | } 170 | 171 | 172 | 173 | void TStateChanWriter_OnIOReqPktRcv( TMasterCmdReq * mc, 174 | struct _TIORequest * req, 175 | TOnReceiveInfo * rcvInfo) 176 | { 177 | UNUSED_VAR ( req ); 178 | UNUSED_VAR ( mc ); 179 | 180 | YASDI_DEBUG(( VERBOSE_MASTER, 181 | "TStateChanWriter::OnIOReqPktRcv(): Set parameter acknowledge. Size=%ld\n", 182 | rcvInfo->BufferSize )); 183 | } 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /sdk/master/chanvalrepo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * YASDI - (Y)et (A)nother (S)MA(D)ata (I)mplementation 3 | * Copyright(C) 2001-2008 SMA Solar Technology AG 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library in the file COPYING.LIB; 17 | * if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 | * 20 | */ 21 | 22 | /************************************************************************** 23 | * Project : YASDI 24 | *************************************************************************** 25 | * Project-no. : 26 | *************************************************************************** 27 | * Filename : chanvalrepo.c 28 | *************************************************************************** 29 | * Description : Storage for channel values (online values only) 30 | *************************************************************************** 31 | * Preconditions : --- 32 | *************************************************************************** 33 | * Changes : Author, Date, Version, Reason 34 | * ********************************************************* 35 | * Pruessing, 27.12.2006, Created 36 | ***************************************************************************/ 37 | 38 | //###### include ########################################################### 39 | 40 | 41 | #include "os.h" 42 | #include "smadef.h" 43 | #include "debug.h" 44 | #include "chanvalrepo.h" 45 | 46 | //Maske um nur das Handle auszumaskieren. Bit 31 wird als "value valid" bit misbraucht... 47 | #define HANDLE_MASK 0x7fffffffL 48 | 49 | //###### local ############################################################# 50 | 51 | typedef WORD TChanValByteOffset; 52 | 53 | void TChanValRepo_CalculateOffsets(TChanValRepo * this, TChanList * channelList); 54 | 55 | //! compares two keys in th TMap 56 | int TChanValRepo_CompareEntry(const void * e1, const void * e2) 57 | { 58 | //compare only the lowest 31 bit, ignore the highest bit... 59 | DWORD v1, v2; 60 | v1 = GetDWORD(e1) & HANDLE_MASK; 61 | v2 = GetDWORD(e2) & HANDLE_MASK; 62 | if ( v1 == v2 ) return 0; 63 | else if (v1 < v2) return -1; 64 | else 65 | return 1; 66 | } 67 | 68 | 69 | 70 | //###### impl ############################################################## 71 | 72 | 73 | //!Constructs an new repo... 74 | TChanValRepo * TChanValRepo_Constructor( TChanList * channelList ) 75 | { 76 | int i=0; 77 | TChannel * c; 78 | TChanValRepo * this; 79 | int channelCnt = 0; 80 | 81 | 82 | this = os_malloc( sizeof(TChanValRepo) ); 83 | 84 | //calc the size of all values to get the right memory size... 85 | i=0; 86 | FOREACH_CHANNEL(i, channelList->ChanList, c, NULL) 87 | { 88 | this->sizeOfBlock = this->sizeOfBlock + 89 | TChannel_GetValCnt(c) * TChannel_GetValueWidth(c); 90 | //printf("%u: '%s' size=%d\n", channelCnt, TChannel_GetName(c), this->sizeOfBlock); 91 | channelCnt++; 92 | } 93 | 94 | TMap_Init(&this->map, 95 | sizeof(TObjectHandle), 96 | sizeof(TChanValByteOffset), 97 | channelCnt, 98 | TChanValRepo_CompareEntry); 99 | 100 | this->chanvalueblock = os_malloc( this->sizeOfBlock ); 101 | 102 | //create the offsets and init map... 103 | TChanValRepo_CalculateOffsets(this, channelList); 104 | 105 | 106 | 107 | return this; 108 | } 109 | 110 | //!Frees all cached channel values... 111 | void TChanValRepo_Destructor(TChanValRepo * this) 112 | { 113 | assert(this); 114 | TMap_Free( &this->map ); 115 | os_free( this->chanvalueblock ); this->chanvalueblock = NULL; 116 | os_free(this); 117 | } 118 | 119 | 120 | void * TChanValRepo_GetValuePtr(TChanValRepo * this, TObjectHandle chanHandle) 121 | { 122 | WORD * pOffsetVal = TMap_Find(&this->map, &chanHandle); 123 | assert(pOffsetVal); 124 | return this->chanvalueblock + *pOffsetVal ; 125 | } 126 | 127 | void TChanValRepo_SetValueValid(TChanValRepo * this, TObjectHandle chanHandle, BOOL val ) 128 | { 129 | 130 | BYTE * k1 = TMap_Find(&this->map, &chanHandle); 131 | DWORD * pkey; 132 | assert(k1); 133 | k1 = k1 - 4; 134 | pkey = (DWORD*)k1; 135 | 136 | if (val) 137 | WriteDWORD((BYTE*)pkey, GetDWORD(pkey) | (1L<<31) ); //set bit 31; 138 | else 139 | WriteDWORD((BYTE*)pkey, GetDWORD(pkey) & HANDLE_MASK); 140 | 141 | } 142 | 143 | BOOL TChanValRepo_IsValueValid(TChanValRepo * this, TObjectHandle chanHandle ) 144 | { 145 | BYTE * pVal = TMap_Find(&this->map, &chanHandle); 146 | DWORD * key = (DWORD*)(pVal - sizeof(DWORD)); 147 | BOOL valid = ((GetDWORD(key)) & (1L<<31)) != 0; 148 | assert(key); 149 | return valid; 150 | } 151 | 152 | 153 | 154 | //!Calculate alle value offsets.. 155 | void TChanValRepo_CalculateOffsets(TChanValRepo * this, TChanList * channelList) 156 | { 157 | int i=0; 158 | TChannel * c; 159 | WORD currOffset = 0; 160 | TObjectHandle ChanHandle; 161 | FOREACH_CHANNEL(i, channelList->ChanList, c, NULL) 162 | { 163 | ChanHandle = c->Handle; 164 | 165 | //**** key = ChanHandle, value = currOffset *** 166 | TMap_Add ( &this->map, 167 | &ChanHandle, //key (DWORD) 168 | &currOffset ); //value: "offset" (WORD) 169 | currOffset = currOffset + TChannel_GetValCnt(c) * TChannel_GetValueWidth(c); 170 | } 171 | assert(currOffset == this->sizeOfBlock); 172 | } 173 | 174 | void TChanValRepo_SetTimeStamp(TChanValRepo * this, TChannel * chan, DWORD time) 175 | { 176 | WORD ctype = TChannel_GetCType(chan); 177 | if ( ctype & CH_PARA) 178 | this->timeParamChannels = time; 179 | else if ( ctype & CH_TEST) 180 | this->timeTestChannels = time; 181 | else if ( ctype & CH_SPOT) 182 | this->timeOnlineChannels = time; 183 | else 184 | assert(false); 185 | } 186 | 187 | DWORD TChanValRepo_GetTimeStamp(TChanValRepo * this, TChannel * chan) 188 | { 189 | WORD ctype = TChannel_GetCType(chan); 190 | if ( ctype & CH_PARA) 191 | return this->timeParamChannels; 192 | else if ( ctype & CH_TEST) 193 | return this->timeTestChannels; 194 | else if ( ctype & CH_SPOT) 195 | return this->timeOnlineChannels; 196 | else 197 | assert(false); 198 | return 0; 199 | } 200 | 201 | 202 | 203 | 204 | --------------------------------------------------------------------------------