Show Posts
Pages: [1] 2 3
1  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 17, 2013, 07:37:28 am
Is there documentation for the STL library?

Google "STL documentation" - About 14,600,000 results.

So, yes, there is.



If you want a book, I would buy this:

The C++ Standard Library - A Tutorial and Reference
By Nicolai M. Josuttis
Published by Addison-Wesley
ISBN: 0-201-37926-0
Cover price: $US 59.99



This is indeed an excellent introduction (around 800 pages), and covers the various container types (lists, maps, vectors etc.) plus the algorithms (sort, etc.), function objects, strings and a whole lot of stuff.

would it be better to get the second edition?
2  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 17, 2013, 07:25:09 am
I would not help someone and then turn around and hang shit on them. I am insulted that you would suggest that.

I have no experience with the STL stuff, as mentioned previously, and think your progress is going well.

Thankfully other people I have (tried to) encouraged / helped have not responded in this way.


trust me, im trying everything people have suggested, only reason i said that your response seemed scarcastic, was because u (aarondc) and Nick seem to be butting heads, and it sounded like u said it in a way because im trying STL and Nicks suggestions. you set the mood here:
I get you're only trying to help, but am confused why you ignore other people's posts, going as far as saying they are "mucking around" suggesting things like circular buffers, when a page later, you are suggesting exactly the same thing, and rehashing what someone has already posted. Seems a bit inefficient?

shall we say that as calls arrive they need to be stored in some sort of simple list. The space needed for this list could be kept short. For example room names can be simply an int (2 bytes) corresponding to where that is in the list of room names from the file on the SD card. For example if  "KITCHEN" is received and that is the 20th line in the data file, we store 20.

Similarly the codes can be a byte (eg. NORMAL, CODE BLUE etc.). The time received can be an unsigned long (4 bytes). The counter you describe can be another byte or int maybe. So far you only need 9 or 10 bytes per outstanding call.

Is pretty much what I said here:

If you can create a basic data structure along the lines of (this is not code, it will not compile, extraneous brackets may be present):

Code:
struct requestType {
    byte room_name_pointer; // pointer to an array of room names
    byte room_floor;    // floor this room appears on
    byte room_number; /// guess ;-)
    byte service_requested; // pointer to an array of possible services
    int request_start_time;  // when we requested the service
(etc)
}

and then a circular buffer similar to what Serial library implements, based on the maximum concurrent requests expected to be current at any one time, +20% to +100%:

requestType request_buffer[200];
...
If you are expecting 120 requests / hour (2 / minute) max, and the longest request response time is 1 hour (just as an example), then you'd only need to store 120 such requests, and for the majority of the time, you'd have less than that in the buffer waiting to be completed.

Where circular buffer is a simple list, and 200 elements is pretty short.

On the Mega with 8K of RAM you could therefore store 800 outstanding calls which I presume you are unlikely to have. The idea of a 1000 bed hospital with 800 rooms in some sort of crisis at the same time seems a bit far-fetched.

Is almost identical to what I wrote a page ago:

My point being: it is unlikely that you will have 1000 rooms simultaneously requesting assistance. Even if you had half the rooms requesting it, as soon as a response has been handled, you don't need that data any more, and could reuse the memory it occupies fairly simply.

Would be curious what simple list implementation you suggest, Nick?
3  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 17, 2013, 12:26:28 am
Good work, love your progress!
sounds sarcastic.

do you have an alternative solution?
4  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 16, 2013, 11:13:52 pm
Well i tried to modify it a bit and make a couple of other functions to find data in the objects.

I made this to remove an object greater than or equal to a passed variable.
Code:
struct time_greaterthan_equal_to :
std::binary_function <requestStruct, unsigned long, bool>
{
  bool operator() (const requestStruct & p, const unsigned long iTime) const
  {
    return p.request_start_time >= iTime;
  };
};  // end of struct room_equal_to

and it works when i call it:  
Code:
requests.remove_if (bind2nd (time_greaterthan_equal_to (), 999));


And i even was able to check with functions to find expired calls.

Code:

