Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 2019_SwitchNode_AR ArmNode 2919_LineSensor 2019_MD ... more
Diff: Mycan.cpp
- Revision:
- 5:4bdeff035517
- Parent:
- 4:7aa2809ad177
- Child:
- 6:9bf1c678d5a4
diff -r 7aa2809ad177 -r 4bdeff035517 Mycan.cpp
--- a/Mycan.cpp Fri Aug 30 03:08:08 2019 +0000
+++ b/Mycan.cpp Sat Aug 31 07:26:26 2019 +0000
@@ -80,3 +80,73 @@
else if (read_type) return decimal_values_storage[rd_id].value[rd_num];
}
+/*
+#include "mbed.h"
+#include "Mycan.h"
+
+Mycan::Mycan(PinName _pin_rd, PinName _pin_td) : can(_pin_rd, _pin_td)
+{
+ min_id = 1;//ここで最小IDを設定
+};
+
+void Mycan::set(unsigned int _id, int _num, float _data)
+{
+ td_id = _id;
+ td_num = _num;
+ data = _data;
+ write_val[td_num] = data;
+ _expressAbsoluteValue();//絶対値にする関数
+}
+
+bool Mycan::send()
+{
+ return can.write(CANMessage(td_id, (char*)&td_data, 8));
+}
+
+void Mycan::read()
+{
+ CANMessage received;
+ can.read(received);
+ rd_data = *(read_can *)received.data;
+ _expressSignVal(received.id);//符号を付与する関数
+}
+
+float Mycan::get(unsigned int _id, int _num)
+{
+ rd_id = _id;
+ rd_num = _num;
+ return read_val[rd_id - min_id][rd_num];
+}
+
+void Mycan::_expressAbsoluteValue()
+{
+ for (int i = 0; i < 2; i++) {
+ td_data.writeVal[i] = write_val[i];
+ }
+
+ write_val[0] = 0;
+ for (int i = 1; i < 8; i++)
+ {
+ if (write_val[i] >= 0)
+ write_val[0] &= ~(1 << i);
+ else
+ write_val[0] |= (1 << i);
+ }
+ td_data.writeVal[0] = write_val[0];
+ for (int i = 1; i < 8; i++) {
+ td_data.writeVal[i] = abs(write_val[i]);
+ }
+}
+
+void Mycan::_expressSignVal(unsigned int id)
+{
+ for(int i = 0; i < 2; i++) {
+ read_val[id - min_id][i] = rd_data.readVal[i];
+ }
+ for (int j = 1; j < 8; j++)
+ {
+ if (read_val[id - min_id][0] & (1 << j))
+ read_val[id - min_id][j] *= -1;
+ }
+}
+*/