Exemplo n.º 1
0
//*****************************************************************************
//
//! \brief This function handles network events such as IP acquisition, IP
//!           leased, IP released etc.
//!
//! \param[in]  pNetAppEvent - Pointer to NetApp Event Info 
//!
//! \return None
//!
//*****************************************************************************
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
    switch(pNetAppEvent->Event)
    {
        case SL_NETAPP_IPV4_ACQUIRED:
        case SL_NETAPP_IPV6_ACQUIRED:
        {
            SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        }
        break;
        
        case SL_NETAPP_IP_LEASED:
        {
            SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_LEASED);
        
            g_ulStaIp = (pNetAppEvent)->EventData.ipLeased.ip_address;
            
            UART_PRINT("[NETAPP EVENT] IP Leased to Client: IP=%d.%d.%d.%d , ",
                        SL_IPV4_BYTE(g_ulStaIp,3), SL_IPV4_BYTE(g_ulStaIp,2),
                        SL_IPV4_BYTE(g_ulStaIp,1), SL_IPV4_BYTE(g_ulStaIp,0));
        }
        break;
        
        default:
        {
            UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r",
                       pNetAppEvent->Event);
        }
        break;
    }
}
Exemplo n.º 2
0
//****************************************************************************
//
//! Confgiures the mode in which the device will work
//!
//! \param iMode is the current mode of the device
//!
//! This function
//!    1. prompt user for desired configuration and accordingly configure the
//!          networking mode(STA or AP).
//!       2. also give the user the option to configure the ssid name in case of
//!       AP mode.
//!
//! \return sl_start return value(int).
//
//****************************************************************************
static int ConfigureMode(int iMode)
{
    char    pcSsidName[33];
    long   retVal = -1;

    UART_PRINT("Enter the AP SSID name: ");
    GetSsidName(pcSsidName,33);

    retVal = sl_WlanSetMode(ROLE_AP);
    ASSERT_ON_ERROR(__LINE__, retVal);

    retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen(pcSsidName),
                            (unsigned char*)pcSsidName);
    ASSERT_ON_ERROR(__LINE__, retVal);

    UART_PRINT("Device is configured in AP mode\n\r");

    /* Restart Network processor */
    retVal = sl_Stop(SL_STOP_TIMEOUT);
    ASSERT_ON_ERROR(__LINE__, retVal);

    // reset status bits
    CLR_STATUS_BIT_ALL(g_ulStatus);

    return sl_Start(NULL,NULL,NULL);
}
Exemplo n.º 3
0
//*****************************************************************************
//
//! Check the device mode and switch to P2P mode
//! restart the NWP to activate P2P mode
//!
//! \param  None
//!
//! \return status code - Success:0, Failure:-ve
//
//*****************************************************************************
long StartDeviceInP2P()
{
    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);
    ASSERT_ON_ERROR(lRetVal);

    if(lRetVal != ROLE_P2P)
    {
        lRetVal = sl_WlanSetMode(ROLE_P2P);
        ASSERT_ON_ERROR(lRetVal);

        lRetVal = sl_Stop(0xFF);

        // reset the Status bits
        CLR_STATUS_BIT_ALL(g_ulStatus);

        lRetVal = sl_Start(NULL,NULL,NULL);
        if(lRetVal < 0 || lRetVal != ROLE_P2P)
        {
            ASSERT_ON_ERROR(P2P_MODE_START_FAILED);
        }
        else
        {
            UART_PRINT("Started SimpleLink Device: P2P Mode\n\r");
            return SUCCESS;
        }
    }

    return SUCCESS;
}
Exemplo n.º 4
0
//****************************************************************************
//
//! \brief This function handles events for IP address acquisition via DHCP
//!           indication
//!
//! \param[in]    pNetAppEvent is the event passed to the handler
//!
//! \return     None
//
//****************************************************************************
void sl_NetAppEvtHdlr(SlNetAppEvent_t *pNetAppEvent)
{
    unsigned char ucQueueMsg = 0;
    switch(pNetAppEvent->Event)
    {
    case SL_NETAPP_IPV4_IPACQUIRED_EVENT:
    case SL_NETAPP_IPV6_IPACQUIRED_EVENT:
        g_ulIpAddr = pNetAppEvent->EventData.ipAcquiredV4.ip;
        ucQueueMsg = (unsigned char)EVENT_IP_ACQUIRED;
        if(g_tConnection != 0)
        {
            osi_MsgQWrite(&g_tConnection, &ucQueueMsg, OSI_WAIT_FOREVER);
        }
        else
        {
            UART_PRINT("Error: sl_NetAppEvtHdlr: Queue does not exist\n\r");
            while(FOREVER);
        }
        UART_PRINT("IP: ");
        PrintIPAddr(g_ulIpAddr);
        UART_PRINT("\n\r");
        break;
    default:
        break;
    }
}
Exemplo n.º 5
0
//****************************************************************************
//
//! \brief This function handles WLAN events
//!
//! \param[in]  pSlWlanEvent is the event passed to the handler
//!
//! \return    None
//
//****************************************************************************
void sl_WlanEvtHdlr(SlWlanEvent_t *pSlWlanEvent)
{
    unsigned char ucQueueMsg = 0;
    switch(pSlWlanEvent->Event)
    {
    case SL_WLAN_CONNECT_EVENT:
        ucQueueMsg = (unsigned char)EVENT_CONNECTION;
        if(g_tConnection != 0)
        {
            osi_MsgQWrite(&g_tConnection, &ucQueueMsg, OSI_WAIT_FOREVER);
        }
        else
        {
            UART_PRINT("Error: sl_WlanEvtHdlr: Queue does not exist\n\r");
            while(FOREVER);
        }
        UART_PRINT("C\n\r");
        break;
    case SL_WLAN_DISCONNECT_EVENT:
        ucQueueMsg = (unsigned char)EVENT_DISCONNECTION;
        if(g_tConnection != 0)
        {
            osi_MsgQWrite(&g_tConnection, &ucQueueMsg, OSI_WAIT_FOREVER);
        }
        else
        {
            UART_PRINT("Error: sl_WlanEvtHdlr: Queue does not exist\n\r");
            while(FOREVER);
        }
        UART_PRINT("D\n\r");
        break;
    default:
        break;
    }
}
Exemplo n.º 6
0
//****************************************************************************
//
//!    \brief device will try to ping the machine that has just connected to the
//!           device.
//!
//!    \param  ulIpAddr is the ip address of the station which has connected to
//!            device
//!
//!    \return 0 if ping is successful, -1 for error
//
//****************************************************************************
static int PingTest(unsigned long ulIpAddr)
{  
    signed long           retVal = -1;
    SlPingStartCommand_t PingParams;
    SlPingReport_t PingReport;
    PingParams.PingIntervalTime = PING_INTERVAL;
    PingParams.PingSize = PING_PKT_SIZE;
    PingParams.PingRequestTimeout = PING_TIMEOUT;
    PingParams.TotalNumberOfAttempts = NO_OF_ATTEMPTS;
    PingParams.Flags = PING_FLAG;
    PingParams.Ip = ulIpAddr; /* Cleint's ip address */
    
    UART_PRINT("Running Ping Test...\n\r");
    /* Check for LAN connection */
    retVal = sl_NetAppPingStart((SlPingStartCommand_t*)&PingParams, SL_AF_INET,
                            (SlPingReport_t*)&PingReport, SimpleLinkPingReport);
    ASSERT_ON_ERROR(__LINE__, retVal);

    while(!IS_PING_DONE(g_ulStatus))
    {
      // Wait for Ping Event
    }

    if (g_ulPingPacketsRecv)
    {
      // LAN connection is successful
      UART_PRINT("Ping Test successful\n\r");
      return SUCCESS;
    }
    else
    {
        // Problem with LAN connection
        return LAN_CONNECTION_FAILED;
    }    
}
Exemplo n.º 7
0
static void Init()
{
    long lRetVal = -1;
    BoardInit();
    UDMAInit();
    PinMuxConfig();
    InitTerm();

    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 applicaton
    //
    // 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()
        ;
    }

    //
    // Asumption is that the device is configured in station mode already
    // and it is in its default state
    //
    lRetVal = sl_Start(0, 0, 0);
    if (lRetVal < 0) {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER()
        ;
    }

    UART_PRINT("Connecting to AP: '%s'...\r\n", SSID_NAME);

    // Connecting to WLAN AP - Set with static parameters defined at common.h
    // After this call we will be connected and have IP address
    lRetVal = WlanConnect();
    if (lRetVal < 0) {
        UART_PRINT("Connection to AP failed \n\r");
        LOOP_FOREVER()
        ;
    }

    UART_PRINT("Connected to AP: '%s' \n\r", SSID_NAME);

