ui: Update codec template with JSDoc (#473)

This commit is contained in:
Bernd Storath 2024-08-05 12:17:13 +02:00 committed by GitHub
parent eda6646b18
commit 7158c0c610
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 63 deletions

View File

@ -24,37 +24,39 @@ function CreateDeviceProfileTemplate() {
});
};
const codecScript = `// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
function decodeUplink(input) {
return {
data: {
temp: 22.5
}
};
}
// Encode downlink function.
//
// Input is an object with the following fields:
// - data = Object representing the payload that must be encoded.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - bytes = Byte array containing the downlink payload.
function encodeDownlink(input) {
return {
bytes: [225, 230, 255, 0]
};
}
`;
const codecScript = `/**
* Decode uplink function
*
* @param {object} input
* @param {number[]} input.bytes Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
* @param {number} input.fPort Uplink fPort.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{data: object}} Object representing the decoded payload.
*/
function decodeUplink(input) {
return {
data: {
// temp: 22.5
}
};
}
/**
* Encode downlink function.
*
* @param {object} input
* @param {object} input.data Object representing the payload that must be encoded.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{bytes: number[]}} Byte array containing the downlink payload.
*/
function encodeDownlink(input) {
return {
// bytes: [225, 230, 255, 0]
};
}
`;
const deviceProfileTemplate = new DeviceProfileTemplate();
deviceProfileTemplate.setPayloadCodecScript(codecScript);

View File

@ -30,38 +30,39 @@ function CreateDeviceProfile(props: IProps) {
});
};
const codecScript = `// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - recvTime = Uplink message timestamp as Date object.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
function decodeUplink(input) {
return {
data: {
temp: 22.5
}
};
}
// Encode downlink function.
//
// Input is an object with the following fields:
// - data = Object representing the payload that must be encoded.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - bytes = Byte array containing the downlink payload.
function encodeDownlink(input) {
return {
bytes: [225, 230, 255, 0]
};
}
`;
const codecScript = `/**
* Decode uplink function
*
* @param {object} input
* @param {number[]} input.bytes Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
* @param {number} input.fPort Uplink fPort.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{data: object}} Object representing the decoded payload.
*/
function decodeUplink(input) {
return {
data: {
// temp: 22.5
}
};
}
/**
* Encode downlink function.
*
* @param {object} input
* @param {object} input.data Object representing the payload that must be encoded.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{bytes: number[]}} Byte array containing the downlink payload.
*/
function encodeDownlink(input) {
return {
// bytes: [225, 230, 255, 0]
};
}
`;
const deviceProfile = new DeviceProfile();
deviceProfile.setPayloadCodecScript(codecScript);