Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "Message.h"
00022 Message::Message(){
00023 }
00024 Message::Message(char dlm,char cmd,ushort len){
00025 delim = dlm;
00026 command = cmd;
00027 length = len;
00028 }
00029 Message::~Message(){
00030 }
00031 MessageSpefications::MessageSpefications(){
00032 }
00033 MessageSpefications::MessageSpefications(char dlm,char cmd,ushort len)
00034 : Message::Message(dlm,cmd,len){
00035 }
00036 MessageSpefications::~MessageSpefications(){
00037 }
00038 void MessageSpefications::parseBuffer(unsigned char *buf){
00039 spf_vector.assign(length, Specification() );
00040 channels = *buf;
00041 buf++;
00042 for(int chnl=0;chnl<channels;chnl++)
00043 { Specification spf;
00044 spf.setChannel(chnl);
00045 spf.setCurrent(*((float *)(buf)));
00046 spf.setVoltage(*((float *)(buf+4)));
00047 spf_vector.push_back(spf);
00048 buf+=8;
00049 }
00050 }
00051
00052 MessageBroadCasting::MessageBroadCasting(){
00053 }
00054 MessageBroadCasting::MessageBroadCasting(unsigned char frq){
00055 frequency = frq;
00056 body = new unsigned char[5];
00057 unsigned char *p;
00058 p = body;
00059 delim = 2;
00060 command = 1;
00061 length = 1;
00062 *p = delim;
00063 p++;
00064 *p = command;
00065 p++;
00066 *((ushort *)p) = length;
00067 p+=2;
00068 *p = frequency;
00069 }
00070 MessageBroadCasting::~MessageBroadCasting(){
00071 delete body;
00072 }
00073
00074 unsigned char* MessageBroadCasting::getBuffer(int & buf_len){
00075 buf_len = 5;
00076 return body;
00077 }
00078
00079 MessageMeasurments::MessageMeasurments(){
00080 }
00081
00082 MessageMeasurments::MessageMeasurments(char dlm,char cmd,ushort len)
00083 : Message(dlm,cmd,len){
00084 }
00085 MessageMeasurments::~MessageMeasurments(){
00086 }
00087 void MessageMeasurments::parseBuffer(unsigned char *buf){
00088 msr_vector.assign(length, Measurment() );
00089 channels = *buf;
00090 buf++;
00091 for(int chnl=0;chnl<channels;chnl++)
00092 {
00093 Measurment m;
00094 m.setChannel(chnl);
00095 m.setChannelState(*buf);
00096 m.setCurrent(*((float *)(buf+1)));
00097 m.setVoltage(*((float *)(buf+5)));
00098 msr_vector.push_back(m);
00099 buf+=9;
00100
00101 }
00102 }
00103
00104 MessageRequest::MessageRequest(){
00105 body = new unsigned char[4];
00106 unsigned char *p;
00107 p=body;
00108 delim = 2;
00109 command = 3;
00110 length = 0;
00111 *p = delim;
00112 p++;
00113 *p = command;
00114 p++;
00115 *((ushort *)p) = length;
00116 }
00117 MessageRequest::~MessageRequest(){
00118 delete body;
00119 }
00120 unsigned char* MessageRequest::getBuffer(int & buf_len){
00121 buf_len=5;
00122 return body;
00123 }
00124
00125 MessageChannelOnOff::MessageChannelOnOff(){}
00126 MessageChannelOnOff::MessageChannelOnOff(char chnl,char st){
00127 channel = chnl;
00128 state = st;
00129 body = new unsigned char[6];
00130 unsigned char *p;
00131 p = body;
00132 delim = 2;
00133 command = 4;
00134 length = 2;
00135 *p = delim;
00136 p++;
00137 *p = command;
00138 p++;
00139 *((ushort *)p) = length;
00140 p+=2;
00141 *p = channel;
00142 p++;
00143 *p = state;
00144 }
00145 MessageChannelOnOff::~MessageChannelOnOff(){
00146 delete body;
00147 }
00148 unsigned char* MessageChannelOnOff::getBuffer(int & buf_len){
00149 buf_len = 6;
00150 return body;
00151 }
00152
00153 MessageAcknowledgment::MessageAcknowledgment(){
00154 }
00155 MessageAcknowledgment::MessageAcknowledgment(char dlm,char cmd,ushort len)
00156 : Message(dlm,cmd,len){
00157 }
00158 MessageAcknowledgment::~MessageAcknowledgment(){
00159 }
00160 void MessageAcknowledgment::parseBuffer(unsigned char *p)
00161 {
00162 ecode = *p;
00163 printf(" ErrorCode= %i",ecode);
00164 }
00165