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
}
arduinocmd() {
mendel_cmd() {
(
IFS=$' \t\n'
LN=0
cmd="$*"
echo "$cmd" >&3;
while [ "$REPLY" != "OK" ]
do
read -u 3
if [ "$LN" -ne 0 ]
then
# if [ "$LN" -ne 0 ]
# then
if [ "$REPLY" != "OK" ]
then
echo "$REPLY"
fi
fi
# fi
LN=$(( $LN + 1 ))
done
) 3<>/dev/arduino;
}
readsym() {
sym=$1
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)
while [ $SIZE -gt 0 ]
mendel_cmd_hr() {
(
IFS=$' \t\n'
LN=0
cmd="$*"
echo "$cmd" >&3;
echo "> $cmd"
while [ "$REPLY" != "OK" ]
do
echo -n $(arduinocmd "M253 S"$ADDR)
ADDR=$(( $ADDR + 1 ))
SIZE=$(( $SIZE - 1 ))
read -u 3
# if [ "$LN" -ne 0 ]
# then
echo "< $REPLY"
# fi
LN=$(( $LN + 1 ))
done
echo
else
echo "unknown symbol: $sym"
fi
) 3<>/dev/arduino;
}
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
val=$(readsym $sym)
val=$(mendel_readsym $sym)
perl -e 'printf "%u\n", eval "0x".$ARGV[0]' $val
}
readsym_int8() {
mendel_readsym_int8() {
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
}
readsym_uint16() {
mendel_readsym_uint16() {
sym=$1
val=$(readsym $sym)
val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%u\n", eval "0x$2$1"' $val
}
readsym_int16() {
mendel_readsym_int16() {
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
}
readsym_uint32() {
mendel_readsym_uint32() {
sym=$1
val=$(readsym $sym)
val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%u\n", eval "0x$4$3$2$1"' $val
}
readsym_int32() {
mendel_readsym_int32() {
sym=$1
val=$(readsym $sym)
val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%d\n", eval "0x$4$3$2$1"' $val
}
readsym_target() {
mendel_readsym_target() {
sym=$1
val=$(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
val=$(mendel_readsym "$sym")
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() {
val=$(readsym movebuffer)
mbhead=$(readsym mb_head)
mbtail=$(readsym mb_tail)
mendel_readsym_mb() {
val=$(mendel_readsym movebuffer)
mbhead=$(mendel_readsym mb_head)
mbtail=$(mendel_readsym mb_tail)
perl - <<'ENDPERL' -- $val $mbhead $mbtail
$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/;
@ -203,4 +242,4 @@ readsym_mb() {
}
printf "\n}\n";
ENDPERL
}
}

View File

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