Morse Encoder/Decoder Library. Transforms char array to binary array and vice-versa.
A Morse Encoding/Decoding Library \n Transforms char arrays into bool arrays and vice-versa
Morse code taken from http://en.wikipedia.org/wiki/Morse_code
Added some more characters :
- : DOT DOT DASH DASH
_ : DASH DASH DASH DOT
. : DASH DASH DASH DASH
/ : DOT DASH DOT DASH
@ : DOT DOT DOT DASH DOT
? : DOT DOT DASH DOT DOT
Here is an quick hello-world that show how to use this library
#include "mbed.h #include "Morse.h" Serial pc(USBTX, USBRX); int main() { int i; Morse_data* data; char message[] = "Hello World"; data = morse_create(morse_getBoolSize(message)); morse_encode(message, data); for (i=0; i<data->length; i++) pc.printf("%d", data->data[i]); morse_decode(data, message); pc.printf("\nMessage was : %s\n", message); while(1); }
MorseEncoder.h
- Committer:
- rominos2
- Date:
- 2014-09-16
- Revision:
- 0:4648894e0d80
File content as of revision 0:4648894e0d80:
#ifndef INCLUDE_MORSE_ENCODER_H #define INCLUDE_MORSE_ENCODER_H #include "Morse.h" #define MORSE_0 {DASH, DASH, DASH, DASH, DASH} #define MORSE_1 {DOT, DASH, DASH, DASH, DASH} #define MORSE_2 {DOT, DOT, DASH, DASH, DASH} #define MORSE_3 {DOT, DOT, DOT, DASH, DASH} #define MORSE_4 {DOT, DOT, DOT, DOT, DASH} #define MORSE_5 {DOT, DOT, DOT, DOT, DOT } #define MORSE_6 {DASH, DOT, DOT, DOT, DOT } #define MORSE_7 {DASH, DASH, DOT, DOT, DOT } #define MORSE_8 {DASH, DASH, DASH, DOT, DOT } #define MORSE_9 {DASH, DASH, DASH, DASH, DOT } #define MORSE_A {DOT, DASH, 0, 0, 0 } #define MORSE_B {DASH, DOT, DOT, DOT, 0 } #define MORSE_C {DASH, DOT, DASH, DOT, 0 } #define MORSE_D {DASH, DOT, DOT, 0, 0 } #define MORSE_E {DOT, 0, 0, 0, 0 } #define MORSE_F {DOT, DOT, DASH, DOT, 0 } #define MORSE_G {DASH, DASH, DOT, 0, 0 } #define MORSE_H {DOT, DOT, DOT, DOT, 0 } #define MORSE_I {DOT, DOT, 0, 0, 0 } #define MORSE_J {DOT, DASH, DASH, DASH, 0 } #define MORSE_K {DASH, DOT, DASH, 0, 0 } #define MORSE_L {DOT, DASH, DOT, DOT, 0 } #define MORSE_M {DASH, DASH, 0, 0, 0 } #define MORSE_N {DASH, DOT, 0, 0, 0 } #define MORSE_O {DASH, DASH, DASH, 0, 0 } #define MORSE_P {DOT, DASH, DASH, DOT, 0 } #define MORSE_Q {DASH, DASH, DOT, DASH, 0 } #define MORSE_R {DOT, DASH, DOT, 0, 0 } #define MORSE_S {DOT, DOT, DOT, 0, 0 } #define MORSE_T {DASH, 0, 0, 0, 0 } #define MORSE_U {DOT, DOT, DASH, 0, 0 } #define MORSE_V {DOT, DOT, DOT, DASH, 0 } #define MORSE_W {DOT, DASH, DASH, 0 , 0 } #define MORSE_X {DASH, DOT, DOT, DASH, 0 } #define MORSE_Y {DASH, DOT, DASH, DASH, 0 } #define MORSE_Z {DASH, DASH, DOT, DOT, 0 } #define MORSE_0_SIZE 19 #define MORSE_1_SIZE 17 #define MORSE_2_SIZE 15 #define MORSE_3_SIZE 13 #define MORSE_4_SIZE 11 #define MORSE_5_SIZE 9 #define MORSE_6_SIZE 11 #define MORSE_7_SIZE 13 #define MORSE_8_SIZE 15 #define MORSE_9_SIZE 17 #define MORSE_A_SIZE 5 #define MORSE_B_SIZE 9 #define MORSE_C_SIZE 11 #define MORSE_D_SIZE 7 #define MORSE_E_SIZE 1 #define MORSE_F_SIZE 9 #define MORSE_G_SIZE 9 #define MORSE_H_SIZE 7 #define MORSE_I_SIZE 3 #define MORSE_J_SIZE 13 #define MORSE_K_SIZE 9 #define MORSE_L_SIZE 9 #define MORSE_M_SIZE 7 #define MORSE_N_SIZE 5 #define MORSE_O_SIZE 11 #define MORSE_P_SIZE 8 #define MORSE_Q_SIZE 13 #define MORSE_R_SIZE 7 #define MORSE_S_SIZE 5 #define MORSE_T_SIZE 3 #define MORSE_U_SIZE 7 #define MORSE_V_SIZE 9 #define MORSE_W_SIZE 9 #define MORSE_X_SIZE 11 #define MORSE_Y_SIZE 13 #define MORSE_Z_SIZE 11 typedef struct { int length; bool* data; } MorseEncoder_data; class MorseEncoder { private: static const unsigned int _values_size[36]; static const bool _values[36][5]; unsigned int find(char c); unsigned int addChar(unsigned int index_value, bool* result, unsigned int place); public: MorseEncoder_data* encode(char* word); void destroy(MorseEncoder_data* data); }; #endif