diff --git a/.github/workflows/arduino_ci.yml b/.github/workflows/arduino_ci.yml index 124485b..5815218 100644 --- a/.github/workflows/arduino_ci.yml +++ b/.github/workflows/arduino_ci.yml @@ -147,6 +147,14 @@ jobs: arch: rp2040 name: seeed_xiao_rp2040 + - sketch-paths: MissionInterface + libraries: | + - + board: + vendor: rp2040 + arch: rp2040 + name: seeed_xiao_rp2040 + include: - code: board: diff --git a/Main/Main.ino b/Main/Main.ino index 470c269..9c29fe3 100644 --- a/Main/Main.ino +++ b/Main/Main.ino @@ -12,6 +12,8 @@ float data_ext_v = 0; bool data_key_sw_active = false; // pinout +const pin_size_t MIF_TX = 2; +const pin_size_t MIF_RX = 3; const pin_size_t BNO_SDA = 4; const pin_size_t BNO_SCL = 5; const pin_size_t VALVE_TX = 6; @@ -73,6 +75,8 @@ MY_OPENER opener(OPENER::SHINSASYO); char valve_mode = '/'; SerialPIO Serial_Valve(VALVE_TX, VALVE_RX, 32); +// MissionInterface +SerialPIO Serial_MIF(MIF_TX, MIF_RX, 256); // setup()ではdelay()使用可 void setup() { @@ -125,6 +129,7 @@ void setup() { Serial_GNSS.begin(9600); Serial_Valve.begin(115200); + Serial_MIF.begin(115200); opener.init(); } @@ -341,6 +346,13 @@ void loop() { Serial_Valve.print("valve-check\n"); } + if (uplink == "mif-on") { + Serial_MIF.print("mif-on\n"); + } + if (uplink == "mif-off") { + Serial_MIF.print("mif-off\n"); + } + float uplink_float = uplink.toFloat(); if (uplink_float != 0) { opener.set_open_threshold_time_ms(uplink_float * 1000); diff --git a/MissionInterface/MissionInterface.ino b/MissionInterface/MissionInterface.ino new file mode 100644 index 0000000..9bda779 --- /dev/null +++ b/MissionInterface/MissionInterface.ino @@ -0,0 +1,63 @@ +#include +#include +#include + +#define CAN_CS D0 +#define CAN_INT D1 +#define MISSION_POWER D3 + +// CAN +CCP_MCP2515 CCP(CAN_CS, CAN_INT); + +// Other +char msgString[128]; +char str_buf[7]; // 6+\0 + +void setup() { + delay(500); + Serial.begin(115200); + pinMode(CAN_CS, OUTPUT); + pinMode(CAN_INT, INPUT); + digitalWrite(CAN_CS, HIGH); + + pinMode(MISSION_POWER, OUTPUT); + digitalWrite(MISSION_POWER, LOW); + + Serial1.begin(115200); + while (Serial1.available()) { + Serial1.read(); + } + + // CAN + CCP.begin(); +} + +void loop() { + while (Serial1.available()) { + String data = Serial1.readStringUntil('\n'); + data.trim(); + + if (data == "mif-on") { + digitalWrite(MISSION_POWER, HIGH); + } + if (data == "mif-off") { + digitalWrite(MISSION_POWER, LOW); + } + } + + if (!digitalRead(CAN_INT)) // データ受信確認 + { + CCP.read_device(); + if (CCP.id < 0x40) { + CCP.string(str_buf, 7); + snprintf(msgString, sizeof(msgString), "%d,ID,%03x,time,%d000,string,%s,,,,", millis(), CCP.id, CCP.time16(), str_buf); + } else if (CCP.id < 0x80) { + snprintf(msgString, sizeof(msgString), "%d,ID,%03x,time,%lu,uint32,%lu,,,,", millis(), CCP.id, CCP.time32(), CCP.data_uint32()); + } else if (CCP.id < 0xC0) { + snprintf(msgString, sizeof(msgString), "%d,ID,%03x,time,%lu,float,%8.2f,,,,", millis(), CCP.id, CCP.time32(), CCP.data_float()); + } else { + snprintf(msgString, sizeof(msgString), "%d,ID,%03x,time,%d000,fp16_0,%8.2f,fp16_1,%8.2f,fp16_2,%8.2f", millis(), CCP.id, CCP.time16(), CCP.data_fp16_0(), CCP.data_fp16_1(), CCP.data_fp16_2()); + } + Serial.println(msgString); + } +}