Dummy program to demonstrate problems: working code
Dependencies: SLCD mbed-rtos mbed
Fork of MNG_TC by
main.cpp
- Committer:
- shreeshas95
- Date:
- 2015-06-11
- Revision:
- 2:994e741028c7
- Parent:
- 1:df31097c8442
- Child:
- 3:eec1097c0dd6
File content as of revision 2:994e741028c7:
//#define ENDL "\r" << endl #include <bitset> #include <iostream> using namespace std; #include "mbed.h" #include "MNG_TC.h" DigitalOut ledr(LED_RED); DigitalOut ledg(LED_GREEN); //Serial PC(USBTX, USBRX); //Serial UART_RX(PTE0, PTE1); namespace ISR{ /* STATE TABLE 1 = intrerrupt not received & MNG_TC not running 2 = interrupt received but MNG_TC not running 3 = interrupt has been handled(no pending interuupts) & MNG_TC running 4 = new interrupt arrived & MNG_TC running */ int state = 1; /* @brief: handle TC interrupts from the receiver @param: none @return: none */ void PC_isr(){ cout << "INSIDE PC_isr" << "\r" << endl; PC.attach(NULL); if(state == 1){ state = 2; } else if(state == 2){ state = 2; } else if(state == 3){ state = 4; // read and decode TC here PC.attach(&PC_isr); state = 3; } else if(state == 4){ state = 4; } } } /* @brief: manage TC */ void manage_TC(void){ unsigned char str[13]; /* Timer time; time.start(); float start_time = time.read();*/ for(int i = 0 ; i < 13 ; ++i){ str[i] = PC.getc(); PC.putc(str[i]); } cout << "Successfully read 13 chars\r" << "\r" << endl; PC.attach(&ISR::PC_isr); // UART_RX.baud(38400); TC_list *tc_node = new TC_list; // remove flag tc_node->TC_string = &(str[1]); uint16_t crc_check = CRC::crc16_gen(&(str[1]), 9); char c1 = (crc_check >> 8) & 0xffff; char c2 = (crc_check) & 0xffff; // str[12] is flag 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->crc_pass = false; } tc_node->short_or_long = true; tc_node->next_TC = NULL; ledr = 0; ledg = 1; // for(int i = 0 ; i < 13; ++i){ // std::bitset<8> b = str[i]; // cout << b << "\r" << ENDL; // } MNG_TC::init(tc_node); MNG_TC::start_with(); MNG_TC::decode_TC(); MNG_TC::check_for_missing_TC(); MNG_TC::execute_TC(); cout << "the received tc is\n" << "\r" << endl; for(int i = 0 ; i < 13 ; ++i){ cout << tc_node->TC_string[i]; } cout << "\n" << "\r" << endl; ISR::state = 1; ledg = 0; } int main(){ UART_TX.baud(38400); // UART_RX.baud(1200); PC.baud(9600); PC.attach(&ISR::PC_isr); while(true){ ledg = !ledg; if(ISR::state != 1){ cout << "Inside while Interrupt received" << "\r" << endl; manage_TC(); } wait(0.2f); } }