tests/plc.c
author laurent
Wed, 16 Mar 2011 10:31:50 +0100
changeset 250 5d2927300e2c
parent 132 39f88c3d803d
child 279 c0453b7f99df
permissions -rw-r--r--
Adding missing support for accessors and retain in configuration files (Bug and fix reported by Manuele Conti)
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
     1
#include "iec_std_lib.h"
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
     2
#include <stdio.h>
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
     3
132
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
     4
#define __print_BOOL(name) printf("  %s = (BOOL) %s\n",#name, name?"TRUE":"FALSE");
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
     5
#define __print_SINT(name) printf("  %s = (SINT) %d\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
     6
#define __print_INT(name) printf("  %s = (INT) %d\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
     7
#define __print_DINT(name) printf("  %s = (DINT) %d\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
     8
#define __print_LINT(name) printf("  %s = (LINT) %d\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
     9
#define __print_USINT(name) printf("  %s = (USINT) %u\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    10
#define __print_UINT(name) printf("  %s = (UINT) %u\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    11
#define __print_UDINT(name) printf("  %s = (UDINT) %u\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    12
#define __print_ULINT(name) printf("  %s = (ULINT) %lu\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    13
#define __print_REAL(name) printf("  %s = (REAL) %f\n",#name, (double)name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    14
#define __print_LREAL(name) printf("  %s = (LREAL) %f\n",#name, (double)name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    15
#define __print_TIME(name) {STRING __tmp = __time_to_string(name);__tmp.body[__tmp.len] = 0; printf("  %s = (TIME) %*s\n",#name, __tmp.len, &__tmp.body);}
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    16
#define __print_DATE(name) {STRING __tmp = __date_to_string(name);__tmp.body[__tmp.len] = 0; printf("  %s = (DATE) %*s\n",#name, __tmp.len, &__tmp.body);}
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    17
#define __print_TOD(name) {STRING __tmp = __tod_to_string(name);__tmp.body[__tmp.len] = 0; printf("  %s = (TOD) %*s\n",#name, __tmp.len, &__tmp.body);}
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    18
#define __print_DT(name) {STRING __tmp = __dt_to_string(name);__tmp.body[__tmp.len] = 0; printf("  %s = (DT) %*s\n",#name, __tmp.len, &__tmp.body);}
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    19
#define __print_STRING(name) printf("  %s = (STRING) {%d, \"%*s\"}\n",#name, name->len, name->len, &name->body);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    20
#define __print_BYTE(name) printf("  %s = (BYTE) 0x%2.2x\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    21
#define __print_WORD(name) printf("  %s = (WORD) 0x%4.4x\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    22
#define __print_DWORD(name) printf("  %s = (DWORD) 0x%8.8x\n",#name, name);
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    23
#define __print_LWORD(name) printf("  %s = (LWORD) 0x%16.16lx\n",#name, name);
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    24
/*
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    25
 * Functions and variables provied by generated C softPLC
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    26
 **/ 
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    27
void config_run__(int tick);
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    28
void config_init__(void);
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    29
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    30
/*
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    31
 *  Functions and variables to export to generated C softPLC
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    32
 **/
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    33
 
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    34
TIME __CURRENT_TIME;
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    35
132
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    36
#define __LOCATED_VAR(type, name, ...) type __##name;
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    37
#include "LOCATED_VARIABLES.h"
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    38
#undef __LOCATED_VAR
39f88c3d803d Updated tests so that they compile again :-)
etisserant
parents: 57
diff changeset
    39
#define __LOCATED_VAR(type, name, ...) type* name = &__##name;
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    40
#include "LOCATED_VARIABLES.h"
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    41
#undef __LOCATED_VAR
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    42
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    43
static int tick = 0;
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    44
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    45
void run()
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    46
{
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    47
    printf("Tick %d\n",tick);
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    48
    config_run__(tick++);
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    49
    printf("  Located variables : \n");
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    50
#define __LOCATED_VAR(type, name,...) __print_##type(name);
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    51
#include "LOCATED_VARIABLES.h"
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    52
#undef __LOCATED_VAR
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    53
}
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff changeset
    54