mirror of
https://github.com/chirpstack/chirpstack.git
synced 2024-12-18 20:57:55 +00:00
ui: Update codec template with JSDoc (#473)
This commit is contained in:
parent
eda6646b18
commit
7158c0c610
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user