Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: How to convert a string of '11001100' into an hex 'CC' on: November 08, 2013, 01:01:28 pm
So then, I receive the data in a long, want to reverse it as explained, convert it in an hex value. This will be exported in an Ascii chain.
This last chain will be sent through an http request to a server as a variable.
I know how to do the last part., But wokring on type conversion is something new for me.

Lot of things for an end of week (a chance that this monday is a day off in France)
2  Using Arduino / Programming Questions / Re: How to convert a string of '11001100' into an hex 'CC' on: November 08, 2013, 12:34:06 pm
Well, to make it simple, I attache the entire code.

Hope this is answering the last questions. I'm testing odometer code.

Code:
#include <stdlib.h>

#define MAX_BITS 100
#define WEIGAND_WAIT_TIME  3000

unsigned char databits[MAX_BITS];
unsigned char bitCount;
unsigned char flagDone;
unsigned int weigand_counter;

unsigned long facilityCode=0;
unsigned long long cardCode=0;
char Cardcsn[64];
String CardcsnString;
long CardscsnHex;


void ISR_INT0()
{
  //Serial.print("0");
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 
 
}


void ISR_INT1()
{
  //Serial.print("1");
  databits[bitCount] = 1;
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 
}

void setup()
{
  pinMode(13, OUTPUT);  // LED
  pinMode(2, INPUT);     // DATA0 (INT0)
  pinMode(3, INPUT);     // DATA1 (INT1)
 
  Serial.begin(9600);
  Serial.println("RFID Readers");
 
  attachInterrupt(0, ISR_INT0, RISING); 
  attachInterrupt(1, ISR_INT1, RISING);
 

  weigand_counter = WEIGAND_WAIT_TIME;
}

void loop()
{
  if (!flagDone) {
    if (--weigand_counter == 0)
      flagDone = 1;
  }
 
  if (bitCount > 0 && flagDone) {
    unsigned char i;
   
    Serial.print("Read ");
    Serial.print(bitCount);
    Serial.println(" bits. ");
   
    if (bitCount == 64)
    {

      for (i=0; i<64; i++)
      {
         cardCode <<=1;
         Cardcsn[i] |= databits[i];
         
   //      CardcsnString +=String(Cardcsn[i]);
           
         Serial.print (Cardcsn[i]);
         

      }
     
      SendHex(); 
    }
   
   
    else {
     
     Serial.println("Unable to decode.");
    }

     // cleanup and get ready for the next card
     bitCount = 0;
     cardCode = 0;
     for (i=0; i<MAX_BITS; i++)
     {
       databits[i] = 0;
     }
  }
}

void SendHex()
{
      CardscsnHex = strtoul(Cardcsn, NULL, 16);
      Serial.println();
      Serial.println("csn = ");
      Serial.print(CardscsnHex);

}
3  Using Arduino / Programming Questions / Re: How to convert a string of '11001100' into an hex 'CC' on: November 08, 2013, 12:04:14 pm
You're so right. Well, the main objective of this is to take the 8 octets of a 64 bits and put these in a reverse order.

Example : what is read when using a wiegand reader :
0101111001001111001100100000000111110001111111100010010111000000

If I split into octet
00101111 00100111 10011001 00000000 11111000 11111111 00010010 11100000
And what I need to have
11100000 00010010 11111111 11111000 00000000 10011001 00100111 00101111
This last chains is to be converted into Hex.
I don't know anything about bitwise operator as of today, but I will read carefully your link and see if I can find a solution for this issue I got.

Thanks for the tip
4  Using Arduino / Programming Questions / Re: How to convert a string of '11001100' into an hex 'CC' on: November 08, 2013, 10:33:40 am
Thanks Pauls for a so fast answer.

Well already tried Strtoul() but certrainly in a wrong way. Here is part of the code (without the modifications on the string)

Code:
  if (bitCount > 0 && flagDone) {
    unsigned char i;
   
    Serial.print("Read ");
    Serial.print(bitCount);
    Serial.print(" bits. ");
   
    if (bitCount == 64)
    {

      for (i=0; i<64; i++)
      {
         cardCode <<=1;
         Cardcsn[i] |= databits[i];
         
         CardcsnString += String(Cardcsn[i]);
           
         Serial.print (Cardcsn[i]);
         

      }
     
      SendHex(); 
    }
   
   
    else {
      // you can add other formats if you want!
     Serial.println("Unable to decode.");
    }

     // cleanup and get ready for the next card
     bitCount = 0;
     cardCode = 0;
     for (i=0; i<MAX_BITS; i++)
     {
       databits[i] = 0;
     }
  }
}

void SendHex()
{
      // I really hope you can figure out what this function does
      Serial.println("csn = ");
      Serial.print(CardcsnString);
}
5  Using Arduino / Programming Questions / How to convert a string of '11001100' into an hex 'CC' on: November 08, 2013, 10:27:45 am
Hi all,

I consider myself still as a beginner, but I'm progressing on C programming... as fast as a french guy can.
I'm back with a new challenge for the community. I collect some binary values into a string. Then, I need to convert this into an Hex value..... It's now few hours / nights that I'm surfing on the web to test different things, but nothing works.

Just to tell you the story. I received a signal from a RFID reader. This signal is a 64 bits. I need to play with this string of bit to mix it differently and then convert this into hex value.
Well, if one of you can help me a bit...

Thanks thanks thanks

Regis
6  Development / Suggestions for the Arduino Project / Re: And What about a Mega Ethernet on: November 27, 2012, 12:07:01 pm
Indeed, I work with a mega and an ethernet shield, but would prefer to have an all in one solution...
7  Development / Suggestions for the Arduino Project / And What about a Mega Ethernet on: November 27, 2012, 04:38:37 am
Hi,

I'm developping dozens of solutions for automatism and other purposes. Today, I have to work on RFID Prject involving 3 readers. Then, no other chance to use the Mega for the 3 interrupt inputs. But need to add an Ethernet Shield.

Xmas is coming soon, and I'm expecting a Mega Ethernet from the Arduino community... Is this in the pipe ?

Cheers all

Regis
8  Using Arduino / Programming Questions / Re: Simple String to Byte conversion on: July 03, 2012, 02:37:24 am
Alright,

I've intergrated your code in mine and used the 'magic atoi'. That works properly now...
But just for fun, I kept my previous code and simply unsed this 'atoi'... it works too. Finally, I've used yours.

Thanks for the help
9  Using Arduino / Programming Questions / Re: Simple String to Byte conversion on: July 02, 2012, 03:45:12 pm
Thanks for the code... and for the explanation. I will keep it in mind for futur development, but.... time is flying faster in France than in the US. I will test this tomorrow morning and intergrate that in my code.
Before working on this, may I change the int type of address[] in byte ? Still the same issue : I need to integrate this variable in the Ethernet.begin function... but may be I ask this question as it is late for me now.

Once again, I thank you for these lines
10  Using Arduino / Programming Questions / Re: Simple String to Byte conversion on: July 02, 2012, 11:47:25 am
Few explanations: the code above is a part only of the overall program (dealing with RFID and LCD).

The variable readString is the http request. For this part of the program, readString = setup?SBM=1&DT1=192&DT2=168&DT3=0&DT4=20&DT5=255&DT6=255&DT7=255&DT8=0&DT9=192&DT10=168&DT11=0&DT12=2

I've used few lines of another project I found on the web (thanks to Jori :  http://www.jo3ri.be/arduino/arduino-projects/network-settings-web-page-form-using-eeprom-to-save-submit) but need to drastically change jori's code.

The entire program is quite hudge but if it can help, I can post all of it.

