-
Notifications
You must be signed in to change notification settings - Fork 311
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
Add recvTime to uplink decoder input #7474
Conversation
f519eb0
to
632b8e6
Compare
But what is the type of Can you return another standard |
The type of If I do
There is a note about the conversion of the time in the goja docs. The time is not directly converted from the Go time.Time to JS Date because Date doesn't keep location info and the time.Time zone will be lost. I also tried what is suggested in the note for the conversion of the time, that is: function decodeUplink(input) {
var data = {};
data.recvTime = new Date(input.recvTime.unixNano()/1e6);
return {
data: data,
};
} or if I simply return a Date object like this: function decodeUplink(input) {
var data = {};
data.recvTime = new Date();
return {
data: data,
};
} Still, I get the same error This works indeed: function decodeUplink(input) {
var data = {};
data.now = Date()
return {
data: data,
};
} but Date() called as a function and not as a constructor returns a string instead of a Date object. Going back to converting the time.Time output, it seems to have a correct format before being converted to a Struct proto:
I added a special case for time.Time processing in goproto.Struct that converts it to a string instead of a struct, which seems to work. The issue with this is converting from map to struct works, but going the other way around there isn't anything that marks the string as a time and when calling the struct to map converter (which I guess they should be mirrored) it will return the string representation instead of time.Time. |
e03423c
to
993d6ff
Compare
Then I suggest the following:
|
993d6ff
to
684bcdb
Compare
done, tested it with the test decoder: function decodeUplink(input) {
var data = {};
data.recvTime = input.recvTime;
data.recvTimeStr = input.recvTime.toString();
data.recvTimeType = input.recvTime.constructor.name;
return {
data: data
};
} Decoded test payload: {
"recvTime": 0,
"recvTimeStr": "Thu Jan 01 1970 02:00:00 GMT+0200 (EET)",
"recvTimeType": "Date"
} Complete uplink data: {
"f_port": 1,
"frm_payload": "AA==",
"decoded_payload": {
"recvTime": 0,
"recvTimeStr": "Thu Jan 01 1970 02:00:00 GMT+0200 (EET)",
"recvTimeType": "Date"
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "test"
},
"rssi": 42,
"channel_rssi": 42,
"snr": 4.2
}
],
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 7
}
},
"frequency": "868000000"
}
} I'll do an end to end test too. |
684bcdb
to
74d0af3
Compare
Summary
References #7467.
Changes
Testing
Steps
Results
Decoded test payload:
Complete uplink data:
Regressions
None.
Notes for Reviewers
There is something really odd happening when trying to access the input directly. If I change this line from the decodeUplink function:
to this:
I get a panic with the following message: reflect.Value.Interface: cannot return value obtained from unexported field or method, that's triggered by this piece of code:
I believe it's something related to conversion of the decoder output:
I'll see how it can be avoided.
EDIT: it seems like this comes from the goproto.Struct not being able to handle time.Time. Reflection is applied on the private fields of time.Time, thus the panic. Should goproto.Struct be able to handle time.Time?
Checklist
README.md
for the chosen target branch.CHANGELOG.md
.CONTRIBUTING.md
, there are no fixup commits left.