Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues #34 #35

Merged
merged 30 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
03c1a19
new dan2 and new dai profile
JasonChenGt Feb 22, 2021
12d7f35
new dan2 and dai
JasonChenGt Feb 25, 2021
28e6460
Update context.js
JasonChenGt Mar 2, 2021
9522f2e
add new line at end of file
JasonChenGt Mar 2, 2021
1d2e18b
change module name to iottalkjs
JasonChenGt Mar 3, 2021
f5bddc5
dan: check whether the online message is published
JasonChenGt Mar 8, 2021
127de63
new Dummy Device example
JasonChenGt Mar 9, 2021
67c85c1
Update index.html
JasonChenGt Mar 9, 2021
e810755
Update index.js
JasonChenGt Mar 9, 2021
6d19044
add exceptions
JasonChenGt Mar 9, 2021
19800bf
rewrite dai
JasonChenGt Mar 10, 2021
ac1a6e9
rename dan.js
JasonChenGt Mar 16, 2021
d0a1eba
change the interval unit to seconds
JasonChenGt Mar 16, 2021
fb1ca00
change coding style
JasonChenGt Mar 17, 2021
9e8e91a
rewrite dan
JasonChenGt Mar 17, 2021
4767273
remove old version callback
JasonChenGt Mar 23, 2021
7c5372f
change register arguments
JasonChenGt Mar 28, 2021
092ccf5
change register arguments
JasonChenGt Mar 30, 2021
204fdda
check if document exists
JasonChenGt Mar 30, 2021
4622132
remove new Promise
JasonChenGt Apr 8, 2021
6366062
subscribe return Promise
JasonChenGt Apr 8, 2021
7382e93
use promise in on_connect()
JasonChenGt Apr 9, 2021
768fa7c
return reject in promise
JasonChenGt Apr 10, 2021
f6c68a9
remove disconnect info
JasonChenGt Apr 10, 2021
99237ab
use df function in df_list
JasonChenGt Apr 10, 2021
0d69e86
Dummy Device
JasonChenGt Apr 11, 2021
bc496b0
use Array.isArray in parse_df_profile()
JasonChenGt Apr 12, 2021
8e2bf31
change ida to sa
JasonChenGt Apr 12, 2021
576f495
use df_func_name() in parse_df_profile()
JasonChenGt Apr 12, 2021
afbcb08
Update index.html
JasonChenGt Apr 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/Dummy_Device/js/ida.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ $(function () {
'device_addr': 'c96ca71c-9e48-2a23-2868-acb420a2f105',
'device_name': 'Dummy',
'persistent_binding': true,
'idf_list': [['Dummy_Sensor', ['int']]],
'odf_list': ['Dummy_Control'],
'df_function_list': [Dummy_Sensor, Dummy_Control],
'idf_list': [[Dummy_Sensor, ['int']]],
'odf_list': [Dummy_Control],
'push_interval': 0,
'interval': {
'Dummy_Sensor': 1.5,
'Dummy-Sensor': 1.5,
JasonChenGt marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down
20 changes: 8 additions & 12 deletions src/dai.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export default class {
}

push_data(df_name) {
iblislin marked this conversation as resolved.
Show resolved Hide resolved
if (this.device_features[df_name].push_data == null)
if (this.device_features[this.df_func_name(df_name)].push_data == null)
return;
let _df_interval = this.interval[df_name] != undefined ? this.interval[df_name] : this.push_interval;
console.debug(`${df_name} : ${this.flags[df_name]} [message / ${_df_interval} s]`);
let _push_interval = setInterval(() => {
let _data = this.device_features[df_name].push_data();
let _data = this.device_features[this.df_func_name(df_name)].push_data();
if (!this.flags[df_name]) {
clearInterval(_push_interval);
return;
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class {

on_data(df_name, data) {
try {
this.device_features[df_name].on_data(data);
this.device_features[this.df_func_name(df_name)].on_data(data);
} catch (err) {
console.error(err);
return false;
Expand Down Expand Up @@ -174,24 +174,20 @@ export default class {
let param_type;
let on_data;
let push_data;
if (typeof option[`${typ}_list`][i] === 'string') {
df_name = option[`${typ}_list`][i];
if (typeof option[`${typ}_list`][i] === 'function') {
df_name = option[`${typ}_list`][i].name;
param_type = null;
on_data = push_data = option[`${typ}_list`][i];
}
else if (typeof option[`${typ}_list`][i] === 'object' && option[`${typ}_list`][i].length == 2) {
JasonChenGt marked this conversation as resolved.
Show resolved Hide resolved
df_name = option[`${typ}_list`][i][0];
df_name = option[`${typ}_list`][i][0].name;
param_type = option[`${typ}_list`][i][1];
on_data = push_data = option[`${typ}_list`][i][0];
}
else {
throw new RegistrationError(`Invalid ${typ}_list, usage: [df_name, ...] or [[df_name, type], ...]`);
JasonChenGt marked this conversation as resolved.
Show resolved Hide resolved
}

option['df_function_list'].forEach(df_function => {
if (this.df_func_name(df_name) == df_function.name) {
on_data = push_data = df_function;
}
});

let df = new DeviceFeature({
'df_name': df_name,
'df_type': typ,
Expand Down