|
|
@ -1,4 +1,28 @@ |
|
|
|
#include "fn_mgr.hpp"
|
|
|
|
|
|
|
|
void fn_map_reg(uint16_t function_id, protocol_impl_func_t funtion) {} |
|
|
|
bool fn_map_process(uint16_t function_id, uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { return true; } |
|
|
|
typedef struct { |
|
|
|
uint16_t function_id; |
|
|
|
protocol_impl_func_t fn; |
|
|
|
} fn_map_t; |
|
|
|
|
|
|
|
fn_map_t fn_map[256]; |
|
|
|
int fn_map_size = 0; |
|
|
|
|
|
|
|
void fn_map_reg(uint16_t function_id, protocol_impl_func_t fn) { |
|
|
|
if (fn_map_size >= 256) { |
|
|
|
printf("fn_map is full\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
fn_map[fn_map_size].function_id = function_id; |
|
|
|
fn_map[fn_map_size].fn = fn; |
|
|
|
fn_map_size++; |
|
|
|
} |
|
|
|
bool fn_map_process(uint16_t function_id, uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
|
for (int i = 0; i < fn_map_size; i++) { |
|
|
|
if (fn_map[i].function_id == function_id) { |
|
|
|
fn_map[i].fn(from, to, (zcanbus_packet_t*)rawpacket, len); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |