- Added missing files
This commit is contained in:
80
fetchwrite.c
Normal file
80
fetchwrite.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* fetchwrite.c
|
||||
*
|
||||
* This is the implementation for the Siemens S5 FETCH/Write
|
||||
* protocol support functions. Docs see header file
|
||||
*
|
||||
* Created on: Mar 24, 2010
|
||||
* Author: koennecke
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "fetchwrite.h"
|
||||
|
||||
Request makeS5WriteRequest(int orgID, unsigned char dbNo,
|
||||
int offset, int length, void *data)
|
||||
{
|
||||
Request result;
|
||||
|
||||
result.totalLength = 16 + length;
|
||||
result.data = malloc(result.totalLength*sizeof(char));
|
||||
if(result.data == NULL){
|
||||
return result;
|
||||
}
|
||||
memset(result.data,0,result.totalLength*sizeof(char));
|
||||
|
||||
result.data[0] = 'S';
|
||||
result.data[1] = '5';
|
||||
result.data[2] = 0x10;
|
||||
result.data[3] = 0x01;
|
||||
result.data[4] = 0x03;
|
||||
result.data[5] = 0x03;
|
||||
result.data[6] = 0x03;
|
||||
result.data[7] = 0x08;
|
||||
result.data[8] = (unsigned char)orgID;
|
||||
result.data[9] = dbNo;
|
||||
result.data[10] = (unsigned short)offset;
|
||||
result.data[12] = (unsigned short)length;
|
||||
result.data[14] = 0xFF;
|
||||
result.data[15] = 0x02;
|
||||
memcpy(result.data+16,data,length);
|
||||
|
||||
return result;
|
||||
}
|
||||
/*-------------------------------------------------------------*/
|
||||
int decodeS5Response(unsigned char data[16])
|
||||
{
|
||||
if(data[0] != 'S' || data[1] != '5'){
|
||||
return S5INVALID;
|
||||
}
|
||||
return (int)data[8];
|
||||
}
|
||||
/*---------------------------------------------------------------*/
|
||||
Request makeS5FetchRequest(int orgID, unsigned char dbNo,
|
||||
int offset, int length)
|
||||
{
|
||||
Request result;
|
||||
|
||||
result.totalLength = 16;
|
||||
result.data = malloc(result.totalLength*sizeof(char));
|
||||
if(result.data == NULL){
|
||||
return result;
|
||||
}
|
||||
memset(result.data,0,result.totalLength*sizeof(char));
|
||||
|
||||
result.data[0] = 'S';
|
||||
result.data[1] = '5';
|
||||
result.data[2] = 0x10;
|
||||
result.data[3] = 0x01;
|
||||
result.data[4] = 0x03;
|
||||
result.data[5] = 0x05;
|
||||
result.data[6] = 0x03;
|
||||
result.data[7] = 0x08;
|
||||
result.data[8] = (unsigned char)orgID;
|
||||
result.data[9] = dbNo;
|
||||
result.data[10] = (unsigned short)offset;
|
||||
result.data[12] = (unsigned short)length;
|
||||
result.data[14] = 0xFF;
|
||||
result.data[15] = 0x02;
|
||||
return result;
|
||||
}
|
Reference in New Issue
Block a user