Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ExampleCanProtocol.h
00001 #ifndef EXAMPLE_CAN_PROTOCOL_H 00002 #define EXAMPLE_CAN_PROTOCOL_H 00003 00004 #include "CanPipe.h" 00005 00006 /** example protocol class */ 00007 class ExampleCanProtocol { 00008 int adder_; 00009 CanPipe* p_can_pipe_; 00010 public: 00011 ExampleCanProtocol(): adder_(0) 00012 {} 00013 00014 int adder_cb(CANMessage &msg) { 00015 adder_ += msg.data[0]; 00016 printf(" ExampleCanProtocol::adder_cb - %d\r\n", adder_); 00017 return CanPipe::kOkay; 00018 } 00019 00020 int echo_cb(CANMessage &msg) { 00021 CANMessage response(msg.id + 0x100); 00022 response.len = msg.len; 00023 response.format = CANStandard; 00024 response.type = CANData; 00025 memcpy(response.data, msg.data, msg.len); 00026 p_can_pipe_->PostMessage(response); 00027 00028 printf(" ExampleCanProtocol::echo_cb \r\n"); 00029 for (int i = 0; i < msg.len; ++i) { 00030 printf(" %d - 0x%02X\r\n", i, msg.data[i]); 00031 } 00032 return CanPipe::kOkay; 00033 } 00034 00035 void RegisterProtocols(CanPipe &can_pipe) { 00036 p_can_pipe_ = &can_pipe; 00037 00038 int handle; 00039 00040 handle = p_can_pipe_->RegisterFilter(0x400, 0x7ff, CANAny, 3); 00041 p_can_pipe_->RegisterCallback<ExampleCanProtocol>(this, &ExampleCanProtocol::adder_cb, handle); 00042 00043 handle = p_can_pipe_->RegisterFilter(0x500, 0x700, CANAny, 2); 00044 p_can_pipe_->RegisterCallback<ExampleCanProtocol>(this, &ExampleCanProtocol::echo_cb, handle); 00045 } 00046 }; 00047 00048 #endif /* EXAMPLE_CAN_PROTOCOL_H */
Generated on Wed Jul 13 2022 08:16:52 by
