8. Use of M601 System API

1 System related API


1.1 ZYF_GetCoreVersion Get system version information
· Function prototype
int32_t ZYF_GetCoreVersion(uint8_t* ptrVer, uint32_t len)
· Parameter
ptrVer: pointer to the array pointer to get the library version
len: must be greater than or equal to 40, otherwise an error code will be returned
· Return value
success: return library version Character length
failure: The returned result is negative, please refer to the error code in the zyf_error.h file for details.


1.2 ZYF_SysUsDelay function delay, unit: microseconds
· Function prototype
void ZYF_SysUsDelay (uint32_t delay)
· Parameter
delay: delay time, unit: us
· Return value
none.


1.3 Function delay of ZYF_SysMsDelay, unit: milliseconds
· Function prototype
void ZYF_SysMsDelay (uint32_t delay)
· Parameter
delay: delay time, unit: ms
· Return value
none.

1.4 ZYF_IsSimValid Query whether the SIM card is valid
· Function prototype
int32_t ZYF_IsSimValid (void)
· Parameter
none
· Return value
ZYF_RET_OK: Success
ZYF_RET_ERR_SIM_NOT_INSERTED: The card is not inserted or the card is broken


1.5 ZYF_GetImei Get the IMEI number
of the device · Function prototype
int32_t ZYF_GetImei(uint8_t *imei_str, uint8_t length)
· Parameter
imei_str: array pointer to the device IMEI number
length: must be greater than or equal to 16, otherwise an error code will be returned
· Return value
ZYF_RETTAL_OK: success
ZYF_RET_ERR_FA: Failed
ZYF_RET_ERR_PARAM: parameter error


1.6 ZYF_GetImsi Get IMSI number
· Function prototype
int32_t ZYF_GetImsi(uint8_t *imsi_data, uint8_t length)
· Parameter
imsi_data: used to save the IMSI number of the SIM card
length: returned data length
· Return value
ZYF_RET_OK: Success
ZYF_RET_ERR_FATAL_Failed
ZYF_RET

1.7 ZYF_GetIccid Get ICCID 
· Function prototype
int32_t ZYF_GetIccid(PsFuncPtr CallBack)
· Parameter
CallBack: Get the ICCID callback function, you can read the ICCID number in the function
· Return value
ZYF_RET_OK: success
ZYF_RET_ERR_PARAM: parameter error


1.8 ZYF_GetCsqValue Get device signal value
· Function prototype
int32_t ZYF_GetCsqValue(uint8_t *csq_value)
· Parameter
csq_value: Get the ICCID callback function, you can read the ICCID number in the function
· Return value
ZYF_RET_OK: Success
ZYF_RET_ERR_FATAL_Failure
ZYF_RET_ERR_ERR_FATAL_ERROR


1.9 ZYF_GetCregStatus Get GSM note network status
· Function prototype
int32_t ZYF_GetCregStatus(uint8_t *creg_status)
· Parameter
creg_status: pointer to uint8_t type variable, used to get CREG value
· Return value
ZYF_RET_OK: success
ZYF_RET_ERR_PARAM: parameter error

1.10 ZYF_GetCgregStatus Get GPRS network status
· Function prototype
int32_t ZYF_GetCgregStatus(uint8_t *cgreg_status, uint8_t *plmn,
uint16_t *lac_value, uint16_t *ci_value)
· Parameter
cgreg_status: point to uint8_t type variable pointer, used to obtain
CGREGint8_t type variable pointer Pointer, used to obtain plmn value (MCC+MNC), the
length of the array must be greater than or equal to 10
lac_value: pointer to uint16_t type variable, used to obtain lac value
ci_value: pointer to uint16_t type variable, used to obtain ci value
· Return value
ZYF_RET_OK: Success
ZYF_RET_ERR_PARAM: parameter error


1.11 ZYF_FlightModeOnOff Turn on/off flight mode
· Function prototype
int32_t ZYF_FlightModeOnOff(uint8_t on_off)
· Parameter
on_off: TRUE: Turn on flight mode, FALSE: Turn off flight mode
· Return value
ZYF_RET_OK: Success
ZYF_RET_ERR_PARAM: Parameter error


1.12 ZYF_MemoryTotalLeftSize Get the remaining heap space size
· Function prototype
uint32_t ZYF_MemoryTotalLeftSize(void)
· Parameter
none
· Return value
Remaining space size

2 Introduction to system routines


This chapter mainly introduces how to use example_system.c in SDK.
Compiling method: .\examples\build\ corresponds to the .bat file by double-clicking to execute or opening it to compile.
Generated file: .\out\corresponding directory\hex\M601_example_**.pac

In the routine, the test result is printed to the serial port, and the serial port assistant can be connected to view the test result.



#include <stdlib.h>
#include <string.h>
#include "zyf_trace.h"
#include "zyf_system.h"
#include "zyf_app.h"
#include "zyf_uart.h"
#include "zyf_thread.h"
#include "zyf_time.h"

#include "zyf_error.h"


static Uart_Param_t g_uart1param;

void UartWriteCallBack(void* Param) // general com
{
    Uart_Param_t *uartparam = (Uart_Param_t *)Param; 
    if(Param == NULL)
    {
        return;
    }    

    ZYF_UartWrite(uartparam->port,(uint8_t *)"UartWrite succeed\r\n",strlen("UartWrite succeed\r\n"));
    ZYF_UartWriteCallbackSwitch(uartparam->port,false);

}

void UartReadCallBack(void* Param) // 
{
    uint32_t recvlen = 0;
    Uart_Param_t *uartparam = (Uart_Param_t *)Param; 

    ZYF_LOG("Uart%d recv",uartparam->port);

    while(ZYF_UartRead(uartparam->port, &(uartparam->uartbuf[recvlen]), 1))
    {
        ZYF_LOG("recv :%02x",uartparam->uartbuf[recvlen]);
        recvlen++;
    }
    ZYF_UartWrite(uartparam->port,uartparam->uartbuf,recvlen);
    ZYF_UartWriteCallbackSwitch(uartparam->port,true);
}


static void AppUartInit(void)
{
    int32_t ret;
    g_uart1param.port = DEBUG_PORT;
    ZYF_UartRegister(g_uart1param.port, UartReadCallBack,&g_uart1param);
    ZYF_UartWriteCbRegister(g_uart1param.port,UartWriteCallBack,&g_uart1param);
    ZYF_UartOpen(g_uart1param.port, 115200, ZYF_FC_NONE);

    ZYF_LOG("AppUartInit");
    return;
}



#if 1
static void GetIccidCallback(void*msg)
{
    uint8_t idx;


    if(NULL == msg)
    {
        ZYF_LOG("SystemApi GetIccid fail");
        return;
    }
    idx = strlen((char*)msg);
    if((idx < 3) || (idx > 20))
    {
        ZYF_LOG("SystemApi GetIccid fail,idx:%d",idx);
        return;
    }
    ZYF_LOG("SystemApi GetIccid %s",(char*)msg);
 
    
}


static void GetImsiCallback(void*msg)
{
    uint8_t idx;

    
    ZYF_LOG("GetImsiCallback");

    if(NULL == msg)
    {
        ZYF_LOG("SystemApi GetImsi fail");
        return;
    }
    idx = strlen((char*)msg);
    if((idx < 3) || (idx > 20))
    {
        ZYF_LOG("SystemApi GetImsi fail,idx:%d",idx);
        //return;
    }
    ZYF_LOG("SystemApi GetImsi %s",(char*)msg);
 
    
}

static void FlightModeOnOff(int on_off)
{
    ZYF_LOG("FlightModeOnOff %d",on_off);
}

#endif


