AntonioVillanueva

CODEC JS POUR CHIRPSTACK

May 17th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Codec pour Chirpstack pour traduire Base64 en Hex
  2. function Decode(fPort, bytes) {
  3.     var decoded = {data: bytesToHex(bytes);}
  4.     return decoded;
  5.  
  6. }
  7.  
  8. // Helper function to convert bytes to hexadecimal string
  9. function bytesToHex(bytes) {
  10.     var hexString = '';
  11.     for (var i = 0; i < bytes.length; i++) {
  12.         var hex = bytes[i].toString(16);
  13.         if (hex.length === 1) {
  14.             hex = '0' + hex; // Zero pad single digit hex values
  15.         }
  16.         hexString += hex;
  17.     }
  18.     return hexString.toUpperCase(); // Convert to uppercase if desired
  19. }
  20.  
  21. /* ******************************************
  22.  * The function has the signature Decode(fPort, bytes) and must return an object.
  23.  * ChirpStack Application Server will convert this object to JSON.
  24.  ********************************************/
  25. function Encode(fPort, obj, variables) {
  26.     return [];
  27. }
  28.  
Add Comment
Please, Sign In to add comment