librpipTransactionMsgVarAdd

uint32_t librpipTransactionMsgVarAdd(struct librpip_tx* t, uint8_t dir, char var);

Description

Adds a variable message segment to a transaction. A variable message segment is used when the data to be sent/received is not known at transaction creation time or varies through the life of the transaction. An example would be writing characters to a LCD display.

Note that the corrosponding function librpipTransactionMsgVarSet() must be used at least once before the transaction can be sent. Transactions containing unpopulated variable segments will be ignored if attempted to send.

Parameters

  • struct librpip_tx* t
    A pointer to a transaction that is to be sent. This will have been created from a previous librpipTransactionCreate().
  • uint8_t dir
    The direction of the message. This should be passed as one of the LIBRPIP_TX_MSG_* constants. Note that only SPI transactions support LIBRPIP_TX_MSG_TXRX (simultaneous transmit and receive) messages. This is the nature of SPI.
  • char var
    The variable name. This needs to be supplied when librpipTransactionMsgVarSet() is used. It needs to be unique within the transaction only. It can be any char you like. It remains to be seen if a single char is too small to hold all the variables needed in a single transaction.

Returns

0 on failure or 1 on success.

Example

Create a transaction to write to a LCD display over I2C:

uint8_t cmd;
struct librpip_tx* WriteLCD;
WriteLCD=librpipTransactionCreate(LIBRPIP_TX_MODE_I2C, 8);
cmd=0b10000000;         
librpipTransactionMsgAdd(WriteLCD, LIBRPIP_TX_MSG_TX, &cmd, 1);
librpipTransactionMsgVarAdd(WriteLCD, LIBRPIP_TX_MSG_TX, '1');
cmd=0b11000000;         
librpipTransactionMsgAdd(WriteLCD, LIBRPIP_TX_MSG_TX, &cmd, 1);
librpipTransactionMsgVarAdd(WriteLCD, LIBRPIP_TX_MSG_TX, '2');


librpipTransactionMsgVarSet(WriteLCD, '1', "Hello - LCD line 1  ", 20);
librpipTransactionMsgVarSet(WriteLCD, '2', "Hello - LCD line 2  ", 20);
librpipTransactionSend(WriteLCD, 0, 0x31);

sleep(10);

librpipTransactionMsgVarSet(WriteLCD, '1', "Something different ", 20);
librpipTransactionMsgVarSet(WriteLCD, '2', "Is on the LCD now   ", 20);
librpipTransactionSend(WriteLCD, 0, 0x31);

librpipTransactionDestroy(WriteLCD); 
librpipClose();