]> git.tdb.fi Git - model-railway-devices.git/blobdiff - arducontrol/monitor.c
Add functions for sending replies
[model-railway-devices.git] / arducontrol / monitor.c
index 112e1ac56486c2317dce74d189e815de0f6afe83..d8f3dadded7c44b73a3f449985380e04b1f29f0f 100644 (file)
@@ -45,8 +45,7 @@ void monitor_check(void)
                                if(!overcurrent_sent)
                                {
                                        overcurrent_sent = 1;
-                                       serial_write(0xFE);
-                                       serial_write(OVERCURRENT);
+                                       interface_send1(OVERCURRENT);
                                }
                        }
                        else
@@ -66,18 +65,20 @@ void monitor_check(void)
        }
 }
 
-uint8_t monitor_command(void)
+uint8_t monitor_command(const uint8_t *cmd_buf, uint8_t cmd_length)
 {
        if(cmd_buf[0]==READ_TRACK_CURRENT)
        {
+               uint8_t reply[3];
+
                if(cmd_length!=1)
                        return LENGTH_ERROR;
 
-               serial_write(0xFC);
-               serial_write(TRACK_CURRENT);
                uint16_t value = track_current_milliamps();
-               serial_write(value>>8);
-               serial_write(value);
+               reply[0] = TRACK_CURRENT;
+               reply[1] = value>>8;
+               reply[2] = value;
+               interface_send(reply, sizeof(reply));
        }
        else if(cmd_buf[0]==SET_OVERCURRENT_LIMIT)
        {
@@ -95,14 +96,16 @@ uint8_t monitor_command(void)
        }
        else if(cmd_buf[0]==READ_INPUT_VOLTAGE)
        {
+               uint8_t reply[3];
+
                if(cmd_length!=1)
                        return LENGTH_ERROR;
 
-               serial_write(0xFC);
-               serial_write(INPUT_VOLTAGE);
                uint16_t value = input_voltage_millivolts();
-               serial_write(value>>8);
-               serial_write(value);
+               reply[0] = INPUT_VOLTAGE;
+               reply[1] = value>>8;
+               reply[2] = value;
+               interface_send(reply, sizeof(reply));
        }
        else
                return INVALID_COMMAND;