Show Posts
Pages: 1 ... 49 50 [51] 52 53 ... 142
751  Using Arduino / General Electronics / Re: Security for Arduino. on: December 04, 2013, 07:57:45 pm
@fungus, that looks really cool, I might look at doing the same to mine.

Pricey! 2 connectors cost more than the board!
http://www.digikey.com/product-detail/en/1725753/277-1283-ND/267472

Damn, I got 20 pro mini's for $63.40, the connectors would set me back $350. Maybe just one set for justin...
752  Community / Bar Sport / Re: About low-level programming... on: December 03, 2013, 07:27:01 pm
I can understand function pointer and static friend. But what does it mean by virtual static friend then? If a function is static, can it be overridden by a class that inherits from the base class?

Where does volatile apply? The pointer is changing value so don't optimize code that accesses its value in a register or memory?

Templated is beyond my understanding. I don't use templates yet.

Hmmm, there are a few things not right, I wouldn't take that little quote as anything more than humor.

Static friend is redundant, static or friend should be used,
You cannot take pointers to template functions only a particular instantiation:  foo<>, foo<int>, which is not a template any more but a fully defined entity.
Virtual static is wrong, a static non-member is not bound to any object and therefore has no 'virtual' implications. This also applies to friend, these keywords imply a non-member entity.
753  Using Arduino / Networking, Protocols, and Devices / Re: Proposed change to Ethernet's write() / print() return value on: December 03, 2013, 11:07:58 am
Quote
Please define why the proposed change will let your code fail. You might just measuring some other fact but the code will run without problems.

The code will run without problems, but will not show the number of bytes physically transmitted through the stream to its final destination. Just because there are multiple destinations, doesn't mean that each byte wasn't separately transmitted.

My throughput class wants to know what has been transmitted by the EthernetServer, not by an individual client of it, which my code knows nothing.

As the value is either 0 for fail or greater for something sent, it might as well contain something useful rather than a partial and unusable count of data transmitted, or more closely, the data transmitted down a single path of a potentially complex system.
754  Using Arduino / Networking, Protocols, and Devices / Re: Proposed change to Ethernet's write() / print() return value on: December 03, 2013, 06:35:55 am
As Serial, EthernetClient, EthernetServer all use the stream library they should all adhere to it. Changing the rules to suit is a bad choice.

For instance, I should have no need to know what is further down the stream. Consider a throughput counter ( I just whipped one up ). It rely's on the rules outlined by the Stream definition, your mods would not return a correct measure of data sent and cause my code to fail. The main point is, changing a stream element can cause all elements higher than it to gracefully fail.

Code:
 enum TP_STREAM_ID{ TP_INPUT, TP_OUTPUT };
  
  class ThroughPut : public Stream{
  
    public:
      ThroughPut( Stream &s_Stream ) : stream( s_Stream ), DataIn( 0 ), DataOut( 0 ) { return; }
      
      int available( void ) { return stream.available(); }
      void flush( void ) { stream.flush(); }
      int peek( void ) { return stream.peek(); }
      
      unsigned int getCount( TP_STREAM_ID t_ID ) { return t_ID ? DataOut : DataIn; }
        
      int read( void ){
        int i_Return = stream.read();
        if( i_Return != -1 ) ++DataIn;
        return i_Return;
      }

      size_t write( uint8_t u_Data ){
        const size_t s_Return = stream.write( u_Data );
        DataOut += s_Return;
        return s_Return;
      }
      
    protected:
    
      Stream &stream;
      unsigned int DataIn;
      unsigned int DataOut;
  };  
755  Using Arduino / Programming Questions / Re: PROGMEM headache !!! Why life is soooo complicated? on: December 03, 2013, 05:45:45 am
Just tried it, works with the change from pointer to array type,  got 'Test 1' in serial.
756  Using Arduino / Programming Questions / Re: PROGMEM headache !!! Why life is soooo complicated? on: December 03, 2013, 05:42:39 am
Oh hadn't actually tried it. Change A, B from:
Code:
char * A PROGMEM = "Test 1"; // Definition of a language-dependent string
char * B PROGMEM = "Test 2"; // Definition of a language-dependent string

To:
Code:
char  A[] PROGMEM = "Test 1"; // Definition of a language-dependent string
char  B[] PROGMEM = "Test 2"; // Definition of a language-dependent string
757  Using Arduino / Programming Questions / Re: PROGMEM headache !!! Why life is soooo complicated? on: December 03, 2013, 05:21:16 am
Its not too dumb at all, you've asked for an array of pointers to chars, which is what you've got.

The trick is the pointers need to be PROGMEM pointers too, like:

Code:
char * A PROGMEM = "Test 1"; // Definition of a language-dependent string
char * B PROGMEM = "Test 2"; // Definition of a language-dependent string

char *MyPRG[]  PROGMEM = {
  A,
  B
};

Then to access the pointer in the array you have to get the PGM data for the pointer:

Code:
 //Read pointer from array.
  const __FlashStringHelper *data = ( __FlashStringHelper * ) pgm_read_word( &MyPRG[ 0 ] );

  //Read data from pointer
  Serial.print(  data  );

