Skip to content

Commit 56dbfba

Browse files
author
root
committed
test commit fgor eye grsph
1 parent cfb7485 commit 56dbfba

File tree

6 files changed

+124
-7
lines changed

6 files changed

+124
-7
lines changed

cli/diag.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <math.h>
3838
#include <stdio.h>
3939
#include <unistd.h>
40+
#include <stdlib.h>
4041

4142
struct diag_common_cfg {
4243
struct switchtec_dev *dev;
@@ -1085,14 +1086,24 @@ int eye_observe_dev(struct switchtec_dev *dev, int port_id,
10851086
int lane_id, int *gen)
10861087
{
10871088
int ret;
1088-
1089+
struct switchtec_diag_port_eye_data data_out;
1090+
unsigned int eye_data[6];
1091+
10891092
ret = switchtec_diag_eye_start(dev, lane_id);
10901093
if (ret) {
10911094
switchtec_perror("eye_start");
10921095
}
10931096

1094-
ret = switchtec_diag_eye_fetch(dev);
1097+
ret = switchtec_diag_eye_fetch(dev, &data_out);
1098+
1099+
data_out.eye_left = abs(data_out.eye_left);
1100+
data_out.eye_right = abs(data_out.eye_right);
1101+
data_out.eye_top_x1 = abs(data_out.eye_top_x1);
1102+
data_out.eye_bottom_x1 = abs(data_out.eye_bottom_x1);
10951103

1104+
printf("%d %d %d %d\n", data_out.eye_left, data_out.eye_right, data_out.eye_top_x1, data_out.eye_bottom_x1);
1105+
memcpy(&eye_data[0], &data_out, sizeof(struct switchtec_diag_port_eye_data));
1106+
graph_draw_eom_win(eye_data, 4,"Eye Observation Monitor","press q to quit");
10961107
return 0;
10971108
}
10981109

cli/graph.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,95 @@ void graph_init(void)
374374
curses_initialized = true;
375375
}
376376

377+
void draw_eom_data(WINDOW *win, unsigned int *data, int count, int x_offset, int y_offset)
378+
{
379+
for (int i = 0; i < count; ++i) {
380+
int xl = data[i] + x_offset;
381+
int xr = data[i] + x_offset;
382+
int yt = data[i] + y_offset;
383+
int yb = data[i] + y_offset;
384+
385+
// Draw points
386+
mvwaddch(win, yt, xl, 'L'); // Left
387+
mvwaddch(win, yt, xr, 'R'); // Right
388+
mvwaddch(win, yt, xl, 'T'); // Top
389+
mvwaddch(win, yb, xl, 'B'); // Bottom
390+
391+
// Draw horizontal line (left to right at eye_top)
392+
for (int x = xl; x <= xr; ++x)
393+
mvwaddch(win, yt, x, '-');
394+
395+
// Draw vertical line (top to bottom at eye_left)
396+
for (int y = yt; y <= yb; ++y)
397+
mvwaddch(win, y, xl, '|');
398+
}
399+
wrefresh(win);
400+
}
401+
402+
int graph_draw_eom_win(unsigned int *data, int count, const char *title, char *status)
403+
{
404+
WINDOW *datawin, *stwin = NULL;
405+
const int x_off = 7, y_off = 4;
406+
int s_off;
407+
int c;
408+
printf("%d %d %d %d\n", data[0], data[1], data[2], data[3]);
409+
if (!isatty(STDOUT_FILENO)) {
410+
// Fallback to text output if not a terminal
411+
return 0;
412+
}
413+
414+
if (!curses_initialized) {
415+
initscr();
416+
curses_initialized = true;
417+
}
418+
419+
noecho();
420+
cbreak();
421+
curs_set(0);
422+
keypad(stdscr, true);
423+
start_color();
424+
425+
if (status) {
426+
s_off = 2;
427+
stwin = newwin(2, 0, LINES - 2, 0);
428+
if (!stwin) {
429+
perror("Unable to create window");
430+
return 1;
431+
}
432+
} else {
433+
s_off = 0;
434+
}
435+
436+
datawin = newwin(LINES - y_off - s_off, COLS - x_off, y_off, x_off);
437+
if (!datawin) {
438+
perror("Unable to create window");
439+
return 1;
440+
}
441+
442+
// Main loop
443+
while (1) {
444+
werase(datawin);
445+
box(datawin, 0, 0);
446+
draw_eom_data(datawin, data, count, 0, 0);
447+
448+
if (stwin) {
449+
werase(stwin);
450+
mvwprintw(stwin, 0, 0, "%s", status);
451+
wrefresh(stwin);
452+
}
453+
454+
c = getch();
455+
if (c == 'q' || c == 'x')
456+
break;
457+
}
458+
459+
if (stwin)
460+
delwin(stwin);
461+
delwin(datawin);
462+
endwin();
463+
return 0;
464+
}
465+
377466
#else /* defined(HAVE_LIBCURSES) || defined(HAVE_LIBNCURSES) */
378467

