Working version
This commit is contained in:
commit
58236d918c
|
@ -0,0 +1,17 @@
|
||||||
|
# Serial2MySQL
|
||||||
|
|
||||||
|
Data Acquisition software for Raspberry Pi and our first board, called Coffee Heater.
|
||||||
|
|
||||||
|
## Prerequisities
|
||||||
|
* Raspberry Pi
|
||||||
|
* WiringPi
|
||||||
|
* MySQL
|
||||||
|
* make
|
||||||
|
* gcc
|
||||||
|
* ncurses library
|
||||||
|
|
||||||
|
## Build
|
||||||
|
Execute the following command:
|
||||||
|
```
|
||||||
|
make
|
||||||
|
```
|
|
@ -0,0 +1,18 @@
|
||||||
|
#makefile for serial project
|
||||||
|
#DE TTK - Villamosmérnök BSC - Baranyai Dávid
|
||||||
|
|
||||||
|
#Compiler:
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
#Compiler flags:
|
||||||
|
CFLAGS = `mysql_config --cflags --libs` -lncurses -lrt
|
||||||
|
TARGET = serial
|
||||||
|
TARGET2 = search
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(TARGET).c
|
||||||
|
$(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(TARGET)
|
|
@ -0,0 +1,357 @@
|
||||||
|
#include <my_global.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <mysql/mysql.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
|
||||||
|
char *server = "localhost"; /* server host (default=localhost) */
|
||||||
|
char *user = "root"; /* username (default=login name) */
|
||||||
|
char *password = "raspberry"; /* password (default=none) */
|
||||||
|
char *database = "adatok"; /* database name (default=none) */
|
||||||
|
|
||||||
|
MYSQL * con;
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct buf_struct
|
||||||
|
{
|
||||||
|
uint8_t chamber_id; //fix 0x00 felsőbb egység állítsa be
|
||||||
|
uint8_t ch_id; //jumper configurable lsb module ch0-1 select next 4 bit 16 modul select next 1 bit xy board select
|
||||||
|
uint32_t inte_data; //integrated curve
|
||||||
|
uint16_t peak_amp;
|
||||||
|
uint16_t width;
|
||||||
|
uint32_t time_sec;
|
||||||
|
uint32_t time_ns;
|
||||||
|
uint16_t cmp_level;
|
||||||
|
uint16_t reserved;
|
||||||
|
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct events
|
||||||
|
{
|
||||||
|
int start_ns;
|
||||||
|
int end_ns;
|
||||||
|
int time_sec;
|
||||||
|
int length;
|
||||||
|
};
|
||||||
|
|
||||||
|
void sigintHandler(int sig_num)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sigintHandler);
|
||||||
|
mysql_close(con);
|
||||||
|
printf("\nExiting... \n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void finish_with_error(MYSQL *con)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", mysql_error(con));
|
||||||
|
mysql_close(con);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//pointerre mutató pointert kell átadni, hogy tudja módosítani az eredeti pointert
|
||||||
|
void mysql_connect(MYSQL **con)
|
||||||
|
{
|
||||||
|
*con = mysql_init(NULL);
|
||||||
|
|
||||||
|
if (*con == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "mysql_init() failed\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Mysql: Connecting to %s@%s as %s\n",database,server,user);
|
||||||
|
if (mysql_real_connect(*con, server, user, password, database, 0, NULL, 0) == NULL)
|
||||||
|
{
|
||||||
|
finish_with_error(*con);
|
||||||
|
}
|
||||||
|
else printf("Mysql: Connected succesfully!\n");
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int mysql_write(struct buf_struct adatok)
|
||||||
|
{
|
||||||
|
char data[300];
|
||||||
|
printf("MySQL: Adatok beírása...\n");
|
||||||
|
snprintf(data,300,"INSERT INTO fb_55(chamber_id,ch_id,inte_data,peak_amp,width,time_sec,time_ns,cmp_lvl) VALUES(%d,%d,%d,%d,%d,%ld,%ld,%d)",adatok.chamber_id,adatok.ch_id,adatok.inte_data,adatok.peak_amp,adatok.width,adatok.time_sec,adatok.time_ns, adatok.cmp_level);
|
||||||
|
mysql_query(conn,data);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//lekéri a megadott másodpercben történt események time_ns oszlopát növekvő sorrendbe rendezve egy tömbbe
|
||||||
|
//bemenő paraméterek: array: null pointerre mutató pointer futás után egy int tömbre mutató pointer lesz használat után free vel felszabadítani!!!!
|
||||||
|
// size: előzú tömb mérete lesz benne
|
||||||
|
int time_ns_col_to_array(MYSQL *con, int **array, int *size, int time_sec, char * table_name)
|
||||||
|
{
|
||||||
|
char q_string[100];
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
|
snprintf(q_string,100, "SELECT time_ns FROM`%s`WHERE time_sec=%d ORDER BY`time_ns`ASC", table_name, time_sec);
|
||||||
|
|
||||||
|
if (mysql_query(con, q_string))
|
||||||
|
{
|
||||||
|
finish_with_error(con);
|
||||||
|
}
|
||||||
|
printf("lekeres ok\n");
|
||||||
|
|
||||||
|
|
||||||
|
MYSQL_RES *result = mysql_store_result(con);
|
||||||
|
|
||||||
|
if (result == NULL)
|
||||||
|
{
|
||||||
|
finish_with_error(con);
|
||||||
|
}
|
||||||
|
printf("store ok\n");
|
||||||
|
|
||||||
|
if( mysql_num_fields(result) != 1) //1 oszlopot kérek le (time_ns)
|
||||||
|
{
|
||||||
|
printf("oszlop nem 1\n");
|
||||||
|
//mysql_close(con);
|
||||||
|
//exit(1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
MYSQL_ROW row;
|
||||||
|
int i;
|
||||||
|
int row_count = mysql_num_rows(result);
|
||||||
|
|
||||||
|
*array = (int*) malloc(row_count * sizeof(int));
|
||||||
|
|
||||||
|
printf("realoc ok\n");
|
||||||
|
|
||||||
|
//while ((row = mysql_fetch_row(result)))
|
||||||
|
for(i=0;i<row_count ;i++)
|
||||||
|
{
|
||||||
|
if((row = mysql_fetch_row(result)) == NULL)
|
||||||
|
{
|
||||||
|
ret = -1; //hiba
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(row[0] != NULL)
|
||||||
|
{
|
||||||
|
(*array)[i] = atoi(row[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql_free_result(result);
|
||||||
|
|
||||||
|
*size = row_count; //feltöltött tömb mérete
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int find(
|
||||||
|
int* array, int array_size, int time_sec, //bemenő tömb
|
||||||
|
struct events** event_array, int *event_array_size, //kimenő tömb
|
||||||
|
int time_diff,int min_event_length //max időbeli különbség 2 egymás után következő között
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int start_ns;
|
||||||
|
int event_count = 0; //struktúra tömb indexeléshez
|
||||||
|
int event_length = 0;
|
||||||
|
*event_array = (struct events*) malloc(array_size * sizeof(struct events)); //legrosszabb esetet feltételezve
|
||||||
|
|
||||||
|
*event_array_size = 0;
|
||||||
|
min_event_length--; //legaláb 2 különben hiba
|
||||||
|
|
||||||
|
start_ns = array[0];
|
||||||
|
for(i=0;i<(array_size-1);i++)
|
||||||
|
{
|
||||||
|
if((array[i] + time_diff) < array[i+1]) //ha nagyobb a különbség mint a megengedett
|
||||||
|
{
|
||||||
|
if(event_length >= min_event_length)
|
||||||
|
{
|
||||||
|
(*((*event_array) + event_count)).start_ns = start_ns; //kezdő elem
|
||||||
|
(*((*event_array) + event_count)).end_ns = array[i]; //utolsó elemnek a még jó idejü
|
||||||
|
(*((*event_array) + event_count)).time_sec = time_sec; //ebben a másodpercben volt az esemény, későbbi hazsnálatra
|
||||||
|
(*((*event_array) + event_count)).length = event_length + 1;
|
||||||
|
event_count++;
|
||||||
|
}
|
||||||
|
start_ns = array[i+1];
|
||||||
|
event_length = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
event_length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event_length >= min_event_length) //utolsó lemaradt elem vizsgálata
|
||||||
|
{
|
||||||
|
(*((*event_array) + event_count)).start_ns = start_ns; //kezdő elem
|
||||||
|
(*((*event_array) + event_count)).end_ns = array[i]; //utolsó elemnek a még jó idejü
|
||||||
|
(*((*event_array) + event_count)).time_sec = time_sec; //ebben a másodpercben volt az esemény, későbbi hazsnálatra
|
||||||
|
(*((*event_array) + event_count)).length = event_length + 1;
|
||||||
|
event_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*event_array_size = event_count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mysql_write_event_data_row(MYSQL *con, int row_buffer[], int id)
|
||||||
|
{
|
||||||
|
char data[300];
|
||||||
|
snprintf(data,300,"INSERT INTO `event_data` (chamber,sec,id,ch_id,inte_data,peak_amp,time_ns,width,cmp_lvl) VALUES(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
|
||||||
|
row_buffer[0], row_buffer[5], id, row_buffer[1],row_buffer[2], row_buffer[3], row_buffer[6], row_buffer[4], row_buffer[7]);
|
||||||
|
if (mysql_query(con,data))
|
||||||
|
{
|
||||||
|
finish_with_error(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fill_event_table(struct events *event_time_buf, int event_time_buf_size, MYSQL *con, char * table_name)
|
||||||
|
{
|
||||||
|
static int event_id=0;
|
||||||
|
int i;
|
||||||
|
char q_string[100];
|
||||||
|
|
||||||
|
int row_buff[8];
|
||||||
|
|
||||||
|
for(i=0;i<event_time_buf_size;i++)
|
||||||
|
{
|
||||||
|
snprintf(q_string,150,"SELECT * FROM `%s` where time_sec =%d AND time_ns >=%d AND time_ns <=%d ORDER BY `ch_id` ASC"
|
||||||
|
, table_name, event_time_buf[i].time_sec, event_time_buf[i].start_ns, event_time_buf[i].end_ns );
|
||||||
|
printf("data:%s",q_string);
|
||||||
|
if (mysql_query(con, q_string))
|
||||||
|
{
|
||||||
|
finish_with_error(con);
|
||||||
|
}
|
||||||
|
//printf("lekeres ok\n");
|
||||||
|
|
||||||
|
MYSQL_RES *result = mysql_store_result(con);
|
||||||
|
|
||||||
|
if (result == NULL)
|
||||||
|
{
|
||||||
|
finish_with_error(con);
|
||||||
|
}
|
||||||
|
//printf("store ok\n");
|
||||||
|
|
||||||
|
if( mysql_num_fields(result) != 8)
|
||||||
|
{
|
||||||
|
printf("oszlop nem 8\n");
|
||||||
|
//mysql_close(con);
|
||||||
|
//exit(1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
MYSQL_ROW row;
|
||||||
|
if(mysql_num_rows(result) != event_time_buf[i].length)
|
||||||
|
{
|
||||||
|
printf("sorok szama nem egyezik meg!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int j,k;
|
||||||
|
//while ((row = mysql_fetch_row(result)))
|
||||||
|
for(j=0;j<event_time_buf[i].length ;j++) //összetartozó sorok
|
||||||
|
{
|
||||||
|
if((row = mysql_fetch_row(result)) == NULL)
|
||||||
|
{
|
||||||
|
printf("row null error");
|
||||||
|
mysql_free_result(result);
|
||||||
|
return -1; //hiba
|
||||||
|
}
|
||||||
|
for(k=0;k<8;k++) //soron belül oszlopok
|
||||||
|
{
|
||||||
|
if(row[k] != NULL)
|
||||||
|
{
|
||||||
|
row_buff[k] = atoi(row[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql_write_event_data_row(con,row_buff,event_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
event_id++;
|
||||||
|
mysql_free_result(result);
|
||||||
|
printf("for i:%d",i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
int main(int argc,char* argv[])
|
||||||
|
{
|
||||||
|
signal(SIGINT, sigintHandler); //CTRL + C kezelése. csak szórakozás
|
||||||
|
mysql_connect(&con);
|
||||||
|
|
||||||
|
int *array = NULL;
|
||||||
|
int size;
|
||||||
|
int sec;
|
||||||
|
|
||||||
|
struct events* event_buf = NULL;
|
||||||
|
int event_buf_size;
|
||||||
|
|
||||||
|
printf("end sec:");
|
||||||
|
scanf("%d",&sec);
|
||||||
|
|
||||||
|
/*
|
||||||
|
time_ns_col_to_array(con, &array, &size, sec, "fb_55"); //másodpercet főként itt beállítani!!!
|
||||||
|
|
||||||
|
for(int i=0;i<size;i++)
|
||||||
|
printf("%d\n",array[i]);
|
||||||
|
|
||||||
|
find(array, size, sec, &event_buf, &event_buf_size, 2000, 2);
|
||||||
|
printf("\nevnet array length:%d\n",event_buf_size);
|
||||||
|
|
||||||
|
for(int i=0;i<event_buf_size;i++)
|
||||||
|
printf("\nstart:%d, end:%d length:%d\n",event_buf[i].start_ns, event_buf[i].end_ns, event_buf[i].length);
|
||||||
|
|
||||||
|
free(array);
|
||||||
|
free(event_buf);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
for(int j=10;j<sec;j++)
|
||||||
|
{
|
||||||
|
time_ns_col_to_array(con, &array, &size, j, "fb_55"); //másodpercet főként itt beállítani!!!
|
||||||
|
|
||||||
|
//for(int i=0;i<size;i++)
|
||||||
|
//printf("%d\n",array[i]);
|
||||||
|
|
||||||
|
find(array, size, j, &event_buf, &event_buf_size, 4000, 4);
|
||||||
|
printf("\nevnet array length:%d\n",event_buf_size);
|
||||||
|
|
||||||
|
//for(int i=0;i<event_buf_size;i++)
|
||||||
|
//printf("\nstart:%d, end:%d length:%d\n",event_buf[i].start_ns, event_buf[i].end_ns, event_buf[i].length);
|
||||||
|
|
||||||
|
fill_event_table(event_buf, event_buf_size, con, "fb_55");
|
||||||
|
|
||||||
|
free(array);
|
||||||
|
free(event_buf);
|
||||||
|
printf("ok\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("end\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mysql_close(con);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,666 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <mysql/mysql.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <ncurses.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
WINDOW *header, *connections, *packages;
|
||||||
|
uint32_t counter = 0;
|
||||||
|
|
||||||
|
timer_t gTimerid;
|
||||||
|
|
||||||
|
WINDOW *create_newwin(int height, int width, int starty, int startx);
|
||||||
|
void destroy_win(WINDOW *local_win);
|
||||||
|
|
||||||
|
|
||||||
|
char *server = "localhost"; /* server host (default=localhost) */
|
||||||
|
char *user = "root"; /* username (default=login name) */
|
||||||
|
char *password = "raspberry"; /* password (default=none) */
|
||||||
|
char *database = "adatok"; /* database name (default=none) */
|
||||||
|
/*static*/
|
||||||
|
static MYSQL *conn;
|
||||||
|
|
||||||
|
|
||||||
|
struct buf_struct
|
||||||
|
{
|
||||||
|
|
||||||
|
//packed start
|
||||||
|
uint16_t start_header; //fix 0xFB55 csak a csomag elejének azonosításához kell
|
||||||
|
|
||||||
|
//innentől kerülnének az adatbázisba mind külön öszlopba
|
||||||
|
uint8_t chamber_id; //fix 0x00 felsőbb egység állítsa be
|
||||||
|
uint8_t ch_id; //jumper configurable lsb module ch0-1 select next 4 bit 16 modul select next 1 bit xy board select
|
||||||
|
int32_t inte_data; //integrated curve
|
||||||
|
uint16_t peak_amp;
|
||||||
|
uint16_t width;
|
||||||
|
uint32_t time_sec;
|
||||||
|
uint32_t time_ns;
|
||||||
|
uint16_t cmp_level;
|
||||||
|
uint16_t reserved;
|
||||||
|
//ez mehetne valami tömbbszerüségbe ha van ilyen
|
||||||
|
#ifdef debug_buf
|
||||||
|
uint16_t buff[raw_buff_size];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//crc-t lehetne ellenőrízni amikor megérkezik a csomag, nem kell az adatbázisba
|
||||||
|
uint16_t crc32;
|
||||||
|
uint16_t end_header; //fix 0xFEAA //csomag vége ez se kell!
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define raw_buff_size 64
|
||||||
|
|
||||||
|
#ifdef debug_buf
|
||||||
|
#define packet_size (28 + (2*raw_buff_size))
|
||||||
|
#else
|
||||||
|
#define packet_size 28
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WINDOW *create_newwin(int height, int width, int starty, int startx)
|
||||||
|
{ WINDOW *local_win;
|
||||||
|
|
||||||
|
local_win = newwin(height, width, starty, startx);
|
||||||
|
//box(local_win, 0 , 0); /* 0, 0 gives default characters
|
||||||
|
// * for the vertical and horizontal
|
||||||
|
// * lines */
|
||||||
|
wborder(local_win, '|', '|', '-', '-', '+', '+', '+', '+');
|
||||||
|
wrefresh(local_win); /* Show that box */
|
||||||
|
|
||||||
|
return local_win;
|
||||||
|
}
|
||||||
|
|
||||||
|
int redrawborder(WINDOW *local_win)
|
||||||
|
{
|
||||||
|
//box(local_win, 0 , 0); /* 0, 0 gives default characters
|
||||||
|
// * for the vertical and horizontal
|
||||||
|
// * lines */
|
||||||
|
wborder(local_win, '|', '|', '-', '-', '+', '+', '+', '+');
|
||||||
|
wrefresh(local_win);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy_win(WINDOW *local_win)
|
||||||
|
{
|
||||||
|
/* box(local_win, ' ', ' '); : This won't produce the desired
|
||||||
|
* result of erasing the window. It will leave it's four corners
|
||||||
|
* and so an ugly remnant of window.
|
||||||
|
*/
|
||||||
|
wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
|
||||||
|
/* The parameters taken are
|
||||||
|
* 1. win: the window on which to operate
|
||||||
|
* 2. ls: character to be used for the left side of the window
|
||||||
|
* 3. rs: character to be used for the right side of the window
|
||||||
|
* 4. ts: character to be used for the top side of the window
|
||||||
|
* 5. bs: character to be used for the bottom side of the window
|
||||||
|
* 6. tl: character to be used for the top left corner of the window
|
||||||
|
* 7. tr: character to be used for the top right corner of the window
|
||||||
|
* 8. bl: character to be used for the bottom left corner of the window
|
||||||
|
* 9. br: character to be used for the bottom right corner of the window
|
||||||
|
*/
|
||||||
|
wrefresh(local_win);
|
||||||
|
delwin(local_win);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialOpen:
|
||||||
|
* Open and initialise the serial port, setting all the right
|
||||||
|
* port parameters - or as many as are required - hopefully!
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
int serialOpen (const char *device, const int baud)
|
||||||
|
{
|
||||||
|
struct termios options ;
|
||||||
|
speed_t myBaud ;
|
||||||
|
int status, fd ;
|
||||||
|
|
||||||
|
switch (baud)
|
||||||
|
{
|
||||||
|
case 50: myBaud = B50 ; break ;
|
||||||
|
case 75: myBaud = B75 ; break ;
|
||||||
|
case 110: myBaud = B110 ; break ;
|
||||||
|
case 134: myBaud = B134 ; break ;
|
||||||
|
case 150: myBaud = B150 ; break ;
|
||||||
|
case 200: myBaud = B200 ; break ;
|
||||||
|
case 300: myBaud = B300 ; break ;
|
||||||
|
case 600: myBaud = B600 ; break ;
|
||||||
|
case 1200: myBaud = B1200 ; break ;
|
||||||
|
case 1800: myBaud = B1800 ; break ;
|
||||||
|
case 2400: myBaud = B2400 ; break ;
|
||||||
|
case 4800: myBaud = B4800 ; break ;
|
||||||
|
case 9600: myBaud = B9600 ; break ;
|
||||||
|
case 19200: myBaud = B19200 ; break ;
|
||||||
|
case 38400: myBaud = B38400 ; break ;
|
||||||
|
case 57600: myBaud = B57600 ; break ;
|
||||||
|
case 115200: myBaud = B115200 ; break ;
|
||||||
|
case 230400: myBaud = B230400 ; break ;
|
||||||
|
case 460800: myBaud = B460800 ; break ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return -2 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1)
|
||||||
|
return -1 ;
|
||||||
|
|
||||||
|
fcntl (fd, F_SETFL, O_RDWR) ;
|
||||||
|
|
||||||
|
// Get and modify current options:
|
||||||
|
|
||||||
|
tcgetattr (fd, &options) ;
|
||||||
|
|
||||||
|
cfmakeraw (&options) ;
|
||||||
|
cfsetispeed (&options, myBaud) ;
|
||||||
|
cfsetospeed (&options, myBaud) ;
|
||||||
|
|
||||||
|
options.c_cflag |= (CLOCAL | CREAD) ;
|
||||||
|
options.c_cflag &= ~PARENB ;
|
||||||
|
options.c_cflag &= ~CSTOPB ;
|
||||||
|
options.c_cflag &= ~CSIZE ;
|
||||||
|
options.c_cflag |= CS8 ;
|
||||||
|
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
|
||||||
|
options.c_oflag &= ~OPOST ;
|
||||||
|
|
||||||
|
options.c_cc [VMIN] = 0 ;
|
||||||
|
options.c_cc [VTIME] = 100 ; // Ten seconds (100 deciseconds)
|
||||||
|
|
||||||
|
tcsetattr (fd, TCSANOW | TCSAFLUSH, &options) ;
|
||||||
|
|
||||||
|
ioctl (fd, TIOCMGET, &status);
|
||||||
|
|
||||||
|
status |= TIOCM_DTR ;
|
||||||
|
status |= TIOCM_RTS ;
|
||||||
|
|
||||||
|
ioctl (fd, TIOCMSET, &status);
|
||||||
|
|
||||||
|
usleep (10000) ; // 10mS
|
||||||
|
|
||||||
|
return fd ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialFlush:
|
||||||
|
* Flush the serial buffers (both tx & rx)
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
void serialFlush (const int fd)
|
||||||
|
{
|
||||||
|
tcflush (fd, TCIOFLUSH) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialClose:
|
||||||
|
* Release the serial port
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
void serialClose (const int fd)
|
||||||
|
{
|
||||||
|
close (fd) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialPutchar:
|
||||||
|
* Send a single character to the serial port
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
void serialPutchar (const int fd, const unsigned char c)
|
||||||
|
{
|
||||||
|
write (fd, &c, 1) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialPuts:
|
||||||
|
* Send a string to the serial port
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
void serialPuts (const int fd, const char *s)
|
||||||
|
{
|
||||||
|
write (fd, s, strlen (s)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialPrintf:
|
||||||
|
* Printf over Serial
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
void serialPrintf (const int fd, const char *message, ...)
|
||||||
|
{
|
||||||
|
va_list argp ;
|
||||||
|
char buffer [1024] ;
|
||||||
|
|
||||||
|
va_start (argp, message) ;
|
||||||
|
vsnprintf (buffer, 1023, message, argp) ;
|
||||||
|
va_end (argp) ;
|
||||||
|
|
||||||
|
serialPuts (fd, buffer) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialDataAvail:
|
||||||
|
* Return the number of bytes of data avalable to be read in the serial port
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
int serialDataAvail (const int fd)
|
||||||
|
{
|
||||||
|
int result ;
|
||||||
|
|
||||||
|
if (ioctl (fd, FIONREAD, &result) == -1)
|
||||||
|
return -1 ;
|
||||||
|
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* serialGetchar:
|
||||||
|
* Get a single character from the serial device.
|
||||||
|
* Note: Zero is a valid character and this function will time-out after
|
||||||
|
* 10 seconds.
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
int serialGetchar (const int fd)
|
||||||
|
{
|
||||||
|
uint8_t x ;
|
||||||
|
|
||||||
|
if (read (fd, &x, 1) != 1)
|
||||||
|
return -1 ;
|
||||||
|
|
||||||
|
return ((int)x) & 0xFF ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************************************************************************************************************************************/
|
||||||
|
/*************************************************************************************************************************************************************************************************/
|
||||||
|
/*************************************************************************************************************************************************************************************************/
|
||||||
|
/*************************************************************************************************************************************************************************************************/
|
||||||
|
/*************************************************************************************************************************************************************************************************/
|
||||||
|
/*************************************************************************************************************************************************************************************************/
|
||||||
|
|
||||||
|
int serialGetarray(const int fd, uint8_t out[], unsigned int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint8_t x;
|
||||||
|
if((out == 0) | (fd == 0)) return -1;
|
||||||
|
if(size == 0) return -1;
|
||||||
|
|
||||||
|
for(i=0;i<size;i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(read (fd, &out[i], 1) != 1)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; //nincs hiba
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int read_packet(uint16_t size, uint8_t buff[], const int fd)
|
||||||
|
{
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
|
//find start
|
||||||
|
do{ //olvasás amíg nem a start header(0xFB55) első bájtja
|
||||||
|
//(0x55 a litle endian miatt(kisebb hejiértékü bájt érkezik hamarabb))
|
||||||
|
|
||||||
|
while(! (serialDataAvail(fd) > 0)) //vár amíg nincs adat
|
||||||
|
{
|
||||||
|
usleep(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
buff[0] = serialGetchar (fd);
|
||||||
|
}while(buff[0] != 0x55); //ha start header eleje akkro tovább
|
||||||
|
|
||||||
|
|
||||||
|
while(! (serialDataAvail(fd) > 0)) //vár amíg nincs adat
|
||||||
|
{
|
||||||
|
//thread sleep? kelhet
|
||||||
|
}
|
||||||
|
buff[1] = serialGetchar (fd);
|
||||||
|
if(buff[1] != 0xFB) //nem start header return error
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
//ha igen akkor beolvassa a maradék 22 bájtot
|
||||||
|
while(! (serialDataAvail(fd) >= (size-2))) //vár amíg nincs adat
|
||||||
|
{
|
||||||
|
usleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(serialGetarray(fd, &buff[2], (size-2)) == -1) //beolvas 22 bájtott a bufferbe a header utánra
|
||||||
|
{
|
||||||
|
return -1; //uart hiba
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buff[size-2] != 0xAA | buff[size-1] != 0xFE) //ha az end header nem passzol error
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
//todo crc check
|
||||||
|
|
||||||
|
return 1; //adat beolvasva
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mysql_connect(WINDOW *local_win)
|
||||||
|
{
|
||||||
|
conn = mysql_init(NULL);
|
||||||
|
//printf("Mysql: Connecting to %s@%s as %s\n",database,server,user);
|
||||||
|
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
|
||||||
|
{
|
||||||
|
wattron(local_win,COLOR_PAIR(1));
|
||||||
|
mvwprintw(local_win,2,1,"MySQL Error");
|
||||||
|
wattroff(local_win,COLOR_PAIR(1));
|
||||||
|
wrefresh(local_win);
|
||||||
|
/*fprintf(stderr, "%s\n", mysql_error(conn));
|
||||||
|
exit(1);*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wattron(local_win,COLOR_PAIR(2));
|
||||||
|
mvwprintw(local_win,2,1,"MySQL OK");
|
||||||
|
wattroff(local_win,COLOR_PAIR(2));
|
||||||
|
wrefresh(local_win);
|
||||||
|
} //printf("Mysql: Connected succesfully!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int mysql_write(struct buf_struct adatok, WINDOW *local_win)
|
||||||
|
{
|
||||||
|
char data[300];
|
||||||
|
//printf("MySQL: Adatok beírása...\n");
|
||||||
|
//snprintf(data,300,"INSERT INTO fb55(chamber_id,ch_id,inte_data,peak_amp,width,time_sec,time_ns,cmp_lvl) VALUES(%d,%d,%d,%d,%d,%ld,%ld,%d)",adatok.chamber_id,adatok.ch_id,adatok.inte_data,adatok.peak_amp,adatok.width,adatok.time_sec,adatok.time_ns, adatok.cmp_level);
|
||||||
|
snprintf(data,300,"INSERT INTO fb55(chamber_id,ch_id,inte_data,peak_amp,width,time_sec,time_ns,cmp_lvl) VALUES(%hhu,%hhu,%d,%hu,%hu,%u,%u,%hu)"
|
||||||
|
,adatok.chamber_id,adatok.ch_id,adatok.inte_data,adatok.peak_amp,adatok.width,adatok.time_sec,adatok.time_ns, adatok.cmp_level);
|
||||||
|
if (!mysql_query(conn,data))
|
||||||
|
{
|
||||||
|
wattron(local_win,COLOR_PAIR(2));
|
||||||
|
mvwprintw(local_win,4,1,"Database OK");
|
||||||
|
wattroff(local_win,COLOR_PAIR(2));
|
||||||
|
wrefresh(local_win);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wattron(local_win,COLOR_PAIR(1));
|
||||||
|
mvwprintw(local_win,4,1,"Database Error");
|
||||||
|
wattroff(local_win,COLOR_PAIR(1));
|
||||||
|
wrefresh(local_win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int droptablecontent(char *tablename, WINDOW *local_win)
|
||||||
|
{
|
||||||
|
char data[100];
|
||||||
|
//printf("MySQL: Tábla ürítése...\n");
|
||||||
|
if (tablename==NULL)
|
||||||
|
{
|
||||||
|
snprintf(data,100,"truncate fb55");
|
||||||
|
}
|
||||||
|
else snprintf(data,100,"truncate %s",tablename);
|
||||||
|
if(mysql_query(conn,data)==0)
|
||||||
|
{
|
||||||
|
//printf("Sikeres ürítés!\n");
|
||||||
|
wattron(local_win,COLOR_PAIR(2));
|
||||||
|
mvwprintw(local_win,5,1,"Truncate OK");
|
||||||
|
wattroff(local_win,COLOR_PAIR(2));
|
||||||
|
wrefresh(local_win);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sigintHandler(int sig_num)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sigintHandler);
|
||||||
|
mysql_close(conn);
|
||||||
|
clear();
|
||||||
|
char msg[]="Exiting...";
|
||||||
|
int row,col;
|
||||||
|
getmaxyx(stdscr,row,col);
|
||||||
|
mvprintw(row/2,(col-strlen(msg))/2,"%s",msg);
|
||||||
|
refresh();
|
||||||
|
//sleep(1);
|
||||||
|
endwin();
|
||||||
|
//printf("\nExiting... \n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int init()
|
||||||
|
{
|
||||||
|
if ( (initscr()) == NULL )
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error initialising ncurses.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
curs_set(0);
|
||||||
|
cbreak();
|
||||||
|
refresh();
|
||||||
|
if(has_colors() == FALSE)
|
||||||
|
{ endwin();
|
||||||
|
printf("Your terminal does not support color\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
start_color(); /* Start color */
|
||||||
|
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||||
|
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
int printheader(WINDOW *header)
|
||||||
|
{
|
||||||
|
int width_max = COLS;
|
||||||
|
mvwprintw(header, 1, (width_max-58)/2, " ___ _ _ ___ __ __ ___ ___ _ ");
|
||||||
|
mvwprintw(header, 2, (width_max-58)/2, "/ __| ___ _ _(_)__ _| | |_ ) | \\/ |_ _/ __|/ _ \\| | ");
|
||||||
|
mvwprintw(header, 3, (width_max-58)/2, "\\__ \\/ -_) '_| / _` | | / / | |\\/| | || \\__ \\ (_) | |__ ");
|
||||||
|
mvwprintw(header, 4, (width_max-58)/2, "|___/\\___|_| |_\\__,_|_| /___| |_| |_|\\_, |___/\\__\\_\\____|");
|
||||||
|
mvwprintw(header, 5, (width_max-58)/2, " |__/");
|
||||||
|
wrefresh(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
int printdatas(WINDOW *datas, struct buf_struct packet, int height, int width)
|
||||||
|
{
|
||||||
|
//ch_id:%d, inte:%ld, peak:%d, width:%d, time_sec:%ld, time_ns:%ld, , , , , , ,
|
||||||
|
|
||||||
|
mvwprintw(datas,height-2,1,"comp_lvl: ");
|
||||||
|
wclrtoeol(datas);
|
||||||
|
mvwprintw(datas,height-2,(width-floor((log10(packet.cmp_level+1) + 2))), "%d",packet.cmp_level);
|
||||||
|
|
||||||
|
mvwprintw(datas,height-4,1,"time_ns: ");
|
||||||
|
wclrtoeol(datas);
|
||||||
|
mvwprintw(datas,height-4,(width-floor((log10(packet.time_ns+1) + 2))), "%d",packet.time_ns);
|
||||||
|
|
||||||
|
mvwprintw(datas,height-6,1,"time_sec: ");
|
||||||
|
wclrtoeol(datas);
|
||||||
|
mvwprintw(datas,height-6,(width-floor((log10(packet.time_sec+1) + 2))), "%d",packet.time_sec);
|
||||||
|
|
||||||
|
mvwprintw(datas,height-8,1,"width: ");
|
||||||
|
wclrtoeol(datas);
|
||||||
|
mvwprintw(datas,height-8,(width-floor((log10(packet.width+1) + 2))), "%d",packet.width);
|
||||||
|
|
||||||
|
mvwprintw(datas,height-10,1,"peak_amp: ");
|
||||||
|
wclrtoeol(datas);
|
||||||
|
mvwprintw(datas,height-10,(width-floor((log10(packet.peak_amp+1) + 2))), "%d",packet.peak_amp);
|
||||||
|
|
||||||
|
mvwprintw(datas,height-12,1,"inte_data: ");
|
||||||
|
wclrtoeol(datas);
|
||||||
|
mvwprintw(datas,height-12,(width-floor((log10(abs(packet.inte_data+1)) + 2))), "%d",packet.inte_data);
|
||||||
|
|
||||||
|
mvwprintw(datas,height-14,1,"ch_id: ");
|
||||||
|
wclrtoeol(datas);
|
||||||
|
mvwprintw(datas,height-14,(width-floor((log10(packet.ch_id+1) + 2))), "%d",packet.ch_id);
|
||||||
|
|
||||||
|
redrawborder(datas);
|
||||||
|
wrefresh(datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
void start_timer(void)
|
||||||
|
{
|
||||||
|
struct itimerspec value;
|
||||||
|
value.it_value.tv_sec = 1;//waits for 5 seconds before sending timer signal
|
||||||
|
value.it_value.tv_nsec = 0;
|
||||||
|
value.it_interval.tv_sec = 1; //sends timer signal every 5 seconds
|
||||||
|
value.it_interval.tv_nsec = 0;
|
||||||
|
timer_create (CLOCK_REALTIME, NULL, &gTimerid);
|
||||||
|
timer_settime (gTimerid, 0, &value, NULL);
|
||||||
|
}
|
||||||
|
void stop_timer(void)
|
||||||
|
{
|
||||||
|
struct itimerspec value;
|
||||||
|
value.it_value.tv_sec = 0;
|
||||||
|
value.it_value.tv_nsec = 0;
|
||||||
|
value.it_interval.tv_sec = 0;
|
||||||
|
value.it_interval.tv_nsec = 0;
|
||||||
|
timer_settime (gTimerid, 0, &value, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void timer_callback(int sig)
|
||||||
|
{
|
||||||
|
int height, width;
|
||||||
|
getmaxyx(connections,height,width);
|
||||||
|
mvwprintw(connections,height-7,1,"Received/Sec:");
|
||||||
|
wmove(connections,height-6,1);
|
||||||
|
wclrtoeol(connections);
|
||||||
|
mvwprintw(connections,height-6,(width-floor((log10(abs(counter)) + 2))),"%d", counter);
|
||||||
|
wrefresh(connections);
|
||||||
|
counter=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc,char* argv[])
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
int startx, starty, width_max, height_max, width, height, serialstatus, packages_maxx, packages_maxy;
|
||||||
|
uint8_t raw_buff[packet_size + 10]; //packet_size + egy kis tartalék, ha nincs hiba sehol akkor nem kell
|
||||||
|
uint16_t i;
|
||||||
|
uint32_t received = 0, writed = 0, count_x=0, count_y=0;
|
||||||
|
struct buf_struct packet;
|
||||||
|
width_max= 0;
|
||||||
|
height_max= 0;
|
||||||
|
height = 7;
|
||||||
|
width = width_max;
|
||||||
|
starty = 0; /* Calculating for a center placement */
|
||||||
|
startx = 0; /* of the window */
|
||||||
|
header = create_newwin(height, width, starty, startx);
|
||||||
|
connections = create_newwin(LINES-(height-1), 15, height-1, 0);
|
||||||
|
packages = create_newwin(LINES-(height-1), COLS-14, height-1, 14);
|
||||||
|
getmaxyx(connections,height_max,width_max);
|
||||||
|
getmaxyx(packages,packages_maxy,packages_maxx);
|
||||||
|
printheader(header);
|
||||||
|
mvwprintw(packages,1,1,"For debug mode use -d | For truncate use -drop | \n|You can truncate another table with -drop tablename");
|
||||||
|
wrefresh(packages);
|
||||||
|
//printf("**********************\n* Serial 2 Mysql *\n* For debug mode: -d *\n*For truncate: -drop *\n* You can truncate *\n* another table with *\n* -drop tablename *\n**********************\n* Script written *\n* by Baranyai Dávid *\n**********************\n");
|
||||||
|
mysql_connect(connections);
|
||||||
|
signal(SIGINT, sigintHandler); //CTRL + C kezelése. csak szórakozás
|
||||||
|
signal(SIGALRM, timer_callback); //timer megszakítás
|
||||||
|
start_timer();
|
||||||
|
if(argc>1)
|
||||||
|
{
|
||||||
|
if (!strcmp(argv[1],"-drop"))
|
||||||
|
{
|
||||||
|
if (argc>2)
|
||||||
|
{
|
||||||
|
droptablecontent(argv[2],connections);
|
||||||
|
}
|
||||||
|
else droptablecontent(NULL,connections);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int fd=serialOpen("/dev/ttyACM0",460800); //serial megnyitása
|
||||||
|
while (fd < 0)
|
||||||
|
{
|
||||||
|
wattron(connections,COLOR_PAIR(1));
|
||||||
|
mvwprintw(connections,1,1,"Serial Error");
|
||||||
|
wattroff(connections,COLOR_PAIR(1));
|
||||||
|
wrefresh(connections);
|
||||||
|
fd=serialOpen("/dev/ttyACM0",460800);
|
||||||
|
} //sikertelen csatlakozás esetén
|
||||||
|
//printf("Serial: Connected succesfully!");
|
||||||
|
wmove(connections,1,1);
|
||||||
|
wclrtoeol(connections);
|
||||||
|
redrawborder(connections);
|
||||||
|
wattron(connections,COLOR_PAIR(2));
|
||||||
|
mvwprintw(connections,1,1,"Serial OK");
|
||||||
|
wattroff(connections,COLOR_PAIR(2));
|
||||||
|
refresh();
|
||||||
|
wrefresh(connections);
|
||||||
|
serialFlush(fd); //buffer ürítése
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if(read_packet(packet_size, &raw_buff[0], fd) != -1)
|
||||||
|
{
|
||||||
|
received++;
|
||||||
|
if (serialstatus==0)
|
||||||
|
{
|
||||||
|
wmove(connections,3,1);
|
||||||
|
wclrtoeol(connections);
|
||||||
|
redrawborder(connections);
|
||||||
|
}
|
||||||
|
//sikerült beolvasni egy csomagot, feldolgozás
|
||||||
|
//printf("Sikeres fogadas\n");
|
||||||
|
wattron(connections,COLOR_PAIR(2));
|
||||||
|
mvwprintw(connections,3,1,"Receive OK");
|
||||||
|
wattroff(connections,COLOR_PAIR(2));
|
||||||
|
mvwprintw(connections,height_max-5,1,"Received: ");
|
||||||
|
wmove(connections,height_max-4,1);
|
||||||
|
wclrtoeol(connections);
|
||||||
|
mvwprintw(connections,height_max-4,(width_max-floor((log10(abs(received+1)) + 2))),"%d",received);
|
||||||
|
|
||||||
|
packet = *((struct buf_struct*) (&raw_buff[0])); //struktúrává kasztolás és átmásolás egy tényleges struktúrába
|
||||||
|
printdatas(packages, packet, packages_maxy, packages_maxx);
|
||||||
|
//struktúra tagok kiíratása
|
||||||
|
//printf("ch_id:%d, inte:%ld, peak:%d, width:%d, time_sec:%ld, time_ns:%ld, comp_lvl:%d\n", packet.ch_id, packet.inte_data, packet.peak_amp , packet.width, packet.time_sec, packet.time_ns, packet.cmp_level);
|
||||||
|
//mvprintw(3,0,"ch_id:%d, inte:%ld, peak:%d, width:%d, time_sec:%ld, time_ns:%ld, comp_lvl:%d\n", packet.ch_id, packet.inte_data, packet.peak_amp , packet.width, packet.time_sec, packet.time_ns, packet.cmp_level);
|
||||||
|
if (mysql_write(packet, connections)==1)
|
||||||
|
{
|
||||||
|
if (packet.ch_id>31)
|
||||||
|
{
|
||||||
|
count_y++;
|
||||||
|
}
|
||||||
|
else count_x++;
|
||||||
|
writed++;
|
||||||
|
counter++;
|
||||||
|
} //ideiglenes rögtönzött megoldás... struktúra átadása beírásra
|
||||||
|
mvwprintw(connections,height_max-3,1,"Writed: ");
|
||||||
|
wmove(connections,height_max-2,1);
|
||||||
|
mvwprintw(connections,height_max-2,(width_max-floor((log10(writed+1) + 2))),"%d",writed);
|
||||||
|
mvwprintw(connections,height_max-8,1,"y: %d",count_y);
|
||||||
|
mvwprintw(connections,height_max-9,1,"x: %d",count_x);
|
||||||
|
wrefresh(connections);
|
||||||
|
serialstatus = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (serialstatus==1)
|
||||||
|
{
|
||||||
|
wmove(connections,3,1);
|
||||||
|
wclrtoeol(connections);
|
||||||
|
redrawborder(connections);
|
||||||
|
}
|
||||||
|
wattron(connections,COLOR_PAIR(1));
|
||||||
|
mvwprintw(connections,3,1,"Receive Error");
|
||||||
|
wattroff(connections,COLOR_PAIR(1));
|
||||||
|
wrefresh(connections);
|
||||||
|
serialstatus = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue