本文整理汇总了C++中ASSERT_ON_ERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ ASSERT_ON_ERROR函数的具体用法?C++ ASSERT_ON_ERROR怎么用?C++ ASSERT_ON_ERROR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ASSERT_ON_ERROR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/*
* Application's entry point
*/
int main(int argc, char** argv)
{
_i32 retVal = -1;
retVal = initializeAppVariables();
ASSERT_ON_ERROR(retVal);
/* Stop WDT and initialize the system-clock of the MCU
These functions needs to be implemented in PAL */
stopWDT();
initClk();
/* Configure command line interface */
CLI_Configure();
displayBanner();
/*
* Following function configures the device to default state by cleaning
* the persistent settings stored in NVMEM (viz. connection profiles &
* policies, power policy etc)
*
* Applications may choose to skip this step if the developer is sure
* that the device is in its default state at start of application
*
* Note that all profiles and persistent settings that were done on the
* device will be lost
*/
retVal = configureSimpleLinkToDefaultState();
if(retVal < 0)
{
if (DEVICE_NOT_IN_STATION_MODE == retVal)
{
CLI_Write(" Failed to configure the device in its default state \n\r");
}
LOOP_FOREVER();
}
CLI_Write(" Device is configured in default state \n\r");
/*
* Assumption is that the device is configured in station mode already
* and it is in its default state
*/
/* Initializing the CC3100 device */
retVal = sl_Start(0, 0, 0);
if ((retVal < 0) ||
(ROLE_STA != retVal) )
{
CLI_Write(" Failed to start the device \n\r");
LOOP_FOREVER();
}
CLI_Write(" Device started as STATION \n\r");
/* Set the power policy to always On (SL_ALWAYS_ON_POLICY)
* Both NWP and Wifi will remain active
* Other Valid options are:
* - SL_NORMAL_POLICY
* - SL_LOW_POWER_POLICY
* - SL_LONG_SLEEP_INTERVAL_POLICY
*
* For Long sleep policy the max sleep time can be defined by
* _u16 pBuff[4] = {0, 0, time, 0}, time:100-2000 in ms
* sl_WlanPolicySet(SL_POLICY_PM , SL_LONG_SLEEP_INTERVAL_POLICY, pBuff, sizeof(pBuff)*/
retVal = sl_WlanPolicySet(SL_POLICY_PM , SL_ALWAYS_ON_POLICY, NULL,0);
if(retVal < 0)
LOOP_FOREVER();
CLI_Write(" Power mode enabled \n\r");
/* Stop the CC3100 device */
retVal = sl_Stop(SL_STOP_TIMEOUT);
if(retVal < 0)
LOOP_FOREVER();
return 0;
}
示例2: GetData
//****************************************************************************
//
//! \brief Obtain the file from the server
//!
//! This function requests the file from the server and save it on serial flash.
//! To request a different file for different user needs to modify the
//! PREFIX_BUFFER macros.
//!
//! \param[in] cli - Instance of the HTTP connection
//!
//! \return 0 for success and negative for error
//
//****************************************************************************
static int GetData(HTTPCli_Handle cli)
{
long lRetVal = 0;
long fileHandle = -1;
unsigned long Token = 0;
int id;
int len=0;
bool moreFlag = 0;
HTTPCli_Field fields[3] = {
{HTTPCli_FIELD_NAME_HOST, HOST_NAME},
{HTTPCli_FIELD_NAME_ACCEPT, "text/html, application/xhtml+xml, */*"},
{NULL, NULL}
};
const char *ids[4] = {
HTTPCli_FIELD_NAME_CONTENT_LENGTH,
HTTPCli_FIELD_NAME_TRANSFER_ENCODING,
HTTPCli_FIELD_NAME_CONNECTION,
NULL
};
UART_PRINT("Start downloading the file\r\n");
// Set request fields
HTTPCli_setRequestFields(cli, fields);
memset(g_buff, 0, sizeof(g_buff));
// Make HTTP 1.1 GET request
lRetVal = HTTPCli_sendRequest(cli, HTTPCli_METHOD_GET, PREFIX_BUFFER, 0);
if (lRetVal < 0)
{
// error
ASSERT_ON_ERROR(TCP_SEND_ERROR);
}
// Test getResponseStatus: handle
lRetVal = HTTPCli_getResponseStatus(cli);
if (lRetVal != 200)
{
FlushHTTPResponse(cli);
if(lRetVal == 404)
{
ASSERT_ON_ERROR(FILE_NOT_FOUND_ERROR);
}
ASSERT_ON_ERROR(INVALID_SERVER_RESPONSE);
}
HTTPCli_setResponseFields(cli, ids);
// Read response headers
while ((id = HTTPCli_getResponseField(cli, (char *)g_buff, sizeof(g_buff), &moreFlag))
!= HTTPCli_FIELD_ID_END)
{
if(id == 0)
{
UART_PRINT("Content length: %s\n\r", g_buff);
}
else if(id == 1)
{
if(!strncmp((const char *)g_buff, "chunked", sizeof("chunked")))
{
UART_PRINT("Chunked transfer encoding\n\r");
}
}
else if(id == 2)
{
if(!strncmp((const char *)g_buff, "close", sizeof("close")))
{
ASSERT_ON_ERROR(FORMAT_NOT_SUPPORTED);
}
}
}
// Open file to save the downloaded file
lRetVal = sl_FsOpen((_u8 *)FILE_NAME, FS_MODE_OPEN_WRITE, &Token, &fileHandle);
if(lRetVal < 0)
{
// File Doesn't exit create a new of 40 KB file
lRetVal = sl_FsOpen((unsigned char *)FILE_NAME, \
FS_MODE_OPEN_CREATE(SIZE_40K, \
_FS_FILE_OPEN_FLAG_COMMIT|_FS_FILE_PUBLIC_WRITE),
&Token, &fileHandle);
ASSERT_ON_ERROR(lRetVal);
//.........这里部分代码省略.........
示例3: ConfigureSimpleLinkToDefaultState
//*****************************************************************************
//! \brief This function puts the device in its default state. It:
//! - Set the mode to STATION
//! - Configures connection policy to Auto and AutoSmartConfig
//! - Deletes all the stored profiles
//! - Enables DHCP
//! - Disables Scan policy
//! - Sets Tx power to maximum
//! - Sets power policy to normal
//! - Unregister mDNS services
//! - Remove all filters
//!
//! \param none
//! \return On success, zero is returned. On error, negative is returned
//*****************************************************************************
static long ConfigureSimpleLinkToDefaultState()
{
SlVersionFull ver = {0};
_WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0};
unsigned char ucVal = 1;
unsigned char ucConfigOpt = 0;
unsigned char ucConfigLen = 0;
unsigned char ucPower = 0;
long lRetVal = -1;
long lMode = -1;
lMode = sl_Start(0, 0, 0);
ASSERT_ON_ERROR(lMode);
// If the device is not in station-mode, try configuring it in station-mode
if (ROLE_STA != lMode)
{
if (ROLE_AP == lMode)
{
// If the device is in AP mode, we need to wait for this event
// before doing anything
while(!IS_IP_ACQUIRED(g_ulStatus))
{
#ifndef SL_PLATFORM_MULTI_THREADED
_SlNonOsMainLoopTask();
#endif
}
}
// Switch to STA role and restart
lRetVal = sl_WlanSetMode(ROLE_STA);
ASSERT_ON_ERROR(lRetVal);
lRetVal = sl_Stop(0xFF);
ASSERT_ON_ERROR(lRetVal);
lRetVal = sl_Start(0, 0, 0);
ASSERT_ON_ERROR(lRetVal);
// Check if the device is in station again
if (ROLE_STA != lRetVal)
{
// We don't want to proceed if the device is not coming up in STA-mode
return DEVICE_NOT_IN_STATION_MODE;
}
}
// Get the device's version-information
ucConfigOpt = SL_DEVICE_GENERAL_VERSION;
ucConfigLen = sizeof(ver);
lRetVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &ucConfigOpt,
&ucConfigLen, (unsigned char *)(&ver));
ASSERT_ON_ERROR(lRetVal);
UART_PRINT("Host Driver Version: %s\n\r",SL_DRIVER_VERSION);
UART_PRINT("Build Version %d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d\n\r",
ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3],
ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1],
ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3],
ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1],
ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3]);
// Set connection policy to Auto + SmartConfig
// (Device's default connection policy)
lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0);
ASSERT_ON_ERROR(lRetVal);
// Remove all profiles
lRetVal = sl_WlanProfileDel(0xFF);
ASSERT_ON_ERROR(lRetVal);
//
// Device in station-mode. Disconnect previous connection if any
// The function returns 0 if 'Disconnected done', negative number if already
// disconnected Wait for 'disconnection' event if 0 is returned, Ignore
// other return-codes
//
lRetVal = sl_WlanDisconnect();
if(0 == lRetVal)
{
//.........这里部分代码省略.........
示例4: Network_IF_InitDriver
//*****************************************************************************
//
//! Network_IF_InitDriver
//! The function initializes a CC3200 device and triggers it to start operation
//!
//! \param uiMode (device mode in which device will be configured)
//!
//! \return 0 : sucess, -ve : failure
//
//*****************************************************************************
long
Network_IF_InitDriver(unsigned int uiMode)
{
long lRetVal = -1;
// Reset CC3200 Network State Machine
InitializeAppVariables();
//
// Following function configure the device to default state by cleaning
// the persistent settings stored in NVMEM (viz. connection profiles &
// policies, power policy etc)
//
// Applications may choose to skip this step if the developer is sure
// that the device is in its default state at start of application
//
// Note that all profiles and persistent settings that were done on the
// device will be lost
//
lRetVal = ConfigureSimpleLinkToDefaultState();
if(lRetVal < 0)
{
if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
UART_PRINT("Failed to configure the device in its default state \n\r");
LOOP_FOREVER();
}
UART_PRINT("Device is configured in default state \n\r");
//
// Assumption is that the device is configured in station mode already
// and it is in its default state
//
lRetVal = sl_Start(NULL,NULL,NULL);
if (lRetVal < 0 || lRetVal != ROLE_STA)
{
UART_PRINT("Failed to start the device \n\r");
LOOP_FOREVER();
}
UART_PRINT("Started SimpleLink Device: STA Mode\n\r");
if(uiMode == ROLE_AP)
{
UART_PRINT("Switching to AP mode on application request\n\r");
// Switch to AP role and restart
lRetVal = sl_WlanSetMode(uiMode);
ASSERT_ON_ERROR(lRetVal);
lRetVal = sl_Stop(0xFF);
lRetVal = sl_Start(0, 0, 0);
ASSERT_ON_ERROR(lRetVal);
// Check if the device is up in AP Mode
if (ROLE_AP == lRetVal)
{
// If the device is in AP mode, we need to wait for this event
// before doing anything
while(!IS_IP_ACQUIRED(g_ulStatus))
{
#ifndef SL_PLATFORM_MULTI_THREADED
_SlNonOsMainLoopTask();
#else
osi_Sleep(1);
#endif
}
}
else
{
// We don't want to proceed if the device is not coming up in AP-mode
ASSERT_ON_ERROR(DEVICE_NOT_IN_AP_MODE);
}
UART_PRINT("Re-started SimpleLink Device: AP Mode\n\r");
}
else if(uiMode == ROLE_P2P)
{
UART_PRINT("Switching to P2P mode on application request\n\r");
// Switch to AP role and restart
lRetVal = sl_WlanSetMode(uiMode);
ASSERT_ON_ERROR(lRetVal);
lRetVal = sl_Stop(0xFF);
lRetVal = sl_Start(0, 0, 0);
ASSERT_ON_ERROR(lRetVal);
//.........这里部分代码省略.........
示例5: WlanConnect
//.........这里部分代码省略.........
//! \return 0 means success, -1 means failure
//!
//! \note
//!
//! \warning If the WLAN connection fails or we don't aquire an IP address,
//! We will be stuck in this function forever.
//
//*****************************************************************************
int WlanConnect()
{
int iRetCode = 0;
int iRetVal = 0;
int iConnect = 0;
unsigned char ucQueueMsg = 0;
SlSecParams_t secParams;
secParams.Key = (signed char *)SECURITY_KEY;
secParams.KeyLen = strlen((const char *)secParams.Key);
secParams.Type = SECURITY_TYPE;
//
// Set up the watchdog interrupt handler.
//
WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS));
/* Enabling the Sleep clock for the Watch Dog Timer*/
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_SLP_MODE_CLK);
g_ucFeedWatchdog = 1;
g_ucWdogCount = 0;
while(!(ucQueueMsg & (EVENT_IP_ACQUIRED|CONNECTION_FAILED)))
{
UART_PRINT("Trying to connect to AP: ");
UART_PRINT(SSID_NAME);
UART_PRINT("\n\r");
sl_WlanConnect((signed char *)SSID_NAME,
strlen((const char *)SSID_NAME), 0, &secParams, 0);
iConnect = 0;
do{
osi_MsgQRead(&g_tConnection, &ucQueueMsg, OSI_WAIT_FOREVER);
switch(ucQueueMsg)
{
case EVENT_CONNECTION:
iConnect = 1;
break;
case EVENT_IP_ACQUIRED:
iRetVal = 0;
break;
case WDOG_EXPIRED:
//
// disconnect from the Access Point
//
if(iConnect)
{
WlanDisconnect();
}
//
// stop the simplelink with reqd. timeout value (30 ms)
//
sl_Stop(SL_STOP_TIMEOUT);
UART_PRINT("sl stop\n\r");
MAP_UtilsDelay(8000);
//
// starting the simplelink
//
sl_Start(NULL, NULL, NULL);
UART_PRINT("sl start\n\r");
break;
case EVENT_DISCONNECTION:
iConnect = 0;
break;
case CONNECTION_FAILED:
iRetVal = -1;
break;
default:
UART_PRINT("unexpected event\n\r");
break;
}
}while(ucQueueMsg == (unsigned char)EVENT_CONNECTION);
}
iRetCode = MAP_WatchdogRunning(WDT_BASE);
if(iRetCode)
{
WDT_IF_DeInit();
MAP_PRCMPeripheralClkDisable(PRCM_WDT, PRCM_RUN_MODE_CLK);
}
ASSERT_ON_ERROR(iRetVal);
return(iRetVal);
}
示例6: ConnectToNetwork
long ConnectToNetwork()
{
long lRetVal = -1;
unsigned int uiConnectTimeoutCnt =0;
//Start Simplelink Device
lRetVal = sl_Start(NULL,NULL,NULL);
ASSERT_ON_ERROR(lRetVal);
if(lRetVal != ROLE_STA)
{
if (ROLE_AP == lRetVal)
{
// If the device is in AP mode, we need to wait for this event
// before doing anything
while(!IS_IP_ACQUIRED(g_ulStatus))
{
#ifndef SL_PLATFORM_MULTI_THREADED
_SlNonOsMainLoopTask();
#endif
}
}
//
// Configure to STA Mode
//
lRetVal = ConfigureMode(ROLE_STA);
if(lRetVal !=ROLE_STA)
{
UART_PRINT("Unable to set STA mode...\n\r");
lRetVal = sl_Stop(SL_STOP_TIMEOUT);
CLR_STATUS_BIT_ALL(g_ulStatus);
return DEVICE_NOT_IN_STATION_MODE;
}
}
//waiting for the device to Auto Connect
while(uiConnectTimeoutCnt<AUTO_CONNECTION_TIMEOUT_COUNT &&
((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))))
{
//Turn Green LED On
GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
osi_Sleep(50);
//Turn Green LED Off
GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
osi_Sleep(50);
uiConnectTimeoutCnt++;
}
//Couldn't connect Using Auto Profile
if(uiConnectTimeoutCnt==AUTO_CONNECTION_TIMEOUT_COUNT)
{
CLR_STATUS_BIT_ALL(g_ulStatus);
//Turn Green LED On
GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
//Connect Using Smart Config
lRetVal = SmartConfigConnect();
ASSERT_ON_ERROR(lRetVal);
//Waiting for the device to Auto Connect
while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
{
MAP_UtilsDelay(500);
}
//Turn Green LED Off
GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
}
return SUCCESS;
}
示例7: BsdTcpServer
//****************************************************************************
//
//! \brief Opening a server side socket and receiving data
//!
//! This function opens a TCP socket in Listen mode and waits for an incoming
//! TCP connection. If a socket connection is established then the function
//! will try to read 1000 TCP packets from the connected client.
//!
//! \param[in] port number on which the server will be listening on
//!
//! \return 0 on success, -1 on Error.
//!
//! \note This function will wait for an incoming connection till one
//! is established
//
//****************************************************************************
static int BsdTcpServer(unsigned short Port)
{
SlSockAddrIn_t Addr;
SlSockAddrIn_t LocalAddr;
int idx;
int AddrSize;
int SockID;
int Status;
int newSockID;
long LoopCount = 0;
long nonBlocking = 1;
for (idx=0 ; idx<BUF_SIZE ; idx++)
{
uBuf.BsdBuf[idx] = (char)(idx % 10);
}
LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons((unsigned short)Port);
LocalAddr.sin_addr.s_addr = 0;
SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
ASSERT_ON_ERROR(SockID);
AddrSize = sizeof(SlSockAddrIn_t);
Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
if( Status < 0 )
{
/* error */
sl_Close(SockID);
ASSERT_ON_ERROR(Status);
}
Status = sl_Listen(SockID, 0);
if( Status < 0 )
{
sl_Close(SockID);
ASSERT_ON_ERROR(Status);
}
Status = sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING,
&nonBlocking, sizeof(nonBlocking));
ASSERT_ON_ERROR(Status);
newSockID = SL_EAGAIN;
while( newSockID < 0 && IS_IP_ACQUIRED(g_ulStatus))
{
newSockID = sl_Accept(SockID, ( struct SlSockAddr_t *)&Addr,
(SlSocklen_t*)&AddrSize);
if( newSockID == SL_EAGAIN )
{
/* Wait for 1 ms */
Delay(1);
}
else if( newSockID < 0 )
{
sl_Close(SockID);
ASSERT_ON_ERROR(newSockID);
}
}
if(! IS_IP_ACQUIRED(g_ulStatus))
{
return CLIENT_DISCONNECTED;
}
// run 'iperf -c <device IP> -i 1 -t 10000' command on PC/Smartphone
while (LoopCount < TCP_PACKET_COUNT)
{
Status = sl_Recv(newSockID, uBuf.BsdBuf, BUF_SIZE, 0);
if( Status <= 0 )
{
/* error */
ASSERT_ON_ERROR(sl_Close(newSockID));
ASSERT_ON_ERROR(sl_Close(SockID));
ASSERT_ON_ERROR(Status);
}
LoopCount++;
}
GPIO_IF_LedOn(MCU_EXECUTE_SUCCESS_IND);
ASSERT_ON_ERROR(sl_Close(newSockID));
ASSERT_ON_ERROR(sl_Close(SockID));
//.........这里部分代码省略.........
示例8: RxStatisticsCollect
//*****************************************************************************
//
//! RxStatisticsCollect
//!
//! This function
//! 1. Function for performing the statistics by listening on the
//! channel given by the user.
//!
//! \return none
//
//*****************************************************************************
static int RxStatisticsCollect()
{
int iSoc;
char acBuffer[1500];
SlGetRxStatResponse_t rxStatResp;
//char cChar;
int iIndex;
int iChannel;
long lRetVal = -1;
int iRightInput = 0;
char acCmdStore[512];
struct SlTimeval_t timeval;
timeval.tv_sec = 0; // Seconds
timeval.tv_usec = 20000; // Microseconds.
//
//Clear all fields to defaults
//
rxStatResp.ReceivedValidPacketsNumber = 0;
rxStatResp.ReceivedFcsErrorPacketsNumber = 0;
rxStatResp.ReceivedAddressMismatchPacketsNumber = 0;
rxStatResp.AvarageMgMntRssi = 0;
rxStatResp.AvarageDataCtrlRssi = 0;
for(iIndex = 0 ; iIndex < SIZE_OF_RSSI_HISTOGRAM ; iIndex++)
{
rxStatResp.RssiHistogram[iIndex] = 0;
}
for(iIndex = 0 ; iIndex < NUM_OF_RATE_INDEXES ; iIndex++)
{
rxStatResp.RateHistogram[iIndex] = 0;
}
rxStatResp.GetTimeStamp = 0;
rxStatResp.StartTimeStamp = 0;
//
//Prompt the user for channel number
//
do
{
UART_PRINT("\n\rEnter the channel to listen[1-13]:");
//
// Wait to receive a character over UART
//
lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
if(lRetVal == 0)
{
//
// No input. Just an enter pressed probably. Display a prompt.
//
UART_PRINT("\n\rEnter Valid Input.");
iRightInput = 0;
}
else
{
iChannel = (int)strtoul(acCmdStore,0,10);
if(iChannel <= 0 || iChannel > 13)
{
UART_PRINT("\n\rWrong Input");
iRightInput = 0;
}
else
{
iRightInput = 1;
}
}
}while(!iRightInput);
UART_PRINT("\n\rPress any key to start collecting statistics...");
//
// Wait to receive a character over UART
//
MAP_UARTCharGet(CONSOLE);
//
//Start Rx statistics collection
//
lRetVal = sl_WlanRxStatStart();
ASSERT_ON_ERROR(lRetVal);
//
//Open Socket on the channel to listen
//
iSoc = sl_Socket(SL_AF_RF,SL_SOCK_RAW,iChannel);
ASSERT_ON_ERROR(iSoc);
//.........这里部分代码省略.........
示例9: CreateFilters
//*****************************************************************************
//
//!This function creates rx filters. Two filters are defined in this example:
//!(1) Drop incoming packets according to source MAC address
//!(2) Drop incoming packets according to source IP address
//!
//! \param None
//!
//! \return 0 on success, -1 on failure
//!
//*****************************************************************************
static int CreateFilters()
{
long lRetVal;
SlrxFilterID_t FilterId = 0;
SlrxFilterRuleType_t RuleType;
SlrxFilterFlags_t FilterFlags;
SlrxFilterRule_t Rule;
SlrxFilterTrigger_t Trigger;
SlrxFilterAction_t Action;
unsigned char ucMacMask[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char ucIPMask[4] = {0xFF, 0xFF, 0xFF, 0xFF};
/*************************************************************************/
/* Build filter to drop incoming packets according to source MAC address */
/*************************************************************************/
//
//define filter as parent
//
Trigger.ParentFilterID = 0;
//
//no trigger to activate the filter.
//
Trigger.Trigger = NO_TRIGGER;
//
//connection state and role
//
Trigger.TriggerArgConnectionState.IntRepresentation = \
RX_FILTER_CONNECTION_STATE_STA_CONNECTED;
Trigger.TriggerArgRoleStatus.IntRepresentation = RX_FILTER_ROLE_STA;
//
// header and Combination types are only supported. Combination for logical
// AND/OR between two filters
//
RuleType = HEADER;
Rule.HeaderType.RuleHeaderfield = MAC_SRC_ADDRESS_FIELD;
memcpy( Rule.HeaderType.RuleHeaderArgsAndMask.RuleHeaderArgs.RxFilterDB6BytesRuleArgs[0],
g_ucMacAddress , SL_MAC_ADDR_LEN);
memcpy( Rule.HeaderType.RuleHeaderArgsAndMask.RuleHeaderArgsMask, ucMacMask,
SL_MAC_ADDR_LEN);
Rule.HeaderType.RuleCompareFunc = COMPARE_FUNC_EQUAL;
//
//Action
//
Action.ActionType.IntRepresentation = RX_FILTER_ACTION_DROP;
FilterFlags.IntRepresentation = RX_FILTER_BINARY;
lRetVal = sl_WlanRxFilterAdd(RuleType, FilterFlags, &Rule, &Trigger,
&Action, &FilterId);
ASSERT_ON_ERROR(lRetVal);
/*************************************************************************/
/* Build filter to drop incoming packets according to source IP address */
/*************************************************************************/
//
//define filter as parent
//
Trigger.ParentFilterID = 0;
//
//no trigger to activate the filter.
//
Trigger.Trigger = NO_TRIGGER;
//
//connection state and role
//
Trigger.TriggerArgConnectionState.IntRepresentation = \
RX_FILTER_CONNECTION_STATE_STA_CONNECTED;
Trigger.TriggerArgRoleStatus.IntRepresentation = RX_FILTER_ROLE_STA;
//
// header and Combination types are only supported. Combination for logical
// AND/OR between two filters
//
RuleType = HEADER;
Rule.HeaderType.RuleHeaderfield = IPV4_SRC_ADRRESS_FIELD;
memcpy(Rule.HeaderType.RuleHeaderArgsAndMask.RuleHeaderArgs.RxFilterDB4BytesRuleArgs[0],
g_ucIpAddress , IP_ADDR_LENGTH);
memcpy(Rule.HeaderType.RuleHeaderArgsAndMask.RuleHeaderArgsMask, ucIPMask,
IP_ADDR_LENGTH);
Rule.HeaderType.RuleCompareFunc = COMPARE_FUNC_EQUAL;
//
//.........这里部分代码省略.........
示例10: BsdTcpServer
//*****************************************************************************
//
//! This function opens a TCP socket in Listen mode and waits for an incoming
//! TCP connection.. If a socket connection is established then the function
//! will try to read 1000 TCP packets from the connected client.
//!
//! \param port number on which the server will be listening on
//!
//! \return 0 on success, -ve on Error.
//!
//*****************************************************************************
static long BsdTcpServer(unsigned short Port)
{
SlSockAddrIn_t Addr;
SlSockAddrIn_t LocalAddr;
int indexCount,iAddrSize,SockID,iStatus,newSockID;
long LoopCount = 0;
long nonBlocking = 1;
SlTimeval_t timeVal;
for (indexCount=0 ; indexCount<BUF_SIZE ; indexCount++)
{
g_uBuf.cBsdBuf[indexCount] = (char)(indexCount % 10);
}
LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons((unsigned short)Port);
LocalAddr.sin_addr.s_addr = 0;
SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
ASSERT_ON_ERROR(SockID);
iAddrSize = sizeof(SlSockAddrIn_t);
iStatus = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, iAddrSize);
if( iStatus < 0 )
{
// error
ASSERT_ON_ERROR(sl_Close(SockID));
ASSERT_ON_ERROR(iStatus);
}
iStatus = sl_Listen(SockID, 0);
if( iStatus < 0 )
{
sl_Close(SockID);
ASSERT_ON_ERROR(iStatus);
}
iStatus = sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING, \
&nonBlocking,
sizeof(nonBlocking));
newSockID = SL_EAGAIN;
while( newSockID < 0 )
{
newSockID = sl_Accept(SockID, ( struct SlSockAddr_t *)&Addr,
(SlSocklen_t*)&iAddrSize);
if( newSockID == SL_EAGAIN )
{
MAP_UtilsDelay(80000);
}
else if( newSockID < 0 )
{
ASSERT_ON_ERROR(sl_Close(SockID));
// error
ASSERT_ON_ERROR(newSockID);
}
}
timeVal.tv_sec = 1;
timeVal.tv_usec = 0;
if( newSockID >= 0 )
{
iStatus = sl_SetSockOpt(newSockID, SL_SOL_SOCKET, SL_SO_RCVTIMEO,
&timeVal, sizeof(timeVal));
ASSERT_ON_ERROR(iStatus);
}
while (LoopCount < PACKET_COUNT)
{
iStatus = sl_Recv(newSockID, g_uBuf.cBsdBuf, BUF_SIZE, 0);
if( iStatus <= 0 )
{
// error
ASSERT_ON_ERROR(sl_Close(newSockID));
ASSERT_ON_ERROR(sl_Close(SockID));
ASSERT_ON_ERROR(iStatus);
}
LoopCount++;
}
ASSERT_ON_ERROR(sl_Close(newSockID));
ASSERT_ON_ERROR(sl_Close(SockID));
return 0;
}
示例11: wlan_set_channel
STATIC void wlan_set_channel (uint8_t channel) {
wlan_obj.channel = channel;
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_CHANNEL, 1, &channel));
}
示例12: wlan_set_mode
STATIC void wlan_set_mode (uint mode) {
wlan_obj.mode = mode;
ASSERT_ON_ERROR(sl_WlanSetMode(mode));
}
示例13: wlan_sl_init
void wlan_sl_init (int8_t mode, const char *ssid, uint8_t ssid_len, uint8_t auth, const char *key, uint8_t key_len,
uint8_t channel, uint8_t antenna, bool add_mac) {
// stop the servers
wlan_servers_stop();
// do a basic start
wlan_first_start();
// close any active connections
wlan_sl_disconnect();
// Remove all profiles
ASSERT_ON_ERROR(sl_WlanProfileDel(0xFF));
// Enable the DHCP client
uint8_t value = 1;
ASSERT_ON_ERROR(sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE, 1, 1, &value));
// Set PM policy to normal
ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0));
// Unregister mDNS services
ASSERT_ON_ERROR(sl_NetAppMDNSUnRegisterService(0, 0));
// Stop the internal HTTP server
sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
// Remove all 64 filters (8 * 8)
_WlanRxFilterOperationCommandBuff_t RxFilterIdMask;
memset ((void *)&RxFilterIdMask, 0 ,sizeof(RxFilterIdMask));
memset(RxFilterIdMask.FilterIdMask, 0xFF, 8);
ASSERT_ON_ERROR(sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)));
#if MICROPY_HW_ANTENNA_DIVERSITY
// set the antenna type
wlan_set_antenna (antenna);
#endif
// switch to the requested mode
wlan_set_mode(mode);
// stop and start again (we need to in the propper mode from now on)
wlan_reenable(mode);
// Set Tx power level for station or AP mode
// Number between 0-15, as dB offset from max power - 0 will set max power
uint8_t ucPower = 0;
if (mode == ROLE_AP) {
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_AP_TX_POWER, sizeof(ucPower),
(unsigned char *)&ucPower));
// configure all parameters
wlan_set_ssid (ssid, ssid_len, add_mac);
wlan_set_security (auth, key, key_len);
wlan_set_channel (channel);
// set the country
_u8* country = (_u8*)"EU";
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE, 2, country));
SlNetCfgIpV4Args_t ipV4;
ipV4.ipV4 = (_u32)SL_IPV4_VAL(192,168,1,1); // _u32 IP address
ipV4.ipV4Mask = (_u32)SL_IPV4_VAL(255,255,255,0); // _u32 Subnet mask for this AP
ipV4.ipV4Gateway = (_u32)SL_IPV4_VAL(192,168,1,1); // _u32 Default gateway address
ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(192,168,1,1); // _u32 DNS server address
ASSERT_ON_ERROR(sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE, IPCONFIG_MODE_ENABLE_IPV4,
sizeof(SlNetCfgIpV4Args_t), (_u8 *)&ipV4));
SlNetAppDhcpServerBasicOpt_t dhcpParams;
dhcpParams.lease_time = 4096; // lease time (in seconds) of the IP Address
dhcpParams.ipv4_addr_start = SL_IPV4_VAL(192,168,1,2); // first IP Address for allocation.
dhcpParams.ipv4_addr_last = SL_IPV4_VAL(192,168,1,254); // last IP Address for allocation.
ASSERT_ON_ERROR(sl_NetAppStop(SL_NET_APP_DHCP_SERVER_ID)); // Stop DHCP server before settings
ASSERT_ON_ERROR(sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT,
sizeof(SlNetAppDhcpServerBasicOpt_t), (_u8* )&dhcpParams)); // set parameters
ASSERT_ON_ERROR(sl_NetAppStart(SL_NET_APP_DHCP_SERVER_ID)); // Start DHCP server with new settings
// stop and start again
wlan_reenable(mode);
} else { // STA and P2P modes
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER,
sizeof(ucPower), (unsigned char *)&ucPower));
// set connection policy to Auto + Fast (tries to connect to the last connected AP)
ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 1, 0, 0, 0), NULL, 0));
}
// set current time and date (needed to validate certificates)
wlan_set_current_time (pyb_rtc_get_seconds());
// start the servers before returning
wlan_servers_start();
}
示例14: SetConnectionPolicy
//****************************************************************************
//
//! \brief Configuring the Connection Policy
//!
//! This function configures different Connection Policy such as FAST,AUTO,OPEN
//!
//! \param[in] None
//!
//! \return 0 on success else error code
//!
//! \note
//
//****************************************************************************
static long SetConnectionPolicy()
{
unsigned char policyVal;
long lRetVal = -1;
/* Clear all stored profiles and reset the policies */
lRetVal = sl_WlanProfileDel(0xFF);
ASSERT_ON_ERROR(lRetVal);
lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), 0, 0);
ASSERT_ON_ERROR(lRetVal);
//Add Profile
/* user needs to change SSID_NAME = "<Secured AP>"
SECURITY_TYPE = SL_SEC_TYPE_WPA
SECURITY_KEY = "<password>"
and set the priority as per requirement
to connect with a secured AP */
SlSecParams_t secParams;
secParams.Key = SECURITY_KEY;
secParams.KeyLen = strlen(SECURITY_KEY);
secParams.Type = SECURITY_TYPE;
lRetVal = sl_WlanProfileAdd(SSID_NAME,strlen(SSID_NAME),0,&secParams,0,1,0);
ASSERT_ON_ERROR(lRetVal);
//set AUTO policy
lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
SL_CONNECTION_POLICY(1,0,0,0,0),
&policyVal, 1 /*PolicyValLen*/);
ASSERT_ON_ERROR(lRetVal);
//wait until IP is acquired
while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
{
_SlNonOsMainLoopTask();
}
CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
//
// ****** Put breakpoint here ******
// If control comes here- means device connected to AP in auto mode
//
// Disconnect from AP
lRetVal = sl_WlanDisconnect();
if(0 == lRetVal)
{
// Wait
while(IS_CONNECTED(g_ulStatus))
{
#ifndef SL_PLATFORM_MULTI_THREADED
_SlNonOsMainLoopTask();
#endif
}
}
//delete profiles
lRetVal = sl_WlanProfileDel(0xFF);
ASSERT_ON_ERROR(lRetVal);
//set Auto SmartConfig policy
lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
SL_CONNECTION_POLICY(1,0,0,0,1),
&policyVal,0);
ASSERT_ON_ERROR(lRetVal);
// reset the NWP
lRetVal = ResetNwp();
ASSERT_ON_ERROR(lRetVal);
// wait for smart config to complete and device to connect to an AP
//wait until IP is acquired
while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
{
_SlNonOsMainLoopTask();
}
CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
//
// ****** Put breakpoint here ******
// If control comes here- means device connected to AP in smartconfig mode
//
/* Delete all profiles (0xFF) stored */
//.........这里部分代码省略.........
示例15: UARTCommandHandler
//.........这里部分代码省略.........
*pcOfemailmessage++ = usBuffer[iIndex];
}
}
iIndex++;
}
*pcOfemailmessage= '\0';
/* TODO here unsigned char is converting to char */
DispatcherUartSendPacket((char*)pucUARTOKString, \
sizeof(pucUARTOKString));
break;
//**********************************************
// Case 05: Send email message using configurations
//**********************************************
case UART_COMMAND_EMAIL_SEND:
{
// reset Orange LED state
GPIO_IF_LedOff(MCU_SENDING_DATA_IND);
// TODO: If no destination email given, default to hardcoded value
SlNetAppEmailOpt_t eMailServerSetting;
lRetVal = Network_IF_GetHostIP(GMAIL_HOST_NAME, &eMailServerSetting.Ip);
if(lRetVal >= 0)
{
eMailServerSetting.Family = AF_INET;
eMailServerSetting.Port = GMAIL_HOST_PORT;
eMailServerSetting.SecurityMethod = SL_SO_SEC_METHOD_SSLV3;
eMailServerSetting.SecurityCypher = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5;
lRetVal = sl_NetAppEmailSet(SL_NET_APP_EMAIL_ID, \
NETAPP_ADVANCED_OPT, \
sizeof(SlNetAppEmailOpt_t), \
(unsigned char*)&eMailServerSetting);
ASSERT_ON_ERROR(lRetVal);
}
else
{
UART_PRINT("Error:%d GetHostIP.", lRetVal);
return -1;
}
g_cConnectStatus = sl_NetAppEmailConnect();
// If return -1, throw connect error
if(g_cConnectStatus == -1)
{
DispatcherUartSendPacket((char*)pucUARTErrorSocketCreateString, \
sizeof(pucUARTErrorSocketCreateString));
}
// If return -2, throw socket option error
if(g_cConnectStatus == -2)
{
DispatcherUartSendPacket((char*)pucUARTErrorSocketOptionString, \
sizeof(pucUARTErrorSocketOptionString));
}
if(g_cConnectStatus == 0)
{
SlNetAppServerError_t sEmailErrorInfo;
long lRetCode = SL_EMAIL_ERROR_FAILED;
if((lRetCode = sl_NetAppEmailSend(pcEmailto,pcEmailsubject, \
pcEmailmessage, \
&sEmailErrorInfo)) == SL_EMAIL_ERROR_NONE)
{
// Blink LED7 to indicate email has been sent
for(iIndex=0 ;iIndex<5 ;iIndex++)
{
MAP_UtilsDelay(6000000);