I used serial as a shortcut to print the PROGMEM data, however you can use memcpy_P or pgm_read_byte.
758  Using Arduino / Programming Questions / Re: Passing object to child class on: December 03, 2013, 02:11:30 am
void is the type, the '*' denotes a pointer. Applied to the Adafruit_NeoPixel type you get:

Code:
Adafruit_NeoPixel*_strip;
759  Development / Other Software Development / Re: CRC32 for Streams ( Ethernet, Serial, Wire, SoftwareSerial,...) on: December 02, 2013, 03:34:28 pm
Yeah, I certainly can do a CRC16, I did this one for quick compatibility with my PHP server. I'm using this in a form of secure communication and thought CRC32 would be better.

I'm also looking at others such as SHA-1 and MD5.
760  Using Arduino / Networking, Protocols, and Devices / Re: URI Encoder, useful for web server/clients. on: December 02, 2013, 10:36:02 am
Cheers Tim, I have just posted another one of my tools which may interest you, it is a CRC class for streams here: http://forum.arduino.cc/index.php?topic=202336.0

I have linked from that page a DualWriter, which may  be useful for debugging purposes, or streaming data to the internet and an SD module at the same time.

Also there is a Base64 encoder, similar to this URI encoder, as in it works with a Print reference.

I will have many more to come soon!
761  Development / Other Software Development / CRC32 for Streams ( Ethernet, Serial, Wire, SoftwareSerial,...) on: December 02, 2013, 10:28:12 am
Hi all, I have a new piece of code to post.
This library can calculate a running CRC32 on a stream object.

Here are some other objects I have recently worked on, these are all part of a new library I'm planning to release.
Dual Writer
Base64Writer
URI Encoder

Below is the test code I wrote for it. The code will take anything and on a new line or carriage return the CRC of what has streamed in & out will be printed.

Like the tools posted above, they take a reference to a Print or Stream object, in this example, I use Serial.

The main functions ( apart from the print functionality ) are:
  • getCRC
  • resetCRC

    Each one takes a value specifying the CRC to use. The options are CRC_INPUT and CRC_OUTPUT

    This library is built off the CRC32 code I found here, linked from here.

    Test code for StreamCRC:
    Code: (test.ino)
    #include <StreamCRC.h>

    StreamCRC s_CRC( Serial );

    void setup(){
      Serial.begin( 9600 );
      Serial.println( F("Type anything to get started, on a new line or carriage return the CRC of what has streamed in & out will be printed.") );
    }

    void loop(){

      if( s_CRC.available() > 0x00 ){

        switch( s_CRC.peek() ){
        
          case '\r':
          case '\n':
          
            //Only print CRC if something has been recieved other than a new line char.
            if( s_CRC.getCRC( CRC_INPUT ) != 0 ){
              
              Serial.print( "\r\nOUT CRC: " );
              Serial.println( s_CRC.getCRC( CRC_OUTPUT ), HEX );
              s_CRC.print( "IN CRC: " );
              s_CRC.println( s_CRC.getCRC( CRC_INPUT ), HEX );
            }
            s_CRC.read();
            s_CRC.resetCRC( CRC_OUTPUT );
            s_CRC.resetCRC( CRC_INPUT );
            break;
        
          default:
            s_CRC.write( s_CRC.read() );
        }
      }
    }

    A test typing HELLO printed a CRC verifyable with PHP.
    Quote
    Type anything to get started, on a new line or carriage return the CRC of what has streamed in & out will be printed.
    HELLO
    OUT CRC: C1446436
    IN CRC: C1446436

    I will add the code here for people not logged on, also the files are attached.

    Code: (StreamCRC.h)
    #include "Arduino.h"

    #ifndef HEADER_CRCSTREAM
      #define HEADER_CRCSTREAM
      
      enum CRC_STREAM_ID{ CRC_INPUT, CRC_OUTPUT };
      
      class StreamCRC : public Stream{
        public:
          StreamCRC( Stream &s_Stream ) : stream( s_Stream ), CRCIN( ~0L ), CRCOUT( CRCIN ) { return; }
          
          int available( void ) { return stream.available(); }
          
          void flush( void ) { stream.flush(); }
          
          unsigned long getCRC( CRC_STREAM_ID c_ID ) { return ~( c_ID ? CRCOUT : CRCIN ); }
            
          int peek( void ) { return stream.peek(); }
            
          int read( void );
          
          void resetCRC( CRC_STREAM_ID c_ID ) { ( c_ID ? CRCOUT : CRCIN ) = ~0L; }
          
          size_t write( uint8_t u_Data );
        protected:
          Stream &stream;
          unsigned long CRCIN;
          unsigned long CRCOUT;
      };
    #endif

    Code: (StreamCRC.cpp)
     #include "StreamCRC.h"
      
      uint32_t crc_table[ 0x10 ] PROGMEM = {
        0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
        0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
      };

      void crc32Byte( unsigned long &u_CRC, uint8_t u_Data )
        {
          uint8_t u_Idx;
          u_Idx = u_CRC ^ u_Data;
          u_CRC = pgm_read_dword( crc_table + ( u_Idx & 0x0F ) ) ^ ( u_CRC >> 4 );
          u_Idx = u_CRC ^ ( u_Data >> 4 );
          u_CRC = pgm_read_dword( crc_table + ( u_Idx & 0x0F ) ) ^ ( u_CRC >> 4 );
        }  
      
      int StreamCRC::read( void )
        {
          const int i_Read = stream.read();
          if( i_Read != -1 ) crc32Byte( CRCIN, ( uint8_t ) i_Read );
          return i_Read;
        }  
        
      size_t StreamCRC::write( uint8_t u_Data )
        {
          crc32Byte( CRCOUT, u_Data );
          return stream.write( u_Data );      
        }

    Hope someone can get some use out of this, and as always any comments are appreciated.
