I2C processor

Hello,
Is it possible to add processor for individual components of I2C packet with the latest API/FW? I've tried to do it in 1.2.5 version and got "the only available process is a counter" error.
Thank you in advance

Comments

  • edited November 2017
    What do you mean by "individual components of I2C packet"?

    The latest SDK will allow you to use data processing with I2C data but it is untested and the behavior is undefined.
  • Thanks, Eric.
    I mean the specific bytes in the packet. I would need to take let's say bytes 4 and 5 out of 12 bytes packet and perform comparison.
  • No, the API does not support data splitting / offsets within the context of data processing.  You would have to adjust your I2C read to only retrieve bytes 4 and 5.
  • ok, makes sense. So I will have to readout complete 12 bytes for logging and also read out specific bytes to implement the logic. But I would be able to have Math processor on those 2 bytes of I2C data to left-right shift them, correct?
  • edited December 2017
    You should be able to, yes.
  • edited December 2017
    I've started migrating to API 3+. I'm struggling setting up data route on the I2C read output.
    In documentation it should be with i2c interface of SerialPassthrough.
    Do you have a code example how to do it?
    Analog of 2.8:
    i2cModule.routeData().fromId((byte) 8, I2CROUTE_ID)
    .log("i2c_log")
    .commit()
    Thank you in advance
  • Thanks, Eric, managed that.
    The comparator is working nicely on 2 bytes short read out from I2C sensor with little endian notation. My other sensor is big endian and here I need to swap the bytes (see code below) before comparator.
    In the swapped output the data.bytes()[0] always comes out zero. 
    I'm new to 3+ data processors so it might be I'm doing something wrong.

    .multicast()
    .to()
    .stream(new Subscriber() {
    @Override
    public void apply(Data data, Object... env) {
    Log.i("test", "Original = " + data.bytes()[0] + " " + data.bytes()[1]);
    }
    })
    .to()
    .map(Function2.RIGHT_SHIFT, 8)
    .map(Function2.MODULUS, 256) // & 0xFF
    .buffer().name("lowbyte")

    .to()
    .map(Function2.MODULUS, 256) // & 0xFF
    .map(Function2.LEFT_SHIFT, 8)
    .map(Function2.ADD,"lowbyte")
    .stream(new Subscriber() {
    @Override
    public void apply(Data data, Object... env) {
    Log.i("test", "Swapped = " + data.bytes()[0] + " " + data.bytes()[1]);
    }
    })

  • Remove the buffer component.


  • Thanks, again, Eric. Worked as expected. Comparator works, the only annoyance is that I can not cast it to Integer for printing in Log. Printing data directly gives me 4 bytes of data, but I can work with this.
This discussion has been closed.