blob: 76782088a051c92c38e3bedddfc4ae2216a37572 [file] [log] [blame]
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include <stdint.h>
#include <string.h>
#define GSW_SMS_SEND_NUM_MAX 5 /**< dest num max count */
#define GSW_SMS_ADDRESS_LEN 32 /**< one dest number max length*/
#define GSW_SMS_CONCAT_SMS_COUNT_MAX 160 /**< one page max bytes*/
#define GSW_SMS_MSG_CONTENT_LEN_MAX 3 /**< sms page max count*/
#define GSW_SMS_CONTENT_LEN_MAX 3 /**< newmsg recv one page*/
#define GSW_SMS_SEND_CONT_MAX (GSW_SMS_MSG_CONTENT_LEN_MAX*GSW_SMS_CONCAT_SMS_COUNT_MAX*2) /**< sms send max len*/
#define GSW_SMS_RECV_CONT_MAX 1440 /**< sms receive max len*/
#define GSW_HAL_SMS_ADDRESS_LEN GSW_SMS_ADDRESS_LEN
#define GSW_HAL_SMS_RECV_CONT_MAX GSW_SMS_RECV_CONT_MAX
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16;
typedef uint32_t sms_client_handle_type;
typedef enum
{
GSW_SMS_FULL_FLG, /**< sms full flag*/
GSW_SMS_RECEIVED_FLG, /**<recv new sms flag*/
}gsw_sms_state_e;
typedef enum
{
SMS_FORMAT_GSM_7BIT = 0, /**< 7bit econde*/
SMS_FORMAT_BINARY_DATA = 1, /**< 8bit binary encode*/
SMS_FORMAT_UCS2 = 2, /**< ucs2 encode*/
}gsw_sms_format_e;
typedef struct gsw_hal_sms_date
{
unsigned char year[5]; /**< year of date*/
unsigned char month[3]; /**< month of date*/
unsigned char day[3]; /**< day of date*/
unsigned char hour[3]; /**< hour of time*/
unsigned char minutes[3]; /**< minute of time*/
unsigned char seconds[3]; /**< second of time*/
unsigned char timezone[4]; /**< timezone*/
} gsw_sms_date_t;
typedef struct gsw_hal_sms_msg_type
{
char src_num[GSW_SMS_ADDRESS_LEN+1]; /**< sms phone num send msg*/
char dest_num[GSW_SMS_ADDRESS_LEN + 1]; /**< sms phone num recv msg*/
gsw_sms_format_e content_encode; /**< sms content is 7bit or 8bit or Ucs2 encode*/
unsigned int content_len; /**< sms content size*/
char content[GSW_SMS_RECV_CONT_MAX + 1]; /**< sms content*/
gsw_sms_date_t date; /**< message time*/
} gsw_sms_msg_type_t;
typedef void (* GSW_HAL_SMS_CALLBACK_FUN)(gsw_sms_state_e state, gsw_sms_msg_type_t *report_info);
int (*gsw_sms_reg_callback)(GSW_HAL_SMS_CALLBACK_FUN handle_ptr);
int (*gsw_sms_sdk_init)(int32_t token);
int (*gsw_sms_sdk_deinit)(void);
int (*gsw_send_sms)(int8_t *phone_num, int32_t char_set, int8_t *msg, int32_t msg_len);
int (*gsw_get_smsc_address)(int32_t len, int8_t *smsc);
int (*gsw_set_smsc_address)(const int8_t *smsc);
#define lib_gsw_sms_path "/lib/libgsw_lib.so"
static void *dlHandle_sms;
void gsw_test_callback(gsw_sms_state_e state, gsw_sms_msg_type_t *report_info)
{
printf("gsw_test_callback: state = %d\n", state);
printf("gsw_test_callback: report_info->src_num = %s\n", report_info->src_num);
printf("gsw_test_callback: report_info->dest_num = %s\n", report_info->dest_num);
printf("gsw_test_callback: report_info->content_encode = %d\n", report_info->content_encode);
printf("gsw_test_callback: report_info->content_len = %d\n", report_info->content_len);
printf("gsw_test_callback: report_info->content = %s\n", report_info->content);
printf("gsw_test_callback: report_info->date->year = %s\n", report_info->date.year);
printf("gsw_test_callback: report_info->date->month = %s\n", report_info->date.month);
printf("gsw_test_callback: report_info->date->day = %s\n", report_info->date.day);
printf("gsw_test_callback: report_info->date->hour = %s\n", report_info->date.hour);
printf("gsw_test_callback: report_info->date->minutes = %s\n", report_info->date.minutes);
printf("gsw_test_callback: report_info->date->seconds = %s\n", report_info->date.seconds);
printf("gsw_test_callback: report_info->date->timezone = %s\n", report_info->date.timezone);
}
static int gsw_sms_api_import()
{
dlHandle_sms = dlopen(lib_gsw_sms_path, RTLD_NOW);
if (dlHandle_sms == NULL) {
printf("Failed to open %s\n", lib_gsw_sms_path);
return -1;
}
gsw_sms_sdk_init = (int(*)(int32_t token))dlsym(dlHandle_sms,"gsw_sms_sdk_init");
if(gsw_sms_sdk_init == NULL)
{
printf("gsw_sms_sdk_init fail\n");
return -1;
}
gsw_sms_reg_callback = (int(*)(GSW_HAL_SMS_CALLBACK_FUN handle_ptr))dlsym(dlHandle_sms,"gsw_sms_reg_callback");
if(gsw_sms_reg_callback == NULL)
{
printf("gsw_sms_reg_callback fail\n");
return -1;
}
gsw_send_sms = (int(*)(int8_t *phone_num, int32_t char_set, int8_t *msg, int32_t msg_len))dlsym(dlHandle_sms,"gsw_send_sms");
if(gsw_send_sms == NULL)
{
printf("gsw_send_sms fail\n");
return -1;
}
gsw_get_smsc_address = (int(*)(int32_t len, int8_t *smsc))dlsym(dlHandle_sms,"gsw_get_smsc_address");
if(gsw_get_smsc_address == NULL)
{
printf("gsw_get_smsc_address fail\n");
return -1;
}
gsw_set_smsc_address = (int(*)(const int8_t *smsc))dlsym(dlHandle_sms,"gsw_set_smsc_address");
if(gsw_set_smsc_address == NULL)
{
printf("gsw_set_smsc_address fail\n");
return -1;
}
gsw_sms_sdk_deinit = (int(*)(void))dlsym(dlHandle_sms,"gsw_sms_sdk_deinit");
if(gsw_sms_sdk_deinit == NULL)
{
printf("gsw_sms_sdk_deinit fail\n");
return -1;
}
return 0;
}
int main()
{
int ret = -1;
int opt = -1;
char operator[10];
char phone_number[GSW_HAL_SMS_ADDRESS_LEN] = {0};
char serv_numer[GSW_HAL_SMS_ADDRESS_LEN] = {0};
ret = gsw_sms_api_import();
if(ret != 0)
{
printf("gsw_sms_api_import fail\n");
return -1;
}
while(1)
{
printf("=========sms main=========\n"
"\t-1 exit\n"
"\t1 sms init\n"
"\t2 send text sms\n"
"\t3 wait receive new sms\n"
"\t4 send PDU sms\n"
"\t7 query service number\n"
"\t8 set service number\n"
"\t9 deinit sms\n"
"operator: >> \n");
opt = -1;
ret = -1;
printf("%s\n",fgets(operator, sizeof(operator), stdin));
fflush(stdin);
opt = atoi(operator);
switch (opt)
{
case -1:
{
printf("main exit\n");
return 0;
}
case 1:
{
printf("gsw_sms_sdk_init start");
ret = gsw_sms_sdk_init(1234);
if(ret != 0)
{
printf("gsw_sms_sdk_init fail,ret = %d\n",ret);
dlclose(dlHandle_sms);
continue;
}
break;
}
case 2:
{
char *tmp = "all man hello world";
printf("input phone number:\n");
memset(phone_number, 0x0, GSW_HAL_SMS_ADDRESS_LEN);
//fgets(phone_number, MAX_LEN, stdin);
printf("%d\n",scanf("%15s", phone_number));
fflush(stdin);
int len = strlen(tmp);
ret = gsw_send_sms((int8_t*)phone_number, 0, (int8_t*)tmp, len);
if(ret != 0)
{
printf("gsw_send_sms fail,ret = %d\n",ret);
continue;
}
break;
}
case 3:
{
printf("gsw_sms_reg_callback start\n");
ret = gsw_sms_reg_callback(gsw_test_callback);
if(ret != 0)
{
printf("gsw_sms_reg_callback fail,ret = %d\n",ret);
continue;
}
printf("gsw_sms_reg_callback end");
break;
}
case 4:
{
char *tmp = "你好";
printf("input phone number:\n");
memset(phone_number, 0x0, GSW_HAL_SMS_ADDRESS_LEN);
//fgets(phone_number, MAX_LEN, stdin);
printf("%d\n",scanf("%15s", phone_number));
fflush(stdin);
int len = strlen(tmp);
ret = gsw_send_sms((int8_t*)phone_number, 2, (int8_t *)tmp, len);
if(ret != 0)
{
printf("gsw_send_sms fail,ret = %d\n",ret);
continue;
}
break;
}
case 7:
{
printf("gsw_get_smsc_address start\n");
ret = gsw_get_smsc_address(GSW_HAL_SMS_ADDRESS_LEN, (int8_t *)serv_numer);
if(ret != 0)
{
printf("gsw_get_smsc_address fail,ret = %d\n",ret);
continue;
}
printf("smsc: %s\n", serv_numer);
break;
}
case 8:
{
printf("input phone number:\n");
memset(phone_number, 0x0, GSW_HAL_SMS_ADDRESS_LEN);
//fgets(phone_number, MAX_LEN, stdin);
printf("%d\n",scanf("%15s", phone_number));
fflush(stdin);
printf("start memcpy\n");
memcpy(serv_numer, phone_number, GSW_HAL_SMS_ADDRESS_LEN);
ret = gsw_set_smsc_address((const int8_t *)serv_numer);
if(ret != 0)
{
printf("gsw_set_smsc_address fail,ret = %d\n",ret);
continue;
}
printf("smsc: %s\n", serv_numer);
break;
}
case 9:
{
printf("gsw_sms_sdk_deinit start\n");
ret = gsw_sms_sdk_deinit();
if(ret != 0)
{
printf("gsw_sms_sdk_deinit fail,ret = %d\n",ret);
dlclose(dlHandle_sms);
continue;
}
break;
}
default:
{
continue;
}
}
}
}