void checkToPage(){
  
  //Serial << F("checking to page. ") << endl;
  
  for (requestIterator it = requests.begin (); it != requests.end (); it++)
  {
    if(it->request_start_time >= 5000)
    Serial << F("PAGING CALL  - Room: ") << it->room_number << F(" type: ") << it->service_requested << F(" time: ") << it->request_start_time << endl;
  }
  //Serial << endl;
}

but i cant remove expired calls with feedback:
Code:

void checkToRemove(){

  //Serial << F("checking to page. ") << endl;

  for (requestIterator it = requests.begin (); it != requests.end (); it++)
  {
    if(it->request_start_time >= millis () - 10000)
      Serial << F("REMOVING CALL - Room: ") << it->room_number << F(" type: ") << it->service_requested << F(" time: ") << it->request_start_time << endl;
      requests.remove_if (bind2nd (time_greaterthan_equal_to (), millis () - 10000));
  }
  //Serial << endl;
}

it crashes and prints this over and over:
Code:
REMOVING CALLS Room: 100 type: 3 time: 0
REMOVING CALLS Room: 8666 type: 208 time: 3520136225
REMOVING CALLS Room: 8666 type: 208 time: 3520136225
REMOVING CALLS Room: 8666 type: 208 time: 3520136225
REMOVING CALLS Room: 8666 type: 208 time: 3520136225
...
...
...


Im sure there are better ways to code these. Is there documentation for the STL library?

5  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 16, 2013, 10:28:24 am
This is great, i can understand this example pretty well.
 
so two calls adds totally add my call to the "List".

Code:
requestStruct r1 = { NORMAL, millis () };   //this sets up the requestStruct.
requests [100] = r1;                                       // this Maps the the Int 100 to the requestStruct Just created.

if i create another call say from the same room, it over writes the previous request. how would i be able to hold multiple calls from the same room? should i use arrays for the service_requested, and request_start_time. Would i have to store it to a different map location? i have no previous experience with this on arduino.

THANK YOU ALL, i appreciate the time you guys are using to help me.
6  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 15, 2013, 10:46:05 pm
so the Struct is basicly the object in java, except for its methods/functions, just the variables that relate to each of the objects.

how do you talk to a Struct ( set or read the variables within) without dictating the methods/functions??
 
7  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 15, 2013, 10:41:18 pm

get it working with one room only - make sure you have all the logic right to handle that room with the different use cases, making sure you have abstracted logic into function calls so the code reads simply and easily

so basicly:
  • setup the Struct...
  • get the serial data to go into my struct.
  • then implement ring buffer??
8  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 15, 2013, 10:37:53 pm
i thought the circular buffer is the "heart" of this type of program, doesn't everything rely and revolve around it?
9  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 15, 2013, 10:31:39 pm
well the HardwareSerial is a library, and my first time building/converting/porting one. I'm just kinda converting over as much as i can of the HardwareSerial to my needs, what ever i can understand anyway...

what is this:
Code:
->
10  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 15, 2013, 10:17:18 pm
Quote
They store chars, just replace the char with your struct and you're good to go.

Im afraid this is where i start to lose ya, I would consider myself a beginner with arduino/c/c++. i learn from examples.

Code:
#define REQUEST_BUFFER_SIZE 200


struct request_buffer
{
  requestStruct request[REQUEST_BUFFER_SIZE];
  volatile unsigned int head;
  volatile unsigned int tail;
};


CustomRingBuffer::CustomRingBuffer(request_buffer *buffer){
_buffer = buffer;
}

int CustomRingBuffer::available(void)
{
  return (unsigned int)(REQUEST_BUFFER_SIZE+ _buffer->head - _buffer->tail) % REQUEST_BUFFER_SIZE;
}

request_buffer HardwareSerial::read(void)
{
  // if the head isn't ahead of the tail, we don't have any characters
  if (_rx_buffer->head == _rx_buffer->tail) {
    return -1;
  } else {
    request_buffer c = _buffer->buffer[_buffer->tail];
    _buffer->tail = (unsigned int)(_buffer->tail + 1) % REQUEST_BUFFER_SIZE;
    return c;
  }
}


with my custom struct:
Code:
struct requestStruct{
    int room_name_pointer; // "pointer" to an array of room names
    byte service_requested; // pointer to an array of possible services
    int request_start_time;  // when we requested the service
}

