Merge pull request #2605 from stuiterveer/numhex
[RRG-proxmark3.git] / client / experimental_lib / example_c / test_grab.c
blobee573fc31f0898fcb4143d6ff764bbd8ca2f442e
1 #include "pm3.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <unistd.h>
7 int main(int argc, char *argv[]) {
9 // char buf[8196 + 1];
10 size_t n;
12 if (argc < 2) {
13 printf("Usage: %s <port>\n", argv[0]);
14 exit(-1);
17 pm3 *p;
18 p = pm3_open(argv[1]);
20 // Execute the command
21 pm3_console(p, "hw status", true, true);
23 const char *buf = pm3_grabbed_output_get(p);
24 const char *line_start = buf;
25 const char *newline_pos;
26 while ((newline_pos = strchr(line_start, '\n')) != NULL) {
27 // Determine the length of the line
28 size_t line_length = newline_pos - line_start;
30 // Create a temporary buffer to hold the line
31 char line[line_length + 1];
32 strncpy(line, line_start, line_length);
33 line[line_length] = '\0'; // Null-terminate the string
35 if (strstr(line, "ERROR") != NULL) {
36 printf("%s", line);
38 if (strstr(line, "Unique ID") != NULL) {
39 printf("%s", line);
42 // Move to the next line
43 line_start = newline_pos + 1;
47 pm3_close(p);