/[H7]/branches/linux-serial/H7Serial.cpp
ViewVC logotype

Diff of /branches/linux-serial/H7Serial.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 43 by torben, Sun Feb 4 20:11:41 2007 UTC revision 56 by torben, Mon Feb 5 10:24:24 2007 UTC
# Line 1  Line 1 
1  #include "StdAfx.h"  
2  #include ".\h7serial.h"  #include "stdafx.h"
3    
4    #include "H7Serial.h"
5    #include <stdexcept>
6    #include <iostream>
7    
8  CH7Serial::CH7Serial(void)  CH7Serial::CH7Serial(void)
9  : CSlipSerial()  : CSlipSerial()
10  {  {
11  }  }
12    
13  CH7Serial::CH7Serial(char* port, int bitrate)  CH7Serial::CH7Serial(char* port, Baudrate bitrate)
14  : CSlipSerial(port, bitrate)  : CSlipSerial(port, bitrate)
15  {  {
16  }  }
# Line 17  CH7Serial::~CH7Serial(void) Line 21  CH7Serial::~CH7Serial(void)
21    
22  short CH7Serial::readTarget(unsigned char target)  short CH7Serial::readTarget(unsigned char target)
23  {  {
24            using namespace std;
25          short retval;          short retval;
26          unsigned char frame[1];          unsigned char frame[1];
27          unsigned char hi_target = (target & 0x0F) << 4;          unsigned char hi_target = (target & 0x0F) << 4;
# Line 27  short CH7Serial::readTarget(unsigned cha Line 32  short CH7Serial::readTarget(unsigned cha
32          std::vector<unsigned char> answer = readFrame();          std::vector<unsigned char> answer = readFrame();
33    
34          if (answer.size() == 0)          if (answer.size() == 0)
35                  throw std::exception("No reply");                  throw std::runtime_error("No reply");
36    
37          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK
38                  throw std::exception("Request not acknowledged");                  throw std::runtime_error("Request not acknowledged");
39    
40          if ( (answer[0] & 0xF0) != hi_target)          if ( (answer[0] & 0xF0) != hi_target)
41                  throw std::exception("Incorrect reply");                  throw std::runtime_error("Incorrect reply");
42    
43          if (answer.size() == 2)          if (answer.size() == 2)
44                  retval = answer[1];                  retval = answer[1];
# Line 47  short CH7Serial::readTarget(unsigned cha Line 52  short CH7Serial::readTarget(unsigned cha
52    
53  void CH7Serial::writeTarget(unsigned char target, unsigned char data)  void CH7Serial::writeTarget(unsigned char target, unsigned char data)
54  {  {
55            using namespace std;
56          unsigned char frame[2];          unsigned char frame[2];
57          unsigned char hi_target = (target & 0x0F) << 4;          unsigned char hi_target = (target & 0x0F) << 4;
58          frame[0] = hi_target | 0x01;          frame[0] = hi_target | 0x01;
# Line 55  void CH7Serial::writeTarget(unsigned cha Line 61  void CH7Serial::writeTarget(unsigned cha
61          writeFrame(frame,2);          writeFrame(frame,2);
62          Sleep(50); //be nice and wait a little          Sleep(50); //be nice and wait a little
63          std::vector<unsigned char> answer = readFrame();          std::vector<unsigned char> answer = readFrame();
64            
65          if (answer.size() == 0)          if (answer.size() == 0)
66                  throw std::exception("No reply");                  throw std::runtime_error("No reply");
67    
68          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK
69                  throw std::exception("Request not acknowledged");                  throw std::runtime_error("Request not acknowledged");
70    
71          if ( (answer[0] & 0xF0) != hi_target)          if ( (answer[0] & 0xF0) != hi_target)
72                  throw std::exception("Incorrect reply");                  throw std::runtime_error("Incorrect reply");
73  }  }
74    
75    

Legend:
Removed from v.43  
changed lines
  Added in v.56

  ViewVC Help
Powered by ViewVC 1.1.20