/* $Id: Text.c,v 1.3 2001/03/16 09:28:08 ltoetsch Exp $ * * pure ncurses based text driver * * Copyright 2001 by Leopold Tötsch (lt@toetsch.at) * * 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA. * * * $Log: Text.c,v $ * Revision 1.3 2001/03/16 09:28:08 ltoetsch * bugfixes * * Revision 1.2 2001/03/09 15:04:53 reinelt * * rename 'raster' to 'Text in Text.c * added TOTO item * * Revision 1.1 2001/03/09 13:08:11 ltoetsch * Added Text driver * * */ /* * * exported fuctions: * * struct LCD Text[] * */ #include #include #include #define min(x,y) (x)<(y)?x:y #ifdef STANDALONE int main(int argc, char *argv[]) { WINDOW *w; int x,y; w = initscr(); for (x=0; x < 255; x++) addch(acs_map[x]); refresh(); sleep(5); endwin(); return 0; } #else #include #include "debug.h" #include "cfg.h" #include "display.h" extern int foreground; static LCD Lcd; static WINDOW *w; WINDOW *err_win; #define BARS ( BAR_R | BAR_H2 ) int err_rows; int Text_clear (void) { werase(w); box(w, 0, 0); return 0; } int Text_quit(void) { endwin(); return 0; } int Text_init (LCD *Self) { int cols=-1, rows=-1; int scr_cols, scr_rows; char *s; if (!foreground) { error("Text: you want me to display on /dev/null: sorry, I can't"); return -1; } if (sscanf(s=cfg_get("size")?:"20x4", "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) { error ("Text: bad size '%s'", s); return -1; } Self->rows=rows; Self->cols=cols; Self->xres=1; Self->yres=1; Lcd=*Self; w = initscr(); scr_cols=COLS; scr_rows=LINES; delwin(w); w = newwin(rows+2,cols+2,0,0); err_rows = scr_rows-rows-3; err_rows = min(99, err_rows); if (err_rows >= 4) { err_win = newwin(err_rows, scr_cols, rows+3, 0); err_rows -= 3; box(err_win, 0, 0); mvwprintw(err_win,0,3, "Stderr:"); wmove(err_win, 1 , 0); wrefresh(err_win); } Text_clear(); return w ? 0 : -1; } /* ncures scroll SIGSEGVs on my system, so this is a workaroud */ int curs_err(char *buffer) { static int lines; static char *lb[100]; int start, i; char *p; if (err_win) { /* replace \r, \n with underscores */ while ((p = strpbrk(buffer, "\r\n")) != NULL) *p='_'; if (lines >= err_rows) { free(lb[0]); for (i=1; i<=err_rows; i++) lb[i-1] = lb[i]; start = 0; } else start = lines; lb[lines] = strdup(buffer); for (i=start; i<=lines; i++) { mvwprintw(err_win,i+1,1, "%s", lb[i]); wclrtoeol(err_win); } box(err_win, 0, 0); mvwprintw(err_win,0,3, "Stderr:"); wrefresh(err_win); if (lines < err_rows) lines++; return 1; } return 0; } int Text_put (int row, int col, char *text) { char *p; if ((p = strpbrk(text, "\r\n")) != NULL) *p='\0'; if (col < Lcd.cols) mvwprintw(w, row+1 , col+1, "%.*s", Lcd.cols-col, text); return 0; } int Text_bar (int type, int row, int col, int max, int len1, int len2) { int len, i; if (cfg_get("TextBar")) mvwprintw(w, row+1 , col+1, "%d %d %d", max, len1, len2); else { len = min(len1, len2); len = min(len, Lcd.cols-col-1); if (len) { wmove(w, row+1 , col+1); for (i=0; i
// gcc weatherstation_test.c -o weatherstation_test `pkg-config --libs --cflags libmodbus`

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

#include <modbus.h>

#define SLAVE_ID       1
#define START_ADDRESS       0
#define NUMBER_REGISTERS       17

#define DEBUG_MODE	1

int main(int argc, char *argv[])
{

modbus_t *ctx;
int16_t mbregister[64];
int rc;

ctx = modbus_new_rtu("/dev/ttyUSB0", 19200, 'E', 8, 1);
modbus_set_slave(ctx, SLAVE_ID);

modbus_set_debug(ctx, DEBUG_MODE);

printf("Verteco Elsner Weatherstation\n\n");

if (ctx == NULL) {
    fprintf(stderr, "Unable to create the libmodbus context\n");
    return -1;
}

if (modbus_connect(ctx) == -1) {
    fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
    modbus_free(ctx);
    return -1;
}

rc = modbus_read_input_registers(ctx, START_ADDRESS, NUMBER_REGISTERS, mbregister);


if (rc == -1) {
    fprintf(stderr, "ERROR: %s\n", modbus_strerror(errno));
    return -1;
}

printf("Read %i mbregisters\n\n", rc);

printf("temperature=%d\n", mbregister[0]);
printf("sun_south=%d\n", mbregister[1]);
printf("sun_east=%d\n", mbregister[2]);
printf("sun_west=%d\n", mbregister[3]);
printf("light=%d\n", mbregister[4]);
printf("wind=%d\n", mbregister[5]);
printf("rain=%d\n", mbregister[6]&1);
printf("GPS/RTC=%d\n", mbregister[6]>>8);
printf("day=%d\n", mbregister[7]);
printf("month=%d\n", mbregister[8]);
printf("year=%d\n", mbregister[9]);
printf("hour=%d\n", mbregister[10]);
printf("min=%d\n", mbregister[11]);
printf("second=%d\n", mbregister[12]);
printf("azimuth=%d\n", mbregister[13]);
printf("elevation=%d\n", mbregister[14]);
printf("long=%d\n", mbregister[15]);
printf("lat=%d\n", mbregister[16]);
modbus_close(ctx);
modbus_free(ctx);

    return 0;
}