Changeset - eaddb578c329
[Not reviewed]
default
0 2 0
matthewreed - 7 years ago 2017-05-23 21:58:52

Fixed bugs in protocol receive and changed can receive led
2 files changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/can.c
Show inline comments
 
@@ -80,59 +80,59 @@ bool can_send(uint32_t id, uint32_t ide,
 
 
        HAL_CAN_Transmit_IT(&can_handle);
 
    }
 
    else
 
    {
 
        result = false;
 
    }
 
 
    return result;
 
}
 
 
void can_set_receive_mask(uint32_t mask)
 
{
 
    can_filter.FilterMode = CAN_FILTERMODE_IDMASK;
 
    can_filter.FilterScale = CAN_FILTERSCALE_32BIT;
 
    can_filter.FilterMaskIdHigh = (mask >> 16) & 0xFFFF;
 
    can_filter.FilterMaskIdLow = mask & 0xFFFF;
 
    can_filter.FilterActivation = ENABLE;
 
 
    HAL_CAN_ConfigFilter(&can_handle, &can_filter);
 
}
 
 
void can_set_receive_id(uint32_t id)
 
{
 
    can_filter.FilterMode = CAN_FILTERMODE_IDMASK;
 
    can_filter.FilterScale = CAN_FILTERSCALE_32BIT;
 
    can_filter.FilterIdHigh = (id >> 16) & 0xFFFF;
 
    can_filter.FilterIdLow = id & 0xFFFF;
 
    can_filter.FilterActivation = ENABLE;
 
 
    HAL_CAN_ConfigFilter(&can_handle, &can_filter);
 
 
}
 
 
bool can_silence_bus(bool value)
 
{
 
    bool result = true;
 
 
    can_silenced = value;
 
 
    return result;
 
}
 
 
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan)
 
{
 
    if ((hcan->pRxMsg->StdId == can_rx_id) | (hcan->pRxMsg->StdId == can_broadcast_id))
 
    {
 
        protocol_receive_message(hcan->pRxMsg);
 
        led_start_time(LED_CAN, 500);
 
        HAL_CAN_Receive_IT(&can_handle, CAN_FIFO0);
 
    }
 
    led_start_time(LED_CAN, 500);
 
}
 
 
void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan) {}
 
 
void HAL_CAN_ErrorCallback(CAN_HandleTypeDef* hcan)
 
{
 
    led_set(LED_ERROR, 1);
 
}
src/protocol.c
Show inline comments
 
#include "protocol.h"
 
 
protocol_device_t protocol_device;
 
flash_settings_t protocol_settings;
 
 
void protocol_init(protocol_device_t device)
 
{
 
    protocol_device = device;
 
    flash_restore(&protocol_settings);
 
 
    can_init(protocol_settings.val.can_id, DEFAULT_BROADCAST_ID);
 
}
 
 
bool protocol_send_test()
 
{
 
    bool result = true;
 
    can_send_test(protocol_settings.val.can_id | 0x00000001);
 
    return result;
 
}
 
 
bool protocol_receive_message(CanRxMsgTypeDef* can_message)
 
{
 
    bool result = true;
 
    
 
    protocol_message_t message;
 
    message.command = can_message->Data[0] & 0x80;
 
    message.id = can_message->Data[0] & 0x7F;
 
    message.key = (can_message->Data[1] << 8) & can_message->Data[2];
 
    message.key = (can_message->Data[1] << 8) | can_message->Data[2];
 
    message.sensor = can_message->Data[3];
 
    message.data.byte_data[0] = can_message->Data[4];
 
    message.data.byte_data[1] = can_message->Data[5];
 
    message.data.byte_data[2] = can_message->Data[6];
 
    message.data.byte_data[3] = can_message->Data[7];
 
    
 
    protocol_process_message(&message);
 
    
 
    return result;
 
}
 
 
bool protocol_send_message(protocol_message_t* message)
 
{
 
    bool result = true;
 
    uint8_t data[8];
 
    
 
    data[0] = (message->command & 0x80) | (message->id & 0x7F);
 
    data[1] = (message->key >> 8) & 0xFF;
 
    data[2] = (message->key >> 0) & 0xFF;
 
    data[3] = message->sensor;
 
    data[4] = message->data.byte_data[0];
 
    data[5] = message->data.byte_data[1];
 
    data[6] = message->data.byte_data[2];
 
    data[7] = message->data.byte_data[3];
 
    
 
    can_send(protocol_settings.val.can_id | 0x00000001, CAN_ID_STD, 8, data);
 
    
 
    return result;
 
}
 
 
bool protocol_process_message(protocol_message_t* message)
 
{
 
    bool result = true;
 
    
 
    if (message->command)
 
    {
 
        switch(message->id)
 
        {
 
            case ESTOP:
 
                {
 
                    //call estop weak function
 
                    result = protocol_estop(message->data.float_data!=0.0f);
 
                }
 
                break;
 
            case SILENCE_BUS:
 
                {
 
                    //silence can bus
 
                    result = can_silence_bus(message->data.float_data!=0.0f);
0 comments (0 inline, 0 general)