示例#1
0
/*!
    \brief Create TCP connection with openweathermap.org

    \param[in]      none

    \return         Socket descriptor for success otherwise negative

    \warning
*/
static int CreateConnection(void){
  SlSockAddrIn_t  Addr;

  INT32 sd = 0;
  INT32 AddrSize = 0;
  INT16 ret_val = 0;

  Addr.sin_family = SL_AF_INET;
  Addr.sin_port = sl_Htons(80);

    /* Change the DestinationIP endianity, to big endian */
  Addr.sin_addr.s_addr = sl_Htonl(appData.DestinationIP);

  AddrSize = sizeof(SlSockAddrIn_t);

  sd = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
  if( sd < 0 ){
    LCD_OutString("Error creating socket\r\n");
    return sd;
  }

  ret_val = sl_Connect(sd, ( SlSockAddr_t *)&Addr, AddrSize);
  if( ret_val < 0 ){
        /* error */
    LCD_OutString("Error connecting to socket\r\n");
    return ret_val;
  }

  return sd;
}
示例#2
0
/*!
    \brief This function handles socket events indication

    \param[in]      pSock is the event passed to the handler

    \return         None
*/
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock){
  switch( pSock->Event )
  {
    case SL_NETAPP_SOCKET_TX_FAILED:
    {
            /*
            * TX Failed
            *
            * Information about the socket descriptor and status will be
            * available in 'SlSockEventData_t' - Applications can use it if
            * required
            *
            * SlSockEventData_t *pEventData = NULL;
            * pEventData = & pSock->EventData;
            */
      switch( pSock->EventData.status )
      {
        case SL_ECLOSE:
          LCD_OutString(" [SOCK EVENT] Close socket operation failed to transmit all queued packets\r\n");
          break;


        default:
          LCD_OutString(" [SOCK EVENT] Unexpected event \r\n");
          break;
      }
    }
    break;

    default:
      LCD_OutString(" [SOCK EVENT] Unexpected event \r\n");
    break;
  }
}
示例#3
0
//***************Get_Speed******************
//Displays the speed at which you are travelling
//Input: the total rotation count and the total rotation count 1 second ago
//Output: none
void Get_Speed(unsigned short *buffer, unsigned char units, unsigned long time) {
    char i;
    unsigned long speed = 0;
    unsigned long rotations = 0;

    unsigned char SaveCCR;
    asm tpa
    asm staa SaveCCR
    asm sei          // make atomic

// The for loop has the 10
    for(i=0; i<10; i++) {
        rotations = rotations + *buffer;
        buffer++;
    }
    rotations = rotations*60;
    if(time < 60) {
        rotations = (rotations*60)/time;
    }

    //rotations currently carries the total number of rotations done in one hour
    if(units == KM)
        speed = ((rotations*WHEEL_CIRCUM_KM));           //speed currently in mm/hr
    else speed = ((rotations*WHEEL_CIRCUM_MI));
    speed = (speed)/1000;                              //speed now in meters/hour

    Fixed_ulDecOut2(speed);

    LCD_OutString(" km/hr");

    asm ldaa SaveCCR
    asm tap          // end critical section
    asm cli
}
示例#4
0
/*!
    \brief This function handles general error events indication

    \param[in]      pDevEvent is the event passed to the handler

    \return         None
*/
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent){
    /*
     * Most of the general errors are not FATAL are are to be handled
     * appropriately by the application
     */
  LCD_OutString(" [GENERAL EVENT] \r\n");
}
示例#5
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

    \note

    \warning
