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

- Main Page
- Modules
- Data Structures
- Files

Data Structures | Macros | Typedefs | Enumerations | Functions
CellularNetwork
Library » Cellular

## Data Structures
struct | Check_Info

## Macros
#define | MODEM_BRAND_PH8 1
#define | SIZE_PIN 4
#define | SIZE_APN 32
#define | SIZE_USERNAME 128
#define | SIZE_PASSWORD 128
#define | SIZE_HOSTNAME 128
#define | SIZE_IMEI 17
#define | SIZE_IP_ADDR 16
#define | MODEM_BAND_PH8_GSM900 1
#define | MODEM_BAND_PH8_GSM1800 2
#define | MODEM_BAND_PH8_GSM850 4
#define | MODEM_BAND_PH8_GSM1900 8
#define | MODEM_BAND_PH8_WCDMA2100 16
#define | MODEM_BAND_PH8_WCDMA1900 32
#define | MODEM_BAND_PH8_WCDMA850 64
#define | MODEM_BAND_PH8_WCDMA800 256
#define | MODEM_BAND_PH8_WCDMA1700 512
#define | MODEM_BAND_PH8_AUTO 895
#define | MODEM_STATE_INIT 0
#define | MODEM_STATE_READY 1
#define | MODEM_STATE_CONNECTING 2
#define | MODEM_STATE_CONNECTED 3
#define | MODEM_STATE_DISCONNECT 4

## Typedefs
typedef struct Check_Info | CheckInfo

## Enumerations
enum | MODEM_ERR_CODE { MODEM_ERR_OK = 0, MODEM_ERR_INIT, MODEM_ERR_PARAM, MODEM_ERR_OPEN, MODEM_ERR_SIM, MODEM_ERR_PIN, MODEM_ERR_BAND, MODEM_ERR_ECHO_OFF, MODEM_ERR_CELLULAR_DENIED, MODEM_ERR_RESET, MODEM_ERR_THREAD, MODEM_ERR_APN, MODEM_ERR_CREDENTIAL, MODEM_ERR_ATTACH, MODEM_ERR_IF, MODEM_ERR_CMD, MODEM_ERR_TIMEOUT, MODEM_ERR_STATE, MODEM_ERR_BREAK, MODEM_ERR_SEM, MODEM_ERR_ttyUSB, MODEM_ERR_SYSTEM_INFO, MODEM_ERR_NOT_SUPPORT_PRODUCT, MODEM_ERR_GPS_SWITCH, MODEM_ERR_QUERY_REG, MODEM_ERR_AMOUNT }

## Functions
MODEM_ERR_CODE | MX_RTU_Cellular_Modem_Init (INT8 *pin, UINT32 band)
MODEM_ERR_CODE | MX_RTU_Cellular_Net_Start (INT8 *apn, INT8 *userName, INT8 *password, CheckInfo *autoCheck)
MODEM_ERR_CODE | MX_RTU_Cellular_Net_Stop (void)
MODEM_ERR_CODE | MX_RTU_Cellular_Net_IP_Address (UINT8 *ipAddress)
MODEM_ERR_CODE | MX_RTU_Cellular_Modem_Reset (void)
INT32 | MX_RTU_Cellular_Net_State (void)
MODEM_ERR_CODE | MX_RTU_Cellular_Modem_RSSI (UINT8 *rssi)
void | MX_RTU_Cellular_Modem_IMEI (INT8 *imei)
void | MX_RTU_Cellular_Set_Debug (UINT8 debug)

## Detailed Description

Sample Code:
cellular_connection.c

## Macro Definition Documentation

#define MODEM_BRAND_PH8 1

#define SIZE_PIN 4

#define SIZE_APN 32

#define SIZE_USERNAME 128

#define SIZE_PASSWORD 128

#define SIZE_HOSTNAME 128

#define SIZE_IMEI 17

#define SIZE_IP_ADDR 16

#define MODEM_BAND_PH8_GSM900 1

#define MODEM_BAND_PH8_GSM1800 2

#define MODEM_BAND_PH8_GSM850 4

#define MODEM_BAND_PH8_GSM1900 8

#define MODEM_BAND_PH8_WCDMA2100 16

#define MODEM_BAND_PH8_WCDMA1900 32

#define MODEM_BAND_PH8_WCDMA850 64

#define MODEM_BAND_PH8_WCDMA800 256

#define MODEM_BAND_PH8_WCDMA1700 512

#define MODEM_BAND_PH8_AUTO 895

#define MODEM_STATE_INIT 0

#define MODEM_STATE_READY 1

#define MODEM_STATE_CONNECTING 2

#define MODEM_STATE_CONNECTED 3

#define MODEM_STATE_DISCONNECT 4

## Typedef Documentation

typedef struct Check_Info CheckInfo

## Enumeration Type Documentation

enum MODEM_ERR_CODE

