FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Codigo Morse en FWH ( SOLUCIONADO ) :)
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Codigo Morse en FWH ( SOLUCIONADO ) :)
Posted: Thu Dec 13, 2012 03:49 AM
Hola Equipo, alguien puede traducir
este codigo en FWH ?
algun guru ?

saludos.
Code (fw): Select all Collapse
/*
** Text to Morse Code Converter
**
** Copyright (C) 2005 Ram贸n E. Torres Salom贸n
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#ifdef _MSC_VER
#include <windows.h>
#else
#include <dos.h>
#endif

#define MORSE_BEEP_FREQ 聽 聽 聽 聽800 // 0.8KHz

// Timers
#define MORSE_DOT_TIME 聽 聽 聽 聽70
#define MORSE_DASH_TIME 聽 聽 聽 聽210
#define MORSE_CHARACTER_SEPARATION 聽MORSE_DOT_TIME*3
#define MORSE_WORD_SEPARATION 聽 聽MORSE_DOT_TIME*7

// Functions prototipes
void playsound(int note, int duration);
void morse(char c);

int main(void)
{
聽 char buffer[256];

聽 printf("Raymondjavaxx Text to Morse Code Converter\n");
聽 printf("------------------------------------------\n");
聽 printf("Type a text and press enter: ");
聽 gets(buffer);

聽 int x=0;
聽 while(buffer[x])
聽 {
聽 聽 if(buffer[x] == ' ')
聽 聽 {
聽 聽 聽 printf("\n");
聽 聽 聽 while(buffer[x] == ' ')
聽 聽 聽 聽 x++;

聽 聽 聽 if(buffer[x] == NULL)
聽 聽 聽 聽 break;

#ifdef _MSC_VER
聽 聽 聽 Sleep(MORSE_WORD_SEPARATION);
#else
聽 聽 聽 delay(MORSE_WORD_SEPARATION);
#endif
聽 聽 }
聽 聽 morse(buffer[x]);
聽 聽 x++;
聽 }

聽 system("PAUSE");
聽 return 0;
}

/*********
* func: morse
* desc: morse parsing function
********************************************/
void morse(char c)
{
聽 char code[8] = {0};

聽 switch(toupper(c))
聽 {
聽 // Letter Morse
聽 case 'A': strcpy(code, ".-"); 聽break;
聽 case 'B': strcpy(code, "-..."); break;
聽 case 'C': strcpy(code, "-.-."); break;
聽 case 'D': strcpy(code, "-.."); 聽break;
聽 case 'E': strcpy(code, "."); 聽break;
聽 case 'F': strcpy(code, "..-."); break;
聽 case 'G': strcpy(code, "--."); 聽break;
聽 case 'H': strcpy(code, "...."); break;
聽 case 'I': strcpy(code, ".."); 聽break;
聽 case 'J': strcpy(code, "-.-."); break;
聽 case 'K': strcpy(code, "-.-"); 聽break;
聽 case 'L': strcpy(code, ".-.."); break;
聽 case 'M': strcpy(code, "--"); 聽break;
聽 case 'N': strcpy(code, "-."); 聽break;
聽 case 'O': strcpy(code, "---"); 聽break;
聽 case 'P': strcpy(code, ".--."); break;
聽 case 'Q': strcpy(code, "--.-"); break;
聽 case 'R': strcpy(code, ".-."); 聽break;
聽 case 'S': strcpy(code, "..."); 聽break;
聽 case 'T': strcpy(code, "-"); 聽break;
聽 case 'U': strcpy(code, "..-"); 聽break;
聽 case 'V': strcpy(code, "...-"); break;
聽 case 'W': strcpy(code, ".--"); 聽break;
聽 case 'X': strcpy(code, "-..-"); break;
聽 case 'Y': strcpy(code, "-.--"); break;
聽 case 'Z': strcpy(code, "--.."); break;

聽 // Digit Morse 
聽 case '0': strcpy(code, "-----"); break;
聽 case '1': strcpy(code, ".----"); break;
聽 case '2': strcpy(code, "..---"); break;
聽 case '3': strcpy(code, "...--"); break;
聽 case '4': strcpy(code, "....-"); break;
聽 case '5': strcpy(code, "....."); break;
聽 case '6': strcpy(code, "-...."); break;
聽 case '7': strcpy(code, "--..."); break;
聽 case '8': strcpy(code, "---.."); break;
聽 case '9': strcpy(code, "----."); break;

聽 // Others
聽 case '.': strcpy(code, ".-.-.-"); break;
聽 case ',': strcpy(code, "--..--"); break;
聽 case '?': strcpy(code, "..--.."); break;

聽 default: printf("[invalid character '%c']\n", c); break;
聽 }

聽 for(int i=0; i<8; i++)
聽 {
聽 聽 if(code[i] == '-')
聽 聽 {
聽 聽 聽 printf("%c", code[i]);
聽 聽 聽 playsound(MORSE_BEEP_FREQ, MORSE_DASH_TIME);
聽 聽 }
聽 聽 else if(code[i] == '.')
聽 聽 {
聽 聽 聽 printf("%c", code[i]);
聽 聽 聽 playsound(MORSE_BEEP_FREQ, MORSE_DOT_TIME);
聽 聽 }
聽 }

聽 printf("\n");
}

/*********
* func: playsound
* desc: play a note with pc internal speaker
********************************************/
void playsound(int note, int duration)
{
#ifdef _MSC_VER
聽 Beep(note, duration);
聽 Sleep(MORSE_CHARACTER_SEPARATION);
#else
聽 sound(note);
聽 delay(duration);
聽 nosound();
聽 delay(MORSE_CHARACTER_SEPARATION);
#endif
}
Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM
Re: Codigo Morse en FWH
Posted: Fri Dec 14, 2012 12:35 PM
No es exactamente igual a la que cuelgas, pero hace lo mismo.
Str2Morse("Hola mundo")
Por curiosidad, donde vas a usar la funci贸n.
Code (fw): Select all Collapse
/*
BielSys 2012 EA6DD
*/
#include "FiveWin.ch"
#define MORSE_BEEP_FREQ 聽 聽 聽 聽800 // 0.8KHz
// Timers
#define WPM 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 20 聽//Palabras por minuto
#define MORSE_DOT_TIME 聽 聽 聽 聽 聽 聽 聽(1200 / WPM) 聽 聽 聽 聽//Tiempo en milisegundos
#define MORSE_DASH_TIME 聽 聽 聽 聽 聽 聽 MORSE_DOT_TIME * 3
#define MORSE_CHARACTER_SEPARATION 聽MORSE_DOT_TIME * 3
#define MORSE_WORD_SEPARATION 聽 聽 聽 MORSE_DOT_TIME * 7
//--------------------------------------------------------
FUNCTION Str2Morse(cStr)
聽 聽LOCAL cDig,cDashDot,hAlfa:=AlfabetoMorse()
聽 聽cStr:=AllTrim(cStr)
聽 聽hb_hCaseMatch( hAlfa, .F. )
聽 聽FOR EACH cDig IN cStr
聽 聽 聽 IF cDig!=Space(1)
聽 聽 聽 聽 聽IF hb_hHasKey(hAlfa,cDig)
聽 聽 聽 聽 聽 聽 FOR EACH cDashDot IN hAlfa[cDig]
聽 聽 聽 聽 聽 聽 聽 聽IF 聽cDashDot == "-"
聽 聽 聽 聽 聽 聽 聽 聽 聽 Beep(MORSE_BEEP_FREQ,MORSE_DASH_TIME )
聽 聽 聽 聽 聽 聽 聽 聽ELSE
聽 聽 聽 聽 聽 聽 聽 聽 聽 Beep(MORSE_BEEP_FREQ,MORSE_DOT_TIME)
聽 聽 聽 聽 聽 聽 聽 聽ENDIF
聽 聽 聽 聽 聽 聽 聽 聽Sleep(MORSE_DOT_TIME)
聽 聽 聽 聽 聽 聽 NEXT
聽 聽 聽 聽 聽 聽 Sleep(MORSE_CHARACTER_SEPARATION)
聽 聽 聽 聽 聽ENDIF
聽 聽 聽 ELSE
聽 聽 聽 聽 聽Sleep(MORSE_WORD_SEPARATION)
聽 聽 聽 ENDIF
聽 聽NEXT
RETURN NIL
//-------------------------------
STATIC FUNCTION AlfabetoMorse()
聽 聽LOCAL hAlfa:=hb_hash()
聽 聽hAlfa[' ']:= " "
聽 聽hAlfa['A']:= ".-"
聽 聽hAlfa['B']:= "-..."
聽 聽hAlfa['C']:= "-.-."
聽 聽hAlfa['D']:= "-.."
聽 聽hAlfa['E']:= "."
聽 聽hAlfa['F']:= "..-."
聽 聽hAlfa['G']:= "--."
聽 聽hAlfa['H']:= "...."
聽 聽hAlfa['I']:= ".."
聽 聽hAlfa['J']:= "-.-."
聽 聽hAlfa['K']:= "-.-"
聽 聽hAlfa['L']:= ".-.."
聽 聽hAlfa['M']:= "--"
聽 聽hAlfa['N']:= "-."
聽 聽hAlfa['O']:= "---"
聽 聽hAlfa['P']:= ".--."
聽 聽hAlfa['Q']:= "--.-"
聽 聽hAlfa['R']:= ".-."
聽 聽hAlfa['S']:= "..."
聽 聽hAlfa['T']:= "-"
聽 聽hAlfa['U']:= "..-"
聽 聽hAlfa['V']:= "...-"
聽 聽hAlfa['W']:= ".--"
聽 聽hAlfa['X']:= "-..-"
聽 聽hAlfa['Y']:= "-.--"
聽 聽hAlfa['Z']:= "--.."
聽 聽// Digit Morse
聽 聽hAlfa['0']:= "-----"
聽 聽hAlfa['1']:= ".----"
聽 聽hAlfa['2']:= "..---"
聽 聽hAlfa['3']:= "...--"
聽 聽hAlfa['4']:= "....-"
聽 聽hAlfa['5']:= "....."
聽 聽hAlfa['6']:= "-...."
聽 聽hAlfa['7']:= "--..."
聽 聽hAlfa['8']:= "---.."
聽 聽hAlfa['9']:= "----."
聽 聽// Others
聽 聽hAlfa['.']:= ".-.-.-"
聽 聽hAlfa[',']:= "--..--"
聽 聽hAlfa['?']:= "..--.."
RETURN hAlfa
#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( SLEEP )
{
聽 聽 Sleep( hb_parnl( 1 ) );
}
HB_FUNC( BEEP )
{
聽 聽Beep(hb_parnl( 1 ), hb_parnl(2) );
}
#pragma ENDDUMP
Saludos desde Mallorca
Biel Maim贸
http://bielsys.blogspot.com/
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Codigo Morse en FWH
Posted: Fri Dec 14, 2012 09:31 PM
Hola Gabriel, gracias por responder,

voy a probar,

Hay programas que traducen las letras a codigo morse pero ninguno traduce la letra

el codigo morse lo usan los militares, la verdad desconozco para que jeje.

saludos.
Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Codigo Morse en FWH
Posted: Fri Dec 14, 2012 09:35 PM

por cierto Biel,
la funcion Str2Morse("Hola mundo")
es para harbour ?
estoy compilando con xhb y no existe .

saludos.

gracias..

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Codigo Morse en FWH
Posted: Fri Dec 14, 2012 09:49 PM

Tambien al compilar la funcion con harbour,
no encuentra la funcion,
de seguro me falta alguna lib,

:shock:

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Codigo Morse en FWH
Posted: Sat Dec 15, 2012 02:29 PM

Cesar, me parece que la Funcion esta incluida en el codigo que coloca Biel en su mensaje ...

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM
Re: Codigo Morse en FWH
Posted: Sat Dec 15, 2012 04:23 PM

Como te comentan el c贸digo de la funci贸n es el que te incluyo en el mensaje. Esta probado con Harbour, puede que para compilar en xHarbour haya que hacer alg煤n cambio en las funciones relacionadas con el uso de hash.

Saludos desde Mallorca
Biel Maim贸
http://bielsys.blogspot.com/
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Codigo Morse en FWH
Posted: Sat Dec 15, 2012 06:27 PM

Gracias Biel, la funcion funciona de maravilla,
y efectivamente solo esta para harbour
pero mas que suficiente para lo que lo necesito
Saludos.

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: Codigo Morse en FWH
Posted: Sun Dec 16, 2012 08:06 PM

run ok on貌y with harbour ..how converte it for xharbour ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 195
Joined: Fri Jan 23, 2009 02:50 AM
Re: Codigo Morse en FWH
Posted: Mon Dec 17, 2012 02:23 AM
Biel buenas noches

Al compilar el c贸digo que cuelgas me da este error, por favor me ayudas? me interesa el ejemplo.
URL=http://imageshack.us/photo/my-images/41/morse.jpg/][/URL]

Uploaded with ImageShack.us

Muy agradecido

Jairo Barbosa

FWH 1204 Harbour xDevstudio, xmate
Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM
Re: Codigo Morse en FWH
Posted: Mon Dec 17, 2012 09:52 AM

Asumo que todos somos programaodores, luego pasar de harbour a xharbour en este caso no tiene mayor problema que buscar las funciones sinonimas para el uso de hash. (hb_hash => hash, etc), o si me apuras siguiendo la misma l贸gica usar alguna alternativa al uso de la tabla hash.

Error BASE/2022 -> Error description: Error BASE/2022 Argument error: ALLTRIM
Luego el error esta en el parametro que se le pasa a Alltrim, posiblemente una cadena vacia o NIL(revisa la llamada a la funci贸n).
La func铆贸n Str2Morse no incorpora control de paramentros, pero es sencillo a帽adirselo para evitar este error.

Saludos desde Mallorca
Biel Maim贸
http://bielsys.blogspot.com/
Posts: 195
Joined: Fri Jan 23, 2009 02:50 AM
Re: Codigo Morse en FWH
Posted: Mon Dec 17, 2012 02:22 PM

Biel Saludo Cordial

Muchas gracias por su respuesta.
Te pido respetuosamente que modifiques tu suposici贸n y reconsidere que en este foro tambi茅n nos encontramos personas en v铆as de aprendizaje "Novatos" y gracias a personas como usted, que con su gran sapiencia en el tema alimentan el deseo de conocimientos de este maravilloso trabajo FiveWin.

Un Fuerte abrazo y aprovecho la oportunidad para desearle una Feliz Navidad y un a帽o venidero lleno de 茅xitos, que cada paso que camines sean Bendecidos junto a los seres que tu mas amas

Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Codigo Morse en FWH
Posted: Mon Dec 17, 2012 07:26 PM
agregen al inicio

Code (fw): Select all Collapse
#include "hbcompat.ch"


para que sirva tanto para xharbour como para harbour.

salu2
carlos vargas
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Codigo Morse en FWH
Posted: Mon Dec 17, 2012 07:33 PM
como explicacion existen tanto en harbour como en xharbour funciones con tareas similares y nombres un poco diferentes
los hash, try..cacth, etc.
el hbcompat.ch existe en ambos compiladores y lo que hace es algo como:
Code (fw): Select all Collapse
#ifdef __XHARBOUR__
   ...
   /* Hash item functions */
   #xtranslate hb_Hash( [<x,...>] )            => Hash( <x> )
   #xtranslate hb_HHasKey( [<x,...>] )         => HHasKey( <x> )
   #xtranslate hb_HPos( [<x,...>] )            => HGetPos( <x> )
   #xtranslate hb_HGet( [<x,...>] )            => HGet( <x> )
   #xtranslate hb_HSet( [<x,...>] )            => HSet( <x> )
   #xtranslate hb_HDel( [<x,...>] )            => HDel( <x> )
   ...
#else
   ...
   /* Hash item functions */
   #xtranslate Hash( [<x,...>] )           => hb_Hash( <x> )
   #xtranslate HHasKey( [<x,...>] )        => hb_HHasKey( <x> )
   #xtranslate HGetPos( [<x,...>] )        => hb_HPos( <x> )
   #xtranslate HGet( [<x,...>] )           => hb_HGet( <x> )
   #xtranslate HSet( [<x,...>] )           => hb_HSet( <x> )
   #xtranslate HDel( [<x,...>] )           => hb_HDel( <x> )
   ...
#endif
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 195
Joined: Fri Jan 23, 2009 02:50 AM
Re: Codigo Morse en FWH
Posted: Tue Dec 18, 2012 12:53 AM
Carlos Muchas gracias.

Mira si se compila el siguiente c贸digo y lo ejecutas, escucharas en telegraf铆a el nombre contenido en cStr.le di mas tiempo al espacio para que se pueda entender mejor.
Disculpa que quiera compartir ese sencillo ejemplo contigo, pero en la nostalgia que abrigan los a帽os que tengo de ser radio aficionado me llenan de alegr铆a mas aun cuando se puede hacer un sof que pueda modular este viejo sistema de comunicaciones es sencillamente fascinante, ya no se usa, solo en las bandas de Radio aficionados y solo en concursos, mis indicativos de llamado son
HK3DQC

Code (fw): Select all Collapse
/*
BielSys 2012 EA6DD
*/
#include "FiveWin.ch"

#define MORSE_BEEP_FREQ        800               // 0.8KHz
// Timers
#define WPM                         20           //Palabras por minuto
#define MORSE_DOT_TIME              (1200 / WPM) //Tiempo en milisegundos
#define MORSE_DASH_TIME             MORSE_DOT_TIME * 3
#define MORSE_CHARACTER_SEPARATION  MORSE_DOT_TIME * 13
#define MORSE_WORD_SEPARATION       MORSE_DOT_TIME * 7
//--------------------------------------------------------
FUNCTION Str2Morse(cStr)
   LOCAL cDig,cDashDot,hAlfa:=AlfabetoMorse()
   cStr:=("F+I+V+E+W+I+N")
   hb_hCaseMatch( hAlfa, .F. )
   FOR EACH cDig IN cStr
      IF cDig!=Space(1)
         IF hb_hHasKey(hAlfa,cDig)
            FOR EACH cDashDot IN hAlfa[cDig]
               IF  cDashDot == "-"
                  Beep(MORSE_BEEP_FREQ,MORSE_DASH_TIME )
               ELSE
                  Beep(MORSE_BEEP_FREQ,MORSE_DOT_TIME)
               ENDIF
               Sleep(MORSE_DOT_TIME)
            NEXT
            Sleep(MORSE_CHARACTER_SEPARATION)
         ENDIF
      ELSE
         Sleep(MORSE_WORD_SEPARATION)
      ENDIF
   NEXT
RETURN NIL
//-------------------------------
STATIC FUNCTION AlfabetoMorse()
   LOCAL hAlfa:=hb_hash()
   hAlfa[' ']:= " "
   hAlfa['A']:= ".-"
   hAlfa['B']:= "-..."
   hAlfa['C']:= "-.-."
   hAlfa['D']:= "-.."
   hAlfa['E']:= "."
   hAlfa['F']:= "..-."
   hAlfa['G']:= "--."
   hAlfa['H']:= "...."
   hAlfa['I']:= ".."
   hAlfa['J']:= "-.-."
   hAlfa['K']:= "-.-"
   hAlfa['L']:= ".-.."
   hAlfa['M']:= "--"
   hAlfa['N']:= "-."
   hAlfa['O']:= "---"
   hAlfa['P']:= ".--."
   hAlfa['Q']:= "--.-"
   hAlfa['R']:= ".-."
   hAlfa['S']:= "..."
   hAlfa['T']:= "-"
   hAlfa['U']:= "..-"
   hAlfa['V']:= "...-"
   hAlfa['W']:= ".--"
   hAlfa['X']:= "-..-"
   hAlfa['Y']:= "-.--"
   hAlfa['Z']:= "--.."
   // Digit Morse
   hAlfa['0']:= "-----"
   hAlfa['1']:= ".----"
   hAlfa['2']:= "..---"
   hAlfa['3']:= "...--"
   hAlfa['4']:= "....-"
   hAlfa['5']:= "....."
   hAlfa['6']:= "-...."
   hAlfa['7']:= "--..."
   hAlfa['8']:= "---.."
   hAlfa['9']:= "----."
   // Others
   hAlfa['.']:= ".-.-.-"
   hAlfa[',']:= "--..--"
   hAlfa['?']:= "..--.."
RETURN hAlfa
#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( SLEEP )
{
    Sleep( hb_parnl( 1 ) );
}
HB_FUNC( BEEP )
{
   Beep(hb_parnl( 1 ), hb_parnl(2) );
}
#pragma ENDDUMP


Un abrazo Mis deseos que Dios este Bendiciendo tus pasos

Atentamente

Jairo Barbosa