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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Functions
power.c File Reference

Power More...

`#include <libmoxa_rtu.h>`

## Functions
int | main (int argc, char *argv[])

## Detailed Description

Power

Copyright
  Moxa Inc.

Date
  04-10-2013

Author
  Eddy Kao

Version
  V1.0
  Power

    Introduction:
    Power detection with SMS alarm.
    Example:
    1. Print Alarm: ./power
    2. SMS Alarm: ./power -p0912345678 -P0000
    Help:

    root@Moxa:/tmp#./power -h
    Power Alarm program.

    Usage: ./power [OPTIONS]

    Options:
            -p       Phone Number
            -P       PIN Code. Default PIN Code = 0000

Library:
Power APIs

## Function Documentation

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

/*******************************************************************************
* Copyright Moxa Inc.
*
* Power
*
* Date Author Comment
* 04-10-2013 Eddy Kao Created.
******************************************************************************/
#include <libmoxa_rtu.h>
int main(int argc, char *argv[])
{
int retval = 0;
UINT32 rc = 0;
UINT8 state = 0;
char phoneNumberFlag = 0;
INT8 phoneNumber[16];
INT8 pinCode[16];
INT8 alarmMsg[64];
memset(phoneNumber, 0, sizeof(phoneNumber));
memset(pinCode, 0, sizeof(pinCode));
strcpy(pinCode, "0000");
while((retval = getopt(argc, argv, "hp:P:")) != -1)
{
switch(retval)
{
case 'p':
strcpy(phoneNumber, optarg);
phoneNumberFlag = 1;
break;
case 'P':
memset(pinCode, 0, sizeof(pinCode));
strcpy(pinCode, optarg);
break;
case '?':
case 'h':
default:
printf("Power Alarm program.\n\n");
printf("Usage: ./power [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Phone Number\n", "-p");
printf("\t%-8s PIN Code. Default PIN Code = 0000\n", "-P");
printf("\n");
return 0;
}
}
rc = MX_RTU_Dual_Power1_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_Dual_Power1_Get(&state), return code = %d\r\n", rc);
else
{
if(phoneNumberFlag)
{
if(state == 0) //Power1 disconnect
{
memset(alarmMsg, 0, sizeof(alarmMsg));
strcpy(alarmMsg, "Power1 disconnect of Moxa RTU");
rc = MX_RTU_SMS_Send_GSM_7bits_Default_Alphabet(phoneNumber, pinCode, alarmMsg, strlen(alarmMsg));
if(rc != SMS_ERR_OK)
{
printf("MX_RTU_SMS_Send_GSM_7bits_Default_Alphabet(%s, %s, %s, %d), return code = %d\r\n", phoneNumber, pinCode, alarmMsg, strlen(alarmMsg), rc);
exit(1);
}
}
}
else
{
if(state == 0) //Power2 disconnect
{
printf("Power1 disconnect of Moxa RTU\r\n");
}
}
}
rc = MX_RTU_Dual_Power2_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_Dual_Power2_Get(&state), return code = %d\r\n", rc);
else
{
if(phoneNumberFlag)
{
if(state == 0) //Power2 disconnect
{
memset(alarmMsg, 0, sizeof(alarmMsg));
strcpy(alarmMsg, "Power2 disconnect of Moxa RTU");
rc = MX_RTU_SMS_Send_GSM_7bits_Default_Alphabet(phoneNumber, pinCode, alarmMsg, strlen(alarmMsg));
if(rc != SMS_ERR_OK)
{
printf("MX_RTU_SMS_Send_GSM_7bits_Default_Alphabet(%s, %s, %s, %d), return code = %d\r\n", phoneNumber, pinCode, alarmMsg, strlen(alarmMsg), rc);
exit(1);
}
}
}
else
{
if(state == 0) //Power2 disconnect
{
printf("Power2 disconnect of Moxa RTU\r\n");
}
}
}
return 0;
}