Sections
You are here: Home Members Brian Jepson RSS Reader Version 0.7

Version 0.7

This is the source code for an RSS reader I'm working on. Right now it's very rough. TODOs: * Put the bits of the RSS feed I want to display into a buffer * Create separate tasks for fetching the RSS feed and displaying it *Clean up the code

make.c — C source code, 4Kb

File contents

/*
	Make.c
*/


#include "stdlib.h"
#include "config.h"
#include "poly.h"
#include "serial.h"
#include "string.h"

#define IP_ADDRESS( a, b, c, d ) ( ( (int)d << 24 ) + ( (int)c << 16 ) + ( (int)b << 8 ) + (int)a )
void BlinkTask( void* parameters );
void SerialTask( void* parameters );
void NetworkCheck( void );
void vBasicWEBServer( void *pvParameters );

void Make( )
{

  // Do this right quick after booting up - otherwise we won't be recognised
  Usb_SetActive( 1 );

  Debug_SetUdp(1);
  Debug_SetActive( 1 );

  // Active the Poly Function Task
  // Poly_SetActive( true );

  // Fire up the OSC system
  Osc_SetActive( true );
  // Add all the subsystems (make sure OSC_SUBSYSTEM_COUNT is large enough to accomodate them all)
  Osc_RegisterSubsystem( 0, AppLedOsc_GetName(), AppLedOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 1, DipSwitchOsc_GetName(), DipSwitchOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 2, ServoOsc_GetName(), ServoOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 3, AnalogInOsc_GetName(), AnalogInOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 4, DigitalOutOsc_GetName(), DigitalOutOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 5, DigitalInOsc_GetName(), DigitalInOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 6, MotorOsc_GetName(), MotorOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 7, PwmOutOsc_GetName(), PwmOutOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 8, LedOsc_GetName(), LedOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 9, DebugOsc_GetName(), DebugOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 10, SystemOsc_GetName(), SystemOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 11, NetworkOsc_GetName(), NetworkOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 12, SerialOsc_GetName(), SerialOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 13, IoOsc_GetName(), IoOsc_ReceiveMessage, NULL );
  Osc_RegisterSubsystem( 14, StepperOsc_GetName(), StepperOsc_ReceiveMessage, NULL );

  // Permit DIP switches to change the base IP settings
  NetworkCheck();

  // Starts the network up.  Will not return until a network is found...
  Network_SetActive( true );

  TaskCreate( BlinkTask, "Blink", 400, 0, 1 );
  Debug(0, "Starting Serial task\n");

  TaskCreate( SerialTask, "Ser", 300, 0, 1 );


}

void SerialTask( void* p )
{
  (void)p;
  char* request = "GET /auto/rss_full/RI/Kingston.xml?units=both HTTP/1.0\r\n\r\n";
  char *init_msg = "Starting up...";
  void* sock;

  Serial_SetActive(1);
  Serial_SetBaud(9600);
  Serial_SetHardwareHandshake(0);
  Serial_SetBits(8);
  Serial_SetStopBits(1);
  Serial_SetParity(0);
  Sleep(1000);
  Serial_Write(init_msg, strlen(init_msg), 2000);

  while (true) {
    char s[33];
    char p[33];

    char marker[] = {'i', 'o', 'n', '>' };
    int m = 0;

    int chars_written = 0;

    int in_closing_tag = 0;

    int count;
    sock = Socket(IP_ADDRESS(104,174,243,64), 80); // rss.wunderground.com
    SocketWrite(sock, request, strlen(request));
    while ((count = SocketRead(sock, s, 32)) != 0) {
      s[count] = 0;
      int j = 0;
      int i;

      // Clean up the output.
      for (i = 0; i < strlen(s); i++) {
	if (s[i] >= ' ') {
	  p[j++] = s[i];
	} else if (s[i] == '\n') {
	  p[j++] = ' ';
	}
      }
      p[j] = 0;

      // Find and display the forecast
      for (i = 0; i < strlen(p); i++) {
	if (m == 4) {
	  if (p[i] == '<') {
	    Debug(0, "Reached end of description");
	    in_closing_tag = 1;
            m = 0;
	  } else {
            char msg[] = {0, 0};
	    msg[0] = p[i];
	    Debug(0, msg);
            Serial_SetChar(p[i]);
	    chars_written++;
	    Sleep(250);
	  }
	} else if (p[i] == marker[m] && m < 4) {
	  m++;
	  if (m == 4) {
            if (in_closing_tag) {
              m = 0;
	      in_closing_tag = 0;
	    } else {
	      Sleep(2500);
  	      Debug(0, "Clearing Screen");
	      Serial_SetChar(254); // attn
	      Serial_SetChar(1);   // cls
	      chars_written = 0;
	    }
	  }
	} else {
	  m = 0;
	}
	if (chars_written == 32) {
	   Sleep(750);
  	   Debug(0, "Clearing Screen after pause");
	   Serial_SetChar(254); // attn
	   Serial_SetChar(1);   // cls
	   chars_written = 0;
	}
      }

      Sleep(10); // let other tasks run
    }
    SocketClose(sock);
    Sleep (60000);
  }
}

void BlinkTask( void* p )
{
 (void)p;
  Led_SetState( 1 );
  Sleep( 1000 );

  while ( true )
  {
    Led_SetState( 0 );
    Sleep( 900 );
    Led_SetState( 1 );
    Sleep( 10 );
  }
}

// Make sure the network settings are OK
void NetworkCheck()
{
  Network_SetAddress( 192, 168, 254, 200 );
  Network_SetMask( 255, 255, 255, 0 );
  Network_SetGateway( 192, 168, 254, 1 );
  Network_SetValid( 1 );
}
Document Actions
Get Started

Lots of clear, easy-to-read documentation makes it easy to get started.  Check the Documentation Section for helpful tutorials, how-tos and FAQs.

Get Involved!

Looking For Teleo?

We're no longer selling Teleo, but all the documentation, downloads, and support materials can be found here.

Log in


Forgot your password?
New user?