Avatar for Mrbbp

Mrbbp

Member since Mar 2017 • Last active Apr 2019
  • 15 conversations
  • 99 comments

I'm newb with espruino, not with arduino, not with js...
But i'm not a coding ninja

Most recent activity

    • 8 comments
    • 307 views
  • in JavaScript
    Avatar for Mrbbp

    i've written something like that

    var reponse= {trame:"",longueur:0};
    
    s.setup(9600,{rx:B6, tx:B5});
    s.on('data', function(data) {
      reponse.trame+= data;
      if (reponse.trame.length >= reponse.longueur) {
        switch (reponse.trame.charCodeAt(1)) {
          case 0x01: // status
            console.log("status:",reponse.trame.char­CodeAt(3));
            break;
          case 0x09: // status
            console.log("check Drive:",reponse.trame.charCodeAt(3));
            break;
          case 0x12: //Check the total numbers of audio in all folders(12)
            console.log("nbr total audios:",(reponse.trame.charCodeAt(3)<<8­ ^ reponse.trame.charCodeAt(4)));
            break;
          case 0x0C: //Check the total audios(0C)
            console.log("nbr total audios:",(reponse.trame.charCodeAt(3)<<8­ ^ reponse.trame.charCodeAt(4)));
            break;
          case 0x0D: //current audio
            console.log("nom fichier audio:",reponse.trame.charCodeAt(3),repo­nse.trame.charCodeAt(4));
            break;
          case 0x24: //duration audio
            console.log("Duréé: "+reponse.trame.charCodeAt(3)+"H "+reponse.trame.charCodeAt(4)+"mn "+reponse.trame.charCodeAt(5)+"s");
            break;
          default:
            break;
          }
      }
    });
    

    and each command sent, fill the reponse.longeur with the appropriate value...

    function Duration() {
     var command = [0xAA, 0x24, 0x00, 0xCE];
      // Return: AA 24 03 hour minute second SM
      reponse.longueur = 7;
      reponse.trame = "";
      s.write(command);
    }
    

    Not Tested

    Thanks for your help @allObjects.

  • in JavaScript
    Avatar for Mrbbp

    oh and a simple question about Upper-byte and Lower-Byte

    Return: AA 11 02 Upper-byte Lower-byte SM
    

    to add these upper and lower bytes...

    should i do like this result = upperByte<<8 ^ lowerByte ?

  • in JavaScript
    Avatar for Mrbbp

    i give you an example of a frame

    //Check Playback Status(01)
    //Command: AA 01 00 AB
    let command= [0xAA,0x01,0x00,0xAB];
    s.write(command)
    //Return: AA 01 01 Playback status SuM
    

    if i've read and kept the good part in the gps module, it use an object and fill the "line" until it's more than 80chars or until \n char.

     var gps = {line:""};
      serial.on('data', function(data) {
        gps.line += data;
      });
    

    i do not have this '\n' in the frame module.
    the length is not always the same. between 5 and 7 chars.
    The last char is always a sum of the values sent...
    I could :
    evaluate continiously the frame to know when it is end (the sum)
    or
    evaluate the second char received to determine the length of the frame (the command),
    or
    anticipate the length (5,6,7) of the response by the command sent.

    'Status', send back 5 chars
    'duration of the current audio', send back 7 chars.

    thanks

    i'll try.

  • in JavaScript
    Avatar for Mrbbp

    Hello Markus,
    a Happy new Year.

    i've found that in the forum and it do the job as i expect.

    console.log("hex:",d.charCodeAt().toStri­ng(16));
    

    the module send some char and the last one is the SUM of the transmitted string.
    i wrote something like that (i did not test it on the espruino)

    let sum=0;
    let buf = new Uint8Array();
    
    function checkAnswer(buff) {
      console.log(buff.toString(16));
     switch (buff[1]) {
       case 0x01: // status
         console.log("status:",buff[3]);
         break;
       case 0x0C: //total audios
         console.log("total audios:",buff[3],buff[4]);
         break;
       case 0x0D: //current audio
         console.log("current audio:",buff[3],buff[4]);
         break;
       default:
         break;
      }
      // reset first buffer
      buf = new Uint8Array();
    }
    
    s.setup(9600,{rx:B6, tx:B5});
      s.on('data', function(d) {
        console.log("hex",d.charCodeAt().toStrin­g(16).toUpperCase());
        let nd = d.charCodeAt();
        buf.push(nd);
        sum+= nd;
        if (sum == nd && buf.length >1) {
          // fin de la transmission
          buf.pop(); // efface le sum du buffer
          sum = 0;
          checkAnswer(buf);
        }
      });
    
    

    regards

  • in JavaScript
    Avatar for Mrbbp

    Hello,
    i'm working with Voice module from DFRobot

    if i use an array of command i'm supposed to receive some datas
    i'm trying to convert the data in hexa value...
    when i'm trying .toString(radix), console displays always the same char, not bin or oct or hex value...

    sorry, where i'm wrong?

    s.setup(9600,{rx:A8, tx:B7});
      s.on('data', function(d) {
        console.log(d.toString(2),d.toString(8),­d.toString(16));
      });
    

    it display

    ª ª ª
    $ $ $
    
  • in Pico / Wifi / Original Espruino
    Avatar for Mrbbp

    Hello,

    i find a strange behaviour of the chrome ide with a pico with v2.00 firmware
    If i use a let in a switch case block, IDE generate an error

    Error: Line 15: Unexpected token let
    

    i'm not not sure why it's wrong?
    in an html page with the code it does not generate error
    and for my point of view i could legaly use a let in the block
    if i upload the code in the espruino, it works.
    in a more complexe prog, it generate error in the code and nothing works (i've took some time to understand the prob)
    if i change the let for a var
    no error anymore and code run on the espruino

    let phrase= "";
    function test() {
      let tire = 7;  
      switch (tire) {
        case 7:
          // try a let
          let vTemp = Math.random(); 
          console.log(vTemp);
          break;
        default:
          break;
      }
    }
    
    function onInit() {
      setInterval(test,1000);
    }
    

    is it an error?

    regards

Actions