C2A_Core
m_pdu.c
[詳解]
1 #pragma section REPRO
2 #include "m_pdu.h"
3 
4 #include "string.h" // for memcpy
5 
6 static void M_PDU_clear_spare_(M_PDU* m_pdu);
7 
8 void M_PDU_generate_byte_stream(const M_PDU* m_pdu,
9  uint8_t byte_stream[M_PDU_LEN])
10 {
11  memcpy(byte_stream, m_pdu->header, M_PDU_HEADER_SIZE);
12  byte_stream += M_PDU_HEADER_SIZE;
13 
14  memcpy(byte_stream, m_pdu->data, M_PDU_DATA_SIZE);
15 }
16 
18 {
19  static uint8_t temp_fill_vcdu_data[432] = {
20  0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
21  0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
22  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc,
24  0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00, 0xcc,
25  0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00,
26  0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0xcc,
27  0xcc, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0xcc,
28  0x00, 0xcc, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00,
29  0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00,
30  0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00,
31  0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00,
32  0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc,
33  0xcc, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00,
34  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00,
35  0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc,
37  0xcc, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc,
38  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00,
39  0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00,
40  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0xcc,
41  0xcc, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00,
42  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00,
43  0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc,
44  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0xcc,
45  0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
47 
48  M_PDU_clear_spare_(m_pdu);
50  memcpy(&m_pdu->data[0], &temp_fill_vcdu_data[0], 432);
51 }
52 
53 static void M_PDU_clear_spare_(M_PDU* m_pdu)
54 {
55  unsigned int pos = 0;
56  uint8_t mask = 0xf8; // 11111000b
57 
58  m_pdu->header[pos] &= (uint8_t)(~mask);
59 }
60 
61 uint16_t M_PDU_get_1st_hdr_ptr(const M_PDU* m_pdu)
62 {
63  unsigned int pos = 0;
64  uint8_t mask = 0x3f; // 00111111b
65 
66  uint16_t ptr = (uint8_t)(m_pdu->header[pos] & mask);
67  ptr <<= 8;
68  ptr += m_pdu->header[pos + 1];
69 
70  return ptr;
71 }
72 
74  uint16_t ptr)
75 {
76  unsigned int pos = 0;
77  uint8_t mask = 0x3f; // 00111111b
78 
79  m_pdu->header[pos] &= (uint8_t)(~mask);
80  m_pdu->header[pos] |= (uint8_t)((ptr >> 8) & mask);
81  m_pdu->header[pos + 1] = (uint8_t)(ptr & 0xff);
82 }
83 
84 void M_PDU_set_data(M_PDU* m_pdu,
85  const uint8_t* data,
86  size_t offset,
87  size_t len)
88 {
89  // 指定されたデータ長が上限値を超過する場合は上限値に制限
90  if (offset + len > M_PDU_DATA_SIZE)
91  {
92  len = M_PDU_DATA_SIZE - offset;
93  }
94 
95  // offset以降にデータを書き込む
96  memcpy(m_pdu->data + offset, data, len);
97 }
98 #pragma section
void M_PDU_set_1st_hdr_ptr(M_PDU *m_pdu, uint16_t ptr)
Definition: m_pdu.c:73
void M_PDU_set_data(M_PDU *m_pdu, const uint8_t *data, size_t offset, size_t len)
Definition: m_pdu.c:84
void M_PDU_setup_idle_m_pdu(M_PDU *m_pdu)
Definition: m_pdu.c:17
static void M_PDU_clear_spare_(M_PDU *m_pdu)
Definition: m_pdu.c:53
uint16_t M_PDU_get_1st_hdr_ptr(const M_PDU *m_pdu)
Definition: m_pdu.c:61
void M_PDU_generate_byte_stream(const M_PDU *m_pdu, uint8_t byte_stream[M_PDU_LEN])
Definition: m_pdu.c:8
#define M_PDU_DATA_SIZE
Definition: m_pdu.h:10
#define M_PDU_HEADER_SIZE
Definition: m_pdu.h:9
@ M_PDU_PTR_IDLE
Definition: m_pdu.h:22
#define M_PDU_LEN
Definition: m_pdu.h:11
Definition: m_pdu.h:14
uint8_t data[M_PDU_DATA_SIZE]
Definition: m_pdu.h:16
uint8_t header[M_PDU_HEADER_SIZE]
Definition: m_pdu.h:15