#ifdef NEW_ID
    iobeam_Reset();
#endif
}
int main()
{
	/*
	 * Preparation
	 */
    // Board Initialization
    BoardInit();
    // Configuring UART
    InitTerm();

    // Connect to AP
    // Put your SSID and password in common.h
    long lRetVal = ConnectToAP();
    if(lRetVal < 0)
    {
    	UART_PRINT("Connection to AP failed\n\r");
        LOOP_FOREVER();
    }
    UART_PRINT("Connected to AP\n\r");
    if(lRetVal < 0)
    {
        LOOP_FOREVER();
    }

    // Declare thing
    Thing_Struct thing;

    // Connect to thethingsiO server
    lRetVal = ConnectTo_thethingsiO(&thing.thing_client);
       if(lRetVal < 0)
       {
           LOOP_FOREVER();
       }
    UART_PRINT("Thing client connected\n\r");

    // In order to initialize the thing correctly you have to use one of
    // following two methods:
    // 1. If you have already activated your thing you should set the token
    thing.token = "YOUR TOKEN HERE";
    // 2. Or if not copy the provided activation code here
    // and uncomment the following line
    // char *act_code = "YOUR ACTIVATION CODE HERE";
    // and activate the thing (uncomment the following line)
    // char *token = thing_activate(&thing, act_code);

    /* Intializes random number generator */
  //  time_t t;
  //  srand((unsigned) time(&t));
    while(1)
    {
    	char *sub = thing_subscribe(&thing);
    	if (strlen(sub) > 0)
    	{
    		UART_PRINT(sub);
    		UART_PRINT("\n\r");
    	}
    	// Free memory
    	free(sub);
    }
}
Exemplo n.º 9
0
void net_ping(const char *host)
{
    SlPingStartCommand_t pingParams = {0};
    SlPingReport_t pingReport = {0};
    unsigned long ulIpAddr = 0;
    CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_PING_DONE);

    // Set the ping parameters
    pingParams.PingIntervalTime = 1000;
    pingParams.PingSize = 20;
    pingParams.PingRequestTimeout = 3000;
    pingParams.TotalNumberOfAttempts = 3;
    pingParams.Flags = 0;
    pingParams.Ip = g_ulGatewayIP;

    UART_PRINT("ping host: %s\r\n", host);

    sl_NetAppDnsGetHostByName((signed char*)host, strlen(host), &ulIpAddr, SL_AF_INET);
    UART_PRINT("host ip: 0x%08X\r\n", host);
    pingParams.Ip = ulIpAddr;
    sl_NetAppPingStart((SlPingStartCommand_t*)&pingParams, SL_AF_INET, (SlPingReport_t*)&pingReport, SimpleLinkPingReport);

    while(!IS_PING_DONE(g_ulStatus))
        _SlNonOsMainLoopTask();
}
Exemplo n.º 10
0
tDSPInstance* DSPCeateInstance(uint32_t signalSize, uint32_t Fs) {
  tDSPInstance* tempInstance;
  tempInstance = (tDSPInstance*)malloc(sizeof(tDSPInstance));
  if (tempInstance == NULL){
    UART_PRINT("DSPCreate malloc error!");
    LOOP_FOREVER(); //malloc error. heap too small?
    return NULL;
  }
  tempInstance->signalSize = signalSize;
  tempInstance->Fs = Fs;
  tempInstance->ucpSignal = (unsigned char*)malloc(sizeof(unsigned char)*signalSize);
  tempInstance->fpSignal = (float32_t*)malloc(sizeof(float32_t)*signalSize/2);
  tempInstance->fftSize = signalSize / 4;
  tempInstance->FFTResults = (float32_t*)malloc(sizeof(float32_t)*tempInstance->fftSize);
  if (tempInstance->ucpSignal==NULL || \
      tempInstance->fpSignal==NULL || \
      tempInstance->FFTResults==NULL) {
    UART_PRINT("DSPCreate malloc error!");
    LOOP_FOREVER(); //malloc error. heap too small?
    return NULL;
  }
  tempInstance->maxEnergyBinIndex = 0;
  tempInstance->maxEnergyBinValue = 0;

  return tempInstance;
}
Exemplo n.º 11
0
//*****************************************************************************
//
//! This function handles socket events indication
//!
//! \param[in]      pSock - Pointer to Socket Event Info
//!
//! \return None
//!
//*****************************************************************************
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
{
    //
    // This application doesn't work w/ socket - Events are not expected
    //
    switch( pSock->Event )
    {
        case SL_SOCKET_TX_FAILED_EVENT:
            switch( pSock->EventData.status )
            {
                case SL_ECLOSE:
                    UART_PRINT("[SOCK ERROR] - close socket (%d) operation "
                                "failed to transmit all queued packets\n\n",
                                pSock->EventData.sd);
                    break;
                default:
                    UART_PRINT("[SOCK ERROR] - TX FAILED : socket %d , reason"
                                "(%d) \n\n",
                                pSock->EventData.sd, pSock->EventData.status);
            }
            break;

        default:
            UART_PRINT("[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event);
    }
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: dlugaz/All
//*****************************************************************************
//
//! Function - Read Predefined Values. Populate Key,PlainText,Mode etc from 
//!   pre-defined Vectors
//!
//! \param ui32Config - Configuration Value (Direction | Mode |KeySize)
//! \out uiConfig - Configuration value 
//! \out uiKeySize - Key Size used
//! \out uiIV - Initialization Vector
//! \out puiKey1 - Key Used
//! \out uiDataLength - DataLength Used
//! \out puiResult - Result
//!
//! \return Returns /\e true on success or \e false on failure.
//
//*****************************************************************************
unsigned int *
LoadDefaultValues(unsigned int ui32Config,unsigned int *uiConfig,
                    unsigned int *uiKeySize,
                    unsigned int **uiIV,unsigned int **puiKey1,
                    unsigned int *uiDataLength,unsigned int **puiResult)
{
    unsigned int *uiData;
    
    //
    // Populate all the out parameters from pre-defined vector
    //
    *uiConfig=ui32Config;
    
    //
    // Read Key and Key size
    //
    *puiKey1=psAESCBCTestVectors.pui32Key1;
    *uiKeySize=psAESCBCTestVectors.ui32KeySize;
    
    //
    // Read Initialization Vector
    //
    *uiIV=&psAESCBCTestVectors.pui32IV[0];
    
    //
    // Read Data Length and allocate Result and Data variables accordingly
    //
    *uiDataLength=psAESCBCTestVectors.ui32DataLength;
    *puiResult=(unsigned int*)malloc(*uiDataLength);
    if(*puiResult != NULL)
    {
        memset(*puiResult,0,*uiDataLength);
    }
    else
    {
        //Failed to allocate memory
        UART_PRINT("Failed to allocate memory");
        return 0;
    }
    uiData=(unsigned int*)malloc(*uiDataLength);
    if(uiData != NULL)
    {
        memset(uiData,0,*uiDataLength);
    }
    else
    {
        //Failed to allocate memory
        UART_PRINT("Failed to allocate memory");
        return 0;
    }
    //
    // Copy Plain Text or Cipher Text into the variable Data
    //
    if(ui32Config & AES_CFG_DIR_ENCRYPT)
        memcpy(uiData,psAESCBCTestVectors.pui32PlainText,*uiDataLength);
    else
         memcpy(uiData,psAESCBCTestVectors.pui32CipherText,*uiDataLength);
    
    return uiData; 
}
Exemplo n.º 13
0
void startApplication(void *pvParameters) {
    // TODO: Change to your SSID and password
    signed char ssid[] = "<wifi ssid>";
    signed char key[] = "<wifi password>";
    SlSecParams_t keyParams;
    keyParams.Type = SL_SEC_TYPE_WPA;
    keyParams.Key = key;
    keyParams.KeyLen = strlen((char *)key);

    initNetwork(ssid, &keyParams);

    // TODO: Set to current date/time (within an hour precision)
    SlDateTime_t dateTime;
    memset(&dateTime, 0, sizeof(dateTime));
    dateTime.sl_tm_year = 2015;
    dateTime.sl_tm_mon = 3;
    dateTime.sl_tm_day = 20;
    dateTime.sl_tm_hour = 12;
    sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, sizeof(SlDateTime_t), (unsigned char *)&dateTime);

    UART_PRINT("\r\n");
    UART_PRINT("[QuickStart] Start application\r\n");
    UART_PRINT("\r\n");

    // TODO: Add Parse code here
}
Exemplo n.º 14
0
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) {
    switch (pNetAppEvent->Event) {
        case SL_NETAPP_IPV4_IPACQUIRED_EVENT:
        {
            UART_PRINT("[QuickStart] IP address                : %d.%d.%d.%d\r\n",
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 3),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 2),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 1),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 0));
            UART_PRINT("[QuickStart] Gateway                   : %d.%d.%d.%d\r\n",
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 3),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 2),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 1),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 0));
            UART_PRINT("[QuickStart] DNS server                : %d.%d.%d.%d\r\n",
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 3),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 2),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 1),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 0));

            SET_STATUS_BIT(g_Status, STATUS_BIT_IP_AQUIRED);
        }
            break;

        default:
            break;
    }
}
Exemplo n.º 15
0
int main(void) {
    // init the hardware
    initBoard();

    UART_PRINT("[Blink] Start application\r\n");

    // create the main application message queue
    // this call properly enables the OSI scheduler to function
    short status = osi_MsgQCreate(&g_ApplicationMessageQueue, "ApplicationMessageQueue", sizeof(ApplicationMessage), 1);
    if (status < 0) {
        UART_PRINT("[Blink] Create application message queue error\r\n");
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    // start the main application task
    // this is necessary because SimpleLink host driver is started by sl_Start(),
    // which cannot be called on before the OSI scheduler is started
    status = osi_TaskCreate(startApplication, (signed char *)"Blink", OSI_STACK_SIZE,  NULL, OOB_TASK_PRIORITY, NULL);
    if (status < 0) {
        UART_PRINT("[Blink] Start application error\r\n");
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    // start the OSI scheduler
    osi_start();

    return 0;
}
Exemplo n.º 16
0
//*****************************************************************************
//
//! This function handles socket events indication
//!
//! \param[in]      pSock - Pointer to Socket Event Info
//!
//! \return None
//!
//*****************************************************************************
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
{
    if(!pSock)
    {
        return;
    }

    switch( pSock->Event )
    {
        case SL_SOCKET_TX_FAILED_EVENT:
            switch( pSock->socketAsyncEvent.SockTxFailData.status)
            {
                case SL_ECLOSE: 
                    UART_PRINT("[SOCK ERROR] - close socket (%d) operation "
                                "failed to transmit all queued packets\n\n", 
                                    pSock->socketAsyncEvent.SockTxFailData.sd);
                    break;
                default: 
                    UART_PRINT("[SOCK ERROR] - TX FAILED  :  socket %d , reason "
                                "(%d) \n\n",
                                pSock->socketAsyncEvent.SockTxFailData.sd, pSock->socketAsyncEvent.SockTxFailData.status);
                  break;
            }
            break;

        default:
        	UART_PRINT("[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event);
          break;
    }

}
Exemplo n.º 17
0
//*****************************************************************************
//
//! \brief  Function display the application banner
//!
//! \param[in]      p_app_name - Application name
//!
//! \return None
//
//*****************************************************************************
static void DisplayBanner(char *p_app_name)
{
    UART_PRINT("\n\n\n\r");
    UART_PRINT("\t\t *************************************************\n\r");
    UART_PRINT("\t\t\t Application Name: %s       \n\r", p_app_name);
    UART_PRINT("\t\t *************************************************\n\r");
    UART_PRINT("\n\n\n\r");
}
Exemplo n.º 18
0
//*****************************************************************************
//
//! Application startup display on UART
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
static void DisplayBanner(char * AppName) {

	UART_PRINT("\n\n\n\r");
	UART_PRINT("\t\t *************************************************\n\r");
	UART_PRINT("\t\t           CC3200 %s Application       \n\r", AppName);
	UART_PRINT("\t\t *************************************************\n\r");
	UART_PRINT("\n\n\n\r");
}
Exemplo n.º 19
0
//****************************************************************************
//
//!  \brief                     Handles HTTP Server Task
//!                                              
//! \param[in]                  pvParameters is the data passed to the Task
//!
//! \return                        None
//
//****************************************************************************
static void HTTPServerTask(void *pvParameters)
{
    long lRetVal = -1;
    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 applicaton
    //
    // 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");  
  
    memset(g_ucSSID,'\0',AP_SSID_LEN_MAX);
    
    //Read Device Mode Configuration
    ReadDeviceConfiguration();

    //Connect to Network
    lRetVal = ConnectToNetwork();

    //Stop Internal HTTP Server
    lRetVal = sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    //Start Internal HTTP Server
    lRetVal = sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    //Handle Async Events
    while(1)
    {
         
    }
}
Exemplo n.º 20
0
//****************************************************************************
//
//! Parses the write command parameters and invokes the I2C APIs
//!
//! \param pcInpString pointer to the write command parameters
//! 
//! This function  
//!    1. Parses the write command parameters.
//!    2. Invokes the corresponding I2C APIs
//!
//! \return 0: Success, < 0: Failure.
//
//****************************************************************************
int
ProcessWriteCommand(char *pcInpString)
{
    unsigned char ucDevAddr, ucStopBit, ucLen;
    unsigned char aucDataBuf[256];
    char *pcErrPtr;
    int iRetVal, iLoopCnt;

    //
    // Get the device address
    //
    pcInpString = strtok(NULL, " ");
    RETERR_IF_TRUE(pcInpString == NULL);
    ucDevAddr = (unsigned char)strtoul(pcInpString+2, &pcErrPtr, 16);
    
    //
    // Get the length of data to be written
    //
    pcInpString = strtok(NULL, " ");
    RETERR_IF_TRUE(pcInpString == NULL);
    ucLen = (unsigned char)strtoul(pcInpString, &pcErrPtr, 10);
    //RETERR_IF_TRUE(ucLen > sizeof(aucDataBuf));

    for(iLoopCnt = 0; iLoopCnt < ucLen; iLoopCnt++)
    {
        //
        // Store the data to be written
        //
        pcInpString = strtok(NULL, " ");
        RETERR_IF_TRUE(pcInpString == NULL);
        aucDataBuf[iLoopCnt] = 
                (unsigned char)strtoul(pcInpString+2, &pcErrPtr, 16);
    }
    
    //
    // Get the stop bit
    //
    pcInpString = strtok(NULL, " ");
    RETERR_IF_TRUE(pcInpString == NULL);
    ucStopBit = (unsigned char)strtoul(pcInpString, &pcErrPtr, 10);
    
    //
    // Write the data to the specified address
    //
    iRetVal = I2C_IF_Write(ucDevAddr, aucDataBuf, ucLen, ucStopBit);
    if(iRetVal == SUCCESS)
    {
        UART_PRINT("I2C Write complete\n\r");
    }
    else
    {
        UART_PRINT("I2C Write failed\n\r");
        return FAILURE;
    }

    return SUCCESS;
}
Exemplo n.º 21
0
//*****************************************************************************
//
//! DisplayBanner
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
static void
DisplayBanner()
{
    UART_PRINT("\n\n\n\r");
    UART_PRINT("\t\t   *********************************************\n\r");
    UART_PRINT("\t\t          CC3200 Idle Profile Application   \n\r");
    UART_PRINT("\t\t   *********************************************\n\r");
    UART_PRINT("\n\n\n\r");

}
Exemplo n.º 22
0
Arquivo: main.c Projeto: dlugaz/All
//*****************************************************************************
//
//! Application startup display on UART
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
void
DisplayBanner()
{
    UART_PRINT("\n\n\n\r");
    UART_PRINT("\t\t   *******************************************\n\r");
    UART_PRINT("\t\t        CC3200 %s Application        \n\r", APP_NAME);
    UART_PRINT("\t\t   *******************************************\n\r");
    UART_PRINT("\n\n\n\r");

}
Exemplo n.º 23
0
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
{
    UART_PRINT("SimpleLinkWlanEventHandler\r\n");
    switch(pWlanEvent->Event)
    {
        case SL_WLAN_CONNECT_EVENT:
        {
            SET_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);

            //
            // Information about the connected AP (like name, MAC etc) will be
            // available in 'slWlanConnectAsyncResponse_t'-Applications
            // can use it if required
            //
            //  slWlanConnectAsyncResponse_t *pEventData = NULL;
            // pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
            //

            UART_PRINT("[WLAN EVENT] STA Connected to the AP: %s\n\r",
                       pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_name);
        }
        break;

        case SL_WLAN_DISCONNECT_EVENT:
        {
            slWlanConnectAsyncResponse_t*  pEventData = NULL;

            CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
            CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);

            pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;

            // If the user has initiated 'Disconnect' request,
            //'reason_code' is SL_USER_INITIATED_DISCONNECTION
            if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code)
            {
                UART_PRINT("[WLAN EVENT]Device disconnected from the AP: %s\r\n",
                           pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_name);
            }
            else
            {
                UART_PRINT("[WLAN ERROR]Device disconnected from the AP AP: %s\r\n",
                           pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_name);
            }
        }
        break;

        default:
        {
            UART_PRINT("[WLAN EVENT] Unexpected event [0x%x]\n\r",
                       pWlanEvent->Event);
        }
        break;
    }
}
Exemplo n.º 24
0
int VerifyFile(const char *fileToVerify, const char *fileWithSHAHash) {
	unsigned long sToken = 0;
	long sfileHandle = -1;
	uint8_t firstHash[20];
	uint8_t secoundHash[21];
	long retVal;
	memset(firstHash, 0, sizeof(firstHash));
	memset(secoundHash, 0, sizeof(secoundHash));

	// get hash of file to verify
	if (ComputeSHA(fileToVerify, firstHash) < 0) {
		UART_PRINT("Error computing SHA1SUM of %s\r\n", fileToVerify);
		return -1;
	}

	// open the source file for reading
	retVal = sl_FsOpen((unsigned char *) fileWithSHAHash, FS_MODE_OPEN_READ, &sToken, &sfileHandle);
	if (retVal < 0) {
		UART_PRINT("Error during opening the source file %s\r\n", fileWithSHAHash);
		return -1;
	}

	// transform the hash from file with sha hash to byte values. The Sha1Sum is decoded in ascii chars
	unsigned int i;
	for (i = 0; i < sizeof(firstHash); i++) {
		retVal = sl_FsRead(sfileHandle, i * 2, (unsigned char *) &secoundHash[i], 2);
		if (retVal < 0) {
			// Error close the file and delete the temporary file
			retVal = sl_FsClose(sfileHandle, 0, 0, 0);
			UART_PRINT("Error during reading the file\r\n");
			return -1;
		}
		uint8_t tempValue;
		if (secoundHash[i] > '9') tempValue = (secoundHash[i] - 'a' + 10) << 4;
		else tempValue = (secoundHash[i] - '0') << 4;

		if (secoundHash[i + 1] > '9') tempValue += (secoundHash[i + 1] - 'a' + 10);
		else tempValue += (secoundHash[i + 1] - '0');
		secoundHash[i] = tempValue;
	}

	// Close the opened files
	retVal = sl_FsClose(sfileHandle, 0, 0, 0);
	if (retVal < 0) {
		// Error close the file and delete the temporary file
		UART_PRINT("Error during close the file\r\n");
		return -1;
	}

	if (memcmp(secoundHash, firstHash, sizeof(firstHash)) != 0) {
		UART_PRINT("\r\nHash-Sums are different\r\n");
		return -1;
	}
	return 0;
}
//*****************************************************************************
//
//! Initiates HIRCP connection sequence.
//!
//! \param None.
//!
//! \return Returns \b true if the connection was successful and \b false
//! otherwise.
//
//*****************************************************************************
tBoolean HIRCP_InitiateConnectionSequence(void)
{
    long lRetVal = 0;
    unsigned char recv_data[HIRCP_MAX_PACKET_LEN];
    unsigned char send_data[HIRCP_MAX_PACKET_LEN];
    unsigned char recv_payload[HIRCP_MAX_PAYLOAD_LEN];
    unsigned char send_payload[HIRCP_MAX_PAYLOAD_LEN];
    HIRCP_Packet *sendPacket = HIRCP_CreatePacket();
    HIRCP_Packet *recvPacket = HIRCP_CreatePacket();

    //
    // Receive CRQ packet
    //
    lRetVal = BsdTcpServerReceive(recv_data, HIRCP_MAX_PACKET_LEN);
    if (lRetVal < 0)
    {
        return false;
    }
    HIRCP_Populate(recvPacket, recv_data, HIRCP_MAX_PACKET_LEN);
    if (!HIRCP_IsValid(recvPacket) || !(HIRCP_GetType(recvPacket) == HIRCP_CRQ))
    {
        return false;
    }

    //
    // Check for mode
    //
    HIRCP_GetPayload(recvPacket, recv_payload, HIRCP_MAX_PAYLOAD_LEN);
    if (recv_payload[0] != HIRCP_NORMAL && recv_payload[0] != HIRCP_CLOSED_LOOP)
    {
        UART_PRINT("Invalid mode.\n\r");
        return false;
    }
    g_hircp_mode = recv_payload[0];

    UART_PRINT("Received CRQ packet.\n\r");

    //
    // Send ACK packet
    //
    HIRCP_ClearPacket(sendPacket);
    HIRCP_SetType(sendPacket, HIRCP_ACK);
    HIRCP_GetData(sendPacket, send_data, HIRCP_MAX_PACKET_LEN);
    lRetVal = BsdTcpServerSend(send_data, HIRCP_MAX_PACKET_LEN);
    if (lRetVal < 0)
    {
        return false;
    }
    UART_PRINT("Sent ACK packet.\n\r");

    HIRCP_DestroyPacket(sendPacket);
    HIRCP_DestroyPacket(recvPacket);
    return true;
}
Exemplo n.º 26
0
void initBoard() {
#ifndef USE_TIRTOS
#if defined(ccs) || defined(gcc)
    MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]);
