00001
00009
00010
00011 #ifndef Mio_h
00012 #define Mio_h
00013
00014 #include "MioComm.h"
00015
00016
00036 class Mio
00037 {
00038
00039 public:
00040
00041
00045 Mio(
00046 );
00047
00051 virtual ~Mio(
00052 );
00053
00066 void SetReceiveTimeout(
00067 unsigned timeout_ms
00069 )
00070 {
00071 m_TimeoutMs = timeout_ms;
00072 }
00073
00081 unsigned GetReceiveTimeout(
00082 ) const
00083 {
00084 return m_TimeoutMs;
00085 }
00086
00096 void SetDrainTime(
00097 unsigned drain_time_ms
00099 )
00100 {
00101 m_DrainTimeMs = drain_time_ms;
00102 }
00103
00111 unsigned GetDrainTime(
00112 ) const
00113 {
00114 return m_DrainTimeMs;
00115 }
00116
00122 virtual const char * ResultCodeToText(
00123 Mio_Rc rc
00125 ) const;
00126
00135 Mio_Rc Reset(
00136 );
00137
00146 Mio_Rc Loopback(
00147 void * out_data,
00149 int & out_data_len,
00151 const void * in_data,
00153 int in_data_len
00155 );
00156
00174 Mio_Rc SetMioPortsModes(
00175 const Mio_PortMode * modes,
00177 const unsigned char * params,
00180 const Mio_Port * ports,
00182 int num_ports
00184 );
00185
00193 Mio_Rc SetMioPortMode(
00194 Mio_PortMode mode,
00196 unsigned char param,
00198 Mio_Port port
00200 )
00201 {
00202 return SetMioPortsModes(&mode, ¶m, &port, 1);
00203 }
00204
00210 Mio_Rc GetMioPortsModes(
00211 Mio_PortMode * modes,
00213 unsigned char * params,
00215 const Mio_Port * ports,
00217 int num_ports
00219 );
00220
00228 Mio_Rc GetMioPortMode(
00229 Mio_PortMode & mode,
00231 unsigned char & param,
00233 Mio_Port port
00235 )
00236 {
00237 return GetMioPortsModes(&mode, ¶m, &port, 1);
00238 }
00239
00249 Mio_Rc SetDigitalOutputValue(
00250 unsigned char value,
00252 Mio_Port port
00254 );
00255
00266 Mio_Rc GetDigitalInputValue(
00267 unsigned char & value,
00269 Mio_Port port
00271 );
00272
00291 Mio_Rc SetDigitalOutputsValues(
00292 const unsigned char * values,
00294 const Mio_Port * ports,
00296 int num_ports
00298 );
00299
00316 Mio_Rc GetDigitalInputsValues(
00317 unsigned char * values,
00319 const Mio_Port * ports,
00321 int num_ports
00323 );
00324
00340 Mio_Rc GetAnalogInputsValues(
00341 int * values,
00343 const Mio_Port * ports,
00345 int num_ports
00347 );
00348
00356 Mio_Rc GetAnalogInputValue(
00357 int & value,
00359 Mio_Port port
00361 )
00362 {
00363 return GetAnalogInputsValues(&value, &port, 1);
00364 }
00365
00385 Mio_Rc StartDS18x20Task(
00386 int task_id,
00388 Mio_Port mio_port,
00390 Mio_DS18x20Type sensor_type,
00392 unsigned conversion_time_x100ms
00394 );
00395
00404 Mio_Rc GetDS18x20TaskTemperature(
00405 int & temperature,
00407 unsigned char & sn,
00409 Mio_DS18x20Error & error,
00411 int task_id
00413 );
00414
00423 Mio_Rc StopTask(
00424 int task_id
00426 );
00427
00431 struct PWMOutSubchannelConfig
00432 {
00440 int config;
00441
00446 int width;
00447 };
00448
00454 struct PWMOutSubchannelConfig2
00455 {
00464 int config;
00465
00467 float duty;
00468 };
00469
00475 static Mio_Rc ConvertPWMOutValues(
00476 Mio_PWMClockSpeed & pwm_clock_speed,
00478 int & pwm_period,
00480 PWMOutSubchannelConfig dst_subchannels[3],
00482 float pwm_frequency,
00484 const PWMOutSubchannelConfig2 src_subchannels[3]
00486 );
00487
00516 Mio_Rc StartPWMOut(
00517 int pwm_clock_channel,
00519 Mio_PWMClockSpeed pwm_clock_speed,
00521 int pwm_period,
00523 const PWMOutSubchannelConfig subchannels[3]
00525 );
00526
00555 Mio_Rc StartPWMOut(
00556 int pwm_clock_channel,
00558 float pwm_frequency,
00560 const PWMOutSubchannelConfig2 subchannels[3]
00562 );
00563
00575 Mio_Rc AdjustPWMOut(
00576 int pwm_clock_channel,
00578 Mio_PWMClockSpeed pwm_clock_speed,
00580 int pwm_period,
00582 const PWMOutSubchannelConfig subchannels[3]
00584 );
00585
00597 Mio_Rc AdjustPWMOut(
00598 int pwm_clock_channel,
00600 float pwm_frequency,
00602 const PWMOutSubchannelConfig2 subchannels[3]
00604 );
00605
00606
00610 struct PWMInSubchannelConfig
00611 {
00620 int config;
00621
00627 int edges;
00628 };
00629
00669 Mio_Rc StartPWMIn(
00670 int pwm_clock_channel,
00672 const PWMInSubchannelConfig subchannels[4]
00674 );
00675
00688 Mio_Rc SetPWMInMode(
00689 int pwm_clock_channel,
00691 int pwm_subchannel,
00693 Mio_PWMInMode mode
00695 );
00696
00725 Mio_Rc GetPWMInResult(
00726 unsigned & total_halfperiod_time,
00728 unsigned & total_period_time,
00730 int & edges_captured,
00732 int pwm_clock_channel,
00734 int pwm_subchannel
00736 );
00737
00745 Mio_Rc StopPWM(
00746 int pwm_clock_channel
00748 );
00749
00750
00751 protected:
00752
00753
00763 virtual Mio_Rc ResetCommunicationPort(
00764 ) = 0;
00765
00774 virtual Mio_Rc SendRawDataToMio(
00775 const void * data,
00777 int data_len
00779 ) = 0;
00780
00802 virtual Mio_Rc ReceiveRawDataFromMio(
00803 void * data,
00805 int data_len,
00807 int & data_bytes_received,
00809 unsigned timeout_ms
00811 ) = 0;
00812
00821 virtual unsigned GetCurrentTimeMs(
00822 ) = 0;
00823
00835 virtual unsigned GetElapsedTimeMs(
00836 unsigned start_time
00838 ) = 0;
00839
00848 virtual void DispatchOutOfBandMessage(
00849 Mio_MioMsgId msg_id,
00851 int payload_len,
00853 const void * payload
00855 )
00856 {
00857
00858 }
00859
00860
00861 private:
00862
00863
00872 static bool CorrectableWithRetransmission(
00873 Mio_Rc rc
00875 );
00876
00880 void DrainBadMessage(
00881 );
00882
00888 Mio_Rc SendMessage(
00889 Mio_HostMsgId msg_id,
00891 const void * payload,
00893 int payload_len
00895 );
00896
00902 Mio_Rc ReceiveMessage(
00903 Mio_MioMsgId & msg_id,
00905 bool & out_of_band,
00907 int & payload_len,
00909 void * payload,
00911 unsigned timeout_ms
00913 );
00914
00923 Mio_Rc ReceiveSpecificMessage(
00924 Mio_MioMsgId msg_id,
00926 int & payload_len,
00928 void * payload
00930 );
00931
00941 Mio_Rc ReceiveSpecificMessage(
00942 Mio_MioMsgId msg_id,
00944 void * payload = 0,
00946 int payload_len = 0
00948 );
00949
00961 Mio_Rc SendAndReceiveSpecificMessage(
00962 Mio_HostMsgId send_msg_id,
00964 const void * send_payload,
00966 int send_payload_len,
00968 Mio_MioMsgId receive_msg_id,
00970 int & received_payload_len,
00972 void * received_payload
00974 );
00975
00988 Mio_Rc SendAndReceiveSpecificMessage(
00989 Mio_HostMsgId send_msg_id,
00991 const void * send_payload,
00993 int send_payload_len,
00995 Mio_MioMsgId receive_msg_id,
00997 void * received_payload = 0,
00999 int receive_payload_len = 0
01001 );
01002
01008 Mio_Rc StartTask(
01009 int task_id,
01011 Mio_TaskType task_type,
01013 const void * task_config,
01015 int task_config_len
01017 );
01018
01019
01021 unsigned m_TimeoutMs;
01022
01024 unsigned m_DrainTimeMs;
01025
01026 };
01027
01028
01029 #endif // Mio_h
01030