void ZYF_SystemApiTest(void)
{
    uint8_t Imei[16+1] = {0};
    uint8_t csq = 0;
    uint8_t CregStatus = 0;
    uint8_t CgregStatus = 0,plmn[6] = {0};
    uint32_t lac_value = 0,ci_value = 0;
    uint64_t ms = 0,sec = 0;;
    uint32_t high = 0;
    uint32_t low = 0;
    int32_t nwMode = 0;

    if(0 == ZYF_IsSimValid())
    {
        ZYF_LOG("SystemApi IsSimValid:true");
    }
    else
    {
        ZYF_LOG("SystemApi IsSimValid:false");
    }

    if(ZYF_RET_OK == ZYF_GetNetworkInfo(&nwMode))
    {
        ZYF_LOG("ZYF_GetNetworkInfo:%d",nwMode);
    }
    else
    {
        ZYF_LOG("ZYF_GetNetworkInfo fail");
    }
    
    ms = ZYF_GetTickMs();
    high = (ms >> 32) & 0xFFFFFFFF;
    low = ms & 0xFFFFFFFF;
    ZYF_LOG("ZYF_GetLocalTimeMs %lu,%lu", high,low);

    sec = ZYF_GetLocalTimeSec();
    high = (sec >> 32) & 0xFFFFFFFF;
    low = sec& 0xFFFFFFFF;

    ZYF_LOG("ZYF_GetLocalTimeSec: %lu,%lu", high,low);

    //ZYF_LOG("ZYF_FlightModeOnOff:%d",ZYF_FlightModeOnOff(1,FlightModeOnOff));
    ZYF_LOG("ZYF_FlightModeIsOn:%d",ZYF_FlightModeIsOn());


    ZYF_LOG("SystemApi nwscanmode:%d",ZYF_Getnwscanmode());
    ZYF_GetImei(Imei,sizeof(Imei));
    ZYF_LOG("SystemApi Imei:%s",Imei);
    ZYF_GetCsqValue(&csq);
    ZYF_LOG("SystemApi csq:%d",csq);
    ZYF_GetCregStatus(&CregStatus);
    ZYF_LOG("SystemApi CregStatus:%d",CregStatus);

    ZYF_GetCgregStatus(&CgregStatus, plmn, &lac_value, &ci_value);
    ZYF_LOG("SystemApi CregStatus:CgregStatus:%02X,plmn:%02x%x%02x,lac_value:%X,ci_value:%X",\
                    CregStatus, plmn[0],plmn[1],plmn[2], lac_value, ci_value);

    ZYF_GetIccid(GetIccidCallback);
    ZYF_GetImsi(GetImsiCallback);

    ZYF_LOG("ZYF_SleepEnable:%d",ZYF_SleepEnable());
    
}


void SystemApiThread_Example(void * Param)
{
    ZYF_MsgQ_t *ptMsg;
    ZYF_AppMsg_t tMsg;
    int iRet = -1;
    ptMsg = ZYF_MsgQCreate(10, sizeof(ZYF_AppMsg_t));
    ZYF_LOG("thread enter!");

    ZYF_SystemApiTest();
    
    while (1) {
        ZYF_LOG("in while.");
        iRet = ZYF_MsgQGet(ptMsg, (void *)&tMsg);
        if (iRet < 0) {
            ZYF_LOG("Failed to get msg");
            ZYF_ThreadSleep(1000);
        }
    }

}

static void prvInvokeGlobalCtors(void)
{
    extern void (*__init_array_start[])();
    extern void (*__init_array_end[])();

    size_t count = __init_array_end - __init_array_start;
    for (size_t i = 0; i < count; ++i)
        __init_array_start[i]();
}


int appimg_enter(void *param)
{
    AppUartInit();
    ZYF_LOG("application image enter, param 0x%x", param);

    prvInvokeGlobalCtors();

    ZYF_ThreadCreate("UartThread_Example", SystemApiThread_Example, NULL, ZYF_PRIORITY_HIGH, 10*1024);
    return 0;
}

void appimg_exit(void)
{
    OSI_LOGI(0, "application image exit");
}








 

Guess you like

Origin blog.csdn.net/w_hizyf_m/article/details/107089085