379468
int graph_draw_win(struct range *X, struct range *Y, int *data, int *shades,

cli/graph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ int graph_draw_win(struct range *X, struct range *Y, int *data, int *shades,
6969
const char *title, char x_title, char y_title, char *status,
7070
graph_anim_fn *anim, void *opaque);
7171

72+
int graph_draw_eom_win(unsigned int *data, int count, const char *title, char *status);
73+
7274
#endif

inc/switchtec/diag.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ struct switchtec_diag_port_eye_fetch {
233233
int32_t eye_top_x2;
234234
int32_t eye_bottom_x2;
235235
};
236+
237+
struct switchtec_diag_port_eye_data {
238+
int32_t eye_left;
239+
int32_t eye_right;
240+
int32_t eye_top_x1;
241+
int32_t eye_bottom_x1;
242+
};
236243
#pragma pack(pop)
237244

238245
struct switchtec_diag_cross_hair_in {

inc/switchtec/switchtec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <stdlib.h>
4141
#include <stdint.h>
4242
#include <stdio.h>
43+
#include "diag.h"
4344

4445
#ifdef __cplusplus
4546
extern "C" {
@@ -1242,7 +1243,7 @@ int switchtec_diag_cross_hair_get(struct switchtec_dev *dev, int start_lane_id,
12421243
int switchtec_diag_eye_set_mode(struct switchtec_dev *dev,
12431244
enum switchtec_diag_eye_data_mode mode);
12441245
int switchtec_diag_eye_start(struct switchtec_dev *dev, int lane_id);
1245-
int switchtec_diag_eye_fetch(struct switchtec_dev *dev);
1246+
int switchtec_diag_eye_fetch(struct switchtec_dev *dev, struct switchtec_diag_port_eye_data *data_out);
12461247
int switchtec_diag_eye_cancel(struct switchtec_dev *dev);
12471248

12481249
int switchtec_diag_loopback_set(struct switchtec_dev *dev, int port_id,

lib/diag.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ const char* diag_eom_status_string[] = {
216216
* mode, otherwise data will be lost and the number of pixels fetched
217217
* will be greater than the space in the pixel buffer.
218218
*/
219-
int switchtec_diag_eye_fetch(struct switchtec_dev *dev)
219+
int switchtec_diag_eye_fetch(struct switchtec_dev *dev, struct switchtec_diag_port_eye_data *data_out)
220220
{
221221
struct switchtec_diag_port_eye_cmd in = {
222222
.sub_cmd = MRPC_EYE_OBSERVE_FETCH,
223223
};
224224
struct switchtec_diag_port_eye_fetch out;
225+
struct switchtec_diag_port_eye_data data;
225226
int ret;
226227

227228
retry:
@@ -242,9 +243,15 @@ int switchtec_diag_eye_fetch(struct switchtec_dev *dev)
242243
else if(out.status == 0)
243244
{
244245
printf("Eye Left %d\n", out.eye_left);
245-
printf("Eye Right %d\n", out.eye_right);
246-
printf("Eye top %d\n", out.eye_top_x1);
247-
printf("Eye Bottom %d\n", out.eye_bottom_x1);
246+
printf("Eye Right %d\n", out.eye_right);
247+
printf("Eye top %d\n", out.eye_top_x1);
248+
printf("Eye Bottom %d\n", out.eye_bottom_x1);
249+
250+
data.eye_left = out.eye_left;
251+
data.eye_right = out.eye_right;
252+
data.eye_top_x1 = out.eye_top_x1;
253+
data.eye_bottom_x1 = out.eye_bottom_x1;
254+
memcpy(data_out, &data, sizeof(struct switchtec_diag_port_eye_fetch));
248255
}
249256
else
250257
{

0 commit comments

Comments
 (0)