Skip to content

Commit

Permalink
add ussd support and add power(charger) info event
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Jun 9, 2018
1 parent 7f9caaf commit 620e413
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 2 deletions.
34 changes: 34 additions & 0 deletions demo/ussd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## ----------------------------------------------------------- ##
## Don't touch the next line unless you know what you're doing.##
## ----------------------------------------------------------- ##

# Name of the module
LOCAL_NAME := demo/ussd

# List of submodules which contain code we need to include in the final lib
LOCAL_API_DEPENDS := \

LOCAL_ADD_INCLUDE := include\
include/std_inc \
include/api_inc \


# Set this to any non-null string to signal a module which
# generates a binary (must contain a "main" entry point).
# If left null, only a library will be generated.
IS_ENTRY_POINT := no

## ------------------------------------ ##
## Add your custom flags here ##
## ------------------------------------ ##
MYCFLAGS +=

## ------------------------------------- ##
## List all your sources here ##
## ------------------------------------- ##
C_SRC := ${notdir ${wildcard src/*.c}}

## ------------------------------------- ##
## Do Not touch below this line ##
## ------------------------------------- ##
include ${SOFT_WORKDIR}/platform/compilation/cust_rules.mk
171 changes: 171 additions & 0 deletions demo/ussd/src/demo_ussd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@


#include <string.h>
#include <stdio.h>
#include <api_os.h>
#include <api_event.h>
#include <api_network.h>
#include <api_debug.h>
#include <api_ss.h>
#include <api_charset.h>


#define DOMAIN_NUMBER 8

#define MAIN_TASK_STACK_SIZE (2048 * 2)
#define MAIN_TASK_PRIORITY 0
#define MAIN_TASK_NAME "Socket Test Task"

#define TEST_TASK_STACK_SIZE (2048 * 2)
#define TEST_TASK_PRIORITY 1
#define TEST_TASK_NAME "Test Task"

static HANDLE networkTaskHandle = NULL;
static HANDLE testTaskHandle = NULL;
HANDLE sem = NULL;


void EventDispatch(API_Event_t* pEvent)
{
switch(pEvent->id)
{
case API_EVENT_ID_NO_SIMCARD:
Trace(10,"!!NO SIM CARD%d!!!!",pEvent->param1);
break;

case API_EVENT_ID_SIMCARD_DROP:
Trace(2,"SIM CARD%d DROP",pEvent->param1);
break;

case API_EVENT_ID_SINGNAL_QUALITY:
Trace(2,"signal quality:%d",pEvent->param1);
break;


case API_EVENT_ID_NETWORK_REGISTERED_HOME:
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
{
Trace(2,"network register success");
OS_ReleaseSemaphore(sem);
break;
}
case API_EVENT_ID_NETWORK_REGISTER_SEARCHING:
Trace(2,"network register searching");
break;

case API_EVENT_ID_NETWORK_REGISTER_DENIED:
Trace(2,"network register denied");
break;

case API_EVENT_ID_NETWORK_REGISTER_NO:
Trace(2,"network register no");
break;

case API_EVENT_ID_NETWORK_DETACHED:
Trace(2,"network detached");
break;

case API_EVENT_ID_NETWORK_ATTACH_FAILED:
Trace(2,"network attach failed");
break;

case API_EVENT_ID_NETWORK_ATTACHED:
Trace(2,"network attach success");
break;

case API_EVENT_ID_NETWORK_DEACTIVED:
Trace(2,"network deactived");
break;

case API_EVENT_ID_NETWORK_ACTIVATE_FAILED:
Trace(2,"network activate failed");
break;

case API_EVENT_ID_NETWORK_ACTIVATED:
Trace(2,"network activate success");
break;

case API_EVENT_ID_NETWORK_GOT_TIME:
Trace(2,"network got time");
break;

case API_EVENT_ID_USSD_SEND_SUCCESS:
{
uint8_t buffer[50];
Trace(1,"ussd execute success");
USSD_Type_t* result = (USSD_Type_t*)pEvent->pParam1;
int len = GSM_8BitTo7Bit(result->usdString,buffer,result->usdStringSize);
Trace(1,"string:%s,size:%d,option:%d,dcs:%d",buffer,len,result->dcs,result->option);
break;
}
case API_EVENT_ID_USSD_SEND_FAIL:
Trace(1,"ussd exec fail,error code:%x,%d",pEvent->param1,pEvent->param2);
break;

case API_EVENT_ID_USSD_IND:
{
uint8_t buffer[50];
Trace(1,"ussd recieved");
USSD_Type_t* result = (USSD_Type_t*)pEvent->pParam1;
int len = GSM_8BitTo7Bit(result->usdString,buffer,result->usdStringSize);
Trace(1,"string:%s,size:%d,option:%d,dcs:%d",buffer,len,result->dcs,result->option);
break;
}
default:
break;
}
}

#define USSD_STRING "*#21#"

void Test_MainTask(void* param)
{
uint8_t buffer[50];
USSD_Type_t usd;

sem = OS_CreateSemaphore(0);
OS_WaitForSemaphore(sem,OS_TIME_OUT_WAIT_FOREVER);

int encodeLen = GSM_8BitTo7Bit(USSD_STRING,buffer,strlen(USSD_STRING));
usd.usdString = buffer;
usd.usdStringSize = encodeLen;
usd.option = 3;
usd.dcs = 0x0f;
uint32_t ret = SS_SendUSSD(usd);
Trace(1,"ussd ret:0x%x",ret);
while(1)
{
OS_Sleep(5000);
}
}


void network_MainTask(void *pData)
{
API_Event_t* event=NULL;

// Network_SetStatusChangedCallback(OnNetworkStatusChanged);
testTaskHandle = OS_CreateTask(Test_MainTask ,
NULL, NULL, TEST_TASK_STACK_SIZE, TEST_TASK_PRIORITY, 0, 0, TEST_TASK_NAME);

while(1)
{
if(OS_WaitEvent(networkTaskHandle, (void**)&event, OS_TIME_OUT_WAIT_FOREVER))
{
EventDispatch(event);
OS_Free(event->pParam1);
OS_Free(event->pParam2);
OS_Free(event);
}
}
}


void ussd_Main()
{
networkTaskHandle = OS_CreateTask(network_MainTask ,
NULL, NULL, MAIN_TASK_STACK_SIZE, MAIN_TASK_PRIORITY, 0, 0, MAIN_TASK_NAME);
OS_SetUserMainHandle(&networkTaskHandle);
}


4 changes: 4 additions & 0 deletions include/api_charset.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#define Unicode2LocalLanguageBigEndian CSDK_FUNC(Unicode2LocalLanguageBigEndian)
#define LocalLanguage2UnicodeBigEndian CSDK_FUNC(LocalLanguage2UnicodeBigEndian)

// int32_t GSM_8BitTo7Bit(const uint8_t* pSrc, uint8_t* pDest, uint16_t nSrcSize );
#define GSM_8BitTo7Bit CSDK_FUNC(GSM_8BitTo7Bit)
// int32_t GSM_7BitTo8Bit(const uint8_t* pSrc, uint8_t* pDest, uint16_t nSrcSize );
#define GSM_7BitTo8Bit CSDK_FUNC(GSM_7BitTo8Bit)

#endif

12 changes: 11 additions & 1 deletion include/api_inc/api_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ typedef enum{

//error
API_EVENT_ID_MALLOC_FAILED ,
API_EVENT_ID_MAX

//ussd
API_EVENT_ID_USSD_IND , //pParam1: USSD_Type_t
API_EVENT_ID_USSD_SEND_SUCCESS , //pParam1: USSD_Type_t
API_EVENT_ID_USSD_SEND_FAIL , //param1:error code(USSD_Error_t) param2:error code2(USSD_Error_t)

//power
API_EVENT_ID_POWER_INFO , //param1: (PM_Charger_State_t<<16|charge_level(%)) , param2: (PM_Battery_State_t<<16|battery_voltage(mV))

API_EVENT_ID_MAX

}API_Event_ID_t;

typedef struct {
Expand Down
40 changes: 40 additions & 0 deletions include/api_inc/api_inc_pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,46 @@ typedef enum{
POWER_ON_CAUSE_MAX
}Power_On_Cause_t;

typedef enum{
PM_SYS_FREQ_32K = 32768,
PM_SYS_FREQ_13M = 13000000,
PM_SYS_FREQ_26M = 26000000,
PM_SYS_FREQ_39M = 39000000,
PM_SYS_FREQ_52M = 52000000,
PM_SYS_FREQ_78M = 78000000,
PM_SYS_FREQ_89M = 89142857, //624M/7
PM_SYS_FREQ_104M = 104000000,
PM_SYS_FREQ_113M = 113454545, //624M/5.5
PM_SYS_FREQ_125M = 124800000,
PM_SYS_FREQ_139M = 138666667, //624M/4.5
PM_SYS_FREQ_156M = 156000000,
PM_SYS_FREQ_178M = 178285714, //624M/3.5
PM_SYS_FREQ_208M = 208000000,
PM_SYS_FREQ_250M = 249600000, //624M/2.5
PM_SYS_FREQ_312M = 312000000,
PM_SYS_FREQ_UNKNOWN = 0,
} PM_Sys_Freq_t;

typedef enum{
PM_CHARGER_STATE_DISCONNECTED = 0,
PM_CHARGER_STATE_CONNECTED = 1,
PM_CHARGER_STATE_CHRGING = 2,
PM_CHARGER_STATE_FINISHED = 3,
PM_CHARGER_STATE_ERROR_TEMPERATURE = 4,
PM_CHARGER_STATE_ERROR_VOLTAGE = 5,
PM_CHARGER_STATE_ERROR_UNKNOWN = 9,
PM_CHARGER_STATE_MAX
}PM_Charger_State_t;

typedef enum{
PM_BATTERY_STATE_NORMAL = 0,
PM_BATTERY_STATE_LOW = 1,
PM_BATTERY_STATE_CRITICAL = 2,
PM_BATTERY_STATE_SHUTDOWN = 3,
PM_BATTERY_STATE_UNKNOWN = 4,
PM_BATTERY_STATE_MAX
}PM_Battery_State_t;


#endif

50 changes: 50 additions & 0 deletions include/api_inc/api_inc_ss.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef API_SS_H
#define API_SS_H

#include "stdint.h"

typedef enum{
USSD_ERROR_LOCAL_NETWORK_REJECT = 0xfa,
USSD_ERROR_NETWORK_RETURN = 0xfb,
USSD_ERROR_NETWORK_RETURN_IE = 0xfd,

USSD_ERROR_SERVICE_NOT_IMPLEMENTED = 10,
USSD_ERROR_INVALID_OPERATION = 11,
USSD_ERROR_INVALID_SERVICE_CODE = 12,
USSD_ERROR_MEM = 14,
USSD_ERROR_MM_ESTABLISHMENT = 20,
USSD_ERROR_TRANSACTION_TIME_OUT = 21,
USSD_ERROR_MM_CONNECTION_RELEASED = 22,
USSD_ERROR_UNKNOWN_COMPONENT_RECEIVED = 23,
USSD_ERROR_MAX
}USSD_Error_t;


// -----------------------------------------------------------------------------------------------------------------------------
// parameter
// pUsdString[in]: pointer the to USSD string. It should be decoded codes.
// nUsdStringSize[in]: size of param pUsdString. different meaning in different nOption, see below
// nOption[in]: operation option of the USSD string. available value can be divided into two groups,
// one is for USSD v2:
// 0 (response the NETWORK with an error), in this case ,param nUsdStringSize must be input as api_SsUSSDErrorPresent_t, not just UINT8.
// 1 (response the NETWORK with reject), in this case ,param nUsdStringSize must be input as api_SsProblemCodeTag_t, not just UINT8.
// 2 (response the NETWORK with MS release request)
// 3 (response the NETWORK with user data or invoke USSD to network)
// the other is for USSD v1:
// 128 (response the NETWORK with an error), in this case ,param nUsdStringSize must be input as api_SsUSSDErrorPresent_t, not just UINT8.
// 129 (response the NETWORK with reject), in this case ,param nUsdStringSize must be input as api_SsProblemCodeTag_t, not just UINT8.
// 130 (response the NETWORK with MS release request)
// 131 (response the NETWORK with user data or invoke USSD to network)
// nDcs[in]: decode scheme for pUsdString, available only when nOption support USSD V2.
// -------------------------------------------------------------------------------------------------------------------------------
typedef struct
{
uint8_t* usdString; //pointer the to USSD string. It should be decoded codes.
//(e.g. if use GSM 7bit data, you can call GSM_8BitTo7Bit(...) to vonvert 8bit data to 7bit data)
uint8_t usdStringSize;
uint8_t option; //0 1 2 3
uint8_t dcs; //Data Coding Scheme, 0x0f: Default GSM 7bit and language unspecified
} USSD_Type_t;


#endif
11 changes: 11 additions & 0 deletions include/api_ss.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __API_SS_H_
#define __API_SS_H_

#include <sdk_init.h>



// uint32_t SS_SendUSSD(USSD_Type_t );
#define SS_SendUSSD CSDK_FUNC(SS_SendUSSD)

#endif
8 changes: 7 additions & 1 deletion include/sdk_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <api_inc_ssl.h>
#include <api_inc_spi.h>
#include <api_inc_fota.h>

#include <api_inc_ss.h>



Expand All @@ -40,6 +40,7 @@ typedef struct T_INTERFACE_VTBL_TAG
uint16_t (*PM_Voltage)(uint8_t* percent);
void (*PM_ShutDown)();
void (*PM_Restart)();
void (*PM_SetSysMinFreq)(PM_Sys_Freq_t freq);

/*api_os*/
void (*OS_SetUserMainHandle)(HANDLE* UserHandle);
Expand Down Expand Up @@ -140,6 +141,8 @@ typedef struct T_INTERFACE_VTBL_TAG
bool (*LocalLanguage2Unicode)(uint8_t* localIn, uint16_t localLenIn, Charset_t localLanguage, uint8_t** unicodeOut, uint32_t* unicodeLenOut);
bool (*Unicode2LocalLanguageBigEndian)(uint8_t* unicodeIn, uint16_t unicodeLenIn, Charset_t localLanguage, uint8_t** localOut, uint32_t* localLenOut);
bool (*LocalLanguage2UnicodeBigEndian)(uint8_t* localIn, uint16_t localLenIn, Charset_t localLanguage, uint8_t** unicodeOut, uint32_t* unicodeLenOut);
int32_t (*GSM_8BitTo7Bit)(const uint8_t* pSrc, uint8_t* pDest, uint16_t nSrcSize );
int32_t (*GSM_7BitTo8Bit)(const uint8_t* pSrc, uint8_t* pDest, uint16_t nSrcSize );

/*fs*/
void (*API_FS_SetUseOldVersion)(bool useOldVersion);
Expand Down Expand Up @@ -266,6 +269,9 @@ typedef struct T_INTERFACE_VTBL_TAG
uint32_t (*SYS_EnterCriticalSection)(void);
void (*SYS_ExitCriticalSection)(uint32_t status);

//ussd
uint32_t (*SS_SendUSSD)(USSD_Type_t );

} T_INTERFACE_VTBL_TAG;
extern T_INTERFACE_VTBL_TAG *g_InterfaceVtbl;
#define CSDK_FUNC(name) (g_InterfaceVtbl->name)
Expand Down

0 comments on commit 620e413

Please sign in to comment.