Skip to content

Commit dad2ca6

Browse files
committed
[Gate] Transformation of messages mode node/topic depending on json
1 parent a439954 commit dad2ca6

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

tool_services/gate/TinyJSON/bootloader_ex.c

+22-17
Original file line numberDiff line numberDiff line change
@@ -101,44 +101,49 @@ void Bootloader_JsonToLuos(service_t *service, char *bin_data, json_t const *boo
101101
// parse all relevant values in json object
102102
uint16_t type = (uint16_t)json_getReal(json_getProperty(command_item, "type"));
103103
uint8_t topic_target = (uint8_t)json_getReal(json_getProperty(command_item, "topic"));
104+
uint16_t node_id = (uint16_t)json_getReal(json_getProperty(command_item, "node"));
105+
104106
// create a message to send to nodes
105107
msg_t boot_msg;
106-
boot_msg.header.target = (uint16_t)topic_target; // first node of the network
107-
boot_msg.header.cmd = BOOTLOADER_CMD; // bootloader cmd
108-
boot_msg.header.target_mode = TOPIC; // msg send to the node
108+
109+
if (node_id == 0)
110+
{
111+
boot_msg.header.target = (uint16_t)topic_target; // first node of the network
112+
boot_msg.header.cmd = BOOTLOADER_CMD; // bootloader cmd
113+
boot_msg.header.target_mode = TOPIC; // msg send to the node
114+
}
115+
else
116+
{
117+
boot_msg.header.target = node_id; // first node of the network
118+
boot_msg.header.cmd = BOOTLOADER_CMD; // bootloader cmd
119+
boot_msg.header.target_mode = NODEIDACK; // msg send to the node
120+
}
109121

110122
uint32_t binary_size = 0;
111123
json_t *item = NULL;
112124
switch (type)
113125
{
114126
case BOOTLOADER_START:
115-
boot_msg.header.target_mode = NODEIDACK;
116-
boot_msg.header.target = (uint16_t)json_getReal(json_getProperty(command_item, "node"));
117-
boot_msg.header.size = sizeof(char);
118-
boot_msg.data[0] = BOOTLOADER_START;
127+
boot_msg.header.size = sizeof(char);
128+
boot_msg.data[0] = BOOTLOADER_START;
119129
Luos_SendMsg(service, &boot_msg);
120130
break;
121131

122132
case BOOTLOADER_STOP:
123133
// send stop command to bootloader app
124-
boot_msg.header.target_mode = NODEIDACK;
125-
boot_msg.header.target = (uint16_t)json_getReal(json_getProperty(command_item, "node"));
126-
boot_msg.header.size = sizeof(char);
127-
boot_msg.data[0] = BOOTLOADER_STOP;
134+
boot_msg.header.size = sizeof(char);
135+
boot_msg.data[0] = BOOTLOADER_STOP;
128136
Luos_SendMsg(service, &boot_msg);
129-
130137
break;
131138

132139
case BOOTLOADER_READY:
133140
// find binary size in json header
134141
binary_size = (uint32_t)json_getReal(json_getProperty(command_item, "size"));
135142

136143
// send ready command to bootloader app
137-
boot_msg.header.target_mode = NODEIDACK;
138-
boot_msg.header.target = (uint16_t)json_getReal(json_getProperty(command_item, "node"));
139-
boot_msg.header.size = 2 * sizeof(char) + sizeof(uint32_t);
140-
boot_msg.data[0] = BOOTLOADER_READY;
141-
boot_msg.data[1] = topic_target;
144+
boot_msg.header.size = 2 * sizeof(char) + sizeof(uint32_t);
145+
boot_msg.data[0] = BOOTLOADER_READY;
146+
boot_msg.data[1] = topic_target;
142147
memcpy(&(boot_msg.data[2]), &binary_size, sizeof(uint32_t));
143148
Luos_SendMsg(service, &boot_msg);
144149
break;

0 commit comments

Comments
 (0)