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.
Dependents: oldheating gps motorhome heating
Diff: net.c
- Revision:
- 136:8a65abb0dc63
- Parent:
- 119:8e1a7805b801
- Child:
- 142:a8c0890a58d1
diff -r a7f026a09543 -r 8a65abb0dc63 net.c
--- a/net.c Sat Mar 23 12:25:48 2019 +0000
+++ b/net.c Sat Apr 06 11:20:20 2019 +0000
@@ -59,7 +59,6 @@
return h;
}
-
int32_t NetToHost32(int32_t n)
{
int32_t h;
@@ -92,30 +91,71 @@
return h;
}
-uint16_t onesComplement(uint16_t start, int count, void* pData)
+void NetInvert16(void* h, void* n)
+{
+ char* pn = (char*)n;
+ char* ph = (char*)h + 1;
+
+ *ph = *pn; ph--; pn++; // 1<-0
+ *ph = *pn; // 0<-1
+}
+void NetInvert32(void* h, void* n)
{
- uint32_t sum = start; //Initialise the 32 bit accumulator with the last sum
- uint16_t* p = (uint16_t*)pData; //Set up a 16 bit pointer for the data
+ char* pn = (char*)n;
+ char* ph = (char*)h + 3;
- while(count > 1)
- {
- sum += *p++; // Add each pair of bytes into 32 bit accumulator
- count -= 2;
- }
- if(count) sum += * (uint8_t*) p; // Add left-over byte, if any
- while (sum>>16) sum = (sum & 0xffff) + (sum >> 16); // Add any carries from the sum back into the sum to make it ones complement
- return sum;
+ *ph = *pn; ph--; pn++; // 3<-0
+ *ph = *pn; ph--; pn++; // 2<-1
+ *ph = *pn; ph--; pn++; // 1<-2
+ *ph = *pn; // 0<-3
}
-uint16_t NetCheckSumTwo(int count1, void* pData1, int count2, void* pData2)
-{
- uint16_t sum = onesComplement(0, count1, pData1);
- return ~onesComplement(sum, count2, pData2);
-}
-uint16_t NetCheckSum(int count, void* pData)
-{
- return ~onesComplement(0, count, pData);
+void NetInvert64(void* h, void* n)
+{
+ char* pn = (char*)n;
+ char* ph = (char*)h + 7;
+
+ *ph = *pn; ph--; pn++; // 7<-0
+ *ph = *pn; ph--; pn++; // 6<-1
+ *ph = *pn; ph--; pn++; // 5<-2
+ *ph = *pn; ph--; pn++; // 4<-3
+ *ph = *pn; ph--; pn++; // 3<-4
+ *ph = *pn; ph--; pn++; // 2<-5
+ *ph = *pn; ph--; pn++; // 1<-6
+ *ph = *pn; // 0<-7
}
+void NetDirect16(void* h, void* n)
+{
+ char* pn = (char*)n;
+ char* ph = (char*)h;
+
+ *ph = *pn; ph++; pn++; // 0<-0
+ *ph = *pn; // 1<-1
+}
+void NetDirect32(void* h, void* n)
+{
+ char* pn = (char*)n;
+ char* ph = (char*)h;
+
+ *ph = *pn; ph++; pn++; // 0<-0
+ *ph = *pn; ph++; pn++; // 1<-1
+ *ph = *pn; ph++; pn++; // 2<-2
+ *ph = *pn; // 3<-3
+}
+void NetDirect64(void* h, void* n)
+{
+ char* pn = (char*)n;
+ char* ph = (char*)h;
+
+ *ph = *pn; ph++; pn++; // 0<-0
+ *ph = *pn; ph++; pn++; // 1<-1
+ *ph = *pn; ph++; pn++; // 2<-2
+ *ph = *pn; ph++; pn++; // 3<-3
+ *ph = *pn; ph++; pn++; // 4<-4
+ *ph = *pn; ph++; pn++; // 5<-5
+ *ph = *pn; ph++; pn++; // 6<-6
+ *ph = *pn; // 7<-7
+}
void NetInit(const char* name4, const char* name6)
{
NetName4 = name4;