Code:
//***************Begin Setup Page**********************
//*********************************************************
void PageSetup()
{
char readStringchar[150];
char buffer[150];
char *pos,*key,*data;
char *keyarray[25];
char *dataarray[25];

readString.toCharArray(readStringchar, 150);

  int i=0;
  key = pos = readStringchar;
  while(*pos)
  {
    switch(*pos)
    {
      case '=':
        *pos = 0;
        pos++;
        data = pos;
        break;
      case '&':
        *pos = 0;
        Serial.print("Key: ");
        Serial.print(key);
        keyarray[i] = key;
        Serial.print(" Value: ");
        Serial.println(data);
        dataarray[i] = data;
        pos++;
        i++;
        key = pos;
        break;
    }
    pos++;
  }

  Serial.print("Key: ");
  Serial.print(key);
  Serial.print(" Value: ");
  Serial.println(data);
  //keyarray[i] = key;
  //dataarray[i] = data;
   
                  for (int i = 0 ; i < 4; i++){
                  Serial.print ("ip");
                  Serial.println (ip[i]);                }
                for (int i = 0 ; i < 4; i++){
                  Serial.print ("subnet");
                  Serial.println (subnet[i]);                }
                for (int i = 0 ; i < 4; i++){
                  Serial.print ("gw");
                  Serial.println (gateway[i]);                }
 
          if (readString.indexOf("SBM")>0){
                Serial.println ("ok SBM");
                for (int i = 1 ; i < 5; i++){
                  ip[i] = int(dataarray[i]);
                  Serial.print ("ip");
                  Serial.println (ip[i]);                }
                for (int i = 1 ; i < 5; i++){
                  subnet[i] = byte(*dataarray[i+4]);
                  Serial.print ("subnet");
                  Serial.println (subnet[i]);                }
                for (int i = 1 ; i < 5; i++){
                  gateway[i] = byte(*dataarray[i+8]);
                  Serial.print ("gw");
                  Serial.println (gateway[i]);                }
            // save to EEPROM
/*            for (int i = 1 ; i < 5; i++){
              EEPROM.write(i, ip[i]);
            }
            for (int i = 1 ; i < 5; i++){
              EEPROM.write(i + 4, subnet[i]);
            }
            for (int i = 1 ; i < 5; i++){
              EEPROM.write(i + 8, gateway[i]);
            }

            // set ID to the known bit
            EEPROM.write(0, 0x92);
*/
          }//End if SBM
         
         
  //ShieldSetup();
  server.begin(); //starting the server
  EthernetClient client = server.available();
  char c;
  if (client) {
    Serial.println ("If CLient");
  boolean currentLineIsBlank = true;
    Serial.println ("While client connected");
  if (client.available()) {
          Serial.println ("If CLient Available");
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          for (int i = 0; i < 4; i++)
            {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table0[i])));
            client.print( buffer );
            }

          strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[0])));
          client.print( buffer );
         
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[0])));
          client.print( buffer );
          client.print(ip[0],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[1])));
          client.print( buffer );
          client.print(ip[1],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[2])));
          client.print( buffer );
          client.print(ip[2],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[3])));
          client.print( buffer );
          client.print(ip[3],DEC);
         
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[0])));
          client.print( buffer );
          client.print(subnet[0],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[1])));
          client.print( buffer );
          client.print(subnet[1],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[2])));
          client.print( buffer );
          client.print(subnet[2],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[3])));
          client.print( buffer );
          client.print(subnet[3],DEC);

          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[0])));
          client.print( buffer );
          client.print(gateway[0],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[1])));
          client.print( buffer );
          client.print(gateway[1],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[2])));
          client.print( buffer );
          client.print(gateway[2],DEC);
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[3])));
          client.print( buffer );
          client.print(gateway[3],DEC);


          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[4])));
          client.print( buffer );
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[5])));
          client.print( buffer );


    }//end If Client.available
    delay(5);

    Serial.println("Client Stop");
    client.stop();
//  }// End While Client
          readString="";

  }//End If Client

      }//End Void
//***************End Setup Page**********************
//*********************************************************
11  Using Arduino / Programming Questions / Re: Simple String to Byte conversion on: July 02, 2012, 11:08:11 am
Understood,
Problem : I need to use this 1234 in the Ethernet.begin(mac, IP). More into details : a server will send the IP to use in the Arduino.

Then, I got something like GET/?IP1=192&IP2=168 and so on. Then, I need to catch thses values to integrate that in the Ethernet.begin variables...

I use this arduino in a hudge project and this can help me to solve some automatism issues...
12  Using Arduino / Programming Questions / Simple String to Byte conversion on: July 02, 2012, 10:12:20 am
All,

I'm working on a new project and as a beginner, I need to catch a string (a figure) from a HTTP request and convert it to Byte type.
I receive data from a server a need to intergrate these into my Arduino program.
After some shours surfing on the web, I'm back on this forum to search some help...
13  Using Arduino / Programming Questions / Re: So Simple in C++ on: June 14, 2012, 09:28:42 am
Awol, Pyro, the code has compiled...

Don't know where you are, but would have the opportunity to pay you a beer for your help.
First, you have solved my problem with only adding a * to my code, plus, I had the pleasure to learn lot more today.

This development is really important and will probably save a hudge project in RFID access control.

Then, many thanks from France
14  Using Arduino / Programming Questions / Re: So Simple in C++ on: June 14, 2012, 09:17:15 am
How Mac represented... not qui te sure to understand the question. Need to replace the original array

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

So, now I've understood the problem I got. Is there any chance for me to 'extract' the data of at a specific addresse ? For me as a beginner, I find strange that if I enter

Serial.println(dataarray); // (with i=5 for example)

I got an answer wich is corresponding to the content and not the address... I got so many things to learn...
Then, my question is : how to convert the content and not the address...

pYro, thanks for the links, didn't have time to read these, but I promise you that I will read these carefully.
15  Using Arduino / Programming Questions / Re: So Simple in C++ on: June 14, 2012, 08:47:44 am
Sure
The first 6 pointers are for mac, the others are for the rest of the code. This array is the result of the parse of a client request.

Thanks for the "just to confuse you more".... I am now more confused....
Pages: [1] 2