#endif
#if defined(ewarm)
    MAP_IntVTableBaseSet((unsigned long)&__vector_table);
#endif
#endif

    MAP_IntMasterEnable();
    MAP_IntEnable(FAULT_SYSTICK);

    PRCMCC3200MCUInit();

    PinMuxConfig();
    GPIO_IF_LedConfigure(LED1);
    GPIO_IF_LedOff(MCU_RED_LED_GPIO);

    InitTerm();
    ClearTerm();

    UART_PRINT("Blink - Parse for IoT sample application\r\n");
    UART_PRINT("----------------------------------------\r\n");
    UART_PRINT("\r\n");
    UART_PRINT("[Blink] Board init\r\n");

    // start the spawn task
    short status = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    if (status < 0) {
        UART_PRINT("[Blink] Spawn task failed\r\n");
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    // initialize the I2C bus
    status = I2C_IF_Open(I2C_MASTER_MODE_FST);
    if (status < 0) {
        UART_PRINT("[Blink] I2C opening error\r\n");
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    UART_PRINT("[Blink] Device                    : TI SimpleLink CC3200\r\n");
#ifdef USE_TIRTOS
    UART_PRINT("[Blink] Operating system          : TI-RTOS\r\n");
#endif
#ifdef USE_FREERTOS
    UART_PRINT("[Blink] Operating system          : FreeRTOS\r\n");
#endif
#ifndef SL_PLATFORM_MULTI_THREADED
    UART_PRINT("[Blink] Operating system          : None\r\n");
#endif
}
Exemplo n.º 27
0
Arquivo: main.c Projeto: dlugaz/All
//*****************************************************************************
//!
//! Initialize Scatter Gather DMA Transfer
//!
//! \param None
//! 
//! \return None
//!
//*****************************************************************************
void
InitSGTransfer()
{
    int i;
    char * pvSrcBuf,*pvDstBuf;
    
    //
    // Source Buffer
    //
    pvSrcBuf=malloc(BUFF_SIZE);
    if(pvSrcBuf == NULL)
    {
        UART_PRINT("Failed to allocate Src buffer\n\r");
        return ;
    }
    for(i=0;i<BUFF_SIZE;i++)
        *(pvSrcBuf+i)=i;

    MAP_uDMAChannelAssign(UDMA_CH0_SW);
    MAP_uDMAChannelAttributeDisable(UDMA_CH0_SW,UDMA_ATTR_ALTSELECT);
    iDone=0;

    pvDstBuf=malloc(BUFF_SIZE);
    if(pvDstBuf == NULL)
    {
        UART_PRINT("Failed to allocate Dst buffer\n\r");
        return ;
    }
    
    //
    // Call to Set Up Scatter Gather Mode Transfer
    //
    SetupSGMemTransfer(UDMA_CH0_SW,pvSrcBuf,pvSrcBuf+BUFF_SIZE/2,
                       pvDstBuf,BUFF_SIZE/2);
    MAP_uDMAChannelRequest(UDMA_CH0_SW);
    
    //
    // Checking for the Completion
    //
    while(!iDone);
    
    //
    // Checking Correctness of SG Transfer
    //
    if(memcmp(pvSrcBuf,pvDstBuf,BUFF_SIZE)==0)
        UART_PRINT("SG Mode Memory to Memory Transfer Completed \n\r\n\r");
    else
        UART_PRINT("SG Mode Memory to Memory Transfer Failed! \n\r\n\r");

    free(pvDstBuf);

}
Exemplo n.º 28
0
//*****************************************************************************
//
//! ReadFromUser - Populates the parameters from User
//!
//! \param  uiConfig Configuration Value
//! \param  uiHashLength is the Length of Hash Value
//! \param  uiKey is the Key Used
//! \param  uiDataLength is the Length of Data
//! \param  puiResult is the Result
//!
//! \return pointer to plain text
//!
//*****************************************************************************
unsigned char *
ReadFromUser(unsigned int *uiConfig,unsigned int *uiHashLength,unsigned 
              char **uiKey,unsigned int *uiDataLength,unsigned char **puiResult)
{
    char ucCmdBuffer[520],*pucKeyBuff,*pucMsgBuff;
    unsigned char *uiData;

    //
    // POinting KeyBuffer into appropriate Keys. 
    //
    pucKeyBuff=(char*)&uiHMACKey[0];
    *uiKey=(unsigned char*)&uiHMACKey[0];
    pucMsgBuff=( char*)&puiPlainMsg[0];

    //
    // Set Default Values
    //
    SetKeys();

    //
    // Usage Display
    //
    UsageDisplay();

    //
    // Get the Command
    //
    UART_PRINT("cmd# ");
    GetCmd(ucCmdBuffer,520);
    if(SHAMD5Parser(ucCmdBuffer,uiConfig,uiHashLength))
    {
        if(GetKey(pucKeyBuff))
        {
            uiData=GetMsg(pucMsgBuff,uiDataLength);
            *puiResult=(unsigned char *)malloc(64);
            memset(*puiResult,0,64);
        }
        else
        {
            UART_PRINT("\n\r Invalid Key \n\r");
            return NULL;
        }
    }
    else
    {
        UART_PRINT("\n\r Wrong Input \n\r");
        return NULL;
    }
    return uiData;
}
Exemplo n.º 29
0
Arquivo: main.c Projeto: dlugaz/All
//*****************************************************************************
//!
//! Initializes the uDMA software channel to perform a memory to memory uDMA
//! transfer.
//!
//! \param None
//!
//! \return None
//*****************************************************************************
void
InitSWTransfer(void)
{
    unsigned int uIdx;

    //
    // Fill the source memory buffer with a simple incrementing pattern.
    //
    for(uIdx = 0; uIdx < MEM_BUFFER_SIZE; uIdx++)
    {
        g_ulSrcBuf[uIdx] = uIdx;
    }

    //
    // Configure the control parameters for the SW channel.  The SW channel
    // will be used to transfer between two memory buffers, 32 bits at a time.
    // Therefore the data size is 32 bits, and the address increment is 32 bits
    // for both source and destination.  The arbitration size will be set to 8,
    // which causes the uDMA controller to rearbitrate after 8 items are
    // transferred.  This keeps this channel from hogging the uDMA controller
    // once the transfer is started, and allows other channels cycles if they
    // are higher priority.
    //

    UDMASetupTransfer(UDMA_CH0_SW, UDMA_MODE_AUTO, MEM_BUFFER_SIZE,
                      UDMA_SIZE_32, UDMA_ARB_8,g_ulSrcBuf, UDMA_SRC_INC_32,
                                            g_ulDstBuf, UDMA_DST_INC_32);

    if(StartAndCompleteSWTransfer(UDMA_CH0_SW))
    {
      UART_PRINT("Memory to Memory Transfer Error \n\r");
    }
    //
    // Verifying the transfered Data
    //
    for(uIdx = 0; uIdx < MEM_BUFFER_SIZE; uIdx++)
    {
      if(uIdx!=g_ulDstBuf[uIdx])
        {
          UART_PRINT("Data transfered in Auto mode is Incorrect at %d th "
                        "location \n\r\n\r",uIdx);
          Done=1;
          return;

        }
    }
    UART_PRINT("Data transfered in Auto mode is verified \n\r\n\r");
    Done=1;

}
Exemplo n.º 30
0
//****************************************************************************
//
//! \brief This function handles WLAN events
//!
//! \param[in]  pSlWlanEvent is the event passed to the handler
//!
//! \return    None
//
//****************************************************************************
void sl_WlanEvtHdlr(SlWlanEvent_t *pSlWlanEvent)
{
    switch(pSlWlanEvent->Event)
    {
    case SL_WLAN_CONNECT_EVENT:
        UART_PRINT("C\n\r");
        break;
    case SL_WLAN_DISCONNECT_EVENT:
        UART_PRINT("D\n\r");
        break;
    default:
        break;
    }
}