#include "data.h"
-/***************************************************************************** */
-/* USB Uart */
+/***************************************************************************** */
volatile uint8_t usb_logs = 0;
-volatile uint8_t usb_send_config = 0;
+/* Start with a "request" to send actual config and version */
+volatile uint8_t send_config = 2;
+volatile uint8_t send_info = 2;
enum comm_states {
Idle = 0, /* Waiting for next command */
Config, /* Received config command, receiving configuration */
};
-/* Rx interrupt handler for system configuration over USB */
-void config_rx(uint8_t c)
-{
- static uint8_t comm_state = 0;
- if (comm_state == Command) {
+/***************************************************************************** */
+/* Rx command handling */
+/* Note that this is an interrupt handler, do NEVER try to send a reply in here */
+void command_handler(uint8_t c, uint8_t* comm_state, uint8_t uart)
+{
+ if (*comm_state == Command) {
/* Handle command value */
- comm_state = Idle;
+ *comm_state = Idle;
return;
}
- if (comm_state == Config) {
+ if (*comm_state == Config) {
/* Receive new config */
/* Check received config checksum */
/* If config received, burn to flash and reset */
- comm_state = Idle;
+ *comm_state = Idle;
return;
}
break;
/* Enter command mode */
case 'a':
- comm_state = Command;
+ *comm_state = Command;
break;
/* Enter config mode */
case 'C':
- comm_state = Config;
+ *comm_state = Config;
break;
/* Get config */
case 'g':
- usb_send_config = 1;
+ send_config = (1 + uart);
+ break;
+ /* Get module info */
+ case 'i':
+ send_info = (1 + uart);
break;
default:
}
}
+/***************************************************************************** */
+/* USB Uart */
+
+/* Rx interrupt handler for system configuration over USB */
+void config_rx(uint8_t c)
+{
+ static uint8_t usb_comm_state = 0;
+ command_handler(c, &usb_comm_state, UART0);
+}
+
/***************************************************************************** */
/* Communication with slave modules over UART1 */
/* Rx interrupt handler */
void comm_rx(uint8_t c)
{
+ static uint8_t ext_comm_state = 0;
+ command_handler(c, &ext_comm_state, UART1);
}
/***************************************************************************** */
extern volatile uint8_t usb_logs;
-extern volatile uint8_t usb_send_config;
+extern volatile uint8_t send_config;
+extern volatile uint8_t send_info;
+
+
+/***************************************************************************** */
+/* Communication over UART0 to USB bridge */
/* Rx interrupt handler for system configuration over USB */
void config_rx(uint8_t c);
/***************************************************************************** */
/* Communication with slave modules over UART1 */
-
/* Rx interrupt handler */
void comm_rx(uint8_t c);
-
void comm_tx(struct scialys_data* data);
* manual_force_type :
* type of termination condition for manual force mode (temp, time, both (first))
* never_force :
- *
+ * if set to 1, prevent entering manual and automatic forced modes
*/
#define CONFIG_OK 0x4F4B /* "OK" in ASCII */
#define CONFIG_VERSION 0x02
#include "version.h"
#include "time.h"
#include "param.h"
+#include "comm.h"
/***************************************************************************** */
/* Buttons inputs on front panel */
} else {
/* Config mode. Mode entered by button action, which implies that interface board is present. */
interface_mode = config_interface_handle();
+ if (interface_mode == MODE_RUN) {
+ /* Exiting config mode : send new config to external communication module */
+ send_config = 2;
+ }
}
/* Update Oled display */
ssd130x_display_full_screen(&display);
#include "data.h"
#include "comm.h"
#include "uSD.h"
+#include "version.h"
#define MODULE_VERSION 0x0A
msg = NULL;
}
}
- if (usb_send_config == 1) {
+ if (send_config != 0) {
char* conf = (char*)&sc_conf;
- serial_write(UART0, "@", 1);
- serial_write(UART0, conf, sizeof(struct scialys_config));
- usb_send_config = 0;
+ uint32_t uart_num = UART0;
+ if (send_config == 2) { /* Send on UART 1 (communication to extention module) */
+ uart_num = UART1;
+ }
+ serial_write(uart_num, "@", 1);
+ serial_write(uart_num, conf, sizeof(struct scialys_config));
+ send_config = 0;
+ }
+ if (send_info != 0) {
+ #define VERSION_BUF_LEN 16
+ char version[VERSION_BUF_LEN] = "& " MODULE_VERSION_STR "-" SOFT_VERSION_STR "." COMPILE_VERSION;
+ uint32_t uart_num = UART0;
+ uint8_t i = 0, sum = 0;
+ if (send_info == 2) { /* Send on UART 1 (communication to extention module) */
+ uart_num = UART1;
+ }
+ for (i = 2; i < VERSION_BUF_LEN; i++) {
+ sum += (uint8_t)version[i];
+ }
+ version[1] = (char)sum;
+ serial_write(uart_num, version, VERSION_BUF_LEN);
+ send_info = 0;
}
}
return 0;
-#define MODULE_VERSION_STR "v1.0"
-#define SOFT_VERSION_STR "P"
-#define COMPILE_VERSION "04"
+#define MODULE_VERSION_STR "v1.0" /* Can be up to 5 chars : "v1.01" */
+#define SOFT_VERSION_STR "T" /* One letter : P : Production - T : Test */
+#define COMPILE_VERSION "06" /* Two digits */