MAX1473 RF Receiver Demo Code
Dependencies: max32630fthr USBDevice
ForwardErrCorr.h@11:72363a906638, 2020-09-04 (annotated)
- Committer:
- tlyp
- Date:
- Fri Sep 04 18:02:33 2020 +0000
- Revision:
- 11:72363a906638
- Parent:
- 10:aec2b8ba06a0
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tlyp | 11:72363a906638 | 1 | /******************************************************************************* |
tlyp | 11:72363a906638 | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. |
tlyp | 11:72363a906638 | 3 | * |
tlyp | 11:72363a906638 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
tlyp | 11:72363a906638 | 5 | * copy of this software and associated documentation files (the "Software"), |
tlyp | 11:72363a906638 | 6 | * to deal in the Software without restriction, including without limitation |
tlyp | 11:72363a906638 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
tlyp | 11:72363a906638 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
tlyp | 11:72363a906638 | 9 | * Software is furnished to do so, subject to the following conditions: |
tlyp | 11:72363a906638 | 10 | * |
tlyp | 11:72363a906638 | 11 | * The above copyright notice and this permission notice shall be included |
tlyp | 11:72363a906638 | 12 | * in all copies or substantial portions of the Software. |
tlyp | 11:72363a906638 | 13 | * |
tlyp | 11:72363a906638 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
tlyp | 11:72363a906638 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
tlyp | 11:72363a906638 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
tlyp | 11:72363a906638 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
tlyp | 11:72363a906638 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
tlyp | 11:72363a906638 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
tlyp | 11:72363a906638 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
tlyp | 11:72363a906638 | 21 | * |
tlyp | 11:72363a906638 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
tlyp | 11:72363a906638 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
tlyp | 11:72363a906638 | 24 | * Products, Inc. Branding Policy. |
tlyp | 11:72363a906638 | 25 | * |
tlyp | 11:72363a906638 | 26 | * The mere transfer of this software does not imply any licenses |
tlyp | 11:72363a906638 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
tlyp | 11:72363a906638 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
tlyp | 11:72363a906638 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
tlyp | 11:72363a906638 | 30 | * ownership rights. |
tlyp | 11:72363a906638 | 31 | ******************************************************************************* |
tlyp | 11:72363a906638 | 32 | */ |
tlyp | 10:aec2b8ba06a0 | 33 | |
tlyp | 11:72363a906638 | 34 | /** |
tlyp | 11:72363a906638 | 35 | * @brief Library for the MAX30208\n |
tlyp | 11:72363a906638 | 36 | * |
tlyp | 11:72363a906638 | 37 | * @code |
tlyp | 11:72363a906638 | 38 | * #include "mbed.h" |
tlyp | 11:72363a906638 | 39 | * #include "max32630fthr.h" |
tlyp | 11:72363a906638 | 40 | * #include "ForwardErrCorr.h" |
tlyp | 11:72363a906638 | 41 | * |
tlyp | 11:72363a906638 | 42 | * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
tlyp | 11:72363a906638 | 43 | * |
tlyp | 11:72363a906638 | 44 | * #define SymmetricKey "PaSsWoRd" |
tlyp | 11:72363a906638 | 45 | * char TransTable[] = {0x1F,0x18,0x06,0x01}; |
tlyp | 11:72363a906638 | 46 | * |
tlyp | 11:72363a906638 | 47 | * //Create translator instance |
tlyp | 11:72363a906638 | 48 | * Translator transTx(SymmetricKey, TransTable); //Constructor takes 7-bit slave adrs |
tlyp | 11:72363a906638 | 49 | * |
tlyp | 11:72363a906638 | 50 | * int main(void) |
tlyp | 11:72363a906638 | 51 | * { |
tlyp | 11:72363a906638 | 52 | * //use Encoder |
tlyp | 11:72363a906638 | 53 | * } |
tlyp | 11:72363a906638 | 54 | * @endcode |
tlyp | 11:72363a906638 | 55 | */ |
tlyp | 10:aec2b8ba06a0 | 56 | |
tlyp | 10:aec2b8ba06a0 | 57 | #ifndef __FORWARDERRCORR_H_ |
tlyp | 10:aec2b8ba06a0 | 58 | #define __FORWARDERRCORR_H_ |
tlyp | 10:aec2b8ba06a0 | 59 | |
tlyp | 10:aec2b8ba06a0 | 60 | #include "mbed.h" |
tlyp | 10:aec2b8ba06a0 | 61 | |
tlyp | 10:aec2b8ba06a0 | 62 | class Translator{ |
tlyp | 10:aec2b8ba06a0 | 63 | |
tlyp | 10:aec2b8ba06a0 | 64 | public: |
tlyp | 11:72363a906638 | 65 | |
tlyp | 11:72363a906638 | 66 | /** |
tlyp | 11:72363a906638 | 67 | * @brief Constructor using reference to Symmetric key for encryption and FEC translation table |
tlyp | 11:72363a906638 | 68 | * @param SymmetricKey - Symmetric Key used by tranmsitter and reciever to encrypt/decrypt transmitted messages |
tlyp | 11:72363a906638 | 69 | * @param TransTable - Translation table used for Forward Error Correction code |
tlyp | 11:72363a906638 | 70 | */ |
tlyp | 11:72363a906638 | 71 | Translator(char *SymmetricKey, char *TransTable); |
tlyp | 11:72363a906638 | 72 | |
tlyp | 11:72363a906638 | 73 | /** |
tlyp | 11:72363a906638 | 74 | * @brief De-constructor |
tlyp | 11:72363a906638 | 75 | */ |
tlyp | 10:aec2b8ba06a0 | 76 | ~Translator(void); |
tlyp | 11:72363a906638 | 77 | |
tlyp | 11:72363a906638 | 78 | /** |
tlyp | 11:72363a906638 | 79 | * @brief Takes 2 byte data packet, converts to FEC 8 byte packet, and encrypts each byte |
tlyp | 11:72363a906638 | 80 | * @param tempData[IN] - 2 byte data that needs to be prepared for transmission |
tlyp | 11:72363a906638 | 81 | * @param EncryptedData[OUT] - Pointer to array where encrypted data will be stored, ready to send |
tlyp | 11:72363a906638 | 82 | * @return 0 on success, 1 on failure |
tlyp | 11:72363a906638 | 83 | */ |
tlyp | 11:72363a906638 | 84 | uint32_t Encrypt(uint16_t tempData,char *EncryptedData); |
tlyp | 10:aec2b8ba06a0 | 85 | |
tlyp | 11:72363a906638 | 86 | /** |
tlyp | 11:72363a906638 | 87 | * @brief Takes 1 byte data packet, converts to FEC 8 byte packet, and encrypts each byte |
tlyp | 11:72363a906638 | 88 | * @param tempData[IN] - 2 byte data that needs to be prepared for transmission |
tlyp | 11:72363a906638 | 89 | * @param EncryptedData[OUT] - Pointer to array where encrypted data will be stroed, ready to send |
tlyp | 11:72363a906638 | 90 | * @return 0 on success, 1 on failure |
tlyp | 11:72363a906638 | 91 | */ |
tlyp | 11:72363a906638 | 92 | uint32_t Encrypt(char tempData, char*EncryptedData); |
tlyp | 10:aec2b8ba06a0 | 93 | |
tlyp | 11:72363a906638 | 94 | /** |
tlyp | 11:72363a906638 | 95 | * @brief Calculates the hamming disatnce between 2 bytes |
tlyp | 11:72363a906638 | 96 | * @param ChkVal[IN] - Byte to use in hamming distance check |
tlyp | 11:72363a906638 | 97 | * @param TableVal[IN] - Byte to use in hamming distance check |
tlyp | 11:72363a906638 | 98 | * @return Hamming distance between the two provided bytes (range of 0-8) |
tlyp | 11:72363a906638 | 99 | */ |
tlyp | 11:72363a906638 | 100 | int HamDist(char ChkVal, char TableVal); |
tlyp | 10:aec2b8ba06a0 | 101 | |
tlyp | 11:72363a906638 | 102 | /** |
tlyp | 11:72363a906638 | 103 | * @brief Converts 1 byte of FEC code back to original 2 bit data |
tlyp | 11:72363a906638 | 104 | * @param ChkVal - 1 byte of encoded data that needs to be decoded |
tlyp | 11:72363a906638 | 105 | * @return 0,1,2,3 to indicate correctly decoded table index, 4 on transmission error |
tlyp | 11:72363a906638 | 106 | */ |
tlyp | 11:72363a906638 | 107 | int ChkHam(char ChkVal); |
tlyp | 11:72363a906638 | 108 | |
tlyp | 11:72363a906638 | 109 | /** |
tlyp | 11:72363a906638 | 110 | * @brief Function that takes encrypted FEC data and converts it back to 2 byte data |
tlyp | 11:72363a906638 | 111 | * @param[IN] EncryptedData - Array of the encrypted data |
tlyp | 11:72363a906638 | 112 | * @param[OUT] Output - 16 bit data returned after decryption |
tlyp | 11:72363a906638 | 113 | * @return 0 on sucess, 1 on failure |
tlyp | 11:72363a906638 | 114 | */ |
tlyp | 11:72363a906638 | 115 | uint32_t Decrypt(char *EncryptedData, uint16_t *Output); |
tlyp | 10:aec2b8ba06a0 | 116 | |
tlyp | 10:aec2b8ba06a0 | 117 | private: |
tlyp | 10:aec2b8ba06a0 | 118 | |
tlyp | 11:72363a906638 | 119 | char *m_TransTable, *m_SymmetricKey; |
tlyp | 10:aec2b8ba06a0 | 120 | }; |
tlyp | 10:aec2b8ba06a0 | 121 | |
tlyp | 10:aec2b8ba06a0 | 122 | #endif /* __ForwardErrCorr_H_*/ |