ADVANCED: gsmIncomingPDU (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


This function block can be used to check whether there is an incoming SMS PDU binary message from the cellular network or over the RTCU Communication Hub.

 

The device has a buffer where SMS and PDU messages are stored. To prevent loss of any messages, this buffer can only contain one message at a time.

Since this buffer is shared between SMS and PDU messages, it is possible if an SMS message is received and no instance of the gsmIncomingSMS is present in the application that this incoming SMS message will block the possibility of other other PDU messages arriving. Because of this, it is recommended to have an instance of the gsmIncomingSMS even if the application is not normally expecting SMS messages.
 

The buffer will not be filled until either gsmIncomingSMS or gsmIncomingPDU is called.

 

A PDU message sent from the RTCU IDE (or any other RACP-compliant peer) that uses a cable or data connection will be delivered to the application with the "phone number" set to "9999". See also gsmSendPDU.

 

Messages received through the RTCU Communication Hub will have the "phone number" set to the node number of the originating node prefixed with "@" (e.g. "@3917321112").

 

Note: the phone book on the used SIM card must be empty. If a caller that is present in the phone book sends an SMS message, this message will not be delivered to the program.

 

Input:

message : PTR

Address of a variable where the message from the sender should be delivered to (only if status is 1 or 2). Please make sure that the size of the variable is big enough to accommodate the biggest SMS message that can be received which in PDU mode is 140 bytes. This variable must be set before the gsmIncomingPDU instance is called the first time.

 

Please note that if a TEXT type SMS message is received and no instance of the gsmIncomingSMS is present in the application, this incoming TEXT SMS message will block for other PDU SMS messages to arrive. Because of this, it is a good idea to have an instance of the gsmIncomingSMS, even if your application is not expecting TEXT SMS messages.

 

 

Output:

status : INT (0..4)

0

If no message.

1

If message with caller id. ("number" contains caller id).

2

If message without caller id.

3

If the message receive buffer is not set (see message input above).

4

If unsupported data coding scheme is received.

 

phonenumber : STRING

Caller id of the sender (if status is 1).

 

If the number is prefixed with an "@", the message is received through the RTCU Communication Hub and the number after the "@" character is the originating node number (only supported on network-enabled devices).

 

The "phone number" will be set to "9999" for messages sent from the RTCU IDE (or any other RACP-compliant peer).

 

length : INT

Number of bytes received in the SMS PDU message.

 

Declaration:

FUNCTION_BLOCK gsmIncomingPDU;
VAR_INPUT
  message     : PTR;
END_VAR;
VAR_OUTPUT
  status     : INT;  
  phonenumber : STRING;
  length     : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
 
VAR
  incoming : gsmIncomingPDU;
  buffer   : ARRAY[0..139] OF SINT;
END_VAR;
 
// Set address BEFORE the 'incoming' is called the first time ! (In this case, by BEGIN)
incoming.message := ADDR(buffer);
 
BEGIN
  incoming();
  ...
  // Check for incoming calls with a callerid
  // NOTE: it is not enough to check if the '.status' is bigger than 0, as the code 3 is an error, see above
  IF incoming.status = 1 THEN
     // Somebody with a callerid has sent us a SMS message
     // Set the current write position to 1,1 (leftmost, first row)
    displayXY(x:=1, y:=1);
     // Print the received callerid in the display
    displayString(message:=incoming.phonenumber);
     // Set the current write position to 1,2 (leftmost, second row)
    displayXY(x:=1, y:=2);
     // Print the value of the first byte in the received SMS message in the display
    displayString(message:=strFormat(format:="\1", v1:=buffer[0]));
     ...
  END_IF;
 
END;
 
END_PROGRAM;