time to save, updated M253 read memory to accept a length, updated utility functions

This commit is contained in:
Michael Moon 2010-03-14 09:54:55 +11:00
parent ee4e71da1a
commit 2182d7b77a
2 changed files with 128 additions and 50 deletions

View File

@ -88,93 +88,132 @@
# } # }
mendel_setup() {
stty 115200 raw ignbrk -hup -echo ixon ixoff < /dev/arduino
}
mendel_cmd() {
arduinocmd() {
( (
IFS=$' \t\n'
LN=0 LN=0
cmd="$*" cmd="$*"
echo "$cmd" >&3; echo "$cmd" >&3;
while [ "$REPLY" != "OK" ] while [ "$REPLY" != "OK" ]
do do
read -u 3 read -u 3
if [ "$LN" -ne 0 ] # if [ "$LN" -ne 0 ]
then # then
if [ "$REPLY" != "OK" ] if [ "$REPLY" != "OK" ]
then then
echo "$REPLY" echo "$REPLY"
fi fi
fi # fi
LN=$(( $LN + 1 )) LN=$(( $LN + 1 ))
done done
) 3<>/dev/arduino; ) 3<>/dev/arduino;
} }
readsym() { mendel_cmd_hr() {
sym=$1 (
make mendel.sym &>/dev/null IFS=$' \t\n'
if egrep -q '\b'$sym'\b' mendel.sym LN=0
then cmd="$*"
ADDR=$(( $(egrep '\b'$sym'\b' mendel.sym | cut -d\ -f1) )) echo "$cmd" >&3;
SIZE=$(egrep '\b'$sym'\b' mendel.sym | cut -d+ -f2) echo "> $cmd"
while [ $SIZE -gt 0 ] while [ "$REPLY" != "OK" ]
do do
echo -n $(arduinocmd "M253 S"$ADDR) read -u 3
ADDR=$(( $ADDR + 1 )) # if [ "$LN" -ne 0 ]
SIZE=$(( $SIZE - 1 )) # then
echo "< $REPLY"
# fi
LN=$(( $LN + 1 ))
done done
echo ) 3<>/dev/arduino;
else
echo "unknown symbol: $sym"
fi
} }
readsym_uint8() { mendel_print() {
( IFS=$'\n'
for F in "$@"
do
for L in $(< $F)
do
mendel_cmd_hr "$L"
done
done
)
}
mendel_readsym() {
(
IFS=$' \t\n'
sym=$1
if [ -n "$sym" ]
then
make mendel.sym &>/dev/null
if egrep -q '\b'$sym'\b' mendel.sym
then
ADDR=$(( $(egrep '\b'$sym'\b' mendel.sym | cut -d\ -f1) ))
SIZE=$(egrep '\b'$sym'\b' mendel.sym | cut -d+ -f2)
mendel_cmd "M253 S$ADDR P$SIZE"
else
echo "unknown symbol: $sym"
fi
else
echo "what symbol?" > /dev/fd/2
fi
)
}
mendel_readsym_uint8() {
sym=$1 sym=$1
val=$(readsym $sym) val=$(mendel_readsym $sym)
perl -e 'printf "%u\n", eval "0x".$ARGV[0]' $val perl -e 'printf "%u\n", eval "0x".$ARGV[0]' $val
} }
readsym_int8() { mendel_readsym_int8() {
sym=$1 sym=$1
val=$(readsym $sym) val=$(mendel_readsym $sym)
perl -e 'printf "%d\n", ((eval "0x".$ARGV[0]) & 0x7F) - (((eval "0x".$ARGV[0]) & 0x80)?0x80:0)' $val perl -e 'printf "%d\n", ((eval "0x".$ARGV[0]) & 0x7F) - (((eval "0x".$ARGV[0]) & 0x80)?0x80:0)' $val
} }
readsym_uint16() { mendel_readsym_uint16() {
sym=$1 sym=$1
val=$(readsym $sym) val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%u\n", eval "0x$2$1"' $val perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%u\n", eval "0x$2$1"' $val
} }
readsym_int16() { mendel_readsym_int16() {
sym=$1 sym=$1
val=$(readsym $sym) val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%d\n", ((eval "0x$2$1") & 0x7FFF) - (((eval "0x$2$1") & 0x8000)?0x8000:0)' $val perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%d\n", ((eval "0x$2$1") & 0x7FFF) - (((eval "0x$2$1") & 0x8000)?0x8000:0)' $val
} }
readsym_uint32() { mendel_readsym_uint32() {
sym=$1 sym=$1
val=$(readsym $sym) val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%u\n", eval "0x$4$3$2$1"' $val perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%u\n", eval "0x$4$3$2$1"' $val
} }
readsym_int32() { mendel_readsym_int32() {
sym=$1 sym=$1
val=$(readsym $sym) val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%d\n", eval "0x$4$3$2$1"' $val perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%d\n", eval "0x$4$3$2$1"' $val
} }
readsym_target() { mendel_readsym_target() {
sym=$1 sym=$1
val=$(readsym $sym) val=$(mendel_readsym "$sym")
perl -e '@a = qw/X Y Z E F/; $c = 0; while (length $ARGV[0]) { $ARGV[0] =~ s#^(..)(..)(..)(..)##; printf "%s: %d\n", $a[$c], eval "0x$4$3$2$1"; $c++; }' $val if [ -n "$val" ]
then
perl -e '@a = qw/X Y Z E F/; $c = 0; while (length $ARGV[0]) { $ARGV[0] =~ s#^(..)(..)(..)(..)##; printf "%s: %d\n", $a[$c], eval "0x$4$3$2$1"; $c++; }' "$val"
fi
} }
readsym_mb() { mendel_readsym_mb() {
val=$(readsym movebuffer) val=$(mendel_readsym movebuffer)
mbhead=$(readsym mb_head) mbhead=$(mendel_readsym mb_head)
mbtail=$(readsym mb_tail) mbtail=$(mendel_readsym mb_tail)
perl - <<'ENDPERL' -- $val $mbhead $mbtail perl - <<'ENDPERL' -- $val $mbhead $mbtail
$i = -1; $i = -1;
@a = qw/eX 4 eY 4 eZ 4 eE 4 eF 4 flags 9 dX 12 dY 4 dZ 4 dE 4 cX 12 cY 4 cZ 4 cE 4 ts 12 c 12 ec 4 n 4/; @a = qw/eX 4 eY 4 eZ 4 eE 4 eF 4 flags 9 dX 12 dY 4 dZ 4 dE 4 cX 12 cY 4 cZ 4 cE 4 ts 12 c 12 ec 4 n 4/;

View File

@ -15,6 +15,7 @@
uint8_t option_bitfield; uint8_t option_bitfield;
#define OPTION_COMMENT 128 #define OPTION_COMMENT 128
#define OPTION_CHECKSUM 64 #define OPTION_CHECKSUM 64
#define OPTION_ECHO 32
decfloat read_digit; decfloat read_digit;
@ -123,11 +124,13 @@ void scan_char(uint8_t c) {
case 'G': case 'G':
next_target.G = read_digit.mantissa; next_target.G = read_digit.mantissa;
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_uint8(next_target.G); serwrite_uint8(next_target.G);
break; break;
case 'M': case 'M':
next_target.M = read_digit.mantissa; next_target.M = read_digit.mantissa;
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_uint8(next_target.M); serwrite_uint8(next_target.M);
break; break;
case 'X': case 'X':
@ -136,6 +139,7 @@ void scan_char(uint8_t c) {
else else
next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_MM_X, 1); next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_MM_X, 1);
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_int32(next_target.target.X); serwrite_int32(next_target.target.X);
break; break;
case 'Y': case 'Y':
@ -144,6 +148,7 @@ void scan_char(uint8_t c) {
else else
next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_MM_Y, 1); next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_MM_Y, 1);
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_int32(next_target.target.Y); serwrite_int32(next_target.target.Y);
break; break;
case 'Z': case 'Z':
@ -152,6 +157,7 @@ void scan_char(uint8_t c) {
else else
next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_MM_Z, 1); next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_MM_Z, 1);
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_int32(next_target.target.Z); serwrite_int32(next_target.target.Z);
break; break;
case 'E': case 'E':
@ -160,6 +166,7 @@ void scan_char(uint8_t c) {
else else
next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_MM_E, 1); next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_MM_E, 1);
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_uint32(next_target.target.E); serwrite_uint32(next_target.target.E);
break; break;
case 'F': case 'F':
@ -169,6 +176,7 @@ void scan_char(uint8_t c) {
else else
next_target.target.F = decfloat_to_int(&read_digit, 1, 1); next_target.target.F = decfloat_to_int(&read_digit, 1, 1);
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_uint32(next_target.target.F); serwrite_uint32(next_target.target.F);
break; break;
case 'S': case 'S':
@ -183,6 +191,7 @@ void scan_char(uint8_t c) {
else else
next_target.S = decfloat_to_int(&read_digit, 1, 1); next_target.S = decfloat_to_int(&read_digit, 1, 1);
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_uint16(next_target.S); serwrite_uint16(next_target.S);
break; break;
case 'P': case 'P':
@ -192,13 +201,18 @@ void scan_char(uint8_t c) {
else else
next_target.P = decfloat_to_int(&read_digit, 1, 1); next_target.P = decfloat_to_int(&read_digit, 1, 1);
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serwrite_uint16(next_target.P); serwrite_uint16(next_target.P);
break; break;
case 'N': case 'N':
next_target.N = decfloat_to_int(&read_digit, 1, 1); next_target.N = decfloat_to_int(&read_digit, 1, 1);
if (option_bitfield & OPTION_ECHO)
serwrite_uint32(next_target.N);
break; break;
case '*': case '*':
next_target.checksum_read = decfloat_to_int(&read_digit, 1, 1); next_target.checksum_read = decfloat_to_int(&read_digit, 1, 1);
if (option_bitfield & OPTION_ECHO)
serwrite_uint8(next_target.checksum_read);
break; break;
} }
// reset for next field // reset for next field
@ -215,6 +229,7 @@ void scan_char(uint8_t c) {
if (indexof(c, alphabet) >= 0) { if (indexof(c, alphabet) >= 0) {
last_field = c; last_field = c;
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serial_writechar(c); serial_writechar(c);
} }
@ -291,34 +306,41 @@ void scan_char(uint8_t c) {
// end of line // end of line
if ((c == 10) || (c == 13)) { if ((c == 10) || (c == 13)) {
// if (DEBUG) // if (DEBUG)
if (option_bitfield & OPTION_ECHO)
serial_writechar(c); serial_writechar(c);
// process // process
if (next_target.seen_G || next_target.seen_M) { if (next_target.seen_G || next_target.seen_M) {
if ( if (
#ifdef REQUIRE_LINENUMBER #ifdef REQUIRE_LINENUMBER
((next_target.N_expected == next_target.N) && (next_target.seen_N == 1)) && ((next_target.N_expected == next_target.N) && (next_target.seen_N == 1))
#else #else
((next_target.N_expected == next_target.N) || (next_target.seen_N == 0)) && ((next_target.N_expected == next_target.N) || (next_target.seen_N == 0))
#endif #endif
) {
if (
#ifdef REQUIRE_CHECKSUM #ifdef REQUIRE_CHECKSUM
((next_target.checksum_calculated == next_target.checksum_read) && (next_target.seen_checksum == 1)) ((next_target.checksum_calculated == next_target.checksum_read) && (next_target.seen_checksum == 1))
#else #else
((next_target.checksum_calculated == next_target.checksum_read) || (next_target.seen_checksum == 0)) ((next_target.checksum_calculated == next_target.checksum_read) || (next_target.seen_checksum == 0))
#endif #endif
) { ) {
process_gcode_command(&next_target); process_gcode_command(&next_target);
serial_writestr_P(PSTR("OK\n")); serial_writestr_P(PSTR("OK\n"));
// expect next line number // expect next line number
next_target.N_expected++; next_target.N_expected++;
}
else {
serial_writestr_P(PSTR("RESEND: BAD CHECKSUM\n"));
}
} }
else { else {
serial_writestr_P(PSTR("RESEND\n")); serial_writestr_P(PSTR("RESEND: BAD LINE NUMBER\n"));
} }
} }
// reset 'seen comment' and 'receiving checksum' // reset 'seen comment' and 'receiving checksum'
option_bitfield = 0; option_bitfield &= (OPTION_COMMENT | OPTION_CHECKSUM);
// reset variables // reset variables
next_target.seen_X = next_target.seen_Y = next_target.seen_Z = next_target.seen_E = next_target.seen_F = next_target.seen_S = next_target.seen_P = next_target.N = next_target.checksum_read = next_target.checksum_calculated = 0; next_target.seen_X = next_target.seen_Y = next_target.seen_Z = next_target.seen_E = next_target.seen_F = next_target.seen_S = next_target.seen_P = next_target.N = next_target.checksum_read = next_target.checksum_calculated = 0;
@ -567,11 +589,23 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
if (gcmd->seen_S) if (gcmd->seen_S)
d_factor = gcmd->S; d_factor = gcmd->S;
break; break;
// M133- heater I limit
case 133: case 133:
if (gcmd->seen_S) if (gcmd->seen_S)
i_limit = gcmd->S; i_limit = gcmd->S;
break; break;
// M140- echo off
case 140:
option_bitfield &= ~OPTION_ECHO;
serial_writestr_P(PSTR("Echo off\n"));
break;
// M141- echo on
case 141:
option_bitfield |= OPTION_ECHO;
serial_writestr_P(PSTR("Echo on\n"));
break;
// DEBUG: return current position // DEBUG: return current position
case 250: case 250:
serial_writestr_P(PSTR("\n{X:")); serial_writestr_P(PSTR("\n{X:"));
@ -607,7 +641,12 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
// DEBUG: read arbitrary memory location // DEBUG: read arbitrary memory location
case 253: case 253:
serwrite_hex8(*(volatile uint8_t *)(gcmd->S)); if (gcmd->seen_P == 0)
gcmd->P = 1;
for (; gcmd->P; gcmd->P--) {
serwrite_hex8(*(volatile uint8_t *)(gcmd->S));
gcmd->S++;
}
serial_writechar('\n'); serial_writechar('\n');
break; break;