Commit ea30371e authored by Xavier de Blas's avatar Xavier de Blas

normal jumps and fall jumps now managed by new chronopic module (reactive jumps pending)

included chronopic.o chronopic.cs test-saltos.mono.cs temporarily
while we have not a good way of installing the two modules
parent fa652974
......@@ -15,11 +15,6 @@ CFLAGS = -Wall
MCS = mcs
#-------- Nombres y dependencias de los programas a construir
TEST1= test-platform
LIBSERIAL = libserial.so
LIBSERIAL_DEP = sg-serial.o
DLL_SERIAL = serial
CHRONOJUMP = chronojump
......@@ -34,38 +29,47 @@ CHRONOJUMP_DEP = src/chronojump.cs src/person.cs src/jump.cs src/jumpType.cs src
RESOURCES = -resource:glade/chronojump.glade,chronojump.glade
CHRONOJUMP_LIB = -pkg:gtk-sharp -pkg:gnome-sharp -pkg:glade-sharp -r System.Data -r Mono.Data.SqliteClient
all: $(CHRONOJUMP).exe $(TEST1).exe
#all: $(CHRONOJUMP).exe $(TEST1).exe
all: $(CHRONOJUMP).exe test-mono
LIBCHRONOPIC = libchronopic.so
LIBCHRONOPIC_DEP = chronopic.o
DLL_CHRONOPIC = chronopic
NAME5= test-saltos.mono
DEP5 = $(NAME5).cs $(DLL_CHRONOPIC).dll
#-- Construccion de los ejemplos de prueba en Mono
test-mono: $(NAME5).exe
#--------------------------
# Reglas
#--------------------------
# ---- Generacion de la libreria libserial
$(LIBSERIAL): $(LIBSERIAL_DEP)
$(CC) -shared -W1,-soname,libserial.so -o $(LIBSERIAL) $(LIBSERIAL_DEP)
# ---- Generacion de la libreria libchronopic
$(LIBCHRONOPIC): $(LIBCHRONOPIC_DEP)
$(CC) -shared -W1,-soname,$(LIBCHRONOPIC) -o $(LIBCHRONOPIC) \
$(LIBCHRONOPIC_DEP)
clean::
rm -f $(LIBSERIAL) $(LIBSERIAL_DEP)
rm -f $(LIBCHRONOPIC) $(LIBCHRONOPIC_DEP)
#----- Crear la libserial.dll
$(DLL_SERIAL).dll: $(LIBSERIAL) $(DLL_SERIAL).cs
$(MCS) -target:library $(DLL_SERIAL).cs -o $(DLL_SERIAL).dll
#----- Crear la DLL
$(DLL_CHRONOPIC).dll: $(LIBCHRONOPIC) $(DLL_CHRONOPIC).cs
$(MCS) -unsafe -target:library $(DLL_CHRONOPIC).cs \
-o $(DLL_CHRONOPIC).dll
clean::
rm -f $(DLL_SERIAL).dll
rm -f $(DLL_CHRONOPIC).dll
#----- Crear test plaform
$(TEST1).exe: $(TEST1).cs $(DLL_SERIAL).dll
$(MCS) $(TEST1).cs -unsafe -r $(DLL_SERIAL).dll -o $(TEST1).exe
clean::
rm -f $(TEST1).exe
#-------------------------------
# Regla para compilar CHRONOJUMP (C#)
#-------------------------------
$(CHRONOJUMP).exe: $(DLL_SERIAL).dll NPlot.dll NPlot.Gtk.dll $(CHRONOJUMP_DEP)
$(MCS) $(CHRONOJUMP_DEP) $(RESOURCES) -unsafe -r $(DLL_SERIAL).dll -r NPlot.dll -r NPlot.Gtk.dll -r System.Drawing $(CHRONOJUMP_LIB) -o $(CHRONOJUMP).exe
$(CHRONOJUMP).exe: $(DLL_CHRONOPIC).dll NPlot.dll NPlot.Gtk.dll $(CHRONOJUMP_DEP)
$(MCS) $(CHRONOJUMP_DEP) $(RESOURCES) -unsafe -r $(DLL_CHRONOPIC).dll -r NPlot.dll -r NPlot.Gtk.dll -r System.Drawing $(CHRONOJUMP_LIB) -o $(CHRONOJUMP).exe
clean::
rm -f $(CHRONOJUMP).exe
......@@ -75,6 +79,15 @@ clean::
#---------------------------------
sg-serial.o : sg-serial.h
#-------------------------------
# EJEMPLOS DE PRUEBA EN C#
#-------------------------------
$(NAME5).exe: $(DEP5)
$(MCS) $(NAME5).cs -unsafe -r $(DLL_CHRONOPIC).dll -o $(NAME5).exe
clean::
rm -f $(NAME5).exe
#--------------------------
# REGLAS GENERICAS
#--------------------------
......
CHANGELOG:
14 march 2005
normal jumps and fall jumps now managed by new chronopic module (reactive jumps pending)
included chronopic.o chronopic.cs test-saltos.mono.cs temporarily
while we have not a good way of installing the two modules
13 march 2005
treeviews
Treeview_jumps and treeview_jumps_rj displayed in a notebook (page
......
No preview for this file type
/**********************************************/
/* chronopic.cs Juan Gonzalez Gomez. */
/*--------------------------------------------*/
/* Licencia GPL */
/**********************************************/
/*------------------------------------------------------------------------
$Id$
$Revision$
$Source$
--------------------------------------------------------------------------*/
using System;
using System.Runtime.InteropServices;
public class Chronopic {
//-- Acceso a la libreria chronopic
const string library = "chronopic";
//****************************
// TIPOS
//****************************
//-- Respuestas en el acceso a Chronopic
public enum Respuesta : int
{
Ok = 1,
Error = -1,
Timeout = 0,
}
//-- Estado de la plataforma
public enum Plataforma : int
{
ON = 1,
OFF = 0,
UNKNOW = -1,
}
//******************************
// CONSTRUCTORES Y DESTRUCTORES
//******************************
//-- Constructor
public Chronopic(string disp)
{
this.serial_fd=this.Open(disp);
}
//-- Destructor
~Chronopic()
{
if (this.serial_fd!=-1)
this.Close();
}
//***************************************
// METODOS PUBLICOS
//***************************************
//----------------------------
//-- Cerrar el puerto serie
//----------------------------
public void Close()
{
Chronopic.close(this.serial_fd);
this.serial_fd=-1;
}
//----------------------------------
//-- Leer un evento en Chronopic
//----------------------------------
public Respuesta Read_event(out double timestamp,
out Plataforma plataforma)
{
double t;
int estado;
int error;
Respuesta resp;
//-- Leer trama
error=read(this.serial_fd,out t, out estado);
//-- Convertir el error al tipo Respuesta
switch(error) {
case 0:
resp = Respuesta.Timeout;
plataforma = Plataforma.UNKNOW;
timestamp = 0.0;
break;
case 1:
resp = Respuesta.Ok;
timestamp = t;
if (estado==0)
plataforma = Plataforma.OFF;
else
plataforma = Plataforma.ON;
break;
default:
resp = Respuesta.Error;
timestamp = 0.0;
plataforma = Plataforma.UNKNOW;
break;
}
return resp;
}
//----------------------------------------
//-- Obtener el estado de la plataforma
//----------------------------------------
public Respuesta Read_platform(out Plataforma plataforma)
{
int error;
int estado;
Respuesta resp;
//-- Enviar trama de estado
error=Chronopic.estado(this.serial_fd, out estado);
//-- Convertir el error al tipo Respueta
switch(error) {
case 0:
resp = Respuesta.Timeout;
plataforma = Plataforma.UNKNOW;
break;
case 1:
resp = Respuesta.Ok;
if (estado==0)
plataforma = Plataforma.OFF;
else
plataforma = Plataforma.ON;
break;
default:
resp = Respuesta.Error;
plataforma = Plataforma.UNKNOW;
break;
}
//-- Devolver Respuesta
return resp;
}
//-- Leer bytes
public unsafe int Read(byte[] buffer, int bytes, int timeout)
{
int error;
fixed(byte *bytepointer = buffer)
{
error=read(this.serial_fd,bytepointer,bytes,timeout);
}
return error;
}
public void Solicitar_estado()
{
solicitar_estado(this.serial_fd);
}
//***************************************
// METODOS PRIVADOS
//***************************************
//-- Apertura del puerto serie
private int Open(string disp)
{
return Chronopic.open(disp);
}
//-------------- Importado del modulo chronopic---------------------
[DllImport(library,EntryPoint="chronopic_open")]
extern static int open(string disp);
[DllImport(library,EntryPoint="chronopic_close")]
static extern int close(int fd);
[DllImport(library,EntryPoint="chronopic_get_trama_cambio")]
static extern int read(int serial_fd, out double t, out int estado);
[DllImport(library,EntryPoint="chronopic_flush")]
static extern int flush(int fd);
[DllImport(library,EntryPoint="chronopic_estado")]
static extern int estado(int fd, out int estado);
[DllImport(library,EntryPoint="chronopic_read")]
static extern unsafe int read(int serial_fd, byte *trama,
int bytes,int timeout);
[DllImport(library,EntryPoint="chronopic_solicitar_estado")]
static extern void solicitar_estado(int serial_fd);
//------------------------------
// Propiedades privadas
//------------------------------
int serial_fd;
}
File added
......@@ -6,6 +6,7 @@
<requires lib="bonobo"/>
<widget class="GnomeApp" id="app1">
<property name="width_request">640</property>
<property name="height_request">480</property>
<property name="visible">True</property>
<property name="title" translatable="yes">ChronoJump</property>
......
......@@ -188,10 +188,19 @@ public class ChronoJump {
//timers
private static System.Timers.Timer timerClockJump;
//platform state variables
private int serial_fd=0;
private bool platformState;
private int estadoInicial;
/*
* platform state variables
*/
enum States {
ON,
OFF
}
Chronopic.Plataforma platformState; //on (in platform), off (jumping), or unknow
Chronopic.Respuesta respuesta; //ok, error, or timeout in calling the platform
Chronopic cp;
States loggedState; //log of last state
//private int estadoInicial;
private double tcDjJump;
private bool firstRjValue;
private string rjTCString;
......@@ -210,7 +219,6 @@ public class ChronoJump {
public ChronoJump (string [] args)
{
Catalog.Init ("chronojump", "./locale");
......@@ -248,13 +256,37 @@ public class ChronoJump {
rand = new Random(40);
Console.WriteLine ( Catalog.GetString ("starting connection with serial port") );
Console.WriteLine ( Catalog.GetString ("if program crashes, disable next line, and work always in 'simulated' mode") );
serial_fd = Serial.Open("/dev/ttyS0");
//init connecting with chronopic
chronopicInit();
program.Run();
}
private void chronopicInit ()
{
Console.WriteLine ( Catalog.GetString ("starting connection with serial port") );
Console.WriteLine ( Catalog.GetString ("if program crashes, write to xavi@xdeblas.com") );
cp = new Chronopic("/dev/ttyS0");
//-- Obtener el estado inicial de la plataforma
respuesta=cp.Read_platform(out platformState);
switch(respuesta) {
case Chronopic.Respuesta.Error:
Console.WriteLine(Catalog.GetString("Error comunicating with Chronopic"));
break;
case Chronopic.Respuesta.Timeout:
Console.WriteLine(Catalog.GetString("Chronopic in not responding"));
break;
default:
Console.WriteLine(Catalog.GetString("Chronopic OK"));
break;
}
Console.Write(Catalog.GetString("Plataform state: "));
Console.WriteLine("{0}", platformState);
}
private void loadPreferences ()
{
Console.WriteLine ("Chronojump database version file: {0}",
......@@ -918,7 +950,7 @@ public class ChronoJump {
private void on_delete_event (object o, DeleteEventArgs args) {
Console.WriteLine("Chao!");
Serial.Close(serial_fd);
cp.Close();
Application.Quit();
}
......@@ -926,7 +958,7 @@ public class ChronoJump {
private void on_quit1_activate (object o, EventArgs args) {
Console.WriteLine("Chao!");
Serial.Close(serial_fd);
cp.Close();
Application.Quit();
}
......@@ -1279,23 +1311,15 @@ public class ChronoJump {
writeNormalJump (myTV);
}
else {
//initialize this ok, and delete buffer
int ok = 0;
do {
//FIXME: change the name of this method to english
ok = Serial.Estado(serial_fd, out estadoInicial);
Console.WriteLine("okey1: {0}" ,ok.ToString());
} while (ok != 1) ;
if (estadoInicial == 1) {
respuesta = cp.Read_platform(out platformState);
} while (respuesta!=Chronopic.Respuesta.Ok);
if (platformState==Chronopic.Plataforma.ON) {
Console.WriteLine( Catalog.GetString("You are IN, JUMP when prepared!!") );
//appbar2.Push( "Estas dentro, cuando quieras SALTA!!" );
platformState = true;
//delete serial buffer
Serial.Flush(serial_fd);
loggedState = States.ON;
timerClockJump = new System.Timers.Timer();
timerClockJump.Elapsed += new ElapsedEventHandler(OnTimerNormalJump);
timerClockJump.Interval = 100; //one decisecond
......@@ -1304,18 +1328,17 @@ public class ChronoJump {
else {
Console.WriteLine( Catalog.GetString("You are OUT, please come inside the platform") );
confirmWin = ConfirmWindow.Show(app1, Catalog.GetString("You are OUT, come inside and press button"), "");
confirmWin = ConfirmWindow.Show(app1,
Catalog.GetString("You are OUT, come inside and press button"), "");
//we call again this function
confirmWin.Button_accept.Clicked += new EventHandler(on_normal_jump_activate);
Console.WriteLine( Catalog.GetString("You are IN, JUMP when prepared!!") );
//appbar2.Push( "Estas dentro, cuando quieras SALTA!!" );
}
}
}
//writes the non-simulated normal jump (sj, sj+, cmj, abk) to the DB, and updates treeviews and stats
//writes the non-simulated normal jump (all non repetitve jumps without startIn (without fall))
//sj, sj+, cmj, cmj+, abk, abk+, ...
private void writeNormalJump (double myTV)
{
string myWeight = "";
......@@ -1352,35 +1375,30 @@ public class ChronoJump {
public void OnTimerNormalJump( System.Object source, ElapsedEventArgs e )
{
//t0 header of frame (always an ascii X): 88
//t1 state of platform (0 free (outside), 1 someone inside)
//t2, t3 time (more significative, and less significative)
//time = t2 * 256 + t3 (in decimals of milliseconds) 0.1 miliseconds
//
int t0,t1,t2,t3;
int ok = Serial.Read(serial_fd, out t0, out t1, out t2, out t3);
if (ok==1) {
Console.WriteLine("trama: {0} {1} {2}", t0, t1, realTime(t2, t3) );
//we were in and now regist out
if(platformState && t1 == 0) {
Console.WriteLine("Changed from {0}, to {1} (out)", platformState, t1);
platformState = false;
}
//we were out and now register in
else if(!platformState && t1 == 1) {
Console.WriteLine("Changed from {0}, to {1} (in) ", platformState, t1);
double timestamp;
respuesta = cp.Read_event(out timestamp, out platformState);
if (respuesta == Chronopic.Respuesta.Ok) {
if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) {
//it's inside, was out (= has landed)
//stop the timer event
timerClockJump.Elapsed -= new ElapsedEventHandler(OnTimerNormalJump);
timerClockJump.Enabled = false;
Console.WriteLine("------------Timer event should be killed----------");
//write the jump
writeNormalJump (timestamp);
//write the Jump
writeNormalJump (realTime(t2,t3));
}
else {
Console.WriteLine("NOT Changed {0} - {1}", platformState, t1);
//change the automata state (not needed in this jump)
loggedState = States.ON;
}
else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON) {
//it's out, was inside (= has jumped)
//don't write nothing here
//change the automata state
loggedState = States.OFF;
}
}
}
......@@ -1398,24 +1416,16 @@ public class ChronoJump {
writeJumpFall (myTC, myTV);
}
else {
//initialize this ok, and delete buffer
int ok = 0;
do {
//FIXME: change the name of this method to english
ok = Serial.Estado(serial_fd, out estadoInicial);
Console.WriteLine("okey1: {0}" ,ok.ToString());
} while (ok != 1) ;
if (estadoInicial == 0) {
respuesta = cp.Read_platform(out platformState);
} while (respuesta!=Chronopic.Respuesta.Ok);
if (platformState==Chronopic.Plataforma.OFF) {
Console.WriteLine( Catalog.GetString("You are OUT, JUMP when prepared!!") );
//appbar2.Push( "Estas fuera, cuando quieras SALTA!!" );
platformState = false;
tcDjJump = 0;
//delete serial buffer
Serial.Flush(serial_fd);
loggedState = States.OFF;
tcDjJump = 0; //useful for tracking the evolution of this jump
timerClockJump = new System.Timers.Timer();
timerClockJump.Elapsed += new ElapsedEventHandler(OnTimerDjJump);
timerClockJump.Interval = 100; //one decisecond
......@@ -1424,7 +1434,8 @@ public class ChronoJump {
else {
Console.WriteLine( Catalog.GetString("You are IN, please go out the platform") );
confirmWin = ConfirmWindow.Show(app1, Catalog.GetString("You are IN, please go out the platform, prepare for jump and press button"), "");
confirmWin = ConfirmWindow.Show(app1,
Catalog.GetString("You are IN, please go out and press button"), "");
//we call again this function
confirmWin.Button_accept.Clicked += new EventHandler(on_jump_fall_accepted);
......@@ -1434,44 +1445,40 @@ public class ChronoJump {
public void OnTimerDjJump( System.Object source, ElapsedEventArgs e )
{
//t0 header of frame (always an ascii X): 88
//t1 state of platform (0 free (outside), 1 someone inside)
//t2, t3 time (more significative, and less significative)
//time = t2 * 256 + t3 (in decimals of milliseconds) 0.1 miliseconds
//
int t0,t1,t2,t3;
int ok = Serial.Read(serial_fd, out t0, out t1, out t2, out t3);
if (ok==1) {
Console.WriteLine("trama: {0} {1} {2}", t0, t1, realTime(t2, t3) );
//we were out and now regist in
if(!platformState && t1 == 1 && tcDjJump == 0) {
Console.WriteLine("Changed from {0}, to {1} (in)", platformState, t1);
platformState = true;
double timestamp;
respuesta = cp.Read_event(out timestamp, out platformState);
if (respuesta == Chronopic.Respuesta.Ok) {
if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF
&& tcDjJump == 0) {
//it's inside, was out (= has landed), first time
loggedState = States.ON;
//dont' write nothing here
}
//we were in and now regist out
else if(platformState && t1 == 0) {
Console.WriteLine("Changed from {0}, to {1} (out)", platformState, t1);
platformState = false;
else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON) {
//it's out, was inside (= has jumped)
//record the TC
tcDjJump = timestamp;
//change the state
loggedState = States.OFF;
}
else if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF
&& tcDjJump != 0) {
//it's inside, was out (= has landed), second time
loggedState = States.ON;
//record the TC in a temp variable
tcDjJump = realTime(t2,t3);
}
//we were out and now register in
else if(!platformState && t1 == 1 && tcDjJump != 0) {
Console.WriteLine("Changed from {0}, to {1} (in) ", platformState, t1);
//stop the timer event
timerClockJump.Elapsed -= new ElapsedEventHandler(OnTimerDjJump);
timerClockJump.Enabled = false;
Console.WriteLine("------------Timer event should be killed----------");
//write the jump
writeJumpFall (tcDjJump, timestamp);
//write the Jump
writeJumpFall (tcDjJump, realTime(t2,t3));
//change the automata state (not needed in this jump)
loggedState = States.ON;
}
else {
Console.WriteLine("NOT Changed {0} - {1}", platformState, t1);
}
}
}
......@@ -1600,6 +1607,7 @@ public class ChronoJump {
else {
//initialize this ok, and delete buffer
int ok = 0;
/*
do {
//FIXME: change the name of this method to english
ok = Serial.Estado(serial_fd, out estadoInicial);
......@@ -1627,12 +1635,13 @@ public class ChronoJump {
firstRjValue = true;
//delete serial buffer
Serial.Flush(serial_fd);
//Serial.Flush(serial_fd);
timerClockJump = new System.Timers.Timer();
timerClockJump.Elapsed += new ElapsedEventHandler(OnTimerRjJump);
timerClockJump.Interval = 100; //one decisecond
timerClockJump.Enabled = true;
*/
}
}
......@@ -1678,6 +1687,7 @@ public class ChronoJump {
}
int t0,t1,t2,t3;
/*
int ok = Serial.Read(serial_fd, out t0, out t1, out t2, out t3);
if (ok==1) {
Console.WriteLine("trama: {0} {1} {2}", t0, t1, realTime(t2, t3) );
......@@ -1725,6 +1735,7 @@ public class ChronoJump {
}
}
*/
}
private void writeRjJump (string myTCString, string myTVString)
......@@ -2012,7 +2023,7 @@ public class ChronoJump {
new Gnome.About (
progname, progversion,
"(C) 2004 Xavier de Blas, Juan Gonzalez",
"Vertical jump analysis with contact plataform.",
"Vertical jump analysis with contact platform.",
authors, null, null, null).Run();
}
......
/***********************************************************/
/* test-saltos.mono Juan Gonzalez Gomez. Febrero 2005 */
/*---------------------------------------------------------*/
/* Medir el tiempo de vuelo de los saltos */
/* Licencia GPL */
/***********************************************************/
/*------------------------------------------------------------------------
$Id$
$Revision$
$Source$
--------------------------------------------------------------------------*/
using System;
class Test {
//-- Estado del automata
enum Automata {
ON,
OFF
}
/**********************/
/* PROGRAMA PRINCIPAL */
/**********************/
public static void Main()
{
Chronopic.Plataforma estado_plataforma;
Chronopic.Respuesta respuesta;
Automata estado_automata;
double timestamp;
double toff;
//-- Crear objeto chronopic, para acceder al chronopic
Chronopic cp = new Chronopic("/dev/ttyS0");
//-- Obtener el estado inicial de la plataforma
respuesta=cp.Read_platform(out estado_plataforma);
switch(respuesta) {
case Chronopic.Respuesta.Error:
Console.WriteLine("Error en comunicacion con Chronopic");
return;
case Chronopic.Respuesta.Timeout:
Console.WriteLine("Chronopic no responde");
return;
default:
break;
}
Console.WriteLine("Estado plataforma: {0}",estado_plataforma);
//-- Establecer el estado inicial del automata
if (estado_plataforma==Chronopic.Plataforma.ON)
estado_automata=Automata.ON;
else {
Console.WriteLine("Suba a la plataforma para realizar el salto");
//-- Esperar a que llegue una trama con el estado de la plataforma
//-- igual a ON. Esto indica que el usuario se ha subido
do {
respuesta = cp.Read_event(out timestamp, out estado_plataforma);
} while (respuesta!=Chronopic.Respuesta.Ok);
//-- Se han subido a la plataforma
estado_automata = Automata.ON;
}
Console.WriteLine("");
Console.WriteLine("Puede saltar cuando quiera");
Console.WriteLine("Pulse control-c para finalizar la sesion");
Console.WriteLine("-----------------------------------------");
while(true) {
//-- Esperar a que llegue una trama
do {
respuesta = cp.Read_event(out timestamp, out estado_plataforma);
} while (respuesta!=Chronopic.Respuesta.Ok);
//-- Segun el estado del automata
switch(estado_automata) {
case Automata.OFF: //-- Usuario estaba en el aire
//-- Si ha aterrizado
if (estado_plataforma==Chronopic.Plataforma.ON) {