Server
 
로딩중...
검색중...
일치하는것 없음
send_time.cpp 파일 참조

여러 보드에 시간 동기화 프레임을 주기적으로 전송하는 예제 더 자세히 ...

#include <iostream>
#include <ctime>
#include <iomanip>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <vector>
#include <cstring>
send_time.cpp에 대한 include 의존 그래프

매크로

#define DLE   0x10
 Data Link Escape (프레임 구분용)
 
#define STX   0x02
 Start of Text (프레임 시작)
 
#define ETX   0x03
 End of Text (프레임 끝)
 
#define CMD_SYNC_TIME   0x03
 시간 동기화 명령 코드
 
#define NUM_BOARDS   4
 보드 개수
 

함수

uint8_t reverse (uint8_t val, int bits)
 8비트 값을 비트 단위로 반전합니다.
 
uint16_t reverse16 (uint16_t val, int bits)
 16비트 값을 비트 단위로 반전합니다.
 
uint16_t crc16 (const std::vector< uint8_t > &data)
 데이터 벡터에 대해 CRC16을 계산합니다.
 
int open_serial (const char *device)
 시리얼 포트를 엽니다.
 
std::vector< uint8_t > encode_frame (uint8_t cmd, int board_id, const std::vector< uint8_t > &extra_data)
 명령 및 추가 데이터를 DLE-STX/ETX 프레임으로 인코딩합니다.
 
int main ()
 프로그램 메인 함수. 모든 보드에 주기적으로 시간 동기화 프레임을 전송합니다.
 

변수

const char * SERIAL_PORTS [NUM_BOARDS]
 각 보드 ID에 대응하는 시리얼 포트 경로
 

상세한 설명

여러 보드에 시간 동기화 프레임을 주기적으로 전송하는 예제

함수 Documentation

◆ crc16()

uint16_t crc16 ( const std::vector< uint8_t > &  data)

데이터 벡터에 대해 CRC16을 계산합니다.

매개변수
dataCRC를 계산할 데이터 벡터
반환값
계산된 CRC16 값

◆ encode_frame()

std::vector< uint8_t > encode_frame ( uint8_t  cmd,
int  board_id,
const std::vector< uint8_t > &  extra_data 
)

명령 및 추가 데이터를 DLE-STX/ETX 프레임으로 인코딩합니다.

매개변수
cmd명령 코드
board_id대상 보드 ID (1부터 시작)
extra_data추가 데이터 벡터
반환값
인코딩된 프레임 벡터

◆ main()

int main ( )

프로그램 메인 함수. 모든 보드에 주기적으로 시간 동기화 프레임을 전송합니다.

반환값
실행 결과 코드

◆ open_serial()

int open_serial ( const char *  device)

시리얼 포트를 엽니다.

매개변수
device포트 디바이스 경로
반환값
파일 디스크립터

◆ reverse()

uint8_t reverse ( uint8_t  val,
int  bits 
)

8비트 값을 비트 단위로 반전합니다.

매개변수
val반전할 값
bits반전할 비트 수
반환값
반전된 값

◆ reverse16()

uint16_t reverse16 ( uint16_t  val,
int  bits 
)

16비트 값을 비트 단위로 반전합니다.

매개변수
val반전할 값
bits반전할 비트 수
반환값
반전된 값

변수 Documentation

◆ SERIAL_PORTS

const char* SERIAL_PORTS[NUM_BOARDS]
초기값:
= {
"/dev/ttyAMA0",
"/dev/ttyAMA2",
"/dev/ttyAMA1",
"/dev/ttyAMA3"
}

각 보드 ID에 대응하는 시리얼 포트 경로