STM32

F722ZE Parser Example2

programmer j 2021. 9. 12. 13:23

Binary프로토콜 파서 예제

- USART, USB CDC인터페이스와 연결

- 다른 바이너리 프로토콜을 만들 때 기본 템플릿으로 사용 예정

- 소스위치

https://github.com/heecheol-jung/F722ZE_Parser_Example.git

- Tools, 디렉터리 구조는 앞의 글 참고

https://blog.daum.net/go_ahead/20

 

1. 프로토콜 형식

그림1, 바이너리 프로토콜 형식

 

2. 구현된 명령

- Read hareware version
- Read firmware version
- Boot mode : 프로토콜에 응답하지만, Boot 모드 설정은 하지 않음
- Reset : 프로토콜에 응답하지만,  리셋은 하지 않음
- Read register : 프로토콜에 응답하지만, 레지스터 읽기는 하지 않음, 고정된 가짜 응답
- Write register : 프로토콜에 응답하지만, 레지스터 쓰기는 하지 않음

 

3. 바이너리 프로토콜 테스트 프로그램

- Visual Studio 2019 project : fl_console_app1

3.1. 호스트 시뮬레이터

그림2. host simulator 명령

3.2. COM 포트 선택(기본 : COM3)

그림3. COM포트 선택

3.3. COM포트 열기

- start명령 후 포트가 열렸는지 확인

그림4. COM포트 열기

3.4. 바이너리 프로토콜 테스트

그림5. 바이너리 프로토콜 테스트

3.5. 결과 확인

- 마지막 Write register명령은 FAIL확인을 위한 테스트(FAIL이 표시되면 정상)

그림6. 바이너리 프로토콜 테스트 결과

4. 파서 함수 사용 예제

4.1. 파싱 결과를 함수 인자로 받기

- Visual Studio 2019 : fl_unittest프로젝트의 fl_bin_message_parser_unit_test.cpp참고

fl_bin_msg_full_t         _parsed_msg;
                     :
for (_i = 0; _i < _len; _i++)
{
  _ret = fl_bin_msg_parser_parse(&_bin_parser, _packet_buf[_i], &_parsed_msg);
}                     
                     :

4.2. 파서의 자체 버퍼를 이용해 파싱 결과받기

- F722ZE_Parser_Poll : main.c의 message_processing, FL_MSG_ID_READ_REGISTER참고

if (g_app.proto_mgr.parser_handle.arg_count == 1)
{
  fl_read_reg_t* rreg = (fl_read_reg_t*)&(g_app.proto_mgr.parser_handle.payload);
  // TODO : Read a value from a register.
  g_app.proto_mgr.out_length = sprintf((char*)g_app.proto_mgr.out_buf, "%s %ld,%d,%ld,%d%c",
              fl_txt_msg_get_message_name(g_app.proto_mgr.parser_handle.msg_id),
              g_app.proto_mgr.parser_handle.device_id,
              FL_OK,
              rreg->address,
              10,
              FL_TXT_MSG_TAIL);
}

4.3. 콜백 함수 이용하기

- F722ZE_Parser_INT_RX : fw_app.c의 on_message_parsed 참고

 

'STM32' 카테고리의 다른 글

F722ZE Parser Example  (0) 2021.09.08
F722ZE USART Example  (0) 2021.08.29