Shop OBEX P1 Docs P2 Docs Learn Events
PropGCC concantenate ? — Parallax Forums

PropGCC concantenate ?

RsadeikaRsadeika Posts: 3,837
edited 2018-04-17 16:43 in Propeller 1
Since I just purchased a FLiP module, I decided to write a diagnostic program for my Roomba 510. I noticed that in the OI manual, for the Roomba, a lot of the commands provide 2 data bytes of information, some are unsigned and some are signed.

I get the part where I have to use the fdserialRX() to capture the two bytes, but how do I combine the two bytes to have one variable. On an Internet search a lot of suggestions refer to the use of concat(), merge(), and others. That is all fine, but PropGCC does not support those commands. So, what is available, in PropGCC, to concatenate two data bytes?

Ray

Comments

  • Heater.Heater. Posts: 21,230
    edited 2018-04-17 16:29
    Something like:
    #include <stdint.h>
    
    int16_t result;    // Or uint16_t
    ...
    Get the bytes...
    ...
    result = (highByte << 8 ) + lowByte;
    ...
    

  • pmrobertpmrobert Posts: 675
    edited 2018-04-17 16:22
    Disregard...
  • Something odd seems to have happened to your right paren and or operator. Did you quote those as code?
  • Heater.Heater. Posts: 21,230
    edited 2018-04-17 16:28
    Same thing happened in my post. Code tags don't help. It's just the forum software corrupting ones posts. As it does for things like 8). Which is "8" followed by ")". Appalling behaviour.
  • Heater. wrote: »
    Same thing happened in my post. Code tags don't help. It's just the forum software corrupting ones posts. As it does for things like 8). Which is "8" followed by ")". Appalling behaviour.
    You would think it would inhibit that sort of substitution when within a code section.

  • Heater.Heater. Posts: 21,230
    edited 2018-04-17 16:36
    I would think it's a duty of a computer program not to corrupt data at random.

    For example, outside of a code section I have sometimes made lists:

    1) ...
    2) ...
    ...
    8) ...
    9) ...

    There is no excuse for intentionally buggering that up!
  • Below is the function that I put together, the problem is that the function just hangs when I run it. I think it might be that the fdserialRx() is missing the incoming data and just waiting? But I am not sure. I guess this function will have to become more elaborate with some code to test for the receiving of the data bytes.

    Thank you for the suggestions.

    Ray
    void CRvolts()
    {
      unsigned int vvalh;
      unsigned int vvall;
      unsigned int vval2;
      CRstart();
      CRsafe();    // Put in OI mode
      fdserial_txChar(roomba,142);
      fdserial_txChar(roomba,24);
      pause(100);
      vvalh = fdserial_rxChar(roomba);  // Get the high byte
      pause(100);
      vvall = fdserial_rxChar(roomba);  // Get the low byte
    
      vval2 = (vvalh << 8) + vvall;     // Concantenate
      print("%d\n",vval2);
      //print("%d%d\n",vvalh,vvall);
      CRstart();
    }     
    
    
  • Heater.Heater. Posts: 21,230
    Anyway, Rsadeika, think if it like this:

    You have two bytes, each of which 8 bits and can therefore represent unsigned integers from 0 to 255.

    But we know that one of the bytes is the high byte of a 16 bit number, so it really represents numbers 256 to 65535.

    So all we have to do in multiply the high byte by 256 and add the low byte:
    result = (highByte * 256) + lowByte;
    

    But a multiply by 256 is the same as shifting the bits left by 8 places:
    result = (highByte << 256) + lowByte;
    

    That shift is faster than a multiply.

    All this is the same as in decimal. The number 34 is (3 * 10) + 4


    It works out for signed numbers as well.

  • dgatelydgately Posts: 1,630
    edited 2018-04-17 17:40
    Rsadeika wrote: »
    void CRvolts()
    {
    ...
      vvalh = fdserial_rxChar(roomba);  // Get the high byte
      pause(100);
      vvall = fdserial_rxChar(roomba);  // Get the low byte
    ...
    }     
    
    

    You probably want to use something like: checkVal = fdserial_rxReady(roomba) to check that there is a byte of data available, before any fdserial_rxChar(roomba) function calls. OR, use: someVal = fdserial_rxTime(roomba, someMillisecondsToWaitVal), which will get a byte from the receive buffer if available, or wait for up to timeout ms to receive a byte.

    dgately
  • Interesting problem. I had my FLiP module connected to the Roomba, and with volts function working correctly, it is putting out a correct value. After connecting an AB WX with an active WX module, and running the volts function, it was putting out a 0.00 value.

    I am not sure what is going on with the AB WX, the program should be showing the same value as the FLiP module was showing. I have the AB WX drawing power from the Roomba, at the din plug. When I apply the CSstart() and CSsafe() to the Roomba, it does put the Roomba into the OI mode, so that shows that the Roomba is getting and responding to commands sent.

    On the AB WX I am using P0 and P1 for the serial connections. Since it looks like an Rx problem, I am starting to wonder if having the WX module active, it is having an affect on the fdserialRx() function? Or should I be using anything but the P0 and P1 for the serial connections?

    Ray

  • As a quick experiment, I used P2 and P3 on the AB WX, and now the volts function seems to be working correctly. So, now I am wondering if I got a bad P0 or P1 on my AB WX. I guess now I have to do some diagnostics on my AB WX. I just got this board last week, so it is a new board that I am working with.

    Ray
  • Heater.Heater. Posts: 21,230
    I'm lost.

    What is an AB WX with an active WX module?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2018-04-17 21:06
    heater wrote:
    For example, outside of a code section I have sometimes made lists:
    6)
    7)
    8)
    9)

    I don't see the problem. :)

    -Phil
  • Heater.Heater. Posts: 21,230
    edited 2018-04-17 21:07
    OK Phil, how did you do that?

    If I cut and paste your post I get this:

    6)
    7)
    8)
    9)


    Such corruption of user input is intolerable.



  • AB WX is an Activity Board WX. It has the WiFi connectivity providing you have the WX (WiFi) module plugged in.

    Ray
  • I put a boldface not-boldface between the 8 and the ). (Of course, I can't just put those bbcodes here to demonstrate, because the forum software doesn't support [noparse] either. Grr!)

    -Phil
  • Heater.Heater. Posts: 21,230
    Yeah, I was just looking at the page source. You list comes out as:

    6)<br />
    7)<br />
    8<b></b>)<br />
    9)<br />

    This is the insanity of the web.

  • I had originally P0 -> Rx and P1 -> Tx, that is where I had the fdserialRx() problem. I went ahead and made a switch, P1 -> Rx and P0 -> Tx, now the fdserialRx() seems to be working as expected. It seems to be narrowing down too, Rx does not work on P0, Tx seems too work on P0. Is this a software or hardware or both, problem?

    Ray
  • kwinnkwinn Posts: 8,697
    Heater. wrote: »
    Yeah, I was just looking at the page source. You list comes out as:

    6)<br />
    7)<br />
    8<b></b>)<br />
    9)<br />

    This is the insanity of the web.

    Anyone else think fluff like emoticons and other such nonsense should be removed from the web?
  • Heater.Heater. Posts: 21,230
    edited 2018-04-18 00:18
    kwinn,

    As old as I am I can handle the idea of emoji and other such fluff.

    After all, for better or worse, they are encoded into Unicode.

    What I do violently object to is the corruption of one's text into something one did not write. Computers should not corrupt data.

    That is just 💩


    Edit: The last character of that last line is also corrupt. What I actually typed was "& # 1 2 8 1 6 9 ;"

    Without all the spaces in it of course.

  • kwinnkwinn Posts: 8,697
    Heater. wrote: »
    kwinn,

    As old as I am I can handle the idea of emoji and other such fluff.

    After all, for better or worse, they are encoded into Unicode.

    What I do violently object to is the corruption of one's text into something one did not write. Computers should not corrupt data.

    That is just 💩


    Edit: The last character of that last line is also corrupt. What I actually typed was "& # 1 2 8 1 6 9 ;"

    Without all the spaces in it of course.

    No argument from me on the data corruption aspect. I really liked the WYSIWYG word processors when they came along. Unfortunately lately they seem to have become WYSIWYMG, and I like to to get what I see all the time, not most of the time.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2018-04-18 03:15
    Anyone else think fluff like emoticons and other such nonsense should be removed from the web?
    Seriously? Hell no! It's all part of the fun.

    The only thing that needs to be fixed is the freaking forum software that's been dysfunctional since 2015.

    -Phil
  • Keep the emojis. I have come to like them. They are most fun when conversing with other, colorful, emotional people. Definite win.
Sign In or Register to comment.