aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--remote_plot.c80
1 files changed, 55 insertions, 25 deletions
diff --git a/remote_plot.c b/remote_plot.c
index 4318ae3..dbf43e0 100644
--- a/remote_plot.c
+++ b/remote_plot.c
@@ -27,11 +27,16 @@
#include <gtk/gtk.h>
-// very small also works, just transfter delays, I test accelerometer data is
-// like 15782 which is 7 bytes consider newline and \0?
-#define MAX_XFER_BUF_SIZE 7
+// voltage max format 8 bytes ,xxx.xxx
+// temp max format 5 bytes ,xx.x
+// timestamp max 8 bytes 86400000
+// 96 voltage, 32 temp
+// 96*8+32*5+8=936 bytes
+#define MAX_XFER_BUF_SIZE 936
#define LEN 10
+#define VOLTLEN 96
+#define TEMPLEN 32
// Variables for holding error return info from PLplot
static PLINT pl_errcode;
@@ -42,7 +47,8 @@ typedef struct {
sftp_session sftp;
PLINT id1;
PLFLT t[LEN];
- PLFLT buffer[LEN];
+ PLFLT volt[LEN][VOLTLEN];
+ PLFLT temp[LEN][TEMPLEN];
GtkWidget *area;
}DATA;
@@ -61,7 +67,7 @@ static gboolean sftp_read_sync(gpointer user_data)
// This is to represent a loop over time
// Let's try a random walk process
- file = sftp_open(data->sftp, "/sys/bus/iio/devices/iio:device2/in_accel_z_raw",
+ file = sftp_open(data->sftp, "/tmp/mycan",
access_type, 0);
if (file == NULL) {
fprintf(stderr, "Can't open file for reading: %s\n",
@@ -71,9 +77,16 @@ static gboolean sftp_read_sync(gpointer user_data)
}
for(int i=0;i<(LEN-1);i++)
- data->buffer[i]=data->buffer[i+1];
+ {
+ //data->t[i]=data->t[i+1];
+ for(int j=0;j<VOLTLEN;j++)
+ data->volt[i][j]=data->volt[i+1][j];
+ for(int j=0;j<TEMPLEN;j++)
+ data->temp[i][j]=data->temp[i+1][j];
+ }
- for (;;) {
+ for(;;)
+ {
nbytes = sftp_read(file, buffer, sizeof(buffer));
if (nbytes == 0) {
break; // EOF
@@ -85,13 +98,14 @@ static gboolean sftp_read_sync(gpointer user_data)
return G_SOURCE_REMOVE;
}
- //printf("buffer %s",buffer);
- //printf("buffer int %d\n",atoi(buffer));
- //printf("id1 %d\n",data->id1);
- //printf("t %f\n",data->t[9]);
- //printf("before sftp_read_sync plstripa\n");
- data->buffer[LEN-1]=atof(buffer);
- //printf("after sftp_read_sync plstripa\n");
+ //printf("receive: %s",buffer);
+ //data->buffer[LEN-1]=atof(buffer);
+ // would be better if check strtok return NULL or not
+ strtok(buffer,",");
+ for(int i=0;i<VOLTLEN;i++)
+ data->volt[LEN-1][i]=atof(strtok(NULL,","));
+ for(int i=0;i<TEMPLEN;i++)
+ data->temp[LEN-1][i]=atof(strtok(NULL,","));
}
rc = sftp_close(file);
@@ -257,7 +271,7 @@ static void draw_function (GtkDrawingArea *area,
styline[2] = colline[2] = 4;
styline[3] = colline[3] = 5;
- legline[0] = "in_accel_z_raw"; // pens legend
+ legline[0] = "voltage"; // pens legend
legline[1] = "not_used";
legline[2] = "not_used";
legline[3] = "not_used";
@@ -306,7 +320,7 @@ static void draw_function (GtkDrawingArea *area,
{
//printf("t%d %f\n",i,data->t[i]);
//printf("buffer%d %f\n",i,data->buffer[i]);
- plstripa( data->id1, 0, data->t[i], data->buffer[i]);
+ plstripa( data->id1, 0, data->t[i], data->volt[i][0]);
}
//printf("before pl free\n");
@@ -318,14 +332,15 @@ static void draw_function (GtkDrawingArea *area,
static void print_data (GtkWidget *widget, gpointer user_data)
{
DATA *data=user_data;
- printf("t:");
- for(int i=0;i<LEN;i++)
- printf(" %g",data->t[i]);
- putchar('\n');
- printf("buffer:");
for(int i=0;i<LEN;i++)
- printf(" %g",data->buffer[i]);
- putchar('\n');
+ {
+ printf("%g",data->t[i]);
+ for(int j=0;j<VOLTLEN;j++)
+ printf(",%g",data->volt[i][j]);
+ for(int j=0;j<TEMPLEN;j++)
+ printf(",%g",data->temp[i][j]);
+ putchar('\n');
+ }
}
static void activate (GtkApplication *app, gpointer user_data)
@@ -355,7 +370,7 @@ static void activate (GtkApplication *app, gpointer user_data)
gtk_window_present (GTK_WINDOW (window));
- g_timeout_add(50,sftp_read_sync,user_data);
+ g_timeout_add(500,sftp_read_sync,user_data);
//printf("after g_timeout_add\n");
}
@@ -372,9 +387,24 @@ int main (int argc, char **argv)
for(int i=0;i<LEN;i++)
{
data.t[i]=i;
- data.buffer[i]=0;
+ for(int j=0;j<VOLTLEN;j++)
+ data.volt[i][j]=0;
+ for(int j=0;j<TEMPLEN;j++)
+ data.temp[i][j]=0;
}
+ //printf("my init test:\n")
+ //for(int i=0;i<LEN;i++)
+ //{
+ // printf("%g",data.t[i]);
+ // for(int j=0;j<VOLTLEN;j++)
+ // printf(",%g",data.volt[i][j]);
+ // for(int j=0;j<TEMPLEN;j++)
+ // printf(",%g",data.temp[i][j]);
+ // putchar('\n');
+ //}
+ //printf("my init test done\n")
+
// Open session and set options
data.session = ssh_new();
if (data.session == NULL)