• For Bangle 1 someone wrote this code - but I think the format is different for this chip.

    function writeGPScmd(cmd) {
      var d = [0xB5,0x62]; // sync chars
      d = d.concat(cmd);
      var a=0,b=0;
      for (var i=2;i<d.length;i++) {
        a += d[i];
        b += a;
      }
      d.push(a&255,b&255);
      console.log(d);
      Serial1.write(d);
    }
    

    Also the DATASHEET has a different checksum method.

    The checksum is the word-by-word of all data from field 2 to field 5 (including field 2 and >field 5) (1 word includes 4(Bytes) cumulative sum, occupying 4 bytes. The calculation of the >check value can follow the following algorithm:

    ckSum = (class << 24) + (id << 16) + len;
    
    for (i = 0; i <(len / 4); i++){
      ckSum = ckSum + payload [i];
    }
    

    Has anyone implemented this function so that you can send the CAS commands without having to work out the checksum by hand all the time.

  • Has anyone implemented this function so that you can send the CAS commands without having to work out the checksum by hand all the time.

    yes, I've done.

    AT6558.prototype.checksum = function(val) {
      var cs = 0;
      for (const c of val) {
        cs = cs ^ c.charCodeAt(0); //XOR
      }
      return cs.toString(16).toUpperCase().padStart(2­, '0');
    };
    
    AT6558.prototype.sendCommand = function(command) {
      cmd = "P" + command;
      cs = this.checksum(cmd);
      cmd = "$" + cmd + "*" + cs;
      print(cmd);
      Serial1.println(cmd);
    };
    
    AT6558.prototype.setBaudRate = function(v) {
      var br = "";
      switch (v) {
        case 4800:
          br = "0";
          break;
        case 9600:
          br = "1";
          break;
        case 19200:
          br = "2";
          break;
        case 38400:
          br = "3";
          break;
        case 57600:
          br = "4";
          break;
        case 115200:
          br = "5";
          break;
        default:
          return;
      }
      this.baudRate = v;
      sendCommand("CAS01," + br);
    };
    
    
    
About

Avatar for HughB @HughB started