Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreePilot PinDetect mbed-src
Fork of FreePilot_V2-2 by
base/atoh.h@35:f9caeb8ca31e, 2015-02-21 (annotated)
- Committer:
- maximbolduc
- Date:
- Sat Feb 21 13:47:37 2015 +0000
- Revision:
- 35:f9caeb8ca31e
- Child:
- 50:07dfcda65732
little basic autosteer routine
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maximbolduc | 35:f9caeb8ca31e | 1 | /** |
maximbolduc | 35:f9caeb8ca31e | 2 | * @file atoh.h |
maximbolduc | 35:f9caeb8ca31e | 3 | * @brief Convert a hex formatted ASCII hex string to hex. Seems like the |
maximbolduc | 35:f9caeb8ca31e | 4 | * std library should include this... maybe it does. Just couldn't find it |
maximbolduc | 35:f9caeb8ca31e | 5 | * @author sam grove |
maximbolduc | 35:f9caeb8ca31e | 6 | * @version 1.0 |
maximbolduc | 35:f9caeb8ca31e | 7 | * |
maximbolduc | 35:f9caeb8ca31e | 8 | * Copyright (c) 2013 |
maximbolduc | 35:f9caeb8ca31e | 9 | * |
maximbolduc | 35:f9caeb8ca31e | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
maximbolduc | 35:f9caeb8ca31e | 11 | * you may not use this file except in compliance with the License. |
maximbolduc | 35:f9caeb8ca31e | 12 | * You may obtain a copy of the License at |
maximbolduc | 35:f9caeb8ca31e | 13 | * |
maximbolduc | 35:f9caeb8ca31e | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
maximbolduc | 35:f9caeb8ca31e | 15 | * |
maximbolduc | 35:f9caeb8ca31e | 16 | * Unless required by applicable law or agreed to in writing, software |
maximbolduc | 35:f9caeb8ca31e | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
maximbolduc | 35:f9caeb8ca31e | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
maximbolduc | 35:f9caeb8ca31e | 19 | * See the License for the specific language governing permissions and |
maximbolduc | 35:f9caeb8ca31e | 20 | * limitations under the License. |
maximbolduc | 35:f9caeb8ca31e | 21 | */ |
maximbolduc | 35:f9caeb8ca31e | 22 | |
maximbolduc | 35:f9caeb8ca31e | 23 | #ifndef ATOH_H |
maximbolduc | 35:f9caeb8ca31e | 24 | #define ATOH_H |
maximbolduc | 35:f9caeb8ca31e | 25 | |
maximbolduc | 35:f9caeb8ca31e | 26 | #include <stdint.h> |
maximbolduc | 35:f9caeb8ca31e | 27 | |
maximbolduc | 35:f9caeb8ca31e | 28 | /** Convert a hex formatted ASCII string to it's binary equivenent |
maximbolduc | 35:f9caeb8ca31e | 29 | * |
maximbolduc | 35:f9caeb8ca31e | 30 | * Example: |
maximbolduc | 35:f9caeb8ca31e | 31 | * @code |
maximbolduc | 35:f9caeb8ca31e | 32 | * #include "mbed.h" |
maximbolduc | 35:f9caeb8ca31e | 33 | * #include "atoh.h" |
maximbolduc | 35:f9caeb8ca31e | 34 | * |
maximbolduc | 35:f9caeb8ca31e | 35 | * int main() |
maximbolduc | 35:f9caeb8ca31e | 36 | * { |
maximbolduc | 35:f9caeb8ca31e | 37 | * uint64_t result = atoh <uint64_t> ("0123456789abcdef" ); |
maximbolduc | 35:f9caeb8ca31e | 38 | * uint32_t lo = result & 0x00000000ffffffff; |
maximbolduc | 35:f9caeb8ca31e | 39 | * uint32_t hi = (result >> 32); |
maximbolduc | 35:f9caeb8ca31e | 40 | * printf( "0x%08X%08X\n", hi, lo ); |
maximbolduc | 35:f9caeb8ca31e | 41 | * printf( "0x%08X\n", atoh <uint32_t> ( "12345678" ) ); |
maximbolduc | 35:f9caeb8ca31e | 42 | * printf( "0x%04X\n", atoh <uint16_t> ( "1234" ) ); |
maximbolduc | 35:f9caeb8ca31e | 43 | * printf( "0x%02X\n", atoh <uint8_t> ( "12" ) ); |
maximbolduc | 35:f9caeb8ca31e | 44 | * } |
maximbolduc | 35:f9caeb8ca31e | 45 | * @endcode |
maximbolduc | 35:f9caeb8ca31e | 46 | */ |
maximbolduc | 35:f9caeb8ca31e | 47 | |
maximbolduc | 35:f9caeb8ca31e | 48 | /** A templated method for ascii to hex conversions. Supported types are: |
maximbolduc | 35:f9caeb8ca31e | 49 | * uint8_t, uint16_t, uint32_t and uint64_t |
maximbolduc | 35:f9caeb8ca31e | 50 | * @param string - An ascii string of hex digits |
maximbolduc | 35:f9caeb8ca31e | 51 | * @returns The binary equivelant of the string |
maximbolduc | 35:f9caeb8ca31e | 52 | */ |
maximbolduc | 35:f9caeb8ca31e | 53 | template<typename T> |
maximbolduc | 35:f9caeb8ca31e | 54 | T atoh( char const *string ); |
maximbolduc | 35:f9caeb8ca31e | 55 | |
maximbolduc | 35:f9caeb8ca31e | 56 | #endif |
maximbolduc | 35:f9caeb8ca31e | 57 |