Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ミッションインターフェース基板追加 #22

Merged
merged 5 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions Main/Main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -125,6 +129,7 @@ void setup() {

Serial_GNSS.begin(9600);
Serial_Valve.begin(115200);
Serial_MIF.begin(115200);

opener.init();
}
Expand Down Expand Up @@ -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);
Expand Down
63 changes: 63 additions & 0 deletions MissionInterface/MissionInterface.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <SPI.h>
#include <string.h>
#include <CCP_MCP2515.h>

#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);
}
}
Loading