Subversion Repositories HomeAutomation

Rev

Rev 1452 | Rev 1454 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1452 Rev 1453
Line 53... Line 53...
53
 
53
 
54
}
54
}
55
 
55
 
56
void sns_Serial_Process(void)
56
void sns_Serial_Process(void)
57
{
57
{
58
    ///TODO: Stuff that needs doing is done here
58
    // prepare a new message, in case new data is available
59
    unsigned int data = uart_getc();
-
 
60
    unsigned char c = (unsigned char)(data & 0x00FF);
-
 
61
    unsigned char status = (unsigned char)((data & 0xFF00) >> 8);
-
 
62
   
-
 
63
    if (status == 0)
-
 
64
    {
-
 
65
        // data received from uart
-
 
66
        StdCan_Msg_t msg;
59
    StdCan_Msg_t msg;
67
        msg.Length = 1;
60
    msg.Length = 0; // no data so far
68
        msg.Data[0] = c;
-
 
69
        StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS);
61
    StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS);
70
        StdCan_Set_direction(msg.Header, DIRECTIONFLAG_TO_OWNER);
62
    StdCan_Set_direction(msg.Header, DIRECTIONFLAG_TO_OWNER);
71
        msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_SERIAL;
63
    msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_SERIAL;
72
        msg.Header.ModuleId = sns_Serial_ID;
64
    msg.Header.ModuleId = sns_Serial_ID;
73
        msg.Header.Command = CAN_MODULE_CMD_SERIAL_SERIALDATA;
65
    msg.Header.Command = CAN_MODULE_CMD_SERIAL_SERIALDATA;
-
 
66
   
-
 
67
    unsigned char status;
-
 
68
   
-
 
69
    do
-
 
70
    {
-
 
71
        // ask uart driver for more data
-
 
72
        unsigned int data = uart_getc();
-
 
73
        // character is contained in LSB
-
 
74
        unsigned char c = (unsigned char)(data & 0x00FF);
-
 
75
        // status is contained in MSB
-
 
76
        status = (unsigned char)((data & 0xFF00) >> 8);
-
 
77
       
-
 
78
        // status == 0 means we just received a new char
74
        // transmit
79
        if (status == 0)
-
 
80
        {
-
 
81
            // insert it into the message
-
 
82
            msg.Data[(uint8_t)msg.Length] = c;
-
 
83
            msg.Length++;
-
 
84
        }
-
 
85
    // keep going until max data length reached, or until uart RXBUF is empty
-
 
86
    } while (status == 0 && msg.Length < 8);
-
 
87
   
-
 
88
    // did we fill any data into the message?
-
 
89
    if (msg.Length > 0)
-
 
90
    {
-
 
91
        // transmit this chunk of data (max 8 chars)
75
        while(StdCan_Put(&msg) != StdCan_Ret_OK);
92
        while(StdCan_Put(&msg) != StdCan_Ret_OK);
76
    }
93
    }
77
}
94
}
78
 
95
 
79
void sns_Serial_HandleMessage(StdCan_Msg_t *rxMsg)
96
void sns_Serial_HandleMessage(StdCan_Msg_t *rxMsg)