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.
goto_serial.hpp
00001 #ifndef _52SERIAL 00002 #define _52SERIAL 00003 00004 #include "mbed.h" 00005 #include "Buffer52.hpp" 00006 /* 00007 使用方法 00008 ARRC::gotoSerial ser(PC_12,PD_2,9600); 00009 DigitalOut rede(PH_1); 00010 送信側 rede = 1; 00011 受信側 rede = 0; 00012 00013 publish(id,送信する値,INT or FLOAT or FUNC(送信する型の指定)); 00014 INT,FLOAT 送信と受信でなるべく合わせること。 00015 FUNC 受信側で設定した関数に値を引数として送信する。 00016 subscribe(id,変数または関数のポインタ(例 &value , func)); 00017 00018 受信側の関数(scrp_slaveでいうところのコマンド)の宣言方法 00019 00020 void func(Pack data){ 00021 printf("subscribed_int:%d\n",data.integer); 00022 printf("subscribed_float:%d\n",data.decimal); 00023 led = !led; 00024 } 00025 ToDo 00026 redeを組み込む 00027 送受信可能にする 00028 */ 00029 00030 namespace ARRC{ 00031 00032 const unsigned STARTDATA = 0x01; 00033 const unsigned ENDDATA = 0x09; 00034 const unsigned INT = 1; 00035 const unsigned FLOAT = 2; 00036 const unsigned FUNC = 3; 00037 00038 typedef union { 00039 float decimal; 00040 int integer; 00041 } Pack; 00042 00043 typedef void (*Func)(Pack data); 00044 00045 typedef union { 00046 float* decimal; 00047 int* integer; 00048 } DATA; 00049 00050 class gotoSerial{ 00051 public: 00052 gotoSerial(PinName tx,PinName rx,int baudrate); 00053 bool publish(unsigned id,int num,unsigned type); 00054 bool publish(unsigned id,float num,unsigned type); 00055 bool subscribe(unsigned id,int* var); 00056 bool subscribe(unsigned id,float* var); 00057 bool subscribe(unsigned id,Func func); 00058 private: 00059 void interrupt_read(); 00060 bool update(); 00061 int sub_vars_size; 00062 std::vector<DATA> sub_vars; 00063 std::vector<Func> sub_funcs; 00064 Buffer<int8_t> buf; 00065 Serial ser; 00066 }; 00067 00068 } 00069 00070 #endif
Generated on Sat Jul 23 2022 18:03:05 by
1.7.2