led example with 2 timers

Dependencies:   mbed mbed-rtos

Committer:
passelin
Date:
Tue Feb 11 20:38:43 2014 +0000
Revision:
4:af325c921e79
Parent:
3:204e23521e39
MAR 15:38

Who changed what in which revision?

UserRevisionLine numberNew contents of line
passelin 1:6e31c704f4d6 1 #include "main.h"
passelin 1:6e31c704f4d6 2
passelin 1:6e31c704f4d6 3 extern Serial pc;
passelin 3:204e23521e39 4 extern Queue<string, 16> WriterQueue;
passelin 2:124a066878cc 5 extern Mail<message_t, 16> mailBox;
passelin 3:204e23521e39 6 message_t gTrame;
passelin 3:204e23521e39 7 string dataTrame;
passelin 3:204e23521e39 8
passelin 1:6e31c704f4d6 9
passelin 3:204e23521e39 10 bool verifyCRC()
passelin 1:6e31c704f4d6 11 {
passelin 3:204e23521e39 12 bool result = false;
passelin 1:6e31c704f4d6 13
passelin 3:204e23521e39 14 dataTrame = "";
passelin 3:204e23521e39 15 string crcTrame = "";
passelin 3:204e23521e39 16 dataTrame = gTrame.trame.substr(32, gTrame.size);
passelin 3:204e23521e39 17 crcTrame = gTrame.trame.substr(32+gTrame.size, 16);
passelin 3:204e23521e39 18
passelin 3:204e23521e39 19 char *a = (char*)dataTrame.c_str();
passelin 3:204e23521e39 20 uint16_t crc = calculate_crc16(a, sizeof(a));
passelin 3:204e23521e39 21 string crc_s = bitset<16>(crc).to_string<char,string::traits_type,string::allocator_type>();
passelin 3:204e23521e39 22
passelin 3:204e23521e39 23 if(crc_s == crcTrame)
passelin 3:204e23521e39 24 {
passelin 3:204e23521e39 25 result = true;
passelin 3:204e23521e39 26 }
passelin 3:204e23521e39 27
passelin 3:204e23521e39 28 return result;
passelin 3:204e23521e39 29 //pc.printf("\n\r%s",dataTrame);
passelin 3:204e23521e39 30 //pc.printf("\n\r%s",crcTrame);
passelin 3:204e23521e39 31 }
passelin 3:204e23521e39 32
passelin 3:204e23521e39 33 string rebuildMessage()
passelin 3:204e23521e39 34 {
passelin 3:204e23521e39 35 string message;
passelin 3:204e23521e39 36 int tab[8] = {128, 64, 32, 16, 8, 4, 2, 1};
passelin 3:204e23521e39 37 int asciiValue = 0;
passelin 3:204e23521e39 38
passelin 3:204e23521e39 39 for(int i=0; i<gTrame.size; i+=OCTET)
passelin 3:204e23521e39 40 {
passelin 3:204e23521e39 41 for(int y=0; y<OCTET; y++)
passelin 3:204e23521e39 42 {
passelin 3:204e23521e39 43 asciiValue += (dataTrame.c_str()[i+y]-48)* tab[y];
passelin 3:204e23521e39 44 }
passelin 3:204e23521e39 45 message += asciiValue;
passelin 3:204e23521e39 46 asciiValue = 0;
passelin 3:204e23521e39 47 }
passelin 3:204e23521e39 48
passelin 3:204e23521e39 49 return message;
passelin 1:6e31c704f4d6 50 }
passelin 1:6e31c704f4d6 51
passelin 1:6e31c704f4d6 52 void Demodulator_thread(void const *args)
passelin 3:204e23521e39 53 {
passelin 1:6e31c704f4d6 54 while(1)
passelin 1:6e31c704f4d6 55 {
passelin 4:af325c921e79 56 /* osEvent evt = mailBox.get();
passelin 3:204e23521e39 57 if (evt.status == osEventMail)
passelin 3:204e23521e39 58 {
passelin 2:124a066878cc 59 message_t *mbTrame = (message_t*)evt.value.p;
passelin 3:204e23521e39 60 gTrame.trame = mbTrame->trame;
passelin 3:204e23521e39 61 gTrame.size = mbTrame->size;
passelin 3:204e23521e39 62 mailBox.free(mbTrame);
passelin 3:204e23521e39 63
passelin 4:af325c921e79 64 pc.printf("get in the mail \n\r", gTrame.trame.c_str());
passelin 3:204e23521e39 65
passelin 4:af325c921e79 66 pc.printf("\n\r%s", mbTrame->trame);
passelin 3:204e23521e39 67 if(verifyCRC())
passelin 3:204e23521e39 68 {
passelin 4:af325c921e79 69 pc.printf("\n\r crc ok");
passelin 4:af325c921e79 70 pc.printf("\n\r%s", rebuildMessage());
passelin 4:af325c921e79 71 //WriterQueue.put(new string(rebuildMessage()));
passelin 4:af325c921e79 72 //pc.printf("put in the queue %s \n\r", gTrame.trame.c_str());
passelin 3:204e23521e39 73 }
passelin 4:af325c921e79 74 }*/
passelin 1:6e31c704f4d6 75 }
passelin 1:6e31c704f4d6 76 }