Enumerator
MODEM_ERR_OK | 0
MODEM_ERR_INIT | 1
MODEM_ERR_PARAM | 2
MODEM_ERR_OPEN | 3
MODEM_ERR_SIM | 4
MODEM_ERR_PIN | 5
MODEM_ERR_BAND | 6
MODEM_ERR_ECHO_OFF | 7
MODEM_ERR_CELLULAR_DENIED | 8
MODEM_ERR_RESET | 9
MODEM_ERR_THREAD | 10
MODEM_ERR_APN | 11
MODEM_ERR_CREDENTIAL | 12
MODEM_ERR_ATTACH | 13
MODEM_ERR_IF | 14
MODEM_ERR_CMD | 15
MODEM_ERR_TIMEOUT | 16
MODEM_ERR_STATE | 17
MODEM_ERR_BREAK | 18
MODEM_ERR_SEM | 19
MODEM_ERR_ttyUSB | 20
MODEM_ERR_SYSTEM_INFO | 21
MODEM_ERR_NOT_SUPPORT_PRODUCT | 22
MODEM_ERR_GPS_SWITCH | 23
MODEM_ERR_QUERY_REG | 24
MODEM_ERR_AMOUNT | 25

## Function Documentation

MODEM_ERR_CODE MX_RTU_Cellular_Modem_Init | ( | INT8 * | pin,
|  | UINT32 | band
| ) |  |

Parameters

  [in] | pin | 4 characters PIN code for the SIM card. If SIM card doesn't has a PIN, use NULL as the input.
  [in] | band | Specify the working band for cellular modem. The valid value are listed as following: MODEM_BAND_PH8_GSM900 MODEM_BAND_PH8_GSM1800 MODEM_BAND_PH8_GSM850 MODEM_BAND_PH8_GSM1900 MODEM_BAND_PH8_WCDMA2100 MODEM_BAND_PH8_WCDMA1900 MODEM_BAND_PH8_WCDMA800 MODEM_BAND_PH8_WCDMA850 MODEM_BAND_PH8_WCDMA1700 MODEM_BAND_PH8_AUTO

Returns
  Please refer to MODEM_ERR_CODE . On success, MODEM_ERR_OK is returned.

Note
  1. If you are not sure the band value, use MODEM_BAND_PH8_AUTO, modem will determine it automatically.
  2. You should call this function to init cellular modem before calling any other MX_RTU_Cellular_XXX functions.
  3. On success, cellular state machine will be in state MODEM_STATE_READY.
     Now, you can use Start and Stop function to control 3G network.

MODEM_ERR_CODE MX_RTU_Cellular_Net_Start | ( | INT8 * | apn,
|  | INT8 * | userName,
|  | INT8 * | password,
|  | CheckInfo * | autoCheck
| ) |  |

This function starts the cellular state machine to establish 3G network.

Parameters

  [in] | apn | The Access Point Name.
  [in] | userName | Specify the account name for the authentication, if none, use NULL instead.
  [in] | password | Specify the password for the authentication, if none, use NULL instead. .
  [in] | autoCheck | If you want the cellular state machine periodically check 3G connection and re-establish it while it failed automatically, use this argument.

Returns
  Please refer to MODEM_ERR_CODE . On success, MODEM_ERR_OK is returned.

Note
  1. Pleaes refer to the sample code for the details of arguement autoCheck.
  2. After calling this function, cellular state machine will be in state MODEM_STATE_CONNECTING.
     Once the 3G network is established, the state of cellular state machine becomes to MODEM_STATE_CONNECTED.

MODEM_ERR_CODE MX_RTU_Cellular_Net_Stop | ( | void |  | ) |

This function stops the established 3G network.

Returns
  Please refer to MODEM_ERR_CODE . On success, MODEM_ERR_OK is returned.

Note
  1. After stopping the 3G network, the cellular state machine will back to state MODEM_STATE_READY

MODEM_ERR_CODE MX_RTU_Cellular_Net_IP_Address | ( | UINT8 * | ipAddress | ) |

Using this function to retrieve the IP address of the cellular modem

Parameters

  [out] | ipAddress |

Returns
  Please refer to MODEM_ERR_CODE . On success, MODEM_ERR_OK is returned.

MODEM_ERR_CODE MX_RTU_Cellular_Modem_Reset | ( | void |  | ) |

This function resets the cellular modem, if the autoCheck function is enabled, you should never use this function to reset modem, the state machine will do it for you automatically.

Returns
  Please refer to MODEM_ERR_CODE . On success, MODEM_ERR_OK is returned.

Note
  1. You can call this function to reset modem only when autoCheck is disabled and the state of cellular state machine is in MODEM_STATE_READY or MODEM_STATE_DISCONNECT

INT32 MX_RTU_Cellular_Net_State | ( | void |  | ) |

This function returns the state of cellular state machine.

Returns
  The states are listed as following:
  MODEM_STATE_INIT
  MODEM_STATE_READY
  MODEM_STATE_CONNECTING
  MODEM_STATE_CONNECTED
  MODEM_STATE_DISCONNECT

MODEM_ERR_CODE MX_RTU_Cellular_Modem_RSSI | ( | UINT8 * | rssi | ) |

Using this function to retrieve the RSSI of the cellular modem

Parameters

  [out] | rssi |

Returns
  Please refer to MODEM_ERR_CODE . On success, MODEM_ERR_OK is returned.

void MX_RTU_Cellular_Modem_IMEI | ( | INT8 * | imei | ) |

Using this function to retrieve the IMEI of cellular modem

Parameters

  [out] | imei |

void MX_RTU_Cellular_Set_Debug | ( | UINT8 | debug | ) |

Using this function to enable cellular debug message

Parameters

  [in] | debug | 0:disable 1:enable verbose debug message.