~jil26/fabathome-model1/FabInterpreter

« back to all changes in this revision

Viewing changes to software/projects/FabStudio v0/Fab@Home Studio/ConfigurePacket.cpp

  • Committer: jil26
  • Date: 2010-03-17 09:27:31 UTC
  • Revision ID: svn-v4:02918aed-e80b-b844-b231-15c4a9332dc2:trunk:7
Added FabStudio v0 to the repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*License Notification
 
2
Fab@Home operates under the BSD Open Source License
 
3
 
 
4
Copyright (c) 2006, Hod Lipson and Evan Malone (evan.malone@cornell.edu) All rights reserved. 
 
5
 
 
6
Redistribution and use in source and binary forms, with or without modification, 
 
7
are permitted provided that the following conditions are met: 
 
8
 
 
9
Redistributions of source code must retain the above copyright notice, 
 
10
this list of conditions and the following disclaimer. 
 
11
Redistributions in binary form must reproduce the above copyright notice, 
 
12
this list of conditions and the following disclaimer in the documentation and/or 
 
13
other materials provided with the distribution. 
 
14
Neither the name of the Fab@Home Project nor the names of its contributors may be 
 
15
used to endorse or promote products derived from this software without specific 
 
16
prior written permission. 
 
17
 
 
18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 
19
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 
21
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 
22
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 
23
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
24
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
25
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 
26
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 
27
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
*/
 
29
 
 
30
#include "StdAfx.h"
 
31
#include ".\configurepacket.h"
 
32
 
 
33
IMPLEMENT_DYNAMIC(CConfigurePacket, CPacket)
 
34
 
 
35
CConfigurePacket::CConfigurePacket(void)
 
36
{
 
37
}
 
38
 
 
39
CConfigurePacket::~CConfigurePacket(void)
 
40
{
 
41
}
 
42
 
 
43
bool CConfigurePacket::InitPacket(BOOL *limSw)
 
44
{
 
45
        //call the base class Init fn FIRST!!!!
 
46
        //it fills in the packet code, so we need to overwrite it afterward
 
47
        if(!CPacket::InitPacket()) return false;
 
48
 
 
49
        //always remember to overwrite the packet type
 
50
        m_enumPktCode = CONFIG;
 
51
 
 
52
        //define which axes and directions have hardware limit switches
 
53
        //should be read in from printer definition file
 
54
        int i = 0;
 
55
        m_hwLimits.flags.X_FWD = limSw[i++];
 
56
        m_hwLimits.flags.X_BKD = limSw[i++];
 
57
        m_hwLimits.flags.Y_FWD = limSw[i++];
 
58
        m_hwLimits.flags.Y_BKD = limSw[i++];
 
59
        m_hwLimits.flags.Z_FWD = limSw[i++];
 
60
        m_hwLimits.flags.Z_BKD = limSw[i++];
 
61
        m_hwLimits.flags.U_FWD = limSw[i++];
 
62
        m_hwLimits.flags.U_BKD = limSw[i++];
 
63
        m_hwLimits.flags.V_FWD = limSw[i++];
 
64
        m_hwLimits.flags.V_BKD = limSw[i++];
 
65
        m_hwLimits.flags.W_FWD = limSw[i++];
 
66
        m_hwLimits.flags.W_BKD = limSw[i++];
 
67
 
 
68
        return true;
 
69
}
 
70
 
 
71
bool CConfigurePacket::PacketToStream(BYTE *buf, unsigned int *size)
 
72
{
 
73
        //convert the packet into a stream of bytes
 
74
        //return a stream of bytes in *buf, and true if successful
 
75
        //*size should pass in the maximum space available in the buffer
 
76
        //and will be used to return the number of bytes written
 
77
        if( (buf == NULL) || (size == NULL) || (*size < m_bytePktSize) )
 
78
                return false;
 
79
 
 
80
        //call the base class PacketToStream to handle the common members
 
81
        unsigned int cnt = *size;
 
82
        if(!CPacket::PacketToStream(buf,&cnt))
 
83
                return false;
 
84
 
 
85
        //now fill in the derived class members
 
86
 
 
87
        //which axes/directions have hardware limit switches?
 
88
        buf[cnt++] = m_hwLimits.data.B.B0;
 
89
        buf[cnt++] = m_hwLimits.data.B.B1;
 
90
 
 
91
        if(cnt > *size) return false;
 
92
        *size = cnt;
 
93
 
 
94
        return true;
 
95
}
 
96
 
 
97
bool CConfigurePacket::StreamToPacket(BYTE *buf, unsigned int *size)
 
98
{
 
99
        //convert a stream of bytes into a packet
 
100
        //read data from *buf as a stream of bytes
 
101
        //*size should pass in the length of the data in the buffer in bytes
 
102
        //and will be used to return the number of bytes read
 
103
        //return true if successful
 
104
        if( (buf == NULL) || (size == NULL) || (*size < m_bytePktSize) )
 
105
                return false;
 
106
 
 
107
        //call the base class StreamToPacket to handle the common members
 
108
        unsigned int cnt = *size;
 
109
        if(!CPacket::StreamToPacket(buf,&cnt))
 
110
                return false;
 
111
 
 
112
        //now fill in the derived class members
 
113
 
 
114
        //which axes/directions have hardware limit switches?
 
115
        m_hwLimits.data.B.B0 = buf[cnt++];
 
116
        m_hwLimits.data.B.B1 = buf[cnt++];
 
117
 
 
118
        if(cnt > *size) return false;
 
119
        *size = cnt;
 
120
 
 
121
        return true;
 
122
}
 
 
b'\\ No newline at end of file'