Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 218 → Rev 219

/DUBwise/trunk/shared/src/DUBwiseDefinitions.java
10,6 → 10,7
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;
19,4 → 20,33
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/trunk/shared/src/MKCommunicator.java
27,11 → 27,13
 
 
public class MKCommunicator
implements Runnable
implements Runnable,DUBwiseDefinitions
{
public byte bl_retrys=0;
public boolean init_bootloader=false;
 
public byte lib_version_major=0;
public byte lib_version_minor=1;
public byte lib_version_minor=3;
 
public String lib_version_str()
{
97,7 → 99,8
}
 
public int CRC16(int ch, int crc)
{ return crc16_table[((crc >> 8) ^ (ch)) & 0xFF] ^ (crc << 8);
{
return crc16_table[((crc >> 8) ^ (ch)) & 0xFF] ^ (crc << 8);
}
 
 
108,15 → 111,17
else
return 0;
}
public final static int BOOTLOADER_STAGE_NONE=0;
public final static int BOOTLOADER_STAGE_GOT_MKBL=1;
public final static byte BOOTLOADER_STAGE_NONE=0;
public final static byte BOOTLOADER_STAGE_GOT_MKBL=1;
 
int bootloader_stage= BOOTLOADER_STAGE_NONE;
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;
178,6 → 183,10
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();
355,11 → 364,19
send_command(FC_SLAVE_ADDR,'t',params);
}
 
public void send_keys(int[] params)
 
public void send_extern_control()
{
send_command(FC_SLAVE_ADDR,'k',params);
 
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)
{
457,6 → 474,8
flash_msgs[msg_pos]="attempt "+attempt;
attempt++;
send_command_nocheck((byte)FC_SLAVE_ADDR,'R',new int[0]);
try{
writer.write( 27);
writer.flush();
 
464,7 → 483,8
writer.write( 0xAA);
writer.flush();
 
}
catch (Exception e) { }
sleep((attempt%2==0)?80:800); //800
}
msg_pos++;
563,7 → 583,6
// 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);
612,6 → 631,10
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));
730,7 → 753,7
// Thread to recieve data from Connection
public void run()
{
 
boolean sigfail=false;
if (bootloader_stage==BOOTLOADER_STAGE_GOT_MKBL)
{
try {
740,6 → 763,10
writer.flush();
int avr_sig=reader.read();
 
while (avr_sig==63)
avr_sig=reader.read();
 
flash_msgs[msg_pos++]="got avr sig " + avr_sig;
 
 
747,7 → 774,10
throw new Exception("val after avrsig isnt 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();
784,27 → 814,32
 
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 + "..";
 
flash_msgs[msg_pos++]="Opening firmware ..";
 
 
InputStream in;
try {
in=this.getClass().getResourceAsStream((avr_sig==224)?"/navi.bin":((avr_sig==120)?"mk3.bin":"/fc.bin"));
in=this.getClass().getResourceAsStream(firmware_filename);
}
catch (Exception e) { throw new Exception(" cant open firmware"); }
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 firmware_size= ((int)in.read()<<24) |((int)in.read()<<16) | ((int)in.read()<<8) | ((int)in.read()&0xff) ;
 
flash_msgs[msg_pos++]=".. open with " + firmware_size + "bytes";
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 ..";
828,7 → 863,7
flash_msgs[msg_pos++]="addr set";
 
 
int blocks2write=((firmware_size/send_buff_size));
// int blocks2write=((firmware_size/send_buff_size));
if ((firmware_size%send_buff_size)>0)
blocks2write++;
 
993,9 → 1028,11
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);
}
 
/DUBwise/trunk/shared/src/MKStatistics.java
9,8 → 9,6
 
package org.ligi.ufo;
 
 
 
public class MKStatistics
 
{
19,6 → 17,8
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;
28,6 → 28,7
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;
38,7 → 39,9
// 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()
{
 
/DUBwise/trunk/shared/src/MKWatchDog.java
34,10 → 34,25
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=40;
public final static int BASE_SLEEP=10;
//#endif
 
public void run()
45,22 → 60,22
mk.log("starting Watchdog");
// get all params
int act_debug_name=0;
int sleeper=BASE_SLEEP;
// int sleeper=BASE_SLEEP;
while(true)
{
try {
Thread.sleep(sleeper);
sleeper=BASE_SLEEP;
Thread.sleep(BASE_SLEEP);
// sleeper=BASE_SLEEP;
if (mk.connected&&(!mk.force_disconnect))
{
 
mk.log("watchdog pre main loop");
/* if (mk.root.canvas.init_bootloader)
if (mk.init_bootloader)
{
mk.jump_bootloader();
mk.root.canvas.init_bootloader=false;
mk.init_bootloader=false;
}
else */if ( mk.version.major==-1 )
else if ( mk.version.major==-1 )
mk.get_version();
else if (mk.ufo_prober.is_navi()&&(mk.error_str==null))
mk.get_error_str();
68,7 → 83,8
else if (mk.ufo_prober.is_mk()&&(mk.params.last_parsed_paramset==-1))
{
mk.get_params(0xFF-1);
sleeper+=150;
Thread.sleep(150);
 
act_paramset=0; // warning - if dropped problem
}
else switch (mk.user_intent)
126,26 → 142,21
break;
 
case USER_INTENT_RCDATA:
if ( resend_check(mk.stats.stick_data_count) )
mk.trigger_rcdata();
sleeper+=250;
break;
case USER_INTENT_EXTERNAL_CONTROL:
if (resend_check(mk.stats.external_control_confirm_frame_count))
mk.send_extern_control();
 
break;
 
case USER_INTENT_LCD:
if (resend_timeout==0)
{
if (resend_check(mk.stats.lcd_data_count))
mk.LCD.trigger_LCD();
resend_timeout=50;
}
if ( last_count!=mk.stats.lcd_data_count)
{
mk.LCD.trigger_LCD();
resend_timeout=50;
}
else
resend_timeout--;
//sleeper +=250;
break;
 
default: