void set_fan_PIN(){
if (oi_fan == 1) {
- SET_OUT_PIN(OUT_PORT,P1_27_FAN);
+ SET_OUT_PIN(OUT_PORT,P1_29_FAN);
printf("FAN PIN UP\n");
} else {
- CLR_OUT_PIN(OUT_PORT,P1_27_FAN);
+ CLR_OUT_PIN(OUT_PORT,P1_29_FAN);
printf("FAN PIN DOWN\n");
}
}
void set_humidifier_PIN(){
if (oi_humidifier == 1) {
- SET_OUT_PIN(OUT_PORT,P1_28_HUMIDIFIER);
+ SET_OUT_PIN(OUT_PORT,P1_30_HUMIDIFIER);
printf("HUM PIN UP\n");
} else {
- CLR_OUT_PIN(OUT_PORT,P1_28_HUMIDIFIER);
+ CLR_OUT_PIN(OUT_PORT,P1_30_HUMIDIFIER);
printf("HUM PIN DOWN\n");
}
}
void set_light_PIN(){
if (oi_light == 1) {
- SET_OUT_PIN(OUT_PORT,P1_29_LIGHT);
+ SET_OUT_PIN(OUT_PORT,P1_31_LIGHT);
printf("LIGHT PIN UP\n");
} else {
- CLR_OUT_PIN(OUT_PORT,P1_29_LIGHT);
+ CLR_OUT_PIN(OUT_PORT,P1_31_LIGHT);
printf("LIGHT PIN DOWN\n");
}
}
cid_cnt++;
}
- if (cid_cnt == 0){
- heartbeat();
- } else {
-
+ if (cid_cnt != 0){
int i;
int buff_len;
msgsend = ul_send_query(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
printf("[I] DATA\n");
- free(buf);
ul_freemsg(ul_fd);
}
}
}
void check_PDO(int cid, int data){
+ printf("CID: %i\n", cid);
if (cid == oi_slot_fan){
oi_fan = data;
set_fan_PIN();
// IO0SET = P0_21_BIT;
// IO0SET = P0_22_BIT;
- SET_OUT_PIN(OUT_PORT, P1_27_FAN);
- CLR_OUT_PIN(OUT_PORT, P1_28_HUMIDIFIER);
- SET_OUT_PIN(OUT_PORT, P1_29_LIGHT);
+ SET_OUT_PIN(OUT_PORT, P1_29_FAN);
+ SET_OUT_PIN(OUT_PORT, P1_31_LIGHT);
+ SET_OUT_PIN(OUT_PORT, P1_30_HUMIDIFIER);
+
IO0SET = LED1_BIT; //vypinani LED
IO0CLR = LED2_BIT; //zapinani LED
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/definitions.c
\ No newline at end of file
+../sensor/definitions.c
\ No newline at end of file
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/definitions.h
\ No newline at end of file
+../sensor/definitions.h
\ No newline at end of file
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/hydroponie.c
\ No newline at end of file
+../sensor/hydroponie.c
\ No newline at end of file
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/hydroponie.h
\ No newline at end of file
+../sensor/hydroponie.h
\ No newline at end of file
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/ul_idstr.c
\ No newline at end of file
+../sensor/ul_idstr.c
\ No newline at end of file
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/ul_idstr.h
\ No newline at end of file
+../sensor/ul_idstr.h
\ No newline at end of file
int hyst_temp = 1;
int hyst_hum = 10;
+
unsigned int fan = 0;
unsigned int hum = 0;
unsigned int light = 0;
return 1;
}
+int oi_want_temp_wrfnc(ULOI_PARAM_coninfo void *context){
+ uloi_uint_wrfnc(ULOI_ARG_coninfo context);
+ return 1;
+}
+
+int oi_want_hum_wrfnc(ULOI_PARAM_coninfo void *context){
+ uloi_uint_wrfnc(ULOI_ARG_coninfo context);
+ return 1;
+}
+
void send_data() {
int msgsend;
cid_cnt++;
}
- if (cid_cnt == 0){
- heartbeat();
- } else {
-
+ if (cid_cnt != 0){
int i;
int buff_len;
msgsend = ul_send_query(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
printf("[I] DATA\n");
- free(buf);
ul_freemsg(ul_fd);
}
}
}
void check_PDO(int cid, int data){
- if (cid == oi_slot_temp)
+ printf("CID: %i\n", cid);
+ if (cid == oi_slot_temp){
temperature = data;
- if (cid == oi_slot_temp)
+ printf("temperature: %i\n", temperature);
+ }
+ if (cid == oi_slot_hum){
humidity = data;
+ printf("humidity: %i\n", humidity);
+ }
}
void regulate(void){
extern const ULOI_CODE uloi_objdes_array_t uloi_objdes_main;
extern unsigned int status_val;
extern unsigned int oi_cid_fan;
-extern unsigned int oi_fan;
extern unsigned int oi_cid_hum;
-extern unsigned int oi_fan;
extern unsigned int oi_cid_light;
-extern unsigned int oi_fan;
extern unsigned int oi_slot_temp;
extern unsigned int oi_slot_hum;
extern unsigned int oi_period;
+extern unsigned int oi_want_temp;
+extern unsigned int oi_want_hum;
typedef struct cid_data {
int cid;
int oi_slot_temp_wrfnc(ULOI_PARAM_coninfo void *context);
int oi_slot_hum_wrfnc(ULOI_PARAM_coninfo void *context);
int oi_period_wrfnc(ULOI_PARAM_coninfo void *context);
+int oi_want_temp_wrfnc(ULOI_PARAM_coninfo void *context);
+int oi_want_hum_wrfnc(ULOI_PARAM_coninfo void *context);
void send_data();
void oiinit(void);
#define I_HUMIDITY_SLOT 910
#define I_PERIOD 1000
+#define I_WANT_TEMP 1100
+#define I_WANT_HUM 1200
+
unsigned int status_val;
int status_rdfnc(ULOI_PARAM_coninfo void *context)
ULOI_GENOBJDES(PERIOD,I_PERIOD,"u2",uloi_uint_rdfnc,&oi_period,oi_period_wrfnc,&oi_period)
+ULOI_GENOBJDES(WANT_TEMP,I_WANT_TEMP,"u2/.1",uloi_uint_rdfnc,&oi_want_temp,oi_want_temp_wrfnc,&oi_want_temp)
+ULOI_GENOBJDES(WANT_HUM,I_WANT_HUM,"u2/.1",uloi_uint_rdfnc,&oi_want_hum,oi_want_hum_wrfnc,&oi_want_hum)
+
const uloi_objdes_t * ULOI_CODE uloi_objdes_main_items[]={
&uloid_objdes_DOII,
&uloid_objdes_DOIO,
&uloid_objdes_LIGHT_CID,
&uloid_objdes_TEMPERATURE_SLOT,
&uloid_objdes_HUMIDITY_SLOT,
- &uloid_objdes_PERIOD
-
+ &uloid_objdes_PERIOD,
+ &uloid_objdes_WANT_TEMP,
+ &uloid_objdes_WANT_HUM
};
const ULOI_CODE uloi_objdes_array_t uloi_objdes_main={
cids[cid_cnt].value = oi_temperature;
cid_cnt++;
}
- if (oi_cid_hum > 0) {
+ if (oi_cid_hum > 0){
cids[cid_cnt].cid = oi_cid_hum;
cids[cid_cnt].value = oi_humidity;
cid_cnt++;
}
- if (cid_cnt == 0){
- heartbeat();
- } else {
-
+ if (cid_cnt != 0){
int i;
int buff_len;
msgsend = ul_send_query(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
printf("[I] DATA\n");
- free(buf);
ul_freemsg(ul_fd);
}
}
return i;
}
+uint buf2uint(uchar *buf){
+ uint i;
+ i = (uchar) buf[0];
+ i = ((uchar) buf[1]<<8) | i;
+ return i;
+}
+
mstime_t current_time(){
mstime_t ret = 0;
if ((ul_inepoll(ul_fd)>0) && (ul_acceptmsg(ul_fd, &msginfo)>=0)) {
if (msginfo.cmd == UL_CMD_PDO){
process_PDO();
+ ul_freemsg(ul_fd);
+ printf("accept PDO msg: sadr: %i, dadr: %i\n", msginfo.sadr, msginfo.dadr);
} else if (msginfo.sadr != 99) {
if (!(msginfo.flg&(UL_BFL_PROC | UL_BFL_FAIL))) {
//waiting for msg from bus
printf("problem in uldy_process_msg\n");
}
} else {
- printf("ULOI message processed\n");
+ printf("ULOI message processed: sadr: %i, dadr: %i\n", msginfo.sadr, msginfo.dadr);
}
} else {
ul_freemsg(ul_fd);
uchar * buf;
int buf_len = 0;
-int position = 0;
+int position = 3;
-int cid = 0;
+uint cid = 0;
int len_data = 0;
int data = 0;
buf_len = msginfo.len;
buf = (uchar *) malloc(buf_len*sizeof(uchar));
ul_read(ul_fd, buf, buf_len);
-
while(1){
if ((position+2) > buf_len) break;
cid = take_cid(&buf[position]);
}
}
-int take_cid(uchar * buf){
- return buf2int(buf);
+uint take_cid(uchar * buf){
+ return buf2uint(buf);
}
int take_len(uchar * buf){
void int2buf(uchar *buf,int mod);
int buf2int(uchar *buf);
+uint buf2uint(uchar *buf);
+
mstime_t current_time();
void blink(void);
void accept_SDO(void);
void process_PDO(void);
-int take_cid(uchar* buf);
+uint take_cid(uchar* buf);
int take_len(uchar* buf);
int take_data(uchar* buf, int len);
l2time = current_time();
}
}
- }
+ } else heartbeat();
accept_SDO();
regulate();