Encoding messsages, continuously written on serial terminal, in Morse code. Resulting code is played by a buzzer. Please, use local echo on terminal for more impressive experience. To verify coded messages, there are some app for smartphone.

Dependencies:   FIFO

Fork of Morse by Romain Berrada

Committer:
rominos2
Date:
Thu Sep 18 17:26:24 2014 +0000
Revision:
1:84ef66bf435d
Parent:
0:4648894e0d80
Child:
2:39d67345f7b3
Morse Encoder/Decoder Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rominos2 1:84ef66bf435d 1 /*
rominos2 1:84ef66bf435d 2 Copyright (c) 2014 Romain Berrada
rominos2 1:84ef66bf435d 3
rominos2 1:84ef66bf435d 4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
rominos2 1:84ef66bf435d 5 and associated documentation files (the "Software"), to deal in the Software without restriction,
rominos2 1:84ef66bf435d 6 including without limitation the rights to use, copy, modify, merge, publish, distribute,
rominos2 1:84ef66bf435d 7 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
rominos2 1:84ef66bf435d 8 furnished to do so, subject to the following conditions:
rominos2 1:84ef66bf435d 9
rominos2 1:84ef66bf435d 10 The above copyright notice and this permission notice shall be included in all copies or
rominos2 1:84ef66bf435d 11 substantial portions of the Software.
rominos2 1:84ef66bf435d 12
rominos2 1:84ef66bf435d 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
rominos2 1:84ef66bf435d 14 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
rominos2 1:84ef66bf435d 15 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
rominos2 1:84ef66bf435d 16 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rominos2 1:84ef66bf435d 17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rominos2 1:84ef66bf435d 18 */
rominos2 1:84ef66bf435d 19
rominos2 0:4648894e0d80 20 #ifndef INCLUDE_MORSE_H
rominos2 0:4648894e0d80 21 #define INCLUDE_MORSE_H
rominos2 0:4648894e0d80 22
rominos2 1:84ef66bf435d 23 /** A Morse Encoding/Decoding Library \n
rominos2 1:84ef66bf435d 24 Transforms char arrays into bool arrays and vice-versa
rominos2 1:84ef66bf435d 25
rominos2 1:84ef66bf435d 26 Morse code taken from http://en.wikipedia.org/wiki/Morse_code \n
rominos2 1:84ef66bf435d 27 Added some more characters : \n
rominos2 1:84ef66bf435d 28 minus : DOT DOT DASH DASH \n
rominos2 1:84ef66bf435d 29 _ : DASH DASH DASH DOT \n
rominos2 1:84ef66bf435d 30 . : DASH DASH DASH DASH \n
rominos2 1:84ef66bf435d 31 / : DOT DASH DOT DASH \n
rominos2 1:84ef66bf435d 32 @ : DOT DOT DOT DASH DOT \n
rominos2 1:84ef66bf435d 33 ? : DOT DOT DASH DOT DOT \n
rominos2 1:84ef66bf435d 34
rominos2 1:84ef66bf435d 35 Here is an quick hello-world that show how to use this library \n
rominos2 1:84ef66bf435d 36 @code
rominos2 1:84ef66bf435d 37 #include "mbed.h
rominos2 1:84ef66bf435d 38 #include "Morse.h"
rominos2 1:84ef66bf435d 39
rominos2 1:84ef66bf435d 40 Serial pc(USBTX, USBRX);
rominos2 1:84ef66bf435d 41
rominos2 1:84ef66bf435d 42 int main() {
rominos2 1:84ef66bf435d 43 int i;
rominos2 1:84ef66bf435d 44 Morse_data* data;
rominos2 1:84ef66bf435d 45 char message[] = "Hello World";
rominos2 1:84ef66bf435d 46
rominos2 1:84ef66bf435d 47 data = morse_create(morse_getBoolSize(message));
rominos2 1:84ef66bf435d 48 morse_encode(message, data);
rominos2 1:84ef66bf435d 49 for (i=0; i<data->length; i++) pc.printf("%d", data->data[i]);
rominos2 1:84ef66bf435d 50
rominos2 1:84ef66bf435d 51 morse_decode(data, message);
rominos2 1:84ef66bf435d 52 pc.printf("\nMessage was : %s\n", message);
rominos2 1:84ef66bf435d 53
rominos2 1:84ef66bf435d 54 while(1);
rominos2 1:84ef66bf435d 55 }
rominos2 1:84ef66bf435d 56 @endcode
rominos2 1:84ef66bf435d 57 */
rominos2 0:4648894e0d80 58
rominos2 1:84ef66bf435d 59 /** Morse_data Structure
rominos2 1:84ef66bf435d 60 */
rominos2 1:84ef66bf435d 61 typedef struct {
rominos2 1:84ef66bf435d 62 int length; /**< Length of the data field */
rominos2 1:84ef66bf435d 63 bool* data; /**< data field containing 'length' booleans */
rominos2 1:84ef66bf435d 64 } Morse_data;
rominos2 1:84ef66bf435d 65
rominos2 1:84ef66bf435d 66 /** Give the size of the Morse_data that would be encoded from this word.
rominos2 1:84ef66bf435d 67 @param word the word.
rominos2 1:84ef66bf435d 68 @return the size of the encoded version of the word.
rominos2 1:84ef66bf435d 69 */
rominos2 1:84ef66bf435d 70 unsigned int morse_getBoolSize(char* word);
rominos2 1:84ef66bf435d 71 /** Give the size of the char array that would be decoded from this Morse_data.
rominos2 1:84ef66bf435d 72 @param data the data.
rominos2 1:84ef66bf435d 73 @return the size of the decoded version of the data.
rominos2 1:84ef66bf435d 74 */
rominos2 1:84ef66bf435d 75 unsigned int morse_getWordSize(Morse_data* data);
rominos2 1:84ef66bf435d 76
rominos2 1:84ef66bf435d 77 /** Encode the char array and put the result into the Morse_data structure.
rominos2 1:84ef66bf435d 78 @param word the word to encode.
rominos2 1:84ef66bf435d 79 @param data the Morse_data structure to store the result. This structure must have a sufficient size.
rominos2 1:84ef66bf435d 80 */
rominos2 1:84ef66bf435d 81 void morse_encode(char* word, Morse_data* data);
rominos2 1:84ef66bf435d 82 /** Decode the Morse_data structure and put the result into the char array.
rominos2 1:84ef66bf435d 83 @param data the data to decode.
rominos2 1:84ef66bf435d 84 @param word the char array to store the result. The array must have a sufficient size. (Also think of the '\0')
rominos2 1:84ef66bf435d 85 */
rominos2 1:84ef66bf435d 86 void morse_decode(Morse_data* data, char* word);
rominos2 1:84ef66bf435d 87
rominos2 1:84ef66bf435d 88 /** Allocate a Morse_data structure with the given size.
rominos2 1:84ef66bf435d 89 @param length the size of the structure to create.
rominos2 1:84ef66bf435d 90 @return the data pointer.
rominos2 1:84ef66bf435d 91 */
rominos2 1:84ef66bf435d 92 Morse_data* morse_create(unsigned int length);
rominos2 1:84ef66bf435d 93 /** Free a Morse_data structure.
rominos2 1:84ef66bf435d 94 @param data the data to free.
rominos2 1:84ef66bf435d 95 */
rominos2 1:84ef66bf435d 96 void morse_destroy(Morse_data* data);
rominos2 0:4648894e0d80 97
rominos2 0:4648894e0d80 98 #endif