LingYun IoT Studio NB-IoT research project
guowenxue
2019-03-27 6db0960200c5a1307914486172094fccf23b33ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/********************************************************************************
 *      Copyright:  (C) guowenxue <guowenxue@gmail.com>
 *                  All rights reserved.
 *
 *       Filename:  module.h
 *    Description:  This is the GPRS module head file
 *
 *        Version:  1.0.0(02/02/2012~)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "02/02/2012 11:33:33 AM"
 *                 
 ********************************************************************************/
 
#ifndef __CP_GPRS_H
#define __CP_GPRS_H
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
 
#include "cp_common.h"
#include "cp_logger.h"
#include "cp_comport.h"
#include "cp_atcmd.h"
#include "cp_time.h"
 
#define YES                   1
#define NO                    0
 
#define OFF                   0
#define ON                    1
 
#define GSM_CTRLPORT          "/dev/gprs"
#define GSM_DATAPORT          "/dev/ttyS2"
 
#define MAX_DATAPORT          4  /* CMUX driver will generate 4 TTY port */
#define CMUX_PORT_START_INDEX 1
#define CMUX_DATAPORT         "/dev/gsmtty"
 
/*GPRS module power status control request event*/
enum
{
    REQ_EVENT_NONE = 0,
    REQ_POWER_OFF,
    REQ_POWER_ON,
    REQ_POWER_RESET,
};
 
/* GPRS Module Ready status */
enum
{
    NOT_READY,
    MODULE_READY,    /* GPRS AT command active and SIM card valid */
    CHECK_HWINFO,    /* Get GPRS hardware Information */
    CHECK_REGISTRY,  /* Check GPRS register network information */
    ALL_READY,
};
 
/* AT+CREG? command show SIM card register status */
enum
{
    REG_UNREGIST = 0, /* not registered, ME is not currently searching a new operator to register to */
    REG_HOMEWORK,     /* registered, home network */
    REG_SEARCHING,    /* not registered, but ME is currently searching a new operator to register to  */
    REG_DENIED,       /* registration denied */
    REG_UNKNOW,       /* unknow */
    REG_ROAMING,      /* registered, roaming */
};
 
/* AT+CNMP=? command to set GPRS module work on which mode */
#define MODE_AUTO     2   /* Automatic */
#define MODE_GSM      13  /* GSM Only */
#define MODE_WCDMA    14  /* WCDMA Only */
 
/* AT+CNSMOD? command show network system mode */
enum
{
    NS_NONE = 0,      /* No service */
    NS_GSM,           /* GSM */
    NS_GPRS,          /* GPRS */
    NS_EGPRS,         /* EGPRS(EDGE) */
    NS_WCDMA,         /* WCDMA */
    NS_HSDPA,         /* HSDPA only */
    NS_HSUPA,         /* HSUPA only */
    NS_HSPA,          /* HSDPA and HSUPA */
};
 
typedef struct modinfo_s
{
    int             users;     /* How many users use the module now  */
    unsigned char   ready;     /* SIM card regist and can work or not */
    unsigned char   event;     /* Request to set GPRS power REQ_POWER_ON, REQ_POWER_OFF or REQ_POWER_RESET */
    unsigned char   pwr_status; /* Current module power status */
 
    pthread_mutex_t lock;      /* Module control mutex lock */
 
    hwinfo_t        hw;        /* GPRS Hardware information */
    reginfo_t       reg;       /* SIM card register network information */
 
    comport_t        *gsmport;  /* The GSM hardware UART port  */
 
    int             comport_cnt; /* GPRS data channel count */
    comport_t        *comport[MAX_DATAPORT]; /* CMUX driver generate CMUX port */
} modinfo_t;
 
 
extern int init_gsm_module(modinfo_t *module);
extern int  open_gsm_dataport(modinfo_t *module);
extern void close_gsm_dataport(modinfo_t *module);
extern comport_t *alloc_gsm_dataport(char *who, modinfo_t *module);
extern void free_gsm_dataport(char *who, modinfo_t *module, comport_t  **comport);
 
extern int power_on_module(modinfo_t *module);
extern int power_off_module(modinfo_t *module);
 
extern int atcmd_check_ready(modinfo_t *module);
extern int atcmd_inspect_status(modinfo_t *module);
extern int atcmd_check_power_on(comport_t *comport);
//unsigned char atcmd_inspect(modinfo_t *module, comport_t *comport);
 
extern void set_module_event(modinfo_t *module, int request);
extern int set_module_event_power(modinfo_t  *module);
 
extern void ctrl_thread_start(void *thread_arg);
extern void ctrl_thread_term(void *thread_arg);
 
#endif /* End of __CP_GPRS_H */