*/
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent){
  switch(pNetAppEvent->Event)
  {
    case SL_NETAPP_IPV4_ACQUIRED:
    {

      SET_STATUS_BIT(g_Status, STATUS_BIT_IP_AQUIRED);
        /*
             * Information about the connected AP's ip, gateway, DNS etc
             * will be available in 'SlIpV4AcquiredAsync_t' - Applications
             * can use it if required
             *
             * SlIpV4AcquiredAsync_t *pEventData = NULL;
             * pEventData = &pNetAppEvent->EventData.ipAcquiredV4;
             * <gateway_ip> = pEventData->gateway;
             *
             */

    }
    break;

    default:
    {
            LCD_OutString(" [NETAPP EVENT] Unexpected event \r\n");
    }
    break;
  }
}
示例#6
0
/*!
    \brief This function handles callback for the HTTP server events

    \param[in]      pServerEvent - Contains the relevant event information
    \param[in]      pServerResponse - Should be filled by the user with the
                    relevant response information

    \return         None

    \note

    \warning
*/
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent,
                                  SlHttpServerResponse_t *pHttpResponse){
    /*
     * This application doesn't work with HTTP server - Hence these
     * events are not handled here
     */
  LCD_OutString(" [HTTP EVENT] Unexpected event \r\n");
}
示例#7
0
/*!
    \brief This function handles WLAN events

    \param[in]      pWlanEvent is the event passed to the handler

    \return         None

    \note

    \warning
*/
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent){
  switch(pWlanEvent->Event){
    case SL_WLAN_CONNECT_EVENT:
    {
      SET_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);

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

    case SL_WLAN_DISCONNECT_EVENT:
    {
      sl_protocol_wlanConnectAsyncResponse_t*  pEventData = NULL;

      CLR_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
      CLR_STATUS_BIT(g_Status, 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){
        LCD_OutString(" Device disconnected from the AP on application's request \r\n");
      }
      else{
        LCD_OutString(" Device disconnected from the AP on an ERROR..!! \r\n");
      }
    }
    break;

    default:
    {
      LCD_OutString(" [WLAN EVENT] Unexpected event \r\n");
    }
    break;
  }
}
示例#8
0
/*!
    \brief This function obtains the server IP address

    \param[in]      none

    \return         zero for success and -1 for error

    \warning
*/
static int32_t GetHostIP(void){
  int32_t status = -1;

  status = sl_NetAppDnsGetHostByName(appData.HostName,
                                       strlen(appData.HostName),
                                       &appData.DestinationIP, SL_AF_INET);
  if (status < 0){
    LCD_OutString("Unable to reach Host\n");
    return status;
  }
  return SUCCESS;
}
示例#9
0
//---------------------mainRx---------------------
// main used for receiver
// Input: none
// Output: none
void main(void) {  
  PLL_Init();
  SCIb_Init(9600);
  XBee_Init();
  LCD_Open();
  LCD_Clear();
  LCD_OutString("Xbee: ");
	EnableInterrupts;
  while(1) {
   // Rx DP512 continually polls the Rx FIFO and any available data is 
   // displayed on the LCD using the LCD driver routines.
    XBee_ReceiveRxFrame(&rxFrame[0]);
    /*if(SCIb_InStatus() && (rxFrame != 0)) {
      unsigned short messageLength = ((rxFrame[1]<<8) + rxFrame[2])-5;//message length only
      unsigned short i;
      for(i = 0; i < messageLength; i++){
        LCD_OutChar(rxFrame[i+8]);
      }
      printf("\n"); 
    }*/
    LCD_GoTo(1,1);
    LCD_OutString(&rxFrame[0]);
  }
}
示例#10
0
//***************Get_Weight******************
//Displays the users weight in lbs
//Input: the weight that the user is inputting
//Output: none
void Get_Weight(unsigned short weight) {
    unsigned char SaveCCR;
    asm tpa
    asm staa SaveCCR
    asm sei          // make atomic

    LCD_GoTo(0,0);
    LCD_OutString("    lbs");
    LCD_GoTo(0,0);
    LCD_OutChar(NUM_TO_CHAR + (weight/100));
    LCD_OutChar(NUM_TO_CHAR + ((weight/10)%10));
    LCD_OutChar(NUM_TO_CHAR + (weight%10));

    asm ldaa SaveCCR
    asm tap          // end critical section
    asm cli
}
示例#11
0
void mainRECEIVER(void) { 
  unsigned char CM[5] = {
    ' ',' ','c','m',0,
  }; 
  unsigned char *txtPnt;
  InData = 0;
  asm sei           // Disable interrupts
  PLL_Init();
  LCD_Open();       // Initializes Timer
  LCD_Clear();
  SCI1R_Init();
  DDRP |= 0x80;     // PP7 output
  OC1_InitR();       // Intializes timer as well, receiver uses interrupt channel 1
  txtPnt = CM;
  asm cli           // Enable interrupts  
  for(;;) {
     SCI1_InData();  // InData returns pnter value
     LCD_Clear();
     LCD_OutFix(Convert(adcValue));      // Displays data in fixed point format
     LCD_OutString(txtPnt);
     Timer_wait(10);       // wait 10ms
  }  
}
示例#12
0
int main(void){
  int32_t retVal = 0;
  char *pConfig = NULL;
  retVal = initializeAppVariables();
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz
  LCD_Init();
  LED_Init();       // initialize LaunchPad I/O 
//  LCD_OutString("Weather App\n");
  LCD_OutString("Lab 16 IoT\n");
  /*
     * 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(pConfig);
  if(retVal < 0){
    if(DEVICE_NOT_IN_STATION_MODE == retVal){
       LCD_OutString(" Failed to configure the device in its default state \r\n");
       Crash(4000000);
    }
  }

    /*
     * Assumption is that the device is configured in station mode already
     * and it is in its default state
     */
  retVal = sl_Start(0, pConfig, 0);
  if((retVal < 0) || (ROLE_STA != retVal) ){
    LCD_OutString(" Failed to start the device \r\n");
    Crash(8000000);

  }
  WlanConnect();
  LCD_OutString("Connected\n");

/* Get weather report */
  while(1){
    Nokia5110_SetCursor(0,2);
 //   retVal = getWeather();
    retVal = Lab16();
    if(retVal == 0){  // valid
      LED_GreenOn();
      UARTprintf("\r\n\r\n");
      UARToutString(appData.Recvbuff); UARTprintf("\r\n");
//      LCD_OutString(City); LCD_OutString("\n");
//      LCD_OutString(Temperature); LCD_OutString(" C\n");
//      LCD_OutString(Weather);
      LCD_OutString(Id); LCD_OutString("\n");
      LCD_OutString(Score); LCD_OutString("\n");
      LCD_OutString(Edxpost);
    }
    while(Board_Input()==0){}; // wait for touch
    LED_GreenOff();
  }
}
示例#13
0
//2 crank rotations equal .1 Cals burned
//20 crank rotations equal 1 calorie burned
void Get_Cals(unsigned long crankRotations) {
    Fixed_ulDecOut1(crankRotations/2);
    LCD_OutString(" Cals");
}
示例#14
0
//***************Get_AvgSpeed******************
//Displays the average speed over the whole trip
//Input: the total time spent on the trip (in seconds), and the total rotations done over the whole trip
//Output: none
void Get_AvgSpeed(unsigned long time, unsigned long rotations, unsigned char units) {
    unsigned long distTraveled;

    unsigned char SaveCCR;
    asm tpa
    asm staa SaveCCR
    asm sei          // make atomic

    if(units == KM)
        distTraveled = rotations*WHEEL_CIRCUM_KM;         //distanceTraveled currently in mm
    else distTraveled = rotations*WHEEL_CIRCUM_MI;         //distanceTraveled currently in miles/1E6

    distTraveled = distTraveled/1000;                 //distanceTravleed now in meters
    distTraveled = ((distTraveled*3600)/(time));      //distanceTravled now in meters/hr

    if(distTraveled<9999) {
        LCD_OutChar(NUM_TO_CHAR+(distTraveled/1000));
        LCD_OutString(".");
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10));
    }
    else if(distTraveled<99999) {
        LCD_OutChar(NUM_TO_CHAR+(distTraveled/10000));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled)%10));
        LCD_OutString(".");
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10));
    }
    else if(distTraveled<999999) {
        LCD_OutChar(NUM_TO_CHAR+(distTraveled/100000));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10000)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000)%10));
        LCD_OutString(".");
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10));
    }
    else if(distTraveled<9999999) {
        LCD_OutChar(NUM_TO_CHAR+(distTraveled/1000000));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/100000)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10000)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000)%10));
        LCD_OutString(".");
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10));
    }
    else if(distTraveled<99999999) {
        LCD_OutChar(NUM_TO_CHAR+(distTraveled/10000000));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000000)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/100000)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10000)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000)%10));
        LCD_OutString(".");
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10));
        LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10));

    }
    LCD_OutString(" km/hr");

    asm ldaa SaveCCR
    asm tap          // end critical section
    asm cli
}