| ioPAC RTU Controllers C/C++ Sample Code Programming Guide

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Functions
sms_send.c File Reference

Send a SMS Sample More...

`#include <stdio.h>`
`#include <libmoxa_rtu.h>`

## Functions
void | usage (void)
int | main (int argc, char **const argv)

## Detailed Description

Send a SMS Sample

Copyright
  Moxa Inc.

Date
  06-04-2013

Author
  Changfu Hsieh

Version
  V1.0
  Send SMS

    Introduction:
    This sample code shows how to send a SMS by MOXA SMS API.
    Example:
    Execute the sample code to send a SMS to phone number 0912345678: ./sms_send -p0912345678 -c 1234 -m "SMS content"
    Default:
    The default PIN code is 0000.
    The default message is "SMS test".
    Help:

    root@Moxa:/home#./sms_send -h
    Send a SMS

    Usage: ./sms_send [OPTIONS]

    Options:
            -p Phone number
            -c SIM PIN
            -m  SMS content in ASCII
            -u Send message:"SMS test" in UCS2 encoded

Library:
SMS send APIs

## Function Documentation

void usage | ( | void |  | ) |

int main | ( | int | argc,
|  | char **const | argv
| ) |  |

/*******************************************************************************
* Copyright Moxa Inc.
*
* Send a SMS
*
* Date Author Comment
* 06-04-2013 Changfu Hsieh Created.
******************************************************************************/
#include <stdio.h>
#include <libmoxa_rtu.h>
void usage(void)
{
printf("usage:\n\tsms_send -p0911123456 -m\"SMS test message\"\n");
printf("\t-p: Phone number\n");
printf("\t-c: PIN code\n");
printf("\t-m: SMS content in ASCII\n");
printf("\t-u: Send message:\"SMS test\" in UCS2 encoded\n");
}
int main(int argc, char **const argv)
{
INT32 rc;
INT8 msg[161];
INT8 ucsMsg[] = {0x00, 0x53, 0x00, 0x4D, 0x00, 0x53, 0x00, 0x20, 0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74};
INT8 phoneNum[30];
INT8 pinCode[5];
INT8 testUcs2Flag = 0;
memset(msg, 0, sizeof(msg));
//Default SMS content
sprintf(msg, "SMS test");
phoneNum[0] = 0;
//Default SIM PIN
sprintf(pinCode, "0000");
for(;;)
{
rc = getopt(argc, argv, "p:m:huc:");
if(rc == EOF) break;
switch(rc)
{
case 'p':
printf("Send a SMS to phone number:%s\r\n", optarg);
sprintf(phoneNum, optarg);
break;
case 'm':
sprintf(msg, optarg);
break;
case 'u':
testUcs2Flag = 1;//send default UCS2 message
break;
case 'c':
memcpy(pinCode, optarg, 4);
break;
case 'h':
default:
usage();
return -1;
}
}
if(phoneNum[0] == 0)
{
printf("Pleaese use -p to specify a target phone number:\n");
printf("Example: ./sms_send -p 0911035532\n");
return -2;
}
if(testUcs2Flag)
{
//Send Unicode SMS in UCS2 format
rc = MX_RTU_SMS_Send_Ucs2(phoneNum, pinCode, ucsMsg, sizeof(ucsMsg));
printf("MX_RTU_SMS_Send_Ucs2 result:%d\r\n", rc);
}
else
{
//Send SMS by GSM 03.38
rc = MX_RTU_SMS_Send_GSM_7bits_Default_Alphabet(phoneNum, pinCode, msg, strlen(msg));
printf("MX_RTU_SMS_Send_GSM_7bits_Default_Alphabet result:%d\r\n", rc);
}
return rc ;
}