• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /******************************************************************************
2   *
3   *  Copyright (C) 2018 ST Microelectronics S.A.
4   *
5   *  Licensed under the Apache License, Version 2.0 (the "License");
6   *  you may not use this file except in compliance with the License.
7   *  You may obtain a copy of the License at:
8   *
9   *  http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   *
17   *
18   ******************************************************************************/
19  #ifndef ATP_H_
20  #define ATP_H_
21  
22  //************************************ Includes ********************************
23  #include <stdint.h>
24  #include <string.h>
25  //************************************ Defines *********************************
26  
27  #define ATP_MAX_ALLOWED_LENGTH 39
28  
29  #define EXPECTED_ATP_LENGTH 37
30  
31  #define DEFAULT_PWT 50
32  
33  #define LEN_LENGTH_IN_ATP 1
34  #define LEN_OFFSET_IN_ATP 0
35  #define VENDOR_ID_OFFSET_IN_ATP 1
36  #define VENDOR_ID_LENGTH_IN_ATP 5
37  #define BWT_OFFSET_IN_ATP 6
38  #define BWT_LENGTH_IN_ATP 2
39  #define CWT_OFFSET_IN_ATP 8
40  #define PWT_OFFSET_IN_ATP 9
41  #define MSF_OFFSET_IN_ATP 10
42  #define MSF_LENGTH_IN_ATP 2
43  #define CHECKSUM_TYPE_OFFSET_IN_ATP 12
44  #define IFSC_OFFSET_IN_ATP 13
45  #define HISTORICAL_CHARACTER_OFFSET_IN_ATP 14
46  #define HISTORICAL_CHARACTER_LENGTH_IN_ATP 22
47  #define CHECKSUM_OFFSET_IN_ATP 36
48  #define CRC_LENGTH_IN_ATP 2
49  
50  //************************************ Structs *********************************
51  typedef enum { LRC, CRC } ChecksumType;
52  
53  typedef struct {
54    uint8_t len;
55    char vendorID[5];
56    uint16_t bwt;
57    uint8_t cwt;
58    uint8_t pwt;
59    uint16_t msf;
60    ChecksumType checksumType;
61    uint8_t ifsc;
62    char historicalCharacter[22];
63    uint16_t checksum;
64  } Atp;
65  
66  /**
67   * This is the extern field that the whole system will have access to.
68   */
69  extern Atp ATP;
70  
71  /**
72   * Gets the value of the checksum stored in the array.
73   *
74   * @param array The array that contains the checksum.
75   * @param checksumStartPosition The position where the checksum starts in array.
76   *
77   * @return The value of the checksum.
78   */
79  uint16_t Atp_getChecksumValue(uint8_t *array, int checksumStartPosition);
80  
81  /**
82   * Sets the ATP struct that will be available for the whole system.
83   *
84   * @param baAtp The ATP as a byte array.
85   *
86   * @return 0 If everything is Ok, -1 otherwise.
87   */
88  int Atp_setAtp(uint8_t *baAtp);
89  
90  /**
91   * Gets the ATP stored
92   *
93   *
94   * @return pointer to the ATP array.
95   */
96  uint8_t *Atp_getAtp();
97  
98  #endif /* ATP_H_ */
99