Skip to content

Commit a5bd8fd

Browse files
authored
Merge pull request #16 from HarvestX/feat/update_api
add init_packet_<type>_pub
2 parents 6ec4b45 + 868048c commit a5bd8fd

File tree

12 files changed

+91
-51
lines changed

12 files changed

+91
-51
lines changed

.github/workflows/ci_humble.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ jobs:
3232
import-token: ${{ secrets.H6X_REPO_TOKEN }}
3333
vcs-repo-file-url: build_depends.repos
3434
package-name: |
35-
h6x_dynamic_packet_handler
35+
h6x_dynamic_packet_handler
36+
h6x_dynamic_packet_tools
37+
h6x_dynamic_serial_port_handler

example/m5core2/include/command_handler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,4 @@ void command_handler(const uint8_t & command, Packet & s_pkt)
250250

251251
}
252252

253-
#endif
253+
#endif

example/m5core2/include/serial_handler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool serial_read(Packet & pkt, const uint8_t mode, const uint8_t own_id)
6262

6363
if (read_data_len == data_len) {break;}
6464
}
65-
if(!packet_division(&pkt, data, read_data_len)){
65+
if (!packet_division(&pkt, data, read_data_len)) {
6666
M5.Lcd.setCursor(0, 100);
6767
M5.Lcd.printf("Packet division error\n");
6868
}
@@ -114,4 +114,4 @@ bool serial_write(Packet & pkt)
114114
M5.Lcd.println();
115115
}
116116

117-
#endif // SERIAL_HANDLER_HPP
117+
#endif // SERIAL_HANDLER_HPP

example/m5core2/primary/main.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ void drawMenu(int highlightIndex = -1)
5858

5959
void sendSelectedCommand()
6060
{
61-
pkt_send = init_packet();
62-
pkt_send.client_id = 0x01; // M5Core2 ID
63-
pkt_send.mode = SERIAL_MODE_HOST;
64-
pkt_send.command = return_values[selected_index];
61+
pkt_send = init_packet_server_pub(0x01, return_values[selected_index]);
6562
if (pkt_send.command == 0x03) {
6663
pkt_send.data[0] = (selected_index == 3) ? 0x05 : 0x01;
6764
pkt_send.data_len = 1;
@@ -128,4 +125,4 @@ void loop()
128125
}
129126

130127
delay(20);
131-
}
128+
}

example/m5core2/secondary/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ void loop()
3434
M5.Lcd.printf("Failed read\n");
3535
return;
3636
}
37-
pkt_send = init_packet();
38-
pkt_send.client_id = ONW_ID; // Set client_id here
39-
pkt_send.mode = SERIAL_MODE_CLIENT; // Set mode to CLIENT
37+
pkt_send = init_packet_client_pub(ONW_ID, ERR_SUCCESS);
4038
command_handler(pkt_recv.command, pkt_send);
4139
pkt_send.start_tick = pkt_recv.start_tick;
4240
pkt_send.elapsed_tick = millis() - pkt_recv.start_tick;
@@ -47,4 +45,4 @@ void loop()
4745
}
4846
}
4947
delay(10); // ~100Hz loop
50-
}
48+
}

h6x_dynamic_packet_handler/include/h6x_dynamic_packet_handler/h6x_dynamic_packet_big_endian.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Note: This header is kept for compatibility reasons.
16+
// Use `Ar-Ray-code/h6xserial_idl` instead.
17+
1518
#ifndef H6X_DYNAMIC_PACKET_HANDLER__H6X_DYNAMIC_PACKET_BIG_ENDIAN_HPP
1619
#define H6X_DYNAMIC_PACKET_HANDLER__H6X_DYNAMIC_PACKET_BIG_ENDIAN_HPP
1720

h6x_dynamic_packet_handler/include/h6x_dynamic_packet_handler/h6x_dynamic_packet_definitions_base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ typedef struct Packet
5555

5656
Packet init_packet();
5757

58+
Packet init_packet_server_pub(const uint8_t client_id, const uint8_t command);
59+
Packet init_packet_client_pub(const uint8_t own_id, const uint8_t status);
60+
61+
5862
// === COMMAND DEFINITIONS ===
5963
typedef enum
6064
{

h6x_dynamic_packet_handler/include/h6x_dynamic_packet_handler/h6x_dynamic_packet_handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ bool check_crc(const Packet * pkt);
4242

4343
bool create_packet(const Packet * pkt, char * send_packet);
4444

45-
Packet get_received_packet(const char * input, const int32_t input_len, const uint8_t client_id);
45+
uint16_t get_total_packet_length(const Packet * packet);
4646

47-
int32_t process_msg(const char * input, int32_t input_len, char * output, int32_t output_max_len);
47+
Packet get_received_packet(const char * input, const int32_t input_len, const uint8_t client_id);
4848

4949
#ifdef __cplusplus
5050
}

h6x_dynamic_packet_handler/src/h6x_dynamic_packet_definitions_base.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,21 @@ Packet init_packet()
2424
pkt.is_valid = true;
2525
return pkt;
2626
}
27+
28+
Packet init_packet_server_pub(const uint8_t client_id, const uint8_t command)
29+
{
30+
Packet pkt = init_packet();
31+
pkt.mode = SERIAL_MODE_HOST;
32+
pkt.client_id = client_id;
33+
pkt.command = command;
34+
return pkt;
35+
}
36+
37+
Packet init_packet_client_pub(const uint8_t own_id, const uint8_t status)
38+
{
39+
Packet pkt = init_packet();
40+
pkt.mode = SERIAL_MODE_CLIENT;
41+
pkt.client_id = own_id;
42+
pkt.status = status;
43+
return pkt;
44+
}

h6x_dynamic_packet_handler/src/h6x_dynamic_packet_handler.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ Packet get_received_packet(const char * input, const int32_t input_len, const ui
122122
return r_pkt;
123123
}
124124

125+
uint16_t get_total_packet_length(const Packet * packet)
126+
{
127+
return (uint16_t)(packet->data_len + ADDITIONAL_PACKET_LENGTH);
128+
}
125129

126130
uint8_t get_serial_data(char * input_buf, const int max_len, serial_getchar_fn_t getchar_fn)
127131
{

0 commit comments

Comments
 (0)