Dummy program to demonstrate problems: working code

Dependencies:   SLCD mbed-rtos mbed

Fork of MNG_TC by Shreesha S

Structures.h

Committer:
shreeshas95
Date:
2015-07-18
Revision:
12:f41a11dc0119
Parent:
8:cb93c1d3209a

File content as of revision 12:f41a11dc0119:

// TELECOMMAND CLASS :

#define TC_SHORT_SIZE 11
#define TC_LONG_SIZE 135

//MASKS
#define SHORT_LONG_TC_MASK 0x4000
#define CRC_MASK 0x2000
#define ABORT_ON_NACK_MASK 0x1000
#define APID_MASK 0x0C00
#define EXEC_STATUS_MASK 0x0300
#define PACKET_SEQ_COUNT_MASK 0x00FF

//PARENT CLASS
class Base_tc {
protected:
    unsigned short int fields;
public:
    unsigned char *TC_string;
    Base_tc *next_node;
    
//    short = 0, long = 1
    bool inline GETshort_or_long(){
        return (fields & SHORT_LONG_TC_MASK);
    }
    void inline PUTshort_or_long(bool input){
        if(input){
            fields |= SHORT_LONG_TC_MASK;
        }
        else{
            fields &= ~(SHORT_LONG_TC_MASK);
        }
    }
    
    bool inline GETcrc_pass(){
        return (fields & CRC_MASK);
    }
    void inline PUTcrc_pass(bool input){
        if(input){
            fields |= CRC_MASK;
        }
        else{
            fields &= ~(CRC_MASK);
        }
    }
        
    bool inline GETabort_on_nack(){
        return (fields & ABORT_ON_NACK_MASK);
    }
    void inline PUTabort_on_nack(bool input){
        if(input){
            fields |= ABORT_ON_NACK_MASK;
        }
        else{
            fields &= ~(ABORT_ON_NACK_MASK);
        }
    }
    
    uint8_t inline GETapid(){
        uint16_t temp = fields & APID_MASK;
        temp = temp >> 10;
        return (temp & 0xFF);
    }
    void inline PUTapid(uint8_t input){
        uint16_t temp = input;
        temp = temp << 10;
        fields &= ~(APID_MASK);
        fields |= (temp & APID_MASK);
    }
    
    uint8_t inline GETexec_status(){
        uint16_t temp = fields & EXEC_STATUS_MASK;
        temp = temp >> 8;
        return (temp & 0xFF);
    }
    void inline PUTexec_status(uint8_t input){
        uint16_t temp = input;
        temp = temp << 8;
        fields &= ~(EXEC_STATUS_MASK);
        fields |= (temp & EXEC_STATUS_MASK);
    }
    
    uint8_t inline GETpacket_seq_count(){
        uint16_t temp = fields & PACKET_SEQ_COUNT_MASK;
        return (temp & 0xFF);
    }
    void inline PUTpacket_seq_count(uint8_t input){
        uint16_t temp = input;
        fields &= ~(PACKET_SEQ_COUNT_MASK);
        fields |= (temp & PACKET_SEQ_COUNT_MASK);
    }
    
//    update everything other than short_or_long, and crc_pass from TC_string
    void update_fields(){
//        abort on nack
        uint8_t temp = TC_string[1];
        uint16_t t16 = 0;
        if(temp & 0x10){
            fields |= ABORT_ON_NACK_MASK;
        }
        else{
            fields &= ~(ABORT_ON_NACK_MASK);
        }
        
        // apid
        t16 = temp;
        t16 = t16 << 4;
        fields &= ~(APID_MASK);
        fields |= (t16 & APID_MASK);
        
        // exec_status : default value of exec status
        fields &= ~(EXEC_STATUS_MASK);
        
        // packet seq count
        temp = TC_string[0];
        t16 = temp;
        fields &= ~(PACKET_SEQ_COUNT_MASK);
        fields |= (t16 & PACKET_SEQ_COUNT_MASK);
    }
    
    virtual ~Base_tc(){}
};

//DERIVED CLASS - SHORT TC
class Short_tc : public Base_tc{
private:
    unsigned char fix_str[TC_SHORT_SIZE];
public:
    Short_tc(){
        TC_string = fix_str;
        fields = 0;
    }
    
    ~Short_tc(){}
};

//DERIVED CLASS - LONG TC
class Long_tc : public Base_tc{
private:
    unsigned char fix_str[TC_LONG_SIZE];
public:
    Long_tc(){
        TC_string = fix_str;
        fields = 0;
    }
    
    ~Long_tc(){}
};










typedef struct TM_list{

    unsigned char *TM_string;
    // bool short_or_long; // true for short
    // pass while calling the function
    unsigned char tmid;

    struct TM_list *next_TM;
    
    ~TM_list(){}
}TM_List;