Projet CRIC / Mbed 2 deprecated CRIC_RFID

Dependencies:   mbed

Fork of CRIC_RFID by Anthony Goncalves

main.cpp

Committer:
toni
Date:
2014-11-12
Revision:
0:a6addbfe44b4
Child:
1:6713f9d95bad

File content as of revision 0:a6addbfe44b4:

#include "mbed.h"

DigitalOut myled(LED1);

Serial debugPC(USBTX, USBRX);   // tx, rx   //Communication pour le debug entre le PC et le mbed
Serial comRFID(p13, p14);       // tx, rx   //Communication entre le mbed et le RFID SM130

void flashingLED();
void sendFrame(unsigned char command, unsigned char lengthData, unsigned char *data);

int main() {
    unsigned char tabData[20];
    
    debugPC.baud(19200);
    debugPC.printf("\nHello World!\n");
    
    while(1) {
        sendFrame(0x80, 0x01, tabData);
        if(comRFID.readable() == 1){
            debugPC.printf("\nOK");
        }
        flashingLED();
    }
}

void sendFrame(unsigned char command, unsigned char lengthData, unsigned char *data){
    unsigned char csum = 0;
    
    lengthData += 1;    // +1 pour ajout taille commande
    
    comRFID.putc(0xFF);                                 //HEADER
    comRFID.putc(0x00);                                 //RESERVED
    comRFID.putc(lengthData );                          //LENGTH
    comRFID.putc(command);                              //COMMAND
    for(unsigned int cpt; cpt<lengthData; cpt++){       //DATA
        comRFID.putc(*(data+cpt));         
    }
    //Calcul du checksum
    csum += lengthData;
    csum += command;
    for(unsigned int cpt; cpt<lengthData-1; cpt++)
        csum += *(data + cpt);
        
    comRFID.putc(csum);     //CSUM
    
    //Affiche debug
    debugPC.printf("\nTX :\t0xFF 0x00");
    debugPC.putc(lengthData );                          
    debugPC.putc(command);   
    for(unsigned int cpt; cpt<lengthData; cpt++)
        debugPC.putc(*(data+cpt));  
    debugPC.putc(csum);    
}

void flashingLED() {
    myled = 1;
    wait(0.2);
    myled = 0;
    wait(0.2);
}