|
16 | 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17 | 17 | ** See the License for the specific language governing permissions and
|
18 | 18 | ** limitations under the License.
|
19 |
| -** |
20 |
| -** lro_ts_crc |
21 |
| -** |
22 |
| -** This program calculates the CRC of a given file using the same |
23 |
| -** algorithm as the LRO spacecraft cFE Table Services flight software uses. |
24 |
| -** |
25 |
| -** Inputs: One string containing the filename of the file to CRC. |
26 |
| -** |
27 |
| -** |
28 |
| -** Outputs: Prints to the terminal the filename, size, and CRC. |
29 |
| -** Returns the CRC. |
30 |
| -** |
31 |
| -** Author: Mike Blau, GSFC Code 582 |
32 |
| -** |
33 |
| -** Date: 1/28/08 |
34 |
| -** |
35 |
| -** Modified 4/24/08 MDB Added option to skip a specified number of header bytes |
36 |
| -** Modified 2/04/09 BDT Modified to compute cFE table services CS |
37 |
| -** Modified 4/01/09 STS Modified to always skip header (116 bytes) |
38 |
| -** Modified 4/01/09 STS Removed option to skip a specified number of header bytes |
39 |
| -** Modified 6/15/12 WFM Replaced the CRC Table with the table used in |
40 |
| -** CFE_ES_CalculateCRC |
41 | 19 | */
|
| 20 | + |
| 21 | +/* |
| 22 | + * This program calculates the CRC-16/ARC of a given table file. |
| 23 | + * |
| 24 | + * Algorithm: |
| 25 | + * - Name: CRC-16/ARC |
| 26 | + * - Polynomial: 0x8005 |
| 27 | + * - Initialization: 0x0000 |
| 28 | + * - Reflect Input/Output: true |
| 29 | + * - XorOut: 0x0000 |
| 30 | + * |
| 31 | + * Inputs: One string containing the filename of the table file to CRC. |
| 32 | + * |
| 33 | + * Outputs: Prints to the terminal the filename, size, and CRC. |
| 34 | + * Returns the CRC. |
| 35 | + * |
| 36 | + * Author: Mike Blau, GSFC Code 582 |
| 37 | + */ |
42 | 38 | #include <stdio.h>
|
43 | 39 | #include <fcntl.h>
|
44 | 40 | #include <string.h>
|
|
49 | 45 |
|
50 | 46 | /* These headers are needed for CFE_FS_Header_t and CFE_TBL_File_Hdr_t, respectively.
|
51 | 47 | * This uses the OSAL definition of fixed-width types, even thought this tool
|
52 |
| - * is not using OSAL itself. */ |
| 48 | + * is not using OSAL itself. |
| 49 | + */ |
53 | 50 | #include "common_types.h"
|
54 | 51 | #include "cfe_fs_extern_typedefs.h"
|
55 | 52 | #include "cfe_tbl_extern_typedefs.h"
|
56 | 53 |
|
57 |
| -#define CFE_ES_CRC_8 1 /**< \brief CRC ( 8 bit additive - returns 32 bit total) (Currently not implemented) */ |
58 |
| -#define CFE_ES_CRC_16 2 /**< \brief CRC (16 bit additive - returns 32 bit total) */ |
59 |
| -#define CFE_ES_CRC_32 3 /**< \brief CRC (32 bit additive - returns 32 bit total) (Currently not implemented) */ |
60 |
| -#define CFE_ES_DEFAULT_CRC CFE_ES_CRC_16 /**< \brief mission specific CRC type */ |
61 |
| - |
62 | 54 | /*
|
63 | 55 | ** Function Prologue
|
64 | 56 | **
|
65 |
| -** Function: CFE_ES_CalculateCRC (taken directly from lro-cfe-4.2.1 delivery - 2/4/09) |
| 57 | +** Function: CalculateCRC (originated from lro-cfe-4.2.1 delivery - 2/4/09) |
66 | 58 | **
|
67 | 59 | ** Purpose: Perform a CRC calculation on a range of memory.
|
68 | 60 | **
|
69 | 61 | */
|
70 |
| -uint32 CFE_ES_CalculateCRC(void *DataPtr, uint32 DataLength, uint32 InputCRC, uint32 TypeCRC) |
| 62 | +uint32 CalculateCRC(void *DataPtr, uint32 DataLength, uint32 InputCRC) |
71 | 63 | {
|
72 | 64 | int32 i;
|
73 | 65 | int16 Index;
|
@@ -96,33 +88,18 @@ uint32 CFE_ES_CalculateCRC(void *DataPtr, uint32 DataLength, uint32 InputCRC, ui
|
96 | 88 | 0x4C80, 0x8C41, 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341,
|
97 | 89 | 0x4100, 0x81C1, 0x8081, 0x4040};
|
98 | 90 |
|
99 |
| - switch (TypeCRC) |
| 91 | + Crc = (int16)(0xFFFF & InputCRC); |
| 92 | + BufPtr = (uint8 *)DataPtr; |
| 93 | + |
| 94 | + for (i = 0; i < DataLength; i++, BufPtr++) |
100 | 95 | {
|
101 |
| - /* case CFE_ES_CRC_32: */ |
102 |
| - /* CFE_ES_WriteToSysLog("CFE ES Calculate CRC32 not Implemented\n"); */ |
103 |
| - /* break; */ |
104 |
| - |
105 |
| - case CFE_ES_CRC_16: |
106 |
| - Crc = (int16)(0xFFFF & InputCRC); |
107 |
| - BufPtr = (uint8 *)DataPtr; |
108 |
| - |
109 |
| - for (i = 0; i < DataLength; i++, BufPtr++) |
110 |
| - { |
111 |
| - Index = ((Crc ^ *BufPtr) & 0x00FF); |
112 |
| - Crc = ((Crc >> 8) & 0x00FF) ^ CrcTable[Index]; |
113 |
| - } |
114 |
| - break; |
115 |
| - |
116 |
| - /* case CFE_ES_CRC_8: */ |
117 |
| - /* CFE_ES_WriteToSysLog("CFE ES Calculate CRC8 not Implemented\n"); */ |
118 |
| - /* break; */ |
119 |
| - |
120 |
| - default: |
121 |
| - break; |
| 96 | + Index = ((Crc ^ *BufPtr) & 0x00FF); |
| 97 | + Crc = ((Crc >> 8) & 0x00FF) ^ CrcTable[Index]; |
122 | 98 | }
|
| 99 | + |
123 | 100 | return (Crc);
|
124 | 101 |
|
125 |
| -} /* End of CFE_ES_CalculateCRC() */ |
| 102 | +} |
126 | 103 |
|
127 | 104 | int main(int argc, char **argv)
|
128 | 105 | {
|
@@ -158,7 +135,7 @@ int main(int argc, char **argv)
|
158 | 135 | while (done == 0)
|
159 | 136 | {
|
160 | 137 | readSize = read(fd, buffer, 100);
|
161 |
| - fileCRC = CFE_ES_CalculateCRC(buffer, readSize, fileCRC, CFE_ES_CRC_16); |
| 138 | + fileCRC = CalculateCRC(buffer, readSize, fileCRC); |
162 | 139 | fileSize += readSize;
|
163 | 140 | if (readSize != 100)
|
164 | 141 | done = 1;
|
|
0 commit comments