-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ussd support and add power(charger) info event
- Loading branch information
Showing
8 changed files
with
328 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters