]> 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 4adc9377ee5da54a78c5aba88aa3497302f8cd94..d8f3dadded7c44b73a3f449985380e04b1f29f0f 100644 (file)
@@ -1,5 +1,5 @@
 #include "adc.h"
-#include "commands.h"
+#include "interface.h"
 #include "monitor.h"
 #include "output.h"
 #include "serial.h"
@@ -45,8 +45,7 @@ void monitor_check(void)
                                if(!overcurrent_sent)
                                {
                                        overcurrent_sent = 1;
-                                       serial_write(0xFE);
-                                       serial_write(OVERCURRENT);
+                                       interface_send1(OVERCURRENT);
                                }
                        }
                        else
@@ -70,14 +69,16 @@ 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(const uint8_t *cmd_buf, uint8_t cmd_length)
        }
        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;