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.
Fork of jro by
Diff: ipserver.cpp
- Revision:
- 0:b444ea725ba7
- Child:
- 1:7c424a3e12ea
diff -r 000000000000 -r b444ea725ba7 ipserver.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ipserver.cpp Tue Dec 02 02:27:30 2014 +0000
@@ -0,0 +1,112 @@
+#include "ipserver.h"
+
+char* IpData::__findHeader(char* buffer){
+ /*
+ Find header and get ip data (without header)
+
+ Input:
+
+ Return:
+ valid_ipdata: ip data without header
+
+ Example:
+
+ buffer = [ B0 B1 $ J R O $ B7 B8 B9 B10 ..... ]
+
+ return
+ valid_ip_data = [ B7 B8 B9 B10 ..... ]
+
+
+ */
+ char* valid_ip_data;
+
+ //Finding header
+ valid_ip_data = strstr(buffer, HEADER);
+
+ if (valid_ip_data == NULL)
+ return NULL;
+
+ valid_ip_data += 5; //skip header
+
+ return valid_ip_data;
+ }
+
+int IpData::__verifyData(char* ip_data, unsigned long len_data){
+
+ char new_xor = 0;
+
+ for(unsigned long i = 0; i < len_data; i++)
+ {
+ new_xor = new_xor xor ip_data[i];
+ }
+
+ if (new_xor != 0)
+ return 0;
+
+ return 1;
+ }
+
+int IpData::__getParameters(){
+ return 1;
+ }
+
+IpData::IpData(){
+
+ this->isData = false;
+
+ }
+
+int IpData::setIpData(char* buffer, unsigned long len_buffer){
+
+ char* ip_data;
+ unsigned long len_data;
+
+ if (len_buffer < 13)
+ return 0;
+
+ //Finding header and get ip data (without header)
+ ip_data = this->__findHeader(buffer);
+
+ if (ip_data == NULL)
+ return 0;
+
+ len_data = ip_data[0]*65536 + ip_data[1]*256 + ip_data[2];
+
+ this->buff = ip_data;
+
+ if (not this->__verifyData(ip_data, len_data)){
+ this->isData = false;
+ return 0;
+ }
+
+ //head = ip_data[0:5];
+ this->id_class = ip_data[3];
+ this->id_dev = ip_data[4];
+ this->cmd = ip_data[5]*256 + ip_data[6];
+ this->payload = ip_data + 7;
+ this->payload_len = len_data - 4;
+ this->isData = true;
+
+ return 1;
+ }
+
+char IpData::getIdClass(){
+ return this->id_class;
+ }
+
+char IpData::getIdDevice(){
+ return this->id_dev;
+ }
+
+char IpData::getIpCmd(){
+ return this->cmd;
+ }
+
+unsigned long IpData::getPayloadLen(){
+ return this->payload_len;
+ }
+
+char* IpData::getPayload(){
+
+ return this->payload;
+ }
\ No newline at end of file
