From: stefic User Date: Mon, 24 Nov 2008 16:09:56 +0000 (+0100) Subject: Adding embedded-hydro file structure X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hydro.git/commitdiff_plain/30ad8eaeb4a894c71ed8691c87437736fea7d2ab Adding embedded-hydro file structure --- 30ad8eaeb4a894c71ed8691c87437736fea7d2ab diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cafc99f --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + +# DO NOT DELETE diff --git a/Makefile.omk b/Makefile.omk new file mode 100644 index 0000000..049f812 --- /dev/null +++ b/Makefile.omk @@ -0,0 +1 @@ +SUBDIRS = app diff --git a/app/Makefile b/app/Makefile new file mode 100644 index 0000000..b22a357 --- /dev/null +++ b/app/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/app/Makefile.omk b/app/Makefile.omk new file mode 100644 index 0000000..ee88ef2 --- /dev/null +++ b/app/Makefile.omk @@ -0,0 +1,3 @@ +# -*- makefile -*- + +SUBDIRS = hydro diff --git a/app/hydro/Makefile b/app/hydro/Makefile new file mode 100644 index 0000000..cafc99f --- /dev/null +++ b/app/hydro/Makefile @@ -0,0 +1,15 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + +# DO NOT DELETE diff --git a/app/hydro/Makefile.omk b/app/hydro/Makefile.omk new file mode 100644 index 0000000..fe3b8c4 --- /dev/null +++ b/app/hydro/Makefile.omk @@ -0,0 +1,33 @@ + +default_CONFIG = CONFIG_APP_HYDROPONIE=n + +ifeq ($(CONFIG_APP_HYDROPONIE),y) + +ULAN_ID=hydroponie + +default_CONFIG += CONFIG_ULOI_LT=x +default_CONFIG += CONFIG_ULAN_DY=x +default_CONFIG += MACH=$(MACH) +default_CONFIG += ULAN_ID=$(ULAN_ID) + +LOCAL_CONFIG_H = ulan_config.h + +INCLUDES += -I. + + +bin_PROGRAMS = hydroponie +hydroponie_SOURCES = hydroponie.c hydroponieoi.c ul_idstr.c +hydroponie_MOREOBJS = $(USER_LIB_DIR)/system_stub.o +hydroponie_MOREOBJS += $(USER_LIB_DIR)/ivt.o + +ifeq ($(BUILD_OS),linux) +lib_LOADLIBES = uloi uldy ulan pthread rt +DEFS += -DOS_POSIX +else +lib_LOADLIBES = uloi uldy bspbase ulan ul_drv lpciap keyval lpciap lpciap_kvpb mach_hal +endif + +# This selects linker script +link_VARIANTS = app + +endif \ No newline at end of file diff --git a/app/hydro/adc.h b/app/hydro/adc.h new file mode 100644 index 0000000..4cfaee4 --- /dev/null +++ b/app/hydro/adc.h @@ -0,0 +1,14 @@ +#ifndef _ADC_H +#define _ADC_H + +//addresses of ADC registers + +//ADC Control Register +#define ADCR 0xE0034000 +//ADC Status Register +#define ADSTAT 0xE0034030 +//ADC Interrupt Enable Register +#define ADINTEN 0xE003400C + +#define ADDR0 0xE0034010 +#define ADDR1 0xE0034014 \ No newline at end of file diff --git a/app/hydro/hydroponie.c b/app/hydro/hydroponie.c new file mode 100644 index 0000000..2ba81e9 --- /dev/null +++ b/app/hydro/hydroponie.c @@ -0,0 +1,343 @@ +/*************************************************************************** + * Copyright (C) 2008 by stefic * + * stefaj1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +//#define OS_POSIX + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include + +#ifdef OS_POSIX + #include +#else + #include + #include + #include +#endif +// #include +// #include +// #include +// #include + +//INCLUDE IN CURRENT DIRECTORY +#include "hydroponie.h" +#include "ul_idstr.h" + +// CONSTANTS +#define UL_DEV "/dev/ulan" +#define SN 101 +#define ULDY_TMBUF_LEN 5 +#define HEART_BUF_LEN 6 +#define DATA_BUF_LEN 16 +#define CID_HEART 1023 +#define CID_TEMP 100 +#define CID_HUM 200 + +// DEFINED TYPES +#ifdef OS_POSIX + typedef unsigned long mstime_t; +#else + typedef lt_mstime_t mstime_t; +#endif + +// GLOBAL VARIABLES +long sn = SN; +uchar server_adr; +ul_dyac_t ul_dyac_global; +uloi_coninfo_t uloi_coninfo_global; +//kvpb_block_t kvpb_block_global; + +ul_fd_t ul_fd; +ul_fd_t ul_fd1; +ul_msginfo msginfo; +int addfilt; + +#ifndef UL_WITHOUT_HANDLE +//kvpb_block_t *kvpb_block=&kvpb_block_global; +uloi_coninfo_t *coninfo=&uloi_coninfo_global; +ul_dyac_t *ul_dyac=&ul_dyac_global; +#endif /* UL_WITHOUT_HANDLE */ + +// OBJECT INTERFACE VARIABLES +uint16_t status_val; +int16_t oi_temperature = 20; +int16_t oi_cid_temp; +int16_t oi_per_temp; +int16_t oi_humidity = 100; +int16_t oi_cid_hum; +int16_t oi_per_hum; + +// OBJECT INTERFACE FUNCTIONS +int oi_temperature_rdfnc(ULOI_PARAM_coninfo void *context){ + return uloi_uint_rdfnc(ULOI_ARG_coninfo &oi_temperature); +} + +int oi_humidity_rdfnc(ULOI_PARAM_coninfo void *context){ + return uloi_uint_rdfnc(ULOI_ARG_coninfo &oi_humidity); +} + +int oi_cid_temp_wrfnc(ULOI_PARAM_coninfo void *context){ + +} + +int oi_per_temp_wrfnc(ULOI_PARAM_coninfo void *context){ + +} + +int oi_cid_hum_wrfnc(ULOI_PARAM_coninfo void *context){ + +} + +int oi_per_hum_wrfnc(ULOI_PARAM_coninfo void *context){ + +} + +// CLASS FUNCTIONS +void long2buf(uchar *buf,unsigned long mod) +{ + buf[0]=mod>>0; + buf[1]=mod>>8; + buf[2]=mod>>16; + buf[3]=mod>>24; +} + +void int2buf(uchar *buf,int mod) +{ + buf[0]=mod>>0; + buf[1]=mod>>8; +} + +char ul_save_sn(uint32_t usn) +{ + //kvpb_set_key(kvpb_block,KVPB_KEYID_ULAN_SN,sizeof(unsigned long),&usn); + return 0; +} + +char ul_save_adr(uint8_t uaddr) +{ + //unsigned int v=uaddr; + //kvpb_set_key(kvpb_block,KVPB_KEYID_ULAN_ADDR,sizeof(unsigned int),&v); + return 0; +} + + +int send_sn(void){ + //declaration + int msgsend; + + //.preparing of msg + uchar buf_out[ULDY_TMBUF_LEN]; + buf_out[0]=ULNCS_ADR_RQ; + long2buf(&buf_out[1],sn); + + //address set and sign on the ulan + ul_setmyadr(ul_fd,255); + msgsend = ul_send_command(ul_fd, msginfo.dadr, UL_CMD_NCS, UL_BFL_NORE, (void*) buf_out, ULDY_TMBUF_LEN); + printf("[I] sn was send\n"); + ul_freemsg(ul_fd); + +} + +int heartbeat(void){ + //int period; + int msgsend, i; + int len = HEART_BUF_LEN; + uchar *buf; + + //.preparing of msg + buf = (uchar *) malloc(len*sizeof(uchar)); // NULL NULL NULL CID_HEART status_val + for (i=0; i<=2; i++) buf[i] = 0; + int2buf(&buf[3],CID_HEART); + int2buf(&buf[5],status_val); + + msgsend = ul_send_command(ul_fd, ul_dyac->ul_dysa, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, HEART_BUF_LEN); + printf("[I] BEAT\n"); + free(buf); +} + +int send_data(void) { + int msgsend; + uchar *buf; + int i; + int len = DATA_BUF_LEN; + + get_data(); + + //.preparing of msg + buf = (uchar *) malloc(len*sizeof(uchar)); // NULL NULL NULL CID_TEMP len_data oi_temperature CID_HUM len_data oi_humidity + for (i=0; i<=2; i++) buf[i] = 0; + int2buf(&buf[3],CID_TEMP); + int2buf(&buf[5],2); + int2buf(&buf[7],oi_temperature); +// int2buf(&buf[9],CID_HUM); +// int2buf(&buf[11],2); +// int2buf(&buf[13],oi_humidity); + + msgsend = ul_send_query(ul_fd, ul_dyac->ul_dysa, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, /*DATA_BUF_LEN*/9); + printf("[I] DATA\n"); + free(buf); + ul_freemsg(ul_fd); + +} + +int get_data(void){ +#ifdef OS_POSIX + oi_temperature = -25000; + oi_humidity = 99; +#else + oi_temperature = AD0DR1; + oi_humidity = AD0DR2; +#endif +} + +int accept_SDO(void) { + + // setting lan configuration + if ((ul_inepoll(ul_fd)>0) && (ul_acceptmsg(ul_fd, &msginfo)>=0)) { + if ((msginfo.cmd != UL_CMD_PDO) && (msginfo.sadr != 255)) { + if (!(msginfo.flg&(UL_BFL_PROC | UL_BFL_FAIL))) { + //waiting for msg from bus + if (uloi_process_msg(ULOI_ARG_coninfo (uloi_objdes_array_t*)&uloi_objdes_main, &msginfo)<0) { + //checking dynamic adresation + if (uldy_process_msg(ULDY_ARG_ul_dyac &msginfo)>=0){ + printf("message recieved - UL_CMD_NCS, sadr: %i, dadr: %i, cmd: %i\n",msginfo.sadr, msginfo.dadr, msginfo.cmd); + printf("server addr :%i\n",ul_dyac->ul_dysa); + } else { + ul_freemsg(ul_fd); + printf("problem in uldy_process_msg\n"); + } + } else { + printf("ULOI message processed\n"); + } + } else { + ul_freemsg(ul_fd); + } + } + } +} + + +mstime_t current_time(){ + mstime_t ret = 0; + + #ifdef OS_POSIX + struct timespec tp; + if(clock_gettime(CLOCK_REALTIME, &tp) == 0){ + ret = tp.tv_sec*1000; + ret += tp.tv_nsec/1000000; + } + #else + lt_mstime_update(); + ret = actual_msec; + #endif + + return ret; +} + +void loop(void){ + //time setting + + mstime_t ltime; + mstime_t l2time; + mstime_t ctime; + + oi_per_temp = 2; + + while(1){ + send_sn(); + ltime = current_time(); + + while(1){ + ctime = current_time(); + if((ctime-ltime) > 1000){ + break; + } + + #ifdef OS_POSIX + usleep(1); + #endif + + accept_SDO(); + + } + if (ul_dyac->ul_dysa != 0) break; + } + + ltime = current_time(); + l2time = current_time(); + + while(1){ + ctime = current_time(); + if((ctime-ltime) > 1000){ +// heartbeat(); + ltime = current_time(); + } + if((ctime-l2time) > 1000*oi_per_temp){ + send_data(); + l2time = current_time(); + } + accept_SDO(); + #ifdef OS_POSIX + usleep(1); + #endif + } + +} + +int main(int argc, char *argv[]) { + + //opening file descriptor + ul_fd = ul_open(UL_DEV,NULL); + ul_fd1 = ul_open(NULL,NULL); + if ((ul_fd == UL_FD_INVALID) && (ul_fd1 == UL_FD_INVALID)){ + printf("error in creating ul_fd\n"); + return -1; + } + + //memory set and filter set + memset(&msginfo,0,sizeof(msginfo)); + addfilt=ul_addfilt(ul_fd,&msginfo); + if(addfilt<0) { + printf("spy_messages : add filter failed\n"); + return addfilt; + } + + // uLan object interface init + coninfo->cmd = UL_CMD_OISV; + coninfo->sn = SN; + coninfo->bsn = 0; + coninfo->ul_fd = ul_fd; + coninfo->ul_fd1 = ul_fd1; + + // uLan dyac init + uldy_init(ul_dyac,ul_fd,ul_save_sn,ul_save_adr,(char*)ul_idstr,sn); + + loop(); + + ul_close(ul_fd); + return EXIT_SUCCESS; +} diff --git a/app/hydro/hydroponie.h b/app/hydro/hydroponie.h new file mode 100644 index 0000000..ccf034b --- /dev/null +++ b/app/hydro/hydroponie.h @@ -0,0 +1,33 @@ +#ifndef _HYDRO +#define _HYDRO + +#ifdef __cplusplus +/*extern "C" {*/ +#endif + +#include +#include +#include + +extern const ULOI_CODE uloi_objdes_array_t uloi_objdes_main; +extern uint16_t status_val; +extern int16_t oi_temperature; +extern int16_t oi_cid_temp; +extern int16_t oi_per_temp; +extern int16_t oi_humidity; +extern int16_t oi_cid_hum; +extern int16_t oi_per_hum; + +int oi_temperature_rdfnc(ULOI_PARAM_coninfo void *context); +int oi_humidity_rdfnc(ULOI_PARAM_coninfo void *context); + +int oi_cid_temp_wrfnc(ULOI_PARAM_coninfo void *context); +int oi_per_temp_wrfnc(ULOI_PARAM_coninfo void *context); +int oi_cid_hum_wrfnc(ULOI_PARAM_coninfo void *context); +int oi_per_hum_wrfnc(ULOI_PARAM_coninfo void *context); + +#ifdef __cplusplus +/*}*/ /* extern "C"*/ +#endif + +#endif /* HYDRO */ diff --git a/app/hydro/hydroponieoi.c b/app/hydro/hydroponieoi.c new file mode 100644 index 0000000..2d049b5 --- /dev/null +++ b/app/hydro/hydroponieoi.c @@ -0,0 +1,85 @@ +/* + OBJECT INTERFACE FOR HYDRO +*/ + +#include +#include "hydroponie.h" + +#define I_TEMPERATURE 100 +#define I_CID_TEMP 110 +#define I_PER_TEMP 120 +#define I_HUMIDITY 200 +#define I_CID_HUM 210 +#define I_PER_HUM 220 + + +uint16_t status_val; +// promene ktere jsou v headeru jako extern musi byt deklarovany normalne i ve fci kde je pouzivam +int16_t oi_temperature; +int16_t oi_cid_temp; +int16_t oi_per_temp; +int16_t oi_humidity; +int16_t oi_cid_hum; +int16_t oi_per_hum; + +int status_rdfnc(ULOI_PARAM_coninfo void *context) +{ + return uloi_uint_rdfnc(ULOI_ARG_coninfo &status_val); +} + +int errclr_wrfnc(ULOI_PARAM_coninfo void *context) +{ + status_val=0; + return 1; +} + +/* description of input objects */ +const ULOI_CODE uloi_objdes_t uloid_objdes_DOII = +ULOI_GENOBJDES_RAW(ULOI_DOII,NULL,NULL_CODE,NULL,uloi_doii_fnc,(void*)&uloi_objdes_main) +/* description of output objects */ +const ULOI_CODE uloi_objdes_t uloid_objdes_DOIO = +ULOI_GENOBJDES_RAW(ULOI_DOIO,NULL,NULL_CODE,NULL,uloi_doio_fnc,(void*)&uloi_objdes_main) +/* ID numbers of recognized input objects */ +const ULOI_CODE uloi_objdes_t uloid_objdes_QOII = +ULOI_GENOBJDES_RAW(ULOI_QOII,NULL,NULL_CODE,NULL,uloi_qoii_fnc,(void*)&uloi_objdes_main) +/* ID numbers of recognized output objects */ +const ULOI_CODE uloi_objdes_t uloid_objdes_QOIO = +ULOI_GENOBJDES_RAW(ULOI_QOIO,NULL,NULL_CODE,NULL,uloi_qoio_fnc,(void*)&uloi_objdes_main) +/* object values read request */ +const ULOI_CODE uloi_objdes_t uloid_objdes_RDRQ = +ULOI_GENOBJDES_RAW(ULOI_RDRQ,NULL,NULL_CODE,NULL,uloi_rdrq_fnc,(void*)&uloi_objdes_main) + +ULOI_GENOBJDES(STATUS,ULOI_STATUS,"u2",status_rdfnc,&status_val,NULL_CODE,NULL) +ULOI_GENOBJDES(ERRCLR,ULOI_ERRCLR,"e",NULL_CODE,NULL,errclr_wrfnc,&status_val) +ULOI_GENOBJDES(TEMPERATURE,I_TEMPERATURE,"s2",oi_temperature_rdfnc,&oi_temperature,NULL_CODE,NULL) +ULOI_GENOBJDES(CID_TEMP,I_CID_TEMP,"u2",uloi_uint_rdfnc,&oi_cid_temp,oi_cid_temp_wrfnc,&oi_cid_temp) +ULOI_GENOBJDES(PER_TEMP,I_PER_TEMP,"u2",uloi_uint_rdfnc,&oi_per_temp,oi_per_temp_wrfnc,&oi_per_temp) +ULOI_GENOBJDES(HUMIDITY,I_HUMIDITY,"s2",oi_humidity_rdfnc,&oi_temperature,NULL_CODE,NULL) +ULOI_GENOBJDES(CID_HUM,I_CID_HUM,"u2",uloi_uint_rdfnc,&oi_cid_hum,oi_cid_hum_wrfnc,&oi_cid_hum) +ULOI_GENOBJDES(PER_HUM,I_PER_HUM,"u2",uloi_uint_rdfnc,&oi_per_hum,oi_per_hum_wrfnc,&oi_per_hum) + +const uloi_objdes_t * ULOI_CODE uloi_objdes_main_items[]={ + &uloid_objdes_DOII, + &uloid_objdes_DOIO, + &uloid_objdes_QOII, + &uloid_objdes_QOIO, + &uloid_objdes_RDRQ, + + &uloid_objdes_STATUS, + &uloid_objdes_ERRCLR, + &uloid_objdes_TEMPERATURE, + &uloid_objdes_CID_TEMP, + &uloid_objdes_PER_TEMP, + &uloid_objdes_HUMIDITY, + &uloid_objdes_CID_HUM, + &uloid_objdes_PER_HUM + +}; + +const ULOI_CODE uloi_objdes_array_t uloi_objdes_main={ + { + /*(void *)*/(uloi_objdes_t **)uloi_objdes_main_items, + sizeof(uloi_objdes_main_items)/sizeof(uloi_objdes_main_items[0]), + -1 + } +}; diff --git a/app/hydro/ul_idstr.c b/app/hydro/ul_idstr.c new file mode 100644 index 0000000..3c13d6c --- /dev/null +++ b/app/hydro/ul_idstr.c @@ -0,0 +1,27 @@ +#include + +#define __STRINGIFY(x) #x /* stringify without expanding x */ +#define STRINGIFY(x) __STRINGIFY(x) /* expand x, then stringify */ + +#ifdef CONFIG_ULAN_DY + #define UL_DYC " .dy" +#else + #define UL_DYC +#endif + +#ifdef CONFIG_ULOI_LT + #define UL_OIC " .oi" +#else + #define UL_OIC +#endif + +#define NAME ".mt " \ + STRINGIFY(ULAN_ID) \ + " .uP " \ + STRINGIFY(MACH) \ + UL_DYC \ + UL_OIC \ + " .co " \ + __DATE__ " " __TIME__ + +const char *ul_idstr = NAME; diff --git a/app/hydro/ul_idstr.h b/app/hydro/ul_idstr.h new file mode 100644 index 0000000..2221d1d --- /dev/null +++ b/app/hydro/ul_idstr.h @@ -0,0 +1,14 @@ +#ifndef _UL_IDSTR_H +#define _UL_IDSTR_H + +#ifdef __cplusplus +/*extern "C" {*/ +#endif + +extern const char *ul_idstr; + +#ifdef __cplusplus +/*}*/ /* extern "C"*/ +#endif + +#endif /* _UL_IDSTR_H */