i hope im on the right track...

would this be how i setup a ring buffer with my custom struct?
Code:
request_buffer buffer = { { 0, 0, 0 }, 0, 0};

11  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 15, 2013, 09:47:41 pm
So to setup this with the recommendations given should i use the STL library?  http://andybrown.me.uk/wk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/

Is there examples using a Struct built buy a user with STL?
12  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 15, 2013, 01:59:11 pm
  • Receive serial Data Strings
 
examples

:"06/28/13  14:44:05    101.    NORMAL     CALL PLACED"
:"06/28/13  14:44:06    101.    NORMAL     CALL CANCELLED"
:"06/28/13  14:44:06    131     NORMAL     CALL PLACED"   // notice the period replaced by space...
:"06/28/13  14:44:06    101.A   NORMAL     CALL PLACED"  // notice the space after the period is now an 'A', it signifies a sub area
:"06/28/13  14:44:06  2A101     NORMAL     CALL PLACED"   //notice the strange formated room number, this is still valid.
:"06/28/13  14:44:36    101     FAILED"         // other messages that for memory reasons, I'm ignoring until system can handle larger scale.
:"06/28/13  14:45:13    101     RESTORED"     // ignoring.
    • "Filter" it..
            Ignore the Date and times. Match Room "numbers" (really a String or char[]) with programmed list so only certian rooms get passed to the next step.
             Only text in these areas are considered room "numbers", ignore the period and possible letter after.
                          :"06/28/13  14:44:05    101.    NORMAL     CALL PLACED"
                          :"06/28/13  14:44:06    101.    NORMAL     CALL CANCELLED"
                          :"06/28/13  14:44:06    131     NORMAL     CALL PLACED"  
                          :"06/28/13  14:44:06    101.A   NORMAL     CALL PLACED"
                          :"06/28/13  14:44:06  2A101     NORMAL     CALL PLACED"  
                          :"06/28/13  14:44:36    101     FAILED"    
                          :"06/28/13  14:45:13    101     RESTORED"          

    • The room "number" match is used to toggle an element in a 2d Boolean array, each Row in this array relates the the rooms. Each column in the 2d array relates the the type of call received (NORMAL, CORDOUT, CODE BLUE, FIRE...). The "CALL PLACED" text sets  the element True, the  "NORMAL     CALL CANCELLED" text sets the element False.

      This doesn't have to be a 2d Boolean array,or the method i used to do it, but has to accomplish the same goal. It stores the information to know if a certain call was placed from a certain room for the next step...
    • Output something else...
            As soon a as call is placed for the first time (found out by checking the 2d Boolean array), a String is passed to Serial2. This String needs to be formatted a certian way. Aside from the Ascii codes sent, A Pager number is sent in this "String". The pager number is contianed in another 2d array, Each row related to rooms, each column is a Pager level. The Pager level array will change throughout the day (one for each shift). Text containing a NEW room "number", and NEW call type text is also sent. These can be hard coded Strings, but they are built from data matching the original incoming data. So when a call is Initially recieved ("06/28/13  14:44:05    101.    NORMAL     CALL PLACED"), new data sent to Serial2 would be (<SOH> "A5" "Pager_level_element[0]" <STX> "New_room_number" " : " "New_call_type" <ETX> <EOT>)....[/list]

    I Use the SimpleTimer Library so every second i go through the 2d Boolean array, find the True elements, then i add 1 to a seperate int TimeArray (2d array) at the same location as the boolean array. During this period i check the TimeArray, if a value reaches a global variable (say 30), then another page is sent out. Most of the data is the same this round, except for the pagerLevel (now using Pager_level_element[1]). If the value reaches a second global variable (say 60), then another page is sent out. Most of the data is the same this round, except for the pagerLevel (now using Pager_level_element[2]). After that if a value reaches a third global variable (say 3600) , we toogle the boolean array false, set the TimeArray element to 0 (Used to Timeout the call).

    That is what i need, and its the reason my first try contained multiple 2d arrays, and a bunch of String arrays.

    Quote
    I'm not too concerned about what the original code actually does, as code posted by beginners to Arduino can often not reflect what they really want.
    I'm with you 100% on this one...


    Quote
    I should point out too that the idea of keeping the lookup data on an SD card would make it much easier to update during its lifetime (eg. if a room gets added, its function changed, or simply a spelling mistake) rather than having to take the Mega out of service to be reprogrammed, assuming that the programmer (person) is still available. Having a simple text file, saved to SD, means anyone with basic computer skills could keep the database up to date.
    Well this is when i started seeing the memory problem... I need to have a feature similar to this, either with the Sdcard, or Via the Ethernet shield. The user only should be able to change the assignments in the PagerArrays at this point. I was even debating on running a webserver from a Raspberry Pi, and Serial the data over to the arduino to change to PagerArrays on the fly. But the main point is that i would like this part of the project to be a single chip/PCB solution. Say if the SdCard is removed, i would like the system to default the user changeable features back to a initially programmed state.


    Moderator edit: Code tags added to show formatting (Nick Gammon)
    13  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 14, 2013, 04:40:55 pm
    a user had said a ring buffer would hold my data with minimum size, but since i dont truly understand the topic, im going to take a step back. Whats the smallest  datatype that i can pout into an array? i searched for arrays of bits, but theres is no easy way to access them.
    14  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 14, 2013, 04:27:22 pm
    what does the "->" minus then greaterthan signs mean in HardwareSerial.cpp

    Code:
    int HardwareSerial::read(void)
    {
      // if the head isn't ahead of the tail, we don't have any characters
      if (_rx_buffer->head == _rx_buffer->tail) {
        return -1;
      } else {
        unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
        _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
        return c;
      }
    }
    15  Using Arduino / Project Guidance / Re: Serial filtering program issues - running out of memory. on: July 14, 2013, 01:10:00 pm
    Ok, so the struct is the ring buffer?:
    Code:
    struct ring_buffer
    {
      unsigned char buffer[SERIAL_BUFFER_SIZE];
      volatile unsigned int head;
      volatile unsigned int tail;
    };

    Depending on the hardware port, the struct(array) is setup accoringly?:
    Code:
    #if defined(USBCON)
      ring_buffer rx_buffer = { { 0 }, 0, 0};
      ring_buffer tx_buffer = { { 0 }, 0, 0};
    #endif
    #if defined(UBRRH) || defined(UBRR0H)
      ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
      ring_buffer tx_buffer  =  { { 0 }, 0, 0 };
    #endif
    #if defined(UBRR1H)
      ring_buffer rx_buffer1  =  { { 0 }, 0, 0 };
      ring_buffer tx_buffer1  =  { { 0 }, 0, 0 };
    #endif
    #if defined(UBRR2H)
      ring_buffer rx_buffer2  =  { { 0 }, 0, 0 };
      ring_buffer tx_buffer2  =  { { 0 }, 0, 0 };
    #endif
    #if defined(UBRR3H)
      ring_buffer rx_buffer3  =  { { 0 }, 0, 0 };
      ring_buffer tx_buffer3  =  { { 0 }, 0, 0 };
    #endif

    Data is sent into the ring buffer via:
    Code:
    inline void store_char(unsigned char c, ring_buffer *buffer)
    {
      int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;

      // if we should be storing the received character into the location
      // just before the tail (meaning that the head would advance to the
      // current location of the tail), we're about to overflow the buffer
      // and so we don't write the character or advance the head.
      if (i != buffer->tail) {
        buffer->buffer[buffer->head] = c;
        buffer->head = i;
      }
    }

     After that i can kinda see how it turns into the Serial library that I'm using to get the data into my current application.I just not making the connection on how this would work with my data? User Aarondc suggested this data structure for the ring buffer:
    Code:
    struct requestType {
        byte room_name_pointer; // pointer to an array of room names
        byte room_floor;    // floor this room appears on
        byte room_number; /// guess ;-)
        byte service_requested; // pointer to an array of possible services
        int request_start_time;  // when we requested the service
    (etc)
    }
    I understand this idea from java with classes/objects. but implementing on the arduino seems too much for me to understand.
    Pages: [1] 2 3