//-------------------------------------------------------------------------------------------------- le_result_t pa_mrc_GetSignalStrength ( int32_t* rssiPtr ///< [OUT] The received signal strength (in dBm). ) { int32_t result=LE_NOT_POSSIBLE; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+CSQ:",NULL}; if (!rssiPtr) { LE_WARN("One parameter is NULL"); return LE_BAD_PARAMETER; } result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+csq", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // Release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is if (atcmdsync_GetNumLines(resRef) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(resRef,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if (FIND_STRING("+CSQ:",atcmd_GetLineParameter(line,1))) { if (numParam==3) { uint32_t val2 = atoi(atcmd_GetLineParameter(line,2)); if (val2==99) { LE_WARN("Quality signal not detectable"); result = LE_OUT_OF_RANGE; } else { *rssiPtr = (-113+(2*val2)); result = LE_OK; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(resRef); // Release atcmdsync_SendCommand return result; }
//-------------------------------------------------------------------------------------------------- static le_result_t GetNetworkReg ( bool first, ///< true -> mode, false -> state int32_t* valuePtr ///< value that will be return ) { int32_t result=LE_NOT_POSSIBLE; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+CREG:",NULL}; result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+creg?", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(resRef) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(resRef,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if (FIND_STRING("+CREG:",atcmd_GetLineParameter(line,1))) { if ((numParam>2) && (numParam<7)) { int32_t val; if (first) { val=(int32_t)atoi(atcmd_GetLineParameter(line,2)); } else { val=(int32_t)atoi(atcmd_GetLineParameter(line,3)); } switch(val) { case 0: *valuePtr = LE_MRC_REG_NONE; break; case 1: *valuePtr = LE_MRC_REG_HOME; break; case 2: *valuePtr = LE_MRC_REG_SEARCHING; break; case 3: *valuePtr = LE_MRC_REG_DENIED; break; case 4: *valuePtr = LE_MRC_REG_UNKNOWN; break; case 5: *valuePtr = LE_MRC_REG_ROAMING; break; default: *valuePtr = LE_MRC_REG_UNKNOWN; break; } result = LE_OK; } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(resRef); // Release atcmdsync_SendCommand return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mdc_ReadProfile ( uint32_t profileIndex, ///< [IN] The profile to read pa_mdc_ProfileData_t* profileDataPtr ///< [OUT] The profile data ) { le_result_t result=LE_NOT_POSSIBLE; char atintermediate[ATCOMMAND_SIZE]; atcmdsync_PrepareString(atintermediate,ATCOMMAND_SIZE,"+CGDCONT: %d,",profileIndex); const char* interRespPtr[] = {atintermediate,NULL}; atcmdsync_ResultRef_t atRespPtr = NULL; result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+cgdcont?", &atRespPtr, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(atRespPtr); // Release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(atRespPtr) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(atRespPtr,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if ( FIND_STRING("+CGDCONT:",atcmd_GetLineParameter(line,1))) { if (numParam==7) { if(atoi(atcmd_GetLineParameter(line,2)) == profileIndex) { strncpy(profileDataPtr->apn, atcmd_GetLineParameter(line,4), PA_MDC_APN_MAX_BYTES); result = LE_OK; } else { LE_WARN("This is not the good profile %d", atoi(atcmd_GetLineParameter(line,2))); result = LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(atRespPtr); // Release atcmdsync_SendCommandDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mdc_GetGatewayAddress ( uint32_t profileIndex, ///< [IN] The profile to use char* gatewayAddrStr, ///< [OUT] The gateway IP address in dotted format size_t gatewayAddrStrSize ///< [IN] The size in bytes of the address buffer ) { le_result_t result=LE_NOT_POSSIBLE; char atcommand[ATCOMMAND_SIZE] ; char atintermediate[ATCOMMAND_SIZE]; atcmdsync_PrepareString(atintermediate,ATCOMMAND_SIZE,"+CGPADDR: %d,",profileIndex); const char* interRespPtr[] = {atintermediate,NULL}; atcmdsync_ResultRef_t atRespPtr = NULL; atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"at+cgpaddr=%d",profileIndex); result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), atcommand, &atRespPtr, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(atRespPtr); return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(atRespPtr) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(atRespPtr,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if (FIND_STRING("+CGPADDR:",atcmd_GetLineParameter(line,1))) { if (numParam==3) { if(atoi(atcmd_GetLineParameter(line,2)) == profileIndex) { const char* pAddr = atcmd_GetLineParameter(line,3); size_t length = strlen(pAddr); if (length-2 < gatewayAddrStrSize) { atcmd_CopyStringWithoutQuote(gatewayAddrStr,pAddr,gatewayAddrStrSize); result = LE_OK; } else { result = LE_OVERFLOW; } } else { LE_WARN("This is not the good profile %d", atoi(atcmd_GetLineParameter(line,2))); result = LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(atRespPtr); // Release atcmdsync_SendCommandDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- static void CREGUnsolHandler(void* reportPtr) { atmgr_UnsolResponse_t* unsolPtr = reportPtr; uint32_t numParam=0; le_mrc_NetRegState_t *statePtr; LE_DEBUG("Handler received -%s-",unsolPtr->line); numParam = atcmd_CountLineParameter(unsolPtr->line); if ( ThisMode == PA_MRC_ENABLE_REG_NOTIFICATION ) { if (numParam == 2) { statePtr = le_mem_ForceAlloc(RegStatePoolRef); switch(atoi(atcmd_GetLineParameter(unsolPtr->line,2))) { case 0: *statePtr = LE_MRC_REG_NONE; break; case 1: *statePtr = LE_MRC_REG_HOME; break; case 2: *statePtr = LE_MRC_REG_SEARCHING; break; case 3: *statePtr = LE_MRC_REG_DENIED; break; case 4: *statePtr = LE_MRC_REG_UNKNOWN; break; case 5: *statePtr = LE_MRC_REG_ROAMING; break; default: *statePtr = LE_MRC_REG_UNKNOWN; break; } LE_DEBUG("Send Event with state %d",*statePtr); le_event_ReportWithRefCounting(EventNewRcStatusId,statePtr); } else { LE_WARN("this Response pattern is not expected -%s-",unsolPtr->line); } } else if (ThisMode == PA_MRC_ENABLE_REG_LOC_NOTIFICATION) { if (numParam == 5) { statePtr = le_mem_ForceAlloc(RegStatePoolRef); switch(atoi(atcmd_GetLineParameter(unsolPtr->line,2))) { case 0: *statePtr = LE_MRC_REG_NONE; break; case 1: *statePtr = LE_MRC_REG_HOME; break; case 2: *statePtr = LE_MRC_REG_SEARCHING; break; case 3: *statePtr = LE_MRC_REG_DENIED; break; case 4: *statePtr = LE_MRC_REG_UNKNOWN; break; case 5: *statePtr = LE_MRC_REG_ROAMING; break; default: *statePtr = LE_MRC_REG_UNKNOWN; break; } LE_DEBUG("Send Event with state %d",*statePtr); le_event_ReportWithRefCounting(EventNewRcStatusId,statePtr); } else { LE_WARN("this Response pattern is not expected -%s-",unsolPtr->line); } } }