1
1
#include " module.h"
2
2
#include " sow.h"
3
3
4
+ using namespace __MODULE__ ;
5
+
4
6
extern " C" {
5
7
8
+ // Most checks are skipped since the json schema is validated before running this.
9
+ // So structure is assumed to be enforced.
6
10
static void tjs_obj2cfg (JSContext *ctx, JSValue obj, cfg_serial *cfg) {
7
- /* JSValue parity = JS_GetPropertyStr(ctx, obj, "parity");
8
- if (!JS_IsUndefined(parity)){
9
- JS
10
- JSToCString(ctx, &cfg->parity, family);
11
+ {
12
+ JSValue value = JS_GetPropertyStr (ctx, obj, " parity" );
13
+ const char * buffer;
14
+ if (!JS_IsUndefined (value)){
15
+ buffer = JS_ToCString (ctx, value);
16
+ if (strcmp (" enabled" ,buffer)==0 ) cfg->parity = feature_t ::ENABLED;
17
+ else if (strcmp (" disabled" ,buffer)==0 ) cfg->parity = feature_t ::DISABLED;
18
+ JS_FreeCString (ctx, buffer);
19
+ }
20
+ JS_FreeValue (ctx, value);
21
+ }
22
+
23
+ {
24
+ JSValue value = JS_GetPropertyStr (ctx, obj, " bits" );
25
+ uint32_t buffer;
26
+ if (!JS_IsUndefined (value)){
27
+ JS_ToUint32 (ctx, &buffer, value);
28
+ cfg->bits = static_cast <bits_t >((uint8_t )buffer-5 );
29
+ }
30
+ JS_FreeValue (ctx, value);
11
31
}
12
- JS_FreeValue(ctx, parity);
13
32
14
- JSValue socktype = JS_GetPropertyStr(ctx, obj, "socktype");
15
- if (!JS_IsUndefined(socktype))
16
- JS_ToInt32(ctx, &ai->ai_socktype, socktype);
17
- JS_FreeValue(ctx, socktype);
18
33
19
- JSValue protocol = JS_GetPropertyStr(ctx, obj, "protocol");
20
- if (!JS_IsUndefined(protocol))
21
- JS_ToInt32(ctx, &ai->ai_protocol, protocol);
22
- JS_FreeValue(ctx, protocol);
23
- */
34
+ {
35
+ JSValue value = JS_GetPropertyStr (ctx, obj, " stop" );
36
+ uint32_t buffer;
37
+ if (!JS_IsUndefined (value)){
38
+ JS_ToUint32 (ctx, &buffer, value);
39
+ cfg->stop = static_cast <stop_t >((uint8_t )buffer-1 );
40
+ }
41
+ JS_FreeValue (ctx, value);
42
+ }
43
+
44
+ {
45
+ JSValue value = JS_GetPropertyStr (ctx, obj, " hardware_flow" );
46
+ const char * buffer;
47
+ if (!JS_IsUndefined (value)){
48
+ buffer = JS_ToCString (ctx, value);
49
+ if (strcmp (" enabled" ,buffer)==0 ) cfg->hardware_flow = feature_t ::ENABLED;
50
+ else if (strcmp (" disabled" ,buffer)==0 ) cfg->hardware_flow = feature_t ::DISABLED;
51
+ JS_FreeCString (ctx, buffer);
52
+ }
53
+ JS_FreeValue (ctx, value);
54
+ }
24
55
25
56
{
26
57
JSValue value = JS_GetPropertyStr (ctx, obj, " vtime" );
@@ -37,7 +68,7 @@ static void tjs_obj2cfg(JSContext *ctx, JSValue obj, cfg_serial *cfg) {
37
68
uint32_t buffer;
38
69
if (!JS_IsUndefined (value)){
39
70
JS_ToUint32 (ctx, &buffer, value);
40
- cfg->vtime = (uint8_t )buffer;
71
+ cfg->vmin = (uint8_t )buffer;
41
72
}
42
73
JS_FreeValue (ctx, value);
43
74
}
@@ -50,7 +81,7 @@ static void tjs_obj2cfg(JSContext *ctx, JSValue obj, cfg_serial *cfg) {
50
81
}
51
82
52
83
{
53
- JSValue value = JS_GetPropertyStr (ctx, obj, " ispeed " );
84
+ JSValue value = JS_GetPropertyStr (ctx, obj, " ospeed " );
54
85
if (!JS_IsUndefined (value))
55
86
JS_ToUint32 (ctx, &cfg->ospeed , value);
56
87
JS_FreeValue (ctx, value);
@@ -73,7 +104,7 @@ static JSValue tjs___MODULE___configure(JSContext *ctx, JSValue this_val, int ar
73
104
74
105
tjs_obj2cfg (ctx,argv[1 ],&cfg);
75
106
76
- int fd = __MODULE___configure (name,cfg);
107
+ int fd = configure (name,cfg);
77
108
if (fd==-1 ) return JS_ThrowPlainError (ctx, " Unable to open file [%s] as serial" , name);
78
109
return JS_NewInt32 (ctx,fd);
79
110
}
0 commit comments