Skip to content

Commit

Permalink
mif
Browse files Browse the repository at this point in the history
  • Loading branch information
771-8bit committed Feb 24, 2024
1 parent c364b6a commit 9ea15f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
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 @@ -340,6 +345,13 @@ void loop() {
if (uplink == "valve-check") {
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) {
Expand Down
46 changes: 27 additions & 19 deletions MissionInterface/MissionInterface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,60 @@
#include <string.h>
#include <CCP_MCP2515.h>

#define CAN_INT D1
#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
char str_buf[7]; // 6+\0

void setup()
{
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, HIGH);
digitalWrite(MISSION_POWER, LOW);

Serial1.begin(115200);
while (Serial1.available()) {
Serial1.read();
}

// CAN
CCP.begin();
}

void loop()
{
if (!digitalRead(CAN_INT)) // データ受信確認
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)
{
if (CCP.id < 0x40) {
CCP.string(str_buf, 7);
sprintf(msgString, "%d,ID,%03x,time,%d000,string,%s,,,,", millis(), CCP.id, CCP.time16(), str_buf);
}
else if (CCP.id < 0x80)
{
} else if (CCP.id < 0x80) {
sprintf(msgString, "%d,ID,%03x,time,%lu,uint32,%lu,,,,", millis(), CCP.id, CCP.time32(), CCP.data_uint32());
}
else if (CCP.id < 0xC0)
{
} else if (CCP.id < 0xC0) {
sprintf(msgString, "%d,ID,%03x,time,%lu,float,%8.2f,,,,", millis(), CCP.id, CCP.time32(), CCP.data_float());
}
else
{
} else {
sprintf(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);
Expand Down

0 comments on commit 9ea15f2

Please sign in to comment.