-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from core-rocket/mission_interface
ミッションインターフェース基板追加
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |