TELECOMMAND MANAGER V1

Dependencies:   mbed SLCD mbed-rtos

main.cpp

Committer:
shreeshas95
Date:
2015-06-06
Revision:
1:df31097c8442
Parent:
0:b5b370873460
Child:
2:994e741028c7

File content as of revision 1:df31097c8442:

#include "mbed.h"
#include "MNG_TC.h"
#include <bitset>
#include <iostream>
using namespace std;

DigitalOut led(LED_RED);
Serial PC(USBTX, USBRX);
DigitalOut led2(LED_GREEN);
//Serial UART_RX(PTE0, PTE1);

int main()
{
    UART_TX.baud(38400);
//    UART_RX.baud(1200);
    
    led = 1;
    led2 = 0;
    unsigned char str[13];
    for(int i = 0 ; i < 13 ; ++i){
        str[i] = PC.getc();
    }
    
//    UART_RX.baud(38400);
    
    TC_list *tc_node = new TC_list;
    tc_node->TC_string = &(str[1]);
    
//    CRC crc_class;
    uint16_t crc_check = CRC::crcGenerate(&(str[1]), 9);
    char c1 = (crc_check >> 8) & 0xffff;
    char c2 = (crc_check) & 0xffff;
    if(c1 == str[10] && c2 == str[11]){
        tc_node->crc_pass = true;
//        printf("received tc successfully crc pass\r\n");
    }
    else{
//        printf("crc fail\r\n");
    }
    
    tc_node->short_or_long = true;
    tc_node->next_TC = NULL;
    
    led = 0;
    led2 = 1;
    
    wait(10);
    
//    for(int i = 0 ; i < 13; ++i){
//        std::bitset<8> b = str[i];
//        cout << b << "\r" << endl;
//    }
    
    MNG_TC mng_tc(tc_node);
    mng_tc.TC_list_cleanup();
    
    led2 = 0;
    while (true) {
        led = !led; // toggle led
        wait(0.2f);
    }
}