Pages: 1 [2]   Go Down
Author Topic: Proof of concept  (Read 2133 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I hopefully got it to work now, sorta. My idea was to first read nine bytes on the eth port, the length of the id string each reader sends out. then the first nine bytes are passed into the idstring variable, after which next 16 bytes are read, which are passed to the serial port, as they are the payload code. This should ensure that the two strings are properly separated.
The compiler gives me an error, as the eth port reads into a separate variable to buffer it, which is initialised without a size, but is increased as the port reads data (the code contains an incrementing counter, which at one point is used as the size of the buffer string).

Code:
int bytesread;
char bufferstring[] = {}
later:
bufferstring[bytesread]

This means the program compiles with an error that conversion from char[0] to char[9] is invalid, but I think this is actually just a result of the compiler being unable to follow the program as it actually executes, so it should not be a problem when actually deployed, no?

I know it will all be easier to imainge and understand once I get some code up, but that will only happen tomorrow, as I'm working without a net access on my own computer this weekend.
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int bytesread;
char bufferstring[] = {}
later:
bufferstring[bytesread]

Need to be more like:

Code:
const byte bytesread = 9;
char bufferstring[bytesread] = {0};

This way the compiler knows the size of bufferstring when creating space (allocating) for it.
 smiley

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I thought of that too, but all input from the eth port is buffered in that string, both the 9-byte ID, and the 16-byte payload. That's why I had to work around like this, as it has to deal with both a 9 and a 16-byte string.

Code:
 char idstring [9] = {};
char bufferstring[] = {};
  char payloadstring[16] ={};
  int temp = 0;
  int bytesread = 0;
  if (client.available() > 0)
  {
    if ((temp = client.read()) == 27)
    {
      bytesread = 0;
      while (bytesread<9)
      {
        if (client.available() > 0)
        {
          temp = client.read();
          if (temp == 9)
          {
            break;
          }
          bufferstring[bytesread] = temp;
          bytesread++;
          if (bytesread == 9)
          {
            idstring = bufferstring;
          }
        }
      }
      bytesread = 0
        while (bytesread<16)
      {
        if (client.available() > 0)
        {
          temp = client.read();
          if (temp == 16)
          {
            break;
          }
          bufferstring[bytesread] = temp;
          bytesread++;
          if (bytesread == 9)
          {
            payloadstring = bufferstring;
          }
        }
      }
    }
  }


  lcd.print(payloadstring);
  Serial.print(payloadstring);
  bufferstring = 0;
}

Here's the whole separating code part. Kinda convoluted and messy, but I've just started programming in C smiley-grin
« Last Edit: July 26, 2009, 06:33:24 am by thunderbird » Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You still need to define the bufferstring with a size.

char bufferstring[16] = {'\0'}; //replace 16 with the maximum length of bufferstring
« Last Edit: July 26, 2009, 11:59:51 am by AlphaBeta » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, it's been a while since I last visited this forum, or at least it feels like a lot of time. Since then, this project went from speculation into an actual, implementable coding project, being done on both the Arduino platform, and on PC in C/C++/mySQL. So yeah, it developed a bit...smiley-grin

Still, since this would be my very first time programming something of this kind, I would like a bit more help: the codes seem to compile fine, but I would like to see if human eyes can spot any irregularities/improvements in my code.

Code:
Reader code: http://pastebin.com/m19ee2851
Mediator code: http://pastebin.com/m5c2f236f

Thank you very much for your time, and your names will be included in the source. smiley
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

instead of using different char for each arduino you could use a device id store on the eeprom and read it a start, each recived message would be sent this way

**edited [8bit function] [id] [data] [ack]

i currently have a class that can handdle this if you want, it was started as a project for the serial port but you can use it for any thing... so you would be able to have up to 255 client and also if you want help i can provide a windows vb.net server code for you....

i will make a demo on the arduino soon for the id thing and i am still working on the wiki for my class..

http://code.google.com/p/serialhandler/

also your arduino code i really repetitive i could be much more smaller.... and i cant find void loop(){}

i don't understand why you use a mediator one arduino could = one device that can read talk to the server and trigger door alarm and all for one turnstiles
« Last Edit: August 04, 2009, 04:31:29 am by madrang » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You mean an Arduino would be capable of doing a mySQL query? I needed the mediator because the code that the does the actual verification runs on a PC, and this way, I could have fewer connections to the actual server, and I could handle all the readers with in one station. Although I've been looking into using an XBee module on each one to transmit data wirelessly to the PC, but that would probably mean rewriting the code from scratch (unless the XBee appears to the PC as an ordinary serial port).

I have no loops because I'm using a state machine architecture, the looping is done by a call to the first state at the end of the last one. AlphaBeta's FSM library made it very easy to construct such a state machine, it's way harder on PC. Plus, this makes for easy automatic flow control of the execution, easier than if-then-else statements
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

an xbee is a wireless serial... also you dont need serial, if you have a network port on your arduino, because each device could connect to your server and talk to it directly. but if you use a serial port the mediator is still not needed as i can make a server using the serial port and it will talk to you sql or have is own database. also if you want i can help you with the server part.
« Last Edit: August 05, 2009, 04:42:25 am by madrang » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The server help would probably be much appreciated, thank you smiley

Yes, I do need serial, because the RFID reader itself, a parallax model, communicates via the serial protocol.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

then it will be a server useing serial port
« Last Edit: August 05, 2009, 04:44:12 am by madrang » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i just look at you reader code again and it look like yes you are using serial but not for talking to the pc only for the rfid, so you don't need a mediator as your ethernet shield can talk to your computer trough a server and do all the needed stuff.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

now i have my tcp/ip server but i am not sure that the arduino can connect to it, but i just by an ethernet shield and i should receive it soon also if you want send me an email and i will send the program to you.
Logged

Pages: 1 [2]   Go Up
Jump to: