/DUBwise/tags/v0.51/shared/src/DUBwiseDefinitions.java |
---|
0,0 → 1,52 |
package org.ligi.ufo; |
public interface DUBwiseDefinitions |
{ |
public final static byte USER_INTENT_NONE =0; |
public final static byte USER_INTENT_RAWDEBUG =1; |
public final static byte USER_INTENT_PARAMS =2; |
public final static byte USER_INTENT_GRAPH =3; |
public final static byte USER_INTENT_RCDATA =4; |
public final static byte USER_INTENT_LCD =5; |
public final static byte USER_INTENT_EXTERNAL_CONTROL =6; |
public final static byte GPS_FORMAT_DECIMAL =0; |
public final static byte GPS_FORMAT_MINSEC =1; |
public final static byte SPEED_FORMAT_KMH =0; // km/h |
public final static byte SPEED_FORMAT_MPH =1; // miles/h |
public final static byte SPEED_FORMAT_CMS =2; // cm/s |
/* from uart.h |
unsigned char Digital[2]; |
unsigned char RemoteTasten; |
signed char Nick; |
signed char Roll; |
signed char Gier; |
unsigned char Gas; |
signed char Hight; |
unsigned char free; |
unsigned char Frame; |
unsigned char Config; |
*/ |
public final static byte EXTERN_CONTROL_NICK =3; |
public final static byte EXTERN_CONTROL_ROLL =4; |
public final static byte EXTERN_CONTROL_GIER =5; |
public final static byte EXTERN_CONTROL_GAS =6; |
public final static byte EXTERN_CONTROL_HIGHT =7; |
public final static byte EXTERN_CONTROL_FRAME =9; |
public final static byte EXTERN_CONTROL_CONFIG =10; |
public final static byte EXTERN_CONTROL_LENGTH =11; |
public final static byte EXTERN_CONTROL_DEFAULT =42; |
public final static byte[] default_extern_keycontrol = { (byte)0, (byte)0, (byte)0, (byte)EXTERN_CONTROL_DEFAULT, (byte)EXTERN_CONTROL_DEFAULT, (byte)EXTERN_CONTROL_DEFAULT, (byte)255 , (byte)0, (byte)0, (byte)1, (byte)1 }; |
} |
/DUBwise/tags/v0.51/shared/src/MKCommunicator.java |
---|
0,0 → 1,1230 |
/******************************************************************************************************************************** |
* |
* Abstaction Layer to Communicate via J2ME and Bluetooth with the FlightCtrl of the MikroKopter Project (www.mikrokopter.de ) |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
* |
*******************************************************************************************************************************/ |
package org.ligi.ufo; |
//#ifdef j2me |
//# import javax.microedition.io.*; |
//#endif |
//#ifdef android |
import android.util.Log; |
//#endif |
import java.io.*; |
public class MKCommunicator |
implements Runnable,DUBwiseDefinitions |
{ |
public int angle_nick=-4242; |
public int angle_roll=-4242; |
public byte bl_retrys=0; |
public boolean init_bootloader=false; |
public byte lib_version_major=0; |
public byte lib_version_minor=4; |
public String lib_version_str() |
{ |
return "V"+lib_version_major+"."+lib_version_minor; |
} |
/***************** Section: public Attributes **********************************************/ |
public boolean connected=false; // flag for the connection state |
public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes |
public final static int DATA_BUFF_LEN = 20; // in lines |
public String[] data_buff; |
// boolean do_log=false; |
boolean do_log=true; |
int data_buff_pos=0; |
public byte user_intent=0; |
public final static int[] crc16_table = { |
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, |
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, |
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, |
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, |
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, |
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, |
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, |
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, |
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, |
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, |
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, |
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, |
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, |
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, |
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, |
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, |
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, |
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, |
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, |
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, |
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, |
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, |
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, |
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, |
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, |
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, |
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, |
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, |
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, |
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, |
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, |
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 |
}; |
public void log(String str) |
{ |
//#ifdef android |
if (do_log) Log.d("MK-Comm",str); |
//#endif |
System.out.println(str); |
} |
public int CRC16(int ch, int crc) |
{ |
return crc16_table[((crc >> 8) ^ (ch)) & 0xFF] ^ (crc << 8); |
} |
public int conn_time_in_s() |
{ |
if (connected) |
return (int)((System.currentTimeMillis()-connection_start_time)/1000); |
else |
return 0; |
} |
public final static byte BOOTLOADER_STAGE_NONE=0; |
public final static byte BOOTLOADER_STAGE_GOT_MKBL=1; |
byte bootloader_stage= BOOTLOADER_STAGE_NONE; |
public MKLCD LCD; |
public MKVersion version; |
public MKDebugData debug_data; |
public int[] extern_control; |
public MKGPSPosition gps_position; |
public MKStickData stick_data; |
public MKParamsParser params; |
public MKWatchDog watchdog; |
public MKProxy proxy=null; |
public MKStatistics stats ; |
// public DUBwiseDebug debug; |
public UFOProber ufo_prober; |
public long connection_start_time=-1; |
public String error_str = null; |
public final static int FC_SLAVE_ADDR = 'a'+1; |
public final static int NAVI_SLAVE_ADDR = 'a'+2; |
public final static int MK3MAG_SLAVE_ADDR = 'a'+3; |
/****************** Section: private Attributes **********************************************/ |
//#ifdef j2me |
//# private javax.microedition.io.StreamConnection connection; |
//#endif |
//#ifdef android |
// java.net.Socket connection; |
java.net.Socket connection; |
//#endif |
private java.io.InputStream reader; |
private java.io.OutputStream writer; |
public String name; |
// DUBwise root; |
private boolean sending=false; |
private boolean recieving=false; |
/****************** Section: public Methods ************************************************/ |
public MKCommunicator() |
{ |
data_buff=new String[DATA_BUFF_LEN]; |
for (int i=0;i<DATA_BUFF_LEN;i++) |
data_buff[i]=""; |
// debug=debug_; |
// root=root_; |
version=new MKVersion(); |
debug_data=new MKDebugData(); |
stick_data=new MKStickData(); |
params=new MKParamsParser(); |
extern_control=new int[EXTERN_CONTROL_LENGTH]; |
extern_control[EXTERN_CONTROL_CONFIG]=1; |
extern_control[EXTERN_CONTROL_FRAME]=1; |
LCD= new MKLCD(this); |
watchdog=new MKWatchDog(this); |
gps_position=new MKGPSPosition(); |
stats = new MKStatistics(); |
proxy =new MKProxy(this); |
ufo_prober=new UFOProber(); |
new Thread( this ).start(); // fire up main Thread |
} |
public void write_raw(byte[] _data) |
{ |
wait4send(); |
sending=true; |
try { |
writer.write(_data,0,_data.length); |
writer.flush(); |
stats.bytes_out+=_data.length; |
} |
catch ( Exception e){} |
sending=false; |
} |
public void do_proxy(String proxy_url) |
{ |
proxy.connect(proxy_url); |
} |
// int port; |
// URL string: "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control |
public void connect_to(String _url,String _name) |
{ |
// port=_port; |
mk_url=_url; // remember URL for connecting / reconnecting later |
name=_name; |
force_disconnect=false; |
connected=false; |
} |
public boolean ready() |
{ |
return (connected&&(version.major!=-1)); |
} |
public String get_buff(int age) |
{ |
age%=DATA_BUFF_LEN; |
if (age<=data_buff_pos) |
return ""+data_buff[data_buff_pos-age]; |
else |
return ""+data_buff[DATA_BUFF_LEN+data_buff_pos-age]; |
} |
/****************** Section: private Methods ************************************************/ |
private void connect() |
{ |
log("trying to connect to" + mk_url); |
try{ |
// old call |
// connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE); |
//#ifdef android |
connection = (new java.net.Socket(mk_url.split(":")[0],Integer.parseInt(mk_url.split(":")[1]))); |
//.Socket |
reader=connection.getInputStream(); |
writer=connection.getOutputStream(); |
String magic="conn:foo bar\r\n"; |
writer.write(magic.getBytes()); |
writer.flush(); |
//#else |
//# connection = (StreamConnection) Connector.open(mk_url); |
//# reader=connection.openInputStream(); |
//# writer=connection.openOutputStream(); |
//#endif |
connection_start_time=System.currentTimeMillis(); |
connected=true; // if we get here everything seems to be OK |
stats.reset(); |
log("connecting OK"); |
} |
catch (Exception ex) |
{ |
// TODO difference fatal errors from those which will lead to reconnection |
log("Problem connecting" + "\n" + ex); |
} |
} |
public int[] Decode64(byte[] in_arr, int offset,int len) |
{ |
int ptrIn=offset; |
int a,b,c,d,x,y,z; |
int ptr=0; |
int[] out_arr=new int[len]; |
while(len!=0) |
{ |
a=0; |
b=0; |
c=0; |
d=0; |
try { |
a = in_arr[ptrIn++] - '='; |
b = in_arr[ptrIn++] - '='; |
c = in_arr[ptrIn++] - '='; |
d = in_arr[ptrIn++] - '='; |
} |
catch (Exception e) {} |
//if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
x = (a << 2) | (b >> 4); |
y = ((b & 0x0f) << 4) | (c >> 2); |
z = ((c & 0x03) << 6) | d; |
if((len--)!=0) out_arr[ptr++] = x; else break; |
if((len--)!=0) out_arr[ptr++] = y; else break; |
if((len--)!=0) out_arr[ptr++] = z; else break; |
} |
return out_arr; |
} |
public void wait4send() |
{ |
while(sending) //||recieving) |
sleep(50); |
} |
public void sleep(int time) |
{ |
try { Thread.sleep(time); } |
catch (Exception e) { } |
} |
// FC - Function Mappers |
// send a version Request to the FC - the reply to this request will be processed in process_data when it arrives |
public void get_version() |
{ |
stats.version_data_request_count++; |
send_command(0,'v'); |
} |
public void set_gps_target(int longitude,int latitude) |
{ |
int[] target=new int[8]; |
target[0]= (0xFF)&(longitude<<24); |
target[1]= (0xFF)&(longitude<<16); |
target[2]= (0xFF)&(longitude<<8); |
target[3]= (0xFF)&(longitude); |
// send_command(0,'s',target); |
} |
// send a MotorTest request - params are the speed for each Motor |
public void motor_test(int[] params) |
{ |
stats.motortest_request_count++; |
send_command(FC_SLAVE_ADDR,'t',params); |
} |
public void send_extern_control() |
{ |
stats.external_control_request_count++; |
send_command(FC_SLAVE_ADDR,'b',extern_control); |
} |
/* public void send_keys(int[] params) |
{ |
send_command(FC_SLAVE_ADDR,'k',params); |
}*/ |
// get params |
public void get_params(int id) |
{ |
wait4send(); |
send_command(FC_SLAVE_ADDR,'q',id+1); |
stats.params_data_request_count++; |
} |
public void get_debug_name(int id) |
{ |
wait4send(); |
send_command(0,'a',id); |
} |
public void trigger_LCD_by_page(int page) |
{ |
wait4send(); |
send_command(0,'l',page); |
stats.lcd_data_request_count++; |
} |
public void trigger_debug() |
{ |
if (sending||recieving) return; // its not that important - can be dropped |
send_command(0,'c'); |
} |
public void switch_todo() |
{ |
sleep(50); |
version=new MKVersion(); |
LCD= new MKLCD(this); |
debug_data=new MKDebugData(); |
} |
public void switch_to_fc() |
{ |
wait4send(); |
send_command(NAVI_SLAVE_ADDR,'u',0); |
switch_todo(); |
} |
public void switch_to_mk3mag() |
{ |
wait4send(); |
send_command(NAVI_SLAVE_ADDR ,'u',1); |
switch_todo(); |
} |
public final static byte[] navi_switch_magic={27,27,0x55,(byte)0xAA,0,(byte)'\r'}; |
public void switch_to_navi() |
{ |
wait4send(); |
sending=true; |
try |
{ |
writer.write(navi_switch_magic); |
stats.bytes_out+=6; |
writer.flush(); |
} |
catch (Exception e) { } |
sending=false; |
switch_todo(); |
} |
public String[] flash_msgs; |
int msg_pos=0; |
public boolean bootloader_intension_flash=false; |
public boolean bootloader_finish_ok=false; |
public void jump_bootloader() |
{ |
bootloader_finish_ok=false; |
msg_pos=0; |
bootloader_stage= BOOTLOADER_STAGE_NONE; |
flash_msgs=new String[100]; |
flash_msgs[msg_pos++]="Initiializing Bootloader"; |
wait4send(); |
sending=true; |
try |
{ |
int attempt=0; |
while(bootloader_stage!= BOOTLOADER_STAGE_GOT_MKBL) |
{ |
flash_msgs[msg_pos]="attempt "+attempt; |
attempt++; |
send_command_nocheck((byte)FC_SLAVE_ADDR,'R',new int[0]); |
try{ |
writer.write( 27); |
writer.flush(); |
sleep(20); |
writer.write( 0xAA); |
writer.flush(); |
} |
catch (Exception e) { } |
sleep((attempt%2==0)?80:800); //800 |
} |
msg_pos++; |
} |
catch (Exception e) { |
flash_msgs[msg_pos++]="Exception:" +e.getMessage() ; |
flash_msgs[msg_pos++]=e.toString() ; |
} |
new Thread( this ).start(); // fire up main Thread |
} |
public void get_error_str() |
{ |
send_command(NAVI_SLAVE_ADDR,'e'); |
} |
public void trigger_rcdata() |
{ |
send_command(FC_SLAVE_ADDR,'p'); |
} |
public void write_params(int to) |
{ |
params.update_backup(to); |
wait4send(); |
params.active_paramset=to; |
send_command(FC_SLAVE_ADDR,'s',params.field_bak[to]); |
} |
public void send_command(int modul,char cmd) |
{ |
send_command(modul,cmd,new int[0]); |
} |
public void send_command(int modul,char cmd,int param) |
{ |
int[] params=new int[1]; |
params[0]=param; |
send_command(modul,cmd,params); |
} |
public void send_command_nocheck(byte modul,char cmd,int[] params) |
{ |
// char[] send_buff=new char[5 + (params.length/3 + (params.length%3==0?0:1) )*4]; // 5=1*start_char+1*addr+1*cmd+2*crc |
byte[] send_buff=new byte[3 + (params.length/3 + (params.length%3==0?0:1) )*4]; // 5=1*start_char+1*addr+1*cmd+2*crc |
send_buff[0]='#'; |
send_buff[1]=modul; |
send_buff[2]=(byte)cmd; |
for(int param_pos=0;param_pos<(params.length/3 + (params.length%3==0?0:1)) ;param_pos++) |
{ |
int a = (param_pos*3<params.length)?params[param_pos*3]:0; |
int b = ((param_pos*3+1)<params.length)?params[param_pos*3+1]:0; |
int c = ((param_pos*3+2)<params.length)?params[param_pos*3+2]:0; |
send_buff[3+param_pos*4] = (byte)((a >> 2)+'=' ); |
send_buff[3+param_pos*4+1] = (byte)('=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4))); |
send_buff[3+param_pos*4+2] = (byte)('=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6))); |
send_buff[3+param_pos*4+3] = (byte)('=' + ( c & 0x3f)); |
//send_buff[3+foo]='='; |
} |
/* for(int foo=0;foo<(params.length/3 + (params.length%3==0?0:1) )*4;foo++) |
{ |
int a = (foo<params.length) params[foo]; |
int a = params[foo]; |
//send_buff[3+foo]='='; |
} |
*/ |
try |
{ |
int tmp_crc=0; |
for ( int tmp_i=0; tmp_i<send_buff.length;tmp_i++) |
tmp_crc+=(int)send_buff[tmp_i]; |
writer.write(send_buff,0,send_buff.length); |
tmp_crc%=4096; |
writer.write( (char)(tmp_crc/64 + '=')); |
writer.write( (char)(tmp_crc%64 + '=')); |
writer.write('\r'); |
stats.bytes_out+=send_buff.length+3; |
writer.flush(); |
} |
catch (Exception e) |
{ // problem sending data to FC |
} |
} |
// send command to FC ( add crc and pack into pseudo Base64 |
public void send_command(int modul,char cmd,int[] params) |
{ |
// if (modul==0) return; |
sending=true; |
send_command_nocheck((byte)modul,cmd,params); |
sending=false; |
} |
public int slave_addr=-1; |
public int UBatt() |
{ |
if (ufo_prober.is_mk()) |
return debug_data.UBatt(); |
else if (ufo_prober.is_navi()) |
return gps_position.UBatt; |
return -1; |
} |
public int SenderOkay() |
{ |
if (ufo_prober.is_mk()) |
return debug_data.SenderOkay(); |
else if (ufo_prober.is_navi()) |
return gps_position.SenderOkay; |
return -1; |
} |
public void process_data(byte[] data,int len) |
{ |
log("command " +(char)data[2] ); |
switch((char)data[2]) |
{ |
case 'A': // debug Data Names |
stats.debug_names_count++; |
debug_data.set_names_by_mk_data(Decode64(data,3,len-3)); |
break; |
case 'B': // external_control confirm frames |
stats.external_control_confirm_frame_count++; |
break; |
case 'L': // LCD Data |
stats.lcd_data_count++; |
LCD.handle_lcd_data(Decode64(data,3,len-3)); |
break; |
case 'D': // debug Data |
log("got debug data"); |
stats.debug_data_count++; |
debug_data.set_by_mk_data(Decode64(data,3,len-3),version); |
log("processed debug data"); |
break; |
case 'V': // Version Info |
stats.version_data_count++; |
slave_addr=data[1]; |
switch(slave_addr) |
{ |
case FC_SLAVE_ADDR: |
ufo_prober.set_to_mk(); |
break; |
case NAVI_SLAVE_ADDR: |
ufo_prober.set_to_navi(); |
break; |
case MK3MAG_SLAVE_ADDR: |
// ufo_prober.set_to_mk(); |
ufo_prober.set_to_mk3mag(); |
break; |
default: |
ufo_prober.set_to_incompatible(); |
break; |
} |
version.set_by_mk_data(Decode64(data,3,len-3)); |
break; |
case 'w': |
int[] dec=Decode64(data,3,len-3); |
angle_nick=MKHelper.parse_signed_int_2(dec[0],dec[1]); |
angle_roll=MKHelper.parse_signed_int_2(dec[2],dec[3]); |
stats.angle_data_count++; |
break; |
case 'Q': |
if (ufo_prober.is_mk()) |
{ |
stats.params_data_count++; |
params.set_by_mk_data(Decode64(data,3,len-3)); |
} |
break; |
case 'P': |
stats.stick_data_count++; |
stick_data.set_by_mk_data(Decode64(data,3,20)); |
break; |
case 'E': |
int[] dec_data=Decode64(data,3,len-3); |
error_str=""; |
for(int foo=0;foo<20;foo++) |
if (dec_data[foo]!=0) |
error_str+=(char)dec_data[foo]; |
break; |
case 'O': |
stats.navi_data_count++; |
log("got navi data(" + len +"):"); |
gps_position.set_by_mk_data(Decode64(data,3,len-3),version); |
log("long:" + gps_position.Longitude); |
log("lat:" + gps_position.Latitude); |
break; |
// Error from Navi |
default: |
stats.other_data_count++; |
break; |
} |
} |
public boolean force_disconnect=true; |
public void close_connections(boolean force) |
{ |
// if ((!force)&&root.canvas.do_vibra) root.vibrate(500); |
force_disconnect=force; |
try{ reader.close(); } |
catch (Exception inner_ex) { } |
try{ writer.close(); } |
catch (Exception inner_ex) { } |
//#ifdef j2me |
//# try{ connection.close(); } |
//# catch (Exception inner_ex) { } |
//#endif |
ufo_prober.set_to_none(); |
stats.reset(); |
connected=false; |
version=new MKVersion(); |
} |
// Thread to recieve data from Connection |
public void run() |
{ |
boolean sigfail=false; |
if (bootloader_stage==BOOTLOADER_STAGE_GOT_MKBL) |
{ |
try { |
flash_msgs[msg_pos++]="reading avr_sig"; |
writer.write( 't'); |
writer.flush(); |
int avr_sig=reader.read(); |
//while (avr_sig==63) |
// avr_sig=reader.read(); |
flash_msgs[msg_pos++]="got avr sig " + avr_sig; |
int avrsig_suff=reader.read(); |
if (avrsig_suff!=0) |
throw new Exception("val after avrsig is" +avrsig_suff +"should b 0"); |
if ((avr_sig!=0x74)&&(avr_sig!=224)&&(avr_sig!=120)) |
{ |
sigfail=true; |
throw new Exception("avr sig" + avr_sig + " unknown"); |
} |
writer.write('T'); |
// writer.flush(); |
writer.write(avr_sig); // set devicetyp = 0x74 oder 0x76 |
writer.flush(); |
if (reader.read()!=0x0d) |
throw new Exception("cant get buffer size"); |
writer.write('V'); |
writer.flush(); |
int bl_version_major=reader.read(); |
int bl_version_minor=reader.read(); |
flash_msgs[msg_pos++]="BL Version " + bl_version_major+"."+bl_version_minor; |
writer.write('b'); |
writer.flush(); |
if (reader.read()!='Y') |
throw new Exception("cant get buffer size"); |
int send_buff_size1=reader.read(); |
int send_buff_size2=reader.read(); |
int send_buff_size=send_buff_size1*0x100+send_buff_size2; |
flash_msgs[msg_pos++]="BUFF Size:" + send_buff_size; |
// if (send_buff_size>128) |
// send_buff_size=128; |
// if (!bootloader_intension |
if (bootloader_intension_flash) |
{ |
byte[] flash_buff =new byte[send_buff_size]; ///!! |
String firmware_filename=(avr_sig==224)?"/navi.bin":((avr_sig==120)?"/mk3.bin":"/fc.bin"); |
flash_msgs[msg_pos++]="Opening firmware " + firmware_filename + ".."; |
InputStream in; |
try { |
in=this.getClass().getResourceAsStream(firmware_filename); |
} |
catch (Exception e) { throw new Exception(" .. cant open firmware"); } |
int firmware_size=-1; |
try { |
firmware_size= ((int)in.read()<<24) |((int)in.read()<<16) | ((int)in.read()<<8) | ((int)in.read()&0xff) ; |
} |
catch (Exception e) { throw new Exception(" .. cant read size"); } |
int blocks2write=((firmware_size/send_buff_size)); |
flash_msgs[msg_pos++]=".. open("+blocks2write+" blocks," + firmware_size + "bytes)"; |
// if (true) throw new Exception("before erasing"); |
// if (true) throw new Exception("before erasing" ); |
flash_msgs[msg_pos++]="Erasing Flash .."; |
writer.write('e'); |
writer.flush(); |
if (reader.read()!=0x0d) |
throw new Exception("cant erase flash"); |
flash_msgs[msg_pos]+="OK"; |
writer.write('A'); |
writer.write(0); |
writer.write(0); |
writer.flush(); |
if (reader.read()!=0x0d) |
throw new Exception("cant set addr"); |
flash_msgs[msg_pos++]="addr set"; |
// int blocks2write=((firmware_size/send_buff_size)); |
if ((firmware_size%send_buff_size)>0) |
blocks2write++; |
for ( int block=0; block<blocks2write; block ++) |
{ |
int hex_bytes_read=in.read(flash_buff,0,send_buff_size); |
flash_msgs[msg_pos]="bl:" + block + "/" + blocks2write + " si:"+hex_bytes_read ; |
writer.write('B'); |
writer.write((hex_bytes_read>>8)& 0xFF); |
writer.write((hex_bytes_read)& 0xFF); |
writer.write('F'); |
writer.flush(); |
writer.write(flash_buff,0,hex_bytes_read); |
writer.flush(); |
if (avr_sig==224) |
{ |
int crc=0xFFFF; |
for (int crc_pos=0;crc_pos<hex_bytes_read;crc_pos++) |
crc=CRC16(flash_buff[crc_pos],crc); |
writer.write(crc>>8); |
writer.write(crc&0xff); |
writer.flush(); |
} |
// flash_msgs[msg_pos]+="ok"; |
// writer.flush(); |
if (reader.read()!=0x0d) |
throw new Exception("abort write at block"+block); |
// sleep(1000); |
} |
// flash_msgs[msg_pos]="bl:" + block + "/" + blocks2write + " si:"+hex_bytes_read ; |
/* |
int inp=0; |
int block=0; |
while (inp!=-1) |
{ |
int flash_buff_pos=0; |
int crc=0xFFFF; |
while ((flash_buff_pos<send_buff_size)&&(inp!=-1)) |
{ |
inp=in.read(); |
if (inp!=-1) |
{ |
crc=CRC16(inp,crc); |
flash_buff[flash_buff_pos++]=(byte)inp; |
} |
} |
// flash_msgs[msg_pos]="block" + block + "size:"+flash_buff_pos; |
block++; |
boolean block_fin=false; |
while(!block_fin) |
{ |
writer.write('B'); |
writer.write((flash_buff_pos>>8)& 0xFF); |
writer.write((flash_buff_pos)& 0xFF); |
writer.write('F'); |
writer.flush(); |
// int ret_v=-1; |
writer.write(flash_buff,0,flash_buff_pos); |
flash_msgs[msg_pos]="bl:" + block + "si:"+flash_buff_pos ; |
writer.flush(); |
// flash_msgs[msg_pos]+="wtc"; |
// append crc if navi |
if (avr_sig==224) |
{ |
writer.write(crc>>8); |
writer.write(crc&0xff); |
writer.flush(); |
} |
// flash_msgs[msg_pos]+="ok"; |
// writer.flush(); |
// if (reader.read()!=0x0d) |
// throw new Exception("abort write at block"+block); |
//ret_v=reader.read(); |
// flash_msgs[msg_pos]="ret"+ret_v + "crc"+crc; |
if (reader.read()==0x0d) |
block_fin=true; |
} |
} |
*/ |
flash_msgs[++msg_pos]="written last block "; |
msg_pos++; |
flash_buff=null; |
ufo_prober.set_to_none(); |
stats.reset(); |
version=new MKVersion(); |
System.gc(); |
} |
else // bootloader intension clear settings |
{ |
flash_msgs[msg_pos]="reset params .."; |
writer.write('B'); |
writer.write(0); |
writer.write(4); |
writer.write('E'); |
writer.flush(); |
writer.write(0xFF); |
writer.write(0xFF); |
writer.write(0xFF); |
writer.write(0xFF); |
writer.flush(); |
flash_msgs[msg_pos++]+=" done"; |
} |
flash_msgs[msg_pos++]="Exiting Bootloader" ; |
params=new MKParamsParser(); |
try{ |
writer.write('E'); |
writer.flush(); |
} |
catch (Exception e) { |
flash_msgs[msg_pos++]="cant exit bootloader" ; |
} |
flash_msgs[msg_pos++]="Exit BL done" ; |
bootloader_finish_ok=true; |
} |
catch (Exception e) { |
flash_msgs[msg_pos++]="Fail:" +e.getMessage() ; |
flash_msgs[msg_pos++]="Exiting Bootloader" ; |
params=new MKParamsParser(); |
try{ |
writer.write('E'); |
writer.flush(); |
} |
catch (Exception e2) { |
flash_msgs[msg_pos++]="cant exit bootloader" ; |
} |
flash_msgs[msg_pos++]="Exit BL done" ; |
if (sigfail&&(bl_retrys<3)) |
{ |
bl_retrys++; |
init_bootloader=true; |
} |
close_connections(false); |
} |
sending=false; |
} |
byte[] data_set=new byte[1024]; |
int data_set_pos=0; |
byte[] data_in_buff=new byte[2048]; |
int input; |
int pos=0; |
log("Thread started"); |
while(true) |
{ |
if (!connected) |
{ |
if (!force_disconnect) connect(); |
sleep(100); |
} |
else |
try{ |
/* |
while(sending) |
{try { Thread.sleep(50); } |
catch (Exception e) { } |
} |
*/ |
recieving=true; |
int read_count =reader.read(data_in_buff,0,reader.available()); |
log("Connected - reading data " + read_count); |
// pos=0; |
input=0; |
//data_buff[data_buff_pos]=""; |
// recieve data-set |
if (read_count==0) sleep(50); |
// int read_count =reader.read(data_in_buff,0,reader.available()); |
stats.bytes_in+=read_count; |
if (read_count>0) |
{ |
log("read" + read_count + " ds_pos" + data_set_pos); |
for ( pos=0;pos<read_count;pos++) |
{ |
if (data_in_buff[pos]==13) |
{ |
data_buff[data_buff_pos]=new String(data_set, 0, data_set_pos); |
data_buff_pos++; |
data_buff_pos%=DATA_BUFF_LEN; |
try{process_data(data_set,data_set_pos); } |
catch (Exception e) |
{ |
log(".. problem processing"); |
log(e.toString()); |
} |
proxy.write(data_set,0,data_set_pos); |
// proxy.writer.write('\r'); |
//proxy.writer.write('\n'); |
//proxy.writer.flush(); |
/* |
if (proxy!=null) |
{ |
} |
*/ |
data_set_pos=0; |
} |
else |
{ |
data_set[data_set_pos++]=data_in_buff[pos]; |
if ( (data_set_pos>4) && (data_set[data_set_pos-4]==(byte)'M') && (data_set[data_set_pos-3]==(byte)'K') && (data_set[data_set_pos-2]==(byte)'B') && (data_set[data_set_pos-1]==(byte)'L')) |
{ |
bootloader_stage= BOOTLOADER_STAGE_GOT_MKBL; |
return; |
} |
} |
} |
} |
else |
sleep(50); |
/* |
while ((input != 13)) //&&(input!=-1)) |
{ |
{ |
//log("pre read"); |
log(""+reader.available()); |
input = reader.read() ; |
log("Byte rcv" + input +"pos"+ pos); |
proxy.write(input); |
data_buff[data_buff_pos]+=(char)input; |
if ((data_buff[data_buff_pos].length()>3)&&(data_buff[data_buff_pos].substring(data_buff[data_buff_pos].length()-4,data_buff[data_buff_pos].length()).equals("MKBL"))) |
{ |
bootloader_stage= BOOTLOADER_STAGE_GOT_MKBL; |
return; |
} |
if (input==-1) throw new Exception("disconnect"); |
else |
{ |
stats.bytes_in++; |
data_set[pos]=input; |
pos++; |
} |
} |
} |
data_buff_pos++; |
data_buff_pos%=DATA_BUFF_LEN; |
recieving=false; |
log("Data recieved (" + pos + "Bytes)"); |
log("processing .."); |
*/ |
/* |
if (proxy!=null) |
{ |
proxy.writer.write('\r'); |
proxy.writer.write('\n'); |
proxy.writer.flush(); |
} |
*/ |
/*if (pos>5) |
{ |
try{process_data(data_set,pos); } |
catch (Exception e) |
{ |
log(".. problem processing"); |
log(e.toString()); |
} |
log(".. processing done"); |
} |
*/ |
} |
catch (Exception ex) |
{ |
log("Problem reading from MK -> closing conn"); |
log(ex.toString()); |
// close the connection |
close_connections(false); |
} |
// sleep a bit to get someting more done |
// sleep(5); //50 |
} // while |
// log("Leaving Communicator thread"); |
} // run() |
} |
/DUBwise/tags/v0.51/shared/src/MKDebugData.java |
---|
0,0 → 1,83 |
/********************************************* |
* |
* class representing the DebugData Structure |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
********************************************/ |
package org.ligi.ufo; |
public class MKDebugData |
{ |
public int[] analog; |
public String[] names; |
public boolean[] got_name; |
public int motor_complete=-1; |
private int i; |
public int motor_val(int id) { return analog[12+id]; } |
public int nick_int() { return analog[0]; } |
public int roll_int() { return analog[1]; } |
public int accnick() { return analog[2]; } |
public int accroll() { return analog[3]; } |
public int UBatt() { return analog[9]; } |
public int SenderOkay() { return analog[10]; } |
public MKDebugData() |
{ |
names=new String[32]; |
analog=new int[32]; |
got_name=new boolean[32]; |
for (i=0;i<32;i++) |
{ |
analog[i]=-1; |
names[i]="-#"+i+"->"; |
got_name[i]=false; |
} |
} |
public void set_names_by_mk_data(int[] in_arr) |
{ |
int id=in_arr[0]; |
names[id]=""; |
for (i=0;i<16;i++) |
{ |
if ((char)in_arr[i+1]!=' ') |
names[id]+=(char)in_arr[i+1]; |
got_name[id]=true; |
} |
names[id]+=":"; |
} |
public void set_by_mk_data(int[] in_arr,MKVersion version) |
{ |
for (i=0;i<32;i++) |
// { |
analog[i]=MKHelper.parse_signed_int_2( in_arr[2+i*2], in_arr[3+i*2] ); |
//(int)((in_arr[3+i*2]<<8) | in_arr[2+i*2]); |
// if ((analog[i]&(1<<15))!=0) |
//analog[i]=-(analog[i]&(0xFFFF-1))^(0xFFFF-1); |
// } |
motor_complete=motor_val(0)+motor_val(1)+motor_val(2)+motor_val(3); |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKGPSPosition.java |
---|
0,0 → 1,407 |
/********************************************* |
* |
* class representing the DebugData Structure |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
* Some code taken from here: |
* http://www.koders.com/java/fidFC75A641A87B51BB757E9CD3136C7886C491487F.aspx |
* |
* and |
* http://www.movable-type.co.uk/scripts/latlong.html |
* |
* thanx a lot for sharing! |
* |
********************************************/ |
package org.ligi.ufo; |
import java.lang.Math; |
public class MKGPSPosition |
implements DUBwiseDefinitions |
{ |
public byte act_gps_format=GPS_FORMAT_DECIMAL; |
public byte act_speed_format=SPEED_FORMAT_KMH; |
public final static int MAX_WAYPOINTS=100; |
public int[] LongWP; |
public int[] LatWP; |
public String[] NameWP; |
int UBatt; |
public int last_wp=0; |
public int Longitude; |
public int Latitude; |
public int Altitude; |
public int TargetLongitude; |
public int TargetLatitude; |
public int TargetAltitude; |
public int HomeLongitude; |
public int HomeLatitude; |
public int HomeAltitude; |
public int Distance2Target; |
public int Angle2Target; |
public int Distance2Home; |
public int Angle2Home; |
public byte SatsInUse=-1; |
public byte WayPointNumber=-1; |
public byte WayPointIndex=-1; |
public int AngleNick = -1; |
public int AngleRoll = -1; |
public int SenderOkay = -1; |
public int MKFlags= -1; |
public int NCFlags= -1; |
public int ErrorCode= -1; |
public int Altimeter=-1; // hight according to air pressure |
public int Variometer=-1; // climb(+) and sink(-) rate |
public int FlyingTime=-1; |
public int GroundSpeed=-1; |
public int Heading=-1; |
public int CompasHeading=-1; |
//#if cldc11=="on" |
public static final double PI = Math.PI; |
public static final double PI_div2 = PI / 2.0; |
public static final double PI_div4 = PI / 4.0; |
public static final double RADIANS = PI / 180.0; |
public static final double DEGREES = 180.0 / PI; |
private static final double p4 = 0.161536412982230228262e2; |
private static final double p3 = 0.26842548195503973794141e3; |
private static final double p2 = 0.11530293515404850115428136e4; |
private static final double p1 = 0.178040631643319697105464587e4; |
private static final double p0 = 0.89678597403663861959987488e3; |
private static final double q4 = 0.5895697050844462222791e2; |
private static final double q3 = 0.536265374031215315104235e3; |
private static final double q2 = 0.16667838148816337184521798e4; |
private static final double q1 = 0.207933497444540981287275926e4; |
private static final double q0 = 0.89678597403663861962481162e3; |
private static double _ATAN(double X) |
{ |
if (X < 0.414213562373095048802) |
return _ATANX(X); |
else if (X > 2.414213562373095048802) |
return PI_div2 - _ATANX(1.0 / X); |
else |
return PI_div4 + _ATANX((X - 1.0) / (X + 1.0)); |
} |
private static double _ATANX(double X) |
{ |
double XX = X * X; |
return X * ((((p4 * XX + p3) * XX + p2) * XX + p1) * XX + p0)/ (((((XX + q4) * XX + q3) * XX + q2) * XX + q1) * XX + q0); |
} |
public double aTan2(double Y, double X) |
{ |
if (X == 0.0) { |
if (Y > 0.0) |
return PI_div2; |
else if (Y < 0.0) |
return -PI_div2; |
else |
return 0.0; |
} |
// X<0 |
else if (X < 0.0) { |
if (Y >= 0.0) |
return (PI - _ATAN(Y / -X)); // Y>=0,X<0 |Y/X| |
else |
return -(PI - _ATAN(Y / X)); // Y<0,X<0 |Y/X| |
} |
// X>0 |
else if (X > 0.0) |
{ |
if (Y > 0.0) |
return _ATAN(Y / X); |
else |
return -_ATAN(-Y / X); |
} |
return 0.0; |
} |
public int distance2wp(int id) |
{ |
double lat1=(Latitude/10000000.0)*RADIANS; |
double long1=(Longitude/10000000.0)*RADIANS; |
double lat2=(LatWP[id]/10000000.0)*RADIANS; |
double long2=(LongWP[id]/10000000.0)*RADIANS; |
double dLat= (lat2-lat1); |
double dLon= (long2-long1); |
double a = Math.sin(dLat/2.0) * Math.sin(dLat/2.0) + |
Math.cos(lat1) * Math.cos(lat2) * |
Math.sin(dLon/2.0) * Math.sin(dLon/2.0); |
return (int)(( 2.0 * aTan2(Math.sqrt(a), Math.sqrt(1.0-a)) )*6371008.8); |
} |
public int angle2wp(int id) |
{ |
// TODO reuse from distance |
double lat1=(Latitude/10000000.0)*RADIANS; |
double long1=(Longitude/10000000.0)*RADIANS; |
double lat2=(LatWP[id]/10000000.0)*RADIANS; |
double long2=(LongWP[id]/10000000.0)*RADIANS; |
double dLat= (lat2-lat1); |
double dLon= (long2-long1); |
double y = Math.sin(dLon) * Math.cos(lat2); |
double x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon); |
return ((int)(aTan2(y, x)*DEGREES)+360)%360; |
} |
//#endif |
//#if cldc11!="on" |
//# public int distance2wp(int id) |
//# { |
//# return -1; |
//# } |
//# public int angle2wp(int id) |
//# { |
//# return -1; |
//# } |
//#endif |
public void push_wp() |
{ |
LongWP[last_wp]=Longitude; |
LatWP[last_wp]=Latitude; |
last_wp++; |
} |
/* public void next_gps_format() |
{ |
act_gps_format=(byte)((act_gps_format+1)%GPS_FORMAT_COUNT); |
}*/ |
public String act_gps_format_str(int val) |
{ |
switch(act_gps_format) |
{ |
case GPS_FORMAT_DECIMAL: |
return "" + val/10000000 + "." +val%10000000 ; |
case GPS_FORMAT_MINSEC: |
return "" + val/10000000 + "^" + ((val%10000000)*60)/10000000 + "'" + ((((val%10000000)*60)%10000000)*60)/10000000 + "." + ((((val%10000000)*60)%10000000)*60)%10000000; |
default: |
return "invalid format"; |
} |
} |
public String act_speed_format_str(int val) |
{ |
switch(act_speed_format) |
{ |
case SPEED_FORMAT_KMH: |
return "" + ((((val*60)/100)*60)/1000) + " km/h"; |
case SPEED_FORMAT_MPH: |
return "" + (((((val*60)/100)*60)/1000)*10)/16 + " m/h"; |
case SPEED_FORMAT_CMS: |
return "" + val+ " cm/s"; |
default: |
return "invalid speed format"; |
} |
} |
public String GroundSpeed_str() |
{ |
return act_speed_format_str(GroundSpeed); |
} |
public String WP_Latitude_str(int id) |
{ |
return act_gps_format_str(LatWP[id]); //+ "''N" ; |
} |
public String WP_Longitude_str(int id) |
{ |
return act_gps_format_str(LongWP[id]); //+ "''E" ; |
} |
public String Latitude_str() |
{ |
return act_gps_format_str(Latitude) ; |
} |
public String Longitude_str() |
{ |
return act_gps_format_str(Longitude) ; |
} |
public String TargetLatitude_str() |
{ |
return act_gps_format_str(TargetLatitude) ; |
} |
public String TargetLongitude_str() |
{ |
return act_gps_format_str(TargetLongitude) ; |
} |
public String HomeLatitude_str() |
{ |
return act_gps_format_str(HomeLatitude) ; |
} |
public String HomeLongitude_str() |
{ |
return act_gps_format_str(HomeLongitude) ; |
} |
// Constructor |
public MKGPSPosition() |
{ |
LongWP=new int[MAX_WAYPOINTS]; |
LatWP=new int[MAX_WAYPOINTS]; |
NameWP=new String[MAX_WAYPOINTS]; |
// predefined waypoints |
/* |
LongWP[0]=123230170; |
LatWP[0]= 513600170 ; |
NameWP[0]="Sicherer PC1"; |
LongWP[1]=123269000; |
LatWP[1]= 513662670; |
NameWP[1]="Sicherer PC2"; |
LongWP[2]=123475570; |
LatWP[2]= 513569750 ; |
NameWP[2]="Treffpunkt Seba"; |
*/ |
last_wp=0; |
} |
private int parse_arr_4(int offset,int[] in_arr) |
{ |
return ((in_arr[offset+3]<<24) | |
(in_arr[offset+2]<<16) | |
(in_arr[offset+1]<<8) | |
(in_arr[offset+0])); |
} |
private int parse_arr_2(int offset,int[] in_arr) |
{ |
return (((in_arr[offset+1]&0xFF)<<8) | |
(in_arr[offset+0]&0xFF )); |
} |
public void set_by_mk_data(int[] in_arr,MKVersion version) |
{ |
Longitude=parse_arr_4(0,in_arr); |
Latitude=parse_arr_4(4,in_arr); |
Altitude=parse_arr_4(8,in_arr); |
//status=in_arr[12]; |
TargetLongitude=parse_arr_4(13,in_arr); |
TargetLatitude=parse_arr_4(17,in_arr); |
TargetAltitude=parse_arr_4(21,in_arr); |
//Targetstatus=in_arr[25]; |
Distance2Target=parse_arr_2(26,in_arr); |
Angle2Target=parse_arr_2(28,in_arr); |
HomeLongitude=parse_arr_4(30,in_arr); |
HomeLatitude=parse_arr_4(34,in_arr); |
HomeAltitude=parse_arr_4(38,in_arr); |
//Targetstatus=in_arr[42]; |
Distance2Home=parse_arr_2(43,in_arr); |
Angle2Home=parse_arr_2(45,in_arr); |
WayPointIndex=(byte)in_arr[47]; |
WayPointNumber=(byte)in_arr[48]; |
SatsInUse=(byte)in_arr[49]; |
Altimeter=parse_arr_2(50,in_arr); // hight according to air pressure |
Variometer=parse_arr_2(52,in_arr);; // climb(+) and sink(-) rate |
FlyingTime=parse_arr_2(54,in_arr);; |
UBatt= in_arr[56]; |
GroundSpeed= parse_arr_2(57,in_arr); |
Heading= parse_arr_2(59,in_arr); |
CompasHeading= parse_arr_2(61,in_arr); |
AngleNick = in_arr[63]; |
AngleRoll = in_arr[64]; |
SenderOkay = in_arr[65]; |
MKFlags=in_arr[66]; |
NCFlags=in_arr[67]; |
ErrorCode=in_arr[67]; |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKHelper.java |
---|
0,0 → 1,21 |
package org.ligi.ufo; |
public final class MKHelper |
{ |
public final static int parse_signed_int_2(int i1,int i2) |
{ |
int res=(int)((i2<<8)|i1); |
if ((res&(1<<15))!=0) |
return -(res&(0xFFFF-1))^(0xFFFF-1); |
else |
return res; |
} |
public final static int parse_unsigned_int_2(int i1,int i2) |
{ |
return (int)((i2<<8)|i1); |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKLCD.java |
---|
0,0 → 1,85 |
/******************************************* |
* |
* Handling of MK LCD |
* |
* Author: Marcus -LiGi- Bueschleb |
* see README for further Infos |
* |
* |
*******************************************/ |
package org.ligi.ufo; |
public class MKLCD |
// implements Runnable |
{ |
MKCommunicator mk=null; |
int last_recieved_page=0; |
int act_page=0; |
public int pages=-1; |
private String[] lcd_buf; |
private String[] lcd_buf_; |
public String[] get_act_page() |
{ return lcd_buf; } |
public MKLCD(MKCommunicator _mk) |
{ |
lcd_buf=new String[4]; |
lcd_buf[0]="no "; |
lcd_buf[1]="DisplayData " ; |
lcd_buf[2]="read "; |
lcd_buf[3]="yet "; |
mk=_mk; |
} |
public void set_page(int page) |
{ |
act_page=page; |
} |
public void handle_lcd_data(int[] data) |
{ |
lcd_buf_=new String[4]; |
last_recieved_page=data[0]; |
pages=data[1]; |
for(int row=0;row<4;row++) |
{ |
lcd_buf_[row]=""; |
for(int col=0;col<20;col++) |
lcd_buf_[row]+=(char)data[row*20+col+2]; |
} |
lcd_buf=lcd_buf_; |
} |
public void trigger_LCD() |
{ |
mk.trigger_LCD_by_page(act_page); |
} |
public void LCD_NEXTPAGE() |
{ |
if (act_page!=pages) |
act_page++; |
else |
act_page=0; |
} |
public void LCD_PREVPAGE() |
{ |
if (act_page!=0) |
act_page--; |
else |
act_page=pages; |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKParamDefinitions.java |
---|
0,0 → 1,14 |
package org.ligi.ufo; |
public interface MKParamDefinitions |
{ |
public final static int PARAMTYPE_BYTE=0; |
public final static int PARAMTYPE_BITSWITCH=1; |
public final static int PARAMTYPE_STICK=2; |
public final static int PARAMTYPE_KEY=3; |
public final static int PARAMTYPE_CHOICE=4; |
// choice must be last! |
} |
/DUBwise/tags/v0.51/shared/src/MKParamsParser.java |
---|
0,0 → 1,209 |
/************************************************** |
* |
* class representing the Params Structure |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
*************************************************/ |
package org.ligi.ufo; |
public class MKParamsParser extends ParamsClass |
{ |
// -- start generated code -- |
public final static int PARAMTYPE_BYTE=0; |
public final static int PARAMTYPE_BITSWITCH=1; |
public final static int PARAMTYPE_STICK=2; |
public final static String[][] all_tab_names={{"Altitude","Camera","Channels","Configuration","Coupling","Gyro","Looping","Navi","Other","Output","Stick","User"},{"Altitude","Camera","Channels","Configuration","Coupling","Gyro","Looping","Navi","Other","Output","Stick","User"}}; |
public final static String[][][] all_field_names={{{"Min. Accelerate","Barometric D","Setpoint","Altitude P","Gain","Z-ACC","3-Way switch"},{"Servo control","Nick compensation","Servo min","Servo max","Refresh rate","Invert Direction"},{"Nick","Roll","Accelerate","Gier","POTI1","POTI2","POTI3","POTI4"},{"ALTITUDE_CONTROL","Switch for Setpoint","Heading Hold","Compas Active","Compas Fix","GPS","Coupling","Yaw Rate Limiter"},{"Yaw pos. feedback","Yaw neg. feedback"},{"ACC/Gyro Factor","P-Rate","I-Rate","ACC/Gyro Comp","Drift-Compensation","Dynamic stability"},{"Gas Limit","Threshold","Hysterese","TurnOver Nick","TurnOver Roll","UP","DOWN","LEFT","RIGHT"},{"Mode Control","GPS-Gain","GPS-P","GPS-I","GPS-D","GPS-ACC","Satelite Minimum","Stick Threhsold","Wind Correction","Speed Compensation","Operating Radius","Angle Limit"},{"Min Gas","Max Gas","Compass Effect","Voltage Warning","Distress Gas","Distress Gas Time"},{"J16 Bitmask","J16 Timing","J17 Bitmask","J17 Timing"},{"Nick/Roll P","Nick/Roll D","Gier P","External Control"},{"Param 1","Param 2","Param 3","Param 4","Param 5","Param 6","Param 7","Param 8"}},{{"Min. Accelerate","Barometric D","Setpoint","Altitude P","Gain","Z-ACC","3-Way switch"},{"Servo control","Nick compensation","Servo min","Servo max","Refresh rate","Invert Direction"},{"Nick","Roll","Accelerate","Gier","POTI1","POTI2","POTI3","POTI4"},{"ALTITUDE_CONTROL","Switch for Setpoint","Heading Hold","Compas Active","Compas Fix","GPS","Coupling","Yaw Rate Limiter"},{"Yaw pos. feedback","Coupling2","Coupling YawCorrect"},{"ACC/Gyro Factor","P-Rate","I-Rate","D-Rate","ACC/Gyro Comp","Drift-Compensation","Dynamic stability"},{"Gas Limit","Threshold","Hysterese","TurnOver Nick","TurnOver Roll","UP","DOWN","LEFT","RIGHT"},{"Mode Control","GPS-Gain","GPS-P","GPS-I","GPS-D","GPS-P Limit","GPS-I Limit","GPS-D Limit","GPS-ACC","Satelite Minimum","Stick Threhsold","Wind Correction","Speed Compensation","Operating Radius","Angle Limit","PH LoginTime"},{"Min Gas","Max Gas","Compass Effect","Voltage Warning","Distress Gas","Distress Gas Time"},{"J16 Bitmask","J16 Timing","J17 Bitmask","J17 Timing"},{"Nick/Roll P","Nick/Roll D","Gier P","External Control"},{"Param 1","Param 2","Param 3","Param 4","Param 5","Param 6","Param 7","Param 8"}}}; |
public final static int[][][] all_field_positions={{{9,10,11,12,13,14,556},{33,34,35,36,37,560},{0,1,2,3,4,5,6,7},{64,65,66,67,68,69,70,71},{41,42},{20,22,23,45,46,47},{38,39,40,43,44,552,553,554,555},{56,57,58,59,60,61,62,63,64,65,66,67},{18,19,21,24,25,26},{52,53,54,55},{15,16,17,68},{29,30,31,32,48,49,50,51}},{{9,10,11,12,13,14,604},{34,35,36,37,38,608},{0,1,2,3,4,5,6,7},{64,65,66,67,68,69,70,71},{42,43,44},{20,22,23,24,47,48,49},{39,40,41,45,46,600,601,602,603},{58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73},{18,19,21,25,26,27},{54,55,56,57},{15,16,17,74},{30,31,32,33,50,51,52,53}}}; |
public final static int[][][] all_field_types={{{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH},{PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK},{PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}},{{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH},{PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK},{PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}}}; |
public final static int[] all_name_positions={75,81}; |
public final static int[] all_lengths={87,93}; |
// -- end generated code -- |
public final static int MAX_PARAMSETS=5; |
// public final static int MAX_PARAMLENGTH=100; |
public int[][] field; |
public int[][] field_bak; |
// public String[] names={"","","","",""}; |
public int act_paramset=0; |
public int params_version=-1; |
public int last_parsed_paramset=-1; |
public int active_paramset=-1; |
public boolean found_incompatible=false; |
public String[] stick_names; |
public int get_field_from_act(int pos) |
{ return field[act_paramset][pos]; } |
public void set_field_from_act(int pos,int val) |
{ |
if (val>255) val=255; |
if (val<0) val=255; |
field[act_paramset][pos]=val; |
} |
/* public void field_from_act_add(int pos,int val) |
{ |
set_field_from_act(pos , get_field_from_act(pos)+val); |
} |
// for boolean Flags |
public void field_from_act_xor(int pos,int val) |
{ |
field[act_paramset][pos]^=val; |
} |
*/ |
public void set_name(String nme) |
{ |
if (nme.length()>10) |
nme=nme.substring(0,10); |
// names[act_paramset]=nme; |
int nme_pos=0; |
while(nme_pos<nme.length()) |
{ |
field[act_paramset][name_start+nme_pos]=(byte)nme.charAt(nme_pos); |
nme_pos++; |
} |
field[act_paramset][name_start+nme_pos]=0; |
} |
public MKParamsParser() |
{ |
field=new int[MAX_PARAMSETS][]; |
field_bak=new int[MAX_PARAMSETS][]; |
for (int ii=0;ii<MAX_PARAMSETS;ii++) |
{ |
field[ii]=null; |
field_bak[ii]=null; |
} |
stick_names=new String[10]; |
for (int i=0;i<10;i++) |
stick_names[i]="not read yet"; |
} |
public int length=0; |
public int name_start=0; |
/* |
public int[] param_type; |
public int[] param_pos; |
public int[] param_innerpos; |
public String[] tab_names; |
public String[][] field_names; |
public int[][] field_positions; |
public int[][] field_types; |
public int length; |
public int name_start; |
*/ |
public void use_backup() |
{ |
set_by_mk_data(field_bak[act_paramset]); |
} |
public void update_backup(int to) |
{ |
for ( int i=0 ; i<field[act_paramset].length;i++) |
{ |
field_bak[to][i+2]=field[act_paramset][i]; |
field[to][i]=field[act_paramset][i]; |
} |
field_bak[to][0]=to+1; |
field_bak[to][1]=params_version; |
} |
public void reset() |
{ |
last_parsed_paramset=-1; |
for (int ii=0;ii<MAX_PARAMSETS;ii++) |
field[ii]=null; |
} |
public String getParamName(int paramset) |
{ |
String res=""; |
for ( int i=name_start;i<length;i++) |
{ |
if(field[paramset][i]==0)break; |
res+=(char)field[paramset][i]; |
} |
return res; |
} |
public void set_by_mk_data(int[] in_arr) |
{ |
params_version=in_arr[1]; |
int definition_pos=params_version-73; |
if ((definition_pos<0)||( (definition_pos>=all_tab_names.length))) |
{ |
found_incompatible=true; |
return; |
} |
last_parsed_paramset=in_arr[0]-1; |
if (active_paramset==-1)active_paramset=last_parsed_paramset; |
tab_names=all_tab_names[definition_pos]; |
field_names=all_field_names[definition_pos]; |
field_positions=all_field_positions[definition_pos]; |
field_types=all_field_types[definition_pos]; |
name_start=all_name_positions[definition_pos]; |
length=all_lengths[definition_pos]; |
field[last_parsed_paramset]=new int[length]; |
field_bak[last_parsed_paramset]=new int[length+2]; |
// names[last_parsed_paramset]=""; |
for ( int i=0;i<length+2;i++) |
{ |
if (i<length) |
field[last_parsed_paramset][i]=in_arr[i+2]; |
field_bak[last_parsed_paramset][i]=in_arr[i]; |
} |
for (int i=0;i<10;i++) |
stick_names[i]="not associated"; |
for (int tab=0;tab<tab_names.length;tab++) |
for (int item=0;item<field_types[tab].length;item++) |
if (field_types[tab][item]==PARAMTYPE_STICK) |
stick_names[ field[last_parsed_paramset][field_positions[tab][item]] ] = field_names[tab][item]; |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKProxy.java |
---|
0,0 → 1,122 |
package org.ligi.ufo; |
import java.io.*; |
//import javax.microedition.io.*; |
//#ifdef j2me |
//# import javax.microedition.io.*; |
//#endif |
public class MKProxy |
implements Runnable |
{ |
public boolean connected; |
public String url; |
public String err_str="none"; |
//#ifdef j2me |
//# StreamConnection connection; |
//#endif |
//#ifdef android |
java.net.Socket connection; |
//#endif |
public java.io.InputStream reader; |
public java.io.OutputStream writer; |
MKCommunicator mk; |
public MKProxy(MKCommunicator _mk) |
{ |
mk=_mk; |
new Thread( this ).start(); // fire up main Thread |
} |
public void connect(String url_) |
{ |
url=url_; |
try |
{ |
// |
//#ifdef android |
connection = new java.net.Socket(url_,9876); |
reader=connection.getInputStream(); |
writer=connection.getOutputStream(); |
//#endif |
//#ifdef j2me |
//# connection = (StreamConnection) Connector.open(url, Connector.READ_WRITE); |
//# reader=connection.openInputStream(); |
//# writer=connection.openOutputStream(); |
//#endif |
String init="new:foo bar\r\n"; |
writer.write(init.getBytes()); |
writer.flush(); |
connected=true; |
} |
catch (Exception e) |
{ |
// err_str=e.toString(); |
// this=null; |
connected=false; |
} |
} |
public void write(byte[] input,int off,int len) |
{ |
if (connected) |
try{ writer.write(input,off,len); |
writer.write(13); |
writer.flush(); |
// if (input==13) writer.flush(); |
} |
catch(Exception e) { connected=false; } |
} |
public void sleep(int time) |
{ |
try { Thread.sleep(time); } |
catch (Exception e) { } |
} |
public void run() |
{ |
while(true) |
{ |
try { |
if (connected) |
{ |
byte[] data_in_buff=new byte[reader.available()]; |
int read_count =reader.read(data_in_buff,0,reader.available()); |
if (read_count>0) mk.write_raw(data_in_buff); |
sleep(30); |
} |
else |
sleep(300); |
} |
catch ( Exception e){} |
} |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKStatistics.java |
---|
0,0 → 1,72 |
/******************************************************************************** |
* Statistics from MK-Connection ( needed for 2. Thread and Readability of Code ) |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
********************************************************************************/ |
package org.ligi.ufo; |
public class MKStatistics |
{ |
public int bytes_in=0; |
public int bytes_out=0; |
public int resend_count=0; |
public int debug_data_count=0; |
public int debug_names_count=0; |
public int angle_data_count=0; |
public int version_data_count=0; |
public int other_data_count=0; |
public int lcd_data_count=0; |
public int params_data_count=0; |
public int navi_data_count=0; |
public int stick_data_count=0; |
public int external_control_confirm_frame_count=0; |
public int debug_data_request_count=0; |
public int debug_name_request_count=0; |
public int version_data_request_count=0; |
public int lcd_data_request_count=0; |
public int params_data_request_count=0; |
// public int navi_data_count=0; |
public int stick_data_request_count=0; |
public int motortest_request_count=0; |
public int external_control_request_count=0; |
public void reset() |
{ |
debug_data_count=0; |
debug_names_count=0; |
angle_data_count=0; |
version_data_count=0; |
other_data_count=0; |
lcd_data_count=0; |
params_data_count=0; |
navi_data_count=0; |
bytes_in=0; |
bytes_out=0; |
stick_data_count=0; |
debug_data_request_count=0; |
debug_name_request_count=0; |
version_data_request_count=0; |
lcd_data_request_count=0; // |
params_data_request_count=0; // |
stick_data_request_count=0; |
motortest_request_count=0; // |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKStickData.java |
---|
0,0 → 1,44 |
/********************************************* |
* |
* class representing the StickData Structure |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
********************************************/ |
package org.ligi.ufo; |
public class MKStickData |
{ |
// holing stick data |
public int[] stick; |
// general counter |
private int i; |
public MKStickData() |
{ |
stick=new int[10]; |
for (i=0;i<10;i++) |
stick[i]=-1; |
} |
public void set_by_mk_data(int[] in_arr) |
{ |
for (i=0;i<10;i++) |
{ |
stick[i]=(int)((in_arr[1+i*2]<<8) | in_arr[i*2]); |
if ((stick[i]&(1<<15))!=0) |
stick[i]=-(stick[i]&(0xFFFF-1))^(0xFFFF-1); |
} |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKVersion.java |
---|
0,0 → 1,48 |
/************************************ |
* |
* class representing the MK-Version |
* Author: Marcus -LiGi- Bueschleb |
* Project-Start: 9/2007 * |
* |
* see README for further Infos |
* |
****************************************/ |
package org.ligi.ufo; |
public class MKVersion |
{ |
public int major=-1; |
public int minor=-1; |
public int compatible=-1; |
public String str="--"; |
// version known? |
public boolean known=false; |
public final byte VERSION_AFTER=0; |
public final byte VERSION_EQUAL=1; |
public final byte VERSION_PREVIOUS=2; |
public void set_by_mk_data(int[] data) |
{ |
major=data[0]; |
minor=data[1]; |
compatible=data[2]; |
str="v"+major+"."+minor+"/"+compatible; |
known=true; |
} |
public byte compare(int major_c,int minor_c) |
{ |
if ((major_c==major)&&(minor_c==minor)) |
return VERSION_EQUAL; |
// TODO - compare major - PC-COMPATIBLE |
else if (minor_c>minor) return VERSION_AFTER; |
return VERSION_PREVIOUS; |
} |
} |
/DUBwise/tags/v0.51/shared/src/MKWatchDog.java |
---|
0,0 → 1,254 |
/************************************** |
* |
* WatchDog for MK-Connection |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
* |
**************************************/ |
package org.ligi.ufo; |
public class MKWatchDog |
implements Runnable,DUBwiseDefinitions |
{ |
MKCommunicator mk=null; |
int debug_data_count_buff=-123; |
public MKWatchDog(MKCommunicator _mk) |
{ |
mk=_mk; |
new Thread( this ).start(); // fire up main Thread |
} |
public int act_paramset=0; |
int conn_check_timeout=0; |
public byte resend_timeout=0; |
int last_count=0; |
public boolean resend_check(int ref_count) |
{ |
if (( last_count!=ref_count)||(resend_timeout<0)) |
{ |
if (resend_timeout<0) mk.stats.resend_count++; |
last_count=ref_count; |
resend_timeout=20; |
return true; |
} |
else |
resend_timeout--; |
return false; |
} |
//#ifdef android |
// public final static int BASE_SLEEP=50; |
//#else |
public final static int BASE_SLEEP=10; |
//#endif |
public void run() |
{ |
mk.log("starting Watchdog"); |
// get all params |
int act_debug_name=0; |
// int sleeper=BASE_SLEEP; |
while(true) |
{ |
try { |
Thread.sleep(BASE_SLEEP); |
// sleeper=BASE_SLEEP; |
if (mk.connected&&(!mk.force_disconnect)) |
{ |
mk.log("watchdog pre main loop"); |
if (mk.init_bootloader) |
{ |
mk.jump_bootloader(); |
mk.init_bootloader=false; |
} |
else if ( mk.version.major==-1 ) |
mk.get_version(); |
else if (mk.ufo_prober.is_navi()&&(mk.error_str==null)) |
mk.get_error_str(); |
else if (mk.ufo_prober.is_mk()&&(mk.params.last_parsed_paramset==-1)) |
{ |
mk.get_params(0xFF-1); |
Thread.sleep(150); |
act_paramset=0; // warning - if dropped problem |
} |
else switch (mk.user_intent) |
{ |
case USER_INTENT_PARAMS: |
if ((act_paramset<5)) |
{ |
if (resend_timeout==0) { |
mk.get_params(act_paramset); |
resend_timeout=120; |
} |
if(mk.params.field[act_paramset]!=null) |
{ |
mk.get_params(++act_paramset); |
resend_timeout=120; |
} |
else |
resend_timeout--; |
/* |
// act_paramset++; |
else |
mk.get_params(act_paramset); |
sleeper+=1200; |
*/ |
} |
break; |
case USER_INTENT_RAWDEBUG: |
if (act_debug_name<32) |
{ |
if (resend_timeout==0) { |
mk.get_debug_name(act_debug_name); |
resend_timeout=50; |
} |
//sleeper+=100; |
if (mk.debug_data.got_name[act_debug_name]) |
{ |
mk.get_debug_name(++act_debug_name); |
resend_timeout=50; |
} |
else |
resend_timeout--; |
} |
else |
if (!(mk.debug_data.got_name[0])) |
act_debug_name=0; |
break; |
case USER_INTENT_RCDATA: |
if ( resend_check(mk.stats.stick_data_count) ) |
mk.trigger_rcdata(); |
break; |
case USER_INTENT_EXTERNAL_CONTROL: |
if (resend_check(mk.stats.external_control_confirm_frame_count)) |
{ |
mk.send_extern_control(); |
mk.send_extern_control(); |
mk.send_extern_control(); |
mk.send_extern_control(); |
} |
break; |
case USER_INTENT_LCD: |
if (resend_check(mk.stats.lcd_data_count)) |
mk.LCD.trigger_LCD(); |
break; |
default: |
// mk.log("uncactched intent " +mk.root.canvas.user_intent ); |
break; |
} |
// if ((!mk.ufo_prober.is_incompatible())) |
{/* |
mk.log("watchdog after main loop"); |
if (debug_data_count_buff==mk.stats.debug_data_count) |
{ |
mk.log("timeout:" +conn_check_timeout ); |
conn_check_timeout++; |
if (conn_check_timeout==1000) |
{ |
mk.log("disconnecting"); |
mk.close_connections(false); |
conn_check_timeout=0; |
} |
debug_data_count_buff=mk.stats.debug_data_count; |
} |
else |
conn_check_timeout=0; |
*/ |
/*else if ((mk.root.canvas.user_intent==USER_INTENT_RAWDEBUG) || (mk.root.canvas.user_intent==USER_INTENT_GRAPH) ) |
{ |
mk.trigger_debug(); |
try { Thread.sleep(100); } |
catch (Exception e) { } |
} |
*/ |
/* |
if (debug_data_count_buff==mk.debug_data_count) |
{ |
// mk.close_connections(false); |
} |
*/ |
/*if (mk.version.major==-1) |
mk.get_version(); |
else |
*/ |
/*for ( int cnt=0;cnt<5;cnt++) |
if (mk.params.field[cnt]==null) |
{ |
mk.get_params(cnt+1); |
break; |
}*/ |
/* |
for (int c=0;c<32;c++) |
if (!mk.debug_data.got_name[c]) |
{ |
mk.get_debug_name(c); |
break; |
} |
*/ |
} |
} |
} // 3000 |
catch (Exception e) { |
mk.log("err in watchdog:"); |
mk.log(e.toString()); |
} |
} |
// mk.log("watchdog quit"); |
} |
} |
/DUBwise/tags/v0.51/shared/src/ParamsClass.java |
---|
0,0 → 1,49 |
/************************************************** |
* |
* class representing the Params Structure |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
*************************************************/ |
package org.ligi.ufo; |
public abstract class ParamsClass |
implements MKParamDefinitions |
{ |
public String[] tab_names; |
public String[][] field_names; |
public int[][] field_positions; |
public int[][] field_types; |
public String[][] choice_strings; |
abstract public int get_field_from_act(int pos); |
abstract public void set_field_from_act(int pos,int val); |
public void field_from_act_add(int pos,int val) |
{ |
set_field_from_act(pos , get_field_from_act(pos)+val); |
} |
public void field_from_act_add_mod(int pos,int val,int mod) |
{ |
int res=(get_field_from_act(pos)+val)%mod; |
if ( (res)<0) res=mod-1; |
set_field_from_act(pos , res); |
} |
public void field_from_act_xor(int pos,int val) |
{ |
set_field_from_act(pos , get_field_from_act(pos)^val); |
} |
} |
/DUBwise/tags/v0.51/shared/src/UFOProber.java |
---|
0,0 → 1,161 |
/********************************************************************************** |
* |
* Probe which type of UFO we talk to |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
* |
**********************************************************************************/ |
package org.ligi.ufo; |
//#ifdef j2me |
//# import javax.microedition.io.*; |
//#endif |
import java.io.*; |
public class UFOProber |
{ |
public final static int PROBE_RESULT_NONE =0; |
public final static int PROBE_RESULT_INCOMPATIBLE =1; |
public final static int PROBE_RESULT_MK =2; |
public final static int PROBE_RESULT_NG =3; |
public final static int PROBE_RESULT_NAVCTRL =4; |
public final static int PROBE_RESULT_MK3MAG =5; |
public boolean change_notify=false; |
public String[] extended_names= { "No Device" , "Inkompatible Device","MK-Connection" , "NG-Connection" , "NavCtrl-Connection","MK3Mag Connection" }; |
public int probe_result=PROBE_RESULT_NONE; |
public void set_to(int _probe_result) |
{ |
if (_probe_result!=probe_result) |
{ |
probe_result=_probe_result; |
change_notify=true; |
} |
} |
public void set_to_navi() |
{ |
set_to(PROBE_RESULT_NAVCTRL); |
} |
public void set_to_mk3mag() |
{ |
set_to(PROBE_RESULT_MK3MAG); |
} |
public void set_to_mk() |
{ |
set_to(PROBE_RESULT_MK); |
} |
public void set_to_none() |
{ |
set_to(PROBE_RESULT_NONE); |
} |
public void set_to_incompatible() |
{ |
set_to(PROBE_RESULT_INCOMPATIBLE); |
} |
public boolean is_navi() |
{ |
return (probe_result==PROBE_RESULT_NAVCTRL); |
} |
public boolean is_mk() |
{ |
return (probe_result==PROBE_RESULT_MK); |
} |
public boolean is_mk3mag() |
{ |
return (probe_result==PROBE_RESULT_MK3MAG); |
} |
public boolean is_incompatible() |
{ |
return (probe_result==PROBE_RESULT_INCOMPATIBLE); |
} |
public String extended_name() |
{ |
return extended_names[probe_result]; |
} |
String reply=""; |
public boolean probe_error=false; |
// j2me |
// private javax.microedition.io.StreamConnection connection; |
// ej2me |
// private java.io.InputStream reader; |
//private java.io.OutputStream writer; |
public void bluetooth_probe(String url) |
{ |
try{ |
/* |
connection = (StreamConnection) Connector.open(url); |
reader=connection.openInputStream(); |
writer=connection.openOutputStream(); |
String magic="\rmk-mode\r"; |
writer.write(magic.getBytes()); |
writer.flush(); |
*/ |
/* |
int input=0; |
// recieve data-set |
// the 1st line is the echo of the command when ng |
while ((input != 13) &&(input!=-1)) |
{ |
input = reader.read() ; |
reply+=(char)input; |
} |
reply=""; |
input=0; |
while ((input != 13) &&(input!=-1)) |
if (input!=10){ |
input = reader.read() ; |
reply+=(char)input; |
} |
if (reply=="NG here\r") |
probe_result=PROBE_RESULT_NG; |
probe_result=PROBE_RESULT_MK; |
*/ |
// writer.close(); |
// reader.close(); |
// connection.close(); |
} |
catch (Exception ex) |
{ |
probe_error=true; |
} |
} |
} |