762  Using Arduino / Networking, Protocols, and Devices / Re: WiFi shield server library corruption/crashes on: December 02, 2013, 05:52:55 am
I would like to help with a firmware solution, however I don't have a shield. So if anyone has seen a cheap(er) version available please post where you saw it.
763  Using Arduino / Networking, Protocols, and Devices / URI / Percent Encoder, useful for web server/clients. on: December 01, 2013, 11:29:44 pm
Here is another tool I have whipped up for use in my project. You can see the previous Base64 Encoder here: http://forum.arduino.cc/index.php?topic=201007.0

This tool will take your input and make it safe for transmission via things like http URL's. Here is a quick example.
URIEncoder is the class, it takes a print object, and an optional value of either: URI_STANDARD, URI_WWWFORM,  or URI_ALL.

By default URI_STANDARD is used.

Code:
#include <URIEncode.h>

void setup() {
  Serial.begin( 9600 );

  URIEncoder u_Enc( Serial, URI_STANDARD );
  
  Serial.print( F("http://www.google.com/search?q=") );
  u_Enc.print( F( "how to use c++ operator []" ) );
}

This returns:
Quote

Using URI_WWWFORM you will get:
Quote

And finally using URI_ALL:
Quote

you can set/get the mode using the Mode function.

The files are attached and provided here for people not logged in:
Code: (URIEncode.h)
#include "Arduino.h"

#ifndef HEADER_URIENCODE
  #define HEADER_URIENCODE
  
  enum URI_MODE{ URI_STANDARD, URI_WWWFORM, URI_ALL };
  
  class URIEncoder : public Print{
    public:
    
      URIEncoder( Print &p_Out, URI_MODE u_Mode = URI_STANDARD ) : Output( p_Out ), Mode( u_Mode ) {}
      size_t write( uint8_t u_Data );  //Derived from Print.
      
      URI_MODE URIMode( void ) { return ( URI_MODE ) Mode; }
      void URIMode( URI_MODE u_Mode ) { Mode = u_Mode; }
      
    protected:
      Print &Output;
      char Mode;
  };
#endif

Code: (URIEncode.cpp)
#include "URIEncode.h"

#define URI_CHAR_COUNT  19

char URIChars[ URI_CHAR_COUNT ] PROGMEM = {
  '!', '*', '\'', '(', ')', ';', ':', '@', '&', '=', '+', '$', ',', '/', '?', '#', '[', ']', ' '
};


size_t URIEncoder::write( uint8_t u_Data )
{
  bool b_Found = false;
  
  if( Mode != URI_ALL ){

for( char c_Index = 0x00 ; c_Index < URI_CHAR_COUNT ; ++c_Index ){
 if( pgm_read_byte( URIChars + c_Index ) == u_Data )
b_Found = true;
}
  }else
b_Found = true;
  
  if( b_Found ){
  
if( u_Data == ' ' && Mode == URI_WWWFORM )
 return Output.write( '+' );

Output.write( '%' );
Output.print( u_Data, HEX );
return 0x03;

  }else
return Output.write( u_Data );
}

Let me know what you think, I'm also planning to do up stream supporting equivalents for this and the base64 class.
764  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 07:49:39 pm
Quote
edit: I don't think you stole anybody's socket. I think the firmware overwrote your socket when your web browser requested the icon. That may be what Matt was trying to get across to me.

Yeah, not stole, but If the wrong remote socket data can be sent to my local socket, then someone could effectively receive my potentially private/secure page that I have requested.

Quote
It would be extremely helpful if I could access the remote IP and port requesting the files. If they are the same on both requests, that would explain a lot, and maybe help fix this.

You could mimic the session ID with a sequential ID, then browsers, will respond with the ID string you provide. Not useful for a first request, but subsequent requests should contain the ID.

Why not just do the mods you where talking about ( or was that the Ethernet shield only ).
765  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 08:18:04 am
Lucky I didn't let the browser page close, cos as you say it did load the favicon. After a short delay the tab changed its icon to that of the waterfall picture. If the wifi shield is at fault, then that is a huge blunder, no need to hack security if you can just steal someones socket.
Pages: 1 ... 49 50 [51] 52 53 ... 142