successfully make
This commit is contained in:
parent
17caf1a667
commit
28533454c0
|
@ -31,7 +31,7 @@ static void CliDisconnect()
|
||||||
|
|
||||||
void PerformTasks()
|
void PerformTasks()
|
||||||
{
|
{
|
||||||
while(true){
|
while(1){
|
||||||
if(bWrite){
|
if(bWrite){
|
||||||
memset(Buffer, 0, sizeof(Buffer));
|
memset(Buffer, 0, sizeof(Buffer));
|
||||||
Buffer[0] = 0x01;
|
Buffer[0] = 0x01;
|
||||||
|
@ -70,5 +70,3 @@ void s7_demo()
|
||||||
// Deletion
|
// Deletion
|
||||||
Cli_Destroy(Client);
|
Cli_Destroy(Client);
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
|
||||||
S7Demo, s7_demo, Siemens Snap7 Demo);
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
SRC_FILES := s7_client.cpp s7_isotcp.cpp s7_micro_client.cpp s7_peer.cpp s7_text.cpp snap_msgsock.cpp snap_sysutils.cpp snap_threads.cpp snap_libmain.cpp
|
SRC_FILES := s7_client.cpp s7_isotcp.cpp s7_micro_client.cpp s7_peer.cpp s7_text.cpp snap_msgsock.cpp snap_sysutils.cpp snap_threads.cpp snap7_libmain.cpp
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|=============================================================================*/
|
|=============================================================================*/
|
||||||
#include "s7_text.h"
|
#include "s7_text.h"
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
static char* itoa(int value, char* result, int base) {
|
static char* s7_itoa(int value, char* result, int base) {
|
||||||
// check that the base if valid
|
// check that the base if valid
|
||||||
if (base < 2 || base > 36){
|
if (base < 2 || base > 36){
|
||||||
*result = '\0'; return result;
|
*result = '\0'; return result;
|
||||||
|
@ -55,7 +55,7 @@ char* NumToString(int Value, int Base, int Len, char* Result)
|
||||||
{
|
{
|
||||||
char CNumber[64];
|
char CNumber[64];
|
||||||
char Pad[65] = "0000000000000000000000000000000000000000000000000000000000000000";
|
char Pad[65] = "0000000000000000000000000000000000000000000000000000000000000000";
|
||||||
itoa(Value, CNumber, Base);
|
s7_itoa(Value, CNumber, Base);
|
||||||
|
|
||||||
if (Len > 0)
|
if (Len > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "snap_platform.h"
|
#include "snap_platform.h"
|
||||||
#include "snap_sysutils.h"
|
#include "snap_sysutils.h"
|
||||||
|
#include "errno.h"
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -32,8 +32,6 @@ void* ThreadProc(void* param)
|
||||||
PSnapThread Thread;
|
PSnapThread Thread;
|
||||||
// Unix but not Solaris
|
// Unix but not Solaris
|
||||||
int last_type, last_state;
|
int last_type, last_state;
|
||||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &last_type);
|
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &last_state);
|
|
||||||
Thread = PSnapThread(param);
|
Thread = PSnapThread(param);
|
||||||
|
|
||||||
if (!Thread->Terminated)
|
if (!Thread->Terminated)
|
||||||
|
@ -71,10 +69,7 @@ TSnapThread::~TSnapThread()
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void TSnapThread::ThreadCreate()
|
void TSnapThread::ThreadCreate()
|
||||||
{
|
{
|
||||||
pthread_attr_t a;
|
pthread_create(&th, NULL, &ThreadProc, this);
|
||||||
pthread_attr_init(&a);
|
|
||||||
pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
|
|
||||||
pthread_create(&th, &a, &ThreadProc, this);
|
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void TSnapThread::Start()
|
void TSnapThread::Start()
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "snap_platform.h"
|
#include "snap_platform.h"
|
||||||
#include "snap_sysutils.h"
|
#include "snap_sysutils.h"
|
||||||
|
#include "pthread.h"
|
||||||
|
#include "mqueue.h"
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
class TSnapCriticalSection
|
class TSnapCriticalSection
|
||||||
|
@ -85,52 +87,35 @@ const longword WAIT_FAILED = 0xFFFFFFFFL;
|
||||||
class TSnapEvent
|
class TSnapEvent
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
pthread_cond_t CVariable;
|
mqd_t mq; // use message queue to simulate conditional variable
|
||||||
pthread_mutex_t Mutex;
|
|
||||||
bool AutoReset;
|
|
||||||
bool State;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TSnapEvent(bool ManualReset)
|
TSnapEvent(bool _ManualReset)
|
||||||
{
|
{
|
||||||
AutoReset = !ManualReset;
|
mq_close(mq);
|
||||||
if (pthread_cond_init(&CVariable, 0) == 0)
|
mq = mq_open("mq event", 0);
|
||||||
pthread_mutex_init(&Mutex, 0);
|
|
||||||
State = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~TSnapEvent()
|
~TSnapEvent()
|
||||||
{
|
{
|
||||||
pthread_cond_destroy(&CVariable);
|
mq_close(mq);
|
||||||
pthread_mutex_destroy(&Mutex);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void Set()
|
void Set()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&Mutex);
|
mq_send(mq, "emit", 4, 0);
|
||||||
State = true;
|
|
||||||
if (AutoReset)
|
|
||||||
pthread_cond_signal(&CVariable);
|
|
||||||
else
|
|
||||||
pthread_cond_broadcast(&CVariable);
|
|
||||||
pthread_mutex_unlock(&Mutex);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&Mutex);
|
|
||||||
State = false;
|
|
||||||
pthread_mutex_unlock(&Mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
longword WaitForever()
|
longword WaitForever()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&Mutex);
|
// the mq must ensure the receive is blocking and atomic
|
||||||
while (!State) // <-- to avoid spurious wakeups
|
char msg[10] = {0};
|
||||||
pthread_cond_wait(&CVariable, &Mutex);
|
unsigned msg_prio;
|
||||||
if (AutoReset)
|
mq_receive(mq, msg, 0, &msg_prio);
|
||||||
State = false;
|
|
||||||
pthread_mutex_unlock(&Mutex);
|
|
||||||
return WAIT_OBJECT_0;
|
return WAIT_OBJECT_0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,27 +127,19 @@ public:
|
||||||
|
|
||||||
if (Timeout > 0)
|
if (Timeout > 0)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&Mutex);
|
timespec ts;
|
||||||
if (!State)
|
uint32_t msec = PrivGetTickTime();
|
||||||
{
|
uint64_t nsecs = msec * 1000000 +
|
||||||
timespec ts;
|
Timeout * 1000000;
|
||||||
timeval tv;
|
ts.tv_sec = nsecs / 1000000000;
|
||||||
gettimeofday(&tv, NULL);
|
ts.tv_nsec = (nsecs - ((uint64_t) ts.tv_sec) * 1000000000);
|
||||||
uint64_t nsecs = ((uint64_t) tv.tv_sec) * 1000000000 +
|
do {
|
||||||
Timeout * 1000000 +
|
char msg[10] = {0};
|
||||||
((uint64_t) tv.tv_usec) * 1000;
|
unsigned msg_prio;
|
||||||
ts.tv_sec = nsecs / 1000000000;
|
Result = mq_timedreceive(mq, msg, 0, &msg_prio, &ts);
|
||||||
ts.tv_nsec = (nsecs - ((uint64_t) ts.tv_sec) * 1000000000);
|
if (Result == -ETIMEOUT)
|
||||||
do {
|
Result = WAIT_TIMEOUT;
|
||||||
Result = pthread_cond_timedwait(&CVariable, &Mutex, &ts);
|
} while (Result == 0);
|
||||||
if (Result == ETIMEDOUT)
|
|
||||||
Result = WAIT_TIMEOUT;
|
|
||||||
} while (Result == 0 && !State);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (AutoReset) // take the ownership
|
|
||||||
State = false;
|
|
||||||
pthread_mutex_unlock(&Mutex);
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
else // Timeout<0
|
else // Timeout<0
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
#ifndef PTHREAD_H
|
#ifndef PTHREAD_H
|
||||||
#define PTHREAD_H
|
#define PTHREAD_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,7 +27,6 @@ Modification: Use file system functions
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
#include <reent.h>
|
#include <reent.h>
|
||||||
#include <sys/errno.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <xiuos.h>
|
#include <xiuos.h>
|
||||||
|
|
|
@ -45,6 +45,10 @@ extern "C" {
|
||||||
|
|
||||||
#ifdef LWIP_PROVIDE_ERRNO
|
#ifdef LWIP_PROVIDE_ERRNO
|
||||||
|
|
||||||
|
# ifndef ENOTSUP
|
||||||
|
# define ENOTSUP EOPNOTSUPP
|
||||||
|
# endif
|
||||||
|
|
||||||
#define EPERM 1 /* Operation not permitted */
|
#define EPERM 1 /* Operation not permitted */
|
||||||
#define ENOENT 2 /* No such file or directory */
|
#define ENOENT 2 /* No such file or directory */
|
||||||
#define ESRCH 3 /* No such process */
|
#define ESRCH 3 /* No such process */
|
||||||
|
@ -79,15 +83,15 @@ extern "C" {
|
||||||
#define EPIPE 32 /* Broken pipe */
|
#define EPIPE 32 /* Broken pipe */
|
||||||
#define EDOM 33 /* Math argument out of domain of func */
|
#define EDOM 33 /* Math argument out of domain of func */
|
||||||
#define ERANGE 34 /* Math result not representable */
|
#define ERANGE 34 /* Math result not representable */
|
||||||
// #define EDEADLK 35 /* Resource deadlock would occur */
|
#define EDEADLK 35 /* Resource deadlock would occur */
|
||||||
// #define ENAMETOOLONG 36 /* File name too long */
|
#define ENAMETOOLONG 36 /* File name too long */
|
||||||
// #define ENOLCK 37 /* No record locks available */
|
#define ENOLCK 37 /* No record locks available */
|
||||||
// #define ENOSYS 38 /* Function not implemented */
|
#define ENOSYS 38 /* Function not implemented */
|
||||||
// #define ENOTEMPTY 39 /* Directory not empty */
|
#define ENOTEMPTY 39 /* Directory not empty */
|
||||||
// #define ELOOP 40 /* Too many symbolic links encountered */
|
#define ELOOP 40 /* Too many symbolic links encountered */
|
||||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||||
// #define ENOMSG 42 /* No message of desired type */
|
#define ENOMSG 42 /* No message of desired type */
|
||||||
// #define EIDRM 43 /* Identifier removed */
|
#define EIDRM 43 /* Identifier removed */
|
||||||
#define ECHRNG 44 /* Channel number out of range */
|
#define ECHRNG 44 /* Channel number out of range */
|
||||||
#define EL2NSYNC 45 /* Level 2 not synchronized */
|
#define EL2NSYNC 45 /* Level 2 not synchronized */
|
||||||
#define EL3HLT 46 /* Level 3 halted */
|
#define EL3HLT 46 /* Level 3 halted */
|
||||||
|
@ -118,10 +122,10 @@ extern "C" {
|
||||||
#define ESRMNT 69 /* Srmount error */
|
#define ESRMNT 69 /* Srmount error */
|
||||||
#define ECOMM 70 /* Communication error on send */
|
#define ECOMM 70 /* Communication error on send */
|
||||||
#define EPROTO 71 /* Protocol error */
|
#define EPROTO 71 /* Protocol error */
|
||||||
// #define EMULTIHOP 72 /* Multihop attempted */
|
#define EMULTIHOP 72 /* Multihop attempted */
|
||||||
#define EDOTDOT 73 /* RFS specific error */
|
#define EDOTDOT 73 /* RFS specific error */
|
||||||
// #define EBADMSG 74 /* Not a data message */
|
#define EBADMSG 74 /* Not a data message */
|
||||||
// #define EOVERFLOW 75 /* Value too large for defined data type */
|
#define EOVERFLOW 75 /* Value too large for defined data type */
|
||||||
#define ENOTUNIQ 76 /* Name not unique on network */
|
#define ENOTUNIQ 76 /* Name not unique on network */
|
||||||
#define EBADFD 77 /* File descriptor in bad state */
|
#define EBADFD 77 /* File descriptor in bad state */
|
||||||
#define EREMCHG 78 /* Remote address changed */
|
#define EREMCHG 78 /* Remote address changed */
|
||||||
|
@ -130,45 +134,45 @@ extern "C" {
|
||||||
#define ELIBSCN 81 /* .lib section in a.out corrupted */
|
#define ELIBSCN 81 /* .lib section in a.out corrupted */
|
||||||
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
|
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
|
||||||
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
|
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
|
||||||
// #define EILSEQ 84 /* Illegal byte sequence */
|
#define EILSEQ 84 /* Illegal byte sequence */
|
||||||
#define ERESTART 85 /* Interrupted system call should be restarted */
|
#define ERESTART 85 /* Interrupted system call should be restarted */
|
||||||
#define ESTRPIPE 86 /* Streams pipe error */
|
#define ESTRPIPE 86 /* Streams pipe error */
|
||||||
#define EUSERS 87 /* Too many users */
|
#define EUSERS 87 /* Too many users */
|
||||||
// #define ENOTSOCK 88 /* Socket operation on non-socket */
|
#define ENOTSOCK 88 /* Socket operation on non-socket */
|
||||||
// #define EDESTADDRREQ 89 /* Destination address required */
|
#define EDESTADDRREQ 89 /* Destination address required */
|
||||||
// #define EMSGSIZE 90 /* Message too long */
|
#define EMSGSIZE 90 /* Message too long */
|
||||||
// #define EPROTOTYPE 91 /* Protocol wrong type for socket */
|
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
|
||||||
// #define ENOPROTOOPT 92 /* Protocol not available */
|
#define ENOPROTOOPT 92 /* Protocol not available */
|
||||||
// #define EPROTONOSUPPORT 93 /* Protocol not supported */
|
#define EPROTONOSUPPORT 93 /* Protocol not supported */
|
||||||
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
|
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
|
||||||
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||||
#define EPFNOSUPPORT 96 /* Protocol family not supported */
|
#define EPFNOSUPPORT 96 /* Protocol family not supported */
|
||||||
// #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||||
// #define EADDRINUSE 98 /* Address already in use */
|
#define EADDRINUSE 98 /* Address already in use */
|
||||||
// #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
||||||
// #define ENETDOWN 100 /* Network is down */
|
#define ENETDOWN 100 /* Network is down */
|
||||||
// #define ENETUNREACH 101 /* Network is unreachable */
|
#define ENETUNREACH 101 /* Network is unreachable */
|
||||||
// #define ENETRESET 102 /* Network dropped connection because of reset */
|
#define ENETRESET 102 /* Network dropped connection because of reset */
|
||||||
// #define ECONNABORTED 103 /* Software caused connection abort */
|
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||||
#define ECONNRESET 104 /* Connection reset by peer */
|
#define ECONNRESET 104 /* Connection reset by peer */
|
||||||
#define ENOBUFS 105 /* No buffer space available */
|
#define ENOBUFS 105 /* No buffer space available */
|
||||||
// #define EISCONN 106 /* Transport endpoint is already connected */
|
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||||
// #define ENOTCONN 107 /* Transport endpoint is not connected */
|
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||||
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
|
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
|
||||||
// #define ETOOMANYREFS 109 /* Too many references: cannot splice */
|
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
|
||||||
// #define ETIMEDOUT 110 /* Connection timed out */
|
#define ETIMEDOUT 110 /* Connection timed out */
|
||||||
#define ECONNREFUSED 111 /* Connection refused */
|
#define ECONNREFUSED 111 /* Connection refused */
|
||||||
// #define EHOSTDOWN 112 /* Host is down */
|
#define EHOSTDOWN 112 /* Host is down */
|
||||||
// #define EHOSTUNREACH 113 /* No route to host */
|
#define EHOSTUNREACH 113 /* No route to host */
|
||||||
// #define EALREADY 114 /* Operation already in progress */
|
#define EALREADY 114 /* Operation already in progress */
|
||||||
// #define EINPROGRESS 115 /* Operation now in progress */
|
#define EINPROGRESS 115 /* Operation now in progress */
|
||||||
// #define ESTALE 116 /* Stale NFS file handle */
|
#define ESTALE 116 /* Stale NFS file handle */
|
||||||
#define EUCLEAN 117 /* Structure needs cleaning */
|
#define EUCLEAN 117 /* Structure needs cleaning */
|
||||||
#define ENOTNAM 118 /* Not a XENIX named type file */
|
#define ENOTNAM 118 /* Not a XENIX named type file */
|
||||||
#define ENAVAIL 119 /* No XENIX semaphores available */
|
#define ENAVAIL 119 /* No XENIX semaphores available */
|
||||||
#define EISNAM 120 /* Is a named type file */
|
#define EISNAM 120 /* Is a named type file */
|
||||||
#define EREMOTEIO 121 /* Remote I/O error */
|
#define EREMOTEIO 121 /* Remote I/O error */
|
||||||
// #define EDQUOT 122 /* Quota exceeded */
|
#define EDQUOT 122 /* Quota exceeded */
|
||||||
|
|
||||||
#define ENOMEDIUM 123 /* No medium found */
|
#define ENOMEDIUM 123 /* No medium found */
|
||||||
#define EMEDIUMTYPE 124 /* Wrong medium type */
|
#define EMEDIUMTYPE 124 /* Wrong medium type */
|
||||||
|
|
Loading…
Reference in New Issue