/**
Configure Module RF output power to meet FCC certification limits. This depends on the module
configuration (whether it has a range extender or not) and the region of the world where the module 
is used. The region of the world is set with DIP switches on the LaunchPad.
@param productId an identifier indicating which firmware version is loaded
@param moduleRegion which RF operating region. Only two are currently supported:
- 0x00: US
- 0x01: Europe

@note the method sysSetTxPower() only works with module firmware 2.5.1 and later. If an earlier
firmware is detected then the method will exit.
@pre productId > MINIMUM_BUILD_ID. It may still be invalid, though (e.g. 0x1E, which is not supported)
@note version 2.5.1 release 1 module firmware builds are configured as the following productIds:
- 0x10: No PA/LNA
- 0x11: Not Used
- 0x12: CC2590
- 0x13: CC2591

@note version 2.5.1 release 2 module firmware builds and RF power levels are as follows. 
The first number ("actual") is what is measured over the air.
The second number ("radio") is the value to use when calling sysSetTxPower.
The third number (in hex) is the corresponding PA_table value.
 - 0x20: No PA/LNA / A2530R24A  US:+4 actual/+3radio (0xF5); Europe:+4 actual/+3radio(0xF5)
 - 0x21: No PA/LNA / A2530R24C  US:+4 actual/+3radio (0xF5); Europe:+4 actual/+3radio(0xF5)
 - 0x22: CC2590                 US:+10 actual/+10radio(0xE5); Europe:+10 actual/+10radio(0xE5) Note: will never see in field
 - 0x23: CC2591/A2530E24A       US:+15 actual/+20radio(0xE5); Europe:+8 actual/+14radio(0x95)
 - 0x24: CC2591/A2530E24C       US:+13 actual/+18radio(0xC5); Europe:+8 actual/+14radio(0x95)

@note version 2.4.0 firmware builds have a productId of 0x7E
@see setModuleRfPower() in simple_api.c
*/
static moduleResult_t setModuleRfPower(uint8_t productId, uint16_t moduleRegion)
{
#ifdef MODULE_UTILITIES_VERBOSE
    printf("productId = %02X, moduleRegion = %04X\r\n", productId, moduleRegion);
#endif
    if ((productId == BUILD_ID_FW_2_4_0) || (!(IS_VALID_MODULE_TYPE(productId))))
    {
        printf("Using Default RF Setting\r\n");
        return MODULE_SUCCESS;
    }
    // Module Product Id:                   0xX0, 0xX1, 0xX2, 0xX3, 0xX4
    // US PA_TABLE Settings                 {0xF5, 0xF5, 0xE5, 0xE5, 0xC5};
    // EUROPE PA_TABLE Settings             {0xF5, 0xF5, 0xE5, 0x95, 0x95};
    // But we use the dB setting here for sysSetTxPower()
 uint8_t rfPowerLevelsUS[] =         {3, 3, 10, 20, 18};
 uint8_t rfPowerLevelsEurope[] =     {3, 3, 10,  14,  14};

     // Which table to use
    const uint8_t* rfPowerLevelTable;

    // The name of the operating region
    char* regionName;

    // Now, set which RF Power Level Table to use and region name based on moduleRegion setting
    if (moduleRegion & 0x01) // Only use Least significant bit; ignore others
    {
        regionName = "EU (E U R O P E)";
        rfPowerLevelTable = rfPowerLevelsEurope;
    } else {
        regionName = "US (U S A / C A N A D A)";
        rfPowerLevelTable = rfPowerLevelsUS;
    }

    // Get module name. This is stored in the module's User Description
    RETURN_RESULT_IF_FAIL(getConfigurationParameter(ZCD_NV_USERDESC), METHOD_SET_MODULE_RF_POWER);
    uint8_t* moduleName = zmBuf + ZB_READ_CONFIGURATION_START_OF_VALUE_FIELD + 1;

    // Warn the user about using incorrect region setting and tell them how to change it
    printf(" * ANAREN MODULE %s CONFIGURED FOR %s\r\n", moduleName, regionName);
    printf(" * WARNING: FOR COMPLIANCE, SELECT CORRECT OPERATING REGION\r\n");
#ifdef LAUNCHPAD_VERBOSE
    printf(" * SET SWITCH 1 ON S4 ON FOR US, OFF FOR EUROPE\r\n\r\n");
#endif

    // Get the RF power from the lookup table
    uint8_t rfPowerLevel = rfPowerLevelTable[(productId & MODULE_TYPE_MASK)];

    // Now, set the RF power. actualRfPowerLevel will be overwritten with the actual level set
    uint8_t actualRfPowerLevel = 0;
    moduleResult_t result = sysSetTxPower(rfPowerLevel, &actualRfPowerLevel);
#ifdef MODULE_UTILITIES_VERBOSE
    printf("Setting RF Power Level Set to %d; actual level = %d\r\n", rfPowerLevel, actualRfPowerLevel);
#endif
    return result;
   // return 0;
}
示例#2
0
void sendcmd(unsigned char * req, unsigned char cmdtype){
	switch (cmdtype)
	{
	case 0:
		sysPing();
		break;
	case 1:
		sysSetExtAddr((SetExtAddrFormat_t*) req);
		break;
	case 2:
		sysGetExtAddr();
		break;
	case 3:
		sysRamRead((RamReadFormat_t*) req);
		break;
	case 4:
		sysRamWrite((RamWriteFormat_t*) req);
		break;
	case 5:
		sysResetReq((ResetReqFormat_t*) req);
		break;
	case 6:
		sysVersion();
		break;
	case 7:
		sysOsalNvRead((OsalNvReadFormat_t*) req);
		break;
	case 8:
		sysOsalNvWrite((OsalNvWriteFormat_t*) req);
		break;
	case 9:
		sysOsalNvItemInit((OsalNvItemInitFormat_t*) req);
		break;
	case 10:
		sysOsalNvDelete((OsalNvDeleteFormat_t*) req);
		break;
	case 11:
		sysOsalNvLength((OsalNvLengthFormat_t*) req);
		break;
	case 12:
		sysOsalStartTimer((OsalStartTimerFormat_t*) req);
		break;
	case 13:
		sysOsalStopTimer((OsalStopTimerFormat_t*) req);
		break;
	case 14:
		sysStackTune((StackTuneFormat_t*) req);
		break;
	case 15:
		sysAdcRead((AdcReadFormat_t*) req);
		break;
	case 16:
		sysGpio((GpioFormat_t*) req);
		break;
	case 17:
		sysRandom();
		break;
	case 18:
		sysSetTime((SetTimeFormat_t*) req);
		break;
	case 19:
		sysGetTime();
		break;
	case 20:
		sysSetTxPower((SetTxPowerFormat_t*) req);
		break;
	case 21:
		afRegister((RegisterFormat_t*) req);
		break;
	case 22:
		afDataRequest((DataRequestFormat_t*) req);
		break;
	case 23:
		afDataRequestExt((DataRequestExtFormat_t*) req);
		break;
	case 24:
		afDataRequestSrcRtg((DataRequestSrcRtgFormat_t*) req);
		break;
	case 25:
		afInterPanCtl((InterPanCtlFormat_t*) req);
		break;
	case 26:
		afDataStore((DataStoreFormat_t*) req);
		break;
	case 27:
		afDataRetrieve((DataRetrieveFormat_t*) req);
		break;
	case 28:
		afApsfConfigSet((ApsfConfigSetFormat_t*) req);
		break;
	case 29:
		zdoNwkAddrReq((NwkAddrReqFormat_t*) req);
		break;
	case 30:
		zdoIeeeAddrReq((IeeeAddrReqFormat_t*) req);
		break;
	case 31:
		zdoNodeDescReq((NodeDescReqFormat_t*) req);
		break;
	case 32:
		zdoPowerDescReq((PowerDescReqFormat_t*) req);
		break;
	case 33:
		zdoSimpleDescReq((SimpleDescReqFormat_t*) req);
		break;
	case 34:
		zdoActiveEpReq((ActiveEpReqFormat_t*) req);
		break;
	case 35:
		zdoMatchDescReq((MatchDescReqFormat_t*) req);
		break;
	case 36:
		zdoComplexDescReq((ComplexDescReqFormat_t*) req);
		break;
	case 37:
		zdoUserDescReq((UserDescReqFormat_t*) req);
		break;
	case 38:
		zdoDeviceAnnce((DeviceAnnceFormat_t*) req);
		break;
	case 39:
		zdoUserDescSet((UserDescSetFormat_t*) req);
		break;
	case 40:
		zdoServerDiscReq((ServerDiscReqFormat_t*) req);
		break;
	case 41:
		zdoEndDeviceBindReq((EndDeviceBindReqFormat_t*) req);
		break;
	case 42:
		zdoBindReq((BindReqFormat_t*) req);
		break;
	case 43:
		zdoUnbindReq((UnbindReqFormat_t*) req);
		break;
	case 44:
		zdoMgmtNwkDiscReq((MgmtNwkDiscReqFormat_t*) req);
		break;
	case 45:
		zdoMgmtLqiReq((MgmtLqiReqFormat_t*) req);
		break;
	case 46:
		zdoMgmtRtgReq((MgmtRtgReqFormat_t*) req);
		break;
	case 47:
		zdoMgmtBindReq((MgmtBindReqFormat_t*) req);
		break;
	case 48:
		zdoMgmtLeaveReq((MgmtLeaveReqFormat_t*) req);
		break;
	case 49:
		zdoMgmtDirectJoinReq((MgmtDirectJoinReqFormat_t*) req);
		break;
	case 50:
		zdoMgmtPermitJoinReq((MgmtPermitJoinReqFormat_t*) req);
		break;
	case 51:
		zdoMgmtNwkUpdateReq((MgmtNwkUpdateReqFormat_t*) req);
		break;
	case 52:
		zdoStartupFromApp((StartupFromAppFormat_t*) req);
		break;
	case 53:
		zdoAutoFindDestination((AutoFindDestinationFormat_t*) req);
		break;
	case 54:
		zdoSetLinkKey((SetLinkKeyFormat_t*) req);
		break;
	case 55:
		zdoRemoveLinkKey((RemoveLinkKeyFormat_t*) req);
		break;
	case 56:
		zdoGetLinkKey((GetLinkKeyFormat_t*) req);
		break;
	case 57:
		zdoNwkDiscoveryReq((NwkDiscoveryReqFormat_t*) req);
		break;
	case 58:
		zdoJoinReq((JoinReqFormat_t*) req);
		break;
	case 59:
		zdoMsgCbRegister((MsgCbRegisterFormat_t*) req);
		break;
	case 60:
		zdoMsgCbRemove((MsgCbRemoveFormat_t*) req);
		break;
	case 61:
		zbSystemReset();
		break;
	case 62:
		zbAppRegisterReq((AppRegisterReqFormat_t*) req);
		break;
	case 63:
		zbStartReq();
		break;
	case 64:
		zbPermitJoiningReq((PermitJoiningReqFormat_t*) req);
		break;
	case 65:
		zbBindDevice((BindDeviceFormat_t*) req);
		break;
	case 66:
		zbAllowBind((AllowBindFormat_t*) req);
		break;
	case 67:
		zbSendDataReq((SendDataReqFormat_t*) req);
		break;
	case 68:
		zbFindDeviceReq((FindDeviceReqFormat_t*) req);
		break;
	case 69:
		zbWriteConfiguration((WriteConfigurationFormat_t*) req);
		break;
	case 70:
		zbGetDeviceInfo((GetDeviceInfoFormat_t*) req);
		break;
	case 71:
		zbReadConfiguration((ReadConfigurationFormat_t*) req);
		break;

	}

}