Vuo 2.4.4
Loading...
Searching...
No Matches
VuoSerialDevice.c
Go to the documentation of this file.
1
10#include "VuoSerialDevice.h"
11#include "VuoSerial.h"
12
14#ifdef VUO_COMPILER
16 "title" : "Serial Device",
17 "description" : "Information about a serial I/O device.",
18 "keywords" : [ ],
19 "version" : "1.0.0",
20 "dependencies" : [
21 "VuoSerialDevices",
22 "VuoText"
23 ]
24 });
25#endif
27
32{
33 if (strcmp(json_object_get_string(js), "path") == 0)
34 return VuoSerialDevice_MatchPath;
35
36 return VuoSerialDevice_MatchName;
37}
38
43{
44 if (type == VuoSerialDevice_MatchPath)
45 return "path";
46
47 return "name";
48}
49
62{
63 return (VuoSerialDevice){
64 VuoJson_getObjectValue(VuoSerialDevice_MatchType, js, "matchType", VuoSerialDevice_MatchName),
65 VuoJson_getObjectValue(VuoText, js, "name", NULL),
66 VuoJson_getObjectValue(VuoText, js, "path", NULL)
67 };
68}
69
74{
75 json_object *js = json_object_new_object();
76
77 json_object *matchTypeObject = json_object_new_string(VuoSerialDevice_getStringForMatchType(value.matchType));
78 json_object_object_add(js, "matchType", matchTypeObject);
79
80 if (value.name)
81 {
82 json_object *o = VuoText_getJson(value.name);
83 json_object_object_add(js, "name", o);
84 }
85
86 if (value.path)
87 {
88 json_object *o = VuoText_getJson(value.path);
89 json_object_object_add(js, "path", o);
90 }
91
92 return js;
93}
94
99{
100 if (valueA.matchType != valueB.matchType)
101 return false;
102
103 if (!VuoText_areEqual(valueA.name, valueB.name))
104 return false;
105
106 if (!VuoText_areEqual(valueA.path, valueB.path))
107 return false;
108
109 return true;
110}
111
116{
117 return VuoText_isLessThan(valueA.name, valueB.name);
118}
119
130{
131 // Already have a path; nothing to do.
132 if (device.matchType == VuoSerialDevice_MatchPath)
133 {
134 realizedDevice->matchType = device.matchType;
135 realizedDevice->name = VuoText_make(device.name);
136 realizedDevice->path = VuoText_make(device.path);
137 return true;
138 }
139
140 // Otherwise, try to find a matching name.
141
143 VuoRetain(devices);
144
145 unsigned long deviceCount = VuoListGetCount_VuoSerialDevice(devices);
146 if (deviceCount == 0)
147 {
148 VUserLog("Warning: No serial devices found.");
149 VuoRelease(devices);
150 return false;
151 }
152
153 VuoText nameToMatch = "";
154 if (device.name)
155 nameToMatch = device.name;
156
157 VuoText foundName = NULL;
158 VuoText foundPath = NULL;
159 for (unsigned long i = 1; i <= deviceCount; ++i)
160 {
162 if (strstr(d.name, nameToMatch))
163 {
164 foundName = d.name;
165 foundPath = d.path;
166 break;
167 }
168 }
169
170 if (foundPath)
171 {
172 realizedDevice->matchType = VuoSerialDevice_MatchPath;
173 realizedDevice->name = VuoText_make(foundName);
174 realizedDevice->path = VuoText_make(foundPath);
175 VuoRelease(devices);
176 return true;
177 }
178
179 VUserLog("Warning: Didn't find a serial device matching '%s'.", device.name);
180 VuoRelease(devices);
181 return false;
182}
183
188{
189 VuoSerialDevice realizedDevice;
190 if (VuoSerialDevice_realize(value, &realizedDevice))
191 {
192 VuoSerialDevice_retain(realizedDevice);
193 char *outputText = VuoText_format("<b>Name:</b> <code>%s</code><br><b>URL:</b> <code>%s</code>", realizedDevice.name, realizedDevice.path);
194 VuoSerialDevice_release(realizedDevice);
195 return outputText;
196 }
197 return strdup("Unknown device");
198}