Commit c7829100 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Write first checks port existence then check message

parent 0845145f
......@@ -37,10 +37,6 @@ public class WriteCommand : Object, Command
public int execute(string[] args, ApplicationState state)
{
if (args.length == (state.bound_port==null?1:0)) {
return error(Err.NO_MESSAGE);
}
Serial.SerialClient p;
if(state.bound_port == null) {
if(args.length == 0) {
......@@ -54,6 +50,10 @@ public class WriteCommand : Object, Command
p.reload_properties();
}
if (args.length == (state.bound_port==null?1:0)) {
return error(Err.NO_MESSAGE);
}
int start_p = state.bound_port==null?1:0;
// Build buffer
......@@ -71,19 +71,19 @@ public class WriteCommand : Object, Command
if(i < args.length-1)
buffer[pointer++] = (uint8) 0x20;
}
// Find dollars
var dollar_positions = new Array<int>();
for(int i = 0; i < char_count; i++) {
if(buffer[i] == DOLLAR)
dollar_positions.append_val(i);
}
// Check dollar count
if(dollar_positions.length%2 == 1) {
return error(Err.NOT_MATCHING_DOLLAR_COUNT);
}
var ints = new Array<BigInt>();
// Parse ints
for ( int i = 0; i < dollar_positions.length; i+=2 ) {
......@@ -105,7 +105,7 @@ public class WriteCommand : Object, Command
} else {
return error(Err.NOT_NUMBER_BETWEEN_DOLLARS);
}
// Read number
var exponent = new BigInt();
exponent.add_uint8(1);
......@@ -119,11 +119,11 @@ public class WriteCommand : Object, Command
}
ints.append_val(number);
}
var tmp = new uint8[char_count];
uint8 tmp_pointer = 0;
uint8 dollar_pointer = 0;
// Construct final message
for(int buffer_pointer = 0; buffer_pointer < char_count; buffer_pointer++) {
if(buffer[buffer_pointer] == DOLLAR) {
......@@ -136,7 +136,7 @@ public class WriteCommand : Object, Command
tmp[tmp_pointer++] = buffer[buffer_pointer];
}
}
stdout.printf("Writing %lli bytes: \n", tmp_pointer);
// Print back
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment