ev3duder  0.3.0
EV3 Downloader/Uploader
info.c
Go to the documentation of this file.
1 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include <hidapi/hidapi.h>
13 #include "tcp.h"
14 #include "ev3_io.h"
15 
16 #include "defs.h"
17 #include "packets.h"
18 #include "error.h"
19 #include "funcs.h"
20 
21 #ifdef __linux__
22 #include <sys/utsname.h>
23 #endif
24 
26 static const u8 tone[] = "\x0\x0F\x00\0\0\x80\x00\x00\x94\x01\x81\x02\x82\xE8\x03\x82\xE8\x03";
27 
28 #define MAX_STR 256
29 
36 int info(const char*arg)
37 {
38  wchar_t wstr[MAX_STR];
39  if (arg)
40  {
41  if((void*)ev3_close == (void*)hid_close)
42  {
43  if (strcmp(arg, "serial") == 0)
44  {
45  hid_get_serial_number_string(handle, wstr, MAX_STR);
46  fputws(wstr, stdout);
47  //fputwc(L'\n', stdout);
48  return ERR_UNK;
49  }
50  }else if(ev3_close == tcp_close)
51  {
52  if (strcmp(arg, "ip") == 0)
53  {
54  fputs(((struct tcp_handle*)handle)->ip, stdout);
55  return ERR_UNK;
56  }
57  }
58 
59  return ERR_ARG;
60  }
61 
62  int res;
63  //TODO:
64  res = ev3_write(handle, tone, sizeof tone - 1);
65  if (res < 0)
66  {
67  return ERR_COMM;
68  }
69  errmsg = "\nAttempting beep..";
70  if ((void*)ev3_close == (void*)hid_close)
71  {
72 #ifdef __linux__
73  struct utsname utsname;
74  uname(&utsname);
75  int isOld = strcmp(utsname.release, "2.6.24") < 0;
77  printf("SUBSYSTEM==\"%s\", ATTRS{idVendor}==\"0694\", ATTRS{idProduct}==\"0005\a, MODE=\"0666\"\n", isOld ? "usb_device" : "usb");
78 #endif
79  res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
80  printf("Manufacturer String: %ls\n", wstr);
81  res = hid_get_product_string(handle, wstr, MAX_STR);
82  printf("Product String: %ls\n", wstr);
83  res = hid_get_serial_number_string(handle, wstr, MAX_STR);
84  printf("Serial Number String: %ls\n", wstr);
85  }else if (ev3_close == tcp_close)
86  {
87  struct tcp_handle* h = (struct tcp_handle*)handle;
88  printf("Serial: %s\n"
89  "Server: %s:%u\n"
90  "Name: %s\n"
91  "Protocol: %s\n",
92  h->serial,
93  h->ip, h->tcp_port,
94  h->name,
95  h->protocol
96  );
97  }
98 
99  return ERR_UNK;
100 }
101 
EXTERN void * handle
Definition: ev3_io.h:17
unsigned tcp_port
Definition: tcp.h:19
char name[96]
Definition: tcp.h:20
Definition: error.h:20
char ip[48]
Definition: tcp.h:18
Error enumerations and decriptions.
EXTERN void(* ev3_close)(void *)
Definition: ev3_io.h:16
int info(const char *arg)
cause a beep and print HID information if applicable
Definition: info.c:36
packed structs for the packets.
Definition: error.h:20
uint8_t u8
Definition: defs.h:9
Definition: error.h:20
char protocol[8]
Definition: tcp.h:21
#define MAX_STR
Definition: info.c:28
char serial[15]
Definition: tcp.h:17
void tcp_close(void *sock)
releases the socket file descriptor opened by tcp_open()
Definition: tcp.c:241
EXTERN const char * errmsg
global variable for last error message
Definition: error.h:25
BSD sockets/Winsock2 Input/Output wrappers.
contains declarations for ev3 commands
Definition: tcp.h:11
EXTERN int(* ev3_write)(void *, const u8 *, size_t)
Definition: ev3_io.h:13