CAN Send Object Name function "fixed"

- Fixed search algorithm to return -1 if id was not found.
- Added destination id to return message as requested by ThingSet protocol

Function as such is not too useful (it returns only upto 4 characters), but shows that the basic receive/reply works
This commit is contained in:
Hogthrob
2018-10-06 19:17:30 +02:00
parent b4e74bbc89
commit d22227f86d
2 changed files with 8 additions and 6 deletions
+7 -5
View File
@@ -166,17 +166,18 @@ void can_list_object_ids(int category) {
}
void can_send_object_name(int data_obj_id) {
void can_send_object_name(int data_obj_id, uint8_t can_dest_id) {
uint8_t msg_priority = 7; // low priority service message
uint8_t function_id = 0x84;
CANMessage msg;
msg.format = CANExtended;
msg.type = CANData;
msg.id = msg_priority << 26 | function_id << 16 | can_node_id; // TODO: add destination node ID
msg.id = msg_priority << 26 | function_id << 16 |(can_dest_id << 8)| can_node_id; // TODO: add destination node ID
int arr_id = -1;
for (arr_id = 0; arr_id < sizeof(dataObjects)/sizeof(DataObject_t); arr_id++) {
if (dataObjects[arr_id].id == data_obj_id) {
for (int idx = 0; idx < sizeof(dataObjects)/sizeof(DataObject_t); idx++) {
if (dataObjects[idx].id == data_obj_id) {
arr_id = idx;
break; // correct array entry found
}
}
@@ -220,6 +221,7 @@ void can_process_inbox() {
serial.printf("Service frame\n");
// service frame
int function_id = (msg.id >> 16) & (int)0xFF;
uint8_t can_dest_id = msg.id & (int)0xFF;
int data_obj_id;
int value;
@@ -241,7 +243,7 @@ void can_process_inbox() {
break;
case TS_OBJ_NAME:
data_obj_id = msg.data[1] + (msg.data[2] << 8);
can_send_object_name(data_obj_id);
can_send_object_name(data_obj_id, can_dest_id);
serial.printf("Get Data Object Name: %d\n", data_obj_id);
break;
case TS_LIST:
+1 -1
View File
@@ -26,6 +26,6 @@ void can_receive();
void can_process_outbox();
void can_process_inbox();
void can_list_object_ids(int category = TS_C_ALL);
void can_send_object_name(int obj_id);
void can_send_object_name(int obj_id, uint8_t can_dest_id);
#endif