@@ -101,44 +101,49 @@ void Bootloader_JsonToLuos(service_t *service, char *bin_data, json_t const *boo
101
101
// parse all relevant values in json object
102
102
uint16_t type = (uint16_t )json_getReal (json_getProperty (command_item , "type" ));
103
103
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
+
104
106
// create a message to send to nodes
105
107
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
+ }
109
121
110
122
uint32_t binary_size = 0 ;
111
123
json_t * item = NULL ;
112
124
switch (type )
113
125
{
114
126
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 ;
119
129
Luos_SendMsg (service , & boot_msg );
120
130
break ;
121
131
122
132
case BOOTLOADER_STOP :
123
133
// 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 ;
128
136
Luos_SendMsg (service , & boot_msg );
129
-
130
137
break ;
131
138
132
139
case BOOTLOADER_READY :
133
140
// find binary size in json header
134
141
binary_size = (uint32_t )json_getReal (json_getProperty (command_item , "size" ));
135
142
136
143
// 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 ;
142
147
memcpy (& (boot_msg .data [2 ]), & binary_size , sizeof (uint32_t ));
143
148
Luos_SendMsg (service , & boot_msg );
144
149
break ;
0 commit comments