blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 3
357
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
58
| license_type
stringclasses 2
values | repo_name
stringlengths 4
115
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringlengths 4
58
| visit_date
timestamp[ns]date 2015-07-14 21:31:45
2023-09-06 10:45:08
| revision_date
timestamp[ns]date 1970-01-01 00:00:00
2023-09-05 23:26:37
| committer_date
timestamp[ns]date 1970-01-01 00:00:00
2023-09-05 23:26:37
| github_id
int64 966
689M
⌀ | star_events_count
int64 0
209k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 24
values | gha_event_created_at
timestamp[ns]date 2012-06-07 00:51:45
2023-09-14 21:58:52
⌀ | gha_created_at
timestamp[ns]date 2008-02-03 21:17:16
2023-08-24 19:49:39
⌀ | gha_language
stringclasses 180
values | src_encoding
stringclasses 35
values | language
stringclasses 1
value | is_vendor
bool 1
class | is_generated
bool 2
classes | length_bytes
int64 6
10.4M
| extension
stringclasses 121
values | filename
stringlengths 1
148
| content
stringlengths 6
10.4M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8e73c964fc3b665e63d0866eb9aeb8c428c752fd
|
bc949cbcded25afc8511d07c8d86509d5746b2a8
|
/dataset/10283.c
|
8e656522d0ed7f9bfba0be7b0ece3eec632f4c85
|
[] |
no_license
|
hqjenny/CSmith_random_pgm
|
52aa1face59749a9d0656fc4088f6f921aac2dab
|
0ebf41b85201cbe791a13304cdb45e22504f0ce7
|
refs/heads/master
| 2023-08-17T23:28:24.519500 | 2021-09-15T19:55:23 | 2021-09-15T19:55:23 | 406,904,982 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,788 |
c
|
10283.c
|
/*
* This is a RANDOMLY GENERATED PROGRAM.
*
* Generator: csmith 2.2.0
* Git version: dcef523
* Options: --no-structs --no-pointers --no-math64 --max-funcs 4 --no-unions --output 10283.c
* Seed: 3591902974
*/
#include "csmith.h"
static long __undefined;
/* --- Struct/Union Declarations --- */
/* --- GLOBAL VARIABLES --- */
static int8_t g_2 = 0x9EL;
static int8_t g_3 = 0x73L;
static uint32_t g_4 = 0x9D568D52L;
static uint16_t g_18 = 0x1C17L;
static int8_t g_29[9][1][3] = {{{(-8L),0xE4L,(-8L)}},{{(-8L),(-4L),(-1L)}},{{(-8L),0x3DL,0x3FL}},{{(-8L),0xE4L,(-8L)}},{{(-8L),(-4L),(-1L)}},{{(-8L),0x3DL,0x3FL}},{{(-8L),0xE4L,(-8L)}},{{(-8L),(-4L),(-1L)}},{{(-8L),0x3DL,0x3FL}}};
/* --- FORWARD DECLARATIONS --- */
static int16_t func_1(void);
/* --- FUNCTIONS --- */
/* ------------------------------------------ */
/*
* reads : g_4 g_2 g_29 g_3 g_18
* writes: g_4 g_18
*/
static int16_t func_1(void)
{ /* block id: 0 */
int8_t l_7 = 0L;
int32_t l_25 = 0x81720D70L;
uint16_t l_26 = 65528UL;
l_25 = ((((g_4--) > l_7) && (safe_mul_func_int8_t_s_s((safe_add_func_int16_t_s_s((safe_rshift_func_uint16_t_u_s(((safe_rshift_func_int8_t_s_s((safe_lshift_func_int16_t_s_s((((g_18 = l_7) , (g_4++)) | (g_2 , (((safe_mul_func_int16_t_s_s(((safe_rshift_func_uint8_t_u_s((l_25 == 4294967290UL), ((g_2 , (((l_26 , (((safe_lshift_func_uint16_t_u_s(g_29[4][0][1], 5)) || g_29[7][0][0]) <= l_7)) , g_29[1][0][1]) <= g_3)) , 0x3AL))) > g_29[4][0][1]), g_29[4][0][1])) > g_2) < 0x09EB818FL))), g_2)), l_25)) && l_26), 12)), 65533UL)), l_25))) && 1UL);
return g_18;
}
/* ---------------------------------------- */
int main (int argc, char* argv[])
{
int i, j, k;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
transparent_crc(g_2, "g_2", print_hash_value);
transparent_crc(g_3, "g_3", print_hash_value);
transparent_crc(g_4, "g_4", print_hash_value);
transparent_crc(g_18, "g_18", print_hash_value);
for (i = 0; i < 9; i++)
{
for (j = 0; j < 1; j++)
{
for (k = 0; k < 3; k++)
{
transparent_crc(g_29[i][j][k], "g_29[i][j][k]", print_hash_value);
if (print_hash_value) printf("index = [%d][%d][%d]\n", i, j, k);
}
}
}
int checksum = platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return checksum;
}
/************************ statistics *************************
XXX max struct depth: 0
breakdown:
depth: 0, occurrence: 8
XXX total union variables: 0
XXX non-zero bitfields defined in structs: 0
XXX zero bitfields defined in structs: 0
XXX const bitfields defined in structs: 0
XXX volatile bitfields defined in structs: 0
XXX structs with bitfields in the program: 0
breakdown:
XXX full-bitfields structs in the program: 0
breakdown:
XXX times a bitfields struct's address is taken: 0
XXX times a bitfields struct on LHS: 0
XXX times a bitfields struct on RHS: 0
XXX times a single bitfield on LHS: 0
XXX times a single bitfield on RHS: 0
XXX max expression depth: 30
breakdown:
depth: 1, occurrence: 2
depth: 30, occurrence: 1
XXX total number of pointers: 0
XXX times a non-volatile is read: 19
XXX times a non-volatile is write: 4
XXX times a volatile is read: 0
XXX times read thru a pointer: 0
XXX times a volatile is write: 0
XXX times written thru a pointer: 0
XXX times a volatile is available for access: 0
XXX percentage of non-volatile access: 100
XXX forward jumps: 0
XXX backward jumps: 0
XXX stmts: 2
XXX max block depth: 0
breakdown:
depth: 0, occurrence: 2
XXX percentage a fresh-made variable is used: 32
XXX percentage an existing variable is used: 68
********************* end of statistics **********************/
|
1f327db5c625e64447aefa03ad93cae3e4cf32ba
|
cefd6c17774b5c94240d57adccef57d9bba4a2e9
|
/WebKit/Source/WebCore/ForwardingHeaders/profiler/LegacyProfiler.h
|
dc0e9bf5ee0ac394854a8d4e02cfe98c15bb78a5
|
[
"BSL-1.0",
"BSD-2-Clause",
"LGPL-2.0-only",
"LGPL-2.1-only"
] |
permissive
|
adzhou/oragle
|
9c054c25b24ff0a65cb9639bafd02aac2bcdce8b
|
5442d418b87d0da161429ffa5cb83777e9b38e4d
|
refs/heads/master
| 2022-11-01T05:04:59.368831 | 2014-03-12T15:50:08 | 2014-03-12T15:50:08 | 17,238,063 | 0 | 1 |
BSL-1.0
| 2022-10-18T04:23:53 | 2014-02-27T05:39:44 |
C++
|
UTF-8
|
C
| false | false | 125 |
h
|
LegacyProfiler.h
|
#ifndef WebCore_FWD_LegacyProfiler_h
#define WebCore_FWD_LegacyProfiler_h
#include <JavaScriptCore/LegacyProfiler.h>
#endif
|
41aec696a2a27de22269feb357e81afbc4939cbf
|
b6a26569f334ba847e474427ecf81b50b0362cea
|
/AmiModulePkg/Include/Protocol/AhciSmmProtocol.h
|
dc5872bc8096e69ce0994a5622c2d85c333c37fc
|
[] |
no_license
|
marktsai0316/Transformer
|
fd553728daa5aaa5b3f3fed9b9a2352d70dcd51c
|
e39ec3030ef0fd1841c6d916bdb77cddaaebc6ad
|
refs/heads/master
| 2022-12-10T22:30:54.984958 | 2020-09-10T05:55:24 | 2020-09-10T05:55:24 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 8,377 |
h
|
AhciSmmProtocol.h
|
//**********************************************************************
//**********************************************************************
//** **
//** (C)Copyright 1985-2017, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//**********************************************************************
//**********************************************************************
/** @file AhciSmmProtocol.h
Protocol definition for Ahci SMM
**/
#ifndef _AMI_AHCI_SMM_PROTOCOLS_H_
#define _AMI_AHCI_SMM_PROTOCOLS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <Protocol/AmiAhciBus.h>
#define AMI_AHCI_SMM_PROTOCOL_GUID \
{0xB2FA5764, 0x3B6E, 0x43D3, { 0x91, 0xDF, 0x87, 0xD1, 0x5A, 0x3E, 0x56, 0x68 } }
typedef struct _AMI_AHCI_BUS_SMM_PROTOCOL AMI_AHCI_BUS_SMM_PROTOCOL;
/**
Initilize the Sata port on S3 resume
@param SataDevInterface
@param Port,
@retval
EFI_STATUS
**/
typedef
EFI_STATUS
(EFIAPI *AMI_AHCI_SMM_INIT_ON_S3) (
IN AMI_AHCI_BUS_SMM_PROTOCOL *SataDevInterface,
IN UINT8 Port
);
/**
Execute the PIO data command
@param SataDevInterface
@param CommandStructure
@param PortNumber,
@param PMPortNumber,
@param DeviceType,
@param READWRITE
@retval
EFI_STATUS
**/
typedef
EFI_STATUS
(EFIAPI *AMI_AHCI_SMM_SATA_DEV_PIO_DATA_IN) (
IN AMI_AHCI_BUS_SMM_PROTOCOL *SataDevInterface,
IN OUT COMMAND_STRUCTURE *CommandStructure,
UINT8 PortNumber,
UINT8 PMPortNumber,
DEVICE_TYPE DeviceType,
IN BOOLEAN READWRITE
);
/**
Execute the DMA data command
@param SataDevInterface
@param CommandStructure
@param PortNumber,
@param PMPortNumber,
@param DeviceType,
@param READWRITE
@retval
EFI_STATUS
**/
typedef
EFI_STATUS
(EFIAPI *AMI_AHCI_SMM_SATA_DEV_DMA_DATA_IN) (
IN AMI_AHCI_BUS_SMM_PROTOCOL *SataDevInterface,
IN OUT COMMAND_STRUCTURE *CommandStructure,
UINT8 PortNumber,
UINT8 PMPortNumber,
DEVICE_TYPE DeviceType,
IN BOOLEAN READWRITE
);
/**
Execute the Non Data command
@param SataDevInterface
@param CommandStructure
@param PortNumber,
@param PMPortNumber,
@param DeviceType,
@retval
EFI_STATUS
**/
typedef
EFI_STATUS
(EFIAPI *AMI_AHCI_SMM_SATA_DEV_NON_DATA_CMD) (
IN AMI_AHCI_BUS_SMM_PROTOCOL *SataDevInterface,
IN COMMAND_STRUCTURE CommandStructure,
UINT8 PortNumber,
UINT8 PMPortNumber,
DEVICE_TYPE DeviceType
);
/**
Execute a Atapi Packet command
@param SataDevInterface
@param CommandStructure
@param READWRITE
@param PortNumber,
@param PMPortNumber,
@param DeviceType
@retval
EFI_STATUS
@note
1. Stop the Controller
2. Check if the device is ready to accept a Command.
3. Build Command list
4. Start the Controller.
5. Wait till command completes. Check for errors.
**/
typedef
EFI_STATUS
(EFIAPI *AMI_AHCI_SMM_SATA_DEV_PACKET_CMD) (
IN AMI_AHCI_BUS_SMM_PROTOCOL *SataDevInterface,
IN COMMAND_STRUCTURE *CommandStructure,
IN BOOLEAN READWRITE,
UINT8 PortNumber,
UINT8 PMPortNumber,
DEVICE_TYPE DeviceType
);
/**
Issues a Port Reset
@param SataDevInterface - Pointer to AMI_AHCI_BUS_SMM_PROTOCOL
@param Port - Device's Port Number
@param PMPort - Device's PMPort Number
@param DeviceType - Type of the device (0-ATA, 1-ATAPI)
@retval EFI_SUCCESS - Port reset successful
@retval EFI_DEVICE_ERROR - Device error/Timeout occurred
@note 1. Issue port reset by setting DET bit in SControl register
2. Call HandlePortComReset to check the status of the reset.
**/
typedef
EFI_STATUS
(EFIAPI *AMI_AHCI_SMM_SATA_DEV_PORT_RESET) (
AMI_AHCI_BUS_SMM_PROTOCOL *SataDevInterface,
UINT8 Port,
UINT8 PMPort,
DEVICE_TYPE DeviceType
);
/**
Generates Soft Reset
@param SataDevInterface - Pointer to AMI_AHCI_BUS_SMM_PROTOCOL
@param Port - Device's Port Number
@param PMPort - Device's PMPort Number
@param DeviceType - Type of the device (0-ATA, 1-ATAPI)
@retval EFI_SUCCESS - Soft reset successful
@retval EFI_DEVICE_ERROR - Device error/Timeout occurred
@note
1. Issue a Control register update, H2D register FIS with reset bit set.
2. Wait for 100usec
3. Issue a Control register update, H2D register FIS with reset bit reset.
**/
typedef
EFI_STATUS
(EFIAPI *AMI_AHCI_SMM_SATA_DEV_SOFT_RESET) (
IN AMI_AHCI_BUS_SMM_PROTOCOL *SataDevInterface,
IN UINT8 Port,
IN UINT8 PMPort,
DEVICE_TYPE DeviceType
);
struct _AMI_AHCI_BUS_SMM_PROTOCOL{
UINT32 AhciBaseAddress;
UINT64 PortCommandTableBaseAddr;
UINT64 PortCommandListBaseAddr;
UINT64 PortFISBaseAddr;
UINT8 PortNumber;
UINT8 PMPortNumber;
DEVICE_TYPE DeviceType;
ATAPI_DEVICE AtapiDevice;
AMI_AHCI_SMM_INIT_ON_S3 AhciSmmInitPortOnS3Resume;
AMI_AHCI_SMM_SATA_DEV_PIO_DATA_IN AhciSmmExecutePioDataCommand;
AMI_AHCI_SMM_SATA_DEV_DMA_DATA_IN AhciSmmExecuteDmaDataCommand;
AMI_AHCI_SMM_SATA_DEV_NON_DATA_CMD AhciSmmExecuteNonDataCommand;
AMI_AHCI_SMM_SATA_DEV_PACKET_CMD AhciSmmExecutePacketCommand;
AMI_AHCI_SMM_SATA_DEV_PORT_RESET AhciSmmGeneratePortReset;
AMI_AHCI_SMM_SATA_DEV_SOFT_RESET AhciSmmGenerateSoftReset;
};
extern EFI_GUID gAmiAhciSmmProtocolGuid;
#ifdef __cplusplus
}
#endif
#endif
//**********************************************************************
//**********************************************************************
//** **
//** (C)Copyright 1985-2017, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//**********************************************************************
//**********************************************************************
|
79c7b33cc2a70eaadb963c352ff8e2cbed064d54
|
0a2a4a3f2ce2b2cf98f6717ef92b22675c9220cf
|
/src/Externals/cleaver/teem/src/moss/methodsMoss.c
|
06161e8dd5fc4b1d828a9e15cb1456244f51807c
|
[
"LGPL-2.0-or-later",
"LGPL-2.1-or-later",
"LicenseRef-scancode-other-copyleft",
"LGPL-2.1-only",
"GPL-1.0-or-later",
"MIT"
] |
permissive
|
Haydelj/SCIRun
|
fa0d22a250c829e65eddf1327399e3795916b012
|
f7ee04d85349b946224dbff183438663e54b9413
|
refs/heads/master
| 2022-11-06T09:01:14.956890 | 2020-03-25T00:37:06 | 2020-03-25T00:37:06 | 164,483,916 | 0 | 0 |
MIT
| 2019-01-07T19:43:50 | 2019-01-07T19:43:50 | null |
UTF-8
|
C
| false | false | 4,561 |
c
|
methodsMoss.c
|
/*
Teem: Tools to process and visualize scientific data and images
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
(LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The terms of redistributing and/or modifying this software also
include exceptions to the LGPL that facilitate static linking.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "moss.h"
#include "privateMoss.h"
/*
******** mossSamplerNew()
**
*/
mossSampler *
mossSamplerNew (void) {
mossSampler *smplr;
int i;
smplr = (mossSampler *)calloc(1, sizeof(mossSampler));
if (smplr) {
smplr->image = NULL;
smplr->kernel = NULL;
for (i=0; i<NRRD_KERNEL_PARMS_NUM; i++)
smplr->kparm[i] = AIR_NAN;
smplr->ivc = NULL;
smplr->xFslw = smplr->yFslw = NULL;
smplr->xIdx = smplr->yIdx = NULL;
smplr->bg = NULL;
smplr->fdiam = smplr->ncol = 0;
smplr->boundary = mossDefBoundary;
for (i=0; i<MOSS_FLAG_NUM; i++)
smplr->flag[i] = AIR_FALSE;
}
return smplr;
}
int
mossSamplerFill (mossSampler *smplr, int fdiam, int ncol) {
char me[]="_mossSamplerFill", err[BIFF_STRLEN];
if (!(smplr)) {
sprintf(err, "%s: got NULL pointer", me);
biffAdd(MOSS, err); return 1;
}
smplr->ivc = (float*)calloc(fdiam*fdiam*ncol, sizeof(float));
smplr->xFslw = (double*)calloc(fdiam, sizeof(double));
smplr->yFslw = (double*)calloc(fdiam, sizeof(double));
smplr->xIdx = (int*)calloc(fdiam, sizeof(int));
smplr->yIdx = (int*)calloc(fdiam, sizeof(int));
if (!( smplr->ivc && smplr->xFslw && smplr->yFslw
&& smplr->xIdx && smplr->yIdx )) {
sprintf(err, "%s: couldn't allocate buffers", me);
biffAdd(MOSS, err); return 1;
}
smplr->fdiam = fdiam;
smplr->ncol = ncol;
return 0;
}
void
mossSamplerEmpty (mossSampler *smplr) {
if (smplr) {
smplr->ivc = (float *)airFree(smplr->ivc);
smplr->xFslw = (double *)airFree(smplr->xFslw);
smplr->yFslw = (double *)airFree(smplr->yFslw);
smplr->xIdx = (int *)airFree(smplr->xIdx);
smplr->yIdx = (int *)airFree(smplr->yIdx);
smplr->fdiam = 0;
smplr->ncol = 0;
}
return;
}
mossSampler *
mossSamplerNix (mossSampler *smplr) {
if (smplr) {
mossSamplerEmpty(smplr);
smplr->bg = (float *)airFree(smplr->bg);
free(smplr);
}
return NULL;
}
int
mossImageCheck (Nrrd *image) {
char me[]="mossImageCheck", err[BIFF_STRLEN];
if (nrrdCheck(image)) {
sprintf(err, "%s: given nrrd invalid", me);
biffMove(MOSS, err, NRRD); return 1;
}
if (!( (2 == image->dim || 3 == image->dim)
&& nrrdTypeBlock != image->type )) {
sprintf(err, "%s: image has invalid dimension (%d) or type (%s)", me,
image->dim, airEnumStr(nrrdType, image->type));
biffAdd(MOSS, err); return 1;
}
return 0;
}
int
mossImageAlloc (Nrrd *image, int type, int sx, int sy, int ncol) {
char me[]="mossImageAlloc", err[BIFF_STRLEN];
int ret;
if (!(image && AIR_IN_OP(nrrdTypeUnknown, type, nrrdTypeBlock)
&& sx > 0 && sy > 0 && ncol > 0)) {
sprintf(err, "%s: got NULL pointer or bad args", me);
biffAdd(MOSS, err); return 1;
}
if (1 == ncol) {
ret = nrrdMaybeAlloc_va(image, type, 2,
AIR_CAST(size_t, sx),
AIR_CAST(size_t, sy));
} else {
ret = nrrdMaybeAlloc_va(image, type, 3,
AIR_CAST(size_t, ncol),
AIR_CAST(size_t, sx),
AIR_CAST(size_t, sy));
}
if (ret) {
sprintf(err, "%s: couldn't allocate image", me);
biffMove(MOSS, err, NRRD); return 1;
}
return 0;
}
int
_mossCenter(int center) {
center = (nrrdCenterUnknown == center
? mossDefCenter
: center);
center = AIR_CLAMP(nrrdCenterUnknown+1, center, nrrdCenterLast-1);
return center;
}
|
3afe314232355825fa1ff5fd3f63e2bd98921700
|
892a019cabfadb1554372e5d478317dafc121579
|
/ipc_server.c
|
f36a5eb9a957c5ccae7dc7150930c14bb78cb58a
|
[] |
no_license
|
eldron/tlsmb
|
8208fd272c7280e76843c8ff63c0bf5f8c2f9608
|
d47b64e68d1bbc7a06f1c1e8e1a473b8c0703ec8
|
refs/heads/master
| 2021-07-09T15:03:04.031764 | 2018-11-30T13:10:09 | 2018-11-30T13:10:09 | 135,407,359 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 4,018 |
c
|
ipc_server.c
|
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <stdlib.h>
#define SERVER_ADDRESS "mysocket"
// strings we send to the client
char * strs[3] = {
"this is the first string from the server\n",
"this is the second string from the server\n",
"this is the third string from the server\n"
};
void test_server_main(){
char c;
FILE * fp;
struct sockaddr_un server_address;
struct sockaddr_un client_address;
int server_sock;
int client_sock;
// get a socket to work with, the socket willbe in the UNIX domain,
// and will be a stream socket
if((server_sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
perror("server: socket");
exit(1);
}
// create the address we will be binding to
server_address.sun_family = AF_UNIX;
strcpy(server_address.sun_path, SERVER_ADDRESS);
// try to bind the address to the server socket, we unlink
// the name first so that the bind won't fail
unlink(SERVER_ADDRESS);
int server_address_len = sizeof(server_address.sun_family) + strlen(server_address.sun_path);
if(bind(server_sock, &server_address, server_address_len) < 0){
perror("server: bind");
exit(1);
}
// listen on server socket
if(listen(server_sock, 5) < 0){
perror("server: listen");
exit(1);
}
int client_address_len;
if((client_sock = accept(server_sock, &client_address, &client_address_len)) < 0){
perror("server: accept");
exit(1);
}
// we will use stdio for reading the socket
fp = fdopen(client_sock, "r");
// first we send some strings to the client
int i;
for(i = 0;i < 3;i++){
send(client_sock, strs[i], strlen(strs[i]), 0);
}
// then we read some strings from the client and
// print them out
for(i = 0;i < 3;i++){
while((c = fgetc(fp)) != EOF){
putchar(c);
if(c == '\n'){
break;
}
}
}
// we can simply use close() to terminate the connection,
// since we are done with both sides
close(server_sock);
}
int main(){
// char c;
// FILE * fp;
// int from_len;
// int i, s, ns, len;
// struct sockaddr_un saun, fsaun;
// // get a socket to work with, the socket will be
// // in the UNIX domain, and will be a stream socket
// if((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
// perror("server: socket");
// exit(1);
// }
// // create the address we will be binding to
// saun.sun_family = AF_UNIX;
// strcpy(saun.sun_path, SERVER_ADDRESS);
// // try to bind the address to the socket, we unlink
// // the name first so that the bind won't fail
// unlink(SERVER_ADDRESS);
// len = sizeof(saun.sun_family) + strlen(saun.sun_path);
// if(bind(s, &saun, len) < 0){
// perror("server: bind");
// exit(1);
// }
// // listen on the socket
// if(listen(s, 5) < 0){
// perror("server: listen");
// exit(1);
// }
// // accept connections, when we accept one,
// // ns will be connected to the client, fsaun
// // wull contain the address of the client
// if((ns = accept(s, &fsaun, &from_len)) < 0){
// perror("server: accept");
// exit(1);
// }
// // we will use stdio for reading the socket
// fp = fdopen(ns, "r");
// // first we send some strings to the client
// for(i = 0;i < 3;i++){
// send(ns, strs[i], strlen(strs[i]), 0);
// }
// // then we read some strings from the client and
// // print them out
// for(i = 0;i < 3;i++){
// while((c = fgetc(fp)) != EOF){
// putchar(c);
// if(c == '\n'){
// break;
// }
// }
// }
// // we can simply use close() to terminate the connection,
// // since we are done with both sides
// close(s);
test_server_main();
return 0;
}
|
acae6d3a25c442a6607bb34b9ff20b5d1109993c
|
4d4787b7244610134c3353d7942f4097f5f2b8f2
|
/Strings/test.c
|
5bc6f540caddc30f645768355c105fced54e5e79
|
[] |
no_license
|
nothingthere/clang
|
c42496da20000b882c3aa0dba8f1941d59ea2413
|
b5beda28fad1aea83c6d76371bef1d0ecc4ca866
|
refs/heads/master
| 2021-01-01T16:52:31.783480 | 2017-07-23T16:52:28 | 2017-07-23T16:52:28 | 97,937,106 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,851 |
c
|
test.c
|
/**************************************************************
* test.c
* Author: Claudio <3261958605@qq.com>
* Created: 2017-07-21 13:42:33
* Commentary: 测试文件
***************************************************************/
#include "Strings.h"
#include <stdio.h>
void print(String str) { printf("%s\n", str); }
int main(void) {
Strings strings = stringsInit();
strings = stringsInsert(strings, 0, "hello");
strings = stringsInsert(strings, 110, "world");
strings = stringsAppend(strings, "my");
strings = stringsAppend(strings, "name");
strings = stringsAppendLeft(strings, "Clang");
strings = stringsRemove(strings, 0);
strings = stringsRemove(strings, 1000);
strings = stringsAppend(strings, "name");
strings = stringsPop(strings);
strings = stringsPopLeft(strings);
strings = stringsAppendLeft(strings, "hello");
strings = stringsAppend(strings, "name");
Strings s2 = stringsInit();
s2 = stringsAppend(s2, "is");
s2 = stringsAppend(s2, "claudio");
printf("s2:\n");
stringsPrint(s2);
strings = stringsExtend(strings, s2);
printf("strings:\n");
stringsPrint(strings);
s2 = stringsExtend(s2, strings);
printf("s2:\n");
stringsPrint(s2);
printf("========================\n");
Strings s3 = stringsCopy(s2);
printf("s3:\n");
stringsPrint(s3);
printf("========================\n");
printf("claudio 在s3的索引为:%d\n", stringsFind(s3, "claudio"));
printf("Claudio 在s2的索引为:%d\n", stringsFind(s2, "Claudio"));
printf("s2中第3个元素为:%s\n", stringsGet(s2, 2));
printf("s2中第-1个元素为:%s\n", stringsGet(s2, -1));
printf("s2中第100个元素为:%s\n", stringsGet(s2, 100));
printf("stringsMap(s3, print)结果:\n");
stringsMap(s3, print);
stringsClear(strings);
stringsClear(s2);
stringsClear(s3);
return 0;
}
|
5561187bf3ca10db9116b0b508692ba22da8193b
|
2ac5506addd12d4b2635ece4ca2a4a2fae0a1221
|
/src/main-master.c
|
eaa3bd8c172e9ceb7825d9e54c94be3ee074c434
|
[] |
no_license
|
blamejoel/growbot
|
17e58e83eeaa0b50c2b0fa5e691e4a77b0b8a222
|
cc58640df038faafaaabce7dc54d953db431d183
|
refs/heads/master
| 2021-06-12T14:28:31.770609 | 2017-01-24T08:19:36 | 2017-01-24T08:19:36 | 74,054,537 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,313 |
c
|
main-master.c
|
/* [growbot] main-ms.c - 11/16/2016
* Name & E-mail: Joel Gomez - jgome043@ucr.edu
* CS Login: jgome043
* Partner(s) Name & E-mail:
* Lab Section: 022
* uC: ATmega1284P
* Exercise Description: RF Master
*
*
* I acknowledge all content contained herein, excluding template or example
* code, is my own original work.
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/portpins.h>
#include <avr/pgmspace.h>
//FreeRTOS include files
#include "FreeRTOS.h"
#include "task.h"
#include "croutine.h"
// CS122A include files
/* #include "usart_ATmega1284.h" */
// Growbot include files
#include "../../growbot/nrf24l01.c"
/* void SendDebug(unsigned char dbug) { */
/* if (dbug <= 255) { */
/* USART_Send(dbug,0); */
/* } */
/* else { */
/* USART_Send(dbug,0); */
/* } */
/* } */
// Task Periods
#define PERIOD_RADIO 100
// Task States
enum RadioState {RADIO_INIT,RADIO_WAIT,RADIO_REQ} radio_state;
// Radio Communication
void RadioInit() {
radio_state = RADIO_INIT;
uint8_t rx_address[5] = {0xD7,0xD7,0xD7,0xD7,0xD7};
uint8_t tx_address[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};
InitRadio(NRF_CH,PL_SIZE);
SetTransmitAddress(tx_address);
SetRadioAddress(rx_address);
}
void RadioTick() {
static unsigned char data[1];
static unsigned char low_water;
const unsigned char LOW_WATER = 0x80;
const unsigned char START_ROUTINE = 0x01;
const unsigned char STOP_ROUTINE = 0x02;
unsigned char btn = (~PIND & 0x80);
//Actions
switch (radio_state) {
case RADIO_INIT:
data[0] = STOP_ROUTINE;
low_water = 0;
break;
case RADIO_WAIT:
if (RadioDataReady()) {
unsigned char incoming = GetRadioData();
low_water = (incoming == LOW_WATER) ? 1 : 0;
}
if (low_water) {
PORTA |= (1<<1);
}
else {
PORTA &= ~(1<<1);
}
break;
default:
break;
}
//Transitions
switch (radio_state) {
case RADIO_INIT:
radio_state = RADIO_WAIT;
break;
case RADIO_WAIT:
if (btn && data[0] == STOP_ROUTINE) {
data[0] = START_ROUTINE;
SendRadioData(data);
PORTA |= (1<<0);
}
else if (btn && data[0] == START_ROUTINE) {
data[0] = STOP_ROUTINE;
SendRadioData(data);
PORTA &= ~(1<<0);
}
radio_state = (btn) ? RADIO_REQ : radio_state;
break;
case RADIO_REQ:
radio_state = (!btn) ? RADIO_WAIT : radio_state;
break;
default:
radio_state = RADIO_INIT;
break;
}
}
void RadioTask() {
RadioInit();
for(;;)
{
RadioTick();
vTaskDelay(PERIOD_RADIO);
}
}
void StartSecPulse(unsigned portBASE_TYPE Priority) {
xTaskCreate(RadioTask, (signed portCHAR *)"RadioTask",
configMINIMAL_STACK_SIZE, NULL, Priority, NULL );
}
int main(void) {
// Inputs, enable pull-up
DDRD = 0x00; PORTD=0xFF;
// Outputs
DDRA = 0xFF; PORTA=0x00;
DDRB = 0xFF; PORTB=0x00;
//Start Tasks
StartSecPulse(1);
//RunSchedular
vTaskStartScheduler();
return 0;
}
|
7e894cae43b50771a05ccd9addd3d56e11f15639
|
5e2164e5a58aa25fb566efb9c7875cc4f5f01e4b
|
/src/core/next_puyo.h
|
553545a371c1b384ff5e64523127a3815fecfe37
|
[
"CC-BY-4.0",
"MIT"
] |
permissive
|
YuriCat/puyoai
|
455e44f264e8c753146aa5fba3bcef8c393e4ffa
|
558056f3d345713b5124dd68bef33770569ba176
|
refs/heads/master
| 2021-01-14T08:55:45.061249 | 2016-11-24T04:58:06 | 2016-11-24T04:58:06 | 36,371,453 | 1 | 0 | null | 2015-05-27T14:15:34 | 2015-05-27T14:15:34 | null |
UTF-8
|
C
| false | false | 236 |
h
|
next_puyo.h
|
#ifndef CORE_NEXT_PUYO_H_
#define CORE_NEXT_PUYO_H_
enum class NextPuyoPosition {
CURRENT_AXIS,
CURRENT_CHILD,
NEXT1_AXIS,
NEXT1_CHILD,
NEXT2_AXIS,
NEXT2_CHILD,
};
const int NUM_NEXT_PUYO_POSITION = 6;
#endif
|
0e9626646e4eac641eac7291c6977bfe2c7f1ff1
|
cc1457a4ac67ae99959314a7bda31c8fba88806a
|
/Day12/ex02/incs/head.h
|
5d48f76d9ab3820fea78ff8039de8e00ce380df5
|
[] |
no_license
|
awoimbee/piscine-42-Juillet-2018
|
7ebf061bf39d11b2274ebf3735a230c5ca0e6eee
|
6f1a53061fa2eb064c10004cb6262f569510aa89
|
refs/heads/master
| 2021-10-15T10:36:40.965394 | 2018-10-18T23:28:38 | 2018-10-18T23:28:38 | 169,273,694 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,356 |
h
|
head.h
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* head.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: awoimbee <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/22 18:32:51 by awoimbee #+# #+# */
/* Updated: 2018/07/22 18:32:54 by awoimbee ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HEAD_H
# define HEAD_H
# include <fcntl.h>
# include <sys/types.h>
# include <sys/uio.h>
# include <unistd.h>
# include <stdlib.h>
# include <errno.h>
int ft_atoi(char *str);
int ft_strlen(char *str);
void print_str(char *str, int channel);
int ft_open(char* filename);
void reset_buff(char* buffer, int size);
void begin_read(int fd, int offset);
void end_read(int fd, int offset);
void prnt_head(char *fname);
int isoffsetlegal(char *str);
#endif
|
5bb9215cf3f2bcd79fe8c01f360b90b5bfdeb434
|
c464f8a70cd9e0bb365843b67537785b708921ce
|
/http.h
|
34cb3262276c6945420e0615a79b316cf5508811
|
[] |
no_license
|
keyur2808/Multi-Threaded-Web-Server
|
c9cdbdfa3b11892ff9c11eca734849ba7596643b
|
3a5cdb54090e3e0e256d86c9acb04bddcf77005e
|
refs/heads/master
| 2020-05-24T15:14:35.187294 | 2014-11-16T07:20:41 | 2014-11-16T07:20:41 | 26,706,928 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 557 |
h
|
http.h
|
#define NFND "HTTP/1.0 404 Not Found\r\n"
#define BRQ "HTTP/1.0 400 Bad Request\r\n"
#define MSG404 "<html><body><h1>FILE NOT FOUND</h1></body></html>"
#define MSG400 "<html><body><h1>REQUEST NOT SUPPORTED/BAD REQUEST</h1></body></html>"
#define RSPOK "HTTP/1.0 200 OK\r\n"
#define TXT "Content-Type: text/html\n"
#define GIF "Content-Type: image/gif\n"
#define LIST "<html>List of Files<br>"
#define TEXT "Content-Type: text/html\r\nContent-Length: 50\r\n\r\n"
#define SERVER "Server: SWEB/2.3.1\n"
|
b51495f1ca976f442f54272c51a9cedafaacecb5
|
1537a2342013bf0b439af0c3fd9d6d7e50277299
|
/Chapter10ex2.c
|
81e371dba95ad749c82c3667b80f2d2bd2916ec5
|
[] |
no_license
|
NBarnfield/C_Programming_Absolute_Beginners_Guide
|
a206102bcbe9ad4cdcb120d28686e087087e8441
|
b4ab7853e7feb5e02b63e8b7226ad1adad824353
|
refs/heads/master
| 2021-04-09T10:22:30.264291 | 2018-04-04T12:26:25 | 2018-04-04T12:26:25 | 125,340,011 | 6 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 995 |
c
|
Chapter10ex2.c
|
// Example program #2 from CHapter 10 of Absolute Beginner's Guide
// to C, 3rd Edition
// File Chapter10ex2.c
/* This program also increases a counter from 1 to 5, printing up-
dates and then counts it back down to 1. HOwever, it uses compound
operators. */
#include <stdio.h>
main()
{
int ctr = 0;
ctr += 1; // increases counter to 1
printf("Counter is at %d.\n", ctr);
ctr += 1; // increases counter to 2
printf("Counter is at %d.\n", ctr);
// Now lets incorporate the incremental change into the print statement.
printf("Counter is at %d.\n", ctr += 1);
ctr += 1; // increases counter to 4
printf("COunter is at %d.\n", ctr);
printf("Counter is at %d.\n", ctr += 1);
ctr -=1; // decreases counter to 4
printf("Counter is at %d.\n", ctr);
printf("Counter is at %d.\n", ctr -= 1);
printf("Counter is at %d.\n", ctr -= 1);
printf("Counter is at %d.\n", ctr -= 1);
printf("Counter is at %d.\n", ctr -= 1);
return 0;
}
|
488d80fd0dca3a4a80a435f3cc80005d2f7a1663
|
d2c9f96953540ac904568136980006983534148a
|
/kernel/interupt/workqueue_test.c
|
ae88b29c1528c284102fa7a7621c5f3d1cb271d5
|
[] |
no_license
|
bbrui/datastructure
|
9680df6befd02c146d2d0641fab80e008676d886
|
7ebbcc2e2f7eee8f83584b1b1cb7b30814c9243d
|
refs/heads/master
| 2021-09-24T11:32:16.369466 | 2018-10-09T03:26:43 | 2018-10-09T03:26:43 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,450 |
c
|
workqueue_test.c
|
#include <linux/module.h>
#include <linux/init.h>
#include <linux/workqueue.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
static struct workqueue_struct *queue = NULL;
static struct work_struct work;
static struct delayed_work test_dwq;
void delay_func(struct work_struct *work){
int i;
printk(KERN_INFO"My name is delay_func!\n");
for (i = 0; i < 3; i++){
printk(KERN_ERR"delay_fun: i=%d\n", i);
msleep(100);
}
}
static void work_handler(struct work_struct *data){
printk(KERN_ALERT"work handler functions. current->pid=%d\n", current->pid);
}
static int __init test_init(void){
int i, ret;
queue = create_workqueue("test_wq");
if (!queue)
goto err;
printk(KERN_INFO"Create workqueue successful\n");
INIT_DELAYED_WORK(&test_dwq, delay_func);
ret = queue_delayed_work(queue, &test_dwq, 5000);
printk(KERN_INFO"first ret=%d\n", ret);
for (i=0; i<3; i++){
printk(KERN_INFO"Example:ret=%d,i=%d\n", ret, i);
msleep(100);
}
ret = queue_delayed_work(queue, &test_dwq, 0);
printk(KERN_INFO"second ret=%d\n", ret);
return 0;
err:
return -1;
}
static void __exit test_exit(void){
int ret;
ret = cancel_delayed_work(&test_dwq);
flush_workqueue(queue);
destroy_workqueue(queue);
}
MODULE_LICENSE("GPL");
module_init(test_init);
module_exit(test_exit);
|
de7cd07500e2ea0fa49ac7046139e8ffc3dfc9fa
|
f1072da7dbff060ca7b538a81d3936571fec56ea
|
/src/cpe/dr/meta-inout/dr_builder_source.c
|
c4c1d3f44166e1f006e1320beffe9892923bb70e
|
[] |
no_license
|
Hkiller/workspace
|
e05374d30a6f309fa8cf1de83887ccb5d22736f9
|
660fc5900300786d7581a850a3fefc90f8d07a93
|
refs/heads/master
| 2021-03-30T22:44:17.469448 | 2017-04-12T06:08:02 | 2017-04-12T06:08:02 | 125,022,632 | 2 | 0 | null | 2018-03-13T09:07:03 | 2018-03-13T09:07:03 | null |
UTF-8
|
C
| false | false | 11,594 |
c
|
dr_builder_source.c
|
#include <assert.h>
#include "cpe/pal/pal_platform.h"
#include "cpe/pal/pal_string.h"
#include "cpe/utils/file.h"
#include "cpe/utils/buffer.h"
#include "cpe/utils/string_utils.h"
#include "cpe/dr/dr_metalib_builder.h"
#include "cpe/dr/dr_metalib_build.h"
#include "dr_builder_ops.h"
struct dr_metalib_source_relation *
dr_metalib_source_relation_create(dr_metalib_source_t user, dr_metalib_source_t using);
void dr_metalib_source_relation_free(struct dr_metalib_source_relation * relation);
uint32_t dr_metalib_source_hash(dr_metalib_source_t source) {
return cpe_hash_str(source->m_name, strlen(source->m_name));
}
int dr_metalib_source_cmp(dr_metalib_source_t l, dr_metalib_source_t r) {
return strcmp(l->m_name, r->m_name) == 0;
}
static dr_metalib_source_t
dr_metalib_source_create(
dr_metalib_builder_t builder, const char * name, size_t capacity,
dr_metalib_source_type_t type,
dr_metalib_source_format_t format,
dr_metalib_source_from_t from)
{
char * buf;
dr_metalib_source_t source;
size_t name_len;
assert(builder);
name_len = strlen(name) + 1;
CPE_PAL_ALIGN_DFT(name_len);
buf = mem_alloc(builder->m_alloc, name_len + sizeof(struct dr_metalib_source) + capacity);
if (buf == NULL) return NULL;
cpe_str_dup(buf, name_len, name);
source = (dr_metalib_source_t)(buf + name_len);
source->m_builder = builder;
source->m_name = buf;
source->m_type = type;
source->m_format = format;
source->m_from = from;
source->m_state = dr_metalib_source_state_not_analize;
source->m_capacity = capacity;
TAILQ_INIT(&source->m_includes);
TAILQ_INIT(&source->m_include_by);
TAILQ_INIT(&source->m_elements);
cpe_hash_entry_init(&source->m_hh);
if (cpe_hash_table_insert_unique(&builder->m_sources, source) != 0) {
mem_free(builder->m_alloc, buf);
return NULL;
}
TAILQ_INSERT_TAIL(&builder->m_sources_in_order, source, m_next);
return source;
}
dr_metalib_source_t
dr_metalib_builder_add_file(dr_metalib_builder_t builder, const char * name, const char * file) {
dr_metalib_source_t source;
struct mem_buffer name_buffer;
size_t file_len;
const char * suffix;
dr_metalib_source_format_t format;
assert(builder);
assert(file);
suffix = file_name_suffix(file);
if (suffix == NULL) return 0;
if (strcmp(suffix, "xml") == 0) {
format = dr_metalib_source_format_xml;
}
else {
return NULL;
}
mem_buffer_init(&name_buffer, 0);
if (name == NULL) {
name = file_name_base(file, &name_buffer);
if (name == NULL) {
mem_buffer_clear(&name_buffer);
return NULL;
}
}
assert(name);
file_len = strlen(file) + 1;
source = dr_metalib_source_create(builder, name, file_len, dr_metalib_source_type_file, format, dr_metalib_source_from_user);
if (source == NULL) {
mem_buffer_clear(&name_buffer);
return NULL;
}
memcpy(source + 1, file, file_len);
mem_buffer_clear(&name_buffer);
return source;
}
dr_metalib_source_t
dr_metalib_builder_add_buf(dr_metalib_builder_t builder, const char * name, dr_metalib_source_format_t format, const char * buf) {
dr_metalib_source_t source;
size_t buf_len;
assert(builder);
assert(buf);
buf_len = strlen(buf) + 1;
source = dr_metalib_source_create(builder, name, buf_len, dr_metalib_source_type_memory, format, dr_metalib_source_from_user);
if (source == NULL) return NULL;
memcpy(source + 1, buf, buf_len);
return source;
}
void dr_metalib_source_free(dr_metalib_source_t source) {
assert(source);
while(!TAILQ_EMPTY(&source->m_elements)) {
dr_metalib_source_element_free(TAILQ_FIRST(&source->m_elements));
}
while(!TAILQ_EMPTY(&source->m_includes)) {
dr_metalib_source_relation_free(TAILQ_FIRST(&source->m_includes));
}
while(!TAILQ_EMPTY(&source->m_include_by)) {
dr_metalib_source_relation_free(TAILQ_FIRST(&source->m_include_by));
}
TAILQ_REMOVE(&source->m_builder->m_sources_in_order, source, m_next);
cpe_hash_table_remove_by_ins(&source->m_builder->m_sources, source);
mem_free(source->m_builder->m_alloc, (void *)source->m_name);
}
dr_metalib_source_t
dr_metalib_source_find(dr_metalib_builder_t builder, const char * name) {
struct dr_metalib_source key;
key.m_name = name;
return (dr_metalib_source_t)cpe_hash_table_find(&builder->m_sources, &key);
}
const char * dr_metalib_source_name(dr_metalib_source_t source) {
return source->m_name;
}
const char * dr_metalib_source_file(dr_metalib_source_t source) {
return source->m_type == dr_metalib_source_type_file
? (const char *)(source + 1)
: NULL;
}
const void * dr_metalib_source_buf(dr_metalib_source_t source) {
return source->m_type == dr_metalib_source_type_memory
? (const void *)(source + 1)
: NULL;
}
size_t dr_metalib_source_buf_capacity(dr_metalib_source_t source) {
return source->m_type == dr_metalib_source_type_memory
? source->m_capacity
: 0;
}
int dr_metalib_source_add_include(dr_metalib_source_t user, dr_metalib_source_t using) {
assert(user);
assert(using);
return dr_metalib_source_relation_create(user, using) == NULL ? -1 : 0;
}
dr_metalib_source_t
dr_metalib_source_add_include_file(dr_metalib_source_t user_source, const char * name, const char * file, dr_metalib_source_from_t from) {
struct mem_buffer name_buffer;
dr_metalib_source_t using;
assert(user_source);
assert(file);
assert(user_source->m_builder);
mem_buffer_init(&name_buffer, 0);
if (name == NULL) {
name = file_name_base(file, &name_buffer);
if (name == NULL) {
mem_buffer_clear(&name_buffer);
return NULL;
}
}
assert(name);
using = dr_metalib_source_find(user_source->m_builder, name);
if (using == NULL) {
using = dr_metalib_builder_add_file(user_source->m_builder, name, file);
if (using == NULL) {
mem_buffer_clear(&name_buffer);
return NULL;
}
using->m_from = from;
}
assert(using);
mem_buffer_clear(&name_buffer);
return dr_metalib_source_add_include(user_source, using) == 0
? using
: NULL;
}
dr_metalib_source_type_t dr_metalib_source_type(dr_metalib_source_t source) {
return source->m_type;
}
dr_metalib_source_format_t dr_metalib_source_format(dr_metalib_source_t source) {
return source->m_format;
}
dr_metalib_source_from_t dr_metalib_source_from(dr_metalib_source_t source) {
return source->m_from;
}
dr_metalib_source_state_t dr_metalib_source_state(dr_metalib_source_t source) {
return source->m_state;
}
const char * dr_metalib_source_libname(dr_metalib_source_t source) {
dr_metalib_source_element_t e;
TAILQ_FOREACH(e, &source->m_elements, m_next) {
if (e->m_type == dr_metalib_source_element_type_lib) {
return dr_metalib_source_element_name(e);
}
}
return NULL;
}
static void dr_metalib_source_do_analize(dr_metalib_source_t source, const void * buf, size_t bufSize) {
if(source->m_format == dr_metalib_source_format_xml) {
dr_metalib_source_analize_xml(
source,
source->m_builder->m_inbuild_lib,
buf, (int)bufSize,
source->m_builder->m_em);
}
else {
CPE_ERROR(source->m_builder->m_em, "not support source format %d", source->m_format);
}
}
void dr_metalib_source_analize(dr_metalib_source_t source) {
assert(source);
if (source->m_state != dr_metalib_source_state_not_analize) return;
source->m_state = dr_metalib_source_state_analizing;
if(source->m_type == dr_metalib_source_type_file) {
struct mem_buffer buffer;
FILE * file;
const char * file_name;
file_name = dr_metalib_source_file(source);
assert(file_name);
file = file_stream_open(file_name, "r", source->m_builder->m_em);
if (file) {
ssize_t file_size;
mem_buffer_init(&buffer, 0);
file_size = file_stream_load_to_buffer(&buffer, file, source->m_builder->m_em);
if (file_size > 0) {
CPE_ERROR_SET_FILE(source->m_builder->m_em, file_name);
dr_metalib_source_do_analize(source, mem_buffer_make_continuous(&buffer, 0), file_size);
CPE_ERROR_SET_FILE(source->m_builder->m_em, 0);
}
mem_buffer_clear(&buffer);
file_stream_close(file, source->m_builder->m_em);
}
}
else if (source->m_type == dr_metalib_source_type_memory) {
CPE_ERROR_SET_FILE(source->m_builder->m_em, source->m_name);
dr_metalib_source_do_analize(source, source + 1, source->m_capacity);
CPE_ERROR_SET_FILE(source->m_builder->m_em, 0);
}
else {
CPE_ERROR(source->m_builder->m_em, "%s: not support type %d", source->m_name, source->m_type);
}
source->m_state = dr_metalib_source_state_analized;
}
struct dr_metalib_source_relation *
dr_metalib_source_relation_create(dr_metalib_source_t user, dr_metalib_source_t using) {
struct dr_metalib_source_relation * relation;
assert(using);
assert(user);
relation = mem_alloc(user->m_builder->m_alloc, sizeof(struct dr_metalib_source_relation));
if (relation == NULL) return NULL;
relation->m_user = user;
relation->m_using = using;
TAILQ_INSERT_TAIL(&user->m_includes, relation, m_next_for_includes);
TAILQ_INSERT_TAIL(&using->m_include_by, relation, m_next_for_include_by);
return relation;
}
void dr_metalib_source_relation_free(struct dr_metalib_source_relation * relation) {
TAILQ_REMOVE(&relation->m_user->m_includes, relation, m_next_for_includes);
TAILQ_REMOVE(&relation->m_using->m_include_by, relation, m_next_for_include_by);
mem_free(relation->m_using->m_builder->m_alloc, relation);
}
static
dr_metalib_source_t
dr_metalib_source_include_next(struct dr_metalib_source_it * it) {
struct dr_metalib_source_relation ** relation;
dr_metalib_source_t r;
relation = (struct dr_metalib_source_relation **)it->m_data;
if ((*relation) == NULL) return NULL;
r = (*relation)->m_using;
*relation = TAILQ_NEXT(*relation, m_next_for_includes);
return r;
}
void dr_metalib_source_includes(struct dr_metalib_source_it * it, dr_metalib_source_t source) {
struct dr_metalib_source_relation ** relation;
relation = (struct dr_metalib_source_relation **)it->m_data;
it->next = dr_metalib_source_include_next;
*relation = TAILQ_EMPTY(&source->m_includes)
? NULL
: TAILQ_FIRST(&source->m_includes);
}
static
dr_metalib_source_t
dr_metalib_source_include_by_next(struct dr_metalib_source_it * it) {
struct dr_metalib_source_relation ** relation;
dr_metalib_source_t r;
relation = (struct dr_metalib_source_relation **)it->m_data;
if ((*relation) == NULL) return NULL;
r = (*relation)->m_user;
*relation = TAILQ_NEXT(*relation, m_next_for_include_by);
return r;
}
void dr_metalib_source_include_by(struct dr_metalib_source_it * it, dr_metalib_source_t source) {
struct dr_metalib_source_relation ** relation;
relation = (struct dr_metalib_source_relation **)it->m_data;
it->next = dr_metalib_source_include_by_next;
*relation = TAILQ_EMPTY(&source->m_include_by)
? NULL
: TAILQ_FIRST(&source->m_include_by);
}
|
e0ea37529e9b87d9cd28c918fae11c1a172f693b
|
33c47488a4d845a579c07c71cf0ee332aeab8006
|
/libft/ft_lstdelone.c
|
4410f157ae3f0a90ee6cabbeb5d8669c2f2be18b
|
[] |
no_license
|
SouthPadre/gnl
|
d0539ad96cfc2a655eef814fc424fb74935a561f
|
18eba4830dfc6cfe02a288549929ce28823f3d9c
|
refs/heads/master
| 2020-06-02T03:52:49.593723 | 2019-06-09T15:55:34 | 2019-06-09T15:55:34 | 191,026,047 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,090 |
c
|
ft_lstdelone.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mraymon <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/08 20:30:35 by mraymon #+# #+# */
/* Updated: 2019/04/12 17:23:12 by mraymon ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
void ft_lstdelone(t_list **alst, void (*del)(void*, size_t))
{
t_list *a;
a = *alst;
del(a->content, a->content_size);
free(a);
a = NULL;
*alst = a;
}
|
daa0981565443945ade7fa29c691131f05ab14bf
|
842e3d4a611e08a1006b81add486608b0738fe0f
|
/umtp/message_parser.c
|
9e760033da0e515a0b05f762595b8c48e378f713
|
[
"BSD-3-Clause"
] |
permissive
|
drachenfels-de/libcx
|
77d725b450b16c5091bb9834e187ba207cb240bd
|
4266b987a1f6c4f04c2552a94ee06ab77ccf6c2f
|
refs/heads/master
| 2023-04-13T00:49:46.462931 | 2021-04-22T10:11:59 | 2021-04-22T10:11:59 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,114 |
c
|
message_parser.c
|
#include "message_parser.h"
static void
event_handler(RagelParser* parser, int event);
static void
simple_body_parser(RagelParser* parser);
MessageParser*
MessageParser_from_buf(StringBuffer* buffer, int keep_buffer)
{
MessageParser* parser = cx_alloc(sizeof(MessageParser));
RagelParser* ragel_parser = (RagelParser*)parser;
RagelParser_init(ragel_parser);
parser->message = Message_new();
parser->message->buffer = buffer;
parser->message->keep_buffer = keep_buffer;
ragel_parser->buffer = buffer;
// set buffer pointer
ragel_parser->buffer_position = buffer->string->value;
ragel_parser->buffer_end = ragel_parser->buffer_position;
/* setup event handlers */
ragel_parser->f_event = event_handler;
ragel_parser->f_parse = message_fsm_parse;
parser->f_body_parse = simple_body_parser;
parser->f_body_event = NULL;
return parser;
}
Message*
MessageParser_free(MessageParser* parser)
{
Message* message = parser->message;
cx_free(parser);
return message;
}
/* keep buffer, reset machine state and replace the machine and event handler */
void
MessageParser_parse_body(MessageParser* message_parser)
{
// replace parser and event handler
RagelParser* parser = (RagelParser*)message_parser;
parser->f_parse = message_parser->f_body_parse;
parser->f_event = message_parser->f_body_event;
}
static void
simple_body_parser(RagelParser* parser)
{
RagelParser_update(parser); // update position
// @optimize shift buffer up to body start
if (RagelParser_eof(parser))
{
size_t nunparsed = RagelParser_unparsed(parser);
assert(nunparsed > 0);
/* save remaining tokens in body */
StringPointer* body_pointer = StringPointer_new(Marker_get(parser), nunparsed);
((MessageParser*)parser)->message->body = body_pointer;
/* advance parser pointer to the end */
parser->buffer_position = parser->buffer_end;
}
parser->iterations++;
}
static void
event_handler(RagelParser* parser, int event)
{
MessageParser* message_parser = (MessageParser*)parser;
Message* message = message_parser->message;
// FIXME if marker length == 1 value is an empty string (set value to null instead ?)
XFDBG("Event %d, at index %zu [%c]",
event,
/* buffer already position points to next token */
parser->buffer_offset - 1,
*(parser->buffer_position - 1));
switch (event)
{
case P_ERROR_MESSAGE_MALFORMED:
// do error handling here
break;
case P_PROTOCOL_VALUE:
List_push(message->protocol_values, Marker_toS(parser));
break;
case P_HEADER_NAME:
{
String* header_name = Marker_toS(parser);
StringPair* header = StringPair_init(header_name, NULL);
List_push(message->headers, header);
break;
}
case P_HEADER_VALUE:
{
StringPair* header = (StringPair*)message->headers->last->data;
header->value = Marker_toS(parser);
break;
}
case P_BODY_START:
MessageParser_parse_body(message_parser);
return;
}
}
#define CHUNK_SIZE 1024
MessageParser*
MessageParser_fread(const char* path)
{
MessageParser* parser = MessageParser_new(CHUNK_SIZE);
RagelParser_parse_file((RagelParser*)parser, path, CHUNK_SIZE);
return parser;
}
|
0ef3fa046970e3ab635a90567778053d9d08911d
|
c1f581d9aeaf816eafed637df795cb4878dc0a7d
|
/HUBULLU/source.c
|
0812356f246a5759b3641a2715edfc3273f170a2
|
[] |
no_license
|
YashviRamanuj/spoj
|
1830e0864455c92102918e17aef1aa99439001ae
|
62904c7ca4c343981eca722daf58c15aae36c14d
|
refs/heads/master
| 2020-08-12T06:01:16.637906 | 2013-07-09T12:55:49 | 2013-07-09T12:55:49 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 197 |
c
|
source.c
|
#include <stdio.h>
int main() {
int t;
scanf("%d", &t);
while(t--) {
int N, P;
scanf("%d %d", &N, &P);
printf("%s wins.\n", (P == 0)? "Airborne": "Pagfloyd");
}
return 0;
}
|
9ac977c7f6eb80213a014c55098f471e1c1dc390
|
0d81a062738df441b490a43a6a322c98ff82b5da
|
/BSP/Inc/bsp_gpio.h
|
0a78cc27800f8856c7957bc86834eb5b9dd62852
|
[
"MIT"
] |
permissive
|
Se64s/STM32G0xx_BOOTLOADER
|
44794d4cf948e01d259e547374a47f2312bec1bd
|
a5df8a298cce1549f9b64d44d17dc3d14b34f4ae
|
refs/heads/main
| 2023-06-17T16:10:17.149257 | 2021-07-12T20:06:28 | 2021-07-12T20:06:28 | 385,365,679 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 901 |
h
|
bsp_gpio.h
|
/**
* @file bsp_gpio.h
* @author Sebastián Del Moral (sebmorgal@gmail.com)
* @brief Low-level initial setup.
* @version 0.1
* @date 2020-09-27
*
* @copyright Copyright (c) 2020
*
*/
/* Define to prevent recursive inclusion ------------------------------------*/
#ifndef __BSP_GPIO_H
#define __BSP_GPIO_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Exported includes --------------------------------------------------------*/
/* Exported defines ---------------------------------------------------------*/
/* Exported types -----------------------------------------------------------*/
/* Exported macro -----------------------------------------------------------*/
/* Exported functions prototypes --------------------------------------------*/
/**
* @brief Init GPIO interface.
*
*/
void BSP_Gpio_Init(void);
#ifdef __cplusplus
}
#endif
#endif /* __BSP_GPIO_H */
/*EOF*/
|
816806bac8178b9157794b2287458e695cb1709e
|
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
|
/source/freebsd/sys/geom/part/extr_g_part_apm.c_g_part_apm_probe.c
|
2b4fdddf02103fcdec775c48e201e6c2d78b4f55
|
[] |
no_license
|
isabella232/AnghaBench
|
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
|
9a5f60cdc907a0475090eef45e5be43392c25132
|
refs/heads/master
| 2023-04-20T09:05:33.024569 | 2021-05-07T18:36:26 | 2021-05-07T18:36:26 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,337 |
c
|
extr_g_part_apm.c_g_part_apm_probe.c
|
#define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
typedef struct TYPE_4__ TYPE_2__ ;
typedef struct TYPE_3__ TYPE_1__ ;
/* Type definitions */
struct g_provider {int mediasize; int sectorsize; } ;
struct g_part_table {scalar_t__ gpt_depth; } ;
struct TYPE_3__ {int ddr_sig; int ddr_blksize; int ddr_blkcount; } ;
struct TYPE_4__ {scalar_t__ ent_sig; int ent_pmblkcnt; int /*<<< orphan*/ ent_type; } ;
struct g_part_apm_table {int tivo_series1; TYPE_1__ ddr; TYPE_2__ self; } ;
struct g_consumer {struct g_provider* provider; } ;
/* Variables and functions */
scalar_t__ APM_DDR_SIG ;
scalar_t__ APM_ENT_SIG ;
int /*<<< orphan*/ APM_ENT_TYPE_SELF ;
int ENOSPC ;
int ENXIO ;
int G_PART_PROBE_PRI_NORM ;
int MIN (int,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ UINT32_MAX ;
int apm_read_ent (struct g_consumer*,int,TYPE_2__*,int) ;
int be16dec (char*) ;
int be32dec (char*) ;
int /*<<< orphan*/ g_free (char*) ;
char* g_read_data (struct g_consumer*,long,int,int*) ;
scalar_t__ strcmp (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
__attribute__((used)) static int
g_part_apm_probe(struct g_part_table *basetable, struct g_consumer *cp)
{
struct g_provider *pp;
struct g_part_apm_table *table;
char *buf;
int error;
/* We don't nest, which means that our depth should be 0. */
if (basetable->gpt_depth != 0)
return (ENXIO);
table = (struct g_part_apm_table *)basetable;
table->tivo_series1 = 0;
pp = cp->provider;
/* Sanity-check the provider. */
if (pp->mediasize < 4 * pp->sectorsize)
return (ENOSPC);
/* Check that there's a Driver Descriptor Record (DDR). */
buf = g_read_data(cp, 0L, pp->sectorsize, &error);
if (buf == NULL)
return (error);
if (be16dec(buf) == APM_DDR_SIG) {
/* Normal Apple DDR */
table->ddr.ddr_sig = be16dec(buf);
table->ddr.ddr_blksize = be16dec(buf + 2);
table->ddr.ddr_blkcount = be32dec(buf + 4);
g_free(buf);
if (table->ddr.ddr_blksize != pp->sectorsize)
return (ENXIO);
if (table->ddr.ddr_blkcount > pp->mediasize / pp->sectorsize)
return (ENXIO);
} else {
/*
* Check for Tivo drives, which have no DDR and a different
* signature. Those whose first two bytes are 14 92 are
* Series 2 drives, and aren't supported. Those that start
* with 92 14 are series 1 drives and are supported.
*/
if (be16dec(buf) != 0x9214) {
/* If this is 0x1492 it could be a series 2 drive */
g_free(buf);
return (ENXIO);
}
table->ddr.ddr_sig = APM_DDR_SIG; /* XXX */
table->ddr.ddr_blksize = pp->sectorsize; /* XXX */
table->ddr.ddr_blkcount =
MIN(pp->mediasize / pp->sectorsize, UINT32_MAX);
table->tivo_series1 = 1;
g_free(buf);
}
/* Check that there's a Partition Map. */
error = apm_read_ent(cp, 1, &table->self, table->tivo_series1);
if (error)
return (error);
if (table->self.ent_sig != APM_ENT_SIG)
return (ENXIO);
if (strcmp(table->self.ent_type, APM_ENT_TYPE_SELF))
return (ENXIO);
if (table->self.ent_pmblkcnt >= table->ddr.ddr_blkcount)
return (ENXIO);
return (G_PART_PROBE_PRI_NORM);
}
|
5d704ace500f2fba6ebaea06a3776176cbe11d72
|
91330996ca54bef1160cda72d24e8b544d93e8a3
|
/11/src/main.c
|
d230e45a7efdfb07cd26c19ad191e7f48cecfcef
|
[] |
no_license
|
jperezu/isel2019
|
160a27401571328490268a1ff1f3e20d533d01db
|
9e67d895d0bf714e7e287041aec62ae26b77ed0f
|
refs/heads/master
| 2022-01-21T00:47:38.284554 | 2019-05-28T11:17:46 | 2019-05-28T11:17:46 | 169,214,287 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 4,594 |
c
|
main.c
|
#include "esp_common.h"
#include "freertos/task.h"
#include "gpio.h"
#include "fsm.h"
#include "control_traffic_light.h"
#include "define_constants.h"
extern fsm_trans_t traffic_transition_table[];
char* get_color(int state);
/******************************************************************************
* FunctionName : user_rf_cal_sector_set
* Description : SDK just reversed 4 sectors, used for rf init data and paramters.
* We add this function to force users to set rf cal sector, since
* we don't know which sector is free in user's application.
* sector map for last several sectors : ABCCC
* A : rf cal
* B : rf init data
* C : sdk parameters
* Parameters : none
* Returns : rf cal sector
*******************************************************************************/
uint32 user_rf_cal_sector_set(void)
{
flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
// MAIN
void task_traffic(void* ignore)
{
portTickType xLastWakeTime;
GPIO_ConfigTypeDef io_conf;
io_conf.GPIO_IntrType = GPIO_PIN_INTR_NEGEDGE;
io_conf.GPIO_Mode = GPIO_Mode_Input;
io_conf.GPIO_Pin = BIT(MAIN_SENSOR);
io_conf.GPIO_Pullup = GPIO_PullUp_EN;
gpio_config(&io_conf);
io_conf.GPIO_IntrType = GPIO_PIN_INTR_NEGEDGE;
io_conf.GPIO_Mode = GPIO_Mode_Input;
io_conf.GPIO_Pin = BIT(SECONDARY_SENSOR);
io_conf.GPIO_Pullup = GPIO_PullUp_EN;
gpio_config(&io_conf);
fsm_t* fsm_main = (fsm_t*) new_traffic_fsm(traffic_transition_table, MAIN_SENSOR, SECONDARY_SENSOR, TIME_MAIN, TIME_SECONDARY, NULL);
fsm_t* fsm_secondary = (fsm_t*) new_traffic_fsm(traffic_transition_table, SECONDARY_SENSOR, MAIN_SENSOR, TIME_SECONDARY, TIME_MAIN, &fsm_main);
xLastWakeTime = xTaskGetTickCount ();
int color_main_next = 0;
int color_secondary_next = 0;
int timer = 0;
int timer_next = 0;
int timer_start = 0;
while(true) {
fsm_fire (fsm_main);
fsm_fire (fsm_secondary);
vTaskDelayUntil(&xLastWakeTime, PERIOD_TICK);
if (DEBUG){
int color_main = 100*(((traffic_fsm_t*) fsm_main) -> green) + 10*(((traffic_fsm_t*) fsm_main) -> ambar) + (((traffic_fsm_t*) fsm_main) -> red);
int color_secondary = 100*(((traffic_fsm_t*) fsm_secondary) -> green) + 10*(((traffic_fsm_t*) fsm_secondary) -> ambar) + (((traffic_fsm_t*) fsm_secondary) -> red);
int timer = xTaskGetTickCount()/100 - timer_start;
if(timer >= timer_next || timer == 0){
printf("\rPrincipal: %s \t Secundario: %s \t", get_color(color_main), get_color(color_secondary));
printf("Sensor_M: %d \t Sensor_S: %d \t", !GPIO_INPUT_GET(MAIN_SENSOR), !GPIO_INPUT_GET(SECONDARY_SENSOR));
printf("Contador: %d \t\t", timer);
fflush(stdout);
timer_next = timer + 1;
}
if (color_main != color_main_next || color_secondary != color_secondary_next){
timer_start = xTaskGetTickCount()/100;
color_main_next = color_main;
color_secondary_next = color_secondary;
}
}
}
delete_digit_fsm((traffic_fsm_t*) fsm_main);
delete_alarm_fsm((traffic_fsm_t*) fsm_secondary);
vTaskDelete(NULL);
}
char* get_color(int state){
switch (state){
case 1:
return (char*) "rojo";
case 10:
return (char*) "ambar";
case 100:
return (char*) "verde";
default:
return (char*) "error";
}
}
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void user_init(void)
{
xTaskCreate(&task_traffic, "fsm", 2048, NULL, 1, NULL);
}
|
31c1e81636e7256c53d83904f6a17c72881a080c
|
8087a29d4d8a26d82b510380447baacbf3198764
|
/exc4_2g.h
|
c474afbcc5ea65eb7588cb7d5ad9733d0dd0be47
|
[] |
no_license
|
theodontate/cpp_tuts
|
8ec970a82903394c57dac829917148cb3eeaba9c
|
d9711f861b421c659330559c414a0ed015b803c5
|
refs/heads/master
| 2021-01-21T13:08:31.369238 | 2016-04-23T19:13:59 | 2016-04-23T19:13:59 | 49,339,889 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 129 |
h
|
exc4_2g.h
|
#ifndef id347
#define id347
struct I {
int a;
};
void init ( I* b , int a);
void show ( I* b );
void cleanup (I* b);
#endif
|
cdc7393c87844fad88c85f8fada7b4dfa27084eb
|
a2f69ec30e6d9bd78b426aacb54e4b45925dfc99
|
/Labs/Lab1/lab1ques6.c
|
df19e878dc28d200f8b94b19c09890daf4261402
|
[] |
no_license
|
tullom/CompEng2SH4
|
9c4c80c7531edd86220784e146cf6b5402db95ec
|
79a4c3d8c50223f83e5b782955b10971cb7c0701
|
refs/heads/master
| 2020-07-24T22:39:15.586201 | 2019-11-26T13:24:59 | 2019-11-26T13:24:59 | 208,072,424 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 618 |
c
|
lab1ques6.c
|
//Matteo Tullo
//tullom
//400175089
//side1<=side2
#include <stdio.h>
int main(void) {
int counter = 0;
for (int side1=1;side1<401;side1++) {
for (int side2=1;side2<401;side2++) {
for (int side3=1;side3<401;side3++) {
float hypotenuse = (side1*side1)+(side2*side2); //c^2 = a^2+b^2
if (hypotenuse==(float)side3*side3 && side1<=side2) {
printf("%d %d %d\n",side1,side2,side3);counter++; //cast side3 to float to compare
}
}
}
}
printf("There were %d total triples.\n",counter);
return 0;
}
|
78043bae027e06031be4e85e4ed1f557cf4e3556
|
091f9992b31366ad4e4b2f0ea901e66cadbba5d5
|
/src/taskQueue.c
|
253a93efe42ef1e341add89ca8145dabc4be2094
|
[] |
no_license
|
asekerci-sudo/Embedded-Software-Project
|
f13c8aa2ef64e8db6087b8accb81ae1eba27b47f
|
c2c1e56f731dc150c4e5c70a931f4a01f802a31e
|
refs/heads/master
| 2023-08-28T20:06:11.522460 | 2021-10-13T16:22:19 | 2021-10-13T16:22:19 | 416,813,327 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 5,507 |
c
|
taskQueue.c
|
#include "bootcamp/taskQueue.h"
#include "bootcamp/task.h"
#include "bootcamp/uart.h"
struct priorityQueue{
uint8_t maxCapacity;
uint8_t elementsinQueue;
Task TaskArray[];
};
struct InterruptScheduler{
priorityQueuePTR ScheduleQueue;
};
priorityQueuePTR priorityQueueInit(uint8_t maxCapacity){
priorityQueuePTR initqueue = malloc(sizeof(priorityQueue)+ sizeof(Task) * maxCapacity);
initqueue -> maxCapacity = maxCapacity;
initqueue -> elementsinQueue = 0;
return initqueue;
}
void freeInterruptScheduler(Schedulerptr Schedulerptr){
free(Schedulerptr);
}
void executeTask(Task task){
task.placeholderFunction(task.arg);
if(task.periodic == false){
free(task.arg);
task.arg = NULL;
}
}
void freePriorityQueue(priorityQueuePTR prioptr){
free(prioptr);
}
void arrayElementDelete(priorityQueuePTR priorityQueue,uint8_t index){
for(index; index < (priorityQueue -> elementsinQueue); index++){
priorityQueue -> TaskArray[index] = priorityQueue -> TaskArray[index+1];
}
}
uint8_t enqueue(priorityQueuePTR priorityQueue,Task Task){
if(!(fullQueue(priorityQueue)))
{
if(emptyQueue(priorityQueue)){
priorityQueue -> TaskArray[0] = Task;
priorityQueue -> elementsinQueue += 1;
return 0;
}
else{
uint8_t index = 0;
while(index != (priorityQueue->elementsinQueue) && Task.priority > (priorityQueue -> TaskArray[index].priority)){
index = index + 1;
}
for(uint8_t movingIndex = (priorityQueue -> maxCapacity)-1; movingIndex > index; movingIndex--){
priorityQueue -> TaskArray[movingIndex] = priorityQueue -> TaskArray[movingIndex - 1];
}
priorityQueue -> TaskArray[index] = Task;
priorityQueue -> elementsinQueue += 1;
return 0;
}
}
return -1;
}
Task dequeue(priorityQueuePTR priorityQueue){
if(!(emptyQueue(priorityQueue))){
uint8_t index = 0;
Task TaskToReturn;
while(index != (priorityQueue->elementsinQueue)-1 && priorityQueue ->TaskArray[index].ready == false){
index = index + 1;
}
if(priorityQueue -> TaskArray[index].ready == true){
TaskToReturn = priorityQueue -> TaskArray[index];
arrayElementDelete(priorityQueue,index);
priorityQueue -> elementsinQueue -= 1;
return TaskToReturn;
}
}
}
int8_t dequeueWithtaskID(priorityQueuePTR priorityQueue,uint8_t searchedTaskID){
if(!(emptyQueue(priorityQueue))){
for(int i = 0; i < priorityQueue -> elementsinQueue; i++){
if(priorityQueue -> TaskArray[i].taskID == searchedTaskID){
free(priorityQueue -> TaskArray[i].arg);
priorityQueue->TaskArray[i].arg = NULL;
arrayElementDelete(priorityQueue,i);
priorityQueue -> elementsinQueue -= 1;
return 0;
}
}
}
return -1;
}
Schedulerptr InterruptSchedulerInit(priorityQueuePTR priorityQueue){
Schedulerptr initScheduler = malloc(sizeof(InterruptScheduler));
initScheduler -> ScheduleQueue = priorityQueue;
return initScheduler;
}
void InterruptSchedulerAdd(Schedulerptr scheduler, void (*taskFunction) (char * FunctionArg) ,uint8_t priority,uint32_t timetoStart,uint32_t timePeriod,bool periodic,bool ready,uint8_t taskID,char * arg){
if(!(fullQueue(scheduler -> ScheduleQueue))){
Task Task;
Task.priority = priority;
Task.placeholderFunction = taskFunction;
Task.timetoStart = timetoStart;
Task.timePeriod = timePeriod;
Task.ready = ready;
Task.periodic = periodic;
Task.taskID = taskID;
Task.arg = arg;
enqueue(scheduler -> ScheduleQueue, Task);
}
}
bool declareReady(Schedulerptr scheduler, uint32_t timer){
bool oneIsReady = false;
for (int x = 0; x < scheduler -> ScheduleQueue -> elementsinQueue; x++){
if((scheduler -> ScheduleQueue -> TaskArray[x].timetoStart) <= timer){
scheduler -> ScheduleQueue -> TaskArray[x].ready = true;
oneIsReady = true;
}
}
return oneIsReady;
}
void InterruptSchedulerMain(Schedulerptr schedule,uint32_t timer){
uint32_t timetoStart;
Task Task;
if(!(emptyQueue(schedule -> ScheduleQueue))){
bool oneIsReady = declareReady(schedule,timer);
if(oneIsReady){
//transmit_uart_char(49);
Task = dequeue(schedule -> ScheduleQueue);
executeTask(Task);
if(Task.periodic == true){
timetoStart = timer + (Task.timePeriod);
InterruptSchedulerAdd(schedule, Task.placeholderFunction, Task.priority, timetoStart, Task.timePeriod,Task.periodic,false,Task.taskID,Task.arg);
}
}
}
}
void InterruptSchedulerTimerIncrement(Schedulerptr scheduler,uint32_t *timer){
*timer = *timer + 1;
}
bool fullQueue(priorityQueuePTR priorityQueue){
return priorityQueue -> maxCapacity == priorityQueue -> elementsinQueue;
}
bool emptyQueue(priorityQueuePTR priorityQueue){
return priorityQueue -> elementsinQueue == 0;
}
uint8_t returnCapacity(priorityQueuePTR priorityQueue){
return priorityQueue -> maxCapacity;
}
uint8_t returnElements(priorityQueuePTR priorityQueue){
return priorityQueue -> elementsinQueue;
}
uint32_t returnCurrentTime(uint32_t timer){
return timer;
}
|
da14a87259b64694cf9e83ba261164f45a7b9548
|
06dc4966a9b25cc445d0bb4303607470d2031da7
|
/ios/Pods/Headers/Private/ABI38_0_0EXRandom/ABI38_0_0EXRandom.h
|
bb303e97f6596d9d6fb95ec34c82558af157a229
|
[
"MIT",
"Apache-2.0",
"BSD-3-Clause"
] |
permissive
|
akinncar/expo
|
ee5bf2f1fcbc18777faa2ecb58959ff613fa2ea0
|
d82f67b69180d75267db6c5857e4dd2064ae6bad
|
refs/heads/master
| 2022-12-08T22:17:49.680090 | 2020-09-09T21:22:50 | 2020-09-09T21:22:50 | 285,950,657 | 3 | 0 |
NOASSERTION
| 2020-09-07T17:53:13 | 2020-08-08T01:24:03 | null |
UTF-8
|
C
| false | false | 96 |
h
|
ABI38_0_0EXRandom.h
|
../../../../versioned-react-native/ABI38_0_0/Expo/EXRandom/ABI38_0_0EXRandom/ABI38_0_0EXRandom.h
|
bad26ea54be61fd7e2e8c75f2624a4e559696c5d
|
ba49422ae5c03151741e621c618569b9d3263eca
|
/glib/test_glib.c
|
fc859cd5d3db56e913be25f69011e36f4e49048a
|
[] |
no_license
|
dolphinsboy/code_for_c
|
af9c8429bb9d9ec6def553bb9819451a6d92102b
|
89efb315f7b4a6fb76075463efa0933bb1445b87
|
refs/heads/master
| 2019-04-02T21:44:30.001997 | 2017-06-05T07:15:06 | 2017-06-05T07:15:06 | 44,159,788 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,578 |
c
|
test_glib.c
|
#include <glib.h>
#include <locale.h>
static GMutex*mutex = NULL;
static gboolean t1_end = FALSE;
static gboolean t2_end = FALSE;
typedef struct _Arg Arg;
struct _Arg{
GMainLoop *loop;
gint max;
};
void run_1(Arg *arg)
{
int i;
for (i=0; i < arg->max; i++)
{
if (g_mutex_trylock(mutex) == FALSE)
{
g_print("%d: 线程2锁定互斥对象\n", i);
}else
{
//sleep 10 微秒
g_usleep(10);
}
}
t1_end = TRUE;
}
void run_2(Arg *arg)
{
int i;
for (i=0; i< arg->max; i++)
{
if (g_mutex_trylock(mutex) == FALSE)
{
g_print("%d:线程1锁定互斥对象\n", i);
}else
{
g_usleep(10);
}
}
t2_end = TRUE;
}
void run_3(Arg *arg)
{
for(;;)
{
if (t1_end && t2_end)
{
g_main_loop_quit(arg->loop);
break;
}
}
}
int main(int argc, char *argv[])
{
//解决中文问题
setlocale(LC_ALL, "");
GMainLoop *mloop;
Arg *arg;
g_thread_init(NULL);
mloop = g_main_loop_new(NULL, FALSE);
arg = g_new(Arg, 1);
arg->loop = mloop;
arg->max = 11;
mutex = g_mutex_new();
g_thread_create(run_1, arg, TRUE,NULL);
g_thread_create(run_2, arg, TRUE,NULL);
g_thread_create(run_3, arg, TRUE,NULL);
g_main_loop_run(mloop);
g_print("线程3退出事件循环\n");
//g_mutex_free(mutex);
g_print("释放互斥对象\n");
g_free(arg);
g_print("释放参数所用的内存\n");
}
|
acdf3d54f9e02c8c4085dbdfa16fac3d0fa620a6
|
81c33be68b9798015249e9f65246f837df85e638
|
/inputs/proteins/1dc1A/1dc1A.h
|
4422ffe0ecc60b403c0fdc5dc82f5aaafc2fa450
|
[] |
no_license
|
hoque3034/EAP
|
742968ac2a73ec0875b303da9a0d0fbddebe49e7
|
7697011c5ad6150e39a42334fb2033fe4378b6d1
|
refs/heads/master
| 2023-03-01T18:34:52.018569 | 2021-02-03T20:21:25 | 2021-02-03T20:21:25 | 335,725,174 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 6,706 |
h
|
1dc1A.h
|
#../chains/1dc1A
LYS A 5 K 26 13 13
PRO A 6 P 31 13 18
PHE A 7 F 41 33 8
GLU A 8 E 29 9 20
ASN A 9 N 25 6 19
HIS A 10 H 31 16 15
LEU A 11 L 35 26 9
LYS A 12 K 24 2 22
SER A 13 S 24 0 24
VAL A 14 V 29 18 11
ASP A 15 D 28 9 19
ASP A 16 D 35 12 23
LEU A 17 L 45 31 14
LYS A 18 K 40 15 25
THR A 19 T 41 29 12
THR A 20 T 29 5 24
TYR A 21 Y 23 6 17
GLU A 22 E 19 0 19
GLU A 23 E 29 15 14
TYR A 24 Y 31 17 14
ARG A 25 R 21 0 21
ALA A 26 A 23 1 22
GLY A 27 G 32 17 15
PHE A 28 F 30 9 21
ILE A 29 I 20 0 20
ALA A 30 A 27 3 24
PHE A 31 F 34 19 15
ALA A 32 A 24 4 20
LEU A 33 L 18 1 17
GLU A 34 E 26 9 17
LYS A 35 K 28 15 13
ASN A 36 N 22 2 20
LYS A 37 K 20 0 20
ARG A 38 R 27 11 16
SER A 39 S 28 19 9
THR A 40 T 19 2 17
PRO A 41 P 21 1 20
TYR A 42 Y 33 19 14
ILE A 43 I 28 10 18
GLU A 44 E 20 0 20
ARG A 45 R 32 11 21
ALA A 46 A 34 20 14
ARG A 47 R 24 1 23
ALA A 48 A 24 1 23
LEU A 49 L 37 23 14
LYS A 50 K 35 16 19
VAL A 51 V 23 0 23
ALA A 52 A 29 9 20
ALA A 53 A 39 29 10
SER A 54 S 30 13 17
VAL A 55 V 22 1 21
ALA A 56 A 31 23 8
LYS A 57 K 23 1 22
THR A 58 T 27 5 22
PRO A 59 P 39 29 10
LYS A 60 K 33 8 25
ASP A 61 D 27 4 23
LEU A 62 L 39 27 12
LEU A 63 L 34 17 17
TYR A 64 Y 23 0 23
LEU A 65 L 25 16 9
GLU A 66 E 20 2 18
ASP A 67 D 22 4 18
ILE A 68 I 34 25 9
GLN A 69 Q 35 18 17
ASP A 70 D 34 7 27
ALA A 71 A 46 23 23
LEU A 72 L 54 32 22
LEU A 73 L 43 19 24
TYR A 74 Y 43 18 25
ALA A 75 A 49 25 24
SER A 76 S 42 22 20
GLY A 77 G 39 12 27
ILE A 78 I 37 20 17
SER A 79 S 32 13 19
ASP A 80 D 26 7 19
LYS A 81 K 17 2 15
ALA A 82 A 21 4 17
LYS A 83 K 27 21 6
LYS A 84 K 16 0 16
PHE A 85 F 14 0 14
LEU A 86 L 21 17 4
THR A 87 T 15 0 15
GLU A 88 E 18 3 15
ASP A 89 D 15 1 14
ASP A 90 D 21 6 15
LYS A 91 K 30 17 13
LYS A 92 K 30 9 21
GLU A 93 E 25 2 23
SER A 94 S 32 10 22
ILE A 95 I 42 25 17
ASN A 96 N 32 8 24
ASN A 97 N 28 2 26
LEU A 98 L 39 20 19
ILE A 99 I 41 24 17
GLU A 100 E 26 1 25
ASN A 101 N 23 1 22
PHE A 102 F 31 12 19
LEU A 103 L 37 25 12
GLU A 104 E 26 9 17
PRO A 105 P 21 1 20
ALA A 106 A 22 11 11
GLY A 107 G 21 9 12
GLU A 108 E 17 3 14
GLU A 109 E 23 5 18
PHE A 110 F 33 17 16
ILE A 111 I 40 20 20
ASP A 112 D 34 8 26
GLU A 113 E 36 13 23
LEU A 114 L 54 32 22
ILE A 115 I 42 16 26
PHE A 116 F 32 1 31
ARG A 117 R 38 15 23
TYR A 118 Y 44 26 18
LEU A 119 L 37 15 22
LEU A 120 L 28 2 26
PHE A 121 F 32 13 19
GLN A 122 Q 38 25 13
GLY A 123 G 32 13 19
ASP A 124 D 26 5 21
SER A 125 S 33 12 21
LEU A 126 L 31 15 16
GLY A 127 G 26 6 20
GLY A 128 G 23 3 20
THR A 129 T 28 9 19
MET A 130 M 31 16 15
ARG A 131 R 31 10 21
ASN A 132 N 24 1 23
ILE A 133 I 31 12 19
ALA A 134 A 37 19 18
GLY A 135 G 37 17 20
ALA A 136 A 32 11 21
LEU A 137 L 37 11 26
ALA A 138 A 46 21 25
GLN A 139 Q 48 20 28
GLN A 140 Q 39 15 24
LYS A 141 K 42 12 30
LEU A 142 L 58 33 25
THR A 143 T 55 29 26
ARG A 144 R 39 12 27
ALA A 145 A 42 15 27
ILE A 146 I 56 25 31
ILE A 147 I 49 28 21
SER A 148 S 36 9 27
ALA A 149 A 35 15 20
LEU A 150 L 38 18 20
ASP A 151 D 31 12 19
ILE A 152 I 19 1 18
ALA A 153 A 22 10 12
ASN A 154 N 19 1 18
ILE A 155 I 30 17 13
PRO A 156 P 32 7 25
TYR A 157 Y 41 31 10
LYS A 158 K 39 10 29
TRP A 159 W 42 25 17
LEU A 160 L 36 17 19
ASP A 161 D 33 12 21
SER A 162 S 28 13 15
ARG A 163 R 19 4 15
ASP A 164 D 16 5 11
LYS A 165 K 16 3 13
LYS A 166 K 12 0 12
TYR A 167 Y 25 19 6
THR A 168 T 23 3 20
ASN A 169 N 22 3 19
TRP A 170 W 30 18 12
MET A 171 M 29 12 17
ASP A 172 D 25 3 22
LYS A 173 K 33 26 7
PRO A 174 P 23 10 13
GLU A 175 E 18 3 15
ASP A 176 D 17 1 16
ASP A 177 D 32 28 4
TYR A 178 Y 20 1 19
GLU A 179 E 24 7 17
LEU A 180 L 35 19 16
GLU A 181 E 38 24 14
THR A 182 T 31 8 23
PHE A 183 F 36 10 26
ALA A 184 A 46 27 19
LYS A 185 K 45 17 28
GLY A 186 G 48 21 27
ILE A 187 I 56 29 27
SER A 188 S 45 22 23
TRP A 189 W 42 22 20
THR A 190 T 32 8 24
ILE A 191 I 26 17 9
ASN A 192 N 15 0 15
GLY A 193 G 15 0 15
LYS A 194 K 23 9 14
HIS A 195 H 28 7 21
ARG A 196 R 37 21 16
THR A 197 T 45 17 28
LEU A 198 L 51 24 27
MET A 199 M 49 23 26
TYR A 200 Y 45 26 19
ASN A 201 N 32 13 19
ILE A 202 I 33 19 14
THR A 203 T 25 3 22
VAL A 204 V 36 28 8
SER A 205 S 23 2 21
LEU A 206 L 32 16 16
VAL A 207 V 31 17 14
LYS A 208 K 20 2 18
LYS A 209 K 31 13 18
ASN A 210 N 27 5 22
VAL A 211 V 43 31 12
ASP A 212 D 40 16 24
ILE A 213 I 52 30 22
CYS A 214 C 50 21 29
LEU A 215 L 48 23 25
PHE A 216 F 39 16 23
ASN A 217 N 34 13 21
CYS A 218 C 29 6 23
GLU A 219 E 29 10 19
PRO A 220 P 30 16 14
GLN A 230 Q 20 11 9
GLN A 231 Q 21 4 17
PRO A 232 P 34 25 9
GLU A 233 E 29 8 21
LYS A 234 K 32 11 21
TYR A 235 Y 43 29 14
LEU A 236 L 37 11 26
LEU A 237 L 47 20 27
LEU A 238 L 55 33 22
GLY A 239 G 51 24 27
GLU A 240 E 52 21 31
LEU A 241 L 53 30 23
LYS A 242 K 51 21 30
GLY A 243 G 47 24 23
GLY A 244 G 45 16 29
ILE A 245 I 46 22 24
ASP A 246 D 36 8 28
PRO A 247 P 34 21 13
ALA A 248 A 22 0 22
GLY A 249 G 27 9 18
ALA A 250 A 38 28 10
ASP A 251 D 31 12 19
GLU A 252 E 24 0 24
HIS A 253 H 34 13 21
TRP A 254 W 41 28 13
LYS A 255 K 29 5 24
THR A 256 T 26 2 24
ALA A 257 A 39 22 17
ASN A 258 N 38 18 20
THR A 259 T 26 1 25
ALA A 260 A 36 17 19
LEU A 261 L 45 24 21
THR A 262 T 32 4 28
ARG A 263 R 31 6 25
ILE A 264 I 46 28 18
ARG A 265 R 40 20 20
ASN A 266 N 26 1 25
LYS A 267 K 26 6 20
PHE A 268 F 32 20 12
SER A 269 S 22 7 15
GLU A 270 E 17 2 15
LYS A 271 K 21 9 12
GLY A 272 G 17 0 17
LEU A 273 L 23 15 8
SER A 274 S 29 9 20
PRO A 275 P 42 25 17
LYS A 276 K 44 14 30
THR A 277 T 50 25 25
ILE A 278 I 52 24 28
PHE A 279 F 58 30 28
ILE A 280 I 59 27 32
GLY A 281 G 58 27 31
ALA A 282 A 52 25 27
ALA A 283 A 49 20 29
ILE A 284 I 46 27 19
GLU A 285 E 40 14 26
HIS A 286 H 28 10 18
SER A 287 S 27 0 27
MET A 288 M 38 20 18
ALA A 289 A 41 23 18
GLU A 290 E 28 4 24
GLU A 291 E 31 6 25
ILE A 292 I 46 27 19
TRP A 293 W 38 19 19
ASP A 294 D 29 0 29
GLN A 295 Q 29 11 18
LEU A 296 L 34 20 14
GLN A 297 Q 24 7 17
SER A 298 S 16 0 16
GLY A 299 G 23 12 11
SER A 300 S 33 10 23
LEU A 301 L 39 24 15
THR A 302 T 37 12 25
ASN A 303 N 51 19 32
SER A 304 S 66 37 29
ALA A 305 A 56 24 32
ASN A 306 N 52 25 27
LEU A 307 L 51 27 24
THR A 308 T 45 21 24
LYS A 309 K 38 18 20
THR A 310 T 33 12 21
GLU A 311 E 27 4 23
GLN A 312 Q 40 22 18
VAL A 313 V 46 25 21
GLY A 314 G 38 13 25
SER A 315 S 34 7 27
LEU A 316 L 47 25 22
CYS A 317 C 47 23 24
ARG A 318 R 36 11 25
TRP A 319 W 35 11 24
ILE A 320 I 53 30 23
ILE A 321 I 44 27 17
ASN A 322 N 32 5 27
ILE A 323 I 38 27 11
|
52958763a0d032725b1c6ceb019f37adfb9e562a
|
3aace9ec2a3ddf638113e68f9ee99980341af246
|
/hfloat/src/hfloat.c
|
69ec35eee04e85f4e76cc0d33bebfc8913f70498
|
[] |
no_license
|
PitchBlack07/Playground
|
43ee8a8309c9bc9b0c3bcbb7768f96bca3b7737e
|
6866dd117e46b6618276a29fa1522020cffabd67
|
refs/heads/master
| 2021-06-25T22:32:50.883183 | 2019-03-29T19:07:18 | 2019-03-29T19:07:18 | 93,295,801 | 0 | 0 | null | 2019-03-29T19:07:19 | 2017-06-04T06:54:00 |
C++
|
UTF-8
|
C
| false | false | 8,591 |
c
|
hfloat.c
|
#include <hfloat/hfloat.h>
#include <string.h>
#include <intrin.h>
#pragma intrinsic(_BitScanReverse)
//
// from ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf
//
static const uint16_t btable[] =
{
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100,
0x0200, 0x0400, 0x0800, 0x0c00, 0x1000, 0x1400, 0x1800, 0x1c00, 0x2000, 0x2400, 0x2800, 0x2c00, 0x3000, 0x3400, 0x3800, 0x3c00,
0x4000, 0x4400, 0x4800, 0x4c00, 0x5000, 0x5400, 0x5800, 0x5c00, 0x6000, 0x6400, 0x6800, 0x6c00, 0x7000, 0x7400, 0x7800, 0x7c00,
0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8001, 0x8002, 0x8004, 0x8008, 0x8010, 0x8020, 0x8040, 0x8080, 0x8100,
0x8200, 0x8400, 0x8800, 0x8c00, 0x9000, 0x9400, 0x9800, 0x9c00, 0xa000, 0xa400, 0xa800, 0xac00, 0xb000, 0xb400, 0xb800, 0xbc00,
0xc000, 0xc400, 0xc800, 0xcc00, 0xd000, 0xd400, 0xd800, 0xdc00, 0xe000, 0xe400, 0xe800, 0xec00, 0xf000, 0xf400, 0xf800, 0xfc00,
0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00,
};
static const int8_t stable[] =
{
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f,
0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0d,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f,
0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0d
};
hfloat convert_float_to_hfloat(float f_)
{
uint32_t f;
memcpy(&f, &f_, sizeof(f_));
return btable[(f >> 23) & 0x1ff] + ((f & 0x007fffff) >> stable[(f >> 23) & 0x1ff]);
}
static float uint_to_float(uint32_t v)
{
float f;
memcpy(&f, &v, sizeof(f));
return f;
}
float convert_hfloat_to_float(hfloat f_)
{
static const uint32_t HALF_FLOAT_MANTISSA_BITS = 10;
uint32_t sign = ((uint32_t)(f_ & 0x8000)) << 16;
uint32_t m = (uint32_t)(f_ & 0x03FF);
int32_t e = (int32_t)((f_ & 0x7C00));
if (e > 0x00 && e < 0x7C00)
{
// normalized number
return uint_to_float(sign | ((e + 0x1C000) << 13) | (m << 13));
}
else if ((f_ & 0x7FFFF) == 0)
{
return 0.f;
}
else if (e == 0x00)
{
uint32_t msb; // index of most signficant bit
_BitScanReverse(&msb, m);
// shift
const uint32_t dexp = 10 - msb;
const uint32_t fexp = 127 - 14 - dexp;
const uint32_t fm = m << (13 + dexp);
return uint_to_float(sign | (fexp << 23) | (fm & 0x7FFFFF));
}
else if (m == 0)
{
return uint_to_float(sign | 0xFF << 23);
}
else
{
return uint_to_float(sign | (0xFF << 23) | (0x7FFFFF));
}
}
|
c518fd427c78e71346f893f09ec523f52c8f3ff3
|
131b6d5381fc3bb4403682135b77f9bce91e79f1
|
/nx/include/switch/services/pgl.h
|
5b3a882481525bfde9b29895150ab9bdce0b3e57
|
[
"ISC"
] |
permissive
|
switchbrew/libnx
|
53deb695b9ee6f3981c559125e8fce3bce6852b7
|
4fcdb6eb34b20f1f65eb9791fe513a710a001bea
|
refs/heads/master
| 2023-08-28T17:00:22.025929 | 2023-08-11T04:11:38 | 2023-08-12T14:51:58 | 103,794,142 | 1,286 | 299 |
ISC
| 2023-09-09T12:08:36 | 2017-09-17T01:12:38 |
C
|
UTF-8
|
C
| false | false | 2,391 |
h
|
pgl.h
|
/**
* @file pgl.h
* @brief PGL service IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../sf/service.h"
#include "../sf/tipc.h"
#include "../services/ncm_types.h"
#include "../services/pm.h"
/// LaunchFlag
typedef enum {
PglLaunchFlag_None = 0,
PglLaunchFlag_EnableDetailedCrashReport = BIT(0),
PglLaunchFlag_EnableCrashReportScreenShotForProduction = BIT(1),
PglLaunchFlag_EnableCrashReportScreenShotForDevelop = BIT(2),
} PglLaunchFlag;
/// SnapShotDumpType
typedef enum {
PglSnapShotDumpType_None = 0,
PglSnapShotDumpType_Auto = 1,
PglSnapShotDumpType_Full = 2,
} PglSnapShotDumpType;
typedef struct {
u64 id; ///< Program Id
u32 version; ///< Version
u8 content_type; ///< NcmContentType
u8 id_offset; ///< Id Offset
u8 reserved_0E[2]; ///< Padding
} PglContentMetaInfo;
typedef union {
Service s;
TipcService t;
} PglEventObserver;
/// Initialize pgl.
Result pglInitialize(void);
/// Exit pgl.
void pglExit(void);
/// Gets the Service object for the actual pgl service session. Requires < 12.0.0
Service* pglGetServiceSessionCmif(void);
/// Gets the TipcService object for the actual pgl service session. Requires 12.0.0+
TipcService* pglGetServiceSessionTipc(void);
Result pglLaunchProgram(u64 *out_pid, const NcmProgramLocation *loc, u32 pm_launch_flags, u8 pgl_launch_flags);
Result pglTerminateProcess(u64 pid);
Result pglLaunchProgramFromHost(u64 *out_pid, const char *content_path, u32 pm_launch_flags);
Result pglGetHostContentMetaInfo(PglContentMetaInfo *out, const char *content_path);
Result pglGetApplicationProcessId(u64 *out);
Result pglBoostSystemMemoryResourceLimit(u64 size);
Result pglIsProcessTracked(bool *out, u64 pid);
Result pglEnableApplicationCrashReport(bool en);
Result pglIsApplicationCrashReportEnabled(bool *out);
Result pglEnableApplicationAllThreadDumpOnCrash(bool en);
Result pglTriggerApplicationSnapShotDumper(PglSnapShotDumpType dump_type, const char *arg);
Result pglGetEventObserver(PglEventObserver *out);
Result pglEventObserverGetProcessEvent(PglEventObserver *observer, Event *out);
Result pglEventObserverGetProcessEventInfo(PglEventObserver *observer, PmProcessEventInfo *out);
void pglEventObserverClose(PglEventObserver *observer);
|
26d54b51b98d23f5de7bfdc3823a998e9c4ee60a
|
f8af93ce1ab3e2d6c028965f5f59a5f26d620f85
|
/Definitions.h
|
ffac4cddc24970ef2e474ae5b84bf9225e3eb994
|
[] |
no_license
|
valeriirud/file_manager
|
bb1e09108c250cf9722f4fd86b96b735d77b687c
|
0c15cb3deec479a6c58840c34b5929ebf05c69ae
|
refs/heads/main
| 2023-03-30T08:47:59.021376 | 2021-03-31T12:55:26 | 2021-03-31T12:55:26 | 349,066,472 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 582 |
h
|
Definitions.h
|
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#define DOMAIN_NAME "fm"
#define APPLICATION_NAME "fm.app"
#define APPLICATION_TITLE "File Manager 0.1"
#define CMD_COPY "rsync -ah --progress \"%1\" \"%2\""
#define CMD_DELETE "rm -rfv \"%1\""
#define CMD_MOVE "mv \"%1\" \"%2\""
#define CMD_SIZE "du -h %1"
#define CMD_ZIP "zip -rdbj \"%1\" \"%2\""
#define CMD_UNZIP "unzip -d \"%1\" \"%2\""
#define ITEM_ICON 0
#define ITEM_NAME 1
#define ITEM_TYPE 2
#define ITEM_SIZE 3
#define ITEM_OWNER 4
#define ITEM_DATE 5
#define ITEMS_COUNT 6
#endif // DEFINITIONS_H
|
1a710b11d495ed72fac554aae6a44f778b235ec7
|
973314e78f73fbc3c9f85c7d5906965434fe0b1d
|
/src/genarm/cham_arm_cortex_m3.c
|
2eb50b6c8ed438113a184344be4f1c31ad2c1a8f
|
[
"MIT"
] |
permissive
|
rweather/lightweight-crypto
|
a94e376dab758643d990570d8c9042d58f73c31a
|
fa4ec9a021b9233263de77e7dd971de8c9761495
|
refs/heads/master
| 2022-06-24T16:51:14.896518 | 2022-06-10T21:27:41 | 2022-06-10T21:27:41 | 231,153,188 | 56 | 12 |
MIT
| 2020-09-25T06:52:16 | 2019-12-31T22:36:30 |
C
|
UTF-8
|
C
| false | false | 19,096 |
c
|
cham_arm_cortex_m3.c
|
/*
* Copyright (C) 2020 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* This program is used to generate the assembly code version of the
* CHAM block cipher for ARM Cortex M3 microprocessors. With minor
* modifications, this can probably also be used to generate assembly
* code versions for other Cortex M variants such as M4, M7, M33, etc.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void function_header(const char *name)
{
printf("\n\t.align\t2\n");
printf("\t.global\t%s\n", name);
printf("\t.thumb\n");
printf("\t.thumb_func\n");
printf("\t.type\t%s, %%function\n", name);
printf("%s:\n", name);
}
static void function_footer(const char *name)
{
printf("\t.size\t%s, .-%s\n", name, name);
}
/* List of all registers that we can work with */
typedef struct
{
const char *x0;
const char *x1;
const char *x2;
const char *x3;
const char *k0;
const char *k1;
const char *k2;
const char *k3;
const char *k4;
const char *k5;
const char *k6;
const char *k7;
const char *t0;
const char *t1;
} reg_names;
/*
* r0 holds the pointer to the CHAM key.
* r1 points to the output buffer.
* r2 points to the input buffer.
*
* r0, r1, r2, r3, and ip can be used as scratch registers without saving,
* but the value of ip may not survive across a branch instruction.
*
* r4, r5, r6, r7, r8, r9, r10, and fp must be callee-saved.
*
* lr can be used as a temporary as long as it is saved on the stack.
*/
/* Generate the body of the CHAM-128 block cipher encrypt function */
static void gen_encrypt_cham128(void)
{
reg_names regs;
int round;
regs.x0 = "r3";
regs.x1 = "r4";
regs.x2 = "r5";
regs.x3 = "r6";
regs.k0 = "r2";
regs.k1 = "r7";
regs.k2 = "r8";
regs.k3 = "r9";
regs.k4 = "r10";
regs.k5 = "r0";
regs.k6 = "fp";
regs.k7 = "lr";
regs.t0 = "r1";
regs.t1 = "ip";
printf("\tpush\t{r4, r5, r6, r7, r8, r9, r10, fp, lr}\n");
/* Save r1 on the stack because we need it for temporaries */
printf("\tpush\t{r1}\n");
/* Load all words of the state and the key into registers */
printf("\tldr\t%s, [r2, #%d]\n", regs.x0, 0);
printf("\tldr\t%s, [r2, #%d]\n", regs.x1, 4);
printf("\tldr\t%s, [r2, #%d]\n", regs.x2, 8);
printf("\tldr\t%s, [r2, #%d]\n", regs.x3, 12);
printf("\tldr\t%s, [r0, #%d]\n", regs.k0, 0);
printf("\tldr\t%s, [r0, #%d]\n", regs.k1, 4);
printf("\tldr\t%s, [r0, #%d]\n", regs.k2, 8);
printf("\tldr\t%s, [r0, #%d]\n", regs.k3, 12);
/* Generate the key schedule:
*
* k[4] = k[1] ^ leftRotate1(k[1]) ^ leftRotate11(k[1]);
* k[5] = k[0] ^ leftRotate1(k[0]) ^ leftRotate11(k[0]);
* k[6] = k[3] ^ leftRotate1(k[3]) ^ leftRotate11(k[3]);
* k[7] = k[2] ^ leftRotate1(k[2]) ^ leftRotate11(k[2]);
* k[0] ^= leftRotate1(k[0]) ^ leftRotate8(k[0]);
* k[1] ^= leftRotate1(k[1]) ^ leftRotate8(k[1]);
* k[2] ^= leftRotate1(k[2]) ^ leftRotate8(k[2]);
* k[3] ^= leftRotate1(k[3]) ^ leftRotate8(k[3]);
*/
printf("\teor\t%s, %s, %s, ror #31\n", regs.k4, regs.k1, regs.k1);
printf("\teor\t%s, %s, %s, ror #31\n", regs.k5, regs.k0, regs.k0);
printf("\teor\t%s, %s, %s, ror #31\n", regs.k6, regs.k3, regs.k3);
printf("\teor\t%s, %s, %s, ror #31\n", regs.k7, regs.k2, regs.k2);
printf("\teor\t%s, %s, %s, ror #21\n", regs.k4, regs.k4, regs.k1);
printf("\teor\t%s, %s, %s, ror #21\n", regs.k5, regs.k5, regs.k0);
printf("\teor\t%s, %s, %s, ror #21\n", regs.k6, regs.k6, regs.k3);
printf("\teor\t%s, %s, %s, ror #21\n", regs.k7, regs.k7, regs.k2);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t0, regs.k0, regs.k0);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t1, regs.k1, regs.k1);
printf("\teor\t%s, %s, %s, ror #24\n", regs.k0, regs.t0, regs.k0);
printf("\teor\t%s, %s, %s, ror #24\n", regs.k1, regs.t1, regs.k1);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t0, regs.k2, regs.k2);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t1, regs.k3, regs.k3);
printf("\teor\t%s, %s, %s, ror #24\n", regs.k2, regs.t0, regs.k2);
printf("\teor\t%s, %s, %s, ror #24\n", regs.k3, regs.t1, regs.k3);
/* Unroll all 80 rounds, 8 at a time */
for (round = 0; round < 80; round += 8) {
/* x0 = leftRotate8((x0 ^ round) + (leftRotate1(x1) ^ k[0])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x0, round);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t1, regs.k0, regs.x1);
printf("\tadd\t%s, %s, %s\n", regs.x0, regs.t1, regs.t0);
printf("\tror\t%s, %s, #24\n", regs.x0, regs.x0);
/* x1 = leftRotate1((x1 ^ (round + 1)) + (leftRotate8(x2) ^ k[1])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x1, round + 1);
printf("\teor\t%s, %s, %s, ror #24\n", regs.t1, regs.k1, regs.x2);
printf("\tadd\t%s, %s, %s\n", regs.x1, regs.t1, regs.t0);
printf("\tror\t%s, %s, #31\n", regs.x1, regs.x1);
/* x2 = leftRotate8((x2 ^ (round + 2)) + (leftRotate1(x3) ^ k[2])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x2, round + 2);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t1, regs.k2, regs.x3);
printf("\tadd\t%s, %s, %s\n", regs.x2, regs.t1, regs.t0);
printf("\tror\t%s, %s, #24\n", regs.x2, regs.x2);
/* x3 = leftRotate1((x3 ^ (round + 3)) + (leftRotate8(x0) ^ k[3])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x3, round + 3);
printf("\teor\t%s, %s, %s, ror #24\n", regs.t1, regs.k3, regs.x0);
printf("\tadd\t%s, %s, %s\n", regs.x3, regs.t1, regs.t0);
printf("\tror\t%s, %s, #31\n", regs.x3, regs.x3);
/* x0 = leftRotate8((x0 ^ (round + 4)) + (leftRotate1(x1) ^ k[4])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x0, round + 4);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t1, regs.k4, regs.x1);
printf("\tadd\t%s, %s, %s\n", regs.x0, regs.t1, regs.t0);
printf("\tror\t%s, %s, #24\n", regs.x0, regs.x0);
/* x1 = leftRotate1((x1 ^ (round + 5)) + (leftRotate8(x2) ^ k[5])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x1, round + 5);
printf("\teor\t%s, %s, %s, ror #24\n", regs.t1, regs.k5, regs.x2);
printf("\tadd\t%s, %s, %s\n", regs.x1, regs.t1, regs.t0);
printf("\tror\t%s, %s, #31\n", regs.x1, regs.x1);
/* x2 = leftRotate8((x2 ^ (round + 6)) + (leftRotate1(x3) ^ k[6])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x2, round + 6);
printf("\teor\t%s, %s, %s, ror #31\n", regs.t1, regs.k6, regs.x3);
printf("\tadd\t%s, %s, %s\n", regs.x2, regs.t1, regs.t0);
printf("\tror\t%s, %s, #24\n", regs.x2, regs.x2);
/* x3 = leftRotate1((x3 ^ (round + 7)) + (leftRotate8(x0) ^ k[7])); */
printf("\teor\t%s, %s, #%d\n", regs.t0, regs.x3, round + 7);
printf("\teor\t%s, %s, %s, ror #24\n", regs.t1, regs.k7, regs.x0);
printf("\tadd\t%s, %s, %s\n", regs.x3, regs.t1, regs.t0);
printf("\tror\t%s, %s, #31\n", regs.x3, regs.x3);
}
/* Store the words back to the state and exit */
printf("\tpop\t{r1}\n");
printf("\tstr\t%s, [r1, #%d]\n", regs.x0, 0);
printf("\tstr\t%s, [r1, #%d]\n", regs.x1, 4);
printf("\tstr\t%s, [r1, #%d]\n", regs.x2, 8);
printf("\tstr\t%s, [r1, #%d]\n", regs.x3, 12);
printf("\tpop\t{r4, r5, r6, r7, r8, r9, r10, fp, pc}\n");
}
/* List of all registers that we can work with for CHAM-64 */
typedef struct
{
const char *x0;
const char *x1;
const char *x2;
const char *x3;
const char *k[7];
const char *t0;
const char *t1;
} reg_names_64;
/* Generate the code for a single CHAM-64 round */
static void gen_cham64_round
(const reg_names_64 *regs, const char *x0, const char *x1,
int round, int shift1, int shift2)
{
/*
* x0 = leftRotate8_shift2
* ((x0 ^ round) +
* (leftRotate1_shift1(x1) ^ k[round % 16]));
*/
printf("\teor\t%s, %s, #%d\n", x0, x0, round);
if ((round % 16) < 7) {
printf("\teor\t%s, %s, %s, lsl #%d\n",
regs->t0, regs->k[round % 16], x1, shift1);
} else {
printf("\tldrh\t%s, [fp, #%d]\n",
regs->t1, -20 + ((round % 16) - 7) * 2);
printf("\teor\t%s, %s, %s, lsl #%d\n",
regs->t0, regs->t1, x1, shift1);
}
printf("\teor\t%s, %s, %s, lsr #%d\n", regs->t0, regs->t0, x1, 16 - shift1);
printf("\tadd\t%s, %s, %s\n", regs->t1, x0, regs->t0);
printf("\tuxth\t%s, %s\n", regs->t1, regs->t1);
if (shift2 == 8) {
printf("\trev16\t%s, %s\n", x0, regs->t1);
} else {
printf("\tlsl\t%s, %s, #%d\n", x0, regs->t1, shift2);
printf("\teor\t%s, %s, %s, lsr #%d\n", x0, x0, regs->t1, 16 - shift2);
printf("\tuxth\t%s, %s\n", x0, x0);
}
}
/* Generate the body of the CHAM-64 block cipher encrypt function */
static void gen_encrypt_cham64(void)
{
reg_names_64 regs;
int round;
regs.x0 = "r3";
regs.x1 = "r4";
regs.x2 = "r5";
regs.x3 = "r6";
regs.k[0] = "r2";
regs.k[1] = "r7";
regs.k[2] = "r8";
regs.k[3] = "r9";
regs.k[4] = "r10";
regs.k[5] = "r1";
regs.k[6] = "lr";
regs.t0 = "r0";
regs.t1 = "ip";
printf("\tpush\t{r4, r5, r6, r7, r8, r9, r10, fp, lr}\n");
/* Create 18 bytes of stack space to store k[7]..k[15], rounded up to 20,
* plus another 4 bytes to save the value of r1 for later */
printf("\tmov\tfp, sp\n");
printf("\tsub\tsp, sp, #24\n");
printf("\tstr\tr1, [fp, #-24]\n");
/* Load all words of the state and the key into registers */
printf("\tldrh\t%s, [r2, #%d]\n", regs.x0, 0);
printf("\tldrh\t%s, [r2, #%d]\n", regs.x1, 2);
printf("\tldrh\t%s, [r2, #%d]\n", regs.x2, 4);
printf("\tldrh\t%s, [r2, #%d]\n", regs.x3, 6);
printf("\tldrh\t%s, [r0, #%d]\n", regs.k[0], 0);
printf("\tldrh\t%s, [r0, #%d]\n", regs.k[1], 2);
printf("\tldrh\t%s, [r0, #%d]\n", regs.k[2], 4);
printf("\tldrh\t%s, [r0, #%d]\n", regs.k[3], 6);
printf("\tldrh\t%s, [r0, #%d]\n", regs.k[4], 8);
printf("\tldrh\t%s, [r0, #%d]\n", regs.k[5], 10);
printf("\tldrh\t%s, [r0, #%d]\n", regs.k[6], 12);
printf("\tldrh\t%s, [r0, #%d]\n", regs.t0, 14);
/* Generate the key schedule:
*
* k[8] = k[1] ^ leftRotate1_16(k[1]) ^ leftRotate11_16(k[1]);
* k[9] = k[0] ^ leftRotate1_16(k[0]) ^ leftRotate11_16(k[0]);
* k[10] = k[3] ^ leftRotate1_16(k[3]) ^ leftRotate11_16(k[3]);
* k[11] = k[2] ^ leftRotate1_16(k[2]) ^ leftRotate11_16(k[2]);
* k[12] = k[5] ^ leftRotate1_16(k[5]) ^ leftRotate11_16(k[5]);
* k[13] = k[4] ^ leftRotate1_16(k[4]) ^ leftRotate11_16(k[4]);
* k[14] = k[7] ^ leftRotate1_16(k[7]) ^ leftRotate11_16(k[7]);
* k[15] = k[6] ^ leftRotate1_16(k[6]) ^ leftRotate11_16(k[6]);
* k[0] ^= leftRotate1_16(k[0]) ^ leftRotate8_16(k[0]);
* k[1] ^= leftRotate1_16(k[1]) ^ leftRotate8_16(k[1]);
* k[2] ^= leftRotate1_16(k[2]) ^ leftRotate8_16(k[2]);
* k[3] ^= leftRotate1_16(k[3]) ^ leftRotate8_16(k[3]);
* k[4] ^= leftRotate1_16(k[4]) ^ leftRotate8_16(k[4]);
* k[5] ^= leftRotate1_16(k[5]) ^ leftRotate8_16(k[5]);
* k[6] ^= leftRotate1_16(k[6]) ^ leftRotate8_16(k[6]);
* k[7] ^= leftRotate1_16(k[7]) ^ leftRotate8_16(k[7]);
*/
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.t0, regs.t0);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.t0);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.t0);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.t0);
printf("\tstrh\t%s, [fp, #-6]\n", regs.t1); /* k[14] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.t0, regs.t0);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.t0);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t1, regs.t1, regs.t0);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t1, regs.t1, regs.t0);
printf("\tstrh\t%s, [fp, #-20]\n", regs.t1); /* k[7] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.k[1], regs.k[1]);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.k[1]);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t0, regs.t1, regs.k[1]);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.k[1]);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t0, regs.t0, regs.k[1]);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.k[1]);
printf("\tuxth\t%s, %s\n", regs.k[1], regs.t0); /* k[1] */
printf("\tstrh\t%s, [fp, #-18]\n", regs.t1); /* k[8] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.k[0], regs.k[0]);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.k[0]);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t0, regs.t1, regs.k[0]);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.k[0]);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t0, regs.t0, regs.k[0]);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.k[0]);
printf("\tuxth\t%s, %s\n", regs.k[0], regs.t0); /* k[0] */
printf("\tstrh\t%s, [fp, #-16]\n", regs.t1); /* k[9] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.k[3], regs.k[3]);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.k[3]);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t0, regs.t1, regs.k[3]);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.k[3]);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t0, regs.t0, regs.k[3]);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.k[3]);
printf("\tuxth\t%s, %s\n", regs.k[3], regs.t0); /* k[3] */
printf("\tstrh\t%s, [fp, #-14]\n", regs.t1); /* k[10] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.k[2], regs.k[2]);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.k[2]);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t0, regs.t1, regs.k[2]);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.k[2]);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t0, regs.t0, regs.k[2]);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.k[2]);
printf("\tuxth\t%s, %s\n", regs.k[2], regs.t0); /* k[2] */
printf("\tstrh\t%s, [fp, #-12]\n", regs.t1); /* k[11] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.k[5], regs.k[5]);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.k[5]);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t0, regs.t1, regs.k[5]);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.k[5]);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t0, regs.t0, regs.k[5]);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.k[5]);
printf("\tuxth\t%s, %s\n", regs.k[5], regs.t0); /* k[5] */
printf("\tstrh\t%s, [fp, #-10]\n", regs.t1); /* k[12] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.k[4], regs.k[4]);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.k[4]);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t0, regs.t1, regs.k[4]);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.k[4]);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t0, regs.t0, regs.k[4]);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.k[4]);
printf("\tuxth\t%s, %s\n", regs.k[4], regs.t0); /* k[4] */
printf("\tstrh\t%s, [fp, #-8]\n", regs.t1); /* k[13] */
printf("\teor\t%s, %s, %s, lsl #1\n", regs.t1, regs.k[6], regs.k[6]);
printf("\teor\t%s, %s, %s, lsr #15\n", regs.t1, regs.t1, regs.k[6]);
printf("\teor\t%s, %s, %s, lsl #8\n", regs.t0, regs.t1, regs.k[6]);
printf("\teor\t%s, %s, %s, lsl #11\n", regs.t1, regs.t1, regs.k[6]);
printf("\teor\t%s, %s, %s, lsr #8\n", regs.t0, regs.t0, regs.k[6]);
printf("\teor\t%s, %s, %s, lsr #5\n", regs.t1, regs.t1, regs.k[6]);
printf("\tuxth\t%s, %s\n", regs.k[6], regs.t0); /* k[6] */
printf("\tstrh\t%s, [fp, #-4]\n", regs.t1); /* k[15] */
/* Unroll all 80 rounds, 4 at a time */
for (round = 0; round < 80; round += 4) {
/*
* x0 = leftRotate8_16
* ((x0 ^ round) +
* (leftRotate1_16(x1) ^ k[round % 16]));
*/
gen_cham64_round(®s, regs.x0, regs.x1, round, 1, 8);
/*
* x1 = leftRotate1_16
* ((x1 ^ (round + 1)) +
* (leftRotate8_16(x2) ^ k[(round + 1) % 16]));
*/
gen_cham64_round(®s, regs.x1, regs.x2, round + 1, 8, 1);
/*
* x2 = leftRotate8_16
* ((x2 ^ (round + 2)) +
* (leftRotate1_16(x3) ^ k[(round + 2) % 16]));
*/
gen_cham64_round(®s, regs.x2, regs.x3, round + 2, 1, 8);
/*
* x3 = leftRotate1_16
* ((x3 ^ (round + 3)) +
* (leftRotate8_16(x0) ^ k[(round + 3) % 16]));
*/
gen_cham64_round(®s, regs.x3, regs.x0, round + 3, 8, 1);
}
/* Store the words back to the state and exit */
printf("\tldr\tr1, [fp, #-24]\n");
printf("\tmov\tsp, fp\n");
printf("\tstrh\t%s, [r1, #%d]\n", regs.x0, 0);
printf("\tstrh\t%s, [r1, #%d]\n", regs.x1, 2);
printf("\tstrh\t%s, [r1, #%d]\n", regs.x2, 4);
printf("\tstrh\t%s, [r1, #%d]\n", regs.x3, 6);
printf("\tpop\t{r4, r5, r6, r7, r8, r9, r10, fp, pc}\n");
}
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
/* Output the file header */
printf("#if defined(__ARM_ARCH_ISA_THUMB) && __ARM_ARCH == 7\n");
printf("\t.syntax unified\n");
printf("\t.thumb\n");
printf("\t.text\n");
/* Output the CHAM-128 encryption function */
function_header("cham128_128_encrypt");
gen_encrypt_cham128();
function_footer("cham128_128_encrypt");
/* Output the CHAM-64 encryption function */
function_header("cham64_128_encrypt");
gen_encrypt_cham64();
function_footer("cham64_128_encrypt");
/* Output the file footer */
printf("\n");
printf("#endif\n");
return 0;
}
|
2528a2dc3698b715d849f0986a6b1293792bf6d5
|
4e3e57483e9cb805a8f4a1a953fb13faa66b9d58
|
/cairoExample/textCairo/example_1.h
|
c09bc09db80412add1165fb11d780ccdd0c0f36f
|
[] |
no_license
|
dhryu1992/mugGame
|
233e6e0d74010f9fa34f27c352f4926faa509893
|
b3bba6e878ef9ac2179828861c11800ad7ebff94
|
refs/heads/master
| 2022-12-02T06:36:31.072050 | 2020-08-14T04:35:19 | 2020-08-14T04:35:19 | 282,587,700 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 336 |
h
|
example_1.h
|
#ifndef EXAMPLE_1_H
#include <string.h>
#include <stdio.h>
int i = 0;
int a = 0;
char *text[10] = {0,};
char *img[10] = {0,};
char *height[10] = {0, };
int iNum = 0;
int t = 0;
int hNum = 0;
int k = 0;
char *naver[10] = { "google", "src", "arin1.png","height", "270", "src", "abc.png","height", "270" ,"chocolate", 0,};
#endif
|
d72c087d856cdfc18c7834215bd0fc6ffe051793
|
a280aa9ac69d3834dc00219e9a4ba07996dfb4dd
|
/regularexpress/home/weilaidb/software/db-6.2.23/test/xa/src4/client.c
|
748357ee08e80cebc7e8bb43d37d4ff6d62a062a
|
[] |
no_license
|
weilaidb/PythonExample
|
b2cc6c514816a0e1bfb7c0cbd5045cf87bd28466
|
798bf1bdfdf7594f528788c4df02f79f0f7827ce
|
refs/heads/master
| 2021-01-12T13:56:19.346041 | 2017-07-22T16:30:33 | 2017-07-22T16:30:33 | 68,925,741 | 4 | 2 | null | null | null | null |
UTF-8
|
C
| false | false | 188 |
c
|
client.c
|
#define HOME "../data"
#define TABLE1 "../data/table1.db"
#define TABLE2 "../data/table2.db"
DB_ENV *dbenv;
char *progname;
int usage(void);
int
main(int argc, char* argv[])
int
usage()
|
8ba35d0e1ca1d905b4fabb1ec5bdef30ea3ca2e0
|
4e7855e7e2356204e66626ff9f8d89ab10aac232
|
/TME8/src/single_converter.c
|
6d51b1227a54504bc39e5a48e5107c337e545a4b
|
[] |
no_license
|
mohamedaf/LI356-ProgrammationPOSIX
|
9f1fc7214df8275ad122e0bf90908611a0ee2e2d
|
c53467a362b11798fa3c5047b9fe623eabee8e70
|
refs/heads/master
| 2020-05-19T09:40:09.392075 | 2014-03-31T12:05:00 | 2014-03-31T12:05:00 | 32,325,013 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 924 |
c
|
single_converter.c
|
#define _POSIX_SOURCE 1
#include <converters.h>
#include <string.h>
int main(int argc, char **argv){
conversion_message req;
results_array rep;
int i;
int tubeDesc[2];
strcpy(req.currency, argv[1]);
req.amount = atof(argv[2]);
if(pipe(tubeDesc) == -1){ /*creation tube*/
perror("Probleme Pipe !\n");
return EXIT_FAILURE;
}
if(fork() == 0){
for(i = 0; i < NB_CONVERTERS; i++)
handle_conversion_request(req, &rep[i], i);
if(write(tubeDesc[1],&rep,sizeof(results_array)) == -1){ /*ecriture sur le tube*/
perror("Probleme write fils!\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
else{
if(read(tubeDesc[0],&rep,sizeof(results_array)) == -1){ /*lecture sur le tube, bloqué j'usqua écriture du fils*/
perror("Probleme write fils!\n");
return EXIT_FAILURE;
}
display_results(req, rep);
}
return EXIT_SUCCESS;
}
|
cfa0a22bd29d819d4e2b96487e46a7583bee2f52
|
aac2b871d5862e7e395b8ad3032c5b755039ff4d
|
/DoraemonKit/iOS/DoraemonKitDemo/Pods/Headers/Private/DoraemonKit/DoraemonANRTool.h
|
a6a694f6f48ce5d10e0ed55ad2e42c53ecd702ed
|
[] |
no_license
|
ydlsl/Graduation
|
61e78872f67d56908a573618bebb64a7c3ca6b5c
|
fbf6a8f91d47e1d561374b4620f1a9b6b6b0a029
|
refs/heads/master
| 2022-07-24T08:25:22.049064 | 2020-05-23T15:42:51 | 2020-05-23T15:42:51 | 266,366,325 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 85 |
h
|
DoraemonANRTool.h
|
../../../../../DoraemonKit/Src/Core/Plugin/Performance/ANR/Function/DoraemonANRTool.h
|
b50765253fb681bb40ed64e137931fb2ac0fccc5
|
751d837b8a4445877bb2f0d1e97ce41cd39ce1bd
|
/edabit/list-of-multiples.c
|
f8a34606af03b48b4d7d8442cbc1bb447e447147
|
[
"MIT"
] |
permissive
|
qeedquan/challenges
|
d55146f784a3619caa4541ac6f2b670b0a3dd8ba
|
56823e77cf502bdea68cce0e1221f5add3d64d6a
|
refs/heads/master
| 2023-08-11T20:35:09.726571 | 2023-08-11T13:02:43 | 2023-08-11T13:02:43 | 115,886,967 | 2 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 799 |
c
|
list-of-multiples.c
|
/*
Create a function that takes two numbers as arguments (num, length) and returns a list of multiples of num up to length.
Notes
Notice that num is also included in the returned list.
*/
#include <stdio.h>
#include <stdlib.h>
int *
listofmultiples(int x, size_t n)
{
size_t i;
int *p, v;
p = calloc(n, sizeof(*p));
if (!p)
return NULL;
v = x;
for (i = 0; i < n; i++) {
p[i] = x;
x += v;
}
return p;
}
void
test(int x, size_t n)
{
size_t i;
int *p;
p = listofmultiples(x, n);
if (!p)
return;
printf("[");
for (i = 0; i < n; i++) {
printf("%d", p[i]);
if (i + 1 < n)
printf(", ");
}
printf("]\n");
free(p);
}
int
main(void)
{
test(7, 5);
test(12, 10);
test(17, 7);
test(630, 14);
test(140, 3);
test(7, 8);
test(11, 21);
test(17, 6);
return 0;
}
|
ca512169ae6d7bc4c9190bb84cacee49ccd0f979
|
b73a11d1cedeee2024265671ea0bd55378e4e0c8
|
/psolbest.c
|
0f89f56fb850a4babd5fa0688bd7ed55d6b17274
|
[] |
no_license
|
khushboopriya/pso_lbest
|
8e936d80f629c352169aa7a06f904d101d4111ff
|
de1db2c3516acabec77ec69881421d65a97d0c7a
|
refs/heads/master
| 2020-03-21T15:33:18.173978 | 2019-01-02T20:02:23 | 2019-01-02T20:02:23 | 138,719,348 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 4,200 |
c
|
psolbest.c
|
+8#include <stdio.h>
#include <stdlib.h>
/* Random number generator in [0, 1] */
#define Rand() ((double)rand()/RAND_MAX)
// #define rand_01 ((float)rand() / (float)RAND_MAX)
/* Structure of a particle */
typedef struct {
double *x;
double *v;
double f;
double pbest;
double *x_star;
int lbestof_p_i;
} ParticleRec, *Particle;
/*
Parameters for PSO
*/
/* Number of particles.this is the swarm size. Good if this lies between 10 and 30 */
#define Nparticles 10
/* Maximum number of iterations */
#define T_MAX 100
/* The value of inertia weight at t=0 (W_0) and t=T_MAX (W_T) . THis is increasing inertia.*/
#define W_0 0.9
#define W_T 0.4
#define MAX_V 2.0
/* The cognitive parameter (c1) and the social parameter (c2) */
#define c1 2.0
#define c2 2.0
/*
Definitions for a problem
*/
/* Number of variables: problem dependent . */
#define Nvariables 3
/* Objective function for minimization: problem dependent */
#define better(y1, y2) (y1<y2)
/* The following is the function of (x_i-2)^2 */
void Evaluate(Particle P)
{
int i;
P->f=0.0;
for(i=0; i<Nvariables; i++)
P->f+=(P->x[i]-2)*(P->x[i]-2);
}
/* update pbest */
void UpdateBest(Particle P)
{
int j;
for(j=0; j<Nvariables; j++)
P->x_star[j]=P->x[j];
P->pbest=P->f;
}
/* Initialization of particles: problem dependent */
/* The function returns the index of the best particle */
void Initialize(Particle P, int n)
{
int i, j,bi,ai,ni;
//
for(i=0; i<n; i++) {
for(j=0; j<Nvariables; j++) {
P[i].x[j]=Rand(); /* problem dependent */
P[i].v[j]=0.0; /* problem dependent */
}
Evaluate(&P[i]);
UpdateBest(&P[i]);
//if(better(P[i].f, P[G].f)) G=i;//need to change the code to store lbest of each ith swarm
P[i].lbestof_p_i=i;//making everyone pbest of itself
//initializing lbest for each particle
/*
bi=i-1;
ni=i;
ai=i+1;
if(i==0)
bi=9;
if(i==9)
ai=0;
if( better(P[bi].f,P[ni].f)&& better(P[bi].f,P[ai].f) )
P[i].lbestof_p_i=bi;
if( better(P[ai].f,P[ni].f)&& better(P[ai].f,P[bi].f) )
P[i].lbestof_p_i=ai;
if( better(P[ni].f,P[bi].f)&& better(P[ni].f,P[ai].f) )
P[i].lbestof_p_i=ni;
*/
}
//return lb;
}
/*
Defination of pso
*/
/* allocate new data structures . purane velocities ko rakhna zaroori hai cauz if the next value is not good then it retains the previous value*/
#define New(type, n, msg) (type *)NewCell(sizeof(type), n, msg)
void *NewCell(int size, int n, char *msg)
{
void *new;
if((new=malloc(size*n))==NULL) {
fprintf(stderr, "Cannot allocate memory for %d %s\n", n, msg);
exit(1);
}
return new;
}
/* allocate "n" new particles */
Particle NewParticles(int n)
{
int i;
Particle P;
P=New(ParticleRec, n, "particles");
for(i=0; i<n; i++)
{
P[i].x=New(double, Nvariables, "x");
P[i].v=New(double, Nvariables, "v");
P[i].x_star=New(double, Nvariables, "x*");
}
return P;
}
/* Print a particle */
void Print(Particle P)
{
int j;
for(j=0; j<Nvariables; j++)
printf("%f ", P->x_star[j]);
printf(" = %g\t", P->pbest);
printf("\tlbestindex %d \n ",P->lbestof_p_i);
}
void main()
{
int t, i, j,a,b,n;
Particle P;
//int lb; index of lbest
double w;
P=NewParticles(Nparticles);
Initialize(P, Nparticles);
w=W_0;
for(t=1; t<=T_MAX; t++) {
for(i=0; i<Nparticles; i++) {
for(j=0; j<Nvariables; j++) {
P[i].v[j]=w*P[i].v[j]+c1*Rand()*(P[i].x_star[j]-P[i].x[j])+c2*Rand()*(P[P[i].lbestof_p_i].x_star[j]-P[i].x[j]);
if(P[i].v[j]<-MAX_V)
P[i].v[j]=-MAX_V;
else if(P[i].v[j]>MAX_V)
P[i].v[j]=MAX_V;
P[i].x[j]+=P[i].v[j];
}
Evaluate(&P[i]);
if(better(P[i].f, P[i].pbest))
UpdateBest(&P[i]);
//if(better(P[i].f, P[G].pbest)) G=i;
b=i-1;
n=i;
a=i+1;
if(i==0)
b=9;
if(i==9)
a=0;
if( better(P[b].f,P[n].f)&& better(P[b].f,P[a].f) )
P[i].lbestof_p_i=b;
if( better(P[a].f,P[n].f)&& better(P[a].f,P[b].f) )
P[i].lbestof_p_i=a;
if( better(P[n].f,P[b].f)&& better(P[n].f,P[a].f) )
P[i].lbestof_p_i=n;
printf(" iteration no is %4d:\n ", t);
printf("values for particleno ==%d is %d %d %d \t",i,b,a,n);
Print(&P[i]);
}
w-=(W_0-W_T)/T_MAX;
}
}
|
62aeb988f67c1eee84a25d468da11016f47eb516
|
c39e0975e5ab5dcc5cb989c1ce5d2352e5493f22
|
/5/5-8.c
|
7b87fd405c78347ea8d1b63324230735d6cd02df
|
[] |
no_license
|
paalso/kernighan_ritchie
|
c5717304449ebd269544980541f5debd59a1be7f
|
6ad318019236aeab401c9e4eb6bcf0e40a9d9fee
|
refs/heads/master
| 2020-05-25T13:08:51.429943 | 2019-07-30T17:56:44 | 2019-07-30T17:56:44 | 187,814,551 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 2,509 |
c
|
5-8.c
|
// Упражнение 5.8. В функциях day_of_year и month_day нет никаких проверок правильности
// вводимых дат. Устраните этот недостаток.
#include <stdio.h>
void month_day(int, int, int *, int *);
int day_of_year(int, int, int);
int is_leap(int);
// Проверка правильности вводимых дат отделены от функций day_of_year и month_day
// т.к. это представляется неудобным и не очень логичным и вынесена в отдельные функции
// Сама проверка проводится при вводе исходных данных
int checkdate(int, int, int);
int check_yearday(int, int);
static int daytab[][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
// --- main -----------------------------------------
int main() {
int y, m, d, num;
// printf("Input a date: year-month-day\n");
// scanf("%d-%d-%d", &y, &m, &d);
// if (! checkdate(y, m, d)) {
// printf("Incorrect date!");
// return 1;
// }
// printf("The day of the year # %d\n", day_of_year(y, m, d));
printf("Input a year and a day's number:\n");
scanf("%d %d", &y, &num);
if (! check_yearday(y, num)) {
printf("Incorrect yearday!");
return 1;
}
month_day(y, num, &m, &d);
printf("The date: %d-%d-%d\n", y,m,d);
return 0;
}
int is_leap(int year) {
return year % 4 == 0 && year % 100 != 0 || year % 1000 == 0;
}
int checkdate(int year, int month, int day) {
if (month < 1 || month > 12)
return 0;
if (day < 1 || day > daytab[is_leap(year)][month])
return 0;
return 1;
}
int check_yearday(int year, int yearday) {
if (yearday < 1 || yearday > (is_leap(year) ? 366 : 365))
return 0 ;
return 1;
}
int day_of_year(int year, int month, int day) {
int leap_index = is_leap(year);
for (int i = 1; i < month; ++i)
day += daytab[leap_index][i];
return day;
}
void month_day(int year, int yearday, int *pmonth, int *pday) {
int leap_index = is_leap(year);
*pmonth = 1;
for (; yearday > 0; *pmonth += 1)
yearday -= daytab[leap_index][*pmonth];
*pmonth -= 1;
*pday = yearday + daytab[leap_index][*pmonth];
}
|
a409b22505d99669953851790aed1275161251a5
|
0d7e1ac5fe197f542a497ae7c489eda5ab537875
|
/Ejercicio 5-2/src/funcionesUTNyMenu.c
|
87e080c89d66ae0294eeb0cc8dca5b3545d3d7c9
|
[] |
no_license
|
ornecurcio/Programacion-y-Labo-1
|
876c889096e011d21e83c9e7505edd1695eccef4
|
b662c55f18ca85b736500351d60232d17b9d55da
|
refs/heads/main
| 2023-06-03T01:34:08.682571 | 2021-06-24T20:17:47 | 2021-06-24T20:17:47 | 351,583,832 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,809 |
c
|
funcionesUTNyMenu.c
|
/*
* numeros.c
*
* Created on: 1 abr. 2021
* Author: orne_
*/
#include <stdio.h>
#include <stdlib.h>
int utn_getNumero(int* pResultado,char* mensaje,char* mensajeError,int minimo,int maximo,int reintentos)
{
int retorno = -1;
int bufferInterno;
if(pResultado != NULL && mensaje != NULL && mensajeError != NULL && minimo <= maximo && reintentos>0)
{
do
{
printf("%s", mensaje);
scanf("%d", &bufferInterno);
if(bufferInterno>=minimo && bufferInterno<=maximo)
{
*pResultado=bufferInterno;
retorno=0;
break;
}
else
{
printf("%s", mensajeError);
reintentos--;
}
}while(reintentos>=0);
}
return retorno;
}
int utn_getNumeroConDecimales(float* pResultado,char* mensaje,char* mensajeError,float minimo,float maximo,int reintentos)
{
int retorno = -1;
float bufferInterno;
if(pResultado != NULL && mensaje != NULL && mensajeError != NULL && minimo <= maximo && reintentos>0)
{
do
{
printf("%s", mensaje);
scanf("%f", &bufferInterno);
if(bufferInterno>=minimo && bufferInterno<=maximo)
{
*pResultado=bufferInterno;
retorno=0;
break;
}
else
{
printf("%s", mensajeError);
reintentos--;
}
}while(reintentos>=0);
}
return retorno;
}
int utn_getCaracter(char* pResultado,char* mensaje,char* mensajeError,char minimo,char maximo,int reintentos)
{
int retorno = -1;
char bufferChar;
if(pResultado != NULL && mensaje != NULL && mensajeError != NULL && minimo <= maximo && reintentos>0)
{
do
{
printf("%s", mensaje);
fflush(stdin);
scanf("%c", &bufferChar);
if(bufferChar>=minimo && bufferChar<=maximo)
{
*pResultado=bufferChar;
retorno=0;
break;
}
else
{
printf("%s", mensajeError);
reintentos--;
}
}while(reintentos>=0);
}
return retorno;
}
|
8661a00b4d26e67d36a0e84b297777efa1dedb61
|
e25c8b65c0115053b14f8ecffaea94a964eefa1f
|
/ds/open/world1/world2/wilfred/magic-card/3/card3.c
|
b1f5ad27ae71b80ca07acc2498ac8a517c5e71c2
|
[] |
no_license
|
zwshen/mudos-game-ds
|
c985b4b64c586bdc7347bd95d97ab12e78a2f20f
|
07ea84ebdff5ee49cb482a520bdf1aaeda886cd0
|
refs/heads/master
| 2022-03-01T14:55:10.537294 | 2022-02-15T15:41:26 | 2022-02-15T15:41:26 | 244,925,365 | 4 | 1 | null | 2022-02-15T15:41:27 | 2020-03-04T14:44:49 |
C
|
BIG5
|
C
| false | false | 235 |
c
|
card3.c
|
inherit __DIR__"std_card.c";
void create()
{
set("short","麻雀");
set("pow", ({1,2,1,1}) );
set("lv",1);
set("ver",3);
set("ver_n","武神");
set("num",3);
set("long","一隻磯磯磯叫的小動物。");
setup();
}
|
f786a1c8a66bccb27bad2693e7b07a4945bd34d5
|
f0e5d9407c39b0da49c2eca05084bb64776fa1de
|
/alexander-chubchik-hw2/Task2_1.c
|
d49866b51aee8b2d90568c9f6e8fafe83ed6f7ed
|
[] |
no_license
|
NataRazmochaeva/pc-2021-6300
|
c63cf8214498ebb91805c4d116356a88c98bb6e0
|
a1491fe30dca5b9b84feea5f1384f1ae98ad6ba3
|
refs/heads/main
| 2023-05-16T19:52:06.842129 | 2021-06-10T07:26:27 | 2021-06-10T07:26:27 | 344,756,262 | 0 | 10 | null | 2021-06-10T07:16:48 | 2021-03-05T09:16:15 |
C
|
UTF-8
|
C
| false | false | 4,089 |
c
|
Task2_1.c
|
#include <pthread.h>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <random>
#include <thread>
struct thread_primitives {
pthread_mutex_t mutex_shared = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutexForProducer = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t CondVal_produced = PTHREAD_COND_INITIALIZER;
pthread_cond_t CondVal_consumed = PTHREAD_COND_INITIALIZER;
};
__thread int partial_amount = 0;
bool inWork = true;
unsigned int Consumer_quantity;
int upper_limit_ofSleep_cons = 0;
pthread_barrier_t consumers_barrier;
std::vector<pthread_t> consumers;
thread_primitives primitives;
int main(int argc, char *argv[]) {
Consumer_quantity = static_cast<unsigned int>(std::stoi(argv[1]));
upper_limit_ofSleep_cons = std::stoi(argv[2]);
std::cout << run_threads() << std::endl;
return 0;
}
void* consumer_routine(void* arg) {
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr);
pthread_barrier_wait(&consumers_barrier);
int* pointerToShared_var = static_cast<int*>(arg);
while (inWork) {
pthread_mutex_lock(&primitives.mutex_shared);
while (inWork && *pointerToShared_var == 0) {
pthread_cond_wait(&primitives.CondVal_produced, &primitives.mutex_shared);
}
partial_amount += *pointerToShared_var;
*pointerToShared_var = 0;
pthread_mutex_lock(&primitives.mutexForProducer);
pthread_cond_signal(&primitives.CondVal_consumed);
pthread_mutex_unlock(&primitives.mutexForProducer);
pthread_mutex_unlock(&primitives.mutex_shared);
std::this_thread::sleep_for(std::chrono::milliseconds(get_random_integer(0, upper_limit_ofSleep_cons)));
}
return &partial_amount;
}
void* consumer_interruptor_routine(void* arg) {
pthread_barrier_wait(&consumers_barrier);
while (inWork) {
pthread_cancel(consumers[get_random_integer(0, Consumer_quantity - 1)]);
}
return nullptr;
}
void* producer_routine(void* arg) {
pthread_barrier_wait(&consumers_barrier);
int* pointerToShared_var = static_cast<int*>(arg);
std::string input;
std::getline(std::cin, input);
std::stringstream ss(input);
int n;
while (ss >> n) {
pthread_mutex_lock(&primitives.mutex_shared);
*pointerToShared_var = n;
pthread_cond_signal(&primitives.CondVal_produced);
pthread_mutex_unlock(&primitives.mutex_shared);
pthread_mutex_lock(&primitives.mutexForProducer);
while (*pointerToShared_var != 0) {
pthread_cond_wait(&primitives.CondVal_consumed, &primitives.mutexForProducer);
}
pthread_mutex_unlock(&primitives.mutexForProducer);
}
pthread_mutex_lock(&primitives.mutex_shared);
inWork = false;
pthread_cond_broadcast(&primitives.CondVal_produced);
pthread_mutex_unlock(&primitives.mutex_shared);
return nullptr;
}
int run_threads() {
pthread_barrier_init(&consumers_barrier, nullptr, Consumer_quantity + 2);
int updates_variable = 0;
pthread_t producer, interrupter;
pthread_create(&producer, nullptr, producer_routine, &updates_variable);
consumers = std::vector<pthread_t>(Consumer_quantity);
for (auto& consumer : consumers) {
pthread_create(&consumer, nullptr, consumer_routine, &updates_variable);
}
pthread_create(&interrupter, nullptr, consumer_interruptor_routine, nullptr);
pthread_join(producer, nullptr);
pthread_join(interrupter, nullptr);
int res = 0;
for (auto& consumer : consumers) {
int* value;
pthread_join(consumer, (void **) &value);
res += *value;
}
return res;
}
int get_random_integer(int lower_limit, int upper_limit) {
std::random_device dev;
std::mt19937 generator(dev());
std::uniform_int_distribution<int> distribution(lower_limit, upper_limit);
return distribution(generator);
}
|
7decc68536570ab32d58ab06417bfa7ec3174636
|
d0ceb76774abc3d54b7f1568746cd6b0a82f2d2c
|
/companies/Zoho/String Manipulation.c
|
8218defa47fe7c066201888058ce63625dff413b
|
[] |
no_license
|
GauthamArunachalam/C
|
51e9441edaf1443da1898354c3037fe51cd4029a
|
720ba132173720ea04920018fba42b8537bc5b53
|
refs/heads/master
| 2021-07-21T14:34:10.274860 | 2020-05-15T17:40:22 | 2020-05-15T17:40:22 | 166,998,404 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,763 |
c
|
String Manipulation.c
|
void printAs(char str[]);
void upperConvert(char str[]);
void firstLast(char str[]);
char *even(char str[]);
char *odd(char str[]);
char b[100];
int main(){
char names[5][100];
printf("\n\n\t String Manipulation\n");
for(int i=0;i<5;i++){
printf("\nEnter string %d: ",i+1);
scanf("%s",names[i]);
}
for(int i=0;i<5;i++){
printAs(names[i]);
}
printf("\n");
for(int i=0;i<5;i++){
upperConvert(names[i]);
}
printf("\n");
for(int i=0;i<5;i++){
firstLast(names[i]);
}
printf("\n");
for(int i=0;i<5;i++){
if(i%2==0)
strcpy(names[i],even(names[i]));
}
printf("\n");
for(int i=0;i<5;i++){
if(i%2!=0)
strcpy(names[i],odd(names[i]));
}
printf("\n");
for(int i=0;i<5;i++){
if(i%2==0)
printf("%s\n",names[i]);
else
printf("%s\n",names[i]);
}
}
void printAs(char str[]){
printf("%s\n",str);
}
void upperConvert(char str[]){
int len=strlen(str);
for(int j=0;j<len;j++){
printf("%c",toupper(str[j]));
}
printf("\n");
}
void firstLast(char str[]){
int len=strlen(str);
printf("%c",toupper(str[0]));
for(int j=1;j<len-1;j++)
printf("%c",str[j]);
printf("%c\n",toupper(str[len-1]));
}
char *even(char str[]){
printf("%s\n",str);
int len=strlen(str)-1;
int last=len,i;
for(i=0;i<=len;i++){
b[i]=str[last];
last--;
}
b[i]='\0';
str=b;
return str;
}
char *odd(char str[]){
printf("%s\n",str);
int len=strlen(str)-1;
for(int i=0;i<len;i++){
if(i%2==0)
str[i]=toupper(str[i]);
else
str[i]=tolower(str[i]);
}
return str;
}
|
566fc4ac2b72f9e28b4bcd04e0fb43cfb1b537e5
|
e66413af1536f70a11eb8592c17f63e9334eca36
|
/c_code/3_1/compiler_scriptconfig.c
|
823ea586d54a6127aaefd7406f2fd7df9fac8066
|
[] |
no_license
|
def-/csources
|
94bb9a11985c852094c01cdc96af914228c66871
|
9d7d95b53c2f2b27912d90e156c000e30a183e74
|
refs/heads/devel
| 2021-01-22T07:43:01.431367 | 2016-03-07T02:00:10 | 2016-03-07T02:00:10 | 53,287,929 | 0 | 1 | null | 2016-03-07T01:58:05 | 2016-03-07T01:58:05 | null |
UTF-8
|
C
| false | false | 52,488 |
c
|
compiler_scriptconfig.c
|
/* Generated by Nim Compiler v0.13.0 */
/* (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32
#include "nimbase.h"
#include <string.h>
#include <setjmp.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <stdio.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Tnode213790 Tnode213790;
typedef struct Tsym213822 Tsym213822;
typedef struct Tpass260014 Tpass260014;
typedef struct Tpasscontext260002 Tpasscontext260002;
typedef struct Trodreader251021 Trodreader251021;
typedef struct Tlinkedlist135016 Tlinkedlist135016;
typedef struct Tlistentry135010 Tlistentry135010;
typedef struct Tidobj188006 Tidobj188006;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Ttypeseq213824 Ttypeseq213824;
typedef struct Tscope213816 Tscope213816;
typedef struct TY213925 TY213925;
typedef struct Tstrtable213794 Tstrtable213794;
typedef struct Tsymseq213792 Tsymseq213792;
typedef struct Ttype213828 Ttype213828;
typedef struct Tident188012 Tident188012;
typedef struct Tlineinfo181337 Tlineinfo181337;
typedef struct Tloc213804 Tloc213804;
typedef struct Ropeobj168006 Ropeobj168006;
typedef struct Tlib213808 Tlib213808;
typedef struct Tctx262036 Tctx262036;
typedef struct TY534182 TY534182;
typedef struct TY262242 TY262242;
typedef struct TY182093 TY182093;
typedef struct PprocHEX3Aobjecttype262221 PprocHEX3Aobjecttype262221;
typedef struct TY262261 TY262261;
typedef struct TY118906 TY118906;
typedef struct Cell47705 Cell47705;
typedef struct Cellseq47721 Cellseq47721;
typedef struct Gcheap50018 Gcheap50018;
typedef struct Gcstack50016 Gcstack50016;
typedef struct Cellset47717 Cellset47717;
typedef struct Pagedesc47713 Pagedesc47713;
typedef struct Memregion29887 Memregion29887;
typedef struct Smallchunk29839 Smallchunk29839;
typedef struct Llchunk29881 Llchunk29881;
typedef struct Bigchunk29841 Bigchunk29841;
typedef struct Intset29814 Intset29814;
typedef struct Trunk29810 Trunk29810;
typedef struct Avlnode29885 Avlnode29885;
typedef struct Gcstat50014 Gcstat50014;
typedef struct Vmargs262030 Vmargs262030;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct TY125402 TY125402;
typedef struct Tllstream201204 Tllstream201204;
typedef struct Tnodeseq213784 Tnodeseq213784;
typedef struct TY213913 TY213913;
typedef struct Tindex251019 Tindex251019;
typedef struct Tiitable220163 Tiitable220163;
typedef struct Tiipairseq220161 Tiipairseq220161;
typedef struct Table251054 Table251054;
typedef struct Keyvaluepairseq251057 Keyvaluepairseq251057;
typedef struct Memfile249202 Memfile249202;
typedef struct Tinstantiation213812 Tinstantiation213812;
typedef struct TY262222 TY262222;
typedef struct TY262227 TY262227;
typedef struct TY262262 TY262262;
typedef struct Basechunk29837 Basechunk29837;
typedef struct Freecell29829 Freecell29829;
typedef struct Tiipair220159 Tiipair220159;
typedef struct Keyvaluepair251060 Keyvaluepair251060;
typedef struct Tblock262018 Tblock262018;
typedef struct TY262202 TY262202;
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_NIMCALL_PTR(Tnode213790*, TY260054) (Tsym213822* m, NI32 fileidx);
typedef N_NIMCALL_PTR(Tsym213822*, TY260049) (Tsym213822* m, NI32 fileidx);
typedef N_NIMCALL_PTR(Tpasscontext260002*, Tpassopen260006) (Tsym213822* module);
typedef N_NIMCALL_PTR(Tpasscontext260002*, Tpassopencached260008) (Tsym213822* module, Trodreader251021* rd);
typedef N_NIMCALL_PTR(Tnode213790*, Tpassprocess260012) (Tpasscontext260002* p, Tnode213790* toplevelstmt);
typedef N_NIMCALL_PTR(Tnode213790*, Tpassclose260010) (Tpasscontext260002* p, Tnode213790* n);
struct Tpass260014 {
Tpassopen260006 Field0;
Tpassopencached260008 Field1;
Tpassprocess260012 Field2;
Tpassclose260010 Field3;
};
struct Tlinkedlist135016 {
Tlistentry135010* head;
Tlistentry135010* tail;
NI counter;
};
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct TNimType {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct TNimObject {
TNimType* m_type;
};
struct Tidobj188006 {
TNimObject Sup;
NI id;
};
struct Tstrtable213794 {
NI counter;
Tsymseq213792* data;
};
struct Tlineinfo181337 {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct Tloc213804 {
NU8 k;
NU8 s;
NU16 flags;
Ttype213828* t;
Ropeobj168006* r;
Ropeobj168006* heaproot;
};
struct Tsym213822 {
Tidobj188006 Sup;
NU8 kind;
union{
struct {Ttypeseq213824* typeinstcache;
Tscope213816* typscope;
} S1;
struct {TY213925* procinstcache;
Tsym213822* gcunsafetyreason;
} S2;
struct {TY213925* usedgenerics;
Tstrtable213794 tab;
} S3;
struct {Tsym213822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype213828* typ;
Tident188012* name;
Tlineinfo181337 info;
Tsym213822* owner;
NU32 flags;
Tnode213790* ast;
NU32 options;
NI position;
NI offset;
Tloc213804 loc;
Tlib213808* annex;
Tnode213790* constraint;
};
struct TY534182 {
NI HEX3Astate;
NimStringDesc* errormsg534080;
NimStringDesc* vthisdir534081;
};
struct TNimNode {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct Tpasscontext260002 {
TNimObject Sup;
NIM_BOOL fromcache;
};
struct Tctx262036 {
Tpasscontext260002 Sup;
TY262242* code;
TY182093* debug;
Tnode213790* globals;
Tnode213790* constants;
Ttypeseq213824* types;
Tnode213790* currentexceptiona;
Tnode213790* currentexceptionb;
NI exceptioninstr;
PprocHEX3Aobjecttype262221* prc;
Tsym213822* module;
Tnode213790* callsite;
NU8 mode;
NU8 features;
NIM_BOOL traceactive;
NI loopiterations;
Tlineinfo181337 comesfromheuristic;
TY262261* callbacks;
NimStringDesc* errorflag;
};
struct TY118906 {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
struct Cell47705 {
NI refcount;
TNimType* typ;
};
struct Cellseq47721 {
NI len;
NI cap;
Cell47705** d;
};
struct Cellset47717 {
NI counter;
NI max;
Pagedesc47713* head;
Pagedesc47713** data;
};
typedef Smallchunk29839* TY29902[512];
typedef Trunk29810* Trunkbuckets29812[256];
struct Intset29814 {
Trunkbuckets29812 data;
};
struct Memregion29887 {
NI minlargeobj;
NI maxlargeobj;
TY29902 freesmallchunks;
Llchunk29881* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29841* freechunkslist;
Intset29814 chunkstarts;
Avlnode29885* root;
Avlnode29885* deleted;
Avlnode29885* last;
Avlnode29885* freeavlnodes;
};
struct Gcstat50014 {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct Gcheap50018 {
Gcstack50016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47721 zct;
Cellseq47721 decstack;
Cellset47717 cycleroots;
Cellseq47721 tempstack;
NI recgclock;
Memregion29887 region;
Gcstat50014 stat;
};
typedef struct {
N_NIMCALL_PTR(void, ClPrc) (Vmargs262030* args, void* ClEnv);
void* ClEnv;
} Vmcallback262032;
struct Exception {
TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
typedef struct {
N_NIMCALL_PTR(NIM_BOOL, ClPrc) (Exception* e, void* ClEnv);
void* ClEnv;
} TY18011;
struct TSafePoint {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY18011 raiseAction;
};
typedef NIM_CHAR TY110370[256];
typedef N_CLOSURE_PTR(void, TMP3686) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3688) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3690) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3692) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3695) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3697) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3699) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3701) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3703) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3705) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3707) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3709) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3712) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3714) (Vmargs262030* args, void* ClEnv);
typedef N_CLOSURE_PTR(void, TMP3716) (Vmargs262030* args, void* ClEnv);
struct Tnode213790 {
Ttype213828* typ;
Tlineinfo181337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym213822* sym;
} S4;
struct {Tident188012* ident;
} S5;
struct {Tnodeseq213784* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
struct Tiitable220163 {
NI counter;
Tiipairseq220161* data;
};
struct Tindex251019 {
NI lastidxkey;
NI lastidxval;
Tiitable220163 tab;
NimStringDesc* r;
NI offset;
};
struct Table251054 {
Keyvaluepairseq251057* data;
NI counter;
};
struct Memfile249202 {
void* mem;
NI size;
int handle;
};
struct Trodreader251021 {
TNimObject Sup;
NI pos;
NCSTRING s;
NU32 options;
NU8 reason;
TY213913* moddeps;
TY213913* files;
NI dataidx;
NI convertersidx;
NI initidx;
NI interfidx;
NI compilerprocsidx;
NI methodsidx;
NimStringDesc* filename;
Tindex251019 index;
Tindex251019 imports;
NI readerindex;
NI line;
NI moduleid;
Table251054 syms;
Memfile249202 memfile;
Tsymseq213792* methods;
NimStringDesc* origfile;
NIM_BOOL inviewmode;
};
struct Tlistentry135010 {
TNimObject Sup;
Tlistentry135010* prev;
Tlistentry135010* next;
};
struct Tscope213816 {
NI depthlevel;
Tstrtable213794 symbols;
Tnodeseq213784* usingsyms;
Tscope213816* parent;
};
struct Ttype213828 {
Tidobj188006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq213824* sons;
Tnode213790* n;
Tsym213822* owner;
Tsym213822* sym;
Tsym213822* destructor;
Tsym213822* deepcopy;
Tsym213822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc213804 loc;
};
struct Tident188012 {
Tidobj188006 Sup;
NimStringDesc* s;
Tident188012* next;
NI h;
};
struct Ropeobj168006 {
TNimObject Sup;
Ropeobj168006* left;
Ropeobj168006* right;
NI length;
NimStringDesc* data;
};
struct Tlib213808 {
Tlistentry135010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj168006* name;
Tnode213790* path;
};
struct TY262227 {
NIM_BOOL Field0;
NU8 Field1;
};
typedef TY262227 TY262230[256];
struct PprocHEX3Aobjecttype262221 {
TY262222* blocks;
Tsym213822* sym;
TY262230 slots;
NI maxslots;
};
struct TY262262 {
NimStringDesc* Field0;
Vmcallback262032 Field1;
};
struct Gcstack50016 {
Gcstack50016* prev;
Gcstack50016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29818[16];
struct Pagedesc47713 {
Pagedesc47713* next;
NI key;
TY29818 bits;
};
struct Basechunk29837 {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct Smallchunk29839 {
Basechunk29837 Sup;
Smallchunk29839* next;
Smallchunk29839* prev;
Freecell29829* freelist;
NI free;
NI acc;
NF data;
};
struct Llchunk29881 {
NI size;
NI acc;
Llchunk29881* next;
};
struct Bigchunk29841 {
Basechunk29837 Sup;
Bigchunk29841* next;
Bigchunk29841* prev;
NI align;
NF data;
};
struct Trunk29810 {
Trunk29810* next;
NI key;
TY29818 bits;
};
typedef Avlnode29885* TY29892[2];
struct Avlnode29885 {
TY29892 link;
NI key;
NI upperbound;
NI level;
};
struct Vmargs262030 {
NI ra;
NI rb;
NI rc;
void* slots;
Tnode213790* currentexception;
};
struct Tllstream201204 {
TNimObject Sup;
NU8 kind;
FILE* f;
NimStringDesc* s;
NI rd;
NI wr;
NI lineoffset;
};
struct Tiipair220159 {
NI key;
NI val;
};
struct Keyvaluepair251060 {
NI Field0;
NI Field1;
Tsym213822* Field2;
};
struct Tinstantiation213812 {
Tsym213822* sym;
Ttypeseq213824* concretetypes;
TY213913* usedby;
NI compilesid;
};
struct Tblock262018 {
Tsym213822* label;
TY262202* fixups;
};
struct Freecell29829 {
Freecell29829* next;
NI zerofield;
};
struct TY125402 {
TGenericSeq Sup;
NimStringDesc* data[SEQ_DECL_SIZE];
};
struct Ttypeseq213824 {
TGenericSeq Sup;
Ttype213828* data[SEQ_DECL_SIZE];
};
struct TY213925 {
TGenericSeq Sup;
Tinstantiation213812* data[SEQ_DECL_SIZE];
};
struct Tsymseq213792 {
TGenericSeq Sup;
Tsym213822* data[SEQ_DECL_SIZE];
};
struct TY262242 {
TGenericSeq Sup;
NU32 data[SEQ_DECL_SIZE];
};
struct TY182093 {
TGenericSeq Sup;
Tlineinfo181337 data[SEQ_DECL_SIZE];
};
struct TY262261 {
TGenericSeq Sup;
TY262262 data[SEQ_DECL_SIZE];
};
struct Tnodeseq213784 {
TGenericSeq Sup;
Tnode213790* data[SEQ_DECL_SIZE];
};
struct TY213913 {
TGenericSeq Sup;
NI32 data[SEQ_DECL_SIZE];
};
struct Tiipairseq220161 {
TGenericSeq Sup;
Tiipair220159 data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq251057 {
TGenericSeq Sup;
Keyvaluepair251060 data[SEQ_DECL_SIZE];
};
struct TY262222 {
TGenericSeq Sup;
Tblock262018 data[SEQ_DECL_SIZE];
};
struct TY262202 {
TGenericSeq Sup;
NI data[SEQ_DECL_SIZE];
};
N_NIMCALL(Tnode213790*, includemodule_530818)(Tsym213822* s, NI32 fileidx);
N_NIMCALL(Tsym213822*, importmodule_530788)(Tsym213822* s, NI32 fileidx);
N_NIMCALL(void, initdefines_189184)(void);
N_NIMCALL(void, definesymbol_189004)(NimStringDesc* symbol);
N_NIMCALL(void, registerpass_260145)(Tpass260014 p);
N_NIMCALL(Tpasscontext260002*, myopen_466665)(Tsym213822* module);
N_NIMCALL(Tpasscontext260002*, myopencached_466696)(Tsym213822* module, Trodreader251021* rd);
N_NIMCALL(Tnode213790*, myprocess_466804)(Tpasscontext260002* context, Tnode213790* n);
N_NIMCALL(Tnode213790*, myclose_466814)(Tpasscontext260002* context, Tnode213790* n);
N_NIMCALL(Tpasscontext260002*, myopen_413030)(Tsym213822* module);
N_NIMCALL(Tnode213790*, myprocess_413203)(Tpasscontext260002* c, Tnode213790* n);
N_NIMCALL(void, appendstr_135244)(Tlinkedlist135016* list, NimStringDesc* data);
N_NIMCALL(Tsym213822*, makemodule_530884)(NimStringDesc* filename);
N_NIMCALL(Tctx262036*, setupvm_534075)(Tsym213822* module, NimStringDesc* scriptname);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP3655)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(Tctx262036*, newctx_262267)(Tsym213822* module);
N_NIMCALL(void, registeradditionalops_412930)(Tctx262036* c);
N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY118906* Result);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell47705*, usrtocell_51640)(void* usr);
static N_INLINE(void, rtladdzct_53201)(Cell47705* c);
N_NOINLINE(void, addzct_51617)(Cellseq47721* s, Cell47705* c);
N_NIMCALL(void, registercallback_262374)(Tctx262036* c, NimStringDesc* name, Vmcallback262032 callback);
N_CLOSURE(void, HEX3Aanonymous_534094)(Vmargs262030* a, void* ClEnv);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(void, listdirs_534003)(Vmargs262030* a, NU8 filter);
N_NIMCALL(NimStringDesc*, getstring_401037)(Vmargs262030* a, NI i);
N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NimStringDesc*, HEX2F_118665)(NimStringDesc* head, NimStringDesc* tail);
static N_INLINE(NIM_BOOL, direxists_122008)(NimStringDesc* dir);
N_NIMCALL(NIM_BOOL, nosexistsDir)(NimStringDesc* dir);
N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq, NI elemsize);
N_NIMCALL(void, setresult_400942)(Vmargs262030* a, TY125402* v);
static N_INLINE(void, popSafePoint)(void);
N_NIMCALL(NIM_BOOL, isObj)(TNimType* obj, TNimType* subclass);
static N_INLINE(Exception*, getCurrentException)(void);
static N_INLINE(NimStringDesc*, getcurrentexceptionmsg_87405)(void);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(void, popCurrentException)(void);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_54019)(Cell47705* c);
static N_INLINE(NIM_BOOL, canbecycleroot_51658)(Cell47705* c);
static N_INLINE(void, rtladdcycleroot_52420)(Cell47705* c);
N_NOINLINE(void, incl_48447)(Cellset47717* s, Cell47705* cell);
static N_INLINE(void, decref_53601)(Cell47705* c);
N_NIMCALL(void, reraiseException)(void);
N_CLOSURE(void, HEX3Aanonymous_534098)(Vmargs262030* a, void* ClEnv);
N_CLOSURE(void, HEX3Aanonymous_534102)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, nosremoveDir)(NimStringDesc* dir);
N_CLOSURE(void, HEX3Aanonymous_534105)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, nosremoveFile)(NimStringDesc* file);
N_CLOSURE(void, HEX3Aanonymous_534108)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, noscreateDir)(NimStringDesc* dir);
N_CLOSURE(void, HEX3Aanonymous_534111)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, setresult_400900)(Vmargs262030* a, NimStringDesc* v);
N_CLOSURE(void, HEX3Aanonymous_534114)(Vmargs262030* a, void* ClEnv);
static N_INLINE(void, setcurrentdir_123001)(NimStringDesc* newdir);
N_NOINLINE(void, raiseoserror_121003)(NI32 errorcode, NimStringDesc* additionalinfo);
N_NIMCALL(NI32, oslasterror_121019)(void);
N_CLOSURE(void, HEX3Aanonymous_534117)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void);
N_CLOSURE(void, HEX3Aanonymous_534120)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, nosmoveFile)(NimStringDesc* source, NimStringDesc* dest);
N_CLOSURE(void, HEX3Aanonymous_534123)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, noscopyFile)(NimStringDesc* source, NimStringDesc* dest);
N_CLOSURE(void, HEX3Aanonymous_534126)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, setresult_400851)(Vmargs262030* a, NF v);
N_NIMCALL(NF, toseconds_105457)(time_t time);
N_NIMCALL(time_t, nosgetLastModificationTime)(NimStringDesc* file);
N_CLOSURE(void, HEX3Aanonymous_534129)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, setresult_400831)(Vmargs262030* a, NI64 v);
N_NIMCALL(NI, nospexecCmd)(NimStringDesc* command);
N_NIMCALL(void, HEX3Aanonymous_534132)(Vmargs262030* a);
N_NIMCALL(NimStringDesc*, getenv_126024)(NimStringDesc* key);
N_NIMCALL(void, HEX3Aanonymous_534135)(Vmargs262030* a);
N_NIMCALL(void, setresult_400871)(Vmargs262030* a, NIM_BOOL v_400874);
N_NIMCALL(NIM_BOOL, existsenv_126033)(NimStringDesc* key);
N_NIMCALL(void, HEX3Aanonymous_534138)(Vmargs262030* a);
N_NIMCALL(void, HEX3Aanonymous_534141)(Vmargs262030* a);
static N_INLINE(NIM_BOOL, fileexists_122004)(NimStringDesc* filename);
N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename);
N_CLOSURE(void, HEX3Aanonymous_534144)(Vmargs262030* a, void* ClEnv);
N_NIMCALL(void, HEX3Aanonymous_534147)(Vmargs262030* a);
N_NIMCALL(void, setconfigvar_159286)(NimStringDesc* key, NimStringDesc* val);
N_NIMCALL(void, HEX3Aanonymous_534150)(Vmargs262030* a);
N_NIMCALL(NimStringDesc*, getconfigvar_159282)(NimStringDesc* key);
N_NIMCALL(void, HEX3Aanonymous_534153)(Vmargs262030* a);
N_NIMCALL(NIM_BOOL, existsconfigvar_159278)(NimStringDesc* key);
N_NIMCALL(void, HEX3Aanonymous_534156)(Vmargs262030* a);
N_NIMCALL(NimStringDesc*, getnimcachedir_159610)(void);
N_NIMCALL(void, HEX3Aanonymous_534159)(Vmargs262030* a);
N_NIMCALL(NimStringDesc*, paramstr_131607)(NI i);
N_NIMCALL(NI64, getint_400986)(Vmargs262030* a, NI i);
N_NIMCALL(void, HEX3Aanonymous_534162)(Vmargs262030* a);
N_NIMCALL(NI, paramcount_131626)(void);
N_NIMCALL(void, HEX3Aanonymous_534165)(Vmargs262030* a);
N_NIMCALL(NI, nsuCmpIgnoreStyle)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(void, HEX3Aanonymous_534168)(Vmargs262030* a);
N_NIMCALL(NI, nsuCmpIgnoreCase)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(void, HEX3Aanonymous_534171)(Vmargs262030* a);
N_NIMCALL(NimStringDesc*, canonicalizepath_159405)(NimStringDesc* path);
N_NIMCALL(void, HEX3Aanonymous_534175)(Vmargs262030* a);
N_NIMCALL(void, HEX3Aanonymous_534178)(Vmargs262030* a);
N_NIMCALL(void, processswitch_199016)(NimStringDesc* switch_199018, NimStringDesc* arg, NU8 pass, Tlineinfo181337 info);
N_NIMCALL(Tlineinfo181337, unknownlineinfo_182090)(void);
N_NIMCALL(void, compilesystemmodule_530856)(void);
N_NIMCALL(void, processmodule_260044)(Tsym213822* module, Tllstream201204* stream, Trodreader251021* rd);
N_NIMCALL(Tllstream201204*, llstreamopen_201241)(NimStringDesc* filename, NU8 mode);
N_NIMCALL(void, resetallmoduleshard_530353)(void);
N_NIMCALL(void, undefsymbol_189007)(NimStringDesc* symbol);
STRING_LITERAL(TMP2058, "nimscript", 9);
STRING_LITERAL(TMP2059, "nimconfig", 9);
STRING_LITERAL(TMP3656, "stdlib.system.listFiles", 23);
STRING_LITERAL(TMP3658, ".", 1);
STRING_LITERAL(TMP3659, "..", 2);
STRING_LITERAL(TMP3660, "", 0);
STRING_LITERAL(TMP3661, "stdlib.system.listDirs", 22);
STRING_LITERAL(TMP3663, "stdlib.system.removeDir", 23);
STRING_LITERAL(TMP3667, "stdlib.system.removeFile", 24);
STRING_LITERAL(TMP3669, "stdlib.system.createDir", 23);
STRING_LITERAL(TMP3671, "stdlib.system.getOsError", 24);
STRING_LITERAL(TMP3673, "stdlib.system.setCurrentDir", 27);
STRING_LITERAL(TMP3675, "stdlib.system.getCurrentDir", 27);
STRING_LITERAL(TMP3677, "stdlib.system.moveFile", 22);
STRING_LITERAL(TMP3679, "stdlib.system.copyFile", 22);
STRING_LITERAL(TMP3681, "stdlib.system.getLastModificationTime", 37);
STRING_LITERAL(TMP3683, "stdlib.system.rawExec", 21);
STRING_LITERAL(TMP3685, "stdlib.system.getEnv", 20);
STRING_LITERAL(TMP3687, "stdlib.system.existsEnv", 23);
STRING_LITERAL(TMP3689, "stdlib.system.dirExists", 23);
STRING_LITERAL(TMP3691, "stdlib.system.fileExists", 24);
STRING_LITERAL(TMP3693, "stdlib.system.thisDir", 21);
STRING_LITERAL(TMP3694, "stdlib.system.put", 17);
STRING_LITERAL(TMP3696, "stdlib.system.get", 17);
STRING_LITERAL(TMP3698, "stdlib.system.exists", 20);
STRING_LITERAL(TMP3700, "stdlib.system.nimcacheDir", 25);
STRING_LITERAL(TMP3702, "stdlib.system.paramStr", 22);
STRING_LITERAL(TMP3704, "stdlib.system.paramCount", 24);
STRING_LITERAL(TMP3706, "stdlib.system.cmpIgnoreStyle", 28);
STRING_LITERAL(TMP3708, "stdlib.system.cmpIgnoreCase", 27);
STRING_LITERAL(TMP3710, "stdlib.system.setCommand", 24);
STRING_LITERAL(TMP3713, "stdlib.system.getCommand", 24);
STRING_LITERAL(TMP3715, "stdlib.system.switch", 20);
extern TY260054 gincludefile_260058;
extern TY260049 gimportmodule_260053;
extern Tlinkedlist135016 searchpaths_159125;
extern NimStringDesc* libpath_159198;
extern Tctx262036* globalctx_413017;
TNimType NTI534182; /* object */
extern TNimType NTI324021; /* range -1..0(int) */
extern TNimType NTI138; /* string */
TNimType NTI534181; /* ref object */
extern Gcheap50018 gch_50059;
extern TSafePoint* exchandler_19637;
extern TNimType NTI125402; /* seq[string] */
extern TNimType NTI3630; /* OSError */
extern Exception* currexception_19639;
extern NimStringDesc* command_159205;
extern NimStringDesc* gprojectname_159199;
extern NimStringDesc* gprojectfull_159201;
extern NimStringDesc* gprojectpath_159200;
N_NIMCALL(void, TMP3655)(void* p, NI op) {
TY534182* a;
a = (TY534182*)p;
nimGCvisit((void*)(*a).errormsg534080, op);
nimGCvisit((void*)(*a).vthisdir534081, op);
}
static N_INLINE(Cell47705*, usrtocell_51640)(void* usr) {
Cell47705* result;
result = 0;
result = ((Cell47705*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(Cell47705))))));
return result;
}
static N_INLINE(void, rtladdzct_53201)(Cell47705* c) {
addzct_51617((&gch_50059.zct), c);
}
static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
Cell47705* c;
c = usrtocell_51640(p);
{
(*c).refcount -= ((NI) 8);
if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
rtladdzct_53201(c);
}
LA3: ;
}
static N_INLINE(void, pushSafePoint)(TSafePoint* s) {
(*s).hasRaiseAction = NIM_FALSE;
(*s).prev = exchandler_19637;
exchandler_19637 = s;
}
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b) {
NIM_BOOL result;
NIM_BOOL LOC11;
int LOC13;
{ result = 0;
{
if (!(a == b)) goto LA3;
result = NIM_TRUE;
goto BeforeRet;
}
LA3: ;
{
NIM_BOOL LOC7;
LOC7 = 0;
LOC7 = (a == NIM_NIL);
if (LOC7) goto LA8;
LOC7 = (b == NIM_NIL);
LA8: ;
if (!LOC7) goto LA9;
result = NIM_FALSE;
goto BeforeRet;
}
LA9: ;
LOC11 = 0;
LOC11 = ((*a).Sup.len == (*b).Sup.len);
if (!(LOC11)) goto LA12;
LOC13 = 0;
LOC13 = memcmp(((NCSTRING) ((*a).data)), ((NCSTRING) ((*b).data)), (*a).Sup.len);
LOC11 = (LOC13 == ((NI32) 0));
LA12: ;
result = LOC11;
goto BeforeRet;
}BeforeRet: ;
return result;
}
static N_INLINE(NIM_BOOL, direxists_122008)(NimStringDesc* dir) {
NIM_BOOL result;
result = 0;
result = nosexistsDir(dir);
return result;
}
N_NIMCALL(void, listdirs_534003)(Vmargs262030* a, NU8 filter) {
NimStringDesc* dir;
TY125402* result;
dir = getstring_401037(a, ((NI) 0));
result = (TY125402*) newSeq((&NTI125402), 0);
{
NU8 kind_534027;
NimStringDesc* path_534028;
DIR* d_534066;
kind_534027 = 0;
path_534028 = 0;
d_534066 = opendir(dir->data);
{
int LOC66;
if (!!((d_534066 == NIM_NIL))) goto LA4;
{
while (1) {
{
struct dirent* x_534068;
NimStringDesc* y_534070;
x_534068 = readdir(d_534066);
{
if (!(x_534068 == NIM_NIL)) goto LA11;
goto LA6;
}
LA11: ;
y_534070 = cstrToNimstr(((NCSTRING) ((*x_534068).d_name)));
{
NIM_BOOL LOC15;
struct stat s_534072;
NU8 k_534074;
LOC15 = 0;
LOC15 = !(eqStrings(y_534070, ((NimStringDesc*) &TMP3658)));
if (!(LOC15)) goto LA16;
LOC15 = !(eqStrings(y_534070, ((NimStringDesc*) &TMP3659)));
LA16: ;
if (!LOC15) goto LA17;
memset((void*)(&s_534072), 0, sizeof(s_534072));
{
if (!NIM_TRUE) goto LA21;
y_534070 = HEX2F_118665(dir, y_534070);
}
LA21: ;
k_534074 = ((NU8) 0);
{
if (!!(((*x_534068).d_type == ((NI8) 0)))) goto LA25;
{
if (!((*x_534068).d_type == ((NI8) 4))) goto LA29;
k_534074 = ((NU8) 2);
}
LA29: ;
{
if (!((*x_534068).d_type == ((NI8) 10))) goto LA33;
{
NIM_BOOL LOC37;
LOC37 = 0;
LOC37 = direxists_122008(y_534070);
if (!LOC37) goto LA38;
k_534074 = ((NU8) 3);
}
goto LA35;
LA38: ;
{
k_534074 = (NU8)(k_534074 + ((NI) 1));
}
LA35: ;
}
LA33: ;
kind_534027 = k_534074;
path_534028 = y_534070;
{
NimStringDesc* LOC45;
if (!((filter &(1U<<((NU)(kind_534027)&7U)))!=0)) goto LA43;
result = (TY125402*) incrSeqV2(&(result)->Sup, sizeof(NimStringDesc*));
LOC45 = 0;
LOC45 = result->data[result->Sup.len]; result->data[result->Sup.len] = copyStringRC1(path_534028);
if (LOC45) nimGCunrefNoCycle(LOC45);
++result->Sup.len;
}
LA43: ;
goto LA8;
}
LA25: ;
{
int LOC48;
LOC48 = 0;
LOC48 = lstat(y_534070->data, (&s_534072));
if (!(LOC48 < ((NI32) 0))) goto LA49;
goto LA6;
}
LA49: ;
{
NIM_BOOL LOC53;
LOC53 = 0;
LOC53 = S_ISDIR(s_534072.st_mode);
if (!LOC53) goto LA54;
k_534074 = ((NU8) 2);
}
LA54: ;
{
NIM_BOOL LOC58;
LOC58 = 0;
LOC58 = S_ISLNK(s_534072.st_mode);
if (!LOC58) goto LA59;
k_534074 = (NU8)(k_534074 + ((NI) 1));
}
LA59: ;
kind_534027 = k_534074;
path_534028 = y_534070;
{
NimStringDesc* LOC65;
if (!((filter &(1U<<((NU)(kind_534027)&7U)))!=0)) goto LA63;
result = (TY125402*) incrSeqV2(&(result)->Sup, sizeof(NimStringDesc*));
LOC65 = 0;
LOC65 = result->data[result->Sup.len]; result->data[result->Sup.len] = copyStringRC1(path_534028);
if (LOC65) nimGCunrefNoCycle(LOC65);
++result->Sup.len;
}
LA63: ;
}
LA17: ;
} LA8: ;
}
} LA6: ;
LOC66 = 0;
LOC66 = closedir(d_534066);
}
LA4: ;
}
setresult_400942(a, result);
}
static N_INLINE(void, popSafePoint)(void) {
exchandler_19637 = (*exchandler_19637).prev;
}
static N_INLINE(Exception*, getCurrentException)(void) {
Exception* result;
result = 0;
result = currexception_19639;
return result;
}
static N_INLINE(NimStringDesc*, getcurrentexceptionmsg_87405)(void) {
NimStringDesc* result;
Exception* e;
{ result = 0;
e = getCurrentException();
{
if (!(e == NIM_NIL)) goto LA3;
result = copyString(((NimStringDesc*) &TMP3660));
}
goto LA1;
LA3: ;
{
result = copyString((*e).message);
}
LA1: ;
goto BeforeRet;
}BeforeRet: ;
return result;
}
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
{
Cell47705* c;
if (!!((src == NIM_NIL))) goto LA3;
c = usrtocell_51640(src);
(*c).refcount += ((NI) 8);
}
LA3: ;
{
Cell47705* c;
if (!!(((*dest) == NIM_NIL))) goto LA7;
c = usrtocell_51640((*dest));
{
(*c).refcount -= ((NI) 8);
if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA11;
rtladdzct_53201(c);
}
LA11: ;
}
LA7: ;
(*dest) = src;
}
static N_INLINE(NIM_BOOL, canbecycleroot_51658)(Cell47705* c) {
NIM_BOOL result;
result = 0;
result = !((((*(*c).typ).flags &(1U<<((NU)(((NU8) 1))&7U)))!=0));
return result;
}
static N_INLINE(void, rtladdcycleroot_52420)(Cell47705* c) {
{
if (!!((((NI) ((NI)((*c).refcount & ((NI) 3)))) == ((NI) 3)))) goto LA3;
(*c).refcount = (NI)((NI)((*c).refcount & ((NI) -4)) | ((NI) 3));
incl_48447((&gch_50059.cycleroots), c);
}
LA3: ;
}
static N_INLINE(void, incref_54019)(Cell47705* c) {
(*c).refcount = (NI)((NU32)((*c).refcount) + (NU32)(((NI) 8)));
{
NIM_BOOL LOC3;
LOC3 = 0;
LOC3 = canbecycleroot_51658(c);
if (!LOC3) goto LA4;
rtladdcycleroot_52420(c);
}
LA4: ;
}
static N_INLINE(void, decref_53601)(Cell47705* c) {
{
(*c).refcount -= ((NI) 8);
if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
rtladdzct_53201(c);
}
goto LA1;
LA3: ;
{
NIM_BOOL LOC6;
LOC6 = 0;
LOC6 = canbecycleroot_51658(c);
if (!LOC6) goto LA7;
rtladdcycleroot_52420(c);
}
goto LA1;
LA7: ;
LA1: ;
}
static N_INLINE(void, asgnRef)(void** dest, void* src) {
{
Cell47705* LOC5;
if (!!((src == NIM_NIL))) goto LA3;
LOC5 = 0;
LOC5 = usrtocell_51640(src);
incref_54019(LOC5);
}
LA3: ;
{
Cell47705* LOC10;
if (!!(((*dest) == NIM_NIL))) goto LA8;
LOC10 = 0;
LOC10 = usrtocell_51640((*dest));
decref_53601(LOC10);
}
LA8: ;
(*dest) = src;
}
static N_INLINE(void, popCurrentException)(void) {
asgnRef((void**) (&currexception_19639), NIM_NIL);
}
N_CLOSURE(void, HEX3Aanonymous_534094)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534185;
TSafePoint TMP3657;
HEX3Aenvp_534185 = (TY534182*) ClEnv;
pushSafePoint(&TMP3657);
TMP3657.status = _setjmp(TMP3657.context);
if (TMP3657.status == 0) {
listdirs_534003(a, 3);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3657.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534185).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3657.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534098)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534187;
TSafePoint TMP3662;
HEX3Aenvp_534187 = (TY534182*) ClEnv;
pushSafePoint(&TMP3662);
TMP3662.status = _setjmp(TMP3662.context);
if (TMP3662.status == 0) {
listdirs_534003(a, 4);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3662.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534187).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3662.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534102)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534188;
TSafePoint TMP3664;
HEX3Aenvp_534188 = (TY534182*) ClEnv;
pushSafePoint(&TMP3664);
TMP3664.status = _setjmp(TMP3664.context);
if (TMP3664.status == 0) {
NimStringDesc* LOC2;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
nosremoveDir(LOC2);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3664.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534188).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3664.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534105)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534189;
TSafePoint TMP3668;
HEX3Aenvp_534189 = (TY534182*) ClEnv;
pushSafePoint(&TMP3668);
TMP3668.status = _setjmp(TMP3668.context);
if (TMP3668.status == 0) {
NimStringDesc* LOC2;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
nosremoveFile(LOC2);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3668.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534189).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3668.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534108)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534190;
TSafePoint TMP3670;
HEX3Aenvp_534190 = (TY534182*) ClEnv;
pushSafePoint(&TMP3670);
TMP3670.status = _setjmp(TMP3670.context);
if (TMP3670.status == 0) {
NimStringDesc* LOC2;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
noscreateDir(LOC2);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3670.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534190).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3670.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534111)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534191;
TSafePoint TMP3672;
HEX3Aenvp_534191 = (TY534182*) ClEnv;
pushSafePoint(&TMP3672);
TMP3672.status = _setjmp(TMP3672.context);
if (TMP3672.status == 0) {
setresult_400900(a, (*HEX3Aenvp_534191).errormsg534080);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3672.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534191).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3672.status != 0) reraiseException();
}
static N_INLINE(void, setcurrentdir_123001)(NimStringDesc* newdir) {
{
int LOC3;
NI32 LOC6;
LOC3 = 0;
LOC3 = chdir(newdir->data);
if (!!((LOC3 == ((NI32) 0)))) goto LA4;
LOC6 = 0;
LOC6 = oslasterror_121019();
raiseoserror_121003(LOC6, ((NimStringDesc*) &TMP3660));
}
LA4: ;
}
N_CLOSURE(void, HEX3Aanonymous_534114)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534192;
TSafePoint TMP3674;
HEX3Aenvp_534192 = (TY534182*) ClEnv;
pushSafePoint(&TMP3674);
TMP3674.status = _setjmp(TMP3674.context);
if (TMP3674.status == 0) {
NimStringDesc* LOC2;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
setcurrentdir_123001(LOC2);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3674.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534192).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3674.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534117)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534193;
TSafePoint TMP3676;
HEX3Aenvp_534193 = (TY534182*) ClEnv;
pushSafePoint(&TMP3676);
TMP3676.status = _setjmp(TMP3676.context);
if (TMP3676.status == 0) {
NimStringDesc* LOC2;
LOC2 = 0;
LOC2 = nosgetCurrentDir();
setresult_400900(a, LOC2);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3676.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534193).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3676.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534120)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534194;
TSafePoint TMP3678;
HEX3Aenvp_534194 = (TY534182*) ClEnv;
pushSafePoint(&TMP3678);
TMP3678.status = _setjmp(TMP3678.context);
if (TMP3678.status == 0) {
NimStringDesc* LOC2;
NimStringDesc* LOC3;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
LOC3 = 0;
LOC3 = getstring_401037(a, ((NI) 1));
nosmoveFile(LOC2, LOC3);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3678.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534194).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3678.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534123)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534195;
TSafePoint TMP3680;
HEX3Aenvp_534195 = (TY534182*) ClEnv;
pushSafePoint(&TMP3680);
TMP3680.status = _setjmp(TMP3680.context);
if (TMP3680.status == 0) {
NimStringDesc* LOC2;
NimStringDesc* LOC3;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
LOC3 = 0;
LOC3 = getstring_401037(a, ((NI) 1));
noscopyFile(LOC2, LOC3);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3680.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534195).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3680.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534126)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534196;
TSafePoint TMP3682;
HEX3Aenvp_534196 = (TY534182*) ClEnv;
pushSafePoint(&TMP3682);
TMP3682.status = _setjmp(TMP3682.context);
if (TMP3682.status == 0) {
NimStringDesc* LOC2;
time_t LOC3;
NF LOC4;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
LOC3 = 0;
LOC3 = nosgetLastModificationTime(LOC2);
LOC4 = 0;
LOC4 = toseconds_105457(LOC3);
setresult_400851(a, LOC4);
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3682.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534196).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3682.status != 0) reraiseException();
}
N_CLOSURE(void, HEX3Aanonymous_534129)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534197;
TSafePoint TMP3684;
HEX3Aenvp_534197 = (TY534182*) ClEnv;
pushSafePoint(&TMP3684);
TMP3684.status = _setjmp(TMP3684.context);
if (TMP3684.status == 0) {
NimStringDesc* LOC2;
NI LOC3;
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 0));
LOC3 = 0;
LOC3 = nospexecCmd(LOC2);
setresult_400831(a, ((NI64) (LOC3)));
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
TMP3684.status = 0;
asgnRefNoCycle((void**) (&(*HEX3Aenvp_534197).errormsg534080), getcurrentexceptionmsg_87405());
popCurrentException();
}
}
if (TMP3684.status != 0) reraiseException();
}
N_NIMCALL(void, HEX3Aanonymous_534132)(Vmargs262030* a) {
NimStringDesc* LOC1;
NimStringDesc* LOC2;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = getenv_126024(LOC1);
setresult_400900(a, LOC2);
}
N_NIMCALL(void, HEX3Aanonymous_534135)(Vmargs262030* a) {
NimStringDesc* LOC1;
NIM_BOOL LOC2;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = existsenv_126033(LOC1);
setresult_400871(a, LOC2);
}
N_NIMCALL(void, HEX3Aanonymous_534138)(Vmargs262030* a) {
NimStringDesc* LOC1;
NIM_BOOL LOC2;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = direxists_122008(LOC1);
setresult_400871(a, LOC2);
}
static N_INLINE(NIM_BOOL, fileexists_122004)(NimStringDesc* filename) {
NIM_BOOL result;
result = 0;
result = nosexistsFile(filename);
return result;
}
N_NIMCALL(void, HEX3Aanonymous_534141)(Vmargs262030* a) {
NimStringDesc* LOC1;
NIM_BOOL LOC2;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = fileexists_122004(LOC1);
setresult_400871(a, LOC2);
}
N_CLOSURE(void, HEX3Aanonymous_534144)(Vmargs262030* a, void* ClEnv) {
TY534182* HEX3Aenvp_534198;
HEX3Aenvp_534198 = (TY534182*) ClEnv;
setresult_400900(a, (*HEX3Aenvp_534198).vthisdir534081);
}
N_NIMCALL(void, HEX3Aanonymous_534147)(Vmargs262030* a) {
NimStringDesc* LOC1;
NimStringDesc* LOC2;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 1));
setconfigvar_159286(LOC1, LOC2);
}
N_NIMCALL(void, HEX3Aanonymous_534150)(Vmargs262030* a) {
NimStringDesc* LOC1;
NimStringDesc* LOC2;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = getconfigvar_159282(LOC1);
setresult_400900(a, LOC2);
}
N_NIMCALL(void, HEX3Aanonymous_534153)(Vmargs262030* a) {
NimStringDesc* LOC1;
NIM_BOOL LOC2;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = existsconfigvar_159278(LOC1);
setresult_400871(a, LOC2);
}
N_NIMCALL(void, HEX3Aanonymous_534156)(Vmargs262030* a) {
NimStringDesc* LOC1;
LOC1 = 0;
LOC1 = getnimcachedir_159610();
setresult_400900(a, LOC1);
}
N_NIMCALL(void, HEX3Aanonymous_534159)(Vmargs262030* a) {
NI64 LOC1;
NimStringDesc* LOC2;
LOC1 = 0;
LOC1 = getint_400986(a, ((NI) 0));
LOC2 = 0;
LOC2 = paramstr_131607(((NI) (LOC1)));
setresult_400900(a, LOC2);
}
N_NIMCALL(void, HEX3Aanonymous_534162)(Vmargs262030* a) {
NI LOC1;
LOC1 = 0;
LOC1 = paramcount_131626();
setresult_400831(a, ((NI64) (LOC1)));
}
N_NIMCALL(void, HEX3Aanonymous_534165)(Vmargs262030* a) {
NimStringDesc* LOC1;
NimStringDesc* LOC2;
NI LOC3;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 1));
LOC3 = 0;
LOC3 = nsuCmpIgnoreStyle(LOC1, LOC2);
setresult_400831(a, ((NI64) (LOC3)));
}
N_NIMCALL(void, HEX3Aanonymous_534168)(Vmargs262030* a) {
NimStringDesc* LOC1;
NimStringDesc* LOC2;
NI LOC3;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 1));
LOC3 = 0;
LOC3 = nsuCmpIgnoreCase(LOC1, LOC2);
setresult_400831(a, ((NI64) (LOC3)));
}
N_NIMCALL(void, HEX3Aanonymous_534171)(Vmargs262030* a) {
NimStringDesc* arg;
asgnRefNoCycle((void**) (&command_159205), getstring_401037(a, ((NI) 0)));
arg = getstring_401037(a, ((NI) 1));
{
NimStringDesc* LOC5;
TSafePoint TMP3711;
if (!(((NI) 0) < (arg ? arg->Sup.len : 0))) goto LA3;
LOC5 = 0;
LOC5 = gprojectname_159199; gprojectname_159199 = copyStringRC1(arg);
if (LOC5) nimGCunrefNoCycle(LOC5);
pushSafePoint(&TMP3711);
TMP3711.status = _setjmp(TMP3711.context);
if (TMP3711.status == 0) {
NimStringDesc* LOC7;
LOC7 = 0;
LOC7 = HEX2F_118665(gprojectpath_159200, gprojectname_159199);
asgnRefNoCycle((void**) (&gprojectfull_159201), canonicalizepath_159405(LOC7));
popSafePoint();
}
else {
popSafePoint();
if (isObj(getCurrentException()->Sup.m_type, (&NTI3630))) {
NimStringDesc* LOC10;
TMP3711.status = 0;
LOC10 = 0;
LOC10 = gprojectfull_159201; gprojectfull_159201 = copyStringRC1(gprojectname_159199);
if (LOC10) nimGCunrefNoCycle(LOC10);
popCurrentException();
}
}
if (TMP3711.status != 0) reraiseException();
}
LA3: ;
}
N_NIMCALL(void, HEX3Aanonymous_534175)(Vmargs262030* a) {
setresult_400900(a, command_159205);
}
N_NIMCALL(void, HEX3Aanonymous_534178)(Vmargs262030* a) {
NimStringDesc* LOC1;
NimStringDesc* LOC2;
Tlineinfo181337 LOC3;
LOC1 = 0;
LOC1 = getstring_401037(a, ((NI) 0));
LOC2 = 0;
LOC2 = getstring_401037(a, ((NI) 1));
LOC3 = unknownlineinfo_182090();
processswitch_199016(LOC1, LOC2, ((NU8) 2), LOC3);
}
N_NIMCALL(Tctx262036*, setupvm_534075)(Tsym213822* module, NimStringDesc* scriptname) {
Tctx262036* result;
TY534182* HEX3Aenv_534200;
TY118906 LOC1;
NimStringDesc* LOC2;
Vmcallback262032 LOC3;
Vmcallback262032 LOC4;
Vmcallback262032 LOC5;
Vmcallback262032 LOC6;
Vmcallback262032 LOC7;
Vmcallback262032 LOC8;
Vmcallback262032 LOC9;
Vmcallback262032 LOC10;
Vmcallback262032 LOC11;
Vmcallback262032 LOC12;
Vmcallback262032 LOC13;
Vmcallback262032 LOC14;
Vmcallback262032 LOC15;
Vmcallback262032 LOC16;
Vmcallback262032 LOC17;
Vmcallback262032 LOC18;
Vmcallback262032 LOC19;
Vmcallback262032 LOC20;
Vmcallback262032 LOC21;
Vmcallback262032 LOC22;
Vmcallback262032 LOC23;
Vmcallback262032 LOC24;
Vmcallback262032 LOC25;
Vmcallback262032 LOC26;
Vmcallback262032 LOC27;
Vmcallback262032 LOC28;
Vmcallback262032 LOC29;
Vmcallback262032 LOC30;
result = 0;
HEX3Aenv_534200 = 0;
HEX3Aenv_534200 = (TY534182*) newObj((&NTI534181), sizeof(TY534182));
result = newctx_262267(module);
(*result).mode = ((NU8) 0);
registeradditionalops_412930(result);
memset((void*)(&LOC1), 0, sizeof(LOC1));
nossplitFile(scriptname, (&LOC1));
LOC2 = 0;
LOC2 = (*HEX3Aenv_534200).vthisdir534081; (*HEX3Aenv_534200).vthisdir534081 = copyStringRC1(LOC1.Field0);
if (LOC2) nimGCunrefNoCycle(LOC2);
memset((void*)(&LOC3), 0, sizeof(LOC3));
LOC3.ClPrc = HEX3Aanonymous_534094; LOC3.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3656), LOC3);
memset((void*)(&LOC4), 0, sizeof(LOC4));
LOC4.ClPrc = HEX3Aanonymous_534098; LOC4.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3661), LOC4);
memset((void*)(&LOC5), 0, sizeof(LOC5));
LOC5.ClPrc = HEX3Aanonymous_534102; LOC5.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3663), LOC5);
memset((void*)(&LOC6), 0, sizeof(LOC6));
LOC6.ClPrc = HEX3Aanonymous_534105; LOC6.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3667), LOC6);
memset((void*)(&LOC7), 0, sizeof(LOC7));
LOC7.ClPrc = HEX3Aanonymous_534108; LOC7.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3669), LOC7);
memset((void*)(&LOC8), 0, sizeof(LOC8));
LOC8.ClPrc = HEX3Aanonymous_534111; LOC8.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3671), LOC8);
memset((void*)(&LOC9), 0, sizeof(LOC9));
LOC9.ClPrc = HEX3Aanonymous_534114; LOC9.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3673), LOC9);
memset((void*)(&LOC10), 0, sizeof(LOC10));
LOC10.ClPrc = HEX3Aanonymous_534117; LOC10.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3675), LOC10);
memset((void*)(&LOC11), 0, sizeof(LOC11));
LOC11.ClPrc = HEX3Aanonymous_534120; LOC11.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3677), LOC11);
memset((void*)(&LOC12), 0, sizeof(LOC12));
LOC12.ClPrc = HEX3Aanonymous_534123; LOC12.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3679), LOC12);
memset((void*)(&LOC13), 0, sizeof(LOC13));
LOC13.ClPrc = HEX3Aanonymous_534126; LOC13.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3681), LOC13);
memset((void*)(&LOC14), 0, sizeof(LOC14));
LOC14.ClPrc = HEX3Aanonymous_534129; LOC14.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3683), LOC14);
memset((void*)(&LOC15), 0, sizeof(LOC15));
LOC15.ClPrc = ((TMP3686) (HEX3Aanonymous_534132)); LOC15.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3685), LOC15);
memset((void*)(&LOC16), 0, sizeof(LOC16));
LOC16.ClPrc = ((TMP3688) (HEX3Aanonymous_534135)); LOC16.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3687), LOC16);
memset((void*)(&LOC17), 0, sizeof(LOC17));
LOC17.ClPrc = ((TMP3690) (HEX3Aanonymous_534138)); LOC17.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3689), LOC17);
memset((void*)(&LOC18), 0, sizeof(LOC18));
LOC18.ClPrc = ((TMP3692) (HEX3Aanonymous_534141)); LOC18.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3691), LOC18);
memset((void*)(&LOC19), 0, sizeof(LOC19));
LOC19.ClPrc = HEX3Aanonymous_534144; LOC19.ClEnv = HEX3Aenv_534200;
registercallback_262374(result, ((NimStringDesc*) &TMP3693), LOC19);
memset((void*)(&LOC20), 0, sizeof(LOC20));
LOC20.ClPrc = ((TMP3695) (HEX3Aanonymous_534147)); LOC20.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3694), LOC20);
memset((void*)(&LOC21), 0, sizeof(LOC21));
LOC21.ClPrc = ((TMP3697) (HEX3Aanonymous_534150)); LOC21.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3696), LOC21);
memset((void*)(&LOC22), 0, sizeof(LOC22));
LOC22.ClPrc = ((TMP3699) (HEX3Aanonymous_534153)); LOC22.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3698), LOC22);
memset((void*)(&LOC23), 0, sizeof(LOC23));
LOC23.ClPrc = ((TMP3701) (HEX3Aanonymous_534156)); LOC23.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3700), LOC23);
memset((void*)(&LOC24), 0, sizeof(LOC24));
LOC24.ClPrc = ((TMP3703) (HEX3Aanonymous_534159)); LOC24.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3702), LOC24);
memset((void*)(&LOC25), 0, sizeof(LOC25));
LOC25.ClPrc = ((TMP3705) (HEX3Aanonymous_534162)); LOC25.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3704), LOC25);
memset((void*)(&LOC26), 0, sizeof(LOC26));
LOC26.ClPrc = ((TMP3707) (HEX3Aanonymous_534165)); LOC26.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3706), LOC26);
memset((void*)(&LOC27), 0, sizeof(LOC27));
LOC27.ClPrc = ((TMP3709) (HEX3Aanonymous_534168)); LOC27.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3708), LOC27);
memset((void*)(&LOC28), 0, sizeof(LOC28));
LOC28.ClPrc = ((TMP3712) (HEX3Aanonymous_534171)); LOC28.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3710), LOC28);
memset((void*)(&LOC29), 0, sizeof(LOC29));
LOC29.ClPrc = ((TMP3714) (HEX3Aanonymous_534175)); LOC29.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3713), LOC29);
memset((void*)(&LOC30), 0, sizeof(LOC30));
LOC30.ClPrc = ((TMP3716) (HEX3Aanonymous_534178)); LOC30.ClEnv = NIM_NIL;
registercallback_262374(result, ((NimStringDesc*) &TMP3715), LOC30);
return result;
}
N_NIMCALL(void, runnimscript_534202)(NimStringDesc* scriptname) {
Tpass260014 LOC1;
Tpass260014 LOC2;
Tsym213822* m;
Tllstream201204* LOC3;
gincludefile_260058 = includemodule_530818;
gimportmodule_260053 = importmodule_530788;
initdefines_189184();
definesymbol_189004(((NimStringDesc*) &TMP2058));
definesymbol_189004(((NimStringDesc*) &TMP2059));
LOC1.Field0 = myopen_466665;
LOC1.Field1 = myopencached_466696;
LOC1.Field2 = myprocess_466804;
LOC1.Field3 = myclose_466814;
registerpass_260145(LOC1);
LOC2.Field0 = myopen_413030;
LOC2.Field1 = NIM_NIL;
LOC2.Field2 = myprocess_413203;
LOC2.Field3 = myprocess_413203;
registerpass_260145(LOC2);
appendstr_135244((&searchpaths_159125), libpath_159198);
m = makemodule_530884(scriptname);
(*m).flags |= ((NU32)1)<<((((NU8) 12))%(sizeof(NU32)*8));
asgnRef((void**) (&globalctx_413017), setupvm_534075(m, scriptname));
compilesystemmodule_530856();
LOC3 = 0;
LOC3 = llstreamopen_201241(scriptname, ((NU8) 0));
processmodule_260044(m, LOC3, NIM_NIL);
resetallmoduleshard_530353();
asgnRef((void**) (&globalctx_413017), NIM_NIL);
undefsymbol_189007(((NimStringDesc*) &TMP2058));
undefsymbol_189007(((NimStringDesc*) &TMP2059));
}
NIM_EXTERNC N_NOINLINE(void, compiler_scriptconfigInit000)(void) {
}
NIM_EXTERNC N_NOINLINE(void, compiler_scriptconfigDatInit000)(void) {
static TNimNode* TMP3654[3];
static TNimNode TMP1631[4];
NTI534182.size = sizeof(TY534182);
NTI534182.kind = 18;
NTI534182.base = 0;
NTI534182.flags = 2;
TMP3654[0] = &TMP1631[1];
TMP1631[1].kind = 1;
TMP1631[1].offset = offsetof(TY534182, HEX3Astate);
TMP1631[1].typ = (&NTI324021);
TMP1631[1].name = ":state";
TMP3654[1] = &TMP1631[2];
TMP1631[2].kind = 1;
TMP1631[2].offset = offsetof(TY534182, errormsg534080);
TMP1631[2].typ = (&NTI138);
TMP1631[2].name = "errorMsg534080";
TMP3654[2] = &TMP1631[3];
TMP1631[3].kind = 1;
TMP1631[3].offset = offsetof(TY534182, vthisdir534081);
TMP1631[3].typ = (&NTI138);
TMP1631[3].name = "vthisDir534081";
TMP1631[0].len = 3; TMP1631[0].kind = 2; TMP1631[0].sons = &TMP3654[0];
NTI534182.node = &TMP1631[0];
NTI534181.size = sizeof(TY534182*);
NTI534181.kind = 22;
NTI534181.base = (&NTI534182);
NTI534181.flags = 2;
NTI534181.marker = TMP3655;
}
|
9fdd340fb4fdc796fbfd5a9bf5dc25bdd2219297
|
55ed258cff2e4cd47559e4a5a5f7966528e559e5
|
/src/bsp/bsp.h
|
8d7639d061559c22e85ac0cd38de6d632e1b9646
|
[] |
no_license
|
facunava92/LabII_UCC_SE
|
6cf1f6d9caa1fdcc5386e54b093fcd487e778724
|
5b856fe3a9e14d6ca79213756720a86b7a835468
|
refs/heads/master
| 2021-01-11T22:05:36.481167 | 2017-01-14T14:54:40 | 2017-01-14T14:54:40 | 78,918,101 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,436 |
h
|
bsp.h
|
#ifndef _BSP_H
#define _BSP_H
#define X_Limit 240
#define Y_Init 72
#define X_Init 40
typedef enum{
SW_RIGHT=0, SW_LEFT=1, SW_UP=2, SW_DOWN=3, SW_DISC=4
}SW_typedef;
typedef enum {
st_showup_0=0,st_showup_1,st_showup_2,st_showup_3,st_showup_4,st_showup_5,st_showup_6,st_showup_7,
st_showup_8,st_showup_9,st_showup_10,st_showup_11,st_showup_12,st_showup_13,st_showup_14,st_showup_15,st_showup_16
}states_showup;
typedef enum {
st_standby_0=0,st_standby_1,st_standby_2,st_standby_3,st_standby_4
}states_standby;
typedef enum {
st_running_0=0,st_running_1,st_running_2,st_running_3,st_running_4,st_running_5,st_running_6,st_running_7,st_running_8,
st_running_9,st_running_10,st_running_11,st_running_12,st_running_13,st_running_14,st_running_15
}states_running;
typedef enum {
st_jump_0=0,st_jump_1,st_jump_2,st_jump_3,st_jump_4,st_jump_5,st_jump_6,st_jump_7,
st_jump_8,st_jump_9,st_jump_10
}states_jump;
typedef enum {
st_shoot_0=0,st_shoot_1,st_shoot_2,st_shoot_3,st_shoot_4,st_shoot_5,st_shoot_6,st_shoot_7,
st_shoot_8,st_shoot_9
}states_shoot;
typedef enum {
showup_0=0,standby_1, running_2, jump_3, shoot_4
}states;
void bsp_init(void);
void led_on(uint8_t led);
void led_off(uint8_t led);
void led_toggle(uint8_t led);
uint8_t get_sw_state(SW_typedef sw);
uint16_t adc_get(void);
void bsp_FillScreen(uint8_t color);
void bsp_SetPixel(uint16_t xp, uint16_t yp, uint8_t color);
void bsp_draw(void);
#endif
|
80fa32b921b62dbabc9e62862b7250fa334ec870
|
a2a0925dce3a526e2904a539d0458f654405bbdc
|
/Assembler/asm_sources/get_file.c
|
d80b05b12ceddd6cc51de7bfe7e50d5122c71450
|
[] |
no_license
|
DenisHuber0988/Corewar
|
bb09bc1f4e7c3f6a87c62f88dc73818534928ca5
|
3a5ab57edfc1f5cd45a83735ef8326459f6fb4c8
|
refs/heads/master
| 2020-03-23T16:34:46.592211 | 2018-11-15T14:09:10 | 2018-11-15T14:09:10 | 141,818,292 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 2,205 |
c
|
get_file.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jauplat <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/06/11 16:14:18 by jauplat #+# #+# */
/* Updated: 2018/10/07 14:59:32 by jauplat ### ########.fr */
/* */
/* ************************************************************************** */
#include "../asm_includes/asm.h"
/*
** check extension file and change it
*/
void magic(t_champ *begin, t_header *head, char *file)
{
int i;
int len;
len = ft_strlen(file);
i = 1;
if (file[len - 1] == 's' && file[len - 2] == '.')
{
file[len - 1] = '\0';
begin->file = ft_strjoin(file, "cor");
head->magic[0] = 0x00;
head->magic[1] = 0xea;
head->magic[2] = 0x83;
head->magic[3] = 0xf3;
}
else
error(-3);
}
/*
** function of redirection to the treatment of name or comment
*/
void tmp_header(char **str, t_header *head, int fd, int *i)
{
if (ft_strstr(str[0], NAME_CMD_STRING))
{
if (i[0] != 0)
error(-4);
name(head, fd, &str[0], 0);
i[0]++;
}
else if (ft_strstr(str[0], COMMENT_CMD_STRING))
{
if (i[0] != 1)
error(-4);
comment(head, fd, &str[0], 0);
i[0]++;
}
else
check_void_line(str[0]);
}
/*
** get a champion ".s" and use magic function and tmp_header function
*/
void get_file(t_champ *begin, t_header *head, char *file)
{
int fd;
char *str;
int i;
i = 0;
str = NULL;
if ((fd = open(file, O_RDONLY)) <= -1)
error(-2);
magic(begin, head, file);
while (get_next_line(fd, &str) > 0 && i != 2)
{
tmp_header(&str, head, fd, &i);
if (i == 2)
break ;
ft_strdel(&str);
}
ft_strdel(&str);
if (i != 2)
error(-4);
prog(begin, fd);
}
|
dd67380ffb9a9f2b5014cc9f7b3768360acde96b
|
b8a833801aa3f3618a4a68c1936299f8bd270038
|
/src/utilities/fbcpl/stdafx.h
|
85c631f89f0d5185bb06b638dc19f26697c63ba1
|
[] |
no_license
|
FirebirdSQL/firebird
|
039a84a81ea089852ad36339e44256c85dbf5b10
|
1973d01f396196d18f284114bd2905ac4dcfeb94
|
refs/heads/master
| 2023-09-01T21:34:39.835826 | 2023-08-31T20:13:52 | 2023-08-31T20:13:52 | 54,005,538 | 1,192 | 303 | null | 2023-09-14T16:12:28 | 2016-03-16T06:10:37 |
C++
|
UTF-8
|
C
| false | false | 1,280 |
h
|
stdafx.h
|
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__A4777E9A_E00D_11D6_9193_0050564001ED__INCLUDED_)
#define AFX_STDAFX_H__A4777E9A_E00D_11D6_9193_0050564001ED__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#undef TRACE // TRACE is used by Firebird too.
#include "firebird.h"
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#ifdef HAVE_SYS_TIMEB_H
# include <sys/timeb.h>
#endif
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef HAVE_PTHREAD_H
#include "fb_pthread.h"
#endif
#include "../ibase.h"
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__A4777E9A_E00D_11D6_9193_0050564001ED__INCLUDED_)
|
3f3a8216362f4fa2bb5ea979e70483353e022a90
|
96ea017090df62abf644a59ff0d3c9008f1a70ac
|
/lockdown/real_Lockdown.c
|
266a02c3007e00f434e57b13e1219de70aedd941
|
[
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] |
permissive
|
BNETDocs/lockdown
|
a58c7608486480a957b0e804e8a930216ec0e884
|
1c9e41e223d528848274a631577aa5914636d760
|
refs/heads/master
| 2021-01-20T00:51:43.807407 | 2017-04-24T06:33:53 | 2017-04-24T06:33:53 | 89,204,421 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 8,722 |
c
|
real_Lockdown.c
|
/* Copyright (c) 2007 x86
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. */
#include <windows.h>
#include "real_Lockdown.h"
static HMODULE ix86;
static HMODULE storm;
static HMODULE battle;
static void *addr_tweedle;
static void *addr_twitter;
static void *addr_sha1init;
static void *addr_sha1update;
static void *addr_sha1final;
static void *addr_sha1transform;
static void *addr_sha1updatewrapper;
static void *addr_calcvaluestring;
static void *addr_addrdecode;
static void *addr_checkrevision;
static void *addr_real_word_shifter;
static void *addr_string_combine;
static void *addr_number_compare_deprecated;
static void *addr_noname;
static void *addr_processreloc;
static void *addr_processimport;
static void *addr_arrangerecords;
static void *addr_ldheap_sort;
static void *addr_ld_sha1_pad;
static void *addr_hash1;
static void *addr_hash2;
static void *addr_hash_file;
static void *addr_addtoheap;
void real_sha1_initialize()
{
ix86 = LoadLibrary("c:\\temp\\lockdown-IX86-00.dll");
storm = LoadLibrary("C:\\program files\\starcraft\\storm.dll");
battle = LoadLibrary("C:\\program files\\starcraft\\battle.snp");
addr_tweedle = (void*) ((int) ix86 + 0x232e);
addr_twitter = (void*) ((int) ix86 + 0x2365);
addr_sha1init = (void*) ((int) ix86 + 0x2731);
addr_sha1update = (void*) ((int) ix86 + 0x275C);
addr_sha1final = (void*) ((int) ix86 + 0x27E8);
addr_sha1transform = (void*) ((int) ix86 + 0x2396);
addr_sha1updatewrapper = (void*) ((int) ix86 + 0x2317);
addr_calcvaluestring = (void*) ((int) ix86 + 0x116D);
addr_addrdecode = (void*) ((int) ix86 + 0x110E);
addr_real_word_shifter = (void*) ((int) ix86 + 0x14D9);
addr_string_combine = (void*) ((int) ix86 + 0x1000);
addr_number_compare_deprecated = (void*) ((int) ix86 + 0x1C8C);
addr_noname = (void*) ((int) ix86 + 0x1A40);
addr_processreloc = (void*) ((int) ix86 + 0x1DFD);
addr_processimport = (void*) ((int) ix86 + 0x1D15);
addr_arrangerecords = (void*) ((int) ix86 + 0x1A40);
addr_ldheap_sort = (void*) ((int) ix86 + 0x1540);
addr_ld_sha1_pad = (void*) ((int) ix86 + 0x1CA8);
addr_hash1 = (void*) ((int) ix86 + 0x1F84);
addr_hash2 = (void*) ((int) ix86 + 0x1E98);
addr_hash_file = (void*) ((int) ix86 + 0x2167);
addr_addtoheap = (void*) ((int) ix86 + 0x1C3D);
addr_checkrevision = GetProcAddress(ix86, "CheckRevision");
*((HANDLE*)(ix86 + 0x433c)) = GetProcessHeap();
}
void real_sha1_tweedle(int *ptr_rotator, int bitwise, int bitwise2, int bitwise3, int *ptr_adder, int *ptr_ret)
{
__asm
{
mov ecx, bitwise3
mov edx, ptr_adder
mov esi, ptr_ret
push bitwise2
push bitwise
push ptr_rotator
call addr_tweedle
add esp, 0x0c
}
}
void real_sha1_twitter(int *ptr_rotator, int bitwise, int rotator2, int bitwise2, int *ptr_rotator3, int *ptr_ret)
{
__asm
{
mov eax, rotator2
mov edx, bitwise2
mov esi, ptr_rotator3
mov edi, ptr_ret
push bitwise
push ptr_rotator
call addr_twitter
add esp, 0x08
}
}
void real_sha1_init(real_LD_SHA1_CTX *ctx)
{
__asm
{
mov eax, ctx
call addr_sha1init
}
}
void real_sha1_update(real_LD_SHA1_CTX *ctx, char *data, int len)
{
__asm
{
mov eax, data
mov esi, ctx
push len
// int 3
call addr_sha1update
}
}
void real_sha1_final(real_LD_SHA1_CTX *ctx, char *buffer)
{
__asm
{
mov ecx, ctx
mov edi, buffer
// int 3
call addr_sha1final
}
}
void real_sha1_transform(int *data, int *state)
{
__asm
{
mov eax, data
push state
call addr_sha1transform
add esp, 4
}
}
BOOL real_shuffle_value_string(char *strn, int len, char *buffer)
{
int retval;
__asm
{
push len
push strn
mov esi, buffer
//int 3
call addr_calcvaluestring;
add esp, 8
mov retval, eax
}
return retval;
}
void real_word_shifter(short *str1,short *str2)
{
__asm
{
mov ecx, str1
mov edx, str2
call addr_real_word_shifter
}
}
int real_string_combine(char *buf1,int *lngth,char *buf2)
{
int retval;
__asm
{
push buf2
push lngth
push buf1
call addr_string_combine
add esp, 0x0c
mov retval, eax
}
return retval;
}
int real_number_compare_deprecated(int *num1, int *num2)
{
int retval;
__asm
{
push num2
push num1
call addr_number_compare_deprecated
add esp, 8
mov retval, eax
}
return retval;
}
int real_process_reloc(t_lockdown_heap *lockdown_heap, void *baseaddr, BOOL is32bit, void *reloc_section)
{
__asm
{
push is32bit
push baseaddr
push lockdown_heap
mov ecx, reloc_section
call addr_processreloc
add esp, 0x0C
}
}
int real_process_import(t_lockdown_heap *lockdown_heap, void *baseaddr, void *import_sectionoffset,void *import_sectionsize,BOOL is32Bit, void *importsection)
{
__asm
{
push is32Bit
push import_sectionsize
push import_sectionoffset
push baseaddr
push lockdown_heap
mov eax, importsection
call addr_processimport
add esp, 0x14
}
}
void real_ArrangeRecords(void *record1, void *record2)
{
__asm
{
push addr_number_compare_deprecated
push record1
mov eax, record2
call addr_arrangerecords
add esp, 8
}
}
void real_ldheap_sort(char *heapdata, int heaplength)
{
__asm
{
push addr_number_compare_deprecated
mov eax, heaplength
mov ecx, heapdata
call addr_ldheap_sort
add esp, 4
}
}
void real_AddTolockdown_heap(char *data, t_lockdown_heap *lockdown_heap)
{
__asm
{
pushad ; Because ebx is being modified, preserving registers is probably a good idea
push data
mov ebx, lockdown_heap
call addr_addtoheap
popad
}
}
void real_ld_sha1_pad(LD_SHA1_CTX *ctx, int amount)
{
int *sha1class = malloc(sizeof(int) * 2);
sha1class[0] = (int) &addr_sha1updatewrapper;
sha1class[1] = (int) ctx;
__asm
{
pushad
mov ecx, amount
mov edi, sha1class
call addr_ld_sha1_pad
popad
}
free(sha1class);
}
BOOL real_hash1(LD_SHA1_CTX *ctx, t_lockdown_heap *lockdown_heap, void *baseaddr, void *preferred_baseaddr, int reserved_for_64bit, void *section_ptr, int section_alignment)
{
BOOL retval;
int *sha1class = malloc(sizeof(int) * 2);
sha1class[0] = (int) &addr_sha1updatewrapper;
sha1class[1] = (int) ctx;
__asm
{
push reserved_for_64bit
push preferred_baseaddr
push baseaddr
push lockdown_heap
push sha1class
mov eax, section_ptr
mov ecx, section_alignment
//int 3
call addr_hash1
mov retval, eax
add esp, 0x14
}
free(sha1class);
return retval;
}
BOOL real_hash2(void *addr_baseaddr, void *preferred_baseaddr, int reserved_for_64bit, LD_SHA1_CTX *ctx, int *offset_memory, void *ptr_memory)
{
int *sha1class = malloc(sizeof(int) * 2);
BOOL retval;
sha1class[0] = (int) &addr_sha1updatewrapper;
sha1class[1] = (int) ctx;
__asm
{
pushad
push reserved_for_64bit
push preferred_baseaddr
push addr_baseaddr
mov eax, sha1class
mov ecx, offset_memory
mov esi, ptr_memory
// int 3
call addr_hash2
mov retval, eax
add esp, 0x0c
popad
}
free(sha1class);
return retval;
}
void real_hash_file(LD_SHA1_CTX *ctx, void *baseaddr)
{
int *sha1class = malloc(sizeof(int) * 2);
sha1class[0] = (int) &addr_sha1updatewrapper;
sha1class[1] = (int) ctx;
__asm
{
push baseaddr
push sha1class
mov eax, baseaddr
// int 3
call addr_hash_file
add esp, 8
}
free(sha1class);
}
|
20cf3db61f0b3583133ddb99583f86ecdec4c41f
|
a84183534fa3d20556ea416b9f8f9c16becd59ce
|
/rvv-test/intrinsic/vmflt_vv_f32.c
|
7953c2fe0139189a0cbb453e14c319c669a12343
|
[] |
no_license
|
compiler-dev/llvm-rv
|
70991e685a1998accbf2af898d97aa780f5d6863
|
a0699d80187287420429540e4223d9a436c5b352
|
refs/heads/vector
| 2023-02-02T18:52:37.371688 | 2020-12-09T07:16:34 | 2020-12-09T07:16:34 | 286,355,378 | 32 | 6 | null | 2020-12-14T03:06:48 | 2020-08-10T02:18:38 |
C++
|
UTF-8
|
C
| false | false | 447 |
c
|
vmflt_vv_f32.c
|
#include "riscv_vector.h"
vmask_t test_vmflt_vv_f32m1(vfloat32m1_t op1, vfloat32m1_t op2){
return vmflt_vv_f32m1(op1,op2);
}
vmask_t test_vmflt_vv_f32m2(vfloat32m2_t op1, vfloat32m2_t op2){
return vmflt_vv_f32m2(op1,op2);
}
vmask_t test_vmflt_vv_f32m4(vfloat32m4_t op1, vfloat32m4_t op2){
return vmflt_vv_f32m4(op1,op2);
}
vmask_t test_vmflt_vv_f32m8(vfloat32m8_t op1, vfloat32m8_t op2){
return vmflt_vv_f32m8(op1,op2);
}
|
ed1d319372ac05b19712466c551877c662473289
|
2657320c54dbf80dee2e035318079fd05f9389aa
|
/src/ctype/isblank.c
|
4be492f2ce321e890428ff6ad65fdd7f528e5eec
|
[
"Unlicense"
] |
permissive
|
Dream-Imperium/neapolitan
|
f126f811904220a3b849ea9939596662e6844306
|
13368685f0bc5b55085087dede265abd92f78d1f
|
refs/heads/master
| 2023-02-11T00:50:11.537147 | 2021-01-10T18:42:26 | 2021-01-10T18:42:26 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 114 |
c
|
isblank.c
|
#include <ctype.h>
#include "vanilla_cpu.h"
int
isblank(int c)
{
return (uchar)c == ' ' || (uchar)c == '\t';
}
|
53197f2b7eb64e9173d29b9b04dcfb5dd9f0b45d
|
1de8c773d3de8ac92472febf9cbe8f15b99fa59f
|
/prog3/smallsh.c
|
70b483b75cf69d022e8fccab08b1eb75b17f7ad1
|
[] |
no_license
|
wilsjame/CS344
|
c9063d5ada3317bf745dfcdcc16ab75aabcd5089
|
ad24ac040f661e0a0e78bdd1dd52cb78e992de1c
|
refs/heads/master
| 2021-08-22T20:51:21.208361 | 2017-12-01T08:04:57 | 2017-12-01T08:04:57 | 106,160,428 | 4 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 12,895 |
c
|
smallsh.c
|
/*********************************************************************
** Author: James G Wilson
** Date: 11/16/2017
** Description: Program 3 CS 344
** smallsh.h
*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
/* Encapsulate IO redirection. */
struct redirect
{
char stdinRedirect[250];
char stdoutRedirect[250];
};
/* Function prototypes. */
void commandPrompt(char* userInput);
bool isCommand(char* userInput);
int determineCommand(char* userInput);
void builtInExit(int size, pid_t trackingArray[]);
void builtInCd(char* userInput);
void builtInStatus(int exitMethod);
void remove_element(char* args[], int index, int size);
bool formatCommand(char* userInput, char* args[], struct redirect*);
void redirect(struct redirect*, bool isBackground);
void execute(char* args[]);
void checkTerminationStatus(int exitMethod);
void orphanCleanup(int size, pid_t trackingArray[]);
/* Signal handling trap. */
bool bgON = true; /* Global. Mr. Worldwide lool. */
void catchSIGTSTP(int signo) /* CTRL+Z toggles fg only mode. */
{
if(bgON == true)
{
char* message = "Entering foreground-only mode (& is now ignored)\n: ";
write(STDOUT_FILENO, message, 51);
fflush(NULL);
bgON = false;
}
else if(bgON == false)
{
char* message = "Exiting foreground-only mode\n: ";
write(STDOUT_FILENO, message, 31);
fflush(NULL);
bgON = true;
}
}
int main()
{
char userInput[2048];
char* args[512];
int numArguments;
int childExitMethod;
int trackerSize = 0;
bool isBuiltIn;
bool isBackground;
struct redirect inOut;
pid_t trackingArray[250]; memset(trackingArray, '\0', 250);
pid_t spawnPid;
/* Signal handling. */
struct sigaction SIGTSTP_action = {0};
struct sigaction ignore_action = {0};
struct sigaction default_action = {0};
SIGTSTP_action.sa_handler = catchSIGTSTP;
SIGTSTP_action.sa_flags = SA_RESTART;
ignore_action.sa_handler = SIG_IGN;
default_action.sa_handler = SIG_DFL;
/* Register handlers. Note: children inherit. */
sigaction(SIGTSTP, &SIGTSTP_action, NULL);
sigaction(SIGINT, &ignore_action, NULL);
/* Main loop prompts input from user among other things. */
while(1)
{
/* Reap any terminated bg processes,
* and prompt a command from the user. */
do
{
orphanCleanup(trackerSize, trackingArray);
commandPrompt(userInput);
}while(!(isCommand(userInput)));
/* Reset flag every loop iteration. */
isBuiltIn = true;
/* Switch on built in commands and default to non built in. */
switch(determineCommand(userInput))
{
case 0:
builtInExit(trackerSize, trackingArray);
break;
case 1:
builtInCd(userInput);
break;
case 2:
builtInStatus(childExitMethod);
break;
default:
isBuiltIn = false;
break;
}
if(!(isBuiltIn))
{
/* Store command and any arguments in args array.
* Store any redirection files in inOut struct.
* Determine if it's a background process. */
isBackground = formatCommand(userInput, args, &inOut);
/* Fork off child to execute the command. */
spawnPid = fork();
switch(spawnPid)
{
case -1:
perror("fork() failure!\n");
exit(1);
break;
case 0: /* In child. */
/* Ignore SIGTSTP and enable
* SIGINT if foreground. */
sigaction(SIGTSTP, &ignore_action, NULL);
if(!isBackground)
{
sigaction(SIGINT, &default_action, NULL);
}
/* Perform any necessary I/O redirection. */
redirect(&inOut, isBackground);
/* Exec hollows out rest of child program. */
execute(args);
break;
default: /* In parent. */
break;
}
if(isBackground && bgON)
{
/* Background process:
* Print and store pid,
* immediately return
* command line control. */
printf("background pid is %d\n", spawnPid);
fflush(NULL);
trackingArray[trackerSize++] = spawnPid;
}
else
{
/* Foreground process:
* Shell (parent) waits
* in a blocked state for
* child termination. */
waitpid(spawnPid, &childExitMethod, 0); // 0 -> Block
checkTerminationStatus(childExitMethod);
}
} // End of non built in command block.
} // End of while(1).
return 0;
}
/* Displays command line prompt and gets user input. No error checking. */
void commandPrompt(char* userInput)
{
/* First things first, clear user input string. */
memset(userInput, '\0', sizeof(userInput));
/* Magic settings. */
size_t bufferSize = 0;
char* lineEntered = NULL;
/* Display prompt and then flush all open output steams. */
printf(": ");
fflush(NULL);
/* By magic settings, getline() buffers automatically use malloc. */
getline(&lineEntered, &bufferSize, stdin);
/* Remove trailing '\n' from pressing enter. */
lineEntered[strcspn(lineEntered, "\n")] = 0;
/* Store user input for use in main(). */
strcpy(userInput, lineEntered);
/* Free memory allocated by getline() aka free Lil B. */
free(lineEntered);
return;
};
/* Returns false if userInput is blank or a comment, true otherwise. */
bool isCommand(char* userInput)
{
bool isCommand;
if(strlen(userInput) == 0 || strncmp(userInput, "#", 1) == 0)
{
isCommand = false;
}
else
{
isCommand = true;
}
return isCommand;
}
/* Built-in commands return 0, 1, or 2 otherwise return 3. */
int determineCommand(char* userInput)
{
/* Temporary variable to hold first
* word in user input's command. */
char command[250]; memset(command, '\0', sizeof(command));
/* Store the first word as command. */
sscanf(userInput, "%s", command);
if(strcmp(command, "exit") == 0)
{
return 0;
}
else if(strcmp(command, "cd") == 0)
{
return 1;
}
else if(strcmp(command, "status") == 0)
{
return 2;
}
else
{
return 3;
}
}
/* Kill other processes or jobs started by the shell then terminate itself. */
void builtInExit(int size, pid_t trackingArray[])
{
int i;
/* Parse bg process tracking array and kill. */
for(i = 0; i < size; i++)
{
kill(trackingArray[i], SIGKILL);
}
exit(EXIT_SUCCESS);
}
/* Changes directories. By itself, change to the directory specified in
* the HOME enviornment variable. Can also take one argument, either the
* absolute or relative path of the directory to change to. */
void builtInCd(char* userInput)
{
if(strcmp(userInput, "cd") == 0)
{
if(chdir(getenv("HOME")) != 0)
{
printf("chdir(HOME) failure!\n");
}
}
else
{
/* Temporary variable to hold directory path. */
char path[250]; memset(path, '\0', sizeof(path));
/* Store the specified path. */
sscanf(userInput, "%*s %s", path);
if(chdir(path) != 0)
{
printf("chdir(path) failure!\n");
}
}
return;
}
/* Print exit status or terminating signal of the last foreground
* process (not both, ps killed by signals don't have exit statuses!). */
void builtInStatus(int exitMethod)
{
if(WIFEXITED(exitMethod))
{
/* Child terminated normally. */
printf("Foreground exit value %d\n", WEXITSTATUS(exitMethod));
fflush(NULL);
}
else
{
/* By deduction, child must've terminated by signal. */
printf("Terminated by signal %d\n", WTERMSIG(exitMethod));
fflush(NULL);
}
return;
}
/* Removes an element from string array. */
void remove_element(char* array[], int index, int size)
{
int i;
size++;
for(i = index; i < size - 1; i++)
{
array[i] = array[i + 1];
}
}
/* Formats command name and arguments in an array,
* extracts any stdin or stdout redirection, and returns
* true if the command is to be run in the background. */
bool formatCommand(char* userInput, char* args[], struct redirect* inOut)
{
int index, argItr, argSize = 0;
pid_t PID = getpid();
bool isBackground = false;
char PIDString[250]; memset(PIDString, '\0', 250);
char tempArgument[250]; memset(tempArgument, '\0', 250);
char expandTemp[250]; memset(expandTemp, '\0', 250);
memset(args, '\0', sizeof(args));
memset(inOut->stdinRedirect, '\0', 250);
memset(inOut->stdoutRedirect, '\0', 250);
/* First token is the command name. */
args[argSize] = strtok(userInput, " ");
/* Remaining tokens (if any) are additional arguments. */
while(args[argSize] != NULL)
{
argSize++;
args[argSize] = strtok(NULL, " ");
/* Cool trick to expand $$ from Piazza. */
memset(tempArgument, '\0', 250);
memset(expandTemp, '\0', 250);
strcpy(tempArgument, args[argSize - 1]);
if(strstr(tempArgument, "$$") != NULL)
{
index = strstr(tempArgument, "$$") - tempArgument;
tempArgument[index] = '%';
index = strstr(tempArgument, "$") - tempArgument;
tempArgument[index] = 'd';
sprintf(expandTemp, tempArgument, getpid());
strcpy(args[argSize - 1], expandTemp);
}
}
/* Check if it's a background process. */
if(strcmp(args[argSize - 1], "&") == 0)
{
/* Remove '&' and set last
* argument NULL for exec(). */
args[--argSize] = NULL;
isBackground = true;
}
/* Parse arguments for I/O redirection. */
for(argItr = 0; argItr < argSize; argItr++)
{
if(strcmp(args[argItr], "<") == 0 || strcmp(args[argItr], ">") == 0)
{
/* The next argument is the redirection file. */
if(strcmp(args[argItr], "<" ) == 0)
{
strcpy(inOut->stdinRedirect, args[argItr + 1]);
}
else if(strcmp(args[argItr], ">" ) == 0)
{
strcpy(inOut->stdoutRedirect, args[argItr + 1]);
}
/* Remove '<' or '>' and 'input_file' from arguments. */
remove_element(args, argItr, argSize--);
remove_element(args, argItr, argSize--);
argItr--;
}
}
return isBackground;
}
//TODO condense logic
/* Perform I/O redirection. */
void redirect(struct redirect* inOut, bool isBackground)
{
int sourceFD;
int targetFD;
if(!strcmp(inOut->stdinRedirect, "\0") == 0)
{
/* Input file open read only. */
sourceFD = open(inOut->stdinRedirect, O_RDONLY);
/* Cannot open, print error and set exit status to 1 (but don't exit shell). */
if(sourceFD == -1)
{
printf("IO redirection failure!\n");
exit(1); // Child exits but not parent!
}
/* Perform redirection. */
dup2(sourceFD, 0);
}
if(!strcmp(inOut->stdoutRedirect, "\0") == 0)
{
/* Output file open write only, truncate if it exists, create otherwise. */
targetFD = open(inOut->stdoutRedirect, O_WRONLY | O_CREAT | O_TRUNC, 0644);
/* Cannot open, print error and set exit status to 1 (but don't exit shell). */
if(targetFD == -1)
{
printf("IO redirection failure!\n");
exit(1); // Child exits but not parent!
}
/* Perform redirection. */
dup2(targetFD, 1);
}
/* Background processes with no redirection redirect to /dev/null. */
if(strcmp(inOut->stdinRedirect, "\0") == 0 && isBackground)
{
/* Input file open read only. */
sourceFD = open("/dev/null", O_RDONLY);
/* Cannot open, print error and set exit status to 1 (but don't exit shell). */
if(sourceFD == -1)
{
printf("IO redirection failure!\n");
exit(1); // Child exits but not parent!
}
/* Perform redirection. */
dup2(sourceFD, 0);
}
if(strcmp(inOut->stdoutRedirect, "\0") == 0 && isBackground)
{
/* Output file open write only, truncate if it exists, create otherwise. */
targetFD = open("/dev/null", O_WRONLY | O_CREAT | O_TRUNC, 0644);
/* Cannot open, print error and set exit status to 1 (but don't exit shell). */
if(targetFD == -1)
{
printf("IO redirection failure!\n");
exit(1); // Child exits but not parent!
}
/* Perform redirection. */
dup2(targetFD, 1);
}
return;
}
/* Lil' function to encapsulate execvp(). */
void execute(char* args[])
{
/* *args == args[0]. */
if(execvp(*args, args) < 0)
{
printf("exec() failure!\n");
fflush(NULL);
exit(1);
}
}
/* Prints termination signal, if any. */
void checkTerminationStatus(int exitMethod)
{
if(WIFSIGNALED(exitMethod))
{
/* Child terminated by a signal. */
printf("Terminated by signal %d\n", WTERMSIG(exitMethod));
fflush(NULL);
}
return;
}
/* Checks for completed bg processes, determined exit status,
* reaps, and prints completed bg pid and exit status. */
void orphanCleanup(int size, pid_t trackingArray[])
{
int i, childExitMethod;
/* Parse bg process tracking array. */
for(i = 0; i < size; i++)
{
/* WNOHANG return immediately if no child has exited. */
pid_t waitpidReturn = waitpid(trackingArray[i], &childExitMethod, WNOHANG);
if(waitpidReturn == trackingArray[i])
{
if(WIFEXITED(childExitMethod))
{
/* Child terminated normally. */
printf("background pid %d is done: exit value %d\n", trackingArray[i], WEXITSTATUS(childExitMethod));
fflush(NULL);
}
else
{
/* Terminated by signal. */
printf("Background pid %d terminated by signal %d\n", trackingArray[i], WTERMSIG(childExitMethod));
fflush(NULL);
}
}
}
return;
}
|
47e21818d9c825f49fa11b94cee7107524bc2775
|
a9007f33b8f2304dd5f25493c8fcafefade58711
|
/Vision/Vision/Resource.h
|
ae41a4b2953fa995e69ae0342cbbb0326e04b309
|
[] |
no_license
|
Danny19920203/MachineVision
|
4e2ee0d75c152d9b0879b0526c5a90b2af456c95
|
29bdb068290ea8ad34aa5e36354fdd1562622aba
|
refs/heads/master
| 2020-04-04T16:07:34.118299 | 2013-09-12T11:31:47 | 2013-09-12T11:31:47 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,241 |
h
|
Resource.h
|
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Vision.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_VISION_DIALOG 102
#define IDR_MAINFRAME 128
#define IDD_TASKNAME 130
#define IDC_LIST_IN 1000
#define IDC_BT_ADD 1001
#define IDC_BT_SAVE 1002
#define IDC_BT_DELETE 1003
#define IDC_BT_OPEN 1004
#define IDC_BT_RUN 1005
#define IDC_LIST_OUT 1006
#define IDC_COMBO 1007
#define IDC_EDIT_TASK_NAME 1009
#define IDC_BT_DONE 1010
#define IDC_EDIT_ID 1011
#define IDC_COMBO1 1012
#define IDC_COMBO_TASK_NAME 1012
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 131
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1013
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
|
45d34e423fe8d2b348eabb391b9af65ebc72723e
|
9056dcc0298c2c9142ceb070bafaec52a75e13a9
|
/C-version/libs/defs.h
|
af1482394f7123bc1bafdfad5088136dbb10947c
|
[] |
no_license
|
vwdorsey/dungeon
|
641597439d2da7adc16cf42230d72fc717cd05bd
|
ad5c315ea3a95a66f52aef530c5795123acc6705
|
refs/heads/master
| 2020-05-29T14:16:34.788538 | 2015-04-26T02:56:50 | 2015-04-26T02:56:50 | 82,594,383 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 2,420 |
h
|
defs.h
|
#ifndef DEFS_H
#define DEFS_H
#include <stdint.h>
// Attributes Block
#define IS_SMART 1
#define TELEPATHIC 2
#define BIT2 4
#define BIT3 8
#define BIT4 16
#define BIT5 32
#define BIT6 64
#define BIT7 128
#define BIT8 256
#define BIT9 512
#define BIT10 1024
#define BIT11 2048
#define BIT12 4096
#define BIT13 8192
#define BIT14 16386
#define BIT15 32768
// Tilings
#define tile_type_wall '+'
#define tile_type_empty ' '
#define tile_type_immutable '#'
#define tile_type_floor '.'
#define tile_type_upstair '<'
#define tile_type_downstair '>'
// Map Settings
#define rows 160
#define columns 96
#define min_rooms 12
#define max_rooms 20
#define min_room_x 10
#define min_room_y 7
#define max_room_x 20
#define max_room_y 15
#define default_num_mon 10
typedef struct point{
unsigned int n_x;
unsigned int n_y;
unsigned int path_size;
} point;
typedef struct Monster{
unsigned char Sprite;
int pos[2];
uint8_t speed;
uint16_t attribs;
point* path_to_player;
unsigned char alive;
} Monster;
typedef struct Player{
unsigned char Sprite;
int pos[2];
uint8_t speed;
unsigned char alive;
unsigned int priority;
} Player;
/*
This struct is used as a tile information holder for any information about the tile.
I expect this struct to expand in terms of variables stored inside.
*/
typedef struct tile{
char type; // All valid tile types have been moved to defs.h
int hardness; // Hardness values are 0-9. 0 represents a floor already made and 9 is immutable.
int is_room; // Used to determine is the tile is part of a room.
Player* pc; // Used if a player is on the current tile
Monster* mon; // Used if a monster is on the current tile
} t_tile;
typedef struct dij_node{
unsigned int x;
unsigned int y;
unsigned int cost;
struct dij_node* previous;
} dij_node;
/*
Struct to hold all of the necessary information about each room, including the dimensions and where the room starts.
I expect this to expand later as more functionality is added to the code.
*/
typedef struct roominfo {
unsigned char x_dim; //X dimension
unsigned char y_dim; //Y dimension
unsigned char x_start; //X start
unsigned char y_start; //Y start
} roominfo;
#endif
|
4dc1684aeafe06833466491167969dc206446723
|
f253cc3c6a19b43aa1ea4e9141365cd0a19faf99
|
/src/include/surface.h
|
1482a042fad16901a534e8707b520b1a30eb1f27
|
[] |
no_license
|
maliku/gitsvn-test
|
fbb521447f83fbb2b4596303fd29ea451c2e680b
|
1327854f1e39acf41564f186752be7515905c1c2
|
refs/heads/master
| 2018-12-29T04:44:43.322355 | 2013-06-26T04:01:21 | 2013-06-26T04:01:21 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 2,981 |
h
|
surface.h
|
/*!============================================================================
* @file surface.h
* @Synopsis
* @author DongKai
* @version 1.0
* @date 2010-04-11 17:01:39
* Organization: http://www.ds0101.net
*/
#ifndef SURFACE_INC
#define SURFACE_INC
#include "MIL_video.h"
#include "MIL_mutex.h"
#include "pixel_format.h"
struct _MIL_BlitMap;
typedef struct _MIL_BlitMap MIL_BlitMap;
CLASS(Surface)
{
BEGIN_METHOD_DECLARE(Surface)
int (*lock)(_SELF);
void (*unlock)(_SELF);
int (*setColorKey)(_SELF, Uint32 flag, Uint32 key);
int (*setAlpha)(_SELF, Uint32 flag, Uint8 alpha);
MIL_Bool (*setClipRect)(_SELF, const MIL_Rect *rect);
void (*getClipRect)(_SELF, MIL_Rect *rect);
int (*blit)(_SELF, const MIL_Rect *srcrect, Surface *dst, const MIL_Point* dstpoint);
int (*fillRect)(_SELF, MIL_Rect *dstrect, Uint32 color);
int (*saveBMP)(_SELF, const char *file);
int (*stretchBlit)(_SELF, const MIL_Rect *srcrect, Surface *dst, const MIL_Rect* dstrect);
Surface* (*displayFormat)(_SELF);
Surface* (*displayFormatAlpha)(_SELF);
Surface* (*convert)(_SELF, PixelFormat *fmt, Uint32 flags);
PixelFormat* (*reallocFormat)(_SELF, int bpp,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
void (*formatChanged)(_SELF);
Uint32 (*getWidth)(_CSELF);
Uint32 (*getHeight)(_CSELF);
Uint32 (*getPitch)(_CSELF);
Uint32 (*getFlags)(_CSELF);
Uint8 (*getBitsPerPixel)(_CSELF);
Uint8 (*getBytesPerPixel)(_CSELF);
const PixelFormat* (*getPixelFormat)(_SELF);
Uint32 (*calculatePitch)(_SELF);
int (*mapSurface)(_SELF, Surface *dst);
int (*RLE)(_SELF);
void (*UnRLE)(_SELF, int recode);
END_METHOD_DECLARE
Uint32 flags; /* Read-only */
PixelFormat* format; /* Read-only */
Uint32 w, h; /* Read-only */
Uint32 pitch; /* Read-only */
void* pixels; /* Read-write */
int offset; /* Private */
/* Hardware-specific surface info */
struct private_hwdata *hwdata;
/* clipping information */
MIL_Rect clip_rect; /* Read-only */
/* Allow recursive locks */
Uint32 locked; /* Private */
/* info for fast blit mapping to other surfaces */
MIL_BlitMap *map; /* Private */
/* format version, bumped at every change to invalidate blit maps */
unsigned int format_version; /* Private */
/* Reference count -- used when freeing surface */
int refcount; /* Read-mostly */
};
//BEGIN_CLASS_INHERIT(MSurface, MRasterSurface)
//END_CLASS_INHERIT
Surface * CreateRGBSurface (Uint32 flags,
int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
int MIL_SoftStretch(Surface *src, const MIL_Rect *srcrect,
Surface *dst, const MIL_Rect *dstrect);
#define MIL_AUTO_FREE 1
Surface * MIL_LoadBMP_RW(MIL_RWops* src, int freesrc);
MIL_Status MIL_SaveBMP_RW (Surface *saveme, MIL_RWops *dst, int freedst);
#endif /* ----- #ifndef SURFACE_INC ----- */
|
8abe0ffbfed136c6c8507a8b7cc20fcdcefb72ec
|
b0afbe1108e5f938244fcf702a9b51937f326719
|
/source/Gen6FoundationApp/FoundationApp/Foundation_Temp/PowerManagement.h
|
3e0a9da399176011da162d84a0a39c4565f39759
|
[] |
no_license
|
huxb23/Test2016
|
fb992a4a1a65cba9ea72e7b89de636244a0e1e7a
|
d63db15ef7216f86f0c1f552fea7e47077c5b6af
|
refs/heads/master
| 2020-05-31T23:32:22.487628 | 2015-12-24T05:09:57 | 2015-12-24T05:09:57 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,811 |
h
|
PowerManagement.h
|
/**************************************************************************************/
//
// HSM 48X0G GENERATION 6 SOFTWARE
//
// Date: 10/31/2008
// Tools: RVCT Build 674
// Target: Freescale iMX25
//
//======================================================================================
// Revision information
//======================================================================================
// $RCSfile: Gen6FoundationApp/FoundationApp/Foundation_Temp/PowerManagement.h $
// $Revision: 1.21 $
// $Date: 2011/11/10 03:22:25EST $
//======================================================================================
//======================================================================================
//------------------------------------------------------------------------------
// HEADER: PowerManagement.h
//
// This module contains a collection of low level functions that control the
// power management for the processor and scanner.
//
//------------------------------------------------------------------------------
#ifndef POWERMANAGEMENT_H_
#define POWERMANAGEMENT_H_
extern volatile bool ProcessingAppCode;
extern volatile bool gOkToPowerDown;
extern "C" void WaitForIRQ(void);
typedef enum {FULL,DOZE,DOZE_LOW,STOP,POWERDOWN,STOPTHENPOWERDOWN}power_t;
void ResetMinimumPowerUp(void);
void ResetPowerTimeOuts(void);
void EnterPowerState(power_t);
void ManageSystemPower(void);
void EnterStopMode(void);
void Prepare_System_for_Suspend(void);
void Restore_System_from_Suspend(void);
void PSMODE_Control(bool);
void Init_PowerPins(void);
void SystemSuspendState(bool);
#if defined(VUQUEST3310) || defined (HI2D_T)
//add by kehe@2011.08.29 for ESD issue
void reset_res_count_and_timout();
bool is_ignore_suspend();
#endif
#endif /*POWERMANAGEMENT_H_*/
|
7c09cb99ddd367dc51397cbec3134d495acda737
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/area_kkj/kkj_01/kkj_01_3_npc.c
|
7e7cdd3fb08c37291ef4e5d60081f6a887a28f68
|
[] |
no_license
|
pmret/papermario
|
8b514b19653cef8d6145e47499b3636b8c474a37
|
9774b26d93f1045dd2a67e502b6efc9599fb6c31
|
refs/heads/main
| 2023-08-31T07:09:48.951514 | 2023-08-21T18:07:08 | 2023-08-21T18:07:08 | 287,151,133 | 904 | 139 | null | 2023-09-14T02:44:23 | 2020-08-13T01:22:57 |
C
|
UTF-8
|
C
| false | false | 15,512 |
c
|
kkj_01_3_npc.c
|
#include "kkj_01.h"
#include "world/common/npc/Toad_Wander.inc.c"
#include "world/common/npc/Toad_Patrol.inc.c"
#include "world/common/npc/Toad_Stationary.inc.c"
#include "world/common/npc/Dryite_Stationary.inc.c"
#include "world/common/npc/Mouser.inc.c"
#include "world/common/npc/Penguin.inc.c"
#include "world/common/npc/Koopa.inc.c"
EvtScript N(EVS_NpcIdle_Dryite) = {
EVT_LOOP(0)
EVT_CALL(GetSelfVar, 1, LVar0)
EVT_IF_EQ(LVar0, 0)
EVT_CALL(SetNpcAnimation, NPC_Dryite, ANIM_Dryite_Yellow_Talk)
EVT_CALL(SetSelfVar, 1, 1)
EVT_ELSE
EVT_CALL(SetNpcAnimation, NPC_Mouser, ANIM_Mouser_Blue_Talk)
EVT_CALL(SetSelfVar, 1, 0)
EVT_END_IF
EVT_CALL(RandInt, 60, LVar0)
EVT_ADD(LVar0, 30)
EVT_WAIT(LVar0)
EVT_CALL(SetNpcAnimation, NPC_Dryite, ANIM_Dryite_Yellow_Idle)
EVT_CALL(SetNpcAnimation, NPC_Mouser, ANIM_Mouser_Blue_Idle)
EVT_WAIT(10)
EVT_END_LOOP
EVT_END
};
EvtScript N(EVS_NpcIdle_MayorPenguin) = {
EVT_LOOP(0)
EVT_CALL(GetSelfVar, 1, LVar0)
EVT_IF_EQ(LVar0, 0)
EVT_CALL(SetNpcAnimation, NPC_MayorPenguin, ANIM_MayorPenguin_Talk)
EVT_CALL(SetSelfVar, 1, 1)
EVT_ELSE
EVT_CALL(SetNpcAnimation, NPC_Koopa, ANIM_Koopa_Talk)
EVT_CALL(SetSelfVar, 1, 0)
EVT_END_IF
EVT_CALL(RandInt, 60, LVar0)
EVT_ADD(LVar0, 30)
EVT_WAIT(LVar0)
EVT_CALL(SetNpcAnimation, NPC_MayorPenguin, ANIM_MayorPenguin_Idle)
EVT_CALL(SetNpcAnimation, NPC_Koopa, ANIM_Koopa_Idle)
EVT_WAIT(10)
EVT_END_LOOP
EVT_END
};
EvtScript N(EVS_NpcIdle_ToadMinister) = {
EVT_WAIT(30)
EVT_LOOP(0)
EVT_WAIT(150)
EVT_LOOP(2)
EVT_CALL(InterpNpcYaw, NPC_SELF, 90, 7)
EVT_WAIT(20)
EVT_CALL(InterpNpcYaw, NPC_SELF, 270, 7)
EVT_WAIT(20)
EVT_END_LOOP
EVT_END_LOOP
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcIdle_Toad_01) = {
EVT_LOOP(0)
EVT_WAIT(150)
EVT_LOOP(2)
EVT_CALL(InterpNpcYaw, NPC_SELF, 90, 7)
EVT_WAIT(15)
EVT_CALL(InterpNpcYaw, NPC_SELF, 270, 7)
EVT_WAIT(15)
EVT_END_LOOP
EVT_END_LOOP
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcIdle_ToadGuard_02) = {
EVT_IF_EQ(AF_KKJ_02, TRUE)
EVT_RETURN
EVT_END_IF
EVT_CALL(GetEntryID, LVar0)
EVT_IF_NE(LVar0, kkj_01_ENTRY_4)
EVT_RETURN
EVT_END_IF
EVT_CALL(WaitForPlayerInputEnabled)
EVT_CALL(DisablePlayerInput, TRUE)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadGuard_Yellow_Talk, ANIM_ToadGuard_Yellow_Idle, 16, MSG_Intro_0042)
EVT_SET(AF_KKJ_02, TRUE)
EVT_CALL(DisablePlayerInput, FALSE)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_ToadMinister) = {
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadMinister_Talk, ANIM_ToadMinister_Idle, 0, MSG_Intro_0033)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_Toad_01) = {
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_Toad_Blue_Talk, ANIM_Toad_Blue_Idle, 16, MSG_Intro_0038)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_Toad_02) = {
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_Toad_Green_Talk, ANIM_Toad_Green_Idle, 16, MSG_Intro_0039)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_Toad_03) = {
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_Toad_Red_Talk, ANIM_Toad_Red_Idle, 16, MSG_Intro_003A)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_Toadette) = {
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_Toadette_Orange_Talk, ANIM_Toadette_Orange_Idle, 16, MSG_Intro_003B)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_ToadGuard_01) = {
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadGuard_Red_Talk, ANIM_ToadGuard_Red_Idle, 16, MSG_Intro_003C)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_ToadGuard_02) = {
EVT_CALL(GetSelfVar, 0, LVar0)
EVT_SWITCH(LVar0)
EVT_CASE_EQ(0)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadGuard_Yellow_Talk, ANIM_ToadGuard_Yellow_Idle, 16, MSG_Intro_003D)
EVT_CASE_EQ(1)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadGuard_Yellow_Talk, ANIM_ToadGuard_Yellow_Idle, 16, MSG_Intro_003E)
EVT_CASE_OR_EQ(2)
EVT_CASE_OR_EQ(3)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadGuard_Yellow_Talk, ANIM_ToadGuard_Yellow_Idle, 16, MSG_Intro_003F)
EVT_END_CASE_GROUP
EVT_CASE_EQ(4)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadGuard_Yellow_Talk, ANIM_ToadGuard_Yellow_Idle, 16, MSG_Intro_0040)
EVT_WAIT(10)
EVT_CALL(GetPlayerPos, LVar0, LVar1, LVar2)
EVT_CALL(SetNpcAnimation, NPC_ToadGuard_02, ANIM_ToadGuard_Yellow_Walk)
EVT_IF_GT(LVar0, 0)
EVT_SET(LVar3, -50)
EVT_ELSE
EVT_SET(LVar3, 50)
EVT_END_IF
EVT_CALL(SetNpcFlagBits, NPC_SELF, NPC_FLAG_IGNORE_PLAYER_COLLISION, TRUE)
EVT_CALL(SetNpcSpeed, NPC_SELF, EVT_FLOAT(2.0))
EVT_CALL(NpcMoveTo, NPC_SELF, LVar3, -245, 0)
EVT_CALL(SetNpcFlagBits, NPC_SELF, NPC_FLAG_IGNORE_PLAYER_COLLISION, FALSE)
EVT_CALL(SetNpcAnimation, NPC_ToadGuard_02, ANIM_ToadGuard_Yellow_Idle)
EVT_CALL(InterpNpcYaw, NPC_SELF, 180, 5)
EVT_SET(AF_KKJ_01, TRUE)
EVT_BIND_TRIGGER(EVT_PTR(N(EVS_ExitDoors_kkj_14_0)), TRIGGER_WALL_PRESS_A, COLLIDER_ttn2, 1, 0)
EVT_CASE_DEFAULT
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_ToadGuard_Yellow_Talk, ANIM_ToadGuard_Yellow_Idle, 16, MSG_Intro_0041)
EVT_END_SWITCH
EVT_ADD(LVar0, 1)
EVT_CALL(SetSelfVar, 0, LVar0)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_Dryite) = {
EVT_CALL(SetNpcAnimation, NPC_Mouser, ANIM_Mouser_Blue_Idle)
EVT_CALL(SetNpcAnimation, NPC_Dryite, ANIM_Dryite_Yellow_Idle)
EVT_WAIT(10)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_Dryite_Yellow_Talk, ANIM_Dryite_Yellow_Idle, 16, MSG_Intro_0034)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_Mouser) = {
EVT_CALL(EnableNpcAI, NPC_Dryite, FALSE)
EVT_CALL(SetNpcAnimation, NPC_Mouser, ANIM_Mouser_Blue_Idle)
EVT_CALL(SetNpcAnimation, NPC_Dryite, ANIM_Dryite_Yellow_Idle)
EVT_WAIT(10)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_Mouser_Blue_Talk, ANIM_Mouser_Blue_Idle, 16, MSG_Intro_0035)
EVT_CALL(EnableNpcAI, NPC_Dryite, TRUE)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_MayorPenguin) = {
EVT_CALL(SetNpcAnimation, NPC_MayorPenguin, ANIM_MayorPenguin_Idle)
EVT_CALL(SetNpcAnimation, NPC_Koopa, ANIM_Koopa_Idle)
EVT_WAIT(10)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_MayorPenguin_Talk, ANIM_MayorPenguin_Idle, 16, MSG_Intro_0036)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInteract_Koopa) = {
EVT_CALL(EnableNpcAI, NPC_MayorPenguin, FALSE)
EVT_CALL(SetNpcAnimation, NPC_MayorPenguin, ANIM_MayorPenguin_Idle)
EVT_CALL(SetNpcAnimation, NPC_Koopa, ANIM_Koopa_Idle)
EVT_WAIT(10)
EVT_CALL(SpeakToPlayer, NPC_SELF, ANIM_Koopa_Talk, ANIM_Koopa_Idle, 16, MSG_Intro_0037)
EVT_CALL(EnableNpcAI, NPC_MayorPenguin, TRUE)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_ToadMinister) = {
EVT_CALL(BindNpcIdle, NPC_SELF, EVT_PTR(N(EVS_NpcIdle_ToadMinister)))
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_ToadMinister)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Toad_01) = {
EVT_CALL(BindNpcIdle, NPC_SELF, EVT_PTR(N(EVS_NpcIdle_Toad_01)))
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_Toad_01)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Toad_02) = {
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_Toad_02)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Toad_03) = {
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_Toad_03)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Toadette) = {
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_Toadette)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_ToadGuard_01) = {
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_ToadGuard_01)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_ToadGuard_02) = {
EVT_IF_EQ(AF_KKJ_01, TRUE)
EVT_CALL(SetNpcPos, NPC_SELF, -50, 0, -245)
EVT_CALL(SetSelfVar, 0, 5)
EVT_ELSE
EVT_CALL(SetNpcPos, NPC_SELF, 0, 0, -260)
EVT_END_IF
EVT_CALL(BindNpcIdle, NPC_SELF, EVT_PTR(N(EVS_NpcIdle_ToadGuard_02)))
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_ToadGuard_02)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Dryite) = {
EVT_CALL(BindNpcIdle, NPC_SELF, EVT_PTR(N(EVS_NpcIdle_Dryite)))
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_Dryite)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Mouser) = {
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_Mouser)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_MayorPenguin) = {
EVT_CALL(BindNpcIdle, NPC_SELF, EVT_PTR(N(EVS_NpcIdle_MayorPenguin)))
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_MayorPenguin)))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_NpcInit_Koopa) = {
EVT_CALL(BindNpcInteract, NPC_SELF, EVT_PTR(N(EVS_NpcInteract_Koopa)))
EVT_RETURN
EVT_END
};
NpcData N(NpcData_ToadMinister)[] = {
{
.id = NPC_ToadMinister,
.pos = { 0.0f, 0.0f, 350.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_ToadMinister),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING,
.animations = TOAD_MINISTER_ANIMS,
},
{
.id = NPC_Toad_01,
.pos = { 100.0f, 0.0f, 175.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_Toad_01),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING,
.animations = TOAD_BLUE_ANIMS,
},
{
.id = NPC_Toad_02,
.pos = { 200.0f, 0.0f, 110.0f },
.yaw = 270,
.territory = {
.wander = {
.isFlying = TRUE,
.moveSpeedOverride = NO_OVERRIDE_MOVEMENT_SPEED,
.wanderShape = SHAPE_CYLINDER,
.centerPos = { 200, 0, 110 },
.wanderSize = { 70 },
.detectShape = SHAPE_CYLINDER,
.detectPos = { 200, 0, 110 },
.detectSize = { 70 },
}
},
.init = &N(EVS_NpcInit_Toad_02),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Toad_Wander),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING,
.animations = TOAD_GREEN_ANIMS,
},
{
.id = NPC_Toad_03,
.pos = { -250.0f, 0.0f, 225.0f },
.yaw = 90,
.territory = {
.patrol = {
.isFlying = TRUE,
.moveSpeedOverride = NO_OVERRIDE_MOVEMENT_SPEED,
.numPoints = 2,
.points = {
{ -250, 0, 225 },
{ 300, 0, -50 },
},
.detectShape = SHAPE_CYLINDER,
.detectPos = { -250, 0, 225 },
.detectSize = { 200 },
}
},
.init = &N(EVS_NpcInit_Toad_03),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Toad_Patrol),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING,
.animations = TOAD_RED_ANIMS,
},
{
.id = NPC_Toadette,
.pos = { -170.0f, 0.0f, 100.0f },
.yaw = 90,
.territory = {
.wander = {
.isFlying = TRUE,
.moveSpeedOverride = NO_OVERRIDE_MOVEMENT_SPEED,
.wanderShape = SHAPE_CYLINDER,
.centerPos = { -170, 0, 100 },
.wanderSize = { 70 },
.detectShape = SHAPE_CYLINDER,
.detectPos = { -170, 0, 100 },
.detectSize = { 70 },
}
},
.init = &N(EVS_NpcInit_Toadette),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Toad_Wander),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING,
.animations = TOADETTE_ORANGE_ANIMS,
},
{
.id = NPC_ToadGuard_01,
.pos = { -55.0f, 100.0f, -360.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_ToadGuard_01),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING,
.animations = TOAD_GUARD_RED_ANIMS,
},
{
.id = NPC_ToadGuard_02,
.pos = { NPC_DISPOSE_LOCATION },
.yaw = 270,
.init = &N(EVS_NpcInit_ToadGuard_02),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Toad_Stationary),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING,
.animations = TOAD_GUARD_YELLOW_ANIMS,
},
{
.id = NPC_Dryite,
.pos = { 170.0f, 0.0f, 345.0f },
.yaw = 90,
.init = &N(EVS_NpcInit_Dryite),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Dryite),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_400000,
.animations = DRYITE_YELLOW_ANIMS,
},
{
.id = NPC_Mouser,
.pos = { 200.0f, 0.0f, 325.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_Mouser),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Mouser),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_400000,
.animations = MOUSER_BLUE_ANIMS,
},
{
.id = NPC_MayorPenguin,
.pos = { -150.0f, 0.0f, 0.0f },
.yaw = 90,
.init = &N(EVS_NpcInit_MayorPenguin),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Penguin),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_400000,
.animations = MAYOR_PENGUIN_ANIMS,
},
{
.id = NPC_Koopa,
.pos = { -120.0f, 0.0f, -15.0f },
.yaw = 270,
.init = &N(EVS_NpcInit_Koopa),
.drops = NO_DROPS,
.settings = &N(NpcSettings_Koopa),
.flags = ENEMY_FLAG_PASSIVE | ENEMY_FLAG_ENABLE_HIT_SCRIPT | ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_400000,
.animations = KOOPA_ANIMS,
},
};
NpcGroupList N(DefaultNPCs) = {
NPC_GROUP(N(NpcData_ToadMinister)),
{}
};
|
7b4e0255f526bb72bcec8b51df02b26794db12a7
|
a2c680b512d1c3bca72031f7f3189e9c54047b40
|
/client.c
|
1208fd1d0e061797c1c222f5471d18b4aa080472
|
[
"Unlicense"
] |
permissive
|
elwinar/simon
|
5dca7bd7408a0ada3fd2473dd08e49768174a18d
|
8e75a1bddf6faa6d786d397fe022f972596b9d8e
|
refs/heads/master
| 2016-09-06T11:09:20.509760 | 2015-05-11T13:05:58 | 2015-05-11T13:05:58 | 35,086,507 | 3 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,479 |
c
|
client.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#define PORT "42000"
#define BUFFER_SIZE 1024
#define STDIN 0
int main(void)
{
// STEP 1: Initialize the server socket
// The server socket will be used to communicate with the server (both
// for sending and receiving).
int server;
struct addrinfo hints; // Hints for getaddrinfo to fill the results
memset(&hints, 0, sizeof hints); // Ensure the struct is empty
hints.ai_family = AF_UNSPEC; // Don't care about IPv4 or IPv6
hints.ai_socktype = SOCK_STREAM; // TCP stream socket
hints.ai_flags = AI_PASSIVE; // Please fill the IP for me, I'm lazy
struct addrinfo* servinfo; // Will point to the results (linked list)
if(getaddrinfo(NULL, PORT, &hints, &servinfo) != 0) // Fill the addrinfo struct automagically
{
perror("getaddrinfo");
exit(EXIT_FAILURE);
}
struct addrinfo* p;
for(p = servinfo; p != NULL; p = p->ai_next) // Iterate over the list
{
server = socket(p->ai_family, p->ai_socktype, p->ai_protocol); // Try initializing the socket
if(server == -1)
{
perror("socket");
continue;
}
if(connect(server, p->ai_addr, p->ai_addrlen) == -1) // Connect to the remote socket
{
close(server);
perror("connect");
continue;
}
break;
}
if (p == NULL) { // If the pointer is NULL, we iterated over all the results without succeeding to connect
fprintf(stderr, "failed to bind\n");
exit(EXIT_FAILURE);
}
freeaddrinfo(servinfo); // Clear the results of the getaddrinfo
// STEP 2: Communicate with the server
// Practically, we treat stdin as if it was a socket and read from
// all available sources, maintaining a write buffer for the user inputs,
// so we can display messages as they arrive while not messing the input.
fd_set pool_fds; // Will contain all sockets handled by the server. It's actually a bit array… don't try to look at it with the naked eye
fd_set read_fds; // Will contain the temporary list of sockets.
FD_ZERO(&pool_fds); // Ensure the socket pool is empty
FD_ZERO(&read_fds); // Ensure the socket pool is empty
FD_SET(server, &pool_fds); // Add the server socket to the pool
FD_SET(STDIN, &pool_fds); // Add stdin to the pool
int max_descriptor = server; // Keep track of the bigest descriptor
while(1) // Loop until the end of times
{
read_fds = pool_fds; // Copy the pool to prevent dumb errors
if(select(max_descriptor + 1, &read_fds, NULL, NULL, NULL) == -1) // Wait for something to happen on any socket
{
perror("select");
exit(EXIT_FAILURE);
}
if(FD_ISSET(STDIN, &read_fds))
{
char buffer[BUFFER_SIZE];
int n = read(STDIN, buffer, BUFFER_SIZE);
buffer[n] = '\0';
if(send(server, buffer, n+1, 0) == -1)
{
perror("send");
return EXIT_FAILURE;
}
}
else
{
char buffer[BUFFER_SIZE];
int n = recv(server, buffer, sizeof buffer, 0); // Read from the socket
if(n == 0) // If the receive returns a zero value, the connection was closed by the client
{
fprintf(stdout, "socket disconnected\n");
close(server); // Close the connection
return EXIT_FAILURE;
}
if(n < 0) // If the receive returns a negative value, it's an error
{
perror("recv");
close(server); // Close the connection
return EXIT_FAILURE;
}
fprintf(stdout, buffer);
}
}
return EXIT_SUCCESS;
}
|
7f82e0d406de289497081c822349f56e8ab15839
|
564923742174524da9ac1e2333b225e1e6970cc2
|
/sfs_api.c
|
6409f7fb4f8dd1bef00185b8daed6e7a14a9dbe4
|
[] |
no_license
|
ZahraKhambaty/Unix-File-System
|
7b707f1ea92010ad34911bf53653da34ea6c9b53
|
6c5fb7c153372e745f124d0f676b6ac6603c8482
|
refs/heads/master
| 2021-09-02T23:41:10.289739 | 2018-01-04T04:19:58 | 2018-01-04T04:19:58 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 17,525 |
c
|
sfs_api.c
|
#include "sfs_api.h"
void init_superBlock_t() {
sb.magic = 0xABCD005;
sb.blockSize = 1024;
// root is j node in the super block;
for (int i = 0; i < 14; i++) {
sb.root.direct[i] = -1;
sb.root.size = -1;
}
}
void init_rootDirTable_t() {
for (int i = 0; i < NUM_OF_FILES; i++) {
rDT.fileEntries[i].inodeNum = 0; // means inode is not used.
for (int k = 0; k < 10; k++) {
rDT.fileEntries[i].filename[k] = '\0';
}
}
}
void init_fileDescriptorTable_t() {
for (int i = 0; i < NUM_OF_FILES; i++) {
fDT.table[i].fileopen = -1;
fDT.table[i].inode.size = -1;
fDT.table[i].inodeNum = -1;
fDT.table[i].readPointer = -1;
fDT.table[i].writePointer = -1;
}
}
void init_InodeBlock_t() {
for (int i = 0; i < 16; i++) {
iNodeBlock.inodes[i].size = -1; // means inode is not used.
for (int j = 0; j < 14; j++) {
iNodeBlock.inodes[i].direct[j] = -1;
}
iNodeBlock.inodes[i].indirect = -1;
}
}
void init_Inodes_t() {
currInode.size = -1; // means inode is not used.
for (int j = 0; j < 14; j++) {
currInode.direct[j] = -1;
}
currInode.indirect = -1;
}
void init_freeBitMap_t() {
for (int i = 0; i < NUM_BLOCKS; i++) {
FBM.data[i] = 0; // means inode is not used.
}
}
int allocateBlock() {
read_blocks(1, 1, &FBM);
for (int i = 0; i < NUM_BLOCKS; i++) {
if (FBM.data[i] == 0) {
FBM.data[i] = 1;
write_blocks(1, 1, &FBM);
return i;
}
}
return -1;
}
int allocateNewInode() {
// find inode by reading all the inode blocks if found return index
for (int i = 0; i < NUM_INODE_DIRECT; i++) {
if (sb.root.direct[i] != -1) {
read_blocks(sb.root.direct[i], 1, &iNodeBlock);
for (int j = 0; j < NUM_INODES_PER_BLOCK; j++) {
currInode = iNodeBlock.inodes[j];
if (currInode.size == -1) {
return j + (i * NUM_INODE_DIRECT);
}
}
} else {
// if not found allocate(create) a new block with the first index
int allocatedBlock = allocateBlock();
read_blocks(allocatedBlock, 1, &iNodeBlock);
currInode = iNodeBlock.inodes[0];
currInode.size = 0;
write_blocks(allocatedBlock, 1, &iNodeBlock);
return (i * NUM_INODE_DIRECT);
}
}
return -1;
}
void mkssfs(int fresh) {
// INITIALIZING
init_superBlock_t();
init_rootDirTable_t();
init_fileDescriptorTable_t();
init_InodeBlock_t();
init_freeBitMap_t();
// init_iNode_tracker_t();
init_Inodes_t();
int iblocks = 3;
printf("initialized\n");
sb.root.direct[0] = 3; // points to 1st inode block
for (int i = 0; i < 14; i++) {
sb.root.direct[i] = iblocks++;
}
FBM.data[0] = 1; //"sb";
FBM.data[1] = 1; //"FBM";
FBM.data[2] = 1; //"WM";
for (int k = 3; k < 17; k++) {
FBM.data[k] = 1;
}//"iNodeBlock";
for (int j = 17; j < 21; j++) {
FBM.data[j] = 1;
}; //"rDT";
// read_blocks(sb.root.direct[0], 1, &iNodeBlock);
iNodeBlock.inodes[0].direct[0] = 17;
iNodeBlock.inodes[0].size = 0;
//OPEN A NEW DISK
if (!fresh) {
if (init_disk(FILE_NAME, BLOCK_SIZE, NUM_BLOCKS) == -1)
printf("CANNOT OPEN the file");
} else {
if (init_fresh_disk(FILE_NAME, BLOCK_SIZE, NUM_BLOCKS) == -1)
printf("CANNOT OPEN");
else {
// writing to the disk
printf("I am writing the initial values to the disk\n");
write_blocks(0, 1, &sb);
write_blocks(1, 1, &FBM);
write_blocks(2, 1, &WM);
for(int i = 3;i<17;i++){
write_blocks(i, 1, &iNodeBlock);
}
for(int j = 17;j<20;j++){
write_blocks(j, 1, &rDT);
}
printf("end\n");
}
}
}
int ssfs_fopen(char *name) {
int i, k; // k is for file index
int inodenum;
int blocknum;
int found = 0;
// Lookup for file if it currently resides in our table
// printf("Looking for the file\n");
if (!name || name[0] == '\0' || strlen(name) > 10) {
return -1;
}
for (i = 0; i < 200; i++) {
if (strcmp(name, rDT.fileEntries[i].filename) == 0) {
found = 1;
break;
}
}
// Lookup for file if it is currently open or not
// find the corresponding inode number
if (found == 1) {
inodenum = rDT.fileEntries[i].inodeNum;
for (int j = 0; j < MAX_FILEDESCRIPTABLE_SIZE; j++) {
if (fDT.table[j].inodeNum == inodenum) {
printf("Already Open!!\n");
return-1;
} else {
break;
}
}
//open a new file descriptor entry for the file
//find the block number that corresponds to the inode
blocknum = sb.root.direct[inodenum / NUM_INODES_PER_BLOCK];
read_blocks(blocknum, 1, &iNodeBlock);
// read the block get the inode details
// want to use the current currInode.
write_blocks(blocknum, 1, &iNodeBlock);
for (k = 0; k < MAX_FILEDESCRIPTABLE_SIZE; k++) {
if (fDT.table[k].fileopen == -1) {
fDT.table[k].fileopen = 1; //its open now
fDT.table[k].inode = iNodeBlock.inodes[inodenum % 16];
fDT.table[k].inodeNum = inodenum;
fDT.table[k].readPointer = 0;
fDT.table[k].writePointer = 0;
return k;
}
}
}
// if the file is not in rdt create one and put it back in the block.
if (found == 0) {
read_blocks(RDIR_BLOCK_ADDRESS, RDIR_BLOCK_SIZE, &rDT);
for (i = 0; i < NUM_OF_FILES; i++) {
// search for an available entry in the root directory table
if (strcmp(rDT.fileEntries[i].filename, "\0") == 0) {
break;
}
}
// create a new entry space
rootDir_t *new = &rDT.fileEntries[i];
// allocate this space to the new entry
// name the file
strcpy(new->filename, name);
//need to allocate a data block for the inode;
int allocatediNode = allocateNewInode();
//need to find an inode for this new file.
new->inodeNum = allocatediNode;
write_blocks(RDIR_BLOCK_ADDRESS, RDIR_BLOCK_SIZE, &rDT);
// assign the inode to the new entry
// access root directory block
blocknum = sb.root.direct[allocatediNode / NUM_INODES_PER_BLOCK];
// read the block we are gonna allocate to
read_blocks(blocknum, 1, &iNodeBlock);
// creates a file descriptor for the new entry and updates the content
// updating the fbm to indicate the data block is used
iNodeBlock.inodes[allocatediNode % 16].size = 0;
write_blocks(blocknum, 1, &iNodeBlock);
for (int j = 0; j < MAX_FILEDESCRIPTABLE_SIZE; j++) {
if (fDT.table[j].fileopen == -1) {
fDT.table[j].fileopen = 1; //its open now
fDT.table[j].inode = iNodeBlock.inodes[allocatediNode % 16];
fDT.table[j].inodeNum = allocatediNode;
fDT.table[j].readPointer = 0;
fDT.table[j].writePointer = 0;
return j;
}
}
}
return -1;
}
int ssfs_fclose(int fileID) {
if (fileID < 0) {
printf("INDEX NOT DEFINED\n");
return-1;
}
if (fileID > 200) {
printf("Too Many files, cannot handle\n");
return -1;
}
if (fDT.table[fileID].fileopen == -1) {
return -1;
}
if (fDT.table[fileID].fileopen != -1) {
fDT.table[fileID].fileopen = -1;
fDT.table[fileID].inode.size = -1;
fDT.table[fileID].readPointer = -1;
fDT.table[fileID].writePointer = -1;
fDT.table[fileID].inodeNum = -1;
return 0;
}
return -1;
}
// printf("fDT.index %i\n", fDT.table[fileID].fdindex);
int ssfs_frseek(int fileID, int loc) {
if (fileID < 0) {
return-1;
} else if (fileID > 200) {
printf("Too Many files, cannot handle");
return -1;
}
if (fDT.table[fileID].fileopen == -1) {
return -1;
}
if (loc < 0 || loc > fDT.table[fileID].inode.size) {
return -1;
}
fDT.table[fileID].readPointer = loc;
return 0;
}
int ssfs_fwseek(int fileID, int loc) {
if (fileID < 0) {
return-1;
} else if (fileID > 200) {
printf("Too Many files, cannot handle");
return -1;
}
if (fDT.table[fileID].fileopen == -1) {
return -1;
}
if (loc < 0 || loc > fDT.table[fileID].inode.size) {
return -1;
}
fDT.table[fileID].writePointer = loc;
return 0;
}
int ssfs_fwrite(int fileID, char *buf, int length) {
int blocknum;
int byteswritten;
int allocatecacheindisk;
int incSize=0;
if (fileID < 0) {
printf("INDEX NOT DEFINED");
return -1;
}
if (fileID > 200) {
printf("Too Many files, cannot handle");
return -1;
}
if (fDT.table[fileID].fileopen == -1) {
printf("Writing to a closed file\n");
return -1;
}
if (fDT.table[fileID].inode.size == 0) {
printf("Writing to a newly created file\n");
blocknum = sb.root.direct[fDT.table[fileID].inodeNum / NUM_INODES_PER_BLOCK];
read_blocks(blocknum, 1, &iNodeBlock);
inode_t currInode = iNodeBlock.inodes[fDT.table[fileID].inodeNum % 16];
// What we want to write is greater than a block
if (length > 1024) {
for (int j = 0; j < length / 1024; j++) {
allocatecacheindisk = allocateBlock();
currInode.direct[j] = allocatecacheindisk;
write_blocks(currInode.direct[j], 1, buf);
buf += 1024;
}
iNodeBlock.inodes[fDT.table[fileID].inodeNum % 16].size += length;
write_blocks(blocknum, 1, &iNodeBlock);
fDT.table[fileID].writePointer = length;
}//what we want to write fits in 1 data Block
else {
allocatecacheindisk = allocateBlock();
currInode.direct[0] = allocatecacheindisk;
read_blocks(currInode.direct[0], 1, &cache);
memcpy(cache.data, buf, length);
write_blocks(currInode.direct[0], 1, &cache);
currInode.size = length;
iNodeBlock.inodes[fDT.table[fileID].inodeNum % 16] = currInode;
write_blocks(blocknum, 1, &iNodeBlock);
fDT.table[fileID].writePointer = length;
fDT.table[fileID].inode = currInode;
return length;
}
}
printf("Writing to an existing file\n");
// 2 cases
// Writing to a block where there is space
blocknum = sb.root.direct[fDT.table[fileID].inodeNum / NUM_INODES_PER_BLOCK];
read_blocks(blocknum, 1, &iNodeBlock);
inode_t currInode = iNodeBlock.inodes[fDT.table[fileID].inodeNum % 16];
// find the inodeData Block corresponding to the write pointer
int num_inodeDataBlock = (fDT.table[fileID].writePointer) / 1024;
// We will face two cases here as well:
//1) if length + writepointer is < 1024
if (length + fDT.table[fileID].writePointer <= 1024) {
// read the data block from the disk
read_blocks(currInode.direct[num_inodeDataBlock], 1, &bufferin);
//memcopy the buffer starting write pointer
memcpy(bufferin + fDT.table[fileID].writePointer, buf, length);
//push back to disk
write_blocks(currInode.direct[num_inodeDataBlock], 1, &bufferin);
// num of bytes written
byteswritten = length;
//increment the write pointer and increment inode size in FDT
fDT.table[fileID].writePointer += length;
incSize = fDT.table[fileID].writePointer - currInode.size;
if(incSize>0){
fDT.table[fileID].inode.size += incSize;
}
//increment the write pointer and increment inode size in the disk
iNodeBlock.inodes[fDT.table[fileID].inodeNum % 16] = currInode;
write_blocks(blocknum, 1, &iNodeBlock);
return length;
}
//2) if length + writepointer is >= 1024
if (length + fDT.table[fileID].writePointer > 1024) {
// we will have to write to multiple data blocks
// lets first find the number of data blocks we will have to write to
int num_dataBlocks = (length + fDT.table[fileID].writePointer) / 1024;
for (int j = num_inodeDataBlock; j < num_dataBlocks; j++) {
//read the data block from the disk
//read_blocks(currInode->direct[j], 1, &cache);
//memcopy the contents of the data block corresponding to the writepointer into the bufferin
//memcpy(bufferin, cache, fDT.table[fileID].writePointer);
//update bufferin pointer
bufferin + fDT.table[fileID].writePointer;
// note that we need to calculate the remaining bytes or available bytes in the block
//memcopy the new content into the bufferin starting at the updated index
int available_byte_space = 1024 - fDT.table[fileID].writePointer;
memcpy(bufferin, buf, available_byte_space);
// update buf // this corresponds to the remaining data that neets to be written
buf = buf + available_byte_space;
//push back to disk
write_blocks(currInode.direct[j], 1, &bufferin);
// clear bufferin for each block
memset(bufferin, '\0', 1024);
}
//increment the write pointer and increment inode size in FDT
fDT.table[fileID].inode.size += (length + 1);
fDT.table[fileID].writePointer += (length + 1);
//increment the write pointer and increment inode size in the disk
iNodeBlock.inodes[fDT.table[fileID].inodeNum % 16].size += (length + 1);
write_blocks(blocknum, 1, &iNodeBlock);
}
return 0;
}
int ssfs_fread(int fileID, char *buf, int length) {
DataBlock_t cache;
int blocknum;
inode_t currInode;
if (fDT.table[fileID].fileopen == -1) {
return -1;
}
if (fileID < 0) {
printf("INDEX NOT DEFINED");
return-1;
}
if (fileID >= 200) {
printf("Too Many files, cannot handle");
return -1;
}
blocknum = sb.root.direct[fDT.table[fileID].inodeNum / NUM_INODES_PER_BLOCK];
read_blocks(blocknum, 1, &iNodeBlock);
currInode = iNodeBlock.inodes[(fDT.table[fileID].inodeNum % 16)];
// find the data block corresponding to the read pointer
int num_inodeDataBlock = (fDT.table[fileID].readPointer) / 1024;
// lets first find the number of data blocks we will have to read
int num_dataBlocks = (length + fDT.table[fileID].readPointer) / 1024;
if (length > 1024) {
for (int j = num_inodeDataBlock; j < num_dataBlocks; j++) {
read_blocks(currInode.direct[j], 1, buf);
buf += 1024;
fDT.table[fileID].readPointer += length;
return length;
}
} else {
// read from the disk
read_blocks(currInode.direct[num_inodeDataBlock], 1, &cache);
memcpy(buf, cache.data+fDT.table[fileID].readPointer, length);
fDT.table[fileID].readPointer += length;
return length;
}
return -1;
}
int ssfs_remove(char *file) {
int getInodenum;
int blocknum;
int inodeIndex;
int i, j; // file descriptor index, j is root dir index
read_blocks(RDIR_BLOCK_ADDRESS, RDIR_BLOCK_SIZE, &rDT);
// access the root directory
// check if file is open
for (j = 0; j < NUM_OF_FILES; j++) {
//compare inode number too
if (strcmp(rDT.fileEntries[j].filename, file) == 0) {
break;
}
}
// if it is close it
for (i = 0; i < NUM_OF_FILES; i++) {
if (fDT.table[i].inodeNum == rDT.fileEntries[j].inodeNum) {
ssfs_fclose(i);
break;
}
}
getInodenum = rDT.fileEntries[j].inodeNum;
// get inodenum corresponding to the file
// Clear the tracker
// release entry from RDT
for (int k = 0; k < 10; k++) {
rDT.fileEntries[j].filename[k] = '\0';
}
rDT.fileEntries[j].inodeNum = -1;
// release it from the disk
// find the block number that corresponds to the inode
blocknum = sb.root.direct[getInodenum / NUM_INODES_PER_BLOCK];
// read the block get the inode details
inodeIndex = getInodenum % NUM_INODES_PER_BLOCK;
read_blocks(blocknum, 1, &iNodeBlock);
// get the inode
inode_t *currInode = &(iNodeBlock.inodes[inodeIndex]);
// want to release the current currInode.
currInode->size = -1;
for (int k = 0; k < 14; k++) {
if (currInode->direct[k] != -1) {
FBM.data[currInode->direct[k]] = 1;
currInode->direct[k] = -1;
write_blocks(blocknum, 1, &iNodeBlock);
write_blocks(RDIR_BLOCK_ADDRESS, RDIR_BLOCK_SIZE, &rDT);
return 0;
}
}
return -1;
}
|
4f9c17e6a98b5aa612d28fdd0b8f02ac14c98ae4
|
c2cedcf36667730f558ab354bea4505b616c90d2
|
/players/scathe/armor/jersey.c
|
cca96ff69f894889e2ae3174454da3f872ff61df
|
[] |
no_license
|
wugouzi/Nirvlp312mudlib
|
965ed876c7080ab00e28c5d8cd5ea9fc9e46258f
|
616cad7472279cc97c9693f893940f5336916ff8
|
refs/heads/master
| 2023-03-16T03:45:05.510851 | 2017-09-21T17:05:00 | 2017-09-21T17:05:00 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 325 |
c
|
jersey.c
|
inherit "obj/armor";
reset(arg){
::reset(arg);
if (arg) return;
set_short("Vince Carter's Jersey");
set_long("\
A nice Vincer Carter jersey, fresh from his victory over those\n\
lousy New York Knicks!.\n");
set_ac(0);
set_weight(3);
set_value(0);
set_name("jersey");
set_type("armor");
}
|
94e10e3b8787f9c23670ff1a521a2080558bf7ec
|
8228c0d684fe1cf64ae5172e51cecaea417fb3d9
|
/new/hicar_service/src/virtual_dev/bt/btserver/src-gen/PhoneBook/phonebook.h
|
1e9d635de0b5bd6cca2b8154e213faddfeda26bb
|
[] |
no_license
|
niefan/workspace
|
363c11dc858be7f6783eaa6f5fde6d6deecca312
|
6ebb09fc432eb7295f922da3fbc764f9d1125b6c
|
refs/heads/master
| 2022-07-31T18:12:39.109983 | 2020-05-22T08:50:42 | 2020-05-22T08:50:42 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 13,528 |
h
|
phonebook.h
|
/*
* Generated by gdbus-codegen 2.40.2. DO NOT EDIT.
*
* The license of this code is the same as for the source it was derived from.
*/
#ifndef __PHONEBOOK_H__
#define __PHONEBOOK_H__
#include <gio/gio.h>
G_BEGIN_DECLS
/* ------------------------------------------------------------------------ */
/* Declarations for com.hsaeyz.bluetooth.phoneBook */
#define TYPE_PHONE_BOOK (phone_book_get_type ())
#define PHONE_BOOK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_PHONE_BOOK, PhoneBook))
#define IS_PHONE_BOOK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_PHONE_BOOK))
#define PHONE_BOOK_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), TYPE_PHONE_BOOK, PhoneBookIface))
struct _PhoneBook;
typedef struct _PhoneBook PhoneBook;
typedef struct _PhoneBookIface PhoneBookIface;
struct _PhoneBookIface
{
GTypeInterface parent_iface;
gboolean (*handle_cancel_down_load_phone_book) (
PhoneBook *object,
GDBusMethodInvocation *invocation);
gboolean (*handle_clearcalllogs) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr);
gboolean (*handle_clearcontacts) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr);
gboolean (*handle_deletecalllog) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr,
const gchar *arg_datatime);
gboolean (*handle_deletecontact) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr,
const gchar *arg_name,
const gchar *arg_num);
gboolean (*handle_down_load_call_log) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
gint arg_type);
gboolean (*handle_down_load_phone_book) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
gint arg_location);
gboolean (*handle_getcontacts) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr);
gboolean (*handle_savecontacts) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr);
gboolean (*handle_searchcontact) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr,
const gchar *arg_sql,
gint arg_type);
gboolean (*handle_syncdata) (
PhoneBook *object,
GDBusMethodInvocation *invocation,
const gchar *arg_addr,
gint arg_type);
void (*call_log_changed) (
PhoneBook *object,
const gchar *arg_callLogList);
void (*new_calllog_changed) (
PhoneBook *object,
const gchar *arg_name,
const gchar *arg_number,
const gchar *arg_type,
const gchar *arg_datatime,
const gchar *arg_talktime);
void (*pbap_down_load_state) (
PhoneBook *object,
gint arg_pbapDownLoadState);
void (*phone_book_changed) (
PhoneBook *object,
const gchar *arg_contactlist);
};
GType phone_book_get_type (void) G_GNUC_CONST;
GDBusInterfaceInfo *phone_book_interface_info (void);
guint phone_book_override_properties (GObjectClass *klass, guint property_id_begin);
/* D-Bus method call completion functions: */
void phone_book_complete_down_load_phone_book (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_down_load_call_log (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_cancel_down_load_phone_book (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_searchcontact (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_deletecontact (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_clearcontacts (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_savecontacts (
PhoneBook *object,
GDBusMethodInvocation *invocation,
gboolean result);
void phone_book_complete_getcontacts (
PhoneBook *object,
GDBusMethodInvocation *invocation,
gboolean dataexits);
void phone_book_complete_syncdata (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_deletecalllog (
PhoneBook *object,
GDBusMethodInvocation *invocation);
void phone_book_complete_clearcalllogs (
PhoneBook *object,
GDBusMethodInvocation *invocation);
/* D-Bus signal emissions functions: */
void phone_book_emit_pbap_down_load_state (
PhoneBook *object,
gint arg_pbapDownLoadState);
void phone_book_emit_phone_book_changed (
PhoneBook *object,
const gchar *arg_contactlist);
void phone_book_emit_new_calllog_changed (
PhoneBook *object,
const gchar *arg_name,
const gchar *arg_number,
const gchar *arg_type,
const gchar *arg_datatime,
const gchar *arg_talktime);
void phone_book_emit_call_log_changed (
PhoneBook *object,
const gchar *arg_callLogList);
/* D-Bus method calls: */
void phone_book_call_down_load_phone_book (
PhoneBook *proxy,
gint arg_location,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_down_load_phone_book_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_down_load_phone_book_sync (
PhoneBook *proxy,
gint arg_location,
GCancellable *cancellable,
GError **error);
void phone_book_call_down_load_call_log (
PhoneBook *proxy,
gint arg_type,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_down_load_call_log_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_down_load_call_log_sync (
PhoneBook *proxy,
gint arg_type,
GCancellable *cancellable,
GError **error);
void phone_book_call_cancel_down_load_phone_book (
PhoneBook *proxy,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_cancel_down_load_phone_book_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_cancel_down_load_phone_book_sync (
PhoneBook *proxy,
GCancellable *cancellable,
GError **error);
void phone_book_call_searchcontact (
PhoneBook *proxy,
const gchar *arg_addr,
const gchar *arg_sql,
gint arg_type,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_searchcontact_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_searchcontact_sync (
PhoneBook *proxy,
const gchar *arg_addr,
const gchar *arg_sql,
gint arg_type,
GCancellable *cancellable,
GError **error);
void phone_book_call_deletecontact (
PhoneBook *proxy,
const gchar *arg_addr,
const gchar *arg_name,
const gchar *arg_num,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_deletecontact_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_deletecontact_sync (
PhoneBook *proxy,
const gchar *arg_addr,
const gchar *arg_name,
const gchar *arg_num,
GCancellable *cancellable,
GError **error);
void phone_book_call_clearcontacts (
PhoneBook *proxy,
const gchar *arg_addr,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_clearcontacts_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_clearcontacts_sync (
PhoneBook *proxy,
const gchar *arg_addr,
GCancellable *cancellable,
GError **error);
void phone_book_call_savecontacts (
PhoneBook *proxy,
const gchar *arg_addr,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_savecontacts_finish (
PhoneBook *proxy,
gboolean *out_result,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_savecontacts_sync (
PhoneBook *proxy,
const gchar *arg_addr,
gboolean *out_result,
GCancellable *cancellable,
GError **error);
void phone_book_call_getcontacts (
PhoneBook *proxy,
const gchar *arg_addr,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_getcontacts_finish (
PhoneBook *proxy,
gboolean *out_dataexits,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_getcontacts_sync (
PhoneBook *proxy,
const gchar *arg_addr,
gboolean *out_dataexits,
GCancellable *cancellable,
GError **error);
void phone_book_call_syncdata (
PhoneBook *proxy,
const gchar *arg_addr,
gint arg_type,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_syncdata_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_syncdata_sync (
PhoneBook *proxy,
const gchar *arg_addr,
gint arg_type,
GCancellable *cancellable,
GError **error);
void phone_book_call_deletecalllog (
PhoneBook *proxy,
const gchar *arg_addr,
const gchar *arg_datatime,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_deletecalllog_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_deletecalllog_sync (
PhoneBook *proxy,
const gchar *arg_addr,
const gchar *arg_datatime,
GCancellable *cancellable,
GError **error);
void phone_book_call_clearcalllogs (
PhoneBook *proxy,
const gchar *arg_addr,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean phone_book_call_clearcalllogs_finish (
PhoneBook *proxy,
GAsyncResult *res,
GError **error);
gboolean phone_book_call_clearcalllogs_sync (
PhoneBook *proxy,
const gchar *arg_addr,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_PHONE_BOOK_PROXY (phone_book_proxy_get_type ())
#define PHONE_BOOK_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_PHONE_BOOK_PROXY, PhoneBookProxy))
#define PHONE_BOOK_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_PHONE_BOOK_PROXY, PhoneBookProxyClass))
#define PHONE_BOOK_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_PHONE_BOOK_PROXY, PhoneBookProxyClass))
#define IS_PHONE_BOOK_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_PHONE_BOOK_PROXY))
#define IS_PHONE_BOOK_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_PHONE_BOOK_PROXY))
typedef struct _PhoneBookProxy PhoneBookProxy;
typedef struct _PhoneBookProxyClass PhoneBookProxyClass;
typedef struct _PhoneBookProxyPrivate PhoneBookProxyPrivate;
struct _PhoneBookProxy
{
/*< private >*/
GDBusProxy parent_instance;
PhoneBookProxyPrivate *priv;
};
struct _PhoneBookProxyClass
{
GDBusProxyClass parent_class;
};
GType phone_book_proxy_get_type (void) G_GNUC_CONST;
void phone_book_proxy_new (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
PhoneBook *phone_book_proxy_new_finish (
GAsyncResult *res,
GError **error);
PhoneBook *phone_book_proxy_new_sync (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
void phone_book_proxy_new_for_bus (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
PhoneBook *phone_book_proxy_new_for_bus_finish (
GAsyncResult *res,
GError **error);
PhoneBook *phone_book_proxy_new_for_bus_sync (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_PHONE_BOOK_SKELETON (phone_book_skeleton_get_type ())
#define PHONE_BOOK_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_PHONE_BOOK_SKELETON, PhoneBookSkeleton))
#define PHONE_BOOK_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_PHONE_BOOK_SKELETON, PhoneBookSkeletonClass))
#define PHONE_BOOK_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_PHONE_BOOK_SKELETON, PhoneBookSkeletonClass))
#define IS_PHONE_BOOK_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_PHONE_BOOK_SKELETON))
#define IS_PHONE_BOOK_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_PHONE_BOOK_SKELETON))
typedef struct _PhoneBookSkeleton PhoneBookSkeleton;
typedef struct _PhoneBookSkeletonClass PhoneBookSkeletonClass;
typedef struct _PhoneBookSkeletonPrivate PhoneBookSkeletonPrivate;
struct _PhoneBookSkeleton
{
/*< private >*/
GDBusInterfaceSkeleton parent_instance;
PhoneBookSkeletonPrivate *priv;
};
struct _PhoneBookSkeletonClass
{
GDBusInterfaceSkeletonClass parent_class;
};
GType phone_book_skeleton_get_type (void) G_GNUC_CONST;
PhoneBook *phone_book_skeleton_new (void);
G_END_DECLS
#endif /* __PHONEBOOK_H__ */
|
46b62b2f5461c5cab1b7357ec6c6a0b7b37f3610
|
e71db43bda802722fe695ceee19c624a020fb6df
|
/rtl819x-sdk-v2.5/rtl819x/users/goahead-2.1.1/LINUX/mibdef.h
|
3ae94bd3f773bafb4a88674ee2112a7768070aa6
|
[] |
no_license
|
copslock/netis_gpl
|
6888500d78a93677c1b40ff100e684081c40421a
|
b9bee431d12d9dc73d6df7f6142cd208a59f6a53
|
refs/heads/master
| 2021-05-18T12:57:51.934055 | 2020-03-31T02:00:57 | 2020-03-31T02:00:57 | 251,248,258 | 0 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 59,380 |
h
|
mibdef.h
|
/*
* Header file of AP mib
* Authors: David Hsu <davidhsu@realtek.com.tw>
*
* $Id: apmib.h,v 1.55 2009/10/06 05:49:10 bradhuang Exp $
*
*/
#ifdef MIB_HW_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, boardVer, , BOARD_VER, BYTE_T, HW_SETTING_T, 0, 0)
MIBDEF(unsigned char, nic0Addr, [6], NIC0_ADDR, BYTE6_T, HW_SETTING_T, 0, 0)
MIBDEF(unsigned char, nic1Addr, [6], NIC1_ADDR, BYTE6_T, HW_SETTING_T, 0, 0)
MIBDEF(HW_WLAN_SETTING_T, wlan, [NUM_WLAN_INTERFACE], WLAN_ROOT, TABLE_LIST_T, HW_SETTING_T, 0, hwmib_wlan_table)
#endif // #ifdef MIB_HW_IMPORT
#ifdef MIB_HW_WLAN_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, macAddr, [6], WLAN_ADDR, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAddr1, [6], WLAN_ADDR1, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAddr2, [6], WLAN_ADDR2, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAddr3, [6], WLAN_ADDR3, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAddr4, [6], WLAN_ADDR4, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAddr5, [6], WLAN_ADDR5, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAddr6,[6], WLAN_ADDR6, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAddr7, [6], WLAN_ADDR7, BYTE6_T, HW_WLAN_SETTING_T, 0, 0)
#if defined(CONFIG_RTL_8196B)
MIBDEF(unsigned char, txPowerCCK, [MAX_CCK_CHAN_NUM], TX_POWER_CCK, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, txPowerOFDM_HT_OFDM_1S, [MAX_OFDM_CHAN_NUM], TX_POWER_OFDM_1S, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, txPowerOFDM_HT_OFDM_2S, [MAX_OFDM_CHAN_NUM], TX_POWER_OFDM_2S, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, regDomain, , REG_DOMAIN, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rfType, , RF_TYPE, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, xCap, , 11N_XCAP, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, LOFDMPwDiffA, , 11N_LOFDMPWDA, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, LOFDMPwDiffB, , 11N_LOFDMPWDB, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, TSSI1, , 11N_TSSI1, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, TSSI2, , 11N_TSSI2, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Ther, , 11N_THER, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, ledType, , LED_TYPE, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved1, , 11N_RESERVED1, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved2, , 11N_RESERVED2, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved3, , 11N_RESERVED3, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved4, , 11N_RESERVED4, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved5, , 11N_RESERVED5, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved6, , 11N_RESERVED6, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved7, , 11N_RESERVED7, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved8, , 11N_RESERVED8, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
#else /*rtl8196c*/
MIBDEF(unsigned char, pwrlevelCCK_A, [MAX_2G_CHANNEL_NUM_MIB], TX_POWER_CCK_A, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrlevelCCK_B, [MAX_2G_CHANNEL_NUM_MIB], TX_POWER_CCK_B, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrlevelHT40_1S_A, [MAX_2G_CHANNEL_NUM_MIB], TX_POWER_HT40_1S_A, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrlevelHT40_1S_B, [MAX_2G_CHANNEL_NUM_MIB], TX_POWER_HT40_1S_B, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrdiffHT40_2S, [MAX_2G_CHANNEL_NUM_MIB], TX_POWER_DIFF_HT40_2S, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrdiffHT20, [MAX_2G_CHANNEL_NUM_MIB], TX_POWER_DIFF_HT20, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrdiffOFDM, [MAX_2G_CHANNEL_NUM_MIB], TX_POWER_DIFF_OFDM, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, regDomain, , REG_DOMAIN, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rfType, , RF_TYPE, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, ledType, , LED_TYPE, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, xCap, , 11N_XCAP, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, TSSI1, , 11N_TSSI1, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, TSSI2, , 11N_TSSI2, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Ther, , 11N_THER, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, trswitch, , 11N_TRSWITCH, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, trswpape_C9, , 11N_TRSWPAPE_C9, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, trswpape_CC, , 11N_TRSWPAPE_CC, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, target_pwr, , 11N_TARGET_PWR, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved5, , 11N_RESERVED5, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved6, , 11N_RESERVED6, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved7, , 11N_RESERVED7, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved8, , 11N_RESERVED8, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved9, , 11N_RESERVED9, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, Reserved10, , 11N_RESERVED10, BYTE_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrlevel5GHT40_1S_A, [MAX_5G_CHANNEL_NUM_MIB], TX_POWER_5G_HT40_1S_A, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrlevel5GHT40_1S_B, [MAX_5G_CHANNEL_NUM_MIB], TX_POWER_5G_HT40_1S_B, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrdiff5GHT40_2S, [MAX_5G_CHANNEL_NUM_MIB], TX_POWER_DIFF_5G_HT40_2S, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrdiff5GHT20, [MAX_5G_CHANNEL_NUM_MIB], TX_POWER_DIFF_5G_HT20, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, pwrdiff5GOFDM, [MAX_5G_CHANNEL_NUM_MIB], TX_POWER_DIFF_5G_OFDM, BYTE_ARRAY_T, HW_WLAN_SETTING_T, 0, 0)
#endif
#ifdef WIFI_SIMPLE_CONFIG
MIBDEF(unsigned char, wscPin, [PIN_LEN+1], WSC_PIN, STRING_T, HW_WLAN_SETTING_T, 0, 0)
#endif
#endif // #ifdef MIB_HW_WLAN_IMPORT
#ifdef MIB_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
// TCP/IP stuffs
MIBDEF(unsigned char, ipAddr, [4], IP_ADDR, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, subnetMask, [4], SUBNET_MASK, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, defaultGateway, [4], DEFAULT_GATEWAY, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dhcp, , DHCP, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dhcpClientStart, [4], DHCP_CLIENT_START, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dhcpClientEnd, [4], DHCP_CLIENT_END, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned long, dhcpLeaseTime, , DHCP_LEASE_TIME, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, elanMacAddr, [6], ELAN_MAC_ADDR, BYTE6_T, APMIB_T, 0, 0)
//Brad add for static dhcp
MIBDEF(unsigned char, dns1, [4], DNS1, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dns2, [4], DNS2, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dns3, [4], DNS3, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, stpEnabled, , STP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, deviceName, [MAX_NAME_LEN], DEVICE_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, scrlogEnabled, , SCRLOG_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, autoDiscoveryEnabled, , AUTO_DISCOVERY_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, domainName, [MAX_NAME_LEN], DOMAIN_NAME, STRING_T, APMIB_T, 0, 0)
// Supervisor of web server account
MIBDEF(unsigned char, superName, [MAX_NAME_LEN], SUPER_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, superPassword, [MAX_NAME_LEN], SUPER_PASSWORD, STRING_T, APMIB_T, 0, 0)
// web server account
MIBDEF(unsigned char, userName, [MAX_NAME_LEN], USER_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, userPassword, [MAX_NAME_LEN], USER_PASSWORD, STRING_T, APMIB_T, 0, 0)
#if defined(CONFIG_RTL_8198_AP_ROOT)
MIBDEF(unsigned char, ntpEnabled, , NTP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, daylightsaveEnabled, , DAYLIGHT_SAVE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpServerId, , NTP_SERVER_ID, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpTimeZone, [8], NTP_TIMEZONE, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpServerIp1, [4], NTP_SERVER_IP1, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpServerIp2, [4], NTP_SERVER_IP2, IA_T, APMIB_T, 0, 0)
#endif
#ifdef HOME_GATEWAY
MIBDEF(unsigned char, wanMacAddr, [6], WAN_MAC_ADDR, BYTE6_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, wanDhcp, , WAN_DHCP, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, wanIpAddr, [4], WAN_IP_ADDR, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, wanSubnetMask, [4], WAN_SUBNET_MASK, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, wanDefaultGateway, [4], WAN_DEFAULT_GATEWAY, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pppUserName, [MAX_NAME_LEN_LONG], PPP_USER_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pppPassword, [MAX_NAME_LEN_LONG], PPP_PASSWORD, STRING_T, APMIB_T, 0, 0)
MIBDEF(DNS_TYPE_T, dnsMode, , DNS_MODE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pppIdleTime, , PPP_IDLE_TIME, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pppConnectType, , PPP_CONNECT_TYPE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dmzEnabled, , DMZ_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dmzHost, [4], DMZ_HOST, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, upnpEnabled, , UPNP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pppMtuSize, , PPP_MTU_SIZE, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpIpAddr, [4], PPTP_IP_ADDR, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpSubnetMask, [4], PPTP_SUBNET_MASK, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpServerIpAddr, [4], PPTP_SERVER_IP_ADDR, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpUserName, [MAX_NAME_LEN_LONG], PPTP_USER_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpPassword, [MAX_NAME_LEN_LONG], PPTP_PASSWORD, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pptpMtuSize, , PPTP_MTU_SIZE, WORD_T, APMIB_T, 0, 0)
/* # keith: add l2tp support. 20080515 */
MIBDEF(unsigned char, l2tpIpAddr, [4], L2TP_IP_ADDR, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, l2tpSubnetMask, [4], L2TP_SUBNET_MASK, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, l2tpServerIpAddr, [MAX_PPTP_HOST_NAME_LEN], L2TP_SERVER_IP_ADDR, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, l2tpGateway, [4], L2TP_GATEWAY, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, l2tpUserName, [MAX_NAME_LEN_LONG], L2TP_USER_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, l2tpPassword, [MAX_NAME_LEN_LONG], L2TP_PASSWORD, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, l2tpMtuSize, , L2TP_MTU_SIZE, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, l2tpIdleTime, , L2TP_IDLE_TIME, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, l2tpConnectType, , L2TP_CONNECTION_TYPE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, L2tpwanIPMode, , L2TP_WAN_IP_DYNAMIC, BYTE_T, APMIB_T, 0, 0)
/* USB3G */
MIBDEF(unsigned char, usb3g_user, [32], USB3G_USER, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, usb3g_pass, [32], USB3G_PASS, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, usb3g_pin, [5], USB3G_PIN, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, usb3g_apn, [20], USB3G_APN, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, usb3g_dialnum, [12], USB3G_DIALNUM, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, usb3g_connType, [5], USB3G_CONN_TYPE, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, usb3g_idleTime, [5] , USB3G_IDLE_TIME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, usb3g_mtuSize, [5], USB3G_MTU_SIZE, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpEnabled, , NTP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, daylightsaveEnabled, , DAYLIGHT_SAVE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpServerId, , NTP_SERVER_ID, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpTimeZone, [8], NTP_TIMEZONE, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpServerIp1, [4], NTP_SERVER_IP1, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ntpServerIp2, [4], NTP_SERVER_IP2, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ddnsEnabled, , DDNS_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ddnsType, , DDNS_TYPE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ddnsDomainName, [MAX_DOMAIN_LEN], DDNS_DOMAIN_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ddnsUser, [MAX_DOMAIN_LEN], DDNS_USER, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ddnsPassword, [MAX_NAME_LEN], DDNS_PASSWORD, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, fixedIpMtuSize, , FIXED_IP_MTU_SIZE, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, dhcpMtuSize, , DHCP_MTU_SIZE, WORD_T, APMIB_T, 0, 0)
#endif // HOME_GATEWAY
MIBDEF(unsigned char, opMode, , OP_MODE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, wispWanId, , WISP_WAN_ID, BYTE_T, APMIB_T, 0, 0)
#ifdef HOME_GATEWAY
MIBDEF(unsigned char, wanAccessEnabled, , WEB_WAN_ACCESS_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pingAccessEnabled, , PING_WAN_ACCESS_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, hostName, [MAX_NAME_LEN], HOST_NAME, STRING_T, APMIB_T, 0, 0)
#endif // #ifdef HOME_GATEWAY
MIBDEF(unsigned char, rtLogEnabled, , REMOTELOG_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, rtLogServer, [4], REMOTELOG_SERVER, IA_T, APMIB_T, 0, 0)
#ifdef UNIVERSAL_REPEATER
// for wlan0 interface
MIBDEF(unsigned char, repeaterEnabled1, , REPEATER_ENABLED1, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, repeaterSSID1, [MAX_SSID_LEN], REPEATER_SSID1, STRING_T, APMIB_T, 0, 0)
// for wlan1 interface
MIBDEF(unsigned char, repeaterEnabled2, , REPEATER_ENABLED2, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, repeaterSSID2, [MAX_SSID_LEN], REPEATER_SSID2, STRING_T, APMIB_T, 0, 0)
#endif // #ifdef UNIVERSAL_REPEATER
MIBDEF(unsigned char, wifiSpecific, , WIFI_SPECIFIC, BYTE_T, APMIB_T, 0, 0)
#ifdef HOME_GATEWAY
MIBDEF(unsigned char, pppServiceName, [41], PPP_SERVICE_NAME, STRING_T, APMIB_T, 0, 0)
#ifdef DOS_SUPPORT
MIBDEF(unsigned long, dosEnabled, , DOS_ENABLED, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, syssynFlood, , DOS_SYSSYN_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, sysfinFlood, , DOS_SYSFIN_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, sysudpFlood, , DOS_SYSUDP_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, sysicmpFlood, , DOS_SYSICMP_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pipsynFlood, , DOS_PIPSYN_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pipfinFlood, , DOS_PIPFIN_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pipudpFlood, , DOS_PIPUDP_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pipicmpFlood, , DOS_PIPICMP_FLOOD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, blockTime, , DOS_BLOCK_TIME, WORD_T, APMIB_T, 0, 0)
#endif // #ifdef DOS_SUPPORT
MIBDEF(unsigned char, vpnPassthruIPsecEnabled, , VPN_PASSTHRU_IPSEC_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, vpnPassthruPPTPEnabled, , VPN_PASSTHRU_PPTP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, vpnPassthruL2TPEnabled, , VPN_PASSTHRU_L2TP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cusPassThru, , CUSTOM_PASSTHRU_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpSecurityEnabled, , PPTP_SECURITY_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, igmpproxyDisabled, , IGMP_PROXY_DISABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpMppcEnabled, , PPTP_MPPC_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, pptpIdleTime, , PPTP_IDLE_TIME, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pptpConnectType, , PPTP_CONNECTION_TYPE, BYTE_T, APMIB_T, 0, 0)
#endif // #ifdef HOME_GATEWAY
MIBDEF(unsigned char, mibVer, , MIB_VER, BYTE_T, APMIB_T, 0, 0)
// added by rock /////////////////////////////////////////
#ifdef VOIP_SUPPORT
MIBDEF(voipCfgParam_t, voipCfgParam, , VOIP_CFG, VOIP_T, APMIB_T, 0, 0)
#endif
MIBDEF(unsigned char, startMp, , START_MP, BYTE_T, APMIB_T, 0, 0)
#ifdef HOME_GATEWAY
#ifdef CONFIG_IPV6
MIBDEF(radvdCfgParam_t, radvdCfgParam, , IPV6_RADVD_PARAM, RADVDPREFIX_T, APMIB_T, 0, 0)
MIBDEF(dnsv6CfgParam_t, dnsCfgParam, , IPV6_DNSV6_PARAM, DNSV6_T, APMIB_T, 0, 0)
MIBDEF(dhcp6sCfgParam_t, dhcp6sCfgParam, , IPV6_DHCPV6S_PARAM, DHCPV6S_T, APMIB_T, 0, 0)
MIBDEF(addrIPv6CfgParam_t, addrIPv6CfgParam, , IPV6_ADDR_PARAM, ADDR6_T, APMIB_T, 0, 0)
MIBDEF(tunnelCfgParam_t, tunnelCfgParam, , IPV6_TUNNEL_PARAM, TUNNEL6_T, APMIB_T, 0, 0)
#endif /* #ifdef CONFIG_IPV6*/
#endif
#ifdef CONFIG_RTL_BT_CLIENT
MIBDEF(unsigned char, uploadDir, [64] , BT_UPLOAD_DIR, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, downloadDir, [64] , BT_DOWNLOAD_DIR, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, uLimit, , BT_TOTAL_ULIMIT, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, dLimit, , BT_TOTAL_DLIMIT, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, refreshTime, , BT_REFRESH_TIME, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, bt_enabled, , BT_ENABLED, BYTE_T, APMIB_T, 0, 0)
#endif
/*+++++added by Jack for Tr-069 configuration+++++*/
#ifdef CONFIG_CWMP_TR069
MIBDEF(unsigned char, cwmp_onoff, , CWMP_ID, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ProvisioningCode, [CWMP_PROVISION_CODE_LEN], CWMP_PROVISIONINGCODE, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ACSURL, [CWMP_ACS_URL_LEN], CWMP_ACS_URL, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ACSUserName, [CWMP_ACS_USERNAME_LEN], CWMP_ACS_USERNAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ACSPassword, [CWMP_ACS_PASSWD_LEN], CWMP_ACS_PASSWORD, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_InformEnable, , CWMP_INFORM_ENABLE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, cwmp_InformInterval, , CWMP_INFORM_INTERVAL, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, cwmp_InformTime, , CWMP_INFORM_TIME, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ConnReqUserName, [CWMP_CONREQ_USERNAME_LEN], CWMP_CONREQ_USERNAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ConnReqPassword, [CWMP_CONREQ_PASSWD_LEN], CWMP_CONREQ_PASSWORD, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_UpgradesManaged, , CWMP_ACS_UPGRADESMANAGED, BYTE_T, APMIB_T, 0, 0)
#if 0
MIBDEF(unsigned char, cwmp_LANConfPassword, [CWMP_LANCONF_PASSWD_LEN], CWMP_LAN_CONFIGPASSWD, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_SerialNumber, [CWMP_SERIALNUMBER_LEN], CWMP_SERIALNUMBER, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_DHCP_ServerConf, , CWMP_DHCP_SERVERCONF, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_LAN_IPIFEnable, , CWMP_LAN_IPIFENABLE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_LAN_EthIFEnable, , CWMP_LAN_ETHIFENABLE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_WLAN_BasicEncry, , CWMP_WLAN_BASICENCRY, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_WLAN_WPAEncry, , CWMP_WLAN_WPAENCRY, BYTE_T, APMIB_T, 0, 0)
#endif
MIBDEF(unsigned char, cwmp_DL_CommandKey, [CWMP_COMMAND_KEY_LEN+1], CWMP_DL_COMMANDKEY, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, cwmp_DL_StartTime, , CWMP_DL_STARTTIME, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, cwmp_DL_CompleteTime, , CWMP_DL_COMPLETETIME, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, cwmp_DL_FaultCode, , CWMP_DL_FAULTCODE, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, cwmp_Inform_EventCode, , CWMP_INFORM_EVENTCODE, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_RB_CommandKey, [CWMP_COMMAND_KEY_LEN+1], CWMP_RB_COMMANDKEY, STRING_T, APMIB_T, 0, 0)
//MIBDEF(unsigned char, cwmp_ACS_ParameterKey, [CWMP_COMMAND_KEY_LEN+1], CWMP_ACS_PARAMETERKEY, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_CERT_Password, [CWMP_CERT_PASSWD_LEN+1], CWMP_CERT_PASSWORD, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_Flag, , CWMP_FLAG, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_SI_CommandKey, [CWMP_COMMAND_KEY_LEN+1], CWMP_SI_COMMANDKEY, STRING_T, APMIB_T, 0, 0)
#ifdef _PRMT_USERINTERFACE_
MIBDEF(unsigned char, UIF_PW_Required, , UIF_PW_REQUIRED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, UIF_PW_User_Sel, , UIF_PW_USER_SEL, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, UIF_Upgrade, , UIF_UPGRADE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, UIF_WarrantyDate, , UIF_WARRANTYDATE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, UIF_AutoUpdateServer, [256], UIF_AUTOUPDATESERVER, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, UIF_UserUpdateServer, [256], UIF_USERUPDATESERVER, BYTE_T, APMIB_T, 0, 0)
#endif // #ifdef _PRMT_USERINTERFACE_
MIBDEF(unsigned char, cwmp_ACS_KickURL, [CWMP_KICK_URL], CWMP_ACS_KICKURL, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ACS_DownloadURL, [CWMP_DOWNLOAD_URL], CWMP_ACS_DOWNLOADURL, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned int, cwmp_ConnReqPort, , CWMP_CONREQ_PORT, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_ConnReqPath, [CONN_REQ_PATH_LEN], CWMP_CONREQ_PATH, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, cwmp_Flag2, , CWMP_FLAG2, BYTE_T, APMIB_T, 0, 0)
#ifdef _PRMT_TR143_
MIBDEF(unsigned char, tr143_udpecho_enable, , TR143_UDPECHO_ENABLE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, tr143_udpecho_itftype, , TR143_UDPECHO_ITFTYPE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, tr143_udpecho_srcip, [4], TR143_UDPECHO_SRCIP, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, tr143_udpecho_port, , TR143_UDPECHO_PORT, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, tr143_udpecho_plus, , TR143_UDPECHO_PLUS, BYTE_T, APMIB_T, 0, 0)
#endif // #ifdef _PRMT_TR143_
#endif // #ifdef CONFIG_CWMP_TR069
// SNMP, Forrest added, 2007.10.25.
#ifdef CONFIG_SNMP
MIBDEF(unsigned char, snmpEnabled, , SNMP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpName, [MAX_SNMP_NAME_LEN], SNMP_NAME, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpLocation, [MAX_SNMP_LOCATION_LEN], SNMP_LOCATION, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpContact, [MAX_SNMP_CONTACT_LEN], SNMP_CONTACT, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpRWCommunity, [MAX_SNMP_COMMUNITY_LEN], SNMP_RWCOMMUNITY, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpROCommunity, [MAX_SNMP_COMMUNITY_LEN], SNMP_ROCOMMUNITY, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpTrapReceiver1, [4], SNMP_TRAP_RECEIVER1, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpTrapReceiver2, [4], SNMP_TRAP_RECEIVER2, IA_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpTrapReceiver3, [4], SNMP_TRAP_RECEIVER3, IA_T, APMIB_T, 0, 0)
#endif // #ifdef CONFIG_SNMP
MIBDEF(unsigned short, system_time_year, , SYSTIME_YEAR, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, system_time_month, , SYSTIME_MON, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, system_time_day, , SYSTIME_DAY, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, system_time_hour, , SYSTIME_HOUR, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, system_time_min, , SYSTIME_MIN, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, system_time_sec, , SYSTIME_SEC, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, wlan11nOnOffTKIP, , WLAN_11N_ONOFF_TKIP, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dhcpRsvdIpEnabled, , DHCPRSVDIP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, dhcpRsvdIpNum, , DHCPRSVDIP_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(DHCPRSVDIP_T, dhcpRsvdIpArray, [MAX_DHCP_RSVD_IP_NUM], DHCPRSVDIP_TBL, DHCPRSVDIP_ARRY_T, APMIB_T, 0, mib_dhcpRsvdIp_tbl)
#if defined(CONFIG_RTL_8198_AP_ROOT)
MIBDEF(unsigned char, VlanConfigEnabled, , VLANCONFIG_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, VlanConfigNum, , VLANCONFIG_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
#if defined(VLAN_CONFIG_SUPPORTED)
MIBDEF(VLAN_CONFIG_T, VlanConfigArray, [MAX_IFACE_VLAN_CONFIG], VLANCONFIG_TBL, VLANCONFIG_ARRAY_T, APMIB_T, 0, mib_vlanconfig_tbl)
#endif
#endif
#ifdef HOME_GATEWAY
MIBDEF(unsigned char, portFwEnabled, , PORTFW_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, portFwNum, , PORTFW_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(PORTFW_T, portFwArray, [MAX_FILTER_NUM], PORTFW_TBL, PORTFW_ARRAY_T, APMIB_T, 0, mib_portfw_tbl)
MIBDEF(unsigned char, ipFilterEnabled, , IPFILTER_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ipFilterNum, , IPFILTER_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(IPFILTER_T, ipFilterArray, [MAX_FILTER_NUM], IPFILTER_TBL, IPFILTER_ARRAY_T, APMIB_T, 0, mib_ipfilter_tbl)
MIBDEF(unsigned char, portFilterEnabled, , PORTFILTER_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, portFilterNum, , PORTFILTER_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(PORTFILTER_T, portFilterArray, [MAX_FILTER_NUM], PORTFILTER_TBL, PORTFILTER_ARRAY_T, APMIB_T, 0, mib_portfilter_tbl)
MIBDEF(unsigned char, macFilterEnabled, , MACFILTER_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, macFilterNum, , MACFILTER_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(MACFILTER_T, macFilterArray, [MAX_FILTER_NUM], MACFILTER_TBL, MACFILTER_ARRAY_T, APMIB_T, 0, mib_macfilter_tbl)
MIBDEF(unsigned char, triggerPortEnabled, , TRIGGERPORT_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, triggerPortNum, , TRIGGERPORT_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(TRIGGERPORT_T, triggerPortArray, [MAX_FILTER_NUM], TRIGGERPORT_TBL, TRIGGERPORT_ARRAY_T, APMIB_T, 0, mib_triggerport_tbl)
MIBDEF(unsigned char, urlFilterEnabled, , URLFILTER_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, urlFilterNum, , URLFILTER_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(URLFILTER_T, urlFilterArray, [MAX_URLFILTER_NUM], URLFILTER_TBL, URLFILTER_ARRAY_T, APMIB_T, 0, mib_urlfilter_tbl)
MIBDEF(unsigned char, VlanConfigEnabled, , VLANCONFIG_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, VlanConfigNum, , VLANCONFIG_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
#if defined(VLAN_CONFIG_SUPPORTED)
MIBDEF(VLAN_CONFIG_T, VlanConfigArray, [MAX_IFACE_VLAN_CONFIG], VLANCONFIG_TBL, VLANCONFIG_ARRAY_T, APMIB_T, 0, mib_vlanconfig_tbl)
#endif
#ifdef ROUTE_SUPPORT
MIBDEF(unsigned char, staticRouteEnabled, , STATICROUTE_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, staticRouteNum, , STATICROUTE_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(STATICROUTE_T, staticRouteArray, [MAX_ROUTE_NUM], STATICROUTE_TBL, STATICROUTE_ARRAY_T, APMIB_T, 0, mib_staticroute_tbl)
MIBDEF(unsigned char, ripEnabled, , RIP_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ripLanTx, , RIP_LAN_TX, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ripLanRx, , RIP_LAN_RX, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ripWanTx, , RIP_WAN_TX, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ripWanRx, , RIP_WAN_RX, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, natEnabled, , NAT_ENABLED, BYTE_T, APMIB_T, 0, 0)
#endif // #ifdef ROUTE_SUPPORT
MIBDEF(unsigned char, sambaEnabled, , SAMBA_ENABLED, BYTE_T, APMIB_T, 0, 0)
#ifdef VPN_SUPPORT
MIBDEF(unsigned char, ipsecTunnelEnabled, , IPSECTUNNEL_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ipsecTunnelNum, , IPSECTUNNEL_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(IPSECTUNNEL_T, ipsecTunnelArray, [MAX_TUNNEL_NUM], IPSECTUNNEL_TBL, IPSECTUNNEL_ARRAY_T, APMIB_T, 0, mib_ipsectunnel_tbl)
MIBDEF(unsigned char, ipsecNattEnabled, , IPSEC_NATT_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, ipsecRsaKeyFile, [MAX_RSA_FILE_LEN], IPSEC_RSA_FILE, BYTE_ARRAY_T, APMIB_T, 0, 0)
#endif // #ifdef VPN_SUPPORT
MIBDEF(unsigned short, pppSessionNum, , PPP_SESSION_NUM, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, pppServerMac, [6], PPP_SERVER_MAC, BYTE6_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, l2tpPayload, [MAX_L2TP_BUFF_LEN], L2TP_PAYLOAD, BYTE_ARRAY_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, l2tpPayloadLength, , L2TP_PAYLOAD_LENGTH, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, l2tpNs, , L2TP_NS, WORD_T, APMIB_T, 0, 0)
#endif // #ifdef HOME_GATEWAY
#ifdef TLS_CLIENT
MIBDEF(unsigned char, certRootNum, , CERTROOT_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(CERTROOT_T, certRootArray, [MAX_CERTROOT_NUM], CERTROOT_TBL, CERTROOT_ARRAY_T, APMIB_T, 0, mib_certroot_tbl)
MIBDEF(unsigned char, certUserNum, , CERTUSER_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
MIBDEF(CERTUSER_T, certUserArray, [MAX_CERTUSER_NUM], CERTUSER_TBL, CERTUSER_ARRAY_T, APMIB_T, 0, mib_certuser_tbl)
MIBDEF(unsigned char, rootIdx, , ROOT_IDX, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, userIdx, , USER_IDX, BYTE_T, APMIB_T, 0, 0)
#endif // #ifdef TLS_CLIENT
#if defined(GW_QOS_ENGINE) || defined(QOS_BY_BANDWIDTH)
MIBDEF(unsigned char, qosEnabled, , QOS_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, qosAutoUplinkSpeed, , QOS_AUTO_UPLINK_SPEED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned long, qosManualUplinkSpeed, , QOS_MANUAL_UPLINK_SPEED, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, qosAutoDownLinkSpeed, , QOS_AUTO_DOWNLINK_SPEED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned long, qosManualDownLinkSpeed, , QOS_MANUAL_DOWNLINK_SPEED, DWORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, qosRuleNum, , QOS_RULE_TBL_NUM, BYTE_T, APMIB_T, 0, 0)
#endif // #if defined(GW_QOS_ENGINE) || defined(QOS_BY_BANDWIDTH)
#if defined(GW_QOS_ENGINE)
MIBDEF(QOS_T, qosRuleArray, [MAX_QOS_RULE_NUM], QOS_RULE_TBL, QOS_ARRAY_T, APMIB_T, 0, mib_qos_tbl)
#endif // #if defined(GW_QOS_ENGINE)
#if defined(QOS_BY_BANDWIDTH)
MIBDEF(IPQOS_T, qosRuleArray, [MAX_QOS_RULE_NUM], QOS_RULE_TBL, QOS_ARRAY_T, APMIB_T, 0, mib_qos_tbl)
#endif // #if defined(GW_QOS_ENGINE)
//=========add for MESH=========
MIBDEF(unsigned char, meshEnabled, , MESH_ENABLE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshRootEnabled, , MESH_ROOT_ENABLE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshID, [33], MESH_ID, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshMaxNumOfNeighbors, , MESH_MAX_NEIGHTBOR, WORD_T, APMIB_T, 0, 0)
// for backbone security
MIBDEF(unsigned char, meshEncrypt, , MESH_ENCRYPT, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshWpaPSKFormat, , MESH_PSK_FORMAT, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshWpaPSK, [MAX_PSK_LEN+1], MESH_WPA_PSK, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshWpaAuth, , MESH_WPA_AUTH, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshWpa2Cipher, , MESH_WPA2_CIPHER_SUITE, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshAclEnabled, , MESH_ACL_ENABLED, BYTE_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshAclNum, , MESH_ACL_NUM, BYTE_T, APMIB_T, 0, 0)
//#if defined(CONFIG_RTK_MESH) && defined(_MESH_ACL_ENABLE_) // below code copy above ACL code
MIBDEF(MACFILTER_T, meshAclAddrArray, [MAX_MESH_ACL_NUM], MESH_ACL_ADDR, MESH_ACL_ARRAY_T, APMIB_T, 0, mib_mech_acl_tbl)
//#endif
#ifdef _11s_TEST_MODE_
MIBDEF(unsigned short, meshTestParam1, , MESH_TEST_PARAM1, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam2, , MESH_TEST_PARAM2, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam3, , MESH_TEST_PARAM3, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam4, , MESH_TEST_PARAM4, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam5, , MESH_TEST_PARAM5, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam6, , MESH_TEST_PARAM6, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam7, , MESH_TEST_PARAM7, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam8, , MESH_TEST_PARAM8, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParam9, , MESH_TEST_PARAM9, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParama, , MESH_TEST_PARAMA, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParamb, , MESH_TEST_PARAMB, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParamc, , MESH_TEST_PARAMC WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParamd, , MESH_TEST_PARAMD, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParame, , MESH_TEST_PARAME WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned short, meshTestParamf, , MESH_TEST_PARAMF, WORD_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, meshTestParamStr1, [16], MESH_TEST_PARAMSTR1, STRING_T, APMIB_T, 0, 0)
#endif // #ifdef _11s_TEST_MODE_
MIBDEF(unsigned char, snmpROcommunity, [MAX_SNMP_COMMUNITY_LEN], SNMP_RO_COMMUNITY, STRING_T, APMIB_T, 0, 0)
MIBDEF(unsigned char, snmpRWcommunity, [MAX_SNMP_COMMUNITY_LEN], SNMP_RW_COMMUNITY, STRING_T, APMIB_T, 0, 0)
MIBDEF(CONFIG_WLAN_SETTING_T, wlan, [NUM_WLAN_INTERFACE][NUM_VWLAN_INTERFACE+1], WLAN_ROOT, TABLE_LIST_T, APMIB_T, 0, mib_wlan_table)
//#ifdef CONFIG_RTL_FLASH_DUAL_IMAGE_ENABLE
MIBDEF(unsigned char, dualBankEnabled, , DUALBANK_ENABLED, BYTE_T, APMIB_T, 0, 0) //default test
MIBDEF(unsigned char, wlanBand2G5GSelect, , WLAN_BAND2G5G_SELECT, BYTE_T, APMIB_T, 0, 0)
#endif // #ifdef MIB_IMPORT
#ifdef MIB_DHCPRSVDIP_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, ipAddr, [4], DHCPRSVDIP_IPADDR, IA_T, DHCPRSVDIP_T, 0, 0)
MIBDEF(unsigned char, macAddr, [6], DHCPRSVDIP_MACADDR, BYTE6_T, DHCPRSVDIP_T, 0, 0)
MIBDEF(unsigned char, hostName, [32], DHCPRSVDIP_HOSTNAME, STRING_T, DHCPRSVDIP_T, 0, 0)
#endif // #ifdef MIB_DHCPRSVDIP_IMPORT
#ifdef MIB_SCHEDULE_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, text, [SCHEDULE_NAME_LEN], SCHEDULE_TEXT, STRING_T, SCHEDULE_T, 0, 0)
MIBDEF(unsigned short, eco, , SCHEDULE_ECO, WORD_T, SCHEDULE_T, 0, 0)
MIBDEF(unsigned short, fTime, , SCHEDULE_FTIME, WORD_T, SCHEDULE_T, 0, 0)
MIBDEF(unsigned short, tTime, , SCHEDULE_TTIME, WORD_T, SCHEDULE_T, 0, 0)
MIBDEF(unsigned short, day, , SCHEDULE_DAY, WORD_T, SCHEDULE_T, 0, 0)
#endif // #ifdef MIB_SCHEDULE_IMPORT
#ifdef MIB_MACFILTER_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, macAddr, [6], MACFILTER_MACADDR, BYTE6_T, MACFILTER_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], MACFILTER_COMMENT, STRING_T, MACFILTER_T, 0, 0)
#endif // #ifdef MIB_MACFILTER_IMPORT
#if defined(CONFIG_RTL_8198_AP_ROOT)
#ifdef MIB_VLAN_CONFIG_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, enabled, , VLANCONFIG_ENTRY_ENABLED, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, netIface, [IFNAMSIZE], VLANCONFIG_NETIFACE, STRING_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, tagged, , VLANCONFIG_TAGGED, BYTE_T, VLAN_CONFIG_T, 0, 0)
//MIBDEF(unsigned char, untagged, , VLANCONFIG_UNTAGGED, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, priority, , VLANCONFIG_PRIORITY, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, cfi, , VLANCONFIG_CFI, BYTE_T, VLAN_CONFIG_T, 0, 0)
//MIBDEF(unsigned char, groupId, , VLANCONFIG_GROUPID, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned short, vlanId, , VLANCONFIG_VLANID, WORD_T, VLAN_CONFIG_T, 0, 0)
#if defined(CONFIG_RTK_VLAN_NEW_FEATURE)
MIBDEF(unsigned char, forwarding_rule, , VLANCONFIG_FORWARDING_RULE, BYTE_T, VLAN_CONFIG_T, 0, 0)
#endif
#endif // #ifdef MIB_VLAN_CONFIG_IMPORT
#endif
#ifdef HOME_GATEWAY
#ifdef MIB_PORTFW_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, ipAddr, [4], PORTFW_IPADDR, IA_T, PORTFW_T, 0, 0)
MIBDEF(unsigned short, fromPort, , PORTFW_FROMPORT, WORD_T, PORTFW_T, 0, 0)
MIBDEF(unsigned short, toPort, , PORTFW_TOPORT, WORD_T, PORTFW_T, 0, 0)
MIBDEF(unsigned char, protoType, , PORTFW_PROTOTYPE, BYTE_T, PORTFW_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], PORTFW_COMMENT, STRING_T, PORTFW_T, 0, 0)
#endif // #ifdef MIB_PORTFW_IMPORT
#ifdef MIB_IPFILTER_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, ipAddr, [4], IPFILTER_IPADDR, IA_T, IPFILTER_T, 0, 0)
MIBDEF(unsigned char, protoType, , IPFILTER_PROTOTYPE, BYTE_T, IPFILTER_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], IPFILTER_COMMENT, STRING_T, IPFILTER_T, 0, 0)
#endif // #ifdef MIB_IPFILTER_IMPORT
#ifdef MIB_PORTFILTER_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned short, fromPort, , PORTFILTER_FROMPORT, WORD_T, PORTFILTER_T, 0, 0)
MIBDEF(unsigned short, toPort, , PORTFILTER_TOPORT, WORD_T, PORTFILTER_T, 0, 0)
MIBDEF(unsigned char, protoType, , PORTFILTER_PROTOTYPE, BYTE_T, PORTFILTER_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], PORTFILTER_COMMENT, STRING_T, PORTFILTER_T, 0, 0)
#endif // #ifdef MIB_PORTFILTER_IMPORT
#ifdef MIB_TRIGGERPORT_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned short, tri_fromPort, , TRIGGERPORT_TRI_FROMPORT, WORD_T, TRIGGERPORT_T, 0, 0)
MIBDEF(unsigned short, tri_toPort, , TRIGGERPORT_TRI_TOPORT, WORD_T, TRIGGERPORT_T, 0, 0)
MIBDEF(unsigned char, tri_protoType, , TRIGGERPORT_TRI_PROTOTYPE, BYTE_T, TRIGGERPORT_T, 0, 0)
MIBDEF(unsigned short, inc_fromPort, , TRIGGERPORT_INC_FROMPORT, WORD_T, TRIGGERPORT_T, 0, 0)
MIBDEF(unsigned short, inc_toPort, , TRIGGERPORT_INC_TOPORT, WORD_T, TRIGGERPORT_T, 0, 0)
MIBDEF(unsigned char, inc_protoType, , TRIGGERPORT_INC_PROTOTYPE, BYTE_T, TRIGGERPORT_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], TRIGGERPORT_COMMENT, STRING_T, TRIGGERPORT_T, 0, 0)
#endif // #ifdef MIB_TRIGGERPORT_IMPORT
#ifdef MIB_URLFILTER_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, urlAddr, [31], URLFILTER_URLADDR, STRING_T, URLFILTER_T, 0, 0)
#endif // #ifdef MIB_URLFILTER_IMPORT
#ifdef MIB_VLAN_CONFIG_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, enabled, , VLANCONFIG_ENTRY_ENABLED, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, netIface, [IFNAMSIZE], VLANCONFIG_NETIFACE, STRING_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, tagged, , VLANCONFIG_TAGGED, BYTE_T, VLAN_CONFIG_T, 0, 0)
//MIBDEF(unsigned char, untagged, , VLANCONFIG_UNTAGGED, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, priority, , VLANCONFIG_PRIORITY, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned char, cfi, , VLANCONFIG_CFI, BYTE_T, VLAN_CONFIG_T, 0, 0)
//MIBDEF(unsigned char, groupId, , VLANCONFIG_GROUPID, BYTE_T, VLAN_CONFIG_T, 0, 0)
MIBDEF(unsigned short, vlanId, , VLANCONFIG_VLANID, WORD_T, VLAN_CONFIG_T, 0, 0)
#if defined(CONFIG_RTK_VLAN_NEW_FEATURE)
MIBDEF(unsigned char, forwarding_rule, , VLANCONFIG_FORWARDING_RULE, BYTE_T, VLAN_CONFIG_T, 0, 0)
#endif
#endif // #ifdef MIB_VLAN_CONFIG_IMPORT
#ifdef ROUTE_SUPPORT
#ifdef MIB_STATICROUTE_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, dstAddr, [4], STATICROUTE_DSTADDR, IA_T, STATICROUTE_T, 0, 0)
MIBDEF(unsigned char, netmask, [4], STATICROUTE_NETMASK, IA_T, STATICROUTE_T, 0, 0)
MIBDEF(unsigned char, gateway, [4], STATICROUTE_GATEWAY, IA_T, STATICROUTE_T, 0, 0)
MIBDEF(unsigned char, interface, , STATICROUTE_INTERFACE, BYTE_T, STATICROUTE_T, 0, 0)
MIBDEF(unsigned char, metric, , STATICROUTE_METRIC, BYTE_T, STATICROUTE_T, 0, 0)
#endif // #ifdef MIB_STATICROUTE_IMPORT
#endif // #ifdef ROUTE_SUPPORT
#ifdef VPN_SUPPORT
#ifdef MIB_IPSECTUNNEL_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, tunnelId, , IPSECTUNNEL_TUNNELID, IA_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, authType, , IPSECTUNNEL_AUTHTYPE, IA_T, IPSECTUNNEL_T, 0, 0)
//local info
MIBDEF(unsigned char, lcType, , IPSECTUNNEL_LCTYPE, IA_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, lc_ipAddr, [4], IPSECTUNNEL_LC_IPADDR, IA_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, lc_maskLen, , IPSECTUNNEL_LC_MASKLEN, BYTE_T, IPSECTUNNEL_T, 0, 0)
//remote Info
MIBDEF(unsigned char, rtType, , IPSECTUNNEL_RTTYPE, IA_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, rt_ipAddr, [4], IPSECTUNNEL_RT_IPADDR, IA_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, rt_maskLen, , IPSECTUNNEL_RT_MASKLEN, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, rt_gwAddr, [4], IPSECTUNNEL_RT_GWADDR, IA_T, IPSECTUNNEL_T, 0, 0)
// Key mode common
MIBDEF(unsigned char, keyMode, , IPSECTUNNEL_KEYMODE, BYTE_T, IPSECTUNNEL_T, 0, 0)
//MIBDEF(unsigned char, espAh, , IPSECTUNNEL_ESPAH, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, espEncr, , IPSECTUNNEL_ESPENCR, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, espAuth, , IPSECTUNNEL_ESPAUTH, BYTE_T, IPSECTUNNEL_T, 0, 0)
//MIBDEF(unsigned char, ahAuth, , IPSECTUNNEL_AHAUTH, BYTE_T, IPSECTUNNEL_T, 0, 0)
//IKE mode
MIBDEF(unsigned char, conType, , IPSECTUNNEL_CONTYPE, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, psKey, [MAX_NAME_LEN], IPSECTUNNEL_PSKEY, STRING_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, rsaKey, [MAX_RSA_KEY_LEN], IPSECTUNNEL_RSAKEY, STRING_T, IPSECTUNNEL_T, 0, 0)
//Manual Mode
MIBDEF(unsigned char, spi, [MAX_SPI_LEN], IPSECTUNNEL_SPI, STRING_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, encrKey, [MAX_ENCRKEY_LEN], IPSECTUNNEL_ENCRKEY, STRING_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, authKey, [MAX_AUTHKEY_LEN], IPSECTUNNEL_AUTHKEY, STRING_T, IPSECTUNNEL_T, 0, 0)
// tunnel info
MIBDEF(unsigned char, enable, , IPSECTUNNEL_ENABLE, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, connName, [MAX_NAME_LEN], IPSECTUNNEL_CONNNAME, STRING_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, lcIdType, , IPSECTUNNEL_LCIDTYPE, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, rtIdType, , IPSECTUNNEL_LCIDTYPE, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, lcId, [MAX_NAME_LEN], IPSECTUNNEL_LCID, STRING_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, rtId, [MAX_NAME_LEN], IPSECTUNNEL_RTID, STRING_T, IPSECTUNNEL_T, 0, 0)
// ike Advanced setup
MIBDEF(unsigned long, ikeLifeTime, , IPSECTUNNEL_IKELIFETIME, DWORD_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, ikeEncr, , IPSECTUNNEL_IKEENCR, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, ikeAuth, , IPSECTUNNEL_IKEAUTH, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, ikeKeyGroup, , IPSECTUNNEL_IKEKEYGROUP, BYTE_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned long, ipsecLifeTime, , IPSECTUNNEL_IPSECLIFETIME, DWORD_T, IPSECTUNNEL_T, 0, 0)
MIBDEF(unsigned char, ipsecPfs, , IPSECTUNNEL_IPSECPFS, BYTE_T, IPSECTUNNEL_T, 0, 0)
#endif // #ifdef MIB_IPSECTUNNEL_IMPORT
#endif //#ifdef VPN_SUPPORT
#endif // #ifdef HOME_GATEWAY
#ifdef TLS_CLIENT
#ifdef MIB_CERTROOT_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, comment, [COMMENT_LEN], CERTROOT_COMMENT, STRING_T, CERTROOT_T, 0, 0)
#endif // #ifdef MIB_CERTROOT_IMPORT
#ifdef MIB_CERTUSER_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, comment, [COMMENT_LEN], CERTUSER_COMMENT, STRING_T, CERTUSER_T, 0, 0)
MIBDEF(unsigned char, pass, [MAX_RS_PASS_LEN], CERTROOT_PASS, STRING_T, CERTUSER_T, 0, 0)
#endif // #ifdef MIB_CERTUSER_IMPORT
#endif //#ifdef TLS_CLIENT
#if defined(GW_QOS_ENGINE)
#ifdef MIB_QOS_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, entry_name, [MAX_QOS_NAME_LEN+1], QOS_ENTRY_NAME, STRING_T, QOS_T, 0, 0)
MIBDEF(unsigned char, enabled, , QOS_ENTRY_ENABLED, STRING_T, QOS_T, 0, 0)
MIBDEF(unsigned char, priority, , QOS_PRIORITY, STRING_T, QOS_T, 0, 0)
MIBDEF(unsigned short, protocol, , QOS_PROTOCOL, WORD_T, QOS_T, 0, 0)
MIBDEF(unsigned char, local_ip_start, [4], QOS_LOCAL_IP_START, IA_T, QOS_T, 0, 0)
MIBDEF(unsigned char, local_ip_end, [4], QOS_LOCAL_IP_END, IA_T, QOS_T, 0, 0)
MIBDEF(unsigned short, local_port_start, , QOS_LOCAL_PORT_START, WORD_T, QOS_T, 0, 0)
MIBDEF(unsigned short, local_port_end, , QOS_LOCAL_PORT_END, WORD_T, QOS_T, 0, 0)
MIBDEF(unsigned char, remote_ip_start, [4], QOS_REMOTE_IP_START, IA_T, QOS_T, 0, 0)
MIBDEF(unsigned char, remote_ip_end, [4], QOS_REMOTE_IP_END, IA_T, QOS_T, 0, 0)
MIBDEF(unsigned short, remote_port_start, , QOS_REMOTE_PORT_START, WORD_T, QOS_T, 0, 0)
MIBDEF(unsigned short, remote_port_send, , QOS_REMOTE_PORT_END, WORD_T, QOS_T, 0, 0)
#endif // #ifdef MIB_QOS_IMPORT
#endif // #if defined(GW_QOS_ENGINE)
#if defined(QOS_BY_BANDWIDTH)
#ifdef MIB_IPQOS_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, entry_name, [MAX_QOS_NAME_LEN+1], IPQOS_ENTRY_NAME, STRING_T, IPQOS_T, 0, 0)
MIBDEF(unsigned char, enabled, , IPQOS_ENABLED, BYTE_T, IPQOS_T, 0, 0)
MIBDEF(unsigned char, mac, [MAC_ADDR_LEN], IPQOS_MAC, BYTE6_T, IPQOS_T, 0, 0)
MIBDEF(unsigned char, mode, , IPQOS_MODE, BYTE_T, IPQOS_T, 0, 0)
MIBDEF(unsigned char, local_ip_start, [4], IPQOS_LOCAL_IP_START, IA_T, IPQOS_T, 0, 0)
MIBDEF(unsigned char, local_ip_end, [4], IPQOS_LOCAL_IP_END, IA_T, IPQOS_T, 0, 0)
MIBDEF(unsigned long, bandwidth, , IPQOS_BANDWIDTH, DWORD_T, IPQOS_T, 0, 0)
MIBDEF(unsigned long, bandwidth_downlink, , IPQOS_BANDWIDTH_DOWNLINK, DWORD_T, IPQOS_T, 0, 0)
#endif // #ifdef MIB_IPQOS_IMPORT
#endif // #if defined(QOS_BY_BANDWIDTH)
#ifdef MIB_MESH_MACFILTER_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, macAddr, [6], MECH_ACL_MACADDR, BYTE6_T, MACFILTER_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], MECH_ACL_COMMENT, STRING_T, MACFILTER_T, 0, 0)
#endif // #ifdef MIB_MESH_MACFILTER_IMPORT
#ifdef MIB_WLAN_MACFILTER_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, macAddr, [6], WLAN_ACL_ADDR_MACADDR, BYTE6_T, MACFILTER_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], WLAN_ACL_ADDR_COMMENT, STRING_T, MACFILTER_T, 0, 0)
#endif // #ifdef MIB_WLAN_MACFILTER_IMPORT
#ifdef MIB_WDS_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, macAddr, [6], WLAN_WDS_MACADDR, BYTE6_T, WDS_T, 0, 0)
MIBDEF(unsigned int, fixedTxRate, , WLAN_WDS_FIXEDTXRATE, DWORD_T, WDS_T, 0, 0)
MIBDEF(unsigned char, comment, [COMMENT_LEN], WLAN_WDS_COMMENT, STRING_T, WDS_T, 0, 0)
#endif // #ifdef MIB_WDS_IMPORT
#ifdef MIB_CONFIG_WLAN_SETTING_IMPORT
/* _ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl */
MIBDEF(unsigned char, ssid, [MAX_SSID_LEN], SSID, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, channel, , CHANNEL, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wlanMacAddr, [6], WLAN_MAC_ADDR, BYTE6_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep, , WEP, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
//MIBDEF(unsigned char, wep64Key, [WEP64_KEY_LEN], WEP64_KEY, BYTE5_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep64Key1, [WEP64_KEY_LEN], WEP64_KEY1, BYTE5_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep64Key2, [WEP64_KEY_LEN], WEP64_KEY2, BYTE5_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep64Key3, [WEP64_KEY_LEN], WEP64_KEY3, BYTE5_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep64Key4, [WEP64_KEY_LEN], WEP64_KEY4, BYTE5_T, CONFIG_WLAN_SETTING_T, 0, 0)
//MIBDEF(unsigned char, wep128Key, [WEP128_KEY_LEN], WEP128_KEY, BYTE13_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep128Key1, [WEP128_KEY_LEN], WEP128_KEY1, BYTE13_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep128Key2, [WEP128_KEY_LEN], WEP128_KEY2, BYTE13_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep128Key3, [WEP128_KEY_LEN], WEP128_KEY3, BYTE13_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wep128Key4, [WEP128_KEY_LEN], WEP128_KEY4, BYTE13_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wepDefaultKey, , WEP_DEFAULT_KEY, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wepKeyType, , WEP_KEY_TYPE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, fragThreshold, , FRAG_THRESHOLD, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, rtsThreshold, , RTS_THRESHOLD, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, supportedRates, , SUPPORTED_RATES, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, basicRates, , BASIC_RATES, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, beaconInterval, , BEACON_INTERVAL, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, preambleType, , PREAMBLE_TYPE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, authType, , AUTH_TYPE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, ackTimeout, , ACK_TIMEOUT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acEnabled, , MACAC_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acNum, , MACAC_NUM, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(MACFILTER_T, acAddrArray, [MAX_WLAN_AC_NUM], MACAC_ADDR, WLAC_ARRAY_T, CONFIG_WLAN_SETTING_T, 0, wlan_acl_addr_tbl)
MIBDEF(unsigned char, scheduleRuleEnabled, , SCHEDULE_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, scheduleRuleNum, , SCHEDULE_TBL_NUM, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(SCHEDULE_T, scheduleRuleArray, [MAX_SCHEDULE_NUM], SCHEDULE_TBL, SCHEDULE_ARRAY_T, CONFIG_WLAN_SETTING_T, 0, mib_schedule_tbl)
MIBDEF(unsigned char, hiddenSSID, , HIDDEN_SSID, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wlanDisabled, , WLAN_DISABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned long, inactivityTime, , INACTIVITY_TIME, DWORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rateAdaptiveEnabled, , RATE_ADAPTIVE_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, dtimPeriod, , DTIM_PERIOD, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wlanMode, , MODE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, networkType, , NETWORK_TYPE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, iappDisabled, , IAPP_DISABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, protectionDisabled, , PROTECTION_DISABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, defaultSsid, [MAX_SSID_LEN], DEFAULT_SSID, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, blockRelay, , BLOCK_RELAY, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, maccloneEnabled, , MACCLONE_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wlanBand, , BAND, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned int, fixedTxRate, , FIX_RATE, DWORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, turboMode, , TURBO_MODE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, RFPowerScale, , RFPOWER_SCALE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
// WPA stuffs
MIBDEF(unsigned char, encrypt, , ENCRYPT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, enableSuppNonWpa, , ENABLE_SUPP_NONWPA, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, suppNonWpa, , SUPP_NONWPA, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wpaAuth, , WPA_AUTH, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wpaCipher, , WPA_CIPHER_SUITE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wpaPSK, [MAX_PSK_LEN+1], WPA_PSK, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned long, wpaGroupRekeyTime, , WPA_GROUP_REKEY_TIME, DWORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rsIpAddr, [4], RS_IP, IA_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, rsPort, , RS_PORT, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rsPassword, [MAX_RS_PASS_LEN], RS_PASSWORD, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, enable1X, , ENABLE_1X, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wpaPSKFormat, , PSK_FORMAT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, accountRsEnabled, , ACCOUNT_RS_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, accountRsIpAddr, [4], ACCOUNT_RS_IP, IA_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, accountRsPort, , ACCOUNT_RS_PORT, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, accountRsPassword, [MAX_RS_PASS_LEN], ACCOUNT_RS_PASSWORD, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, accountRsUpdateEnabled, , ACCOUNT_RS_UPDATE_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, accountRsUpdateDelay, , ACCOUNT_RS_UPDATE_DELAY, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, macAuthEnabled, , MAC_AUTH_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rsMaxRetry, , RS_MAXRETRY, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, rsIntervalTime, , RS_INTERVAL_TIME, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, accountRsMaxRetry, , ACCOUNT_RS_MAXRETRY, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned short, accountRsIntervalTime, , ACCOUNT_RS_INTERVAL_TIME, WORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wpa2PreAuth, , WPA2_PRE_AUTH, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wpa2Cipher, , WPA2_CIPHER_SUITE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
// WDS stuffs
MIBDEF(unsigned char, wdsEnabled, , WDS_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wdsNum, , WDS_NUM, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(WDS_T, wdsArray, [MAX_WDS_NUM], WDS, WDS_ARRAY_T, CONFIG_WLAN_SETTING_T, 0, wlan_wds_tbl)
MIBDEF(unsigned char, wdsEncrypt, , WDS_ENCRYPT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wdsWepKeyFormat, , WDS_WEP_FORMAT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wdsWepKey, [WEP128_KEY_LEN*2+1], WDS_WEP_KEY, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wdsPskFormat, , WDS_PSK_FORMAT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wdsPsk, [MAX_PSK_LEN+1], WDS_PSK, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
// for WMM
MIBDEF(unsigned char, wmmEnabled, , WMM_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
#ifdef WLAN_EASY_CONFIG
MIBDEF(unsigned char, acfEnabled, , EASYCFG_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfMode, , EASYCFG_MODE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfSSID, [MAX_SSID_LEN], EASYCFG_SSID, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfKey, [MAX_ACF_KEY_LEN+1], EASYCFG_KEY, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfDigest, [MAX_ACF_DIGEST_LEN+1], EASYCFG_DIGEST, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfAlgReq, , EASYCFG_ALG_REQ, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfAlgSupp, , EASYCFG_ALG_SUPP, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfRole, , EASYCFG_ROLE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfScanSSID, [MAX_SSID_LEN], EASYCFG_SCAN_SSID, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, acfWlanMode, , EASYCFG_WLAN_MODE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
#endif // #ifdef WLAN_EASY_CONFIG
#ifdef WIFI_SIMPLE_CONFIG
MIBDEF(unsigned char, wscDisable, , WSC_DISABLE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscMethod, , WSC_METHOD, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscConfigured, , WSC_CONFIGURED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscAuth, , WSC_AUTH, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscEnc, , WSC_ENC, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscManualEnabled, , WSC_MANUAL_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscUpnpEnabled, , WSC_UPNP_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscRegistrarEnabled, , WSC_REGISTRAR_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscSsid, [MAX_SSID_LEN], WSC_SSID, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscPsk, [MAX_PSK_LEN+1], WSC_PSK, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wscConfigByExtReg, , WSC_CONFIGBYEXTREG, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
#endif // #ifdef WIFI_SIMPLE_CONFIG
//for 11N
MIBDEF(unsigned char, channelbonding, , CHANNEL_BONDING, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, controlsideband, , CONTROL_SIDEBAND, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, aggregation, , AGGREGATION, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, shortgiEnabled, , SHORT_GI, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, access, , ACCESS, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, priority, , PRIORITY, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
// for WAPI
#if CONFIG_RTL_WAPI_SUPPORT
MIBDEF(unsigned char, wapiPsk, [MAX_PSK_LEN+1], WAPI_PSK, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiPskLen, , WAPI_PSKLEN, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiAuth, , WAPI_AUTH, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiPskFormat, , WAPI_PSK_FORMAT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiAsIpAddr, [4], WAPI_ASIPADDR, IA_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiMcastkey, , WAPI_MCASTREKEY, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned long, wapiMcastRekeyTime, , WAPI_MCAST_TIME, DWORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned long, wapiMcastRekeyPackets, , WAPI_MCAST_PACKETS, DWORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiUcastkey, , WAPI_UCASTREKEY, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned long, wapiUcastRekeyTime, , WAPI_UCAST_TIME, DWORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned long, wapiUcastRekeyPackets, , WAPI_UCAST_PACKETS, DWORD_T, CONFIG_WLAN_SETTING_T, 0, 0)
//internal use
MIBDEF(unsigned char, wapiSearchCertInfo, [32], WAPI_SEARCHINFO, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiSearchIndex, , WAPI_SEARCHINDEX, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiCAInit, , WAPI_CA_INIT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, wapiCertSel, , WAPI_CERT_SEL, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
#endif // #if CONFIG_RTL_WAPI_SUPPORT
MIBDEF(unsigned char, STBCEnabled, , STBC_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, CoexistEnabled, , COEXIST_ENABLED, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, phyBandSelect, , PHY_BAND_SELECT, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0) //bit1:2G bit2:5G
MIBDEF(unsigned char, macPhyMode, , MAC_PHY_MODE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0) //bit0:SmSphy. bit1:DmSphy. bit2:DmDphy.
//### add by sen_liu 2011.3.29 add TX Beamforming in 92D
MIBDEF(unsigned char, TxBeamforming, , TX_BEAMFORMING, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
//### end
MIBDEF(unsigned char, CountryStr, [4], COUNTRY_STRING, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
#ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT
MIBDEF(unsigned char, eapType, , EAP_TYPE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, eapInsideType, , EAP_INSIDE_TYPE, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, eapUserId, [MAX_EAP_USER_ID_LEN+1], EAP_USER_ID, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rsUserName, [MAX_RS_USER_NAME_LEN+1], RS_USER_NAME, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rsUserPasswd, [MAX_RS_USER_PASS_LEN+1], RS_USER_PASSWD, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rsUserCertPasswd, [MAX_RS_USER_CERT_PASS_LEN+1], RS_USER_CERT_PASSWD, STRING_T, CONFIG_WLAN_SETTING_T, 0, 0)
MIBDEF(unsigned char, rsBandSel, , RS_BAND_SEL, BYTE_T, CONFIG_WLAN_SETTING_T, 0, 0)
#endif
#endif // #ifdef MIB_CONFIG_WLAN_SETTING_IMPORT
|
e41042dcf305b59f23a69cc14c895c4f36670d6f
|
d64875eb68d82517254ea2004f26db797fe64231
|
/UOJ_1174 - (3216712) Accepted.c
|
4ee6e0b6b261ea4bc45d4a772062370565d1b18f
|
[] |
no_license
|
andersonprovox/urionlinejudge
|
940a027e784aa7d1df28721191995461b46faaef
|
ab30f21be94253b7f6aa11157961d209d8af2dd2
|
refs/heads/master
| 2021-01-10T14:31:05.838524 | 2017-05-11T03:21:27 | 2017-05-11T03:21:27 | 46,582,940 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 611 |
c
|
UOJ_1174 - (3216712) Accepted.c
|
#include <stdio.h>
int main() {
int i;
double a[100];
/*O problema necessita que leia 100 valores inteiros, reais, positivos e negativos por isso
começo usando o double, o for abaixo vai ler esses 100 valores*/
for (i=0;i<100;i++){
scanf("%lf", &a[i]);
}
/* aqui farei a leitura de todos os valores no vetor e verificarei se
o valor que consta naquela posição verificada é menor ou igual a 10 sendo verificado dentro de uma
condição if e impresso caso atenda a condição determinada*/
for(i=0;i<100;i++){
if(a[i]<=10){
printf("A[%d] = %.1lf\n", i, a[i]);
}
}
return 0;
}1
|
db56deac44f2e062da62ff0df2a633d99cb7862d
|
685f1edc5763cdfa63310f43a5ce9c07c8c406fc
|
/mergeTags/mergeTags.c
|
cbc27e2aa9b82d7ce1d9051cd3b7cc78c8292d82
|
[
"MIT"
] |
permissive
|
yunfengwang0317/2-kupl
|
3b02f7fb1095cfc0a9cb84d76d663a62c80a2e44
|
0b525a147edaacd2a3aebc8b18f59e0f1882ffaf
|
refs/heads/master
| 2023-05-30T19:47:58.174724 | 2021-06-23T11:35:57 | 2021-06-23T11:35:57 | 300,064,708 | 2 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 9,634 |
c
|
mergeTags.c
|
#include <stdio.h> //fprintf
#include <stdlib.h> //free
#include <zlib.h>
#include <inttypes.h>
#include <math.h> // pow()
#include <stdint.h>
#include "kstring.h"
#include "kseq.h"
#include "khash.h"
#include "kvec.h"
#include "dna.h"
#define VERSION "0.0.3"
#define MIN_ASSEMBLY_K 15
KSEQ_INIT(gzFile, gzread)
typedef struct {
uint32_t ref_kmer_id;
double pvalue;
int nb_merged_kmers;
char *seq;
} assembly_t;
typedef struct {
uint32_t assembly_id;
uint8_t revcomp;
} assembly_kmer_t;
void assembly_destroy(assembly_t *a) {
if(a->seq)
free(a->seq);
free(a);
}
int cmp_assembly(const void * a, const void * b) {
const assembly_t *ass_a = *(const assembly_t **)a;
const assembly_t *ass_b = *(const assembly_t **)b;
if(ass_a->ref_kmer_id == ass_b->ref_kmer_id) {
return 0;
} else {
return (ass_a->ref_kmer_id - ass_b->ref_kmer_id);
}
}
// Init k-mers hash
KHASH_MAP_INIT_INT64(kmers, assembly_kmer_t)
typedef khash_t(kmers) kmers_hash_t;
typedef kvec_t(assembly_t*) assemblies_array_t;
void add_assembly_kmer(kmers_hash_t *h, uint64_t kmer, uint32_t assembly_id, uint8_t rc) {
khiter_t k = kh_get(kmers, h, kmer);
int dret = 0;
if(k == kh_end(h)) {
k = kh_put(kmers, h, kmer, &dret);
kh_value(h, k).assembly_id = assembly_id + 1;
kh_value(h, k).revcomp = rc;
} else {
kh_value(h, k).assembly_id = 0;
}
}
int main(int argc, char *argv[])
{
char *counts_file;
int k_length = 31;
int stranded = 1;
int min_assembly_k = MIN_ASSEMBLY_K;
int c;
while ((c = getopt(argc, argv, "nk:m:")) >= 0) {
switch (c) {
case 'n': stranded = 0; break;
case 'k': k_length = atoi(optarg); break;
case 'm': min_assembly_k = atoi(optarg); break;
}
}
if (optind == argc) {
fprintf(stderr, "\n");
fprintf(stderr, "Usage: mergeTags [options] <counts.tsv>\n\n");
fprintf(stderr, "Options: -k INT length of k-mers (max_value: 32) [%d]\n", k_length);
fprintf(stderr, " -m INT min assembly overlap (max_value: k) [%d]\n", min_assembly_k);
fprintf(stderr, " -n Unstranded merging procedure\n");
fprintf(stderr, "\n");
return 1;
}
counts_file = argv[optind++];
fprintf(stderr, "Loading k-mers into memory\n");
int nb_kmers = 0, dret = 0, i, j;
gzFile fp;
kstream_t *ks;
kstring_t *str;
assemblies_array_t *a = (assemblies_array_t*)calloc(1, sizeof(assemblies_array_t));
khiter_t k, k2;
kv_init(*a);
str = calloc(1, sizeof(kstring_t));
fp = gzopen(counts_file, "r");
if(!fp) { fprintf(stderr, "Failed to open %s\n", counts_file); exit(EXIT_FAILURE); }
ks = ks_init(fp);
// Skip headers
ks_getuntil(ks, KS_SEP_LINE, str, &dret);
while (ks_getuntil(ks, 0, str, &dret) >= 0) {
assembly_t *assembly = (assembly_t*)calloc(1, sizeof(assembly_t));
assembly->ref_kmer_id = nb_kmers;
assembly->seq = ks_release(str);
assembly->nb_merged_kmers = 1;
if(dret != '\n' && ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) {
assembly->pvalue = atof(str->s);
kv_push(assembly_t*, *a, assembly);
} else {
assembly_destroy(assembly);
}
// skip the rest of the line
if (dret != '\n') while ((dret = ks_getc(ks)) > 0 && dret != '\n');
nb_kmers++;
}
ks_destroy(ks);
gzclose(fp);
fprintf(stderr, "%d k-mers loaded\n", nb_kmers);
fprintf(stderr, "Assembling k-mers\n");
for(i = k_length - 1; i >= min_assembly_k; i--) {
int has_merge_assemblies = 1;
while(has_merge_assemblies) {
has_merge_assemblies = 0;
khash_t(kmers) *left_h = kh_init(kmers);
khash_t(kmers) *right_h = kh_init(kmers);
assemblies_array_t *new_a = (assemblies_array_t*)calloc(1, sizeof(assemblies_array_t));
kv_init(*new_a);
fprintf(stderr, "Merging sequences with k = %d\n", i);
fprintf(stderr, "Creating kmer-end indexes\n");
// First we index the start and ends of each assembly
for(j = 0; j < kv_size(*a); j++) {
assembly_t *assembly = kv_A(*a,j);
if(strlen(assembly->seq) <= i) continue;
uint64_t left_kmer = dna_to_int(assembly->seq, i);
uint64_t right_kmer = dna_to_int(&assembly->seq[strlen(assembly->seq) - i], i);
uint8_t is_left_kmer_rc = 0, is_right_kmer_rc = 0;
// If we are not in stranded mode, we index the canonical k-i k-mers
if(!stranded) {
uint64_t left_kmer_rc = int_revcomp(left_kmer, i);
uint64_t right_kmer_rc = int_revcomp(right_kmer, i);
if(left_kmer_rc < left_kmer) {
left_kmer = left_kmer_rc;
is_left_kmer_rc = 1;
}
if(right_kmer_rc < right_kmer) {
right_kmer = right_kmer_rc;
is_right_kmer_rc = 1;
}
}
if(is_left_kmer_rc) {
add_assembly_kmer(right_h, left_kmer, j, is_left_kmer_rc);
} else {
add_assembly_kmer(left_h, left_kmer, j, is_left_kmer_rc);
}
if(is_right_kmer_rc) {
add_assembly_kmer(left_h, right_kmer, j, is_right_kmer_rc);
} else {
add_assembly_kmer(right_h, right_kmer, j, is_right_kmer_rc);
}
}
fprintf(stderr, "Merging sequences\n");
// Now we try to merge assemblies
for(k = kh_begin(right_h); k != kh_end(right_h); ++k) {
if(!kh_exist(right_h, k)) continue;
if(kh_value(right_h, k).assembly_id == 0) continue;
assembly_t *left_assembly = kv_A(*a, kh_value(right_h, k).assembly_id - 1);
if(!left_assembly) continue;
k2 = kh_get(kmers, left_h, kh_key(right_h, k));
if(k2 != kh_end(left_h) && kh_value(left_h, k2).assembly_id != 0 && kh_value(left_h, k2).assembly_id != kh_value(right_h, k).assembly_id) {
has_merge_assemblies = 1;
// Merge the two sequences into a new assembly
assembly_t *right_assembly = kv_A(*a, kh_value(left_h, k2).assembly_id - 1);
if(!right_assembly) continue;
assembly_t *assemblies_merge, *removed_assembly;
// Keep the k-mers with lowest pvalue to represent the assembly
if(left_assembly->pvalue < right_assembly->pvalue) {
assemblies_merge = left_assembly;
removed_assembly = right_assembly;
} else {
assemblies_merge = right_assembly;
removed_assembly = left_assembly;
}
// Create a new string for the assembly merging
char *merge_seq = malloc(strlen(right_assembly->seq) + strlen(left_assembly->seq) - i + 1);
// If the assemblies are not in the same orientation, we reverse one of them
if(kh_value(left_h, k2).revcomp != kh_value(right_h, k).revcomp) {
if(kh_value(left_h, k2).revcomp) {
char* buffer = malloc(strlen(right_assembly->seq) + 1);
revcomp(right_assembly->seq, buffer, strlen(right_assembly->seq));
free(right_assembly->seq);
right_assembly->seq = buffer;
} else {
char* buffer = malloc(strlen(left_assembly->seq) + 1);
revcomp(left_assembly->seq, buffer, strlen(left_assembly->seq));
free(left_assembly->seq);
left_assembly->seq = buffer;
}
} else if(kh_value(left_h, k2).revcomp && kh_value(right_h, k).revcomp) {
// If both assemblies are in RC, we swap them
assembly_t *tmp_assembly = left_assembly;
left_assembly = right_assembly;
right_assembly = tmp_assembly;
}
strcpy(merge_seq, left_assembly->seq);
strcat(merge_seq, &right_assembly->seq[i]);
free(right_assembly->seq);
free(left_assembly->seq);
right_assembly->seq = NULL;
left_assembly->seq = NULL;
assemblies_merge->nb_merged_kmers = left_assembly->nb_merged_kmers + right_assembly->nb_merged_kmers;
assemblies_merge->seq = merge_seq;
assembly_destroy(removed_assembly);
kv_push(assembly_t*, *new_a, assemblies_merge);
kv_A(*a, kh_value(right_h, k).assembly_id - 1) = NULL;
kv_A(*a, kh_value(left_h, k2).assembly_id - 1) = NULL;
}
}
fprintf(stderr, "Add un-merged sequences\n");
// Add assemblies that were not merged
for(j = 0; j < kv_size(*a); j++) {
assembly_t *assembly = kv_A(*a,j);
if(assembly) {
kv_push(assembly_t*, *new_a, assembly);
}
}
fprintf(stderr, "%zu assemblies after merging\n", kv_size(*new_a));
// Delete previous assebly array and replace it with the new one
kv_destroy(*a);
a = new_a;
// Delete hashes
kh_destroy(kmers, left_h);
kh_destroy(kmers, right_h);
}
}
// Sort assemblies by ref_kmer_id
qsort(a->a, kv_size(*a), sizeof(a->a[0]), cmp_assembly);
fp = gzopen(counts_file, "r");
if(!fp) { fprintf(stderr, "Failed to open %s\n", counts_file); exit(EXIT_FAILURE); }
ks = ks_init(fp);
nb_kmers = 0;
j = 0;
// Print headers
ks_getuntil(ks, KS_SEP_LINE, str, &dret);
fprintf(stdout, "nb_merged_kmers\tcontig\t%s\n", str->s);
while (ks_getuntil(ks, KS_SEP_LINE, str, &dret) >= 0 && j < kv_size(*a)) {
if(nb_kmers == a->a[j]->ref_kmer_id) {
assembly_t *assembly = kv_A(*a,j);
fprintf(stdout, "%d\t%s\t%s\n",assembly->nb_merged_kmers,assembly->seq,str->s);
assembly_destroy(assembly);
kv_A(*a, j) = NULL;
j++;
}
nb_kmers++;
}
gzclose(fp);
ks_destroy(ks);
free(str->s); free(str);
kv_destroy(*a);
//free(a);
return 0;
}
|
13ef114b9cd029778333d5c574c88f5b60228b57
|
7884174d7ac30e015c95563c2f720da091b9ff3c
|
/src/utils.c
|
4f7ffa9155cd3e9353b74fdec0d13d0306fe5217
|
[
"MIT"
] |
permissive
|
OSSome01/sra-board-component
|
79574e3a6b2ad82098e6a7342c1ae5a7b28a8f46
|
4507a7e1eedb24d4331ca5414ccc8e2baa76e49a
|
refs/heads/main
| 2023-02-08T01:45:38.551704 | 2020-12-19T08:43:46 | 2020-12-19T08:43:46 | 322,993,736 | 2 | 0 |
MIT
| 2020-12-20T04:35:45 | 2020-12-20T04:35:45 | null |
UTF-8
|
C
| false | false | 165 |
c
|
utils.c
|
#include "utils.h"
float bound(float val, float min, float max)
{
if (val > max)
val = max;
else if (val < min)
val = min;
return val;
}
|
d8a84a72fe4cb5dcab5bbee8b919b8b740ac66a0
|
dd5554323214f466ebbd4ec846e86f2ee08c1abb
|
/C Program to Find the Largest Number Among Three Numbers.c
|
ea4f869b9334a6a77e58e90a1de2494bb6ce2274
|
[] |
no_license
|
manojrathinam1562/C-Programming
|
829bc32a3edb9f446fe8beb4284556328b42304a
|
ff4b3e2217776efb8ad74394c16d26ecbe8a0666
|
refs/heads/main
| 2023-08-02T21:55:40.410720 | 2021-09-16T11:11:47 | 2021-09-16T11:11:47 | 407,127,759 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 351 |
c
|
C Program to Find the Largest Number Among Three Numbers.c
|
#include <stdio.h>
int main(){
int a, b, c, max;
printf("Enter the values : ");
scanf("%d%d%d",&a,&b,&c);
if(a > b){
max = a;
}
else{
max = b;
}
if(max > c){
printf("Largest number is %d",max);
}
else{
printf("Largest number is %d",c);
}
return 0;
}
|
5d6e9259b724f84ac33c6ec11a6fccfd6d0714a9
|
627bf9169e006d377df33b39ad13a1a4caf5c8f7
|
/C++/tempCodeRunnerFile.c
|
de2f14d6a2c366f84fa13717cb9286dfd70fd64d
|
[
"MIT"
] |
permissive
|
iamsuryakant/100-days-of-code
|
82a33c5d0939ff940af445a00ac2f0a44111117c
|
eaf4863d98dc273f03a989fe87d010d201d91516
|
refs/heads/master
| 2023-06-26T15:25:42.866603 | 2021-07-16T16:42:53 | 2021-07-16T16:42:53 | 275,725,210 | 1 | 0 |
MIT
| 2020-12-13T04:28:11 | 2020-06-29T03:54:16 |
Jupyter Notebook
|
UTF-8
|
C
| false | false | 54 |
c
|
tempCodeRunnerFile.c
|
}
if(i%2!=0)
{
printf("%d", i+1);
}
|
b6aa70cf2bb12939390eb096a126129230172f54
|
10c2f70cecb1eb1fd47cba8bb6b7b51f8c7c320b
|
/EX2/ex2.c
|
77eb234c9c93296df49d45c8d480cc880804ebc7
|
[] |
no_license
|
orrpaz/OpertaingSystem
|
99a89cc2d5b82a2a057125ecda24d89af6fc7a7d
|
a09ea703aca1436284c91934055035bf0d9a78ac
|
refs/heads/master
| 2020-03-13T08:41:37.340969 | 2018-06-22T10:27:01 | 2018-06-22T10:27:01 | 131,048,662 | 0 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 11,405 |
c
|
ex2.c
|
// Or Paz
// 311250708
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define PROMPT "prompt> "
#define MAX_COMMAND_LEN 512
#define MAX_ARGS_COMMAND_LEN 512
#define PATH_SIZE 1024
#define MAX_JOBS 100
typedef enum State {
WAIT, DONTWAIT, NONE
} State;
typedef enum cmd {
CD, JOBS, EXIT, ECHO, OTHER
} cmd;
typedef struct job {
pid_t pid; /* PID of the job */
State state; /* state of the job */
char command[MAX_COMMAND_LEN]; /* command to print */
} job;
typedef struct info {
job* jobs;
size_t maxJobs;
}info;
/**
* read a line from prompt
* @param str - pointer to line
* @param n -size
* @param stream -stdin
*/
static void readline(char *str, int n, FILE *stream);
/**
* parse the commend with "" and " ".
* @param words the line
* @param line
* @return number of args
*/
size_t parseline(char **words,char *line);
/**
* check if thre is & in the end of commend
* @param command -command
* @param n -size
* @return return state - WAIT or DONTWAIT (for &)
*/
State isBackground(char **command, size_t n);
/**
* check if the caommand is cd,exit,jobs or other
* return enum that symbolize thr command.
*/
cmd specialCommand(char *command);
/**
* this function handle cd command
* @param args - all command.
* @param numOfelement - number of element in command
* @return return always 1.
*/
int changeDirectory(char **args,size_t numOfElement);
/**
* display jobs in screen
* @param args - all command
* @param information struct that contain jobs and size.
* @return always 1.
*/
int listOfJobs(char **args, info *information);
/**
* kill all process and exit
* @param information struct that contain jobs and size.
* @return 0.
*/
int exitFromShell(info *information);
/**
* execute the OTHER command.
* @param input - all line(command)
* @param command -just the first args.
* @param information struct that contain jobs and size.
* @param state - WAIT or DONTWAIT.
* @param numberOfElement - number of element in command
* @return always 1.
*/
int run(char **input,char* command, info *information,State state, size_t numberOfElement);
/**
*
* @param c - enum that symbolize the special command.
* @param input all command (line)
* @param command -just the first args.
* @param information struct that contain jobs and size.
* @param numberOfElement - number of element in command
* @param state - WAIT or DONTWAIT.
* @return 0 in exit and 1 otherwise
*/
int executeCommand(cmd c, char **input,char* command, info *information,size_t numOfElement,State state);
/**
*
* @param information struct that contain jobs and size.
* @param pid pid
* @param state - WAIT or DONTWAIT.
* @param command -just the first args.
* @return always 1
*/
int addJob(info *information, pid_t pid,State state, char* command);
/**
* initilazie the jobs array
* @param information struct that contain jobs and size.
* @param initialIndex - index that symbolize from where to start the init.
*/
void initalizeJobs(info *information, int initialIndex);
static char prev[PATH_SIZE]="";
static void readline(char *str, int n, FILE *stream)
{
fgets(str, n, stream);
str[strlen(str) - 1] = '\0';
}
size_t parseline(char **words,char *line) {
size_t position = 0;
//char *ptr;
size_t i=0;
char *token = strtok(line, " ");
if (token) {
words[position] = token;
line += (strlen(token) + 1);
while (token != NULL) {
if (line) {
if (*line == '"') {
++position;
token = strtok(NULL, "\"");
if (token)
words[position] = token;
} else {
++position;
token = strtok(NULL, " ");
if (token) {
words[position] = token;
line += (strlen(token) + 1);
}
}
}
}
}
words[position]=NULL;
return position;
}
State isBackground(char **command, size_t n) {
int i = 0;
State retState = WAIT;
for (; i < n; ++i) {
if (!strcmp(command[i], "&")) {
retState = DONTWAIT;
break;
}
}
return retState;
}
cmd specialCommand(char *command) {
int i = 4;
static char *commands[] = {"cd", "jobs", "exit", "echo"};
if (command) {
for (i = 0; i < sizeof(commands) / sizeof(char *); ++i) {
if (!strcmp(command, commands[i])) {
break;
}
}
}
return (cmd) i;
}
int changeDirectory(char **args, size_t numOfElement) {
printf("%d\n", getpid());
// Home directory
if((numOfElement==1) || !strcmp(args[1], "~")) {
if (getcwd(prev, PATH_SIZE) == NULL) {
fprintf(stderr, "Error in system call\n");
}
if (chdir(getenv("HOME")) != 0) {
fprintf(stderr, "Error in system call\n");
}
// '-' argument
}else if(!strcmp(args[1], "-")){
char cwd[PATH_SIZE];
getcwd(cwd, PATH_SIZE);
if(!strcmp(prev,"")) {
fprintf(stderr, "bash: cd: OLDPWD not set\n");
}else if (chdir(prev) != 0) {
fprintf(stderr, "Error in system call\n");
} else {
printf("%s\n",prev);
}
strcpy(prev, cwd);
} else {
if(getcwd(prev,PATH_SIZE) == NULL){
fprintf(stderr, "Error in system call\n");
}
// otherwise.
if(chdir(args[1])!= 0) {
fprintf(stderr, "Error in system call\n");
}
}
return 1;
}
int listOfJobs(char **args, info *information) {
int i, status;
for (i = 0; i < information->maxJobs; i++) {
// introduce only active process.
if (information->jobs[i].pid != -1)
if (waitpid(information->jobs[i].pid, &status, WNOHANG) == 0) {
printf("%d ", information->jobs[i].pid);
printf("%s \n", information->jobs[i].command);
} else {
information->jobs[i].pid = -1;
}
}
return 1;
}
int exitFromShell(info *information) {
int i;
for (i = 0; i < information->maxJobs; ++i) {
// kill process before exit.
if(kill(information->jobs[i].pid, 0) == -1)
{
fprintf(stderr, "Error in system call\n");
exit(1);
}
}
return 0;
}
int run(char **input, char *command, info *information, State state, size_t numberOfElement) {
int status = 0;
pid_t pid, wpid;
// replace & with \0
if (state) {
input[numberOfElement - 1] = '\0';
}
pid = fork();
if (pid == 0) {
// Child process
if (execvp(input[0], input) == -1) {
fprintf(stderr, "Error in system call\n");
exit(1);
}
return 0;
} else if (pid < 0) {
// Error forking
fprintf(stderr, "Fork error\n");
return 1;
} else {
// Parent process
do {
printf("%d\n", pid);
if (state == WAIT) {
wpid = waitpid(pid, &status, WUNTRACED);
} else {
command[strlen(command) - 1] = '\0';
addJob(information, pid, state, command);
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}
return 1;
}
int addJob(info *information, pid_t pid, State state, char *command) {
int i = 0;
int status;
while (i < information->maxJobs) {
if (information->jobs[i].pid == -1 || waitpid(information->jobs[i].pid, &status, WNOHANG) != 0) {
information->jobs[i].pid = pid;
information->jobs[i].state = state;
strcpy(information->jobs[i].command, command);
break;
}
i++;
// resize of arrays jobs
if (i == information->maxJobs) {
size_t n = information->maxJobs * 2;
job *ptr;
ptr = realloc(information->jobs, n * sizeof(job));
if (ptr) {
size_t temp = information->maxJobs;
information->maxJobs = n;
information->jobs = ptr;
initalizeJobs(information, (int) temp);
information->maxJobs = n;
}
}
}
}
int executeCommand(cmd c, char **input, char *command, info *information, size_t numOfElement, State state) {
int i;
switch (c) {
case CD:
i = changeDirectory(input, numOfElement);
break;
case JOBS:
i = listOfJobs(input, information);
break;
case EXIT:
i = exitFromShell(information);
break;
case ECHO:
case OTHER:
i = run(input, command, information, state, numOfElement);
break;
default:
i = 0;
break;
}
return i;
}
void initalizeJobs(info *information, int initialIndex) {
int i;
for (i = initialIndex; i < information->maxJobs; i++) {
strcpy(information->jobs[i].command, "");
information->jobs[i].pid = -1;
information->jobs[i].state = NONE;
}
}
int main() {
char command[MAX_COMMAND_LEN];
int flag = 1;
int initialIndex = 0;
char *argCommand[MAX_ARGS_COMMAND_LEN];
size_t numOfWordPerCommand = 0;
cmd c;
State state = NONE;
info *information = malloc(sizeof(info));
if (information == NULL) {
exit(1);
}
information->maxJobs = MAX_JOBS;
information->jobs = (void *) calloc(MAX_JOBS, sizeof(job));
// job *jobs = (void *) calloc(MAX_JOBS, sizeof(job));
if (information->jobs == NULL) {
fprintf(stderr, "allocation error\n");
exit(EXIT_FAILURE);
}
initalizeJobs(information, initialIndex);
while (flag) {
printf(PROMPT);
readline(command, MAX_COMMAND_LEN, stdin);
char commandCpy[MAX_COMMAND_LEN];
strcpy(commandCpy, command);
numOfWordPerCommand = parseline(argCommand, command);
state = isBackground(argCommand, numOfWordPerCommand);
c = specialCommand(argCommand[0]);
flag = executeCommand(c, argCommand, commandCpy, information, numOfWordPerCommand, state);
}
free(information->jobs);
free(information);
}
|
4b4072654b6829e9b7bfe4da3ec75b3d460048b7
|
f074587284a9a34526a6e2e7affa7d4811bcf1f4
|
/graphs/heapq.h
|
029dffdab41385a785f7edf316f0b75af4ef9162
|
[] |
no_license
|
Ivan-Terex91/test_git
|
f0243d7aa1acd59c05a1adc5dad45ac36f6d3575
|
726afe0d164789f7340e206de556808e55b81570
|
refs/heads/master
| 2020-09-06T17:24:38.198705 | 2019-11-10T14:47:59 | 2019-11-10T14:47:59 | 220,493,319 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 2,083 |
h
|
heapq.h
|
#define PARENT(x) (((x) - 1) >> 1)
#define LEFT(x) (((x) << 1) + 1)
#define RIGHT(x) (((x) << 1) + 2)
typedef struct {
Node **nodes;
int count;
} minHeap;
void moveNode(Node **nodes, int from, int to) {
nodes[to] = nodes[from];
nodes[to]->hIdx = to;
}
/**
* Move node up if needed to maintain heap property
*/
void heapifyUp(minHeap* heap, int idx) {
Node **h = heap->nodes;
Node *n = h[idx];
int parent = PARENT(idx);
while(idx > 0 && n->value < h[parent]->value) {
moveNode(h, parent, idx);
idx = parent;
parent = PARENT(idx);
}
h[idx] = n;
h[idx]->hIdx = idx;
}
/**
* Make sure the subtree rooted at idx is a heap
* Used after remove
*/
void heapifyDown(minHeap* heap, int idx) {
Node **h = heap->nodes;
Node *n = h[idx];
while(true) {
int l = LEFT(idx);
int r = RIGHT(idx);
ull min; int minidx;
if(r < heap->count) {
int lv = h[l]->value;
int rv = h[r]->value;
if(lv < rv) {
min = lv;
minidx = l;
} else {
min = rv;
minidx = r;
}
} else if(l < heap->count) {
min = h[l]->value;
minidx = l;
} else {
break;
}
if(n->value < min) break;
moveNode(h, minidx, idx);
idx = minidx;
}
n->hIdx = idx;
h[idx] = n;
}
void insertHeap(minHeap* heap, Node *n) {
heap->nodes[heap->count] = n;
n->hIdx = heap->count;
heap->count++;
heapifyUp(heap, heap->count - 1);
}
void removeHeap(minHeap* heap, Node** item) {
heap->count--;
Node **h = heap->nodes;
*item = h[0];
h[0] = h[heap->count];
h[0]->hIdx = 0;
if(heap->count > 0)
heapifyDown(heap, 0);
}
void updateValue(minHeap* heap, int idx, int newVal) {
Node *item = heap->nodes[idx];
if(item->value > newVal) {
item->value = newVal;
heapifyUp(heap, idx);
} else {
item->value = newVal;
heapifyDown(heap, idx);
}
}
void initHeap(minHeap* heap, int size) {
heap->count = 0;
heap->nodes = new Node*[size];
}
void deleteHeap(minHeap* heap) {
delete[] heap->nodes;
heap->count = 0;
}
void printHeap(minHeap* heap) {
for(int i = 0; i < heap->count; i++)
printf("%d ", heap->nodes[i]->value);
printf("\n");
}
|
798106943f1be7830c62d27b68fbcfc4d0886b99
|
aa8a72f9654044a0f1efd895ae22821adaecfd5a
|
/core/ets_alloc.c
|
5fd0dba0601c20b2802ba44e9dcc96a9d463ee97
|
[] |
no_license
|
EarlGray/ling
|
a7a98a516b49517a874ede619ed19e3cf7467a52
|
790a730cea237133aa46fa354263e63fe6838425
|
refs/heads/master
| 2020-12-11T09:25:21.989572 | 2015-08-20T10:58:11 | 2015-08-20T10:58:11 | 35,478,636 | 6 | 0 | null | 2015-05-12T09:18:39 | 2015-05-12T09:18:39 | null |
UTF-8
|
C
| false | false | 5,246 |
c
|
ets_alloc.c
|
// Copyright (c) 2013-2014 Cloudozer LLP. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Redistributions in any form must be accompanied by information on how to
// obtain complete source code for the LING software and any accompanying
// software that uses the LING software. The source code must either be included
// in the distribution or be available for no more than the cost of distribution
// plus a nominal fee, and must be freely redistributable under reasonable
// conditions. For an executable file, complete source code means the source
// code for all modules it contains. It does not include source code for modules
// or files that typically accompany the major components of the operating
// system on which the executable file runs.
//
// THIS SOFTWARE IS PROVIDED BY CLOUDOZER LLP ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE
// DISCLAIMED. IN NO EVENT SHALL CLOUDOZER LLP BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
//
#include "ets.h"
#include <stdint.h>
#include "ling_common.h"
#include "nalloc.h"
#include "bits.h"
#include "limits.h"
#define ETS_ALLOC_INIT_SIZE 16384
#define ETS_ALLOC_EXT_SIZE 16384
static ets_plane_t *ets_current_plane = 0;
uint32_t total_ets_alloc_size = 0;
void ets_alloc_init(void)
{
assert(sizeof(ets_plane_t) == sizeof(memnode_t));
ets_current_plane = (ets_plane_t *)nalloc(ETS_ALLOC_INIT_SIZE -sizeof(ets_plane_t));
total_ets_alloc_size += ets_current_plane->index *PAGE_SIZE;
}
uint32_t *ets_alloc(int wsize)
{
assert(wsize > 0);
assert(ets_current_plane != 0);
if (ets_current_plane->ends - ets_current_plane->starts < WSIZE(ets_lot_t) + wsize)
{
// switch to a new plane - release current plane if unreferenced
if (ets_current_plane->refc == 0)
{
total_ets_alloc_size -= ets_current_plane->index *PAGE_SIZE;
nfree((memnode_t *)ets_current_plane);
}
int size = wsize *sizeof(uint32_t) +sizeof(ets_lot_t) +sizeof(ets_plane_t);
if (size < ETS_ALLOC_EXT_SIZE)
size = ETS_ALLOC_EXT_SIZE;
// EXCEPTION POSSIBLE
ets_current_plane = (ets_plane_t *)nalloc(size -sizeof(ets_plane_t));
ets_current_plane->refc = 0;
total_ets_alloc_size += ets_current_plane->index *PAGE_SIZE;
assert(ets_current_plane->ends - ets_current_plane->starts >= WSIZE(ets_lot_t) + wsize);
}
ets_lot_t *lot = (ets_lot_t *)ets_current_plane->starts;
ets_current_plane->starts += WSIZE(ets_lot_t) + wsize;
lot->my_plane = ets_current_plane;
ets_current_plane->refc++;
lot->proc_bins = 0;
lot->wsize = wsize;
return (uint32_t *)(lot +1);
}
uint32_t *ets_alloc_N(int wsize)
{
assert(wsize > 0);
assert(ets_current_plane != 0);
if (ets_current_plane->ends - ets_current_plane->starts < WSIZE(ets_lot_t) + wsize)
{
// switch to a new plane - release current plane if unreferenced
if (ets_current_plane->refc == 0)
{
total_ets_alloc_size -= ets_current_plane->index *PAGE_SIZE;
nfree((memnode_t *)ets_current_plane);
}
int size = wsize *sizeof(uint32_t) +sizeof(ets_lot_t) +sizeof(ets_plane_t);
if (size < ETS_ALLOC_EXT_SIZE)
size = ETS_ALLOC_EXT_SIZE;
ets_plane_t *new_plane = (ets_plane_t *)nalloc_N(size -sizeof(ets_plane_t));
if (new_plane == 0)
return 0;
ets_current_plane = new_plane;
ets_current_plane->refc = 0;
total_ets_alloc_size += ets_current_plane->index *PAGE_SIZE;
assert(ets_current_plane->ends - ets_current_plane->starts >= WSIZE(ets_lot_t) + wsize);
}
ets_lot_t *lot = (ets_lot_t *)ets_current_plane->starts;
ets_current_plane->starts += WSIZE(ets_lot_t) +wsize;
lot->my_plane = ets_current_plane;
ets_current_plane->refc++;
lot->proc_bins = 0;
lot->wsize = wsize;
return (uint32_t *)(lot +1);
}
void ets_free(uint32_t *p)
{
ets_lot_t *lot = (ets_lot_t *)p -1;
// Unlink embedded proc bins
while (lot->proc_bins != 0)
proc_bin_unlink(lot->proc_bins, 0);
assert(lot->my_plane->refc > 0);
lot->my_plane->refc--;
if (lot->my_plane->refc == 0)
{
// my_plane may be the current plane
if (lot->my_plane == ets_current_plane)
ets_current_plane->starts = (uint32_t *)(ets_current_plane +1);
else
{
total_ets_alloc_size -= lot->my_plane->index *PAGE_SIZE;
nfree((memnode_t *)lot->my_plane);
}
}
}
//EOF
|
4b505741adf4438a9017a0a85b48711e0425fff1
|
b227fa671d1ce3e8c3bef3925831d1f9d06b5589
|
/src/kalimba/core/pskey.h
|
30006b9f85aed742d41868badaf66a33620b20d8
|
[] |
no_license
|
layne11/csr8670_adk4_1
|
b9636a3a1226ee8842c8673524da0b27414a9345
|
9cf63ef4d0c015a111793af25f615b7d1c4da67e
|
refs/heads/master
| 2021-07-12T00:15:10.877596 | 2020-09-28T01:20:57 | 2020-09-28T01:20:57 | 205,702,144 | 9 | 4 | null | null | null | null |
UTF-8
|
C
| false | false | 985 |
h
|
pskey.h
|
// *****************************************************************************
// Copyright (c) 2005 - 2015 Qualcomm Technologies International, Ltd.
// Part of ADK 4.1
//
// *****************************************************************************
#ifndef PSKEY_HEADER_INCLUDED
#define PSKEY_HEADER_INCLUDED
#ifdef DEBUG_ON
#define PSKEY_DEBUG_ON
#endif
// structure fields
.CONST $pskey.NEXT_ENTRY_FIELD 0;
.CONST $pskey.KEY_NUM_FIELD 1;
.CONST $pskey.HANDLER_ADDR_FIELD 2;
.CONST $pskey.STRUC_SIZE 3;
// set the maximum possible number of handlers - this is only used to detect
// corruption in the linked list, and so can be quite large
.CONST $pskey.MAX_HANDLERS 50;
.CONST $pskey.LAST_ENTRY -1;
.CONST $pskey.REATTEMPT_TIME_PERIOD 10000;
.CONST $pskey.FAILED_READ_LENGTH -1;
#endif
|
57d02056d15df3979cdc4227cfd78a53b2f25ff0
|
131073c43d99106f52d1de2ac367d5bba1e9f116
|
/src/spectro/i1pro_imp.c
|
a8cb9e0e6a7f796a363ee2b33d16a08f9c14ce81
|
[] |
no_license
|
teunispolak/XY_Table
|
ada6c214e074d47c014235d9ec70633948e723bd
|
d1912e662749fc3255d6fde2eab2a15be62781c5
|
refs/heads/master
| 2022-10-05T22:17:31.399502 | 2020-05-30T21:11:39 | 2020-05-30T21:11:39 | 266,624,844 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 426,226 |
c
|
i1pro_imp.c
|
/*
* Argyll Color Correction System
*
* Gretag i1Pro implementation functions
*/
/*
* Author: Graeme W. Gill
* Date: 24/11/2006
*
* Copyright 2006 - 2014 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*/
/*
If you make use of the instrument driver code here, please note
that it is the author(s) of the code who take responsibility
for its operation. Any problems or queries regarding driving
instruments with the Argyll drivers, should be directed to
the Argyll's author(s), and not to any other party.
If there is some instrument feature or function that you
would like supported here, it is recommended that you
contact Argyll's author(s) first, rather than attempt to
modify the software yourself, if you don't have firm knowledge
of the instrument communicate protocols. There is a chance
that an instrument could be damaged by an incautious command
sequence, and the instrument companies generally cannot and
will not support developers that they have not qualified
and agreed to support.
*/
/* TTBD:
Would be nice to have option to save raw scan data to .ti3 file,
and then have a utility/option to replay it through scan
recognition, to be able to help remote diagnose scan problems.
Some things probably aren't quite correct:
The way the sensor saturation and optimal target is
computed probably doesn't account for the dark level
correctly, since the targets are in sensor value,
but the comparison is done after subtracting black ??
See the Munki implementation for an approach to fix this ??
It should be possible to add a refresh-display calibration
routine based on an emissive scan + the auto-correlation
(see i1d3.c). Whether this will noticably improve repeatibility
remains to be seen.
*/
/*
Notes:
Naming of spectral values:
sensor - the 16 bit values from the sensor including any dummy/shielded values
raw - the floating point values of the spectral section
absraw - raw after scaling for integration time and gain settings.
The Rev D seems to die if it is ever given a GET_STATUS. This is why
the WinUSB driver can't be used with it.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <math.h>
#if defined(UNIX)
# include <utime.h>
#else
# include <sys/utime.h>
#endif
#include <sys/stat.h>
#ifndef SALONEINSTLIB
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "rspl.h"
#else /* SALONEINSTLIB */
#include <fcntl.h>
#include "sa_config.h"
#include "numsup.h"
#include "rspl1.h"
#endif /* SALONEINSTLIB */
#include "xspect.h"
#include "insttypes.h"
#include "conv.h"
#include "icoms.h"
#include "sort.h"
/* Configuration */
#define ENABLE_2 /* [Def] Enable i1pro2/Rev E driver code, else treat i1pro2 as i1pro */
#undef USE_HIGH_GAIN_MODE /* [Und] Make use of high gain mode in Rev A-D mode */
#define USE_THREAD /* Need to use thread, or there are 1.5 second internal */
/* instrument delays ! */
#undef WAIT_FOR_DELAY_TRIGGER /* [Und] Hack to diagnose threading problems */
#undef ENABLE_WRITE /* [Und] Enable writing of calibration and log data to the EEProm */
#define ENABLE_NONVCAL /* [Def] Enable saving calibration state between program runs in a file */
#define ENABLE_NONLINCOR /* [Def] Enable non-linear correction */
#define ENABLE_BKDRIFTC /* [Def] Enable Emis. Black drift compensation using sheilded cell values */
#define HEURISTIC_BKDRIFTC /* [Def] Enable heusristic black drift correction */
#define WLCALTOUT (24 * 60 * 60) /* [24 Hrs] Wavelength calibration timeout in seconds */
#define DCALTOUT ( 30 * 60) /* [30 Minutes] Dark Calibration timeout in seconds */
#define DCALTOUT2 ( 1 * 60 * 60) /* [1 Hr] i1pro2 Dark Calibration timeout in seconds */
#define WCALTOUT ( 1 * 60 * 60) /* [1 Hr] White Calibration timeout in seconds */
#define MAXSCANTIME 30.0 /* [30] Maximum scan time in seconds */
#define SW_THREAD_TIMEOUT (10 * 60.0) /* [10 Min] Switch read thread timeout */
#define SINGLE_READ /* [Def] Use a single USB read for scan to eliminate latency issues. */
#define HIGH_RES /* [Def] Enable high resolution spectral mode code. Dissable */
/* to break dependency on rspl library. */
# undef FAST_HIGH_RES_SETUP /* Slightly better accuracy ? */
/* Debug [Und] */
#undef DEBUG /* Turn on debug printfs */
#undef PLOT_DEBUG /* Use plot to show readings & processing */
#undef PLOT_REFRESH /* Plot refresh rate measurement info */
#undef PLOT_UPDELAY /* Plot data used to determine display update delay */
#undef DUMP_SCANV /* Dump scan readings to a file "i1pdump.txt" */
#undef DUMP_DARKM /* Append raw dark readings to file "i1pddump.txt" */
#undef APPEND_MEAN_EMMIS_VAL /* Append averaged uncalibrated reading to file "i1pdump.txt" */
#undef TEST_DARK_INTERP /* Test out the dark interpolation (need DEBUG for plot) */
#undef PATREC_DEBUG /* Print & Plot patch/flash recognition information */
#undef PATREC_ALLBANDS /* Plot all bands of scan */
#undef PATREC_SAVETRIMMED /* Saved trimmed raw to file "i1pro_raw_trimed_N.csv */
#undef IGNORE_WHITE_INCONS /* Ignore define reference reading inconsistency */
#undef HIGH_RES_DEBUG
#undef HIGH_RES_PLOT
#undef ANALIZE_EXISTING /* Analize the manufacturers existing filter shape */
#undef PLOT_BLACK_SUBTRACT /* Plot temperature corrected black subtraction */
#undef FAKE_AMBIENT /* Fake the ambient mode for a Rev A */
#undef USE_SPOT_OMD /* [Und] Use Original Manufacturers Driver timing. Reduce */
/* integration time and lamp turn on time. */
#define DISP_INTT 2.0 /* Seconds per reading in display spot mode */
/* More improves repeatability in dark colors, but limits */
/* the maximum brightness level befor saturation. */
/* A value of 2.0 seconds has a limit of about 110 cd/m^2 */
#define DISP_INTT2 0.8 /* High brightness display spot mode seconds per reading, */
/* Should be good up to 275 cd/m^2 */
#define DISP_INTT3 0.3 /* High brightness display spot mode seconds per reading, */
/* Should be good up to 700 cd/m^2 */
#define DISP_INTT4 0.1 /* Very high brightness display spot mode seconds per reading, */
/* Should be good up to 2000 cd/m^2 ? */
#define ADARKINT_MAX 2.0 /* Max cal time for adaptive dark cal */
#define ADARKINT_MAX2 4.0 /* Max cal time for adaptive dark cal Rev E or no high gain */
#define EMIS_SCALE_FACTOR 1.0 /* Emission mode scale factor */
#define AMB_SCALE_FACTOR 1.0 /* Ambient mode scale factor for Lux */
//#define AMB_SCALE_FACTOR (1.0/3.141592654) /* Ambient mode scale factor - convert */
// /* from Lux to Lux/PI */
// /* These factors get the same behaviour as the GMB drivers. */
#define NSEN_MAX 140 /* Maximum nsen value we can cope with */
/* High res mode settings */
#define HIGHRES_SHORT 370.0 /* i1pro2 uses more of the CCD, */
#define HIGHRES_LONG 730.0 /* leaving less scope for extenion */
#define HIGHRES_WIDTH (10.0/3.0) /* (The 3.3333 spacing and lanczos2 seems a good combination) */
#define HIGHRES_REF_MIN 375.0 /* Too much stray light below this in reflective mode */
#include "i1pro.h"
#include "i1pro_imp.h"
#include "xrga.h"
/* - - - - - - - - - - - - - - - - - - */
#define LAMP_OFF_TIME 1500 /* msec to make sure lamp is dark for dark measurement */
#define PATCH_CONS_THR 0.1 /* Dark measurement consistency threshold */
#define USE_RD_SYNC /* Use mutex syncronisation, else depend on TRIG_DELAY */
#define TRIG_DELAY 10 /* Measure trigger delay to allow pending read, msec */
/* - - - - - - - - - - - - - - - - - - */
#if defined(DEBUG) || defined(PLOT_DEBUG) || defined(PATREC_DEBUG)
# include <plot.h>
#endif
#if defined(DEBUG) || defined(PLOT_DEBUG) || defined(HIGH_RES_PLOT) || defined(PATREC_DEBUG)
static int disdebplot = 0;
#define DISDPLOT disdebplot = 1;
#define ENDPLOT disdebplot = 0;
#else
#define DISDPLOT
#define ENDPLOT
#endif /* DEBUG */
#if defined(DEBUG) || defined(PLOT_DEBUG) || defined(PATREC_DEBUG)
/* ============================================================ */
/* Debugging support */
/* Plot a CCD spectra */
void plot_raw(double *data) {
int i;
double xx[NSEN_MAX];
double yy[NSEN_MAX];
if (disdebplot)
return;
for (i = 0; i < 128; i++) {
xx[i] = (double)i;
yy[i] = data[i];
}
do_plot(xx, yy, NULL, NULL, 128);
}
/* Plot two CCD spectra */
void plot_raw2(double *data1, double *data2) {
int i;
double xx[128];
double y1[128];
double y2[128];
if (disdebplot)
return;
for (i = 0; i < 128; i++) {
xx[i] = (double)i;
y1[i] = data1[i];
y2[i] = data2[i];
}
do_plot(xx, y1, y2, NULL, 128);
}
/* Plot a converted spectra */
void plot_wav(i1proimp *m, int hires, double *data) {
int i;
double xx[128];
double yy[128];
if (disdebplot)
return;
for (i = 0; i < m->nwav[hires]; i++) {
xx[i] = XSPECT_WL(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], i);
yy[i] = data[i];
}
do_plot(xx, yy, NULL, NULL, m->nwav[hires]);
}
/* Plot two converted spectra for the current res. mode */
void plot_wav_2(i1proimp *m, int hires, double *data1, double *data2) {
int i;
double xx[128];
double y1[128];
double y2[128];
if (disdebplot)
return;
for (i = 0; i < m->nwav[hires]; i++) {
xx[i] = XSPECT_WL(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], i);
y1[i] = data1[i];
y2[i] = data2[i];
}
do_plot(xx, y1, y2, NULL, m->nwav[hires]);
}
#endif /* PLOT_DEBUG */
/* ============================================================ */
/* Return a linear interpolated spectral value. Clip to ends */
static double wav_lerp(i1proimp *m, int hires, double *ary, double wl) {
int jj;
double wl0, wl1, bl;
double rv;
jj = (int)floor(XSPECT_DIX(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], wl));
if (jj < 0)
jj = 0;
else if (jj > (m->nwav[hires]-2))
jj = m->nwav[hires]-2;
wl0 = XSPECT_WL(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], jj);
wl1 = XSPECT_WL(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], jj+1);
bl = (wl - wl0)/(wl1 - wl0);
if (bl < 0.0)
bl = 0;
else if (bl > 1.0)
bl = 1.0;
rv = (1.0 - bl) * ary[jj] + bl * ary[jj+1];
return rv;
}
/* Same as above, but return cv value on clip */
static double wav_lerp_cv(i1proimp *m, int hires, double *ary, double wl, double cv) {
int jj;
double wl0, wl1, bl;
double rv;
jj = (int)floor(XSPECT_DIX(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], wl));
if (jj < 0)
jj = 0;
else if (jj > (m->nwav[hires]-2))
jj = m->nwav[hires]-2;
wl0 = XSPECT_WL(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], jj);
wl1 = XSPECT_WL(m->wl_short[hires], m->wl_long[hires], m->nwav[hires], jj+1);
bl = (wl - wl0)/(wl1 - wl0);
if (bl < 0.0 || bl > 1.0)
return cv;
rv = (1.0 - bl) * ary[jj] + bl * ary[jj+1];
return rv;
}
/* ============================================================ */
/* Implementation struct */
/* Add an implementation structure */
i1pro_code add_i1proimp(i1pro *p) {
i1proimp *m;
if ((m = (i1proimp *)calloc(1, sizeof(i1proimp))) == NULL) {
a1logd(p->log,1,"add_i1proimp malloc %ld bytes failed (1)\n",sizeof(i1proimp));
return I1PRO_INT_MALLOC;
}
m->p = p;
/* EEProm data store */
if ((m->data = new_i1data(m)) == NULL)
return I1PRO_INT_CREATE_EEPROM_STORE;
m->lo_secs = 2000000000; /* A very long time */
m->msec = msec_time();
p->m = (void *)m;
return I1PRO_OK;
}
/* Shutdown instrument, and then destroy */
/* implementation structure */
void del_i1proimp(i1pro *p) {
a1logd(p->log,5,"i1pro_del called\n");
#ifdef ENABLE_NONVCAL
/* Touch it so that we know when the instrument was last open */
i1pro_touch_calibration(p);
#endif /* ENABLE_NONVCAL */
if (p->m != NULL) {
int i, j;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s;
i1pro_code ev;
if (p->itype != instI1Pro2 && (ev = i1pro_update_log(p)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_update_log: Updating the cal and log parameters to"
" EEProm failed failed\n");
}
/* i1pro_terminate_switch() seems to fail on a rev A & Rev C ?? */
if (m->th != NULL) { /* Terminate switch monitor thread */
m->th_term = 1; /* Tell thread to exit on error */
i1pro_terminate_switch(p);
for (i = 0; m->th_termed == 0 && i < 5; i++)
msec_sleep(50); /* Wait for thread to terminate */
if (i >= 5) {
a1logd(p->log,5,"i1pro switch thread termination failed\n");
}
m->th->del(m->th);
usb_uninit_cancel(&m->sw_cancel); /* Don't need cancel token now */
usb_uninit_cancel(&m->rd_sync); /* Don't need sync token now */
a1logd(p->log,5,"i1pro switch thread terminated\n");
}
if (m->trig_thread != NULL) {
m->trig_thread->del(m->trig_thread);
a1logd(p->log,5,"i1pro trigger thread terminated\n");
}
/* Free any per mode data */
for (i = 0; i < i1p_no_modes; i++) {
s = &m->ms[i];
free_dvector(s->dark_data, -1, m->nraw-1);
free_dvector(s->dark_data2, -1, m->nraw-1);
free_dvector(s->dark_data3, -1, m->nraw-1);
free_dvector(s->dark_data4, -1, m->nraw-1);
free_dvector(s->white_data, -1, m->nraw-1);
free_dmatrix(s->idark_data, 0, 3, -1, m->nraw-1);
free_dvector(s->cal_factor[0], 0, m->nwav[0]-1);
free_dvector(s->cal_factor[1], 0, m->nwav[1]-1);
}
/* Free EEProm key data */
if (m->data != NULL)
m->data->del(m->data);
/* Free all Rev E and high res raw2wav filters */
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
if (m->mtx_c[i][j].index != NULL)
free(m->mtx_c[i][j].index);
if (m->mtx_c[i][j].nocoef != NULL)
free(m->mtx_c[i][j].nocoef);
if (m->mtx_c[i][j].coef != NULL)
free(m->mtx_c[i][j].coef);
}
}
/* Free RevE straylight arrays */
for (i = 0; i < 2; i++) {
if (m->straylight[i] != NULL)
free_dmatrix(m->straylight[i], 0, m->nwav[i]-1, 0, m->nwav[i]-1);
}
/* RevA-D high res. recal support */
if (m->raw2wav != NULL)
m->raw2wav->del(m->raw2wav);
free(m);
p->m = NULL;
}
}
/* ============================================================ */
/* High level functions */
/* Initialise our software state from the hardware */
i1pro_code i1pro_imp_init(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
unsigned char *eeprom; /* EEProm contents, i1pro = half, i1pro2 = full */
int len = 8192;
char *envv;
a1logd(p->log,5,"i1pro_init:\n");
m->native_calstd = xcalstd_gmdi; /* Rev A-D */
if (p->itype == instI1Pro2) {
m->native_calstd = xcalstd_xrga; /* Rev E */
}
m->target_calstd = xcalstd_native; /* Default to native calibration */
/* Honor Environment override */
if ((envv = getenv("ARGYLL_XCALSTD")) != NULL) {
if (strcmp(envv, "XRGA") == 0)
m->target_calstd = xcalstd_xrga;
else if (strcmp(envv, "XRDI") == 0)
m->target_calstd = xcalstd_xrdi;
else if (strcmp(envv, "GMDI") == 0)
m->target_calstd = xcalstd_gmdi;
}
/* Revert to i1pro if i1pro2 driver is not enabled */
if (p->itype == instI1Pro2
#ifdef ENABLE_2
&& getenv("ARGYLL_DISABLE_I1PRO2_DRIVER") != NULL /* Disabled by environment */
#endif
) {
p->itype = instI1Pro;
}
if (p->itype != instI1Monitor
&& p->itype != instI1Pro
&& p->itype != instI1Pro2)
return I1PRO_UNKNOWN_MODEL;
m->trig = inst_opt_trig_user;
m->scan_toll_ratio = 1.0;
/* Take conservative approach to when the light was last on. */
/* Assume it might have been on right before init was called again. */
m->slamponoff = msec_time();
m->llampoffon = msec_time();
m->llamponoff = msec_time();
if ((ev = i1pro_reset(p, 0x1f)) != I1PRO_OK)
return ev;
usb_init_cancel(&m->sw_cancel); /* Init switch cancel token */
usb_init_cancel(&m->rd_sync); /* Init reading sync token */
#ifdef USE_THREAD
/* Setup the switch monitoring thread */
if ((m->th = new_athread(i1pro_switch_thread, (void *)p)) == NULL)
return I1PRO_INT_THREADFAILED;
#endif
/* Get the current misc. status, fwrev etc */
if ((ev = i1pro_getmisc(p, &m->fwrev, NULL, &m->maxpve, NULL, &m->powmode)) != I1PRO_OK)
return ev;
a1logd(p->log,2,"Firmware rev = %d, max +ve value = 0x%x\n",m->fwrev, m->maxpve);
if (p->itype == instI1Pro2 && m->fwrev < 600) { /* Hmm */
a1logd(p->log,2, "Strange, firmware isn't up to i1pro2 but has extra pipe..revert to i1pro driver\n",m->fwrev);
p->itype = instI1Pro;
}
/* Get the EEProm size */
m->eesize = 8192; /* Rev A..D */
if (p->itype == instI1Pro2) {
#ifdef NEVER
// ~~99 Hmm. makes it worse. Why ???
// /* Make sure LED sequence is finished, because it interferes with EEProm read! */
// if ((ev = i1pro2_indLEDoff(p)) != I1PRO_OK)
// return ev;
#endif
if ((ev = i1pro2_geteesize(p, &m->eesize)) != I1PRO_OK) {
return ev;
}
}
if (m->eesize < 8192) {
a1logd(p->log,2,"Strange, EEProm size is < 8192!\n",m->fwrev);
return I1PRO_HW_EE_SIZE;
}
if ((eeprom = (unsigned char *)malloc(m->eesize)) == NULL) {
a1logd(p->log,1,"Malloc %d bytes for eeprom failed\n",m->eesize);
return I1PRO_INT_MALLOC;
}
/* Read the EEProm */
if ((ev = i1pro_readEEProm(p, eeprom, 0, m->eesize)) != I1PRO_OK) {
free(eeprom);
return ev;
}
if (p->itype == instI1Pro2) {
/* Get the Chip ID (This doesn't work until after reading the EEProm !) */
if ((ev = i1pro2_getchipid(p, m->chipid)) != I1PRO_OK) {
free(eeprom);
return ev;
}
}
/* Parse the i1pro data */
if ((ev = m->data->parse_eeprom(m->data, eeprom, m->eesize, 0)) != I1PRO_OK) {
free(eeprom);
return ev;
}
/* Parse the i1pro2 extra data */
if (p->itype == instI1Pro2) {
if ((ev = m->data->parse_eeprom(m->data, eeprom, m->eesize, 1)) != I1PRO_OK) {
free(eeprom);
return ev;
}
}
free(eeprom); eeprom = NULL;
/* Setup various calibration parameters from the EEprom */
{
int *ip, i, xcount;
unsigned int count;
double *dp;
/* Information about the instrument */
if ((ip = m->data->get_ints(m->data, &count, key_serno)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->serno = ip[0];
a1logd(p->log,2,"Serial number = %d\n",m->serno);
sprintf(m->sserno,"%ud",m->serno);
if ((ip = m->data->get_ints(m->data, &count, key_dom)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->dom = ip[0];
a1logd(p->log,2, "Date of manufactur = %d-%d-%d\n",
m->dom/1000000, (m->dom/10000) % 100, m->dom % 10000);
if ((ip = m->data->get_ints(m->data, &count, key_cpldrev)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->cpldrev = ip[0];
a1logd(p->log,2,"CPLD rev = %d\n",m->cpldrev);
if ((ip = m->data->get_ints(m->data, &count, key_capabilities)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->capabilities = ip[0];
if (m->capabilities & 0x6000) /* Has ambient */
m->capabilities2 |= I1PRO_CAP2_AMBIENT; /* Mimic in capabilities2 */
a1logd(p->log,2,"Capabilities flag = 0x%x\n",m->capabilities);
if (m->capabilities & 0x6000)
a1logd(p->log,2," Can read ambient\n");
if ((ip = m->data->get_ints(m->data, &count, key_physfilt)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->physfilt = ip[0];
if (m->physfilt == 0x82)
m->capabilities2 |= I1PRO_CAP2_UV_FILT; /* Mimic in cap 2 */
a1logd(p->log,2,"Physical filter flag = 0x%x\n",m->physfilt);
if (m->physfilt == 0x80)
a1logd(p->log,2," No filter fitted\n");
else if (m->physfilt == 0x81)
a1logd(p->log,2," Emission only ??\n");
else if (m->physfilt == 0x82)
a1logd(p->log,2," Is fitted with Ultra Violet Filter\n");
/* Underlying calibration information */
m->nsen = 128;
m->nraw = 128;
if (p->itype == instI1Pro2) {
int clkusec, subdiv, xraw, nraw;
if ((ev = i1pro2_getmeaschar(p, &clkusec, &xraw, &nraw, &subdiv)) != I1PRO_OK)
return ev;
m->intclkp2 = clkusec * 1e-6; /* Rev E integration clock period, ie. 36 usec */
m->subclkdiv2 = subdiv; /* Rev E sub clock divider, ie. 136 */
m->nsen = nraw + xraw;
if (clkusec != 36 || xraw != 6 || nraw != 128 || subdiv != 136)
return I1PRO_HW_UNEX_SPECPARMS;
if (m->nsen > NSEN_MAX) /* Static allocation assumed */
return I1PRO_HW_UNEX_SPECPARMS;
}
if (m->data->get_ints(m->data, &m->nwav[0], key_mtx_index) == 0)
return I1PRO_HW_CALIBINFO;
if (m->nwav[0] != 36)
return I1PRO_HW_CALIBINFO;
m->wl_short[0] = 380.0; /* Normal res. range */
m->wl_long[0] = 730.0;
/* Fill high res in too */
m->wl_short[1] = HIGHRES_SHORT;
m->wl_long[1] = HIGHRES_LONG;
m->nwav[1] = (int)((m->wl_long[1]-m->wl_short[1])/HIGHRES_WIDTH + 0.5) + 1;
if ((dp = m->data->get_doubles(m->data, &count, key_hg_factor)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->highgain = dp[0];
a1logd(p->log,2,"High gain = %.10f\n",m->highgain);
if ((m->lin0 = m->data->get_doubles(m->data, &m->nlin0, key_ng_lin)) == NULL
|| m->nlin0 < 1)
return I1PRO_HW_CALIBINFO;
if ((m->lin1 = m->data->get_doubles(m->data, &m->nlin1, key_hg_lin)) == NULL
|| m->nlin1 < 1)
return I1PRO_HW_CALIBINFO;
if (p->log->debug >= 2) {
char oline[200] = { '\000' }, *bp = oline;
bp += sprintf(bp,"Normal non-lin =");
for(i = 0; i < m->nlin0; i++)
bp += sprintf(bp," %1.10f",m->lin0[i]);
bp += sprintf(bp,"\n");
a1logd(p->log,2,oline);
bp = oline;
bp += sprintf(bp,"High Gain non-lin =");
for(i = 0; i < m->nlin1; i++)
bp += sprintf(bp," %1.10f",m->lin1[i]);
bp += sprintf(bp,"\n");
a1logd(p->log,2,oline);
}
if ((dp = m->data->get_doubles(m->data, &count, key_min_int_time)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->min_int_time = dp[0];
/* And then override it */
if (p->itype == instI1Pro2) {
m->min_int_time = m->subclkdiv2 * m->intclkp2; /* 0.004896 */
} else {
if (m->fwrev >= 301)
m->min_int_time = 0.004716;
else
m->min_int_time = 0.00884; /* == 1 sub clock */
}
if ((dp = m->data->get_doubles(m->data, &count, key_max_int_time)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->max_int_time = dp[0];
if ((m->mtx_o.index = m->data->get_ints(m->data, &count, key_mtx_index)) == NULL
|| count != m->nwav[0])
return I1PRO_HW_CALIBINFO;
if ((m->mtx_o.nocoef = m->data->get_ints(m->data, &count, key_mtx_nocoef)) == NULL
|| count != m->nwav[0])
return I1PRO_HW_CALIBINFO;
for (xcount = i = 0; i < m->nwav[0]; i++) /* Count number expected in matrix coeffs */
xcount += m->mtx_o.nocoef[i];
if ((m->mtx_o.coef = m->data->get_doubles(m->data, &count, key_mtx_coef)) == NULL
|| count != xcount)
return I1PRO_HW_CALIBINFO;
if ((m->white_ref[0] = m->data->get_doubles(m->data, &count, key_white_ref)) == NULL
|| count != m->nwav[0]) {
if (p->itype != instI1Monitor)
return I1PRO_HW_CALIBINFO;
m->white_ref[0] = NULL;
}
if ((m->emis_coef[0] = m->data->get_doubles(m->data, &count, key_emis_coef)) == NULL
|| count != m->nwav[0])
return I1PRO_HW_CALIBINFO;
if ((m->amb_coef[0] = m->data->get_doubles(m->data, &count, key_amb_coef)) == NULL
|| count != m->nwav[0]) {
if (p->itype != instI1Monitor
&& m->capabilities & 0x6000) /* Expect ambient calibration */
return I1PRO_HW_CALIBINFO;
m->amb_coef[0] = NULL;
}
/* Default to original EEProm raw to wav filters values*/
m->mtx[0][0] = m->mtx_o; /* Std res reflective */
m->mtx[0][1] = m->mtx_o; /* Std res emissive */
if ((ip = m->data->get_ints(m->data, &count, key_sens_target)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->sens_target = ip[0];
if ((ip = m->data->get_ints(m->data, &count, key_sens_dark)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->sens_dark = ip[0];
if ((ip = m->data->get_ints(m->data, &count, key_ng_sens_sat)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->sens_sat0 = ip[0];
if ((ip = m->data->get_ints(m->data, &count, key_hg_sens_sat)) == NULL || count < 1)
return I1PRO_HW_CALIBINFO;
m->sens_sat1 = ip[0];
a1logd(p->log,2,"sens_target %d, sens_dark %d, sens_sat0 %d, sens_sat1 %d\n",
m->sens_target, m->sens_dark, m->sens_sat0, m->sens_sat1);
/* Then read the log data. Don't fatal error if there is a problem with this. */
for (;;) {
/* Total Measure (Emis/Remis/Ambient/Trans/Cal) count */
if ((ip = m->data->get_ints(m->data, &count, key_meascount)) == NULL || count < 1)
break;
m->meascount = ip[0];
/* Remspotcal last calibration date */
if ((ip = m->data->get_ints(m->data, &count, key_caldate)) == NULL || count < 1)
break;
m->caldate = ip[0];
/* Remission spot measure count at last Remspotcal. */
if ((ip = m->data->get_ints(m->data, &count, key_calcount)) == NULL || count < 1)
break;
m->calcount = ip[0];
/* Last remision spot reading integration time */
if ((dp = m->data->get_doubles(m->data, &count, key_rpinttime)) == NULL || count < 1)
break;
m->rpinttime = dp[0];
/* Remission spot measure count */
if ((ip = m->data->get_ints(m->data, &count, key_rpcount)) == NULL || count < 1)
break;
m->rpcount = ip[0];
/* Remission scan measure count (??) */
if ((ip = m->data->get_ints(m->data, &count, key_acount)) == NULL || count < 1)
break;
m->acount = ip[0];
/* Total lamp usage time in seconds (??) */
if ((dp = m->data->get_doubles(m->data, &count, key_lampage)) == NULL || count < 1)
break;
m->lampage = dp[0];
a1logd(p->log,3,"Read log information OK\n");
break;
}
}
/* Read Rev E specific keys */
if (p->itype == instI1Pro2) {
int i, j;
double *dp;
int *sip;
unsigned int count;
int *ip;
/* Capability bits */
if ((ip = m->data->get_ints(m->data, &count, key2_capabilities)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
m->capabilities2 = *ip;
if (p->log->debug >= 2) {
a1logd(p->log,2,"Capabilities2 flag = 0x%x\n",m->capabilities2);
if (m->capabilities2 & I1PRO_CAP2_AMBIENT)
a1logd(p->log,2," Can read ambient\n");
if (m->capabilities2 & I1PRO_CAP2_WL_LED)
a1logd(p->log,2," Has Wavelength Calibration LED\n");
if (m->capabilities2 & I1PRO_CAP2_UV_LED)
a1logd(p->log,2," Has Ultra Violet LED\n");
if (m->capabilities2 & I1PRO_CAP2_ZEB_RUL)
a1logd(p->log,2," Has Zebra Ruler sensor\n");
if (m->capabilities2 & I1PRO_CAP2_IND_LED)
a1logd(p->log,2," Has user indicator LEDs\n");
if (m->capabilities2 & I1PRO_CAP2_UV_FILT)
a1logd(p->log,2," Is fitted with Ultra Violet Filter\n");
}
if (m->capabilities2 & I1PRO_CAP2_WL_LED) {
/* wavelength LED calibration integration time (0.56660) */
if ((dp = m->data->get_doubles(m->data, &count, key2_wlcal_intt)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
m->wl_cal_inttime = *dp;
/* Wavelength calibration minimum level */
if ((ip = m->data->get_ints(m->data, &count, key2_wlcal_minlev)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
/* Normalize it to 1.0 seconds (ie. 500/0.56660) */
m->wl_cal_min_level = (double)(*ip) / m->wl_cal_inttime;
/* wavelength LED measurement expected FWHM in nm */
if ((dp = m->data->get_doubles(m->data, &count, key2_wlcal_fwhm)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
m->wl_cal_fwhm = *dp;
/* wavelength LED measurement FWHM tollerance in nm */
if ((dp = m->data->get_doubles(m->data, &count, key2_wlcal_fwhm_tol)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
m->wl_cal_fwhm_tol = *dp;
/* wavelength LED reference spectrum */
if ((m->wl_led_spec = m->data->get_doubles(m->data, &m->wl_led_count, key2_wlcal_spec)) == NULL)
return I1PRO_HW_CALIBINFO;
/* wavelength LED spectraum reference offset */
if ((ip = m->data->get_ints(m->data, &count, key2_wlcal_ooff)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
m->wl_led_ref_off = *ip;
/* Hmm. this is odd, but it doesn't work correctly otherwise... */
m->wl_led_ref_off--;
/* wavelength calibration maximum error */
if ((dp = m->data->get_doubles(m->data, &count, key2_wlcal_max)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
m->wl_err_max = *dp;
}
/* CCD bin to wavelength polinomial */
if ((m->wlpoly1 = m->data->get_doubles(m->data, &count, key2_wlpoly_1)) == NULL || count != 4)
return I1PRO_HW_CALIBINFO;
if ((m->wlpoly2 = m->data->get_doubles(m->data, &count, key2_wlpoly_2)) == NULL || count != 4)
return I1PRO_HW_CALIBINFO;
/* Stray light compensation. Note that 16 bit numbers are signed. */
if ((sip = m->data->get_shorts(m->data, &count, key2_straylight)) == NULL
|| count != (36 * 36))
return I1PRO_HW_CALIBINFO;
/* stray light scale factor */
if ((dp = m->data->get_doubles(m->data, &count, key2_straylight_scale)) == NULL
|| count != 1)
return I1PRO_HW_CALIBINFO;
/* Convert from ints to floats */
m->straylight[0] = dmatrixz(0, 35, 0, 35);
for (i = 0; i < 36; i++) {
for (j = 0; j < 36; j++) {
m->straylight[0][i][j] = *dp * sip[i * 36 + j]/32767.0;
if (i == j)
m->straylight[0][i][j] += 1.0;
}
}
if (p->log->debug >= 7) {
a1logd(p->log,7,"Stray Light matrix:\n");
for(i = 0; i < 36; i++) {
double sum = 0.0;
for (j = 0; j < 36; j++) {
sum += m->straylight[0][i][j];
a1logd(p->log,7," Wt %d = %f\n",j, m->straylight[0][i][j]);
}
a1logd(p->log,7," Sum = %f\n",sum);
}
}
#ifdef NEVER
/* Plot raw2wav polinomials for Rev E */
{
double *xx;
double *y1, *y2; /* Rev E poly1 and poly2 */
double d1, d2;
int i, k;
xx = dvector(0, m->nraw); /* X index = raw bin */
y1 = dvector(0, m->nraw); /* Y = nm */
y2 = dvector(0, m->nraw); /* Y = nm */
d1 = d2 = 0.0;
for (i = 0; i < m->nraw; i++) {
double iv, v1, v2;
xx[i] = i;
iv = (double)(128-i);
for (v1 = m->wlpoly1[4-1], k = 4-2; k >= 0; k--)
v1 = v1 * iv + m->wlpoly1[k];
y1[i] = v1;
d1 += fabs(y2[i] - yy[i]);
for (v2 = m->wlpoly2[4-1], k = 4-2; k >= 0; k--)
v2 = v2 * iv + m->wlpoly2[k];
y2[i] = v2;
d2 += fabs(y3[i] - yy[i]);
// printf("ix %d, poly1 %f, poly2 %f, del12 %f\n",i, y1[i], y2[i], y2[i] - y1[i]);
}
printf("Avge del of poly1 = %f, poly2 = %f\n",d1/128.0, d2/128.0);
printf("CCD bin to wavelength mapping of RevE polinomial:\n");
do_plot6(xx, y1, y2, NULL, NULL, NULL, NULL, m->nraw);
free_dvector(xx, 0, m->nraw);
free_dvector(y1, 0, m->nraw);
free_dvector(y2, 0, m->nraw);
}
#endif
}
/* Set up the current state of each mode */
{
int i, j;
i1pro_state *s;
/* First set state to basic configuration */
/* (We assume it's been zero'd) */
for (i = 0; i < i1p_no_modes; i++) {
s = &m->ms[i];
s->mode = i;
/* Default to an emissive configuration */
s->targoscale = 1.0; /* Default full scale */
s->targmaxitime = 2.0; /* Maximum integration time to aim for */
s->targoscale2 = 0.15; /* Proportion of targoscale to meed etargmaxitime2 (!higain) */
s->gainmode = 0; /* Normal gain mode */
s->inttime = 0.5; /* Integration time */
s->lamptime = 0.50; /* Lamp turn on time (up to 1.0 sec is better, */
s->wl_valid = 0;
s->wl_led_off = m->wl_led_ref_off;
s->dark_valid = 0; /* Dark cal invalid */
s->dark_data = dvectorz(-1, m->nraw-1);
s->dark_data2 = dvectorz(-1, m->nraw-1);
s->dark_data3 = dvectorz(-1, m->nraw-1);
s->dark_data4 = dvectorz(-1, m->nraw-1);
s->cal_valid = 0; /* Scale cal invalid */
s->cal_factor[0] = dvectorz(0, m->nwav[0]-1);
s->cal_factor[1] = dvectorz(0, m->nwav[1]-1);
s->white_data = dvectorz(-1, m->nraw-1);
s->idark_valid = 0; /* Dark cal invalid */
s->idark_data = dmatrixz(0, 3, -1, m->nraw-1);
s->min_wl = 0.0; /* No minimum by default */
s->dark_int_time = DISP_INTT; /* 2.0 */
s->dark_int_time2 = DISP_INTT2; /* 0.8 */
s->dark_int_time3 = DISP_INTT3; /* 0.3 */
s->dark_int_time4 = DISP_INTT4; /* 0.1 */
s->idark_int_time[0] = s->idark_int_time[2] = m->min_int_time;
if (p->itype == instI1Pro2) {
s->idark_int_time[1] = s->idark_int_time[3] = ADARKINT_MAX2; /* 4.0 */
} else {
#ifdef USE_HIGH_GAIN_MODE
s->idark_int_time[1] = s->idark_int_time[3] = ADARKINT_MAX; /* 2.0 */
#else
s->idark_int_time[1] = s->idark_int_time[3] = ADARKINT_MAX2; /* 4.0 */
#endif
}
s->want_calib = 1; /* Do an initial calibration */
s->want_dcalib = 1;
}
/* Then add mode specific settings */
for (i = 0; i < i1p_no_modes; i++) {
s = &m->ms[i];
switch(i) {
case i1p_refl_spot:
s->targoscale = 1.0; /* Optimised sensor scaling to full */
s->reflective = 1;
s->adaptive = 1;
s->inttime = 0.02366; /* Should get this from the log ?? */
s->dark_int_time = s->inttime;
s->dadaptime = 0.10;
s->wadaptime = 0.10;
#ifdef USE_SPOT_OMD
s->lamptime = 0.20332; /* (Lamp doesn't stabilize with this) */
s->dcaltime = 0.02366;
s->wcaltime = 0.02366;
s->dreadtime = 0.02366;
s->wreadtime = 0.02366;
#else
#ifndef NEVER
s->lamptime = 0.25; /* This should give better accuracy */
s->dcaltime = 0.05; /* without increasing lamp usage much. */
s->wcaltime = 0.05; /* Make it too large (ie. 1.0 sec total) */
s->dreadtime = 0.05; /* and it will dirty the i1pro2 lamp quickly */
s->wreadtime = 0.05; /* though. */
#else
# pragma message("######### i1pro_imp.c Dirty Lamp timing !!!!! ########")
s->lamptime = 0.5; /* Dirty up the lamp. */
s->dcaltime = 2.0;
s->wcaltime = 2.0;
s->dreadtime = 2.0;
s->wreadtime = 2.0;
#endif
#endif
s->maxscantime = 0.0;
s->min_wl = HIGHRES_REF_MIN;/* Too much stray light below this */
/* given low illumination < 375nm */
break;
case i1p_refl_scan:
s->reflective = 1;
s->scan = 1;
s->adaptive = 1;
s->inttime = m->min_int_time; /* Maximize scan rate */
s->dark_int_time = s->inttime;
if (m->fwrev >= 301) /* (We're not using scan targoscale though) */
s->targoscale = 0.25;
else
s->targoscale = 0.5;
s->lamptime = 0.5; /* Lamp turn on time - lots to match scan */
s->dadaptime = 0.10;
s->wadaptime = 0.10;
s->dcaltime = 0.5;
s->wcaltime = 2.5; /* Lots to get lamp up to temp */
s->dreadtime = 0.10; /* and to match OMD scan cal. on time */
s->wreadtime = 0.10;
s->maxscantime = MAXSCANTIME;
s->min_wl = HIGHRES_REF_MIN; /* Too much stray light below this */
break;
case i1p_emiss_spot_na: /* Emissive spot not adaptive */
s->targoscale = 0.90; /* Allow extra 10% margine for drift */
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = EMIS_SCALE_FACTOR * m->emis_coef[0][j];
s->cal_valid = 1;
s->emiss = 1;
s->adaptive = 0;
s->inttime = DISP_INTT; /* Default disp integration time (ie. 2.0 sec) */
s->lamptime = 0.0;
s->dark_int_time = s->inttime;
s->dark_int_time2 = DISP_INTT2; /* Alternate disp integration time (ie. 0.8) */
s->dark_int_time3 = DISP_INTT3; /* Alternate disp integration time (ie. 0.3) */
s->dark_int_time4 = DISP_INTT4; /* Alternate disp integration time (ie. 0.1) */
s->dadaptime = 0.0;
s->wadaptime = 0.10;
s->dcaltime = DISP_INTT; /* ie. determines number of measurements */
s->dcaltime2 = DISP_INTT2 * 2; /* Make it 1.6 seconds (ie, 2 x 0.8 seconds) */
s->dcaltime3 = DISP_INTT3 * 3; /* Make it 0.9 seconds (ie, 3 x 0.3 seconds) */
s->dcaltime4 = DISP_INTT4 * 3; /* Make it 0.3 seconds (ie, 3 x 0.1 seconds) */
s->wcaltime = 0.0;
s->dreadtime = 0.0;
s->wreadtime = DISP_INTT;
s->maxscantime = 0.0;
break;
case i1p_emiss_spot:
s->targoscale = 0.90; /* Allow extra 10% margine for drift */
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = EMIS_SCALE_FACTOR * m->emis_coef[0][j];
s->cal_valid = 1;
s->emiss = 1;
s->adaptive = 1;
s->lamptime = 0.0;
s->dadaptime = 0.0;
s->wadaptime = 0.10;
s->dcaltime = 1.0;
s->wcaltime = 0.0;
s->dreadtime = 0.0;
s->wreadtime = 1.0;
s->maxscantime = 0.0;
break;
case i1p_emiss_scan:
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = EMIS_SCALE_FACTOR * m->emis_coef[0][j];
s->cal_valid = 1;
s->emiss = 1;
s->scan = 1;
s->adaptive = 1; /* ???? */
s->inttime = m->min_int_time; /* Maximize scan rate */
s->lamptime = 0.0;
s->dark_int_time = s->inttime;
if (m->fwrev >= 301)
s->targoscale = 0.25; /* (We're not using scan targoscale though) */
else
s->targoscale = 0.5;
s->dadaptime = 0.0;
s->wadaptime = 0.10;
s->dcaltime = 1.0;
s->wcaltime = 0.0;
s->dreadtime = 0.0;
s->wreadtime = 0.10;
s->maxscantime = MAXSCANTIME;
break;
case i1p_amb_spot:
#ifdef FAKE_AMBIENT
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = EMIS_SCALE_FACTOR * m->emis_coef[0][j];
s->cal_valid = 1;
#else
if (m->amb_coef[0] != NULL) {
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = AMB_SCALE_FACTOR * m->emis_coef[0][j] * m->amb_coef[0][j];
s->cal_valid = 1;
}
#endif
s->emiss = 1;
s->ambient = 1;
s->adaptive = 1;
s->lamptime = 0.0;
s->dadaptime = 0.0;
s->wadaptime = 0.10;
s->dcaltime = 1.0;
s->wcaltime = 0.0;
s->dreadtime = 0.0;
s->wreadtime = 1.0;
s->maxscantime = 0.0;
break;
case i1p_amb_flash:
/* This is intended for measuring flashes */
#ifdef FAKE_AMBIENT
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = EMIS_SCALE_FACTOR * m->emis_coef[0][j];
s->cal_valid = 1;
#else
if (m->amb_coef[0] != NULL) {
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = AMB_SCALE_FACTOR * m->emis_coef[0][j] * m->amb_coef[0][j];
s->cal_valid = 1;
}
#endif
s->emiss = 1;
s->ambient = 1;
s->scan = 1;
s->adaptive = 0;
s->flash = 1;
s->inttime = m->min_int_time; /* Maximize scan rate */
s->lamptime = 0.0;
s->dark_int_time = s->inttime;
if (m->fwrev >= 301)
s->targoscale = 0.25; /* (We're not using scan targoscale though) */
else
s->targoscale = 0.5;
s->dadaptime = 0.0;
s->wadaptime = 0.10;
s->dcaltime = 1.0;
s->wcaltime = 0.0;
s->dreadtime = 0.0;
s->wreadtime = 0.12;
s->maxscantime = MAXSCANTIME;
break;
case i1p_trans_spot:
s->trans = 1;
s->adaptive = 1;
s->lamptime = 0.0;
s->dadaptime = 0.10;
s->wadaptime = 0.10;
s->dcaltime = 1.0;
s->wcaltime = 1.0;
s->dreadtime = 0.0;
s->wreadtime = 1.0;
s->maxscantime = 0.0;
s->min_wl = HIGHRES_REF_MIN; /* Too much stray light below this */
break;
case i1p_trans_scan:
s->trans = 1;
s->scan = 1;
s->adaptive = 0;
s->inttime = m->min_int_time; /* Maximize scan rate */
s->dark_int_time = s->inttime;
if (m->fwrev >= 301) /* (We're not using scan targoscale though) */
s->targoscale = 0.25;
else
s->targoscale = 0.5;
s->lamptime = 0.0;
s->dadaptime = 0.10;
s->wadaptime = 0.10;
s->dcaltime = 1.0;
s->wcaltime = 1.0;
s->dreadtime = 0.00;
s->wreadtime = 0.10;
s->maxscantime = MAXSCANTIME;
s->min_wl = HIGHRES_REF_MIN; /* Too much stray light below this */
break;
}
}
}
if (p->itype != instI1Monitor /* Monitor doesn't have reflective cal */
&& p->itype != instI1Pro2) { /* Rev E mode has different calibration */
/* Restore the previous reflective spot calibration from the EEProm */
/* Get ready to operate the instrument */
if ((ev = i1pro_restore_refspot_cal(p)) != I1PRO_OK)
return ev;
}
#ifdef ENABLE_NONVCAL
/* Restore the all modes calibration from the local system */
i1pro_restore_calibration(p);
/* Touch it so that we know when the instrument was last opened */
i1pro_touch_calibration(p);
#endif
/* Get ready to operate the instrument */
if ((ev = i1pro_establish_high_power(p)) != I1PRO_OK)
return ev;
/* Get the current measurement parameters (why ?) */
if ((ev = i1pro_getmeasparams(p, &m->r_intclocks, &m->r_lampclocks, &m->r_nummeas, &m->r_measmodeflags)) != I1PRO_OK)
return ev;
if (p->log->verb >= 1) {
a1logv(p->log,1,"Instrument Type: %s\n",inst_name(p->itype));
a1logv(p->log,1,"Serial Number: %d\n",m->serno);
a1logv(p->log,1,"Firmware version: %d\n",m->fwrev);
a1logv(p->log,1,"CPLD version: %d\n",m->cpldrev);
if (p->itype == instI1Pro2)
a1logv(p->log,1,"Chip ID: %02x-%02x%02x%02x%02x%02x%02x%02x\n",
m->chipid[0], m->chipid[1], m->chipid[2], m->chipid[3],
m->chipid[4], m->chipid[5], m->chipid[6], m->chipid[7]);
a1logv(p->log,1,"Date manufactured: %d-%d-%d\n",
m->dom/1000000, (m->dom/10000) % 100, m->dom % 10000);
// Hmm. physfilt == 0x81 for instI1Monitor ???
a1logv(p->log,1,"U.V. filter ?: %s\n",m->physfilt == 0x82 ? "Yes" : "No");
a1logv(p->log,1,"Measure Ambient ?: %s\n",m->capabilities & 0x6000 ? "Yes" : "No");
a1logv(p->log,1,"Tot. Measurement Count: %d\n",m->meascount);
a1logv(p->log,1,"Remission Spot Count: %d\n",m->rpcount);
a1logv(p->log,1,"Remission Scan Count: %d\n",m->acount);
a1logv(p->log,1,"Date of last Remission spot cal: %s",ctime(&m->caldate));
a1logv(p->log,1,"Remission Spot Count at last cal: %d\n",m->calcount);
a1logv(p->log,1,"Total lamp usage: %f\n",m->lampage);
}
#ifdef NEVER
// ~~99 play with LED settings
if (p->itype == instI1Pro2) {
/* Makes it white */
unsigned char b2[] = {
0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x0a,
0x00, 0x00, 0x00, 0x01,
0x00, 0x36, 0x00,
0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x0a,
0xff, 0xff, 0xff, 0xff,
0x3f, 0x36, 0x40,
0x00, 0x00, 0x01
};
printf("~1 send led sequence length %d\n",sizeof(b2));
if ((ev = i1pro2_indLEDseq(p, b2, sizeof(b2))) != I1PRO_OK)
return ev;
}
/* Make sure LED sequence is finished, because it interferes with EEProm read! */
if ((ev = i1pro2_indLEDoff(p)) != I1PRO_OK)
return ev;
#endif
return ev;
}
/* Return a pointer to the serial number */
char *i1pro_imp_get_serial_no(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
return m->sserno;
}
/* Return non-zero if capable of ambient mode */
int i1pro_imp_ambient(i1pro *p) {
if (p->inited) {
i1proimp *m = (i1proimp *)p->m;
if (m->capabilities & 0x6000) /* Expect ambient calibration */
return 1;
#ifdef FAKE_AMBIENT
return 1;
#endif
return 0;
} else {
return 0;
}
}
/* Set the measurement mode. It may need calibrating */
i1pro_code i1pro_imp_set_mode(
i1pro *p,
i1p_mode mmode, /* Operating mode */
inst_mode mode /* Full mode mask for options */
) {
i1proimp *m = (i1proimp *)p->m;
a1logd(p->log,2,"i1pro_imp_set_mode called with mode no %d and mask 0x%x\n",mmode,m);
switch(mmode) {
case i1p_refl_spot:
case i1p_refl_scan:
if (p->itype == instI1Monitor)
return I1PRO_INT_ILLEGALMODE; /* i1Monitor can't do reflection */
break;
case i1p_emiss_spot_na:
case i1p_emiss_spot:
case i1p_emiss_scan:
break;
case i1p_amb_spot:
case i1p_amb_flash:
if (!i1pro_imp_ambient(p))
return I1PRO_INT_ILLEGALMODE;
break;
case i1p_trans_spot:
case i1p_trans_scan:
break;
default:
return I1PRO_INT_ILLEGALMODE;
}
m->mmode = mmode;
m->spec_en = (mode & inst_mode_spectral) != 0;
if ((mode & inst_mode_highres) != 0) {
i1pro_code rv;
if ((rv = i1pro_set_highres(p)) != I1PRO_OK)
return rv;
} else {
i1pro_set_stdres(p); /* Ignore any error */
}
m->uv_en = 0;
if (mmode == i1p_refl_spot
|| mmode == i1p_refl_scan)
m->uv_en = (mode & inst_mode_ref_uv) != 0;
return I1PRO_OK;
}
/* Return needed and available inst_cal_type's */
i1pro_code i1pro_imp_get_n_a_cals(i1pro *p, inst_cal_type *pn_cals, inst_cal_type *pa_cals) {
i1proimp *m = (i1proimp *)p->m;
i1pro_state *cs = &m->ms[m->mmode];
time_t curtime = time(NULL);
inst_cal_type n_cals = inst_calt_none;
inst_cal_type a_cals = inst_calt_none;
int wl_valid = cs->wl_valid; /* Locally timed out versions of valid state */
int idark_valid = cs->idark_valid;
int dark_valid = cs->dark_valid;
int cal_valid = cs->cal_valid;
a1logd(p->log,2,"i1pro_imp_get_n_a_cals: checking mode %d\n",m->mmode);
/* Timout calibrations that are too old */
if (m->capabilities2 & I1PRO_CAP2_WL_LED) {
if ((curtime - cs->wldate) > WLCALTOUT) {
a1logd(p->log,2,"Invalidating wavelength cal as %d secs from last cal\n",curtime - cs->wldate);
wl_valid = 0;
}
}
if ((curtime - cs->iddate) > ((p->itype == instI1Pro2) ? DCALTOUT2 : DCALTOUT)) {
a1logd(p->log,2,"Invalidating adaptive dark cal as %d secs from last cal\n",curtime - cs->iddate);
idark_valid = 0;
}
if ((curtime - cs->ddate) > ((p->itype == instI1Pro2) ? DCALTOUT2 : DCALTOUT)) {
a1logd(p->log,2,"Invalidating dark cal as %d secs from last cal\n",curtime - cs->ddate);
dark_valid = 0;
}
if (!cs->emiss && (curtime - cs->cfdate) > WCALTOUT) {
a1logd(p->log,2,"Invalidating white cal as %d secs from last cal\n",curtime - cs->cfdate);
cal_valid = 0;
}
#ifdef NEVER
printf("~1 reflective = %d, adaptive = %d, emiss = %d, trans = %d, scan = %d\n",
cs->reflective, cs->adaptive, cs->emiss, cs->trans, cs->scan);
printf("~1 idark_valid = %d, dark_valid = %d, cal_valid = %d\n",
idark_valid,dark_valid,cal_valid);
printf("~1 want_calib = %d, want_dcalib = %d, noinitcalib = %d\n",
cs->want_calib,cs->want_dcalib, m->noinitcalib);
#endif /* NEVER */
if (m->capabilities2 & I1PRO_CAP2_WL_LED) {
if (!wl_valid
|| (cs->want_dcalib && !m->noinitcalib)) // ?? want_dcalib ??
n_cals |= inst_calt_wavelength;
a_cals |= inst_calt_wavelength;
}
if (cs->reflective) {
if (!dark_valid
|| (cs->want_dcalib && !m->noinitcalib))
n_cals |= inst_calt_ref_dark;
a_cals |= inst_calt_ref_dark;
if (!cal_valid
|| (cs->want_calib && !m->noinitcalib))
n_cals |= inst_calt_ref_white;
a_cals |= inst_calt_ref_white;
}
if (cs->emiss) {
if ((!cs->adaptive && !dark_valid)
|| (cs->adaptive && !idark_valid)
|| (cs->want_dcalib && !m->noinitcalib))
n_cals |= inst_calt_em_dark;
a_cals |= inst_calt_em_dark;
}
if (cs->trans) {
if ((!cs->adaptive && !dark_valid)
|| (cs->adaptive && !idark_valid)
|| (cs->want_dcalib && !m->noinitcalib))
n_cals |= inst_calt_trans_dark;
a_cals |= inst_calt_trans_dark;
if (!cal_valid
|| (cs->want_calib && !m->noinitcalib))
n_cals |= inst_calt_trans_vwhite;
a_cals |= inst_calt_trans_vwhite;
}
if (cs->emiss && !cs->adaptive && !cs->scan) {
if (!cs->done_dintsel)
n_cals |= inst_calt_emis_int_time;
a_cals |= inst_calt_emis_int_time;
}
/* Special case high res. emissive cal fine calibration, */
/* needs reflective cal. */
/* Hmmm. Should we do this every time for emission, in case */
/* we switch to hires mode ??? */
if ((cs->emiss || cs->trans) /* We're in an emissive mode */
&& m->hr_inited /* and hi-res has been setup */
&& (!m->emis_hr_cal || (n_cals & inst_calt_em_dark)) /* and the emis cal hasn't been */
/* fine tuned or we will be doing a dark cal */
&& p->itype != instI1Monitor) { /* i1Monitor doesn't have reflective cal capability */
n_cals |= inst_calt_ref_white; /* Need a reflective white calibration */
a_cals |= inst_calt_ref_white;
}
if (pn_cals != NULL)
*pn_cals = n_cals;
if (pa_cals != NULL)
*pa_cals = a_cals;
a1logd(p->log,3,"i1pro_imp_get_n_a_cals: returning n_cals 0x%x, a_cals 0x%x\n",n_cals, a_cals);
return I1PRO_OK;
}
/* - - - - - - - - - - - - - - - - */
/* Calibrate for the current mode. */
/* Request an instrument calibration of the current mode. */
i1pro_code i1pro_imp_calibrate(
i1pro *p,
inst_cal_type *calt, /* Calibration type to do/remaining */
inst_cal_cond *calc, /* Current condition/desired condition */
inst_calc_id_type *idtype, /* Condition identifier type */
char id[CALIDLEN] /* Condition identifier (ie. white reference ID) */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
int mmode = m->mmode;
i1pro_state *cs = &m->ms[m->mmode];
int sx1, sx2, sx3, sx;
time_t cdate = time(NULL);
int nummeas = 0;
int ltocmode = 0; /* 1 = Lamp turn on compensation mode */
int i, k;
inst_cal_type needed, available;
a1logd(p->log,2,"i1pro_imp_calibrate called with calt 0x%x, calc 0x%x\n",*calt, *calc);
if ((ev = i1pro_imp_get_n_a_cals(p, &needed, &available)) != I1PRO_OK)
return ev;
/* Translate inst_calt_all/needed into something specific */
if (*calt == inst_calt_all
|| *calt == inst_calt_needed
|| *calt == inst_calt_available) {
if (*calt == inst_calt_all)
*calt = (needed & inst_calt_n_dfrble_mask) | inst_calt_ap_flag;
else if (*calt == inst_calt_needed)
*calt = needed & inst_calt_n_dfrble_mask;
else if (*calt == inst_calt_available)
*calt = available & inst_calt_n_dfrble_mask;
a1logd(p->log,4,"i1pro_imp_calibrate: doing calt 0x%x\n",*calt);
if ((*calt & inst_calt_n_dfrble_mask) == 0) /* Nothing todo */
return I1PRO_OK;
}
/* See if it's a calibration we understand */
if (*calt & ~available & inst_calt_all_mask) {
a1logd(p->log,4,"i1pro_imp_calibrate: unsupported, calt 0x%x, available 0x%x\n",*calt,available);
return I1PRO_UNSUPPORTED;
}
if (*calt & inst_calt_ap_flag) {
sx1 = 0; sx2 = sx3 = i1p_no_modes; /* Go through all the modes */
} else {
/* Special case - doing reflective cal. to fix emiss hires */
if ((cs->emiss || cs->trans) /* We're in an emissive mode */
&& (*calt & inst_calt_ref_white)) { /* but we're asked for a ref white cal */
sx1 = m->mmode; sx2 = sx1 + 1; /* Just current mode */
sx3 = i1p_refl_spot; /* no extra mode */
} else {
sx1 = m->mmode; sx2 = sx1 + 1; /* Just current mode */
sx3 = i1p_no_modes; /* no extra mode */
}
}
/* Go through the modes we are going to cover */
for (sx = sx1; sx < sx2; (++sx >= sx2 && sx3 != i1p_no_modes) ? sx = sx3, sx2 = sx+1, sx3 = i1p_no_modes : 0) {
i1pro_state *s = &m->ms[sx];
m->mmode = sx; /* A lot of functions we call rely on this */
a1logd(p->log,2,"\nCalibrating mode %d\n", s->mode);
/* Sanity check scan mode settings, in case something strange */
/* has been restored from the persistence file. */
if (s->scan && s->inttime > (2.1 * m->min_int_time)) {
s->inttime = m->min_int_time; /* Maximize scan rate */
}
/* Wavelength calibration: */
if ((m->capabilities2 & I1PRO_CAP2_WL_LED)
&& (*calt & (inst_calt_wavelength | inst_calt_ap_flag))
&& ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white
|| (*calc & inst_calc_cond_mask) == inst_calc_man_am_dark)) {
double *wlraw;
double optscale;
double *abswav;
a1logd(p->log,2,"\nDoing wavelength calibration\n");
wlraw = dvectorz(-1, m->nraw-1);
if ((ev = i1pro2_wl_measure(p, wlraw, &optscale, &m->wl_cal_inttime, 1.0)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro2_wl_measure() failed\n");
return ev;
}
/* Find the best fit of the measured values to the reference spectrum */
if ((ev = i1pro2_match_wl_meas(p, &cs->wl_led_off, wlraw)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro2_match_wl_meas() failed\n");
return ev;
}
free_dvector(wlraw, -1, m->nraw-1);
/* Compute normal res. emissive/transmissive wavelength corrected filters */
if ((ev = i1pro_compute_wav_filters(p, 0, 0)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_compute_wav_filters() failed\n");
return ev;
}
/* Compute normal res. reflective wavelength corrected filters */
if ((ev = i1pro_compute_wav_filters(p, 0, 1)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_compute_wav_filters() failed\n");
return ev;
}
/* Re-compute high res. wavelength corrected filters */
if (m->hr_inited && (ev = i1pro_create_hr(p)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_create_hr() failed\n");
return ev;
}
cs->wl_valid = 1;
cs->wldate = cdate;
*calt &= ~inst_calt_wavelength;
/* Save the calib to all modes */
a1logd(p->log,5,"Saving wavelength calib to similar modes\n");
for (i = 0; i < i1p_no_modes; i++) {
i1pro_state *ss = &m->ms[i];
if (ss == cs)
continue;
ss->wl_valid = cs->wl_valid;
ss->wldate = cs->wldate;
ss->wl_led_off = cs->wl_led_off;
}
}
/* Fixed int. time black calibration: */
/* Reflective uses on the fly black, even for adaptive. */
/* Emiss and trans can use single black ref only for non-adaptive */
/* using the current inttime & gainmode, while display mode */
/* does an extra fallback black cal for bright displays. */
if ((*calt & (inst_calt_ref_dark
| inst_calt_em_dark
| inst_calt_trans_dark | inst_calt_ap_flag))
&& ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white /* Any condition conducive to dark calib */
|| (*calc & inst_calc_cond_mask) == inst_calc_man_em_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_am_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_trans_dark)
&& ( s->reflective
|| (s->emiss && !s->adaptive && !s->scan)
|| (s->trans && !s->adaptive))) {
int stm;
int usesdct234 = 0; /* Is a mode that uses dcaltime2, 3 & 4 */
if (s->emiss && !s->adaptive && !s->scan)
usesdct234 = 1;
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->inttime);
a1logd(p->log,2,"\nDoing initial black calibration with dcaltime %f, int_time %f, nummeas %d, gainmode %d\n", s->dcaltime, s->inttime, nummeas, s->gainmode);
stm = msec_time();
if ((ev = i1pro_dark_measure(p, s->dark_data,
nummeas, &s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
a1logd(p->log,2,"Execution time of dark calib time %f sec = %d msec\n",s->inttime,msec_time() - stm);
/* Special display mode alternate integration time black measurement */
if (usesdct234) {
nummeas = i1pro_comp_nummeas(p, s->dcaltime2, s->dark_int_time2);
a1logd(p->log,2,"Doing 2nd initial black calibration with dcaltime2 %f, dark_int_time2 %f, nummeas %d, gainmode %d\n", s->dcaltime2, s->dark_int_time2, nummeas, s->gainmode);
stm = msec_time();
if ((ev = i1pro_dark_measure(p, s->dark_data2,
nummeas, &s->dark_int_time2, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
a1logd(p->log,2,"Execution time of 2nd dark calib time %f sec = %d msec\n",s->inttime,msec_time() - stm);
nummeas = i1pro_comp_nummeas(p, s->dcaltime3, s->dark_int_time3);
a1logd(p->log,2,"Doing 3rd initial black calibration with dcaltime3 %f, dark_int_time3 %f, nummeas %d, gainmode %d\n", s->dcaltime3, s->dark_int_time3, nummeas, s->gainmode);
nummeas = i1pro_comp_nummeas(p, s->dcaltime3, s->dark_int_time3);
stm = msec_time();
if ((ev = i1pro_dark_measure(p, s->dark_data3,
nummeas, &s->dark_int_time3, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
a1logd(p->log,2,"Execution time of 3rd dark calib time %f sec = %d msec\n",s->inttime,msec_time() - stm);
nummeas = i1pro_comp_nummeas(p, s->dcaltime4, s->dark_int_time4);
a1logd(p->log,2,"Doing 4th initial black calibration with dcaltime4 %f, dark_int_time4 %f, nummeas %d, gainmode %d\n", s->dcaltime4, s->dark_int_time4, nummeas, s->gainmode);
nummeas = i1pro_comp_nummeas(p, s->dcaltime4, s->dark_int_time4);
stm = msec_time();
if ((ev = i1pro_dark_measure(p, s->dark_data4,
nummeas, &s->dark_int_time4, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
a1logd(p->log,2,"Execution time of 4rd dark calib time %f sec = %d msec\n",s->inttime,msec_time() - stm);
}
s->dark_valid = 1;
s->want_dcalib = 0;
s->ddate = cdate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
*calt &= ~(inst_calt_ref_dark
| inst_calt_em_dark
| inst_calt_trans_dark);
/* Save the calib to all similar modes */
for (i = 0; i < i1p_no_modes; i++) {
i1pro_state *ss = &m->ms[i];
if (ss == s || ss->ddate == cdate)
continue;
if (( s->reflective
|| (ss->emiss && !ss->adaptive && !ss->scan)
|| (ss->trans && !ss->adaptive))
&& ss->dark_int_time == s->dark_int_time
&& ss->dark_gain_mode == s->dark_gain_mode) {
ss->dark_valid = s->dark_valid;
ss->want_dcalib = s->want_dcalib;
ss->ddate = s->ddate;
ss->dark_int_time = s->dark_int_time;
ss->dark_gain_mode = s->dark_gain_mode;
for (k = -1; k < m->nraw; k++)
ss->dark_data[k] = s->dark_data[k];
/* If this is a mode with dark_data2/3/4, tranfer it too */
if (usesdct234 && ss->emiss && !ss->adaptive && !ss->scan) {
ss->dark_int_time2 = s->dark_int_time2;
ss->dark_int_time3 = s->dark_int_time3;
ss->dark_int_time4 = s->dark_int_time4;
for (k = -1; k < m->nraw; k++) {
ss->dark_data2[k] = s->dark_data2[k];
ss->dark_data3[k] = s->dark_data3[k];
ss->dark_data4[k] = s->dark_data4[k];
}
}
}
}
}
/* Emissive scan black calibration: */
/* Emsissive scan (flash) uses the fastest possible scan rate (??) */
if ((*calt & (inst_calt_em_dark | inst_calt_ap_flag))
&& ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white /* Any condition conducive to dark calib */
|| (*calc & inst_calc_cond_mask) == inst_calc_man_em_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_am_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_trans_dark)
&& (s->emiss && !s->adaptive && s->scan)) {
int stm;
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->inttime);
a1logd(p->log,2,"\nDoing emissive (flash) black calibration with dcaltime %f, int_time %f, nummeas %d, gainmode %d\n", s->dcaltime, s->inttime, nummeas, s->gainmode);
stm = msec_time();
if ((ev = i1pro_dark_measure(p, s->dark_data,
nummeas, &s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
a1logd(p->log,2,"Execution time of dark calib time %f sec = %d msec\n",s->inttime,msec_time() - stm);
s->dark_valid = 1;
s->want_dcalib = 0;
s->ddate = cdate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
*calt &= ~inst_calt_em_dark;
/* Save the calib to all similar modes */
/* We're assuming they have the same int times */
a1logd(p->log,5,"Saving emissive scan black calib to similar modes\n");
for (i = 0; i < i1p_no_modes; i++) {
i1pro_state *ss = &m->ms[i];
if (ss == s || ss->ddate == s->ddate)
continue;
if (ss->emiss && !ss->adaptive && ss->scan) {
ss->dark_valid = s->dark_valid;
ss->want_dcalib = s->want_dcalib;
ss->ddate = s->ddate;
ss->dark_int_time = s->dark_int_time;
ss->dark_gain_mode = s->dark_gain_mode;
for (k = -1; k < m->nraw; k++)
ss->dark_data[k] = s->dark_data[k];
}
}
}
/* Adaptive black calibration: */
/* Deal with an emmissive/transmissive black reference */
/* in non-scan mode, where the integration time and gain may vary. */
/* The black is interpolated from readings with two extreme integration times */
if ((*calt & (inst_calt_ref_dark
| inst_calt_em_dark
| inst_calt_trans_dark | inst_calt_ap_flag))
/* Any condition conducive to dark calib */
&& ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white
|| (*calc & inst_calc_cond_mask) == inst_calc_man_em_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_am_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_trans_dark)
&& ((s->emiss && s->adaptive && !s->scan)
|| (s->trans && s->adaptive && !s->scan))) {
int i, j, k;
a1logd(p->log,2,"\nDoing emis/trans adapative black calibration\n");
/* Adaptive where we can't measure the black reference on the fly, */
/* so bracket it and interpolate. */
/* The black reference is probably temperature dependent, but */
/* there's not much we can do about this. */
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->idark_int_time[0]);
a1logd(p->log,2,"\nDoing adaptive interpolated black calibration, dcaltime %f, idark_int_time[0] %f, nummeas %d, gainmode %d\n", s->dcaltime, s->idark_int_time[0], nummeas, 0);
if ((ev = i1pro_dark_measure(p, s->idark_data[0],
nummeas, &s->idark_int_time[0], 0)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->idark_int_time[1]);
a1logd(p->log,2,"Doing adaptive interpolated black calibration, dcaltime %f, idark_int_time[1] %f, nummeas %d, gainmode %d\n", s->dcaltime, s->idark_int_time[1], nummeas, 0);
if ((ev = i1pro_dark_measure(p, s->idark_data[1],
nummeas, &s->idark_int_time[1], 0)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
#ifdef USE_HIGH_GAIN_MODE
if (p->itype != instI1Pro2) { /* Rev E doesn't have high gain mode */
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->idark_int_time[2]);
a1logd(p->log,2,"Doing adaptive interpolated black calibration, dcaltime %f, idark_int_time[2] %f, nummeas %d, gainmode %d\n", s->dcaltime, s->idark_int_time[2], nummeas, 1);
if ((ev = i1pro_dark_measure(p, s->idark_data[2],
nummeas, &s->idark_int_time[2], 1)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
a1logd(p->log,2,"Doing adaptive interpolated black calibration, dcaltime %f, idark_int_time[3] %f, nummeas %d, gainmode %d\n", s->dcaltime, s->idark_int_time[3], nummeas, 1);
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->idark_int_time[3]);
if ((ev = i1pro_dark_measure(p, s->idark_data[3],
nummeas, &s->idark_int_time[3], 1)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
}
#endif /* USE_HIGH_GAIN_MODE */
i1pro_prepare_idark(p);
s->idark_valid = 1;
s->iddate = cdate;
if ((ev = i1pro_interp_dark(p, s->dark_data, s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
s->dark_valid = 1;
s->want_dcalib = 0;
s->ddate = s->iddate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
*calt &= ~(inst_calt_ref_dark
| inst_calt_em_dark
| inst_calt_trans_dark);
/* Save the calib to all similar modes */
/* We're assuming they have the same int times */
a1logd(p->log,5,"Saving adaptive black calib to similar modes\n");
for (i = 0; i < i1p_no_modes; i++) {
i1pro_state *ss = &m->ms[i];
if (ss == s || ss->iddate == s->iddate)
continue;
if ((ss->emiss || ss->trans) && ss->adaptive && !ss->scan) {
ss->idark_valid = s->idark_valid;
ss->want_dcalib = s->want_dcalib;
ss->iddate = s->iddate;
ss->dark_int_time = s->dark_int_time;
ss->dark_gain_mode = s->dark_gain_mode;
#ifdef USE_HIGH_GAIN_MODE
for (j = 0; j < (p->itype != instI1Pro2) ? 4 : 2; j++)
#else
for (j = 0; j < 2; j++)
#endif
{
ss->idark_int_time[j] = s->idark_int_time[j];
for (k = -1; k < m->nraw; k++)
ss->idark_data[j][k] = s->idark_data[j][k];
}
}
}
a1logd(p->log,5,"Done adaptive interpolated black calibration\n");
/* Test accuracy of dark level interpolation */
#ifdef TEST_DARK_INTERP
{
double tinttime;
double ref[128], interp[128];
// fprintf(stderr,"Normal gain offsets:\n");
// plot_raw(s->idark_data[0]);
// fprintf(stderr,"Normal gain multiplier:\n");
// plot_raw(s->idark_data[1]);
#ifdef DUMP_DARKM
extern int ddumpdarkm;
ddumpdarkm = 1;
#endif
for (tinttime = m->min_int_time; ; tinttime *= 2.0) {
if (tinttime >= m->max_int_time)
tinttime = m->max_int_time;
nummeas = i1pro_comp_nummeas(p, s->dcaltime, tinttime);
if ((ev = i1pro_dark_measure(p, ref, nummeas, &tinttime, 0)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
i1pro_interp_dark(p, interp, tinttime, 0);
#ifdef DEBUG
fprintf(stderr,"Low gain ref vs. interp dark offset for inttime %f:\n",tinttime);
plot_raw2(ref, interp);
#endif
if ((tinttime * 1.1) > m->max_int_time)
break;
}
#ifdef DUMP_DARKM
ddumpdarkm = 0;
#endif
#ifdef USE_HIGH_GAIN_MODE
if (p->itype != instI1Pro2) { /* Rev E doesn't have high gain mode */
// fprintf(stderr,"High gain offsets:\n");
// plot_raw(s->idark_data[2]);
// fprintf(stderr,"High gain multiplier:\n");
// plot_raw(s->idark_data[3]);
for (tinttime = m->min_int_time; ; tinttime *= 2.0) {
if (tinttime >= m->max_int_time)
tinttime = m->max_int_time;
nummeas = i1pro_comp_nummeas(p, s->dcaltime, tinttime);
if ((ev = i1pro_dark_measure(p, ref, nummeas, &tinttime, 1)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
i1pro_interp_dark(p, interp, tinttime, 1);
#ifdef DEBUG
fprintf(stderr,"High gain ref vs. interp dark offset for inttime %f:\n",tinttime);
plot_raw2(ref, interp);
#endif
if ((tinttime * 1.1) > m->max_int_time)
break;
}
}
#endif /* USE_HIGH_GAIN_MODE */
}
#endif /* NEVER */
}
/* Deal with an emissive/transmisive adaptive black reference */
/* when in scan mode. */
if ((*calt & (inst_calt_ref_dark
| inst_calt_em_dark
| inst_calt_trans_dark | inst_calt_ap_flag))
/* Any condition conducive to dark calib */
&& ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white
|| (*calc & inst_calc_cond_mask) == inst_calc_man_em_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_am_dark
|| (*calc & inst_calc_cond_mask) == inst_calc_man_trans_dark)
&& ((s->emiss && s->adaptive && s->scan)
|| (s->trans && s->adaptive && s->scan))) {
int j;
a1logd(p->log,2,"\nDoing emis/trans adapative scan mode black calibration\n");
/* We know scan is locked to the minimum integration time, */
/* so we can measure the dark data at that integration time, */
/* but we don't know what gain mode will be used, so measure both, */
/* and choose the appropriate one on the fly. */
s->idark_int_time[0] = s->inttime;
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->idark_int_time[0]);
a1logd(p->log,2,"\nDoing adaptive scan black calibration, dcaltime %f, idark_int_time[0] %f, nummeas %d, gainmode %d\n", s->dcaltime, s->idark_int_time[0], nummeas, s->gainmode);
if ((ev = i1pro_dark_measure(p, s->idark_data[0],
nummeas, &s->idark_int_time[0], 0)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
#ifdef USE_HIGH_GAIN_MODE
if (p->itype != instI1Pro2) { /* Rev E doesn't have high gain mode */
s->idark_int_time[2] = s->inttime;
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->idark_int_time[2]);
a1logd(p->log,2,"Doing adaptive scan black calibration, dcaltime %f, idark_int_time[2] %f, nummeas %d, gainmode %d\n", s->dcaltime, s->idark_int_time[2], nummeas, s->gainmode);
if ((ev = i1pro_dark_measure(p, s->idark_data[2],
nummeas, &s->idark_int_time[2], 1)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
}
#endif
s->idark_valid = 1;
s->iddate = cdate;
#ifdef USE_HIGH_GAIN_MODE
if (s->gainmode) {
for (j = -1; j < m->nraw; j++)
s->dark_data[j] = s->idark_data[2][j];
} else
#endif
{
for (j = -1; j < m->nraw; j++)
s->dark_data[j] = s->idark_data[0][j];
}
s->dark_valid = 1;
s->want_dcalib = 0;
s->ddate = s->iddate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
*calt &= ~(inst_calt_ref_dark
| inst_calt_em_dark
| inst_calt_trans_dark);
a1logd(p->log,2,"Done adaptive scan black calibration\n");
/* Save the calib to all similar modes */
/* We're assuming they have the same int times */
a1logd(p->log,5,"Saving adaptive scan black calib to similar modes\n");
for (i = 0; i < i1p_no_modes; i++) {
i1pro_state *ss = &m->ms[i];
if (ss == s || ss->iddate == s->iddate)
continue;
if ((ss->emiss || ss->trans) && ss->adaptive && s->scan) {
ss->idark_valid = s->idark_valid;
ss->want_dcalib = s->want_dcalib;
ss->iddate = s->iddate;
ss->dark_int_time = s->dark_int_time;
ss->dark_gain_mode = s->dark_gain_mode;
#ifdef USE_HIGH_GAIN_MODE
for (j = 0; j < (p->itype != instI1Pro2) ? 4 : 2; j += 2)
#else
for (j = 0; j < 2; j += 2)
#endif
{
ss->idark_int_time[j] = s->idark_int_time[j];
for (k = -1; k < m->nraw; k++)
ss->idark_data[j][k] = s->idark_data[j][k];
}
}
}
}
/* If we are doing a white reference calibrate */
if ((*calt & (inst_calt_ref_white
| inst_calt_trans_vwhite | inst_calt_ap_flag))
&& (((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white && s->reflective)
|| ((*calc & inst_calc_cond_mask) == inst_calc_man_trans_white && s->trans))) {
double scale;
a1logd(p->log,2,"\nDoing initial white calibration with current inttime %f, gainmode %d\n",
s->inttime, s->gainmode);
nummeas = i1pro_comp_nummeas(p, s->wcaltime, s->inttime);
ev = i1pro_whitemeasure(p, s->cal_factor[0], s->cal_factor[1], s->white_data, &scale, nummeas,
&s->inttime, s->gainmode, s->scan ? 1.0 : s->targoscale, 0);
if (ev == I1PRO_RD_SENSORSATURATED) {
scale = 0.0; /* Signal it this way */
ev = I1PRO_OK;
}
if (ev != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
/* For non-scan modes, we adjust the integration time to avoid saturation, */
/* and to try and match the target optimal sensor value */
if (!s->scan) {
/* If it's adaptive and not good, or if it's not adaptive and even worse, */
/* or if we're using lamp dynamic compensation for reflective scan, */
/* change the parameters until the white is optimal. */
if ((s->adaptive && (scale < 0.95 || scale > 1.05))
|| (scale < 0.3 || scale > 2.0)) {
/* Need to have done adaptive black measure to change inttime/gain params */
if ((*calc & inst_calc_cond_mask) != inst_calc_man_ref_white
&& !s->idark_valid) {
m->mmode = mmode; /* Restore actual mode */
return I1PRO_RD_TRANSWHITERANGE;
}
if (scale == 0.0) { /* If sensor was saturated */
s->inttime = m->min_int_time;
s->gainmode = 0;
s->dark_valid = 0;
if (!s->emiss)
s->cal_valid = 0;
if ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white) {
nummeas = i1pro_comp_nummeas(p, s->dadaptime, s->inttime);
a1logd(p->log,2,"Doing another black calibration with dadaptime %f, min inttime %f, nummeas %d, gainmode %d\n", s->dadaptime, s->inttime, nummeas, s->gainmode);
if ((ev = i1pro_dark_measure(p, s->dark_data,
nummeas, &s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
} else if (s->idark_valid) {
/* compute interpolated dark refence for chosen inttime & gainmode */
a1logd(p->log,2,"Interpolate dark calibration reference\n");
if ((ev = i1pro_interp_dark(p, s->dark_data,
s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
s->dark_valid = 1;
s->ddate = s->iddate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
} else {
m->mmode = mmode; /* Restore actual mode */
return I1PRO_INT_NOINTERPDARK;
}
a1logd(p->log,2,"Doing another white calibration with min inttime %f, gainmode %d\n",
s->inttime,s->gainmode);
nummeas = i1pro_comp_nummeas(p, s->wadaptime, s->inttime);
if ((ev = i1pro_whitemeasure(p, s->cal_factor[0], s->cal_factor[1], s->white_data,
&scale, nummeas, &s->inttime, s->gainmode, s->targoscale, 0))
!= I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
}
/* Compute a new integration time and gain mode */
/* in order to optimise the sensor values. Error if can't get */
/* scale we want. */
if ((ev = i1pro_optimise_sensor(p, &s->inttime, &s->gainmode,
s->inttime, s->gainmode, s->trans, 0, s->targoscale, scale)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
a1logd(p->log,2,"Computed optimal white inttime %f and gainmode %d\n",
s->inttime,s->gainmode);
if ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white) {
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->inttime);
a1logd(p->log,2,"Doing final black calibration with dcaltime %f, opt inttime %f, nummeas %d, gainmode %d\n", s->dcaltime, s->inttime, nummeas, s->gainmode);
if ((ev = i1pro_dark_measure(p, s->dark_data,
nummeas, &s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
s->dark_valid = 1;
s->ddate = cdate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
} else if (s->idark_valid) {
/* compute interpolated dark refence for chosen inttime & gainmode */
a1logd(p->log,2,"Interpolate dark calibration reference\n");
if ((ev = i1pro_interp_dark(p, s->dark_data,
s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
s->dark_valid = 1;
s->ddate = s->iddate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
} else {
m->mmode = mmode; /* Restore actual mode */
return I1PRO_INT_NOINTERPDARK;
}
a1logd(p->log,2,"Doing final white calibration with opt int_time %f, gainmode %d\n",
s->inttime,s->gainmode);
nummeas = i1pro_comp_nummeas(p, s->wcaltime, s->inttime);
if ((ev = i1pro_whitemeasure(p, s->cal_factor[0], s->cal_factor[1], s->white_data,
&scale, nummeas, &s->inttime, s->gainmode, s->targoscale, ltocmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
}
/* For scan we take a different approach. We try and use the minimum possible */
/* integration time so as to maximize sampling rate, and adjust the gain */
/* if necessary. */
} else if (s->adaptive) {
int j;
if (scale == 0.0) { /* If sensor was saturated */
a1logd(p->log,3,"Scan illuminant is saturating sensor\n");
if (s->gainmode == 0) {
m->mmode = mmode; /* Restore actual mode */
return I1PRO_RD_SENSORSATURATED; /* Nothing we can do */
}
a1logd(p->log,3,"Switching to low gain mode\n");
s->gainmode = 0;
/* Measure white again with low gain */
nummeas = i1pro_comp_nummeas(p, s->wcaltime, s->inttime);
if ((ev = i1pro_whitemeasure(p, s->cal_factor[0], s->cal_factor[1], s->white_data,
&scale, nummeas, &s->inttime, s->gainmode, 1.0, 0)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
} else if (p->itype != instI1Pro2 && s->gainmode == 0 && scale > m->highgain) {
#ifdef USE_HIGH_GAIN_MODE
a1logd(p->log,3,"Scan signal is so low we're switching to high gain mode\n");
s->gainmode = 1;
/* Measure white again with high gain */
nummeas = i1pro_comp_nummeas(p, s->wcaltime, s->inttime);
if ((ev = i1pro_whitemeasure(p, s->cal_factor[0], s->cal_factor[1], s->white_data,
&scale, nummeas, &s->inttime, s->gainmode, 1.0, 0)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
#endif /* USE_HIGH_GAIN_MODE */
}
a1logd(p->log,2,"After scan gain adaption scale = %f\n",scale);
if (scale > 6.0) {
m->transwarn |= 2;
a1logd(p->log,2, "scan white reference is not bright enough by %f\n",scale);
}
if ((*calc & inst_calc_cond_mask) == inst_calc_man_ref_white) {
nummeas = i1pro_comp_nummeas(p, s->dcaltime, s->inttime);
a1logd(p->log,2,"Doing final black calibration with dcaltime %f, opt inttime %f, nummeas %d, gainmode %d\n", s->dcaltime, s->inttime, nummeas, s->gainmode);
if ((ev = i1pro_dark_measure(p, s->dark_data,
nummeas, &s->inttime, s->gainmode)) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
s->dark_valid = 1;
s->ddate = cdate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
} else if (s->idark_valid) {
/* compute interpolated dark refence for chosen inttime & gainmode */
a1logd(p->log,2,"Interpolate dark calibration reference\n");
if (s->gainmode) {
for (j = -1; j < m->nraw; j++)
s->dark_data[j] = s->idark_data[2][j];
} else {
for (j = -1; j < m->nraw; j++)
s->dark_data[j] = s->idark_data[0][j];
}
s->dark_valid = 1;
s->ddate = s->iddate;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
} else {
m->mmode = mmode; /* Restore actual mode */
return I1PRO_INT_NOINTERPDARK;
}
a1logd(p->log,2,"Doing final white calibration with opt int_time %f, gainmode %d\n",
s->inttime,s->gainmode);
}
/* We've settled on the inttime and gain mode to get a good white reference. */
if (s->reflective) { /* We read the white reference - check it */
/* Check a reflective white measurement, and check that */
/* it seems reasonable. Return I1PRO_OK if it is, error if not. */
/* (Using cal_factor[] as temp.) */
a1logd(p->log,2,"Checking white reference\n");
if ((ev = i1pro_check_white_reference1(p, s->cal_factor[0])) != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
/* Compute a calibration factor given the reading of the white reference. */
ev = i1pro_compute_white_cal(p,
s->cal_factor[0], m->white_ref[0], s->cal_factor[0],
s->cal_factor[1], m->white_ref[1], s->cal_factor[1],
!s->scan); /* Use this for emis hires fine tune if not scan */
/* Print white lamp magnitude to track lamp darkening */
if (p->log != NULL && p->log->debug >= 1) {
double sum = 0.0;
for (i = 0; i < m->nwav[0]; i++)
sum += 1.0/s->cal_factor[0][i];
a1logd(p->log,1,"Refl. lamp magnitude = %e\n",sum);
}
if (ev == I1PRO_RD_TRANSWHITEWARN) /* Shouldn't happen ? */
ev = I1PRO_OK;
if (ev != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
} else { /* transmissive */
/* Compute a calibration factor given the reading of the white reference. */
ev = i1pro_compute_white_cal(p, s->cal_factor[0], NULL, s->cal_factor[0],
s->cal_factor[1], NULL, s->cal_factor[1], 0);
if (ev == I1PRO_RD_TRANSWHITEWARN) {
m->transwarn |= 1;
ev = I1PRO_OK;
}
if (ev != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
}
s->cal_valid = 1;
s->cfdate = cdate;
s->want_calib = 0;
*calt &= ~(inst_calt_ref_white
| inst_calt_trans_vwhite);
}
/* Deal with a display integration time selection */
if ((*calt & (inst_calt_emis_int_time | inst_calt_ap_flag))
&& (*calc & inst_calc_cond_mask) == inst_calc_emis_white
&& (s->emiss && !s->adaptive && !s->scan)) {
double scale;
double *data;
double *tt, tv;
data = dvectorz(-1, m->nraw-1);
a1logd(p->log,2,"\nDoing display integration time calibration\n");
/* Undo any previous swaps */
if (s->dispswap == 1) {
tv = s->inttime; s->inttime = s->dark_int_time2; s->dark_int_time2 = tv;
tt = s->dark_data; s->dark_data = s->dark_data2; s->dark_data2 = tt;
} else if (s->dispswap == 2) {
tv = s->inttime; s->inttime = s->dark_int_time3; s->dark_int_time3 = tv;
tt = s->dark_data; s->dark_data = s->dark_data3; s->dark_data3 = tt;
} else if (s->dispswap == 3) {
tv = s->inttime; s->inttime = s->dark_int_time4; s->dark_int_time4 = tv;
tt = s->dark_data; s->dark_data = s->dark_data4; s->dark_data4 = tt;
}
s->dispswap = 0;
/* Simply measure the full display white, and if it's close to */
/* saturation, switch to the alternate display integration time */
nummeas = i1pro_comp_nummeas(p, s->wreadtime, s->inttime);
ev = i1pro_whitemeasure(p, NULL, NULL, data , &scale, nummeas,
&s->inttime, s->gainmode, s->targoscale, 0);
if (ev == I1PRO_RD_SENSORSATURATED || scale < 1.0) {
a1logd(p->log,2,"Switching to 2nd display integration time %f seconds\n",s->dark_int_time2);
/* swap in 2nd display integration time */
tv = s->inttime; s->inttime = s->dark_int_time2; s->dark_int_time2 = tv;
tt = s->dark_data; s->dark_data = s->dark_data2; s->dark_data2 = tt;
s->dispswap = 1;
/* Do another measurement of the full display white, and if it's close to */
/* saturation, switch to the 3rd display integration time */
nummeas = i1pro_comp_nummeas(p, s->wreadtime, s->inttime);
ev = i1pro_whitemeasure(p, NULL, NULL, data , &scale, nummeas,
&s->inttime, s->gainmode, s->targoscale, 0);
if (ev == I1PRO_RD_SENSORSATURATED || scale < 1.0) {
a1logd(p->log,2,"Switching to 3rd display integration time %f seconds\n",s->dark_int_time3);
/* Undo previous swap */
tv = s->inttime; s->inttime = s->dark_int_time2; s->dark_int_time2 = tv;
tt = s->dark_data; s->dark_data = s->dark_data2; s->dark_data2 = tt;
/* swap in 3rd time */
tv = s->inttime; s->inttime = s->dark_int_time3; s->dark_int_time3 = tv;
tt = s->dark_data; s->dark_data = s->dark_data3; s->dark_data3 = tt;
s->dispswap = 2;
/* Do another measurement of the full display white, and if it's close to */
/* saturation, switch to the 4th display integration time */
nummeas = i1pro_comp_nummeas(p, s->wreadtime, s->inttime);
ev = i1pro_whitemeasure(p, NULL, NULL, data , &scale, nummeas,
&s->inttime, s->gainmode, s->targoscale, 0);
if (ev == I1PRO_RD_SENSORSATURATED || scale < 1.0) {
a1logd(p->log,2,"Switching to 4th display integration time %f seconds\n",s->dark_int_time3);
/* Undo previous swap */
tv = s->inttime; s->inttime = s->dark_int_time3; s->dark_int_time3 = tv;
tt = s->dark_data; s->dark_data = s->dark_data3; s->dark_data3 = tt;
/* swap in 4th time */
tv = s->inttime; s->inttime = s->dark_int_time4; s->dark_int_time4 = tv;
tt = s->dark_data; s->dark_data = s->dark_data4; s->dark_data4 = tt;
s->dispswap = 3;
}
}
}
free_dvector(data, -1, m->nraw-1);
if (ev != I1PRO_OK) {
m->mmode = mmode; /* Restore actual mode */
return ev;
}
s->done_dintsel = 1;
s->diseldate = cdate;
*calt &= ~inst_calt_emis_int_time;
a1logd(p->log,5,"Done display integration time calibration\n");
}
} /* Look at next mode */
m->mmode = mmode; /* Restore actual mode */
/* Make sure there's the right condition for any remaining calibrations. */
/* Do ref_white first in case we are doing a high res fine tune. */
if (*calt & (inst_calt_ref_dark | inst_calt_ref_white)) {
*idtype = inst_calc_id_ref_sn;
sprintf(id, "%d",m->serno);
if ((*calc & inst_calc_cond_mask) != inst_calc_man_ref_white) {
/* Calibrate using white tile */
*calc = inst_calc_man_ref_white;
return I1PRO_CAL_SETUP;
}
} else if (*calt & inst_calt_wavelength) { /* Wavelength calibration */
if (cs->emiss && cs->ambient) {
*idtype = inst_calc_id_none;
id[0] = '\000';
if ((*calc & inst_calc_cond_mask) != inst_calc_man_am_dark) {
/* Calibrate using ambient adapter */
*calc = inst_calc_man_am_dark;
return I1PRO_CAL_SETUP;
}
} else {
*idtype = inst_calc_id_ref_sn;
sprintf(id, "%d",m->serno);
if ((*calc & inst_calc_cond_mask) != inst_calc_man_ref_white) {
/* Calibrate using white tile */
*calc = inst_calc_man_ref_white;
return I1PRO_CAL_SETUP;
}
}
} else if (*calt & inst_calt_em_dark) { /* Emissive Dark calib */
*idtype = inst_calc_id_none;
id[0] = '\000';
if ((*calc & inst_calc_cond_mask) != inst_calc_man_em_dark) {
/* Any sort of dark reference */
*calc = inst_calc_man_em_dark;
return I1PRO_CAL_SETUP;
}
} else if (*calt & inst_calt_trans_dark) { /* Transmissvice dark */
*idtype = inst_calc_id_none;
id[0] = '\000';
if ((*calc & inst_calc_cond_mask) != inst_calc_man_trans_dark) {
*calc = inst_calc_man_trans_dark;
return I1PRO_CAL_SETUP;
}
} else if (*calt & inst_calt_trans_vwhite) {/* Transmissvice white for emulated transmission */
*idtype = inst_calc_id_none;
id[0] = '\000';
if ((*calc & inst_calc_cond_mask) != inst_calc_man_trans_white) {
*calc = inst_calc_man_trans_white;
return I1PRO_CAL_SETUP;
}
} else if (*calt & inst_calt_emis_int_time) {
*idtype = inst_calc_id_none;
id[0] = '\000';
if ((*calc & inst_calc_cond_mask) != inst_calc_emis_white) {
*calc = inst_calc_emis_white;
return I1PRO_CAL_SETUP;
}
}
/* Go around again if we've still got calibrations to do */
if (*calt & inst_calt_all_mask) {
return I1PRO_CAL_SETUP;
}
/* We must be done */
/* Update and write the EEProm log if the is a refspot calibration */
if (cs->reflective && !cs->scan && cs->dark_valid && cs->cal_valid) {
m->calcount = m->rpcount;
m->caldate = cdate;
if ((ev = i1pro_update_log(p)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_update_log: Updating the cal and log parameters"
" to EEProm failed\n");
}
}
#ifdef ENABLE_NONVCAL
/* Save the calibration to a file */
i1pro_save_calibration(p);
#endif
if (m->transwarn) {
*calc = inst_calc_message;
if (m->transwarn & 2) {
*idtype = inst_calc_id_trans_low;
strcpy(id, "Warning: Transmission light source is too low for accuracy!");
} else {
*idtype = inst_calc_id_trans_wl;
strcpy(id, "Warning: Transmission light source is low at some wavelengths!");
}
m->transwarn = 0;
}
a1logd(p->log,2,"Finished cal with dark_valid = %d, cal_valid = %d\n",cs->dark_valid, cs->cal_valid);
return I1PRO_OK;
}
/* Interpret an icoms error into a I1PRO error */
int icoms2i1pro_err(int se) {
if (se != ICOM_OK)
return I1PRO_COMS_FAIL;
return I1PRO_OK;
}
/* - - - - - - - - - - - - - - - - */
/* Do a dummy reflective read, to fix Lamp Drift. */
i1pro_code i1pro_imp_lamp_fix(
i1pro *p,
double seconds) { /* Number of seconds to turn lamp on for */
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
int nummeas;
double inttime;
unsigned char *buf; /* Raw USB reading buffer */
unsigned int bsize;
i1p_mode cmode = m->mmode; /* Remember current mode */
if (seconds > (5 * 60.0)) {
a1loge(p->log, inst_internal_error, "i1pro_imp_lamp_fix %f sec is too long\n",seconds);
return I1PRO_INT_ASSERT;
}
m->mmode = i1p_refl_spot; /* Override current mode */
inttime = 0.2; /* Constrain buffer size */
nummeas = (int)(seconds/inttime + 0.5);
bsize = m->nsen * 2 * nummeas; /* 16 bit raw values */
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
m->mmode = cmode;
a1logd(p->log,1,"i1pro_read_patches malloc %d bytes failed (11)\n",bsize);
return I1PRO_INT_MALLOC;
}
/* Trigger measure and gather raw readings */
a1logd(p->log, 1, "i1pro_imp_lamp_fix %f seconds\n",seconds);
if ((ev = i1pro_read_patches_1(p, nummeas, nummeas, &inttime, 0,
NULL, buf, bsize)) != I1PRO_OK) {
m->mmode = cmode;
free(buf);
return ev;
}
m->mmode = cmode;
free(buf);
return I1PRO_OK;
}
/* - - - - - - - - - - - - - - - - */
/* Measure a display update delay. It is assumed that */
/* white_stamp(init) has been called, and then a */
/* white to black change has been made to the displayed color, */
/* and this will measure the time it took for the update to */
/* be noticed by the instrument, up to 2.0 seconds. */
/* (It is assumed that white_change() will be called at the time the patch */
/* changes color.) */
/* inst_misread will be returned on failure to find a transition to black. */
#define NDMXTIME 2.0 /* Maximum time to take */
#define NDSAMPS 500 /* Debug samples */
typedef struct {
double sec;
double rgb[3];
double tot;
} i1rgbdsamp;
i1pro_code i1pro_imp_meas_delay(
i1pro *p,
int *pdispmsec, /* Return display update delay in msec */
int *pinstmsec) { /* Return instrument latency in msec */
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
int i, j, k, mm;
double **multimeas; /* Spectral measurements */
int nummeas;
double rgbw[3] = { 610.0, 520.0, 460.0 };
double inttime;
double rstart;
i1rgbdsamp *samp;
double stot, etot, del, thr;
double stime, etime;
int dispmsec, instmsec;
if (pinstmsec != NULL)
*pinstmsec = 0;
if ((rstart = usec_time()) < 0.0) {
a1loge(p->log, inst_internal_error, "i1pro_imp_meas_delay: No high resolution timers\n");
return inst_internal_error;
}
/* Read the samples */
inttime = m->min_int_time;
nummeas = (int)(NDMXTIME/inttime + 0.5);
multimeas = dmatrix(0, nummeas-1, -1, m->nwav[m->highres]-1);
if ((samp = (i1rgbdsamp *)calloc(sizeof(i1rgbdsamp), nummeas)) == NULL) {
a1logd(p->log, 1, "i1pro_meas_delay: malloc failed\n");
return I1PRO_INT_MALLOC;
}
/* We rely on the measurement code setting m->trigstamp when the */
/* trigger packet is sent to the instrument */
if ((ev = i1pro_read_patches_all(p, multimeas, nummeas, &inttime, 0)) != inst_ok) {
free_dmatrix(multimeas, 0, nummeas-1, 0, m->nwav[m->highres]-1);
free(samp);
return ev;
}
if (m->whitestamp < 0.0) {
a1logd(p->log, 1, "i1pro_meas_delay: White transition wasn't timestamped\n");
return inst_internal_error;
}
/* Convert the samples to RGB */
/* Add 10 msec fudge factor */
for (i = 0; i < nummeas; i++) {
samp[i].sec = i * inttime + (m->trigstamp - m->whitestamp)/1000000.0 + 0.01;
samp[i].rgb[0] = samp[i].rgb[1] = samp[i].rgb[2] = 0.0;
for (j = 0; j < m->nwav[m->highres]; j++) {
double wl = XSPECT_WL(m->wl_short[m->highres], m->wl_long[m->highres], m->nwav[m->highres], j);
//printf("~1 multimeas %d %d = %f\n",i, j, multimeas[i][j]);
for (k = 0; k < 3; k++) {
double tt = (double)(wl - rgbw[k]);
tt = (50.0 - fabs(tt))/50.0;
if (tt < 0.0)
tt = 0.0;
samp[i].rgb[k] += sqrt(tt) * multimeas[i][j];
}
}
samp[i].tot = samp[i].rgb[0] + samp[i].rgb[1] + samp[i].rgb[2];
}
free_dmatrix(multimeas, 0, nummeas-1, 0, m->nwav[m->highres]-1);
a1logd(p->log, 3, "i1pro_meas_delay: Read %d samples for refresh calibration\n",nummeas);
/* Over the first 100msec, locate the maximum value */
stime = samp[0].sec;
stot = -1e9;
for (i = 0; i < nummeas; i++) {
if (samp[i].tot > stot)
stot = samp[i].tot;
if ((samp[i].sec - stime) > 0.1)
break;
}
/* Over the last 100msec, locate the maximum value */
etime = samp[nummeas-1].sec;
etot = -1e9;
for (i = nummeas-1; i >= 0; i--) {
if (samp[i].tot > etot)
etot = samp[i].tot;
if ((etime - samp[i].sec) > 0.1)
break;
}
del = etot - stot;
thr = stot + 0.30 * del; /* 30% of transition threshold */
#ifdef PLOT_UPDELAY
a1logd(p->log, 0, "i1pro_meas_delay: start tot %f end tot %f del %f, thr %f\n", stot, etot, del, thr);
#endif
#ifdef PLOT_UPDELAY
/* Plot the raw sensor values */
{
double xx[NDSAMPS];
double y1[NDSAMPS];
double y2[NDSAMPS];
double y3[NDSAMPS];
double y4[NDSAMPS];
for (i = 0; i < nummeas && i < NDSAMPS; i++) {
xx[i] = samp[i].sec;
y1[i] = samp[i].rgb[0];
y2[i] = samp[i].rgb[1];
y3[i] = samp[i].rgb[2];
y4[i] = samp[i].tot;
//printf("%d: %f -> %f\n",i,samp[i].sec, samp[i].tot);
}
printf("Display update delay measure sensor values and time (sec)\n");
do_plot6(xx, y1, y2, y3, y4, NULL, NULL, nummeas);
}
#endif
/* Check that there has been a transition */
if (del < 5.0) {
free(samp);
a1logd(p->log, 1, "i1pro_meas_delay: can't detect change from black to white\n");
return I1PRO_RD_NOTRANS_FOUND;
}
/* Working from the start, locate the time at which the level was above the threshold */
for (i = 0; i < (nummeas-1); i++) {
if (samp[i].tot > thr)
break;
}
a1logd(p->log, 2, "i1pro_meas_delay: stoped at sample %d time %f\n",i,samp[i].sec);
/* Compute overall delay */
dispmsec = (int)(samp[i].sec * 1000.0 + 0.5); /* Display update time */
instmsec = (int)((m->trigstamp - rstart)/1000.0 + 0.5); /* Reaction time */
#ifdef PLOT_UPDELAY
a1logd(p->log, 0, "i1pro_meas_delay: disp %d, trig %d msec\n",dispmsec,instmsec);
#else
a1logd(p->log, 2, "i1pro_meas_delay: disp %d, trig %d msec\n",dispmsec,instmsec);
#endif
if (dispmsec < 0) /* This can happen if the patch generator delays it's return */
dispmsec = 0;
if (pdispmsec != NULL)
*pdispmsec = dispmsec;
if (pinstmsec != NULL)
*pinstmsec = instmsec;
#ifdef PLOT_UPDELAY
a1logd(p->log, 0, "i1pro_meas_delay: returning %d & %d msec\n",dispmsec,instmsec);
#else
a1logd(p->log, 2, "i1pro_meas_delay: returning %d & %d msec\n",dispmsec,instmsec);
#endif
free(samp);
return I1PRO_OK;
}
#undef NDSAMPS
#undef NDMXTIME
/* Timestamp the white patch change during meas_delay() */
inst_code i1pro_imp_white_change(i1pro *p, int init) {
i1proimp *m = (i1proimp *)p->m;
if (init)
m->whitestamp = -1.0;
else {
if ((m->whitestamp = usec_time()) < 0.0) {
a1loge(p->log, inst_internal_error, "i1pro_imp_wite_change: No high resolution timers\n");
return inst_internal_error;
}
}
return inst_ok;
}
/* - - - - - - - - - - - - - - - - */
/* Measure a patch or strip in the current mode. */
/* To try and speed up the reaction time between */
/* triggering a scan measurement and being able to */
/* start moving the instrument, we pre-allocate */
/* all the buffers and arrays, and pospone processing */
/* until after the scan is complete. */
i1pro_code i1pro_imp_measure(
i1pro *p,
ipatch *vals, /* Pointer to array of instrument patch value */
int nvals, /* Number of values */
instClamping clamp /* Clamp XYZ/Lab to be +ve */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
unsigned char *buf = NULL; /* Raw USB reading buffer for reflection dark cal */
unsigned int bsize;
unsigned char *mbuf = NULL; /* Raw USB reading buffer for measurement */
unsigned int mbsize;
int nummeas = 0, maxnummeas = 0;
int nmeasuered = 0; /* Number actually measured */
double **specrd = NULL; /* Cooked spectral patch values */
double duration = 0.0; /* Possible flash duration value */
int user_trig = 0;
a1logd(p->log,2,"i1pro_imp_measure: Taking %d measurments in %s%s%s%s%s%s mode called\n", nvals,
s->emiss ? "Emission" : s->trans ? "Trans" : "Refl",
s->emiss && s->ambient ? " Ambient" : "",
s->scan ? " Scan" : "",
s->flash ? " Flash" : "",
s->adaptive ? " Adaptive" : "",
m->uv_en ? " UV" : "");
if ((s->emiss && s->adaptive && !s->idark_valid)
|| ((!s->emiss || !s->adaptive) && !s->dark_valid)
|| !s->cal_valid) {
a1logd(p->log,3,"emis %d, adaptive %d, idark_valid %d\n",s->emiss,s->adaptive,s->idark_valid);
a1logd(p->log,3,"dark_valid %d, cal_valid %d\n",s->dark_valid,s->cal_valid);
a1logd(p->log,3,"i1pro_imp_measure need calibration\n");
return I1PRO_RD_NEEDS_CAL;
}
if (nvals <= 0
|| (!s->scan && nvals > 1)) {
a1logd(p->log,2,"i1pro_imp_measure wrong number of patches\n");
return I1PRO_INT_WRONGPATCHES;
}
/* Notional number of measurements, before adaptive and not counting scan */
nummeas = i1pro_comp_nummeas(p, s->wreadtime, s->inttime);
/* Allocate buf for pre-measurement dark calibration */
if (s->reflective) {
bsize = m->nsen * 2 * nummeas;
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
a1logd(p->log,1,"i1pro_imp_measure malloc %d bytes failed (5)\n",bsize);
return I1PRO_INT_MALLOC;
}
}
/* Allocate buffer for measurement */
maxnummeas = i1pro_comp_nummeas(p, s->maxscantime, s->inttime);
if (maxnummeas < nummeas)
maxnummeas = nummeas;
mbsize = m->nsen * 2 * maxnummeas;
if ((mbuf = (unsigned char *)malloc(sizeof(unsigned char) * mbsize)) == NULL) {
if (buf != NULL)
free(buf);
a1logd(p->log,1,"i1pro_imp_measure malloc %d bytes failed (6)\n",mbsize);
return I1PRO_INT_MALLOC;
}
specrd = dmatrix(0, nvals-1, 0, m->nwav[m->highres]-1);
if (m->trig == inst_opt_trig_user_switch) {
m->hide_switch = 1; /* Supress switch events */
#ifdef USE_THREAD
{
int currcount = m->switch_count; /* Variable set by thread */
while (currcount == m->switch_count) {
inst_code rc;
int cerr;
/* Don't trigger on user key if scan, only trigger */
/* on instrument switch */
if (p->uicallback != NULL
&& (rc = p->uicallback(p->uic_cntx, inst_armed)) != inst_ok) {
if (rc == inst_user_abort) {
ev = I1PRO_USER_ABORT;
break; /* Abort */
}
if (!s->scan && rc == inst_user_trig) {
ev = I1PRO_USER_TRIG;
user_trig = 1;
break; /* Trigger */
}
}
msec_sleep(100);
}
}
#else
/* Throw one away in case the switch was pressed prematurely */
i1pro_waitfor_switch_th(p, 0.01);
for (;;) {
inst_code rc;
int cerr;
if ((ev = i1pro_waitfor_switch_th(p, 0.1)) != I1PRO_OK
&& ev != I1PRO_INT_BUTTONTIMEOUT)
break; /* Error */
if (ev == I1PRO_OK)
break; /* switch triggered */
/* Don't trigger on user key if scan, only trigger */
/* on instrument switch */
if (p->uicallback != NULL
&& (rc = p->uicallback(p->uic_cntx, inst_armed)) != inst_ok) {
if (rc == inst_user_abort) {
ev = I1PRO_USER_ABORT;
break; /* Abort */
}
if (!s->scan && rc == inst_user_trig) {
ev = I1PRO_USER_TRIG;
user_trig = 1;
break; /* Trigger */
}
}
}
#endif
a1logd(p->log,3,"############# triggered ##############\n");
if (p->uicallback) /* Notify of trigger */
p->uicallback(p->uic_cntx, inst_triggered);
m->hide_switch = 0; /* Enable switch events again */
} else if (m->trig == inst_opt_trig_user) {
if (p->uicallback == NULL) {
a1logd(p->log, 1, "hcfr: inst_opt_trig_user but no uicallback function set!\n");
ev = I1PRO_UNSUPPORTED;
} else {
for (;;) {
inst_code rc;
if ((rc = p->uicallback(p->uic_cntx, inst_armed)) != inst_ok) {
if (rc == inst_user_abort) {
ev = I1PRO_USER_ABORT; /* Abort */
break;
}
if (rc == inst_user_trig) {
ev = I1PRO_USER_TRIG;
user_trig = 1;
break; /* Trigger */
}
}
msec_sleep(200);
}
}
a1logd(p->log,3,"############# triggered ##############\n");
if (p->uicallback) /* Notify of trigger */
p->uicallback(p->uic_cntx, inst_triggered);
/* Progromatic Trigger */
} else {
/* Check for abort */
if (p->uicallback != NULL
&& (ev = p->uicallback(p->uic_cntx, inst_armed)) == inst_user_abort)
ev = I1PRO_USER_ABORT; /* Abort */
}
if (ev != I1PRO_OK && ev != I1PRO_USER_TRIG) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(mbuf);
if (buf != NULL)
free(buf);
a1logd(p->log,2,"i1pro_imp_measure user aborted, terminated, command, or failure\n");
return ev; /* User abort, term, command or failure */
}
if (s->emiss && !s->scan && s->adaptive) {
int saturated = 0;
double optscale = 1.0;
s->inttime = 0.25;
s->gainmode = 0;
s->dark_valid = 0;
a1logd(p->log,2,"Trial measure emission with inttime %f, gainmode %d\n",s->inttime,s->gainmode);
/* Take a trial measurement reading using the current mode. */
/* Used to determine if sensor is saturated, or not optimal */
// nummeas = i1pro_comp_nummeas(p, s->wreadtime, s->inttime);
nummeas = 1;
if ((ev = i1pro_trialmeasure(p, &saturated, &optscale, nummeas, &s->inttime, s->gainmode,
s->targoscale)) != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure trial measure failed\n");
return ev;
}
if (saturated) {
s->inttime = m->min_int_time;
a1logd(p->log,2,"2nd trial measure emission with inttime %f, gainmode %d\n",
s->inttime,s->gainmode);
/* Take a trial measurement reading using the current mode. */
/* Used to determine if sensor is saturated, or not optimal */
nummeas = i1pro_comp_nummeas(p, 0.25, s->inttime);
if ((ev = i1pro_trialmeasure(p, &saturated, &optscale, nummeas, &s->inttime,
s->gainmode, s->targoscale)) != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure trial measure failed\n");
return ev;
}
}
a1logd(p->log,2,"Compute optimal integration time\n");
/* For adaptive mode, compute a new integration time and gain mode */
/* in order to optimise the sensor values. */
if ((ev = i1pro_optimise_sensor(p, &s->inttime, &s->gainmode,
s->inttime, s->gainmode, 1, 1, s->targoscale, optscale)) != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure optimise sensor failed\n");
return ev;
}
a1logd(p->log,2,"Computed optimal emiss inttime %f and gainmode %d\n",s->inttime,s->gainmode);
a1logd(p->log,2,"Interpolate dark calibration reference\n");
if ((ev = i1pro_interp_dark(p, s->dark_data, s->inttime, s->gainmode)) != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure interplate dark ref failed\n");
return ev;
}
s->dark_valid = 1;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
/* Recompute number of measurements and realloc measurement buffer */
free(mbuf);
nummeas = i1pro_comp_nummeas(p, s->wreadtime, s->inttime);
maxnummeas = i1pro_comp_nummeas(p, s->maxscantime, s->inttime);
if (maxnummeas < nummeas)
maxnummeas = nummeas;
mbsize = m->nsen * 2 * maxnummeas;
if ((mbuf = (unsigned char *)malloc(sizeof(unsigned char) * mbsize)) == NULL) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
a1logd(p->log,1,"i1pro_imp_measure malloc %d bytes failed (7)\n",mbsize);
return I1PRO_INT_MALLOC;
}
} else if (s->reflective) {
DISDPLOT
a1logd(p->log,2,"Doing on the fly black calibration_1 with nummeas %d int_time %f, gainmode %d\n",
nummeas, s->inttime, s->gainmode);
if ((ev = i1pro_dark_measure_1(p, nummeas, &s->inttime, s->gainmode, buf, bsize))
!= I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(buf);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure dak measure 1 failed\n");
return ev;
}
ENDPLOT
}
/* Take a measurement reading using the current mode. */
/* Converts to completely processed output readings. */
a1logd(p->log,2,"Do main measurement reading\n");
/* Indicate to the user that they can now scan the instrument, */
/* after a little delay that allows for the instrument reaction time. */
if (s->scan) {
int delay = 200 + (int)(s->lamptime * 1000.0 + 0.5);
if (p->eventcallback != NULL) {
issue_scan_ready((inst *)p, delay);
} else {
/* delay then 1KHz for 200 msec */
msec_beep(delay, 1000, 200);
}
}
/* Retry loop for certaing cases */
for (;;) {
/* Trigger measure and gather raw readings */
if ((ev = i1pro_read_patches_1(p, nummeas, maxnummeas, &s->inttime, s->gainmode,
&nmeasuered, mbuf, mbsize)) != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
if (buf != NULL)
free(buf);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure failed at i1pro_read_patches_1\n");
return ev;
}
/* Complete reflective black reference measurement */
if (s->reflective) {
a1logd(p->log,3,"Calling black calibration_2 calc with nummeas %d, inttime %f, gainmode %d\n", nummeas, s->inttime,s->gainmode);
if ((ev = i1pro_dark_measure_2(p, s->dark_data,
nummeas, s->inttime, s->gainmode, buf, bsize)) != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(buf);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure failed at i1pro_dark_measure_2\n");
return ev;
}
s->dark_valid = 1;
s->dark_int_time = s->inttime;
s->dark_gain_mode = s->gainmode;
free(buf);
}
/* Process the raw measurement readings into final spectral readings */
ev = i1pro_read_patches_2(p, &duration, specrd, nvals, s->inttime, s->gainmode,
nmeasuered, mbuf, mbsize);
/* Special case display mode read. If the sensor is saturated, and */
/* we haven't already done so, switch to the alternate integration time */
/* and try again. */
if (s->emiss && !s->scan && !s->adaptive
&& ev == I1PRO_RD_SENSORSATURATED
&& s->dispswap < 3) {
double *tt, tv;
if (s->dispswap == 0) {
a1logd(p->log,2,"Switching to 2nd display integration time %f seconds\n",s->dark_int_time2);
tv = s->inttime; s->inttime = s->dark_int_time2; s->dark_int_time2 = tv;
tt = s->dark_data; s->dark_data = s->dark_data2; s->dark_data2 = tt;
s->dispswap = 1;
} else if (s->dispswap == 1) {
a1logd(p->log,2,"Switching to 3rd display integration time %f seconds\n",s->dark_int_time3);
/* Undo first swap */
tv = s->inttime; s->inttime = s->dark_int_time2; s->dark_int_time2 = tv;
tt = s->dark_data; s->dark_data = s->dark_data2; s->dark_data2 = tt;
/* Do 2nd swap */
tv = s->inttime; s->inttime = s->dark_int_time3; s->dark_int_time3 = tv;
tt = s->dark_data; s->dark_data = s->dark_data3; s->dark_data3 = tt;
s->dispswap = 2;
} else if (s->dispswap == 2) {
a1logd(p->log,2,"Switching to 4th display integration time %f seconds\n",s->dark_int_time4);
/* Undo 2nd swap */
tv = s->inttime; s->inttime = s->dark_int_time3; s->dark_int_time3 = tv;
tt = s->dark_data; s->dark_data = s->dark_data3; s->dark_data3 = tt;
/* Do 3rd swap */
tv = s->inttime; s->inttime = s->dark_int_time4; s->dark_int_time4 = tv;
tt = s->dark_data; s->dark_data = s->dark_data4; s->dark_data4 = tt;
s->dispswap = 3;
}
/* Recompute number of measurements and realloc measurement buffer */
free(mbuf);
nummeas = i1pro_comp_nummeas(p, s->wreadtime, s->inttime);
maxnummeas = i1pro_comp_nummeas(p, s->maxscantime, s->inttime);
if (maxnummeas < nummeas)
maxnummeas = nummeas;
mbsize = m->nsen * 2 * maxnummeas;
if ((mbuf = (unsigned char *)malloc(sizeof(unsigned char) * mbsize)) == NULL) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
a1logd(p->log,1,"i1pro_imp_measure malloc %d bytes failed (7)\n",mbsize);
return I1PRO_INT_MALLOC;
}
continue; /* Do the measurement again */
}
if (ev != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
free(mbuf);
a1logd(p->log,2,"i1pro_imp_measure failed at i1pro_read_patches_2\n");
return ev;
}
break; /* Don't repeat */
}
free(mbuf);
/* Transfer spectral and convert to XYZ */
if ((ev = i1pro_conv2XYZ(p, vals, nvals, specrd, clamp)) != I1PRO_OK) {
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
a1logd(p->log,2,"i1pro_imp_measure failed at i1pro_conv2XYZ\n");
return ev;
}
free_dmatrix(specrd, 0, nvals-1, 0, m->nwav[m->highres]-1);
if (nvals > 0)
vals[0].duration = duration; /* Possible flash duration */
/* Update log counters */
if (s->reflective) {
if (s->scan)
m->acount++;
else {
m->rpinttime = s->inttime;
m->rpcount++;
}
}
a1logd(p->log,3,"i1pro_imp_measure sucessful return\n");
if (user_trig)
return I1PRO_USER_TRIG;
return ev;
}
/* - - - - - - - - - - - - - - - - */
/*
Determining the refresh rate for a refresh type display.
This is easy when the max sample rate of the i1 is above
the nyquist of the display, and will always be the case
for the range we are prepared to measure (up to 100Hz)
when using an Rev B, D or E, but is a problem for the
rev A and ColorMunki, which can only sample at 113Hz.
We work around this problem by detecting when
we are measuring an alias of the refresh rate, and
average the aliasing corrected measurements.
If there is no aparent refresh, or the refresh rate is not determinable,
return a period of 0.0 and inst_ok;
*/
i1pro_code i1pro_measure_rgb(i1pro *p, double *inttime, double *rgb);
#ifndef PSRAND32L
# define PSRAND32L(S) ((S) * 1664525L + 1013904223L)
#endif
#undef FREQ_SLOW_PRECISE /* [und] Interpolate then autocorrelate, else autc & filter */
#define NFSAMPS 80 /* Number of samples to read */
#define NFMXTIME 6.0 /* Maximum time to take (2000 == 6) */
#define PBPMS 20 /* bins per msec */
#define PERMIN ((1000 * PBPMS)/40) /* 40 Hz */
#define PERMAX ((1000 * PBPMS)/4) /* 4 Hz*/
#define NPER (PERMAX - PERMIN + 1)
#define PWIDTH (8 * PBPMS) /* 8 msec bin spread to look for peak in */
#define MAXPKS 20 /* Number of peaks to find */
#define TRIES 8 /* Number of different sample rates to try */
i1pro_code i1pro_imp_meas_refrate(
i1pro *p,
double *ref_rate
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
int i, j, k, mm;
double **multimeas; /* Spectral measurements */
int nummeas;
double rgbw[3] = { 610.0, 520.0, 460.0 };
double inttime;
static unsigned int randn = 0x12345678;
struct {
double sec;
double rgb[3];
} samp[NFSAMPS * 2];
int nfsamps; /* Actual samples read */
double minv[3]; /* Minimum reading */
double maxv[3]; /* Maximum reading */
double maxt; /* Time range */
#ifdef FREQ_SLOW_PRECISE
int nbins;
double *bins[3]; /* PBPMS sample bins */
#else
double tcorr[NPER]; /* Temp for initial autocorrelation */
int ntcorr[NPER]; /* Number accumulated */
#endif
double corr[NPER]; /* Filtered correlation for each period value */
double mincv, maxcv; /* Max and min correlation values */
double crange; /* Correlation range */
double peaks[MAXPKS]; /* Peak wavelength */
double peakh[MAXPKS]; /* Peak heighheight */
int npeaks; /* Number of peaks */
double pval; /* Period value */
double rfreq[TRIES]; /* Computed refresh frequency for each try */
double rsamp[TRIES]; /* Sampling rate used to measure frequency */
int tix = 0; /* try index */
a1logd(p->log,2,"i1pro_imp_meas_refrate called\n");
if (ref_rate != NULL)
*ref_rate = 0.0;
if (!s->emiss) {
a1logd(p->log,2,"i1pro_imp_meas_refrate not in emissive mode\n");
return I1PRO_UNSUPPORTED;
}
for (mm = 0; mm < TRIES; mm++) {
rfreq[mm] = 0.0;
npeaks = 0; /* Number of peaks */
nummeas = NFSAMPS;
multimeas = dmatrix(0, nummeas-1, -1, m->nwav[m->highres]-1);
if (mm == 0)
inttime = m->min_int_time;
else {
double rval, dmm;
randn = PSRAND32L(randn);
rval = (double)randn/4294967295.0;
dmm = ((double)mm + rval - 0.5)/(TRIES - 0.5);
inttime = m->min_int_time * (1.0 + dmm * 0.80);
}
if ((ev = i1pro_read_patches_all(p, multimeas, nummeas, &inttime, 0)) != inst_ok) {
free_dmatrix(multimeas, 0, nummeas-1, 0, m->nwav[m->highres]-1);
return ev;
}
rsamp[tix] = 1.0/inttime;
/* Convert the samples to RGB */
for (i = 0; i < nummeas && i < NFSAMPS; i++) {
samp[i].sec = i * inttime;
samp[i].rgb[0] = samp[i].rgb[1] = samp[i].rgb[2] = 0.0;
for (j = 0; j < m->nwav[m->highres]; j++) {
double wl = XSPECT_WL(m->wl_short[m->highres], m->wl_long[m->highres], m->nwav[m->highres], j);
//printf("~1 multimeas %d %d = %f\n",i, j, multimeas[i][j]);
for (k = 0; k < 3; k++) {
double tt = (double)(wl - rgbw[k]);
tt = (40.0 - fabs(tt))/40.0;
if (tt < 0.0)
tt = 0.0;
samp[i].rgb[k] += sqrt(tt) * multimeas[i][j];
}
}
}
free_dmatrix(multimeas, 0, nummeas-1, 0, m->nwav[m->highres]-1);
nfsamps = i;
a1logd(p->log, 3, "i1pro_meas_refrate: Read %d samples for refresh calibration\n",nfsamps);
#ifdef NEVER
/* Plot the raw sensor values */
{
double xx[NFSAMPS];
double y1[NFSAMPS];
double y2[NFSAMPS];
double y3[NFSAMPS];
for (i = 0; i < nfsamps; i++) {
xx[i] = samp[i].sec;
y1[i] = samp[i].rgb[0];
y2[i] = samp[i].rgb[1];
y3[i] = samp[i].rgb[2];
// printf("%d: %f -> %f\n",i,samp[i].sec, samp[i].rgb[0]);
}
printf("Fast scan sensor values and time (sec)\n");
do_plot6(xx, y1, y2, y3, NULL, NULL, NULL, nfsamps);
}
#endif
/* Locate the smallest values and maximum time */
maxt = -1e6;
minv[0] = minv[1] = minv[2] = 1e20;
maxv[0] = maxv[1] = maxv[2] = -11e20;
for (i = nfsamps-1; i >= 0; i--) {
if (samp[i].sec > maxt)
maxt = samp[i].sec;
for (j = 0; j < 3; j++) {
if (samp[i].rgb[j] < minv[j])
minv[j] = samp[i].rgb[j];
if (samp[i].rgb[j] > maxv[j])
maxv[j] = samp[i].rgb[j];
}
}
/* Re-zero the sample times, and normalise the readings */
for (i = nfsamps-1; i >= 0; i--) {
samp[i].sec -= samp[0].sec;
if (samp[i].sec > maxt)
maxt = samp[i].sec;
for (j = 0; j < 3; j++) {
samp[i].rgb[j] -= minv[j];
}
}
#ifdef FREQ_SLOW_PRECISE /* Interp then autocorrelate */
/* Create PBPMS bins and interpolate readings into them */
nbins = 1 + (int)(maxt * 1000.0 * PBPMS + 0.5);
for (j = 0; j < 3; j++) {
if ((bins[j] = (double *)calloc(sizeof(double), nbins)) == NULL) {
a1loge(p->log, inst_internal_error, "i1pro_meas_refrate: malloc failed\n");
return I1PRO_INT_MALLOC;
}
}
/* Do the interpolation */
for (k = 0; k < (nfsamps-1); k++) {
int sbin, ebin;
sbin = (int)(samp[k].sec * 1000.0 * PBPMS + 0.5);
ebin = (int)(samp[k+1].sec * 1000.0 * PBPMS + 0.5);
for (i = sbin; i <= ebin; i++) {
double bl;
#if defined(__APPLE__) && defined(__POWERPC__)
gcc_bug_fix(i);
#endif
bl = (i - sbin)/(double)(ebin - sbin); /* 0.0 to 1.0 */
for (j = 0; j < 3; j++) {
bins[j][i] = (1.0 - bl) * samp[k].rgb[j] + bl * samp[k+1].rgb[j];
}
}
}
#ifdef NEVER
/* Plot interpolated values */
{
double *xx;
double *y1;
double *y2;
double *y3;
xx = malloc(sizeof(double) * nbins);
y1 = malloc(sizeof(double) * nbins);
y2 = malloc(sizeof(double) * nbins);
y3 = malloc(sizeof(double) * nbins);
if (xx == NULL || y1 == NULL || y2 == NULL || y3 == NULL) {
a1loge(p->log, inst_internal_error, "i1pro_meas_refrate: malloc failed\n");
for (j = 0; j < 3; j++)
free(bins[j]);
return I1PRO_INT_MALLOC;
}
for (i = 0; i < nbins; i++) {
xx[i] = i / (double)PBPMS; /* msec */
y1[i] = bins[0][i];
y2[i] = bins[1][i];
y3[i] = bins[2][i];
}
printf("Interpolated fast scan sensor values and time (msec) for inttime %f\n",inttime);
do_plot6(xx, y1, y2, y3, NULL, NULL, NULL, nbins);
free(xx);
free(y1);
free(y2);
free(y3);
}
#endif /* PLOT_REFRESH */
/* Compute auto-correlation at 1/PBPMS msec intervals */
/* from 25 msec (40Hz) to 100msec (10 Hz) */
mincv = 1e48, maxcv = -1e48;
for (i = 0; i < NPER; i++) {
int poff = PERMIN + i; /* Offset to corresponding sample */
corr[i] = 0;
for (k = 0; (k + poff) < nbins; k++) {
corr[i] += bins[0][k] * bins[0][k + poff]
+ bins[1][k] * bins[1][k + poff]
+ bins[2][k] * bins[2][k + poff];
}
corr[i] /= (double)k; /* Normalize */
if (corr[i] > maxcv)
maxcv = corr[i];
if (corr[i] < mincv)
mincv = corr[i];
}
/* Free the bins */
for (j = 0; j < 3; j++)
free(bins[j]);
#else /* !FREQ_SLOW_PRECISE Fast - autocorrellate then filter */
/* Upsample by a factor of 2 */
for (i = nfsamps-1; i >= 0; i--) {
j = 2 * i;
samp[j].sec = samp[i].sec;
samp[j].rgb[0] = samp[i].rgb[0];
samp[j].rgb[1] = samp[i].rgb[1];
samp[j].rgb[2] = samp[i].rgb[2];
if (i > 0) {
j--;
samp[j].sec = 0.5 * (samp[i].sec + samp[i-1].sec);
samp[j].rgb[0] = 0.5 * (samp[i].rgb[0] + samp[i-1].rgb[0]);
samp[j].rgb[1] = 0.5 * (samp[i].rgb[1] + samp[i-1].rgb[1]);
samp[j].rgb[2] = 0.5 * (samp[i].rgb[2] + samp[i-1].rgb[2]);
}
}
nfsamps = 2 * nfsamps - 1;
/* Do point by point correllation of samples */
for (i = 0; i < NPER; i++) {
tcorr[i] = 0.0;
ntcorr[i] = 0;
}
for (j = 0; j < (nfsamps-1); j++) {
for (k = j+1; k < nfsamps; k++) {
double del, cor;
int bix;
del = samp[k].sec - samp[j].sec;
bix = (int)(del * 1000.0 * PBPMS + 0.5);
if (bix < PERMIN)
continue;
if (bix > PERMAX)
break;
bix -= PERMIN;
cor = samp[j].rgb[0] * samp[k].rgb[0]
+ samp[j].rgb[1] * samp[k].rgb[1]
+ samp[j].rgb[2] * samp[k].rgb[2];
//printf("~1 j %d k %d, del %f bix %d cor %f\n",j,k,del,bix,cor);
tcorr[bix] += cor;
ntcorr[bix]++;
}
}
/* Divide out count and linearly interpolate */
j = 0;
for (i = 0; i < NPER; i++) {
if (ntcorr[i] > 0) {
tcorr[i] /= ntcorr[i];
if ((i - j) > 1) {
if (j == 0) {
for (k = j; k < i; k++)
tcorr[k] = tcorr[i];
} else { /* Linearly interpolate from last value */
double ww = (double)i-j;
for (k = j+1; k < i; k++) {
double bl = (k-j)/ww;
tcorr[k] = (1.0 - bl) * tcorr[j] + bl * tcorr[i];
}
}
}
j = i;
}
}
if (j < (NPER-1)) {
for (k = j+1; k < NPER; k++) {
tcorr[k] = tcorr[j];
}
}
#ifdef PLOT_REFRESH
/* Plot unfiltered auto correlation */
{
double xx[NPER];
double y1[NPER];
for (i = 0; i < NPER; i++) {
xx[i] = (i + PERMIN) / (double)PBPMS; /* msec */
y1[i] = tcorr[i];
}
printf("Unfiltered auto correlation (msec)\n");
do_plot6(xx, y1, NULL, NULL, NULL, NULL, NULL, NPER);
}
#endif /* PLOT_REFRESH */
/* Apply a gausian filter */
#define FWIDTH 100
{
double gaus_[2 * FWIDTH * PBPMS + 1];
double *gaus = &gaus_[FWIDTH * PBPMS];
double bb = 1.0/pow(2, 5.0);
double fw = inttime * 1000.0;
int ifw;
//printf("~1 sc = %f = %f msec\n",1.0/inttime, fw);
//printf("~1 fw = %f, ifw = %d\n",fw,ifw);
fw *= 0.9;
ifw = (int)ceil(fw * PBPMS);
if (ifw > FWIDTH * PBPMS)
error("i1pro: Not enough space for lanczos 2 filter");
for (j = -ifw; j <= ifw; j++) {
double x, y;
x = j/(PBPMS * fw);
if (fabs(x) > 1.0)
y = 0.0;
else
y = 1.0/pow(2, 5.0 * x * x) - bb;
gaus[j] = y;
//printf("~1 gaus[%d] = %f\n",j,y);
}
for (i = 0; i < NPER; i++) {
double sum = 0.0;
double wght = 0.0;
for (j = -ifw; j <= ifw; j++) {
double w;
int ix = i + j;
if (ix < 0)
ix = -ix;
if (ix > (NPER-1))
ix = 2 * NPER-1 - ix;
w = gaus[j];
sum += w * tcorr[ix];
wght += w;
}
//printf("~1 corr[%d] wgt = %f\n",i,wght);
corr[i] = sum / wght;
}
}
/* Compute min & max */
mincv = 1e48, maxcv = -1e48;
for (i = 0; i < NPER; i++) {
if (corr[i] > maxcv)
maxcv = corr[i];
if (corr[i] < mincv)
mincv = corr[i];
}
#endif /* !FREQ_SLOW_PRECISE Fast - autocorrellate then filter */
crange = maxcv - mincv;
a1logd(p->log,3,"Correlation value range %f - %f = %f = %f%%\n",mincv, maxcv,crange, 100.0 * (maxcv-mincv)/maxcv);
#ifdef PLOT_REFRESH
/* Plot this measuremnts auto correlation */
{
double xx[NPER];
double y1[NPER];
for (i = 0; i < NPER; i++) {
xx[i] = (i + PERMIN) / (double)PBPMS; /* msec */
y1[i] = corr[i];
}
printf("Auto correlation (msec)\n");
do_plot6(xx, y1, NULL, NULL, NULL, NULL, NULL, NPER);
}
#endif /* PLOT_REFRESH */
#define PFDB 4 // normally 4
/* If there is sufficient level and distict correlations */
if (crange/maxcv >= 0.1) {
a1logd(p->log,PFDB,"Searching for peaks\n");
/* Locate all the peaks starting at the longest correllation */
for (i = (NPER-1-PWIDTH); i >= 0 && npeaks < MAXPKS; i--) {
double v1, v2, v3;
v1 = corr[i];
v2 = corr[i + PWIDTH/2]; /* Peak */
v3 = corr[i + PWIDTH];
if (fabs(v3 - v1)/crange < 0.05
&& (v2 - v1)/crange > 0.025
&& (v2 - v3)/crange > 0.025
&& (v2 - mincv)/crange > 0.5) {
double pkv; /* Peak value */
int pki; /* Peak index */
double ii, bl;
#ifdef PLOT_REFRESH
a1logd(p->log,PFDB,"Max between %f and %f msec\n",
(i + PERMIN)/(double)PBPMS,(i + PWIDTH + PERMIN)/(double)PBPMS);
#endif
/* Locate the actual peak */
pkv = -1.0;
pki = 0;
for (j = i; j < (i + PWIDTH); j++) {
if (corr[j] > pkv) {
pkv = corr[j];
pki = j;
}
}
#ifdef PLOT_REFRESH
a1logd(p->log,PFDB,"Peak is at %f msec, %f corr\n", (pki + PERMIN)/(double)PBPMS, pkv);
#endif
/* Interpolate the peak value for higher precision */
/* j = bigest */
if (corr[pki-1] > corr[pki+1]) {
j = pki-1;
k = pki+1;
} else {
j = pki+1;
k = pki-1;
}
bl = (corr[pki] - corr[j])/(corr[pki] - corr[k]);
bl = (bl + 1.0)/2.0;
ii = bl * pki + (1.0 - bl) * j;
pval = (ii + PERMIN)/(double)PBPMS;
#ifdef PLOT_REFRESH
a1logd(p->log,PFDB,"Interpolated peak is at %f msec\n", pval);
#endif
peaks[npeaks] = pval;
peakh[npeaks] = corr[pki];
npeaks++;
i -= PWIDTH;
}
#ifdef NEVER
if (v2 > v1 && v2 > v3) {
printf("Peak rehjected:\n");
printf("(v3 - v1)/crange = %f < 0.05 ?\n",fabs(v3 - v1)/crange);
printf("(v2 - v1)/crange = %f > 0.025 ?\n",(v2 - v1)/crange);
printf("(v2 - v3)/crange = %f > 0.025 ?\n",(v2 - v3)/crange);
printf("(v2 - mincv)/crange = %f > 0.5 ?\n",(v2 - mincv)/crange);
}
#endif
}
a1logd(p->log,3,"Number of peaks located = %d\n",npeaks);
} else {
a1logd(p->log,3,"All rejected, crange/maxcv = %f < 0.06\n",crange/maxcv);
}
#undef PFDB
a1logd(p->log,3,"Number of peaks located = %d\n",npeaks);
if (npeaks > 1) { /* Compute aparent refresh rate */
int nfails;
double div, avg, ano;
/* Try and locate a common divisor amongst all the peaks. */
/* This is likely to be the underlying refresh rate. */
for (k = 0; k < npeaks; k++) {
for (j = 1; j < 25; j++) {
avg = ano = 0.0;
div = peaks[k]/(double)j;
if (div < 5.0)
continue; /* Skip anything higher than 200Hz */
//printf("~1 trying %f Hz\n",1000.0/div);
for (nfails = i = 0; i < npeaks; i++) {
double rem, cnt;
rem = peaks[i]/div;
cnt = floor(rem + 0.5);
rem = fabs(rem - cnt);
#ifdef PLOT_REFRESH
a1logd(p->log, 3, "remainder for peak %d = %f\n",i,rem);
#endif
if (rem > 0.06) {
if (++nfails > 2)
break; /* Fail this divisor */
} else {
avg += peaks[i]; /* Already weighted by cnt */
ano += cnt;
}
}
if (nfails == 0 || (nfails <= 2 && npeaks >= 6))
break; /* Sucess */
/* else go and try a different divisor */
}
if (j < 25)
break; /* Success - found common divisor */
}
if (k >= npeaks) {
a1logd(p->log,3,"Failed to locate common divisor\n");
} else {
pval = 0.001 * avg/ano;
if (pval < inttime) {
a1logd(p->log,3,"Discarding frequency %f > sample rate %f\n",1.0/pval, 1.0/inttime);
} else {
pval = 1.0/pval; /* Convert to frequency */
rfreq[tix++] = pval;
a1logd(p->log,3,"Located frequency %f sum %f dif %f\n",pval, pval + 1.0/inttime, fabs(pval - 1.0/inttime));
}
}
}
}
if (tix >= 3) {
for (mm = 0; mm < tix; mm++) {
a1logd(p->log, 3, "Try %d, samp %f Hz, Meas %f Hz, Sum %f Hz, Dif %f Hz\n",mm,rsamp[mm],rfreq[mm], rsamp[mm] + rfreq[mm], fabs(rsamp[mm] - rfreq[mm]));
}
/* Decide if we are above the nyquist, or whether */
/* we have aliases of the fundamental */
{
double brange = 1e38;
double brate = 0.0;
int bsplit = -1;
double min, max, avg, range;
int split, mul, niia;
/* Compute fundamental and sub aliases at all possible splits. */
/* Skip the reading at the split. */
for (split = tix; split >= -1; split--) {
min = 1e38; max = -1e38; avg = 0.0; niia = 0;
for (mm = 0; mm < tix; mm++) {
double alias;
if (mm == split)
continue;
if (mm < split)
alias = rfreq[mm];
else
alias = fabs(rsamp[mm] - rfreq[mm]);
avg += alias;
niia++;
if (alias < min)
min = alias;
if (alias > max)
max = alias;
}
avg /= (double)niia;
range = (max - min)/(max + min);
//printf("~1 split %d avg = %f, range = %f\n",split,avg,range);
if (range < brange) {
brange = range;
brate = avg;
bsplit = split;
}
}
/* Compute sub and add aliases at all possible splits */
/* Skip the reading at the split. */
for (split = tix; split >= -1; split--) {
min = 1e38; max = -1e38; avg = 0.0; niia = 0;
for (mm = 0; mm < tix; mm++) {
double alias;
if (mm == split)
continue;
if (mm < split)
alias = fabs(rsamp[mm] - rfreq[mm]);
else
alias = rsamp[mm] + rfreq[mm];
avg += alias;
niia++;
if (alias < min)
min = alias;
if (alias > max)
max = alias;
}
avg /= (double)niia;
range = (max - min)/(max + min);
//printf("~1 split %d avg = %f, range = %f\n",100 + split,avg,range);
if (range < brange) {
brange = range;
brate = avg;
bsplit = 100 + split;
}
}
a1logd(p->log, 3, "Selected split %d range %f\n",bsplit,brange);
/* Hmm. Could reject result and re-try if brange is too large ? ( > 0.005 ?) */
if (brange > 0.05) {
a1logd(p->log, 3, "Readings are too inconsistent (brange %.1f%%) - should retry ?\n",brange * 100.0);
} else {
if (ref_rate != NULL)
*ref_rate = brate;
/* Error against my 85Hz CRT - GWG */
// a1logd(p->log, 1, "Refresh rate %f Hz, error = %.4f%%\n",brate,100.0 * fabs(brate - 85.0)/(85.0));
return I1PRO_OK;
}
}
} else {
a1logd(p->log, 3, "Not enough tries suceeded to determine refresh rate\n");
}
return I1PRO_RD_NOREFR_FOUND;
}
#undef NFSAMPS
#undef PBPMS
#undef PERMIN
#undef PERMAX
#undef NPER
#undef PWIDTH
/* - - - - - - - - - - - - - - - - - - - - - - */
/* i1 refspot calibration/log stored on instrument */
/* RevA..D only! */
/* Restore the reflective spot calibration information from the EEPRom */
/* Always returns success, even if the restore fails, */
/* which may happen for an instrument that's never been used or had calibration */
/* written to its EEProm */
/* RevA..D only! */
i1pro_code i1pro_restore_refspot_cal(i1pro *p) {
int chsum1, *chsum2;
int *ip, i;
unsigned int count;
double *dp;
unsigned char buf[256];
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[i1p_refl_spot]; /* NOT current mode, refspot mode */
i1key offst = 0; /* Offset to copy to use */
i1pro_code ev = I1PRO_OK;
int o_nsen; /* Actual nsen data */
a1logd(p->log,2,"Doing Restoring reflective spot calibration information from the EEProm\n");
chsum1 = m->data->checksum(m->data, 0);
if ((chsum2 = m->data->get_int(m->data, key_checksum, 0)) == NULL || chsum1 != *chsum2) {
offst = key_2logoff;
chsum1 = m->data->checksum(m->data, key_2logoff);
if ((chsum2 = m->data->get_int(m->data, key_checksum + key_2logoff, 0)) == NULL
|| chsum1 != *chsum2) {
a1logd(p->log,2,"Neither EEPRom checksum was valid\n");
return I1PRO_OK;
}
}
/* Get the calibration gain mode */
if ((ip = m->data->get_ints(m->data, &count, key_gainmode + offst)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to read calibration gain mode from EEPRom\n");
return I1PRO_OK;
}
if (ip[0] == 0) {
#ifdef USE_HIGH_GAIN_MODE
s->gainmode = 1;
#else
s->gainmode = 0;
a1logd(p->log,2,"Calibration gain mode was high, and high gain not compiled in\n");
return I1PRO_OK;
#endif /* !USE_HIGH_GAIN_MODE */
} else
s->gainmode = 0;
/* Get the calibration integration time */
if ((dp = m->data->get_doubles(m->data, &count, key_inttime + offst)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to read calibration integration time from EEPRom\n");
return I1PRO_OK;
}
s->inttime = dp[0];
if (s->inttime < m->min_int_time) /* Hmm. EEprom is occasionaly screwed up */
s->inttime = m->min_int_time;
/* Get the dark data */
if ((ip = m->data->get_ints(m->data, &count, key_darkreading + offst)) == NULL
|| count != 128) {
a1logv(p->log,1,"Failed to read calibration dark data from EEPRom\n");
return I1PRO_OK;
}
/* Convert back to a single raw big endian instrument readings */
for (i = 0; i < 128; i++) {
buf[i * 2 + 0] = (ip[i] >> 8) & 0xff;
buf[i * 2 + 1] = ip[i] & 0xff;
}
/* Convert to calibration data */
a1logd(p->log,3,"Calling black calibration_2 calc with nummeas %d, inttime %f, gainmode %d\n", 1, s->inttime,s->gainmode);
o_nsen = m->nsen;
m->nsen = 128; /* Assume EEprom cal data is <= Rev D format */
if ((ev = i1pro_dark_measure_2(p, s->dark_data, 1, s->inttime, s->gainmode,
buf, 256)) != I1PRO_OK) {
a1logd(p->log,2,"Failed to convert EEProm dark data to calibration\n");
m->nsen = o_nsen;
return I1PRO_OK;
}
/* We've sucessfully restored the dark calibration */
s->dark_valid = 1;
s->ddate = m->caldate;
/* Get the white calibration data */
if ((ip = m->data->get_ints(m->data, &count, key_whitereading + offst)) == NULL
|| count != 128) {
a1logd(p->log,2,"Failed to read calibration white data from EEPRom\n");
m->nsen = o_nsen;
return I1PRO_OK;
}
/* Convert back to a single raw big endian instrument readings */
for (i = 0; i < 128; i++) {
buf[i * 2 + 0] = (ip[i] >> 8) & 0xff;
buf[i * 2 + 1] = ip[i] & 0xff;
}
/* Convert to calibration data */
m->nsen = 128; /* Assume EEprom cal data is <= Rev D format */
if ((ev = i1pro_whitemeasure_buf(p, s->cal_factor[0], s->cal_factor[1], s->white_data,
s->inttime, s->gainmode, buf)) != I1PRO_OK) {
/* This may happen for an instrument that's never been used */
a1logd(p->log,2,"Failed to convert EEProm white data to calibration\n");
m->nsen = o_nsen;
return I1PRO_OK;
}
m->nsen = o_nsen;
/* Check a reflective white measurement, and check that */
/* it seems reasonable. Return I1PRO_OK if it is, error if not. */
/* (Using cal_factor[] as temp.) */
if ((ev = i1pro_check_white_reference1(p, s->cal_factor[0])) != I1PRO_OK) {
/* This may happen for an instrument that's never been used */
a1logd(p->log,2,"Failed to convert EEProm white data to calibration\n");
return I1PRO_OK;
}
/* Compute a calibration factor given the reading of the white reference. */
ev = i1pro_compute_white_cal(p, s->cal_factor[0], m->white_ref[0], s->cal_factor[0],
s->cal_factor[1], m->white_ref[1], s->cal_factor[1], 1);
if (ev != I1PRO_RD_TRANSWHITEWARN && ev != I1PRO_OK) {
a1logd(p->log,2,"i1pro_compute_white_cal failed to convert EEProm data to calibration\n");
return I1PRO_OK;
}
/* We've sucessfully restored the calibration */
s->cal_valid = 1;
s->cfdate = m->caldate;
return I1PRO_OK;
}
/* Save the reflective spot calibration information to the EEPRom data object. */
/* Note we don't actually write to the EEProm here! */
/* For RevA..D only! */
static i1pro_code i1pro_set_log_data(i1pro *p) {
int *ip, i;
unsigned int count;
double *dp;
double absmeas[128];
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[i1p_refl_spot]; /* NOT current mode, refspot mode */
i1key offst = 0; /* Offset to copy to use */
i1pro_code ev = I1PRO_OK;
a1logd(p->log,3,"i1pro_set_log_data called\n");
if (s->dark_valid == 0 || s->cal_valid == 0)
return I1PRO_INT_NO_CAL_TO_SAVE;
/* Set the calibration gain mode */
if ((ip = m->data->get_ints(m->data, &count, key_gainmode + offst)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access calibration gain mode from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
if (s->gainmode == 0)
ip[0] = 1;
else
ip[0] = 0;
/* Set the calibration integration time */
if ((dp = m->data->get_doubles(m->data, &count, key_inttime + offst)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to read calibration integration time from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
dp[0] = s->inttime;
/* Set the dark data */
if ((ip = m->data->get_ints(m->data, &count, key_darkreading + offst)) == NULL
|| count != 128) {
a1logd(p->log,2,"Failed to access calibration dark data from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
/* Convert abs dark_data to raw data */
if ((ev = i1pro_absraw_to_meas(p, ip, s->dark_data, s->inttime, s->gainmode)) != I1PRO_OK)
return ev;
/* Add back black level to white data */
for (i = 0; i < 128; i++)
absmeas[i] = s->white_data[i] + s->dark_data[i];
/* Get the white data */
if ((ip = m->data->get_ints(m->data, &count, key_whitereading + offst)) == NULL
|| count != 128) {
a1logd(p->log,2,"Failed to access calibration white data from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
/* Convert abs white_data to raw data */
if ((ev = i1pro_absraw_to_meas(p, ip, absmeas, s->inttime, s->gainmode)) != I1PRO_OK)
return ev;
/* Set all the log counters */
/* Total Measure (Emis/Remis/Ambient/Trans/Cal) count */
if ((ip = m->data->get_ints(m->data, &count, key_meascount)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access meascount log counter from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
ip[0] = m->meascount;
/* Remspotcal last calibration date */
if ((ip = m->data->get_ints(m->data, &count, key_caldate)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access caldate log counter from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
ip[0] = m->caldate;
/* Remission spot measure count at last Remspotcal. */
if ((ip = m->data->get_ints(m->data, &count, key_calcount)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access calcount log counter from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
ip[0] = m->calcount;
/* Last remision spot reading integration time */
if ((dp = m->data->get_doubles(m->data, &count, key_rpinttime)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access rpinttime log counter from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
dp[0] = m->rpinttime;
/* Remission spot measure count */
if ((ip = m->data->get_ints(m->data, &count, key_rpcount)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access rpcount log counter from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
ip[0] = m->rpcount;
/* Remission scan measure count (??) */
if ((ip = m->data->get_ints(m->data, &count, key_acount)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access acount log counter from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
ip[0] = m->acount;
/* Total lamp usage time in seconds (??) */
if ((dp = m->data->get_doubles(m->data, &count, key_lampage)) == NULL || count < 1) {
a1logd(p->log,2,"Failed to access lampage log counter from EEPRom\n");
return I1PRO_INT_EEPROM_DATA_MISSING;
}
dp[0] = m->lampage;
a1logd(p->log,5,"i1pro_set_log_data done\n");
return I1PRO_OK;
}
/* Update the single remission calibration and instrument usage log */
/* For RevA..D only! */
i1pro_code i1pro_update_log(i1pro *p) {
i1pro_code ev = I1PRO_OK;
#ifdef ENABLE_WRITE
i1proimp *m = (i1proimp *)p->m;
unsigned char *buf; /* Buffer to write to EEProm */
unsigned int len;
a1logd(p->log,5,"i1pro_update_log:\n");
/* Copy refspot calibration and log data to EEProm data store */
if ((ev = i1pro_set_log_data(p)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_update_log i1pro_set_log_data failed\n");
return ev;
}
/* Compute checksum and serialise into buffer ready to write */
if ((ev = m->data->prep_section1(m->data, &buf, &len)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_update_log prep_section1 failed\n");
return ev;
}
/* First copy of log */
if ((ev = i1pro_writeEEProm(p, buf, 0x0000, len)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_update_log i1pro_writeEEProm 0x0000 failed\n");
return ev;
}
/* Second copy of log */
if ((ev = i1pro_writeEEProm(p, buf, 0x0800, len)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_update_log i1pro_writeEEProm 0x0800 failed\n");
return ev;
}
free(buf);
a1logd(p->log,5,"i1pro_update_log done\n");
#else
a1logd(p->log,5,"i1pro_update_log: skipped as EPRom write is disabled\n");
#endif
return ev;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Save the calibration for all modes, stored on local system */
#ifdef ENABLE_NONVCAL
/* non-volatile save/restor state */
typedef struct {
int ef; /* Error flag, 1 = write failed, 2 = close failed */
unsigned int chsum; /* Checksum */
int nbytes; /* Number of bytes checksummed */
} i1pnonv;
static void update_chsum(i1pnonv *x, unsigned char *p, int nn) {
int i;
for (i = 0; i < nn; i++, p++)
x->chsum = ((x->chsum << 13) | (x->chsum >> (32-13))) + *p;
x->nbytes += nn;
}
/* Write an array of ints to the file. Set the error flag to nz on error */
static void write_ints(i1pnonv *x, FILE *fp, int *dp, int n) {
if (fwrite((void *)dp, sizeof(int), n, fp) != n) {
x->ef = 1;
} else {
update_chsum(x, (unsigned char *)dp, n * sizeof(int));
}
}
/* Write an array of doubles to the file. Set the error flag to nz on error */
static void write_doubles(i1pnonv *x, FILE *fp, double *dp, int n) {
if (fwrite((void *)dp, sizeof(double), n, fp) != n) {
x->ef = 1;
} else {
update_chsum(x, (unsigned char *)dp, n * sizeof(double));
}
}
/* Write an array of time_t's to the file. Set the error flag to nz on error */
/* (This will cause file checksum fail if different executables on the same */
/* system have different time_t values) */
static void write_time_ts(i1pnonv *x, FILE *fp, time_t *dp, int n) {
if (fwrite((void *)dp, sizeof(time_t), n, fp) != n) {
x->ef = 1;
} else {
update_chsum(x, (unsigned char *)dp, n * sizeof(time_t));
}
}
/* Read an array of ints from the file. Set the error flag to nz on error */
static void read_ints(i1pnonv *x, FILE *fp, int *dp, int n) {
if (fread((void *)dp, sizeof(int), n, fp) != n) {
x->ef = 1;
} else {
update_chsum(x, (unsigned char *)dp, n * sizeof(int));
}
}
/* Read an array of doubles from the file. Set the error flag to nz on error */
static void read_doubles(i1pnonv *x, FILE *fp, double *dp, int n) {
if (fread((void *)dp, sizeof(double), n, fp) != n) {
x->ef = 1;
} else {
update_chsum(x, (unsigned char *)dp, n * sizeof(double));
}
}
/* Read an array of time_t's from the file. Set the error flag to nz on error */
/* (This will cause file checksum fail if different executables on the same */
/* system have different time_t values) */
static void read_time_ts(i1pnonv *x, FILE *fp, time_t *dp, int n) {
if (fread((void *)dp, sizeof(time_t), n, fp) != n) {
x->ef = 1;
} else {
update_chsum(x, (unsigned char *)dp, n * sizeof(time_t));
}
}
i1pro_code i1pro_save_calibration(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
i1pro_state *s;
int i;
char nmode[10];
char cal_name[100]; /* Name */
char **cal_paths = NULL;
int no_paths = 0;
FILE *fp;
i1pnonv x;
int ss;
int argyllversion = ARGYLL_VERSION;
int isRevE = p->itype == instI1Pro2 ? 1 : 0;
strcpy(nmode, "w");
#if !defined(O_CREAT) && !defined(_O_CREAT)
# error "Need to #include fcntl.h!"
#endif
#if defined(O_BINARY) || defined(_O_BINARY)
strcat(nmode, "b");
#endif
/* Create the file name */
sprintf(cal_name, "ArgyllCMS/.i1p_%d.cal", m->serno);
if ((no_paths = xdg_bds(NULL, &cal_paths, xdg_cache, xdg_write, xdg_user, cal_name)) < 1) {
a1logd(p->log,1,"i1pro_save_calibration xdg_bds returned no paths\n");
return I1PRO_INT_CAL_SAVE;
}
a1logd(p->log,2,"i1pro_save_calibration saving to file '%s'\n",cal_paths[0]);
if (create_parent_directories(cal_paths[0])
|| (fp = fopen(cal_paths[0], nmode)) == NULL) {
a1logd(p->log,2,"i1pro_save_calibration failed to open file for writing\n");
xdg_free(cal_paths, no_paths);
return I1PRO_INT_CAL_SAVE;
}
x.ef = 0;
x.chsum = 0;
x.nbytes = 0;
/* A crude structure signature */
ss = sizeof(i1pro_state) + sizeof(i1proimp);
/* Some file identification */
write_ints(&x, fp, &argyllversion, 1);
write_ints(&x, fp, &ss, 1);
write_ints(&x, fp, &m->serno, 1);
write_ints(&x, fp, &isRevE, 1);
write_ints(&x, fp, (int *)&m->nraw, 1);
write_ints(&x, fp, (int *)&m->nwav[0], 1);
write_ints(&x, fp, (int *)&m->nwav[1], 1);
/* For each mode, save the calibration if it's valid */
for (i = 0; i < i1p_no_modes; i++) {
s = &m->ms[i];
/* Mode identification */
write_ints(&x, fp, &s->emiss, 1);
write_ints(&x, fp, &s->trans, 1);
write_ints(&x, fp, &s->reflective, 1);
write_ints(&x, fp, &s->scan, 1);
write_ints(&x, fp, &s->flash, 1);
write_ints(&x, fp, &s->ambient, 1);
write_ints(&x, fp, &s->adaptive, 1);
/* Configuration calibration is valid for */
write_ints(&x, fp, &s->gainmode, 1);
write_doubles(&x, fp, &s->inttime, 1);
/* Calibration information */
write_ints(&x, fp, &s->wl_valid, 1);
write_time_ts(&x, fp, &s->wldate, 1);
write_doubles(&x, fp, &s->wl_led_off, 1);
write_ints(&x, fp, &s->dark_valid, 1);
write_time_ts(&x, fp, &s->ddate, 1);
write_doubles(&x, fp, &s->dark_int_time, 1);
write_doubles(&x, fp, s->dark_data-1, m->nraw+1);
write_doubles(&x, fp, &s->dark_int_time2, 1);
write_doubles(&x, fp, s->dark_data2-1, m->nraw+1);
write_doubles(&x, fp, &s->dark_int_time3, 1);
write_doubles(&x, fp, s->dark_data3-1, m->nraw+1);
write_doubles(&x, fp, &s->dark_int_time4, 1);
write_doubles(&x, fp, s->dark_data4-1, m->nraw+1);
write_ints(&x, fp, &s->dark_gain_mode, 1);
if (!s->emiss) {
write_ints(&x, fp, &s->cal_valid, 1);
write_time_ts(&x, fp, &s->cfdate, 1);
write_doubles(&x, fp, s->cal_factor[0], m->nwav[0]);
write_doubles(&x, fp, s->cal_factor[1], m->nwav[1]);
write_doubles(&x, fp, s->white_data-1, m->nraw+1);
}
write_ints(&x, fp, &s->idark_valid, 1);
write_time_ts(&x, fp, &s->iddate, 1);
write_doubles(&x, fp, s->idark_int_time, 4);
write_doubles(&x, fp, s->idark_data[0]-1, m->nraw+1);
write_doubles(&x, fp, s->idark_data[1]-1, m->nraw+1);
write_doubles(&x, fp, s->idark_data[2]-1, m->nraw+1);
write_doubles(&x, fp, s->idark_data[3]-1, m->nraw+1);
}
a1logd(p->log,3,"nbytes = %d, Checkum = 0x%x\n",x.nbytes,x.chsum);
write_ints(&x, fp, (int *)&x.chsum, 1);
if (fclose(fp) != 0)
x.ef = 2;
if (x.ef != 0) {
a1logd(p->log,2,"Writing calibration file failed with %d\n",x.ef);
delete_file(cal_paths[0]);
return I1PRO_INT_CAL_SAVE;
} else {
a1logd(p->log,2,"Writing calibration file succeeded\n");
}
xdg_free(cal_paths, no_paths);
return ev;
}
/* Restore the all modes calibration from the local system */
i1pro_code i1pro_restore_calibration(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
i1pro_state *s, ts;
int i, j;
char nmode[10];
char cal_name[100]; /* Name */
char **cal_paths = NULL;
int no_paths = 0;
FILE *fp;
i1pnonv x;
int argyllversion;
int isRevE;
int ss, serno, nraw, nwav0, nwav1, nbytes, chsum1, chsum2;
strcpy(nmode, "r");
#if !defined(O_CREAT) && !defined(_O_CREAT)
# error "Need to #include fcntl.h!"
#endif
#if defined(O_BINARY) || defined(_O_BINARY)
strcat(nmode, "b");
#endif
/* Create the file name */
sprintf(cal_name, "ArgyllCMS/.i1p_%d.cal" SSEPS "color/.i1p_%d.cal", m->serno, m->serno);
if ((no_paths = xdg_bds(NULL, &cal_paths, xdg_cache, xdg_read, xdg_user, cal_name)) < 1) {
a1logd(p->log,2,"i1pro_restore_calibration xdg_bds failed to locate file'\n");
return I1PRO_INT_CAL_RESTORE;
}
a1logd(p->log,2,"i1pro_restore_calibration restoring from file '%s'\n",cal_paths[0]);
/* Check the last modification time */
{
struct sys_stat sbuf;
if (sys_stat(cal_paths[0], &sbuf) == 0) {
m->lo_secs = time(NULL) - sbuf.st_mtime;
a1logd(p->log,2,"i1pro_restore_calibration: %d secs from instrument last open\n",m->lo_secs);
} else {
a1logd(p->log,2,"i1pro_restore_calibration: stat on file failed\n");
}
}
if ((fp = fopen(cal_paths[0], nmode)) == NULL) {
a1logd(p->log,2,"i1pro_restore_calibration failed to open file for reading\n");
xdg_free(cal_paths, no_paths);
return I1PRO_INT_CAL_RESTORE;
}
x.ef = 0;
x.chsum = 0;
x.nbytes = 0;
/* Check the file identification */
read_ints(&x, fp, &argyllversion, 1);
read_ints(&x, fp, &ss, 1);
read_ints(&x, fp, &serno, 1);
read_ints(&x, fp, &isRevE, 1);
read_ints(&x, fp, &nraw, 1);
read_ints(&x, fp, &nwav0, 1);
read_ints(&x, fp, &nwav1, 1);
if (x.ef != 0
|| argyllversion != ARGYLL_VERSION
|| ss != (sizeof(i1pro_state) + sizeof(i1proimp))
|| serno != m->serno
|| isRevE != (p->itype == instI1Pro2 ? 1 : 0)
|| nraw != m->nraw
|| nwav0 != m->nwav[0]
|| nwav1 != m->nwav[1]) {
a1logd(p->log,2,"Identification didn't verify\n");
goto reserr;
}
/* Do a dummy read to check the checksum */
for (i = 0; i < i1p_no_modes; i++) {
int di;
double dd;
time_t dt;
int emiss, trans, reflective, ambient, scan, flash, adaptive;
s = &m->ms[i];
/* Mode identification */
read_ints(&x, fp, &emiss, 1);
read_ints(&x, fp, &trans, 1);
read_ints(&x, fp, &reflective, 1);
read_ints(&x, fp, &scan, 1);
read_ints(&x, fp, &flash, 1);
read_ints(&x, fp, &ambient, 1);
read_ints(&x, fp, &adaptive, 1);
/* Configuration calibration is valid for */
read_ints(&x, fp, &di, 1);
read_doubles(&x, fp, &dd, 1);
/* Calibration information */
read_ints(&x, fp, &di, 1);
read_time_ts(&x, fp, &dt, 1);
read_doubles(&x, fp, &dd, 1);
read_ints(&x, fp, &di, 1);
read_time_ts(&x, fp, &dt, 1);
read_doubles(&x, fp, &dd, 1);
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
read_doubles(&x, fp, &dd, 1);
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
read_doubles(&x, fp, &dd, 1); /* dark_data3 */
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
read_doubles(&x, fp, &dd, 1); /* dark_data4 */
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
read_ints(&x, fp, &di, 1);
if (!s->emiss) {
read_ints(&x, fp, &di, 1);
read_time_ts(&x, fp, &dt, 1);
for (j = 0; j < m->nwav[0]; j++)
read_doubles(&x, fp, &dd, 1);
for (j = 0; j < m->nwav[1]; j++)
read_doubles(&x, fp, &dd, 1);
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
}
read_ints(&x, fp, &di, 1);
read_time_ts(&x, fp, &dt, 1);
for (j = 0; j < 4; j++)
read_doubles(&x, fp, &dd, 1);
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
for (j = -1; j < m->nraw; j++)
read_doubles(&x, fp, &dd, 1);
}
chsum1 = x.chsum;
nbytes = x.nbytes;
read_ints(&x, fp, &chsum2, 1);
if (x.ef != 0
|| chsum1 != chsum2) {
a1logd(p->log,2,"Checksum didn't verify, bytes %d, got 0x%x, expected 0x%x\n",nbytes,chsum1, chsum2);
goto reserr;
}
rewind(fp);
x.ef = 0;
x.chsum = 0;
x.nbytes = 0;
/* Allocate space in temp structure */
ts.dark_data = dvectorz(-1, m->nraw-1);
ts.dark_data2 = dvectorz(-1, m->nraw-1);
ts.dark_data3 = dvectorz(-1, m->nraw-1);
ts.dark_data4 = dvectorz(-1, m->nraw-1);
ts.cal_factor[0] = dvectorz(0, m->nwav[0]-1);
ts.cal_factor[1] = dvectorz(0, m->nwav[1]-1);
ts.white_data = dvectorz(-1, m->nraw-1);
ts.idark_data = dmatrixz(0, 3, -1, m->nraw-1);
/* Read the identification */
read_ints(&x, fp, &argyllversion, 1);
read_ints(&x, fp, &ss, 1);
read_ints(&x, fp, &m->serno, 1);
read_ints(&x, fp, &isRevE, 1);
read_ints(&x, fp, (int *)&m->nraw, 1);
read_ints(&x, fp, (int *)&m->nwav[0], 1);
read_ints(&x, fp, (int *)&m->nwav[1], 1);
/* For each mode, restore the calibration if it's valid */
for (i = 0; i < i1p_no_modes; i++) {
s = &m->ms[i];
/* Mode identification */
read_ints(&x, fp, &ts.emiss, 1);
read_ints(&x, fp, &ts.trans, 1);
read_ints(&x, fp, &ts.reflective, 1);
read_ints(&x, fp, &ts.scan, 1);
read_ints(&x, fp, &ts.flash, 1);
read_ints(&x, fp, &ts.ambient, 1);
read_ints(&x, fp, &ts.adaptive, 1);
/* Configuration calibration is valid for */
read_ints(&x, fp, &ts.gainmode, 1);
read_doubles(&x, fp, &ts.inttime, 1);
/* Calibration information: */
/* Wavelength */
read_ints(&x, fp, &ts.wl_valid, 1);
read_time_ts(&x, fp, &ts.wldate, 1);
read_doubles(&x, fp, &ts.wl_led_off, 1);
/* Static Dark */
read_ints(&x, fp, &ts.dark_valid, 1);
read_time_ts(&x, fp, &ts.ddate, 1);
read_doubles(&x, fp, &ts.dark_int_time, 1);
read_doubles(&x, fp, ts.dark_data-1, m->nraw+1);
read_doubles(&x, fp, &ts.dark_int_time2, 1);
read_doubles(&x, fp, ts.dark_data2-1, m->nraw+1);
read_doubles(&x, fp, &ts.dark_int_time3, 1);
read_doubles(&x, fp, ts.dark_data3-1, m->nraw+1);
read_doubles(&x, fp, &ts.dark_int_time4, 1);
read_doubles(&x, fp, ts.dark_data4-1, m->nraw+1);
read_ints(&x, fp, &ts.dark_gain_mode, 1);
if (!ts.emiss) {
/* Reflective */
read_ints(&x, fp, &ts.cal_valid, 1);
read_time_ts(&x, fp, &ts.cfdate, 1);
read_doubles(&x, fp, ts.cal_factor[0], m->nwav[0]);
read_doubles(&x, fp, ts.cal_factor[1], m->nwav[1]);
read_doubles(&x, fp, ts.white_data-1, m->nraw+1);
}
/* Adaptive Dark */
read_ints(&x, fp, &ts.idark_valid, 1);
read_time_ts(&x, fp, &ts.iddate, 1);
read_doubles(&x, fp, ts.idark_int_time, 4);
read_doubles(&x, fp, ts.idark_data[0]-1, m->nraw+1);
read_doubles(&x, fp, ts.idark_data[1]-1, m->nraw+1);
read_doubles(&x, fp, ts.idark_data[2]-1, m->nraw+1);
read_doubles(&x, fp, ts.idark_data[3]-1, m->nraw+1);
/* If the configuration for this mode matches */
/* that of the calibration, restore the calibration */
/* for this mode. */
if (x.ef == 0 /* No read error */
&& s->emiss == ts.emiss
&& s->trans == ts.trans
&& s->reflective == ts.reflective
&& s->scan == ts.scan
&& s->flash == ts.flash
&& s->ambient == ts.ambient
&& s->adaptive == ts.adaptive
&& (s->adaptive || fabs(s->inttime - ts.inttime) < 0.01)
&& (s->adaptive || fabs(s->dark_int_time - ts.dark_int_time) < 0.01)
&& (s->adaptive || fabs(s->dark_int_time2 - ts.dark_int_time2) < 0.01)
&& (s->adaptive || fabs(s->dark_int_time3 - ts.dark_int_time3) < 0.01)
&& (s->adaptive || fabs(s->dark_int_time4 - ts.dark_int_time4) < 0.01)
&& (!s->adaptive || fabs(s->idark_int_time[0] - ts.idark_int_time[0]) < 0.01)
&& (!s->adaptive || fabs(s->idark_int_time[1] - ts.idark_int_time[1]) < 0.01)
&& (!s->adaptive || fabs(s->idark_int_time[2] - ts.idark_int_time[2]) < 0.01)
&& (!s->adaptive || fabs(s->idark_int_time[3] - ts.idark_int_time[3]) < 0.01)
) {
/* Copy all the fields read above */
s->emiss = ts.emiss;
s->trans = ts.trans;
s->reflective = ts.reflective;
s->scan = ts.scan;
s->flash = ts.flash;
s->ambient = ts.ambient;
s->adaptive = ts.adaptive;
s->gainmode = ts.gainmode;
s->inttime = ts.inttime;
s->wl_valid = ts.wl_valid;
s->wldate = ts.wldate;
s->wl_led_off = ts.wl_led_off;
s->dark_valid = ts.dark_valid;
s->ddate = ts.ddate;
s->dark_int_time = ts.dark_int_time;
for (j = -1; j < m->nraw; j++)
s->dark_data[j] = ts.dark_data[j];
s->dark_int_time2 = ts.dark_int_time2;
for (j = -1; j < m->nraw; j++)
s->dark_data2[j] = ts.dark_data2[j];
s->dark_int_time3 = ts.dark_int_time3;
for (j = -1; j < m->nraw; j++)
s->dark_data3[j] = ts.dark_data3[j];
s->dark_int_time4 = ts.dark_int_time4;
for (j = -1; j < m->nraw; j++)
s->dark_data4[j] = ts.dark_data4[j];
s->dark_gain_mode = ts.dark_gain_mode;
if (!ts.emiss) {
s->cal_valid = ts.cal_valid;
s->cfdate = ts.cfdate;
for (j = 0; j < m->nwav[0]; j++)
s->cal_factor[0][j] = ts.cal_factor[0][j];
for (j = 0; j < m->nwav[1]; j++)
s->cal_factor[1][j] = ts.cal_factor[1][j];
for (j = -1; j < m->nraw; j++)
s->white_data[j] = ts.white_data[j];
}
s->idark_valid = ts.idark_valid;
s->iddate = ts.iddate;
for (j = 0; j < 4; j++)
s->idark_int_time[j] = ts.idark_int_time[j];
for (j = -1; j < m->nraw; j++)
s->idark_data[0][j] = ts.idark_data[0][j];
for (j = -1; j < m->nraw; j++)
s->idark_data[1][j] = ts.idark_data[1][j];
for (j = -1; j < m->nraw; j++)
s->idark_data[2][j] = ts.idark_data[2][j];
for (j = -1; j < m->nraw; j++)
s->idark_data[3][j] = ts.idark_data[3][j];
} else {
a1logd(p->log,2,"Not restoring cal for mode %d since params don't match:\n",i);
a1logd(p->log,2,"emis = %d : %d, trans = %d : %d, ref = %d : %d\n",s->emiss,ts.emiss,s->trans,ts.trans,s->reflective,ts.reflective);
a1logd(p->log,2,"scan = %d : %d, flash = %d : %d, ambi = %d : %d, adapt = %d : %d\n",s->scan,ts.scan,s->flash,ts.flash,s->ambient,ts.ambient,s->adaptive,ts.adaptive);
a1logd(p->log,2,"inttime = %f : %f\n",s->inttime,ts.inttime);
a1logd(p->log,2,"darkit1 = %f : %f, 2 = %f : %f, 3 = %f : %f, 4 = %f : %f\n",s->dark_int_time,ts.dark_int_time,s->dark_int_time2,ts.dark_int_time2,s->dark_int_time3,ts.dark_int_time3,s->dark_int_time4,ts.dark_int_time4);
a1logd(p->log,2,"idarkit0 = %f : %f, 1 = %f : %f, 2 = %f : %f, 3 = %f : %f\n",s->idark_int_time[0],ts.idark_int_time[0],s->idark_int_time[1],ts.idark_int_time[1],s->idark_int_time[2],ts.idark_int_time[2],s->idark_int_time[3],ts.idark_int_time[3]);
}
}
/* Free up temporary space */
free_dvector(ts.dark_data, -1, m->nraw-1);
free_dvector(ts.dark_data2, -1, m->nraw-1);
free_dvector(ts.dark_data3, -1, m->nraw-1);
free_dvector(ts.dark_data4, -1, m->nraw-1);
free_dvector(ts.white_data, -1, m->nraw-1);
free_dmatrix(ts.idark_data, 0, 3, -1, m->nraw-1);
free_dvector(ts.cal_factor[0], 0, m->nwav[0]-1);
free_dvector(ts.cal_factor[1], 0, m->nwav[1]-1);
a1logd(p->log,5,"i1pro_restore_calibration done\n");
reserr:;
fclose(fp);
xdg_free(cal_paths, no_paths);
return ev;
}
i1pro_code i1pro_touch_calibration(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
char cal_name[100]; /* Name */
char **cal_paths = NULL;
int no_paths = 0;
int rv;
/* Locate the file name */
sprintf(cal_name, "ArgyllCMS/.i1p_%d.cal" SSEPS "color/.i1p_%d.cal", m->serno, m->serno);
if ((no_paths = xdg_bds(NULL, &cal_paths, xdg_cache, xdg_read, xdg_user, cal_name)) < 1) {
a1logd(p->log,2,"i1pro_restore_calibration xdg_bds failed to locate file'\n");
return I1PRO_INT_CAL_TOUCH;
}
a1logd(p->log,2,"i1pro_touch_calibration touching file '%s'\n",cal_paths[0]);
if ((rv = sys_utime(cal_paths[0], NULL)) != 0) {
a1logd(p->log,2,"i1pro_touch_calibration failed with %d\n",rv);
xdg_free(cal_paths, no_paths);
return I1PRO_INT_CAL_TOUCH;
}
xdg_free(cal_paths, no_paths);
return ev;
}
#endif /* ENABLE_NONVCAL */
/* ============================================================ */
/* Intermediate routines - composite commands/processing */
/* Some sort of configuration needed get instrument ready. */
/* Does it have a sleep mode that we need to deal with ?? */
/* Note this always does a reset. */
i1pro_code
i1pro_establish_high_power(i1pro *p) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
int i;
/* Get the current misc. status */
if ((ev = i1pro_getmisc(p, &m->fwrev, NULL, &m->maxpve, NULL, &m->powmode)) != I1PRO_OK)
return ev;
a1logd(p->log,2,"CPLD rev = %d\n",m->cpldrev);
if (m->powmode != 8) { /* In high power mode */
if ((ev = i1pro_reset(p, 0x1f)) != I1PRO_OK)
return ev;
return I1PRO_OK;
}
a1logd(p->log,4,"Switching to high power mode\n");
/* Switch to high power mode */
if ((ev = i1pro_reset(p, 1)) != I1PRO_OK)
return ev;
/* Wait up to 1.5 seconds for it return high power indication */
for (i = 0; i < 15; i++) {
/* Get the current misc. status */
if ((ev = i1pro_getmisc(p, &m->fwrev, NULL, &m->maxpve, NULL, &m->powmode)) != I1PRO_OK)
return ev;
if (m->powmode != 8) { /* In high power mode */
if ((ev = i1pro_reset(p, 0x1f)) != I1PRO_OK)
return ev;
return I1PRO_OK;
}
msec_sleep(100);
}
/* Failed to switch into high power mode */
return I1PRO_HW_HIGHPOWERFAIL;
}
/* Take a dark reference measurement - part 1 */
i1pro_code i1pro_dark_measure_1(
i1pro *p,
int nummeas, /* Number of readings to take */
double *inttime, /* Integration time to use/used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
unsigned char *buf, /* USB reading buffer to use */
unsigned int bsize /* Size of buffer */
) {
i1pro_code ev = I1PRO_OK;
if (nummeas <= 0)
return I1PRO_INT_ZEROMEASURES;
if ((ev = i1pro_trigger_one_measure(p, nummeas, inttime, gainmode, i1p_dark_cal)) != I1PRO_OK)
return ev;
if ((ev = i1pro_readmeasurement(p, nummeas, 0, buf, bsize, NULL, i1p_dark_cal)) != I1PRO_OK)
return ev;
return ev;
}
/* Take a dark reference measurement - part 2 */
i1pro_code i1pro_dark_measure_2(
i1pro *p,
double *absraw, /* Return array [-1 nraw] of absraw values */
int nummeas, /* Number of readings to take */
double inttime, /* Integration time to use/used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
unsigned char *buf, /* raw USB reading buffer to process */
unsigned int bsize /* Buffer size to process */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
double **multimes; /* Multiple measurement results */
double sensavg; /* Overall average of sensor readings */
double satthresh; /* Saturation threshold */
double darkthresh; /* Dark threshold */
int rv;
multimes = dmatrix(0, nummeas-1, -1, m->nraw-1); /* -1 is RevE shielded cells values */
if (gainmode == 0)
satthresh = m->sens_sat0;
else
satthresh = m->sens_sat1;
darkthresh = m->sens_dark + inttime * 900.0;
if (gainmode)
darkthresh *= m->highgain;
/* Take a buffer full of raw readings, and convert them to */
/* absolute linearised sensor values. */
if ((ev = i1pro_sens_to_absraw(p, multimes, buf, nummeas, inttime, gainmode, &darkthresh))
!= I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
return ev;
}
satthresh = i1pro_raw_to_absraw(p, satthresh, inttime, gainmode);
darkthresh = i1pro_raw_to_absraw(p, darkthresh, inttime, gainmode);
/* Average a set of measurements into one. */
/* Return zero if readings are consistent and not saturated. */
/* Return nz with bit 1 set if the readings are not consistent */
/* Return nz with bit 2 set if the readings are saturated */
/* Return the highest individual element. */
/* Return the overall average. */
rv = i1pro_average_multimeas(p, absraw, multimes, nummeas, NULL, &sensavg,
satthresh, darkthresh);
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
#ifdef PLOT_DEBUG
printf("Average absolute sensor readings, average = %f, satthresh %f:\n",sensavg, satthresh);
plot_raw(absraw);
#endif
if (rv & 1)
return I1PRO_RD_DARKREADINCONS;
if (rv & 2)
return I1PRO_RD_SENSORSATURATED;
a1logd(p->log,3,"Dark threshold = %f\n",darkthresh);
if (sensavg > (2.0 * darkthresh))
return I1PRO_RD_DARKNOTVALID;
return ev;
}
#ifdef DUMP_DARKM
int ddumpdarkm = 0;
#endif
/* Take a dark reference measurement (combined parts 1 & 2) */
i1pro_code i1pro_dark_measure(
i1pro *p,
double *absraw, /* Return array [-1 nraw] of absraw values */
int nummeas, /* Number of readings to take */
double *inttime, /* Integration time to use/used */
int gainmode /* Gain mode to use, 0 = normal, 1 = high */
) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
unsigned char *buf; /* Raw USB reading buffer */
unsigned int bsize;
bsize = m->nsen * 2 * nummeas;
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
a1logd(p->log,1,"i1pro_dark_measure malloc %d bytes failed (8)\n",bsize);
return I1PRO_INT_MALLOC;
}
if ((ev = i1pro_dark_measure_1(p, nummeas, inttime, gainmode, buf, bsize)) != I1PRO_OK) {
free(buf);
return ev;
}
if ((ev = i1pro_dark_measure_2(p, absraw,
nummeas, *inttime, gainmode, buf, bsize)) != I1PRO_OK) {
free(buf);
return ev;
}
free(buf);
#ifdef DUMP_DARKM
/* Dump raw dark readings to a file "i1pddump.txt" */
if (ddumpdarkm) {
int j;
FILE *fp;
if ((fp = fopen("i1pddump.txt", "a")) == NULL)
a1logw(p->log,"Unable to open debug file i1pddump.txt\n");
else {
fprintf(fp, "\nDark measure: nummeas %d, inttime %f, gainmode %d, darkcells %f\n",nummeas,*inttime,gainmode, absraw[-1]);
fprintf(fp,"\t\t\t{ ");
for (j = 0; j < (m->nraw-1); j++)
fprintf(fp, "%f, ",absraw[j]);
fprintf(fp, "%f },\n",absraw[j]);
fclose(fp);
}
}
#endif
return ev;
}
/* Take a white reference measurement */
/* (Subtracts black and processes into wavelenths) */
i1pro_code i1pro_whitemeasure(
i1pro *p,
double *abswav0, /* Return array [nwav[0]] of abswav values (may be NULL) */
double *abswav1, /* Return array [nwav[1]] of abswav values (if hr_init, may be NULL) */
double *absraw, /* Return array [-1 nraw] of absraw values */
double *optscale, /* Factor to scale gain/int time by to make optimal (may be NULL) */
int nummeas, /* Number of readings to take */
double *inttime, /* Integration time to use/used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
double targoscale, /* Optimal reading scale factor */
int ltocmode /* 1 = Lamp turn on compensation mode */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
unsigned char *buf; /* Raw USB reading buffer */
unsigned int bsize;
double **multimes; /* Multiple measurement results */
double darkthresh; /* Consitency threshold scale limit */
int rv;
a1logd(p->log,3,"i1pro_whitemeasure called \n");
darkthresh = m->sens_dark + *inttime * 900.0; /* Default */
if (gainmode)
darkthresh *= m->highgain;
if (nummeas <= 0)
return I1PRO_INT_ZEROMEASURES;
/* Allocate temporaries up front to avoid delay between trigger and read */
bsize = m->nsen * 2 * nummeas;
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
a1logd(p->log,1,"i1pro_whitemeasure malloc %d bytes failed (10)\n",bsize);
return I1PRO_INT_MALLOC;
}
multimes = dmatrix(0, nummeas-1, -1, m->nraw-1);
a1logd(p->log,3,"Triggering measurement cycle, nummeas %d, inttime %f, gainmode %d\n",
nummeas, *inttime, gainmode);
if ((ev = i1pro_trigger_one_measure(p, nummeas, inttime, gainmode, i1p_cal)) != I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
return ev;
}
a1logd(p->log,4,"Gathering readings\n");
if ((ev = i1pro_readmeasurement(p, nummeas, 0, buf, bsize, NULL, i1p_cal)) != I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
return ev;
}
/* Take a buffer full of raw readings, and convert them to */
/* absolute linearised sensor values. */
if ((ev = i1pro_sens_to_absraw(p, multimes, buf, nummeas, *inttime, gainmode, &darkthresh))
!= I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
return ev;
}
#ifdef PLOT_DEBUG
printf("Dark data:\n");
plot_raw(s->dark_data);
#endif
/* Subtract the black level */
i1pro_sub_absraw(p, nummeas, *inttime, gainmode, multimes, s->dark_data);
/* Convert linearised white value into output wavelength white reference */
ev = i1pro_whitemeasure_3(p, abswav0, abswav1, absraw, optscale, nummeas,
*inttime, gainmode, targoscale, multimes, darkthresh);
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
return ev;
}
/* Process a single raw white reference measurement */
/* (Subtracts black and processes into wavelenths) */
/* Used for restoring calibration from the EEProm */
i1pro_code i1pro_whitemeasure_buf(
i1pro *p,
double *abswav0, /* Return array [nwav[0]] of abswav values (may be NULL) */
double *abswav1, /* Return array [nwav[1]] of abswav values (if hr_init, may be NULL) */
double *absraw, /* Return array [-1 nraw] of absraw values */
double inttime, /* Integration time to used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
unsigned char *buf /* Raw buffer */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
double *meas; /* Multiple measurement results */
double darkthresh; /* Consitency threshold scale limit */
a1logd(p->log,3,"i1pro_whitemeasure_buf called \n");
meas = dvector(-1, m->nraw-1);
darkthresh = m->sens_dark + inttime * 900.0; /* Default */
if (gainmode)
darkthresh *= m->highgain;
/* Take a buffer full of raw readings, and convert them to */
/* absolute linearised sensor values. */
if ((ev = i1pro_sens_to_absraw(p, &meas, buf, 1, inttime, gainmode, &darkthresh))
!= I1PRO_OK) {
return ev;
}
/* Subtract the black level */
i1pro_sub_absraw(p, 1, inttime, gainmode, &meas, s->dark_data);
/* Convert linearised white value into output wavelength white reference */
ev = i1pro_whitemeasure_3(p, abswav0, abswav1, absraw, NULL, 1, inttime, gainmode,
0.0, &meas, darkthresh);
free_dvector(meas, -1, m->nraw-1);
return ev;
}
/* Take a white reference measurement - part 3 */
/* Average, check, and convert to output wavelengths */
i1pro_code i1pro_whitemeasure_3(
i1pro *p,
double *abswav0, /* Return array [nwav[0]] of abswav values (may be NULL) */
double *abswav1, /* Return array [nwav[1]] of abswav values (if hr_init, may be NULL) */
double *absraw, /* Return array [-1 nraw] of absraw values */
double *optscale, /* Factor to scale gain/int time by to make optimal (may be NULL) */
int nummeas, /* Number of readings to take */
double inttime, /* Integration time to use/used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
double targoscale, /* Optimal reading scale factor */
double **multimes, /* Multiple measurement results */
double darkthresh /* Raw dark threshold */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
double highest; /* Highest of sensor readings */
double sensavg; /* Overall average of sensor readings */
double satthresh; /* Saturation threshold */
double opttarget; /* Optimal sensor target */
int rv;
a1logd(p->log,3,"i1pro_whitemeasure_3 called \n");
if (gainmode == 0)
satthresh = m->sens_sat0;
else
satthresh = m->sens_sat1;
satthresh = i1pro_raw_to_absraw(p, satthresh, inttime, gainmode);
darkthresh = i1pro_raw_to_absraw(p, darkthresh, inttime, gainmode);
/* Average a set of measurements into one. */
/* Return zero if readings are consistent and not saturated. */
/* Return nz with bit 1 set if the readings are not consistent */
/* Return nz with bit 2 set if the readings are saturated */
/* Return the highest individual element. */
/* Return the overall average. */
rv = i1pro_average_multimeas(p, absraw, multimes, nummeas, &highest, &sensavg,
satthresh, darkthresh);
#ifdef PLOT_DEBUG
printf("Average absolute sensor readings, average = %f, satthresh %f:\n",sensavg, satthresh);
plot_raw(absraw);
#endif
#ifndef IGNORE_WHITE_INCONS
if (rv & 1) {
return I1PRO_RD_WHITEREADINCONS;
}
#endif /* IGNORE_WHITE_INCONS */
if (rv & 2) {
return I1PRO_RD_SENSORSATURATED;
}
/* Convert an absraw array from raw wavelengths to output wavelenths */
if (abswav0 != NULL) {
i1pro_absraw_to_abswav(p, 0, s->reflective, 1, &abswav0, &absraw);
#ifdef PLOT_DEBUG
printf("Converted to wavelengths std res:\n");
plot_wav(m, 0, abswav0);
#endif
}
#ifdef HIGH_RES
if (abswav1 != NULL && m->hr_inited) {
i1pro_absraw_to_abswav(p, 1, s->reflective, 1, &abswav1, &absraw);
#ifdef PLOT_DEBUG
printf("Converted to wavelengths high res:\n");
plot_wav(m, 1, abswav1);
#endif
}
#endif /* HIGH_RES */
if (optscale != NULL) {
double lhighest = highest;
if (lhighest < 1.0)
lhighest = 1.0;
/* Compute correction factor to make sensor optimal */
opttarget = i1pro_raw_to_absraw(p, (double)m->sens_target, inttime, gainmode);
opttarget *= targoscale;
a1logd(p->log,3,"Optimal target = %f, amount to scale = %f\n",opttarget, opttarget/lhighest);
*optscale = opttarget/lhighest;
}
return ev;
}
/* Take a wavelength reference measurement */
/* (Measure and subtracts black and convert to absraw) */
i1pro_code i1pro2_wl_measure(
i1pro *p,
double *absraw, /* Return array [-1 nraw] of absraw values */
double *optscale, /* Factor to scale gain/int time by to make optimal (may be NULL) */
double *inttime, /* Integration time to use/used */
double targoscale /* Optimal reading scale factor */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
int nummeas = 1; /* Number of measurements to take */
int gainmode = 0; /* Gain mode to use, 0 = normal, 1 = high */
unsigned char *buf; /* Raw USB reading buffer */
unsigned int bsize;
double *dark; /* Dark reading */
double **multimes; /* Measurement results */
double darkthresh; /* Consitency threshold scale limit/reading dark cell values */
double highest; /* Highest of sensor readings */
double sensavg; /* Overall average of sensor readings */
double satthresh; /* Saturation threshold */
double opttarget; /* Optimal sensor target */
int rv;
a1logd(p->log,3,"i1pro2_wl_measure called \n");
/* Allocate temporaries up front to avoid delay between trigger and read */
bsize = m->nsen * 2;
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
a1logd(p->log,1,"i1pro2_wl_measure malloc %d bytes failed (10)\n",bsize);
return I1PRO_INT_MALLOC;
}
/* Do a dark reading at our integration time */
dark = dvector(-1, m->nraw-1);
multimes = dmatrix(0, nummeas-1, -1, m->nraw-1);
if ((ev = i1pro_dark_measure(p, dark, nummeas, inttime, gainmode)) != I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(dark, -1, m->nraw-1);
free(buf);
return ev;
}
#ifdef PLOT_DEBUG
printf("Absraw dark data:\n");
plot_raw(dark);
#endif
a1logd(p->log,3,"Triggering wl measurement cycle, inttime %f\n", *inttime);
if ((ev = i1pro_trigger_one_measure(p, nummeas, inttime, gainmode, i1p2_wl_cal)) != I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(dark, -1, m->nraw-1);
free(buf);
return ev;
}
a1logd(p->log,4,"Gathering readings\n");
if ((ev = i1pro_readmeasurement(p, nummeas, 0, buf, bsize, NULL, i1p2_wl_cal)) != I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(dark, -1, m->nraw-1);
free(buf);
return ev;
}
/* Take a buffer full of raw readings, and convert them to */
/* absolute linearised sensor values. */
if ((ev = i1pro_sens_to_absraw(p, multimes, buf, nummeas, *inttime, gainmode, &darkthresh))
!= I1PRO_OK) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(dark, -1, m->nraw-1);
free(buf);
return ev;
}
/* Convert satthresh and darkthresh/dark_cell values to abs */
if (gainmode == 0)
satthresh = m->sens_sat0;
else
satthresh = m->sens_sat1;
satthresh = i1pro_raw_to_absraw(p, satthresh, *inttime, gainmode);
darkthresh = i1pro_raw_to_absraw(p, darkthresh, *inttime, gainmode);
#ifdef PLOT_DEBUG
printf("Absraw WL data:\n");
plot_raw(multimes[0]);
#endif
/* Subtract the black level */
i1pro_sub_absraw(p, nummeas, *inttime, gainmode, multimes, dark);
#ifdef PLOT_DEBUG
printf("Absraw WL - black data:\n");
plot_raw(multimes[0]);
#endif
/* Average a set of measurements into one. */
/* Return zero if readings are consistent and not saturated. */
/* Return nz with bit 1 set if the readings are not consistent */
/* Return nz with bit 2 set if the readings are saturated */
/* Return the highest individual element. */
/* Return the overall average. */
rv = i1pro_average_multimeas(p, absraw, multimes, 1, &highest, &sensavg,
satthresh, darkthresh);
#ifdef PLOT_DEBUG
printf("Average absolute sensor readings, average = %f, satthresh %f, absraw WL result:\n",sensavg, satthresh);
plot_raw(absraw);
#endif
#ifndef IGNORE_WHITE_INCONS
if (rv & 1) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(dark, -1, m->nraw-1);
free(buf);
return I1PRO_RD_WHITEREADINCONS;
}
#endif /* IGNORE_WHITE_INCONS */
if (rv & 2) {
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(dark, -1, m->nraw-1);
free(buf);
return I1PRO_RD_SENSORSATURATED;
}
if (optscale != NULL) {
double lhighest = highest;
if (lhighest < 1.0)
lhighest = 1.0;
/* Compute correction factor to make sensor optimal */
opttarget = i1pro_raw_to_absraw(p, (double)m->sens_target, *inttime, gainmode);
opttarget *= targoscale;
a1logd(p->log,3,"Optimal target = %f, amount to scale = %f\n",opttarget, opttarget/lhighest);
*optscale = opttarget/lhighest;
}
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(dark, -1, m->nraw-1);
free(buf);
return ev;
}
/* Take a measurement reading using the current mode, part 1 */
/* Converts to completely processed output readings. */
/* (NOTE:- this can't be used for calibration, as it implements uv mode) */
i1pro_code i1pro_read_patches_1(
i1pro *p,
int minnummeas, /* Minimum number of measurements to take */
int maxnummeas, /* Maximum number of measurements to allow for */
double *inttime, /* Integration time to use/used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
int *nmeasuered, /* Number actually measured */
unsigned char *buf, /* Raw USB reading buffer */
unsigned int bsize
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
i1p_mmodif mmod = i1p_norm;
int rv = 0;
if (minnummeas <= 0)
return I1PRO_INT_ZEROMEASURES;
if (minnummeas > maxnummeas)
maxnummeas = minnummeas;
if (m->uv_en)
mmod = i1p2_UV;
a1logd(p->log,3,"Triggering & gathering cycle, minnummeas %d, inttime %f, gainmode %d\n",
minnummeas, *inttime, gainmode);
if ((ev = i1pro_trigger_one_measure(p, minnummeas, inttime, gainmode, mmod)) != I1PRO_OK) {
return ev;
}
if ((ev = i1pro_readmeasurement(p, minnummeas, m->c_measmodeflags & I1PRO_MMF_SCAN,
buf, bsize, nmeasuered, mmod)) != I1PRO_OK) {
return ev;
}
return ev;
}
/* Take a measurement reading using the current mode, part 2 */
/* Converts to completely processed output readings. */
i1pro_code i1pro_read_patches_2(
i1pro *p,
double *duration, /* Return flash duration */
double **specrd, /* Return array [numpatches][nwav] of spectral reading values */
int numpatches, /* Number of patches to return */
double inttime, /* Integration time to used */
int gainmode, /* Gain mode useed, 0 = normal, 1 = high */
int nmeasuered, /* Number actually measured */
unsigned char *buf, /* Raw USB reading buffer */
unsigned int bsize
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
double **multimes; /* Multiple measurement results [maxnummeas|nmeasuered][-1 nraw]*/
double **absraw; /* Linearsised absolute sensor raw values [numpatches][-1 nraw]*/
double satthresh; /* Saturation threshold */
double darkthresh; /* Dark threshold for consistency scaling limit */
int rv = 0;
if (duration != NULL)
*duration = 0.0; /* default value */
darkthresh = m->sens_dark + inttime * 900.0; /* Default */
if (gainmode)
darkthresh *= m->highgain;
/* Allocate temporaries */
multimes = dmatrix(0, nmeasuered-1, -1, m->nraw-1);
absraw = dmatrix(0, numpatches-1, -1, m->nraw-1);
/* Take a buffer full of raw readings, and convert them to */
/* absolute linearised sensor values. */
if ((ev = i1pro_sens_to_absraw(p, multimes, buf, nmeasuered, inttime, gainmode, &darkthresh))
!= I1PRO_OK) {
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
free_dmatrix(multimes, 0, nmeasuered-1, -1, m->nraw-1);
return ev;
}
/* Subtract the black level */
i1pro_sub_absraw(p, nmeasuered, inttime, gainmode, multimes, s->dark_data);
#ifdef DUMP_SCANV
/* Dump raw scan readings to a file "i1pdump.txt" */
{
int i, j;
FILE *fp;
if ((fp = fopen("i1pdump.txt", "w")) == NULL)
a1logw(p->log,"Unable to open debug file i1pdump.txt\n");
else {
for (i = 0; i < nmeasuered; i++) {
fprintf(fp, "%d ",i);
for (j = 0; j < m->nraw; j++) {
fprintf(fp, "%f ",multimes[i][j]);
}
fprintf(fp,"\n");
}
fclose(fp);
}
}
#endif
if (gainmode == 0)
satthresh = m->sens_sat0;
else
satthresh = m->sens_sat1;
satthresh = i1pro_raw_to_absraw(p, satthresh, inttime, gainmode);
darkthresh = i1pro_raw_to_absraw(p, darkthresh, inttime, gainmode);
if (!s->scan) {
if (numpatches != 1) {
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
free_dmatrix(multimes, 0, nmeasuered-1, -1, m->nraw-1);
a1logd(p->log,2,"i1pro_read_patches_2 spot read failed because numpatches != 1\n");
return I1PRO_INT_WRONGPATCHES;
}
/* Average a set of measurements into one. */
/* Return zero if readings are consistent and not saturated. */
/* Return nz with bit 1 set if the readings are not consistent */
/* Return nz with bit 2 set if the readings are saturated */
/* Return the highest individual element. */
/* Return the overall average. */
rv = i1pro_average_multimeas(p, absraw[0], multimes, nmeasuered, NULL, NULL,
satthresh, darkthresh);
} else {
if (s->flash) {
if (numpatches != 1) {
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
free_dmatrix(multimes, 0, nmeasuered-1, -1, m->nraw-1);
a1logd(p->log,2,"i1pro_read_patches_2 spot read failed because numpatches != 1\n");
return I1PRO_INT_WRONGPATCHES;
}
if ((ev = i1pro_extract_patches_flash(p, &rv, duration, absraw[0], multimes,
nmeasuered, inttime)) != I1PRO_OK) {
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
free_dmatrix(multimes, 0, nmeasuered-1, -1, m->nraw-1);
a1logd(p->log,2,"i1pro_read_patches_2 spot read failed at i1pro_extract_patches_flash\n");
return ev;
}
} else {
a1logd(p->log,3,"Number of patches measured = %d\n",nmeasuered);
{
/* Recognise the required number of ref/trans patch locations, */
/* and average the measurements within each patch. */
if ((ev = i1pro_extract_patches_multimeas(p, &rv, absraw, numpatches, multimes,
nmeasuered, NULL, satthresh, inttime)) != I1PRO_OK) {
free_dmatrix(multimes, 0, nmeasuered-1, -1, m->nraw-1);
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
a1logd(p->log,2,"i1pro_read_patches_2 spot read failed at i1pro_extract_patches_multimeas\n");
return ev;
}
}
}
}
free_dmatrix(multimes, 0, nmeasuered-1, -1, m->nraw-1);
if (rv & 1) {
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
a1logd(p->log,3,"i1pro_read_patches_2 spot read failed with inconsistent readings\n");
return I1PRO_RD_READINCONS;
}
if (rv & 2) {
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
a1logd(p->log,3,"i1pro_read_patches_2 spot read failed with sensor saturated\n");
return I1PRO_RD_SENSORSATURATED;
}
/* Convert an absraw array from raw wavelengths to output wavelenths */
i1pro_absraw_to_abswav(p, m->highres, s->reflective, numpatches, specrd, absraw);
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
#ifdef APPEND_MEAN_EMMIS_VAL
/* Append averaged emission reading to file "i1pdump.txt" */
{
int i, j;
FILE *fp;
/* Create wavelegth label */
if ((fp = fopen("i1pdump.txt", "r")) == NULL) {
if ((fp = fopen("i1pdump.txt", "w")) == NULL)
a1logw(p->log,"Unable to reate debug file i1pdump.txt\n");
else {
for (j = 0; j < m->nwav[m->highres]; j++)
fprintf(fp,"%f ",XSPECT_WL(m->wl_short[m->highres], m->wl_long[m->highres], m->nwav[m->highres], j));
fprintf(fp,"\n");
fclose(fp);
}
}
if ((fp = fopen("i1pdump.txt", "a")) == NULL) {
a1logw(p->log,"Unable to open debug file i1pdump.txt\n");
else {
for (j = 0; j < m->nwav[m->highres]; j++)
fprintf(fp, "%f ",specrd[0][j] * m->emis_coef[j]);
fprintf(fp,"\n");
fclose(fp);
}
}
#endif
#ifdef PLOT_DEBUG
printf("Converted to wavelengths:\n");
plot_wav(m, m->highres, specrd[0]);
#endif
/* Scale to the calibrated output values */
i1pro_scale_specrd(p, specrd, numpatches, specrd);
#ifdef PLOT_DEBUG
printf("Calibrated measuerment spectra:\n");
plot_wav(m, m->highres, specrd[0]);
#endif
return ev;
}
/* Take a measurement reading using the current mode, part 2a */
/* Converts to completely processed output readings, */
/* but don't average together or extract patches or flash. */
/* (! Note that we aren't currently detecting saturation here!) */
i1pro_code i1pro_read_patches_2a(
i1pro *p,
double **specrd, /* Return array [numpatches][nwav] of spectral reading values */
int numpatches, /* Number of patches measured and to return */
double inttime, /* Integration time to used */
int gainmode, /* Gain mode useed, 0 = normal, 1 = high */
unsigned char *buf, /* Raw USB reading buffer */
unsigned int bsize
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
double **absraw; /* Linearsised absolute sensor raw values [numpatches][-1 nraw]*/
double satthresh; /* Saturation threshold */
double darkthresh; /* Dark threshold for consistency scaling limit */
darkthresh = m->sens_dark + inttime * 900.0; /* Default */
if (gainmode)
darkthresh *= m->highgain;
/* Allocate temporaries */
absraw = dmatrix(0, numpatches-1, -1, m->nraw-1);
/* Take a buffer full of raw readings, and convert them to */
/* absolute linearised sensor values. */
if ((ev = i1pro_sens_to_absraw(p, absraw, buf, numpatches, inttime, gainmode, &darkthresh))
!= I1PRO_OK) {
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
return ev;
}
/* Subtract the black level */
i1pro_sub_absraw(p, numpatches, inttime, gainmode, absraw, s->dark_data);
if (gainmode == 0)
satthresh = m->sens_sat0;
else
satthresh = m->sens_sat1;
satthresh = i1pro_raw_to_absraw(p, satthresh, inttime, gainmode);
darkthresh = i1pro_raw_to_absraw(p, darkthresh, inttime, gainmode);
a1logd(p->log,3,"Number of patches measured = %d\n",numpatches);
/* Convert an absraw array from raw wavelengths to output wavelenths */
i1pro_absraw_to_abswav(p, m->highres, s->reflective, numpatches, specrd, absraw);
free_dmatrix(absraw, 0, numpatches-1, -1, m->nraw-1);
#ifdef PLOT_DEBUG
printf("Converted to wavelengths:\n");
plot_wav(m, m->highres, specrd[0]);
#endif
/* Scale to the calibrated output values */
i1pro_scale_specrd(p, specrd, numpatches, specrd);
#ifdef PLOT_DEBUG
printf("Calibrated measuerment spectra:\n");
plot_wav(m, m->highres, specrd[0]);
#endif
return ev;
}
/* Take a measurement reading using the current mode (combined parts 1 & 2) */
/* Converts to completely processed output readings. */
/* (NOTE:- this can't be used for calibration, as it implements uv mode) */
i1pro_code i1pro_read_patches(
i1pro *p,
double *duration, /* Return flash duration */
double **specrd, /* Return array [numpatches][nwav] of spectral reading values */
int numpatches, /* Number of patches to return */
int minnummeas, /* Minimum number of measurements to take */
int maxnummeas, /* Maximum number of measurements to allow for */
double *inttime, /* Integration time to use/used */
int gainmode /* Gain mode to use, 0 = normal, 1 = high */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
unsigned char *buf; /* Raw USB reading buffer */
unsigned int bsize;
int nmeasuered; /* Number actually measured */
int rv = 0;
if (minnummeas <= 0)
return I1PRO_INT_ZEROMEASURES;
if (minnummeas > maxnummeas)
maxnummeas = minnummeas;
/* Allocate temporaries */
bsize = m->nsen * 2 * maxnummeas;
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
a1logd(p->log,1,"i1pro_read_patches malloc %d bytes failed (11)\n",bsize);
return I1PRO_INT_MALLOC;
}
/* Trigger measure and gather raw readings */
if ((ev = i1pro_read_patches_1(p, minnummeas, maxnummeas, inttime, gainmode,
&nmeasuered, buf, bsize)) != I1PRO_OK) {
free(buf);
return ev;
}
/* Process the raw readings */
if ((ev = i1pro_read_patches_2(p, duration, specrd, numpatches, *inttime, gainmode,
nmeasuered, buf, bsize)) != I1PRO_OK) {
free(buf);
return ev;
}
free(buf);
return ev;
}
/* Take a measurement reading using the current mode (combined parts 1 & 2a) */
/* Converts to completely processed output readings, without averaging or extracting */
/* sample patches. */
/* (NOTE:- this can't be used for calibration, as it implements uv mode) */
i1pro_code i1pro_read_patches_all(
i1pro *p,
double **specrd, /* Return array [numpatches][nwav] of spectral reading values */
int numpatches, /* Number of sample to measure */
double *inttime, /* Integration time to use/used */
int gainmode /* Gain mode to use, 0 = normal, 1 = high */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
unsigned char *buf; /* Raw USB reading buffer */
unsigned int bsize;
int rv = 0;
bsize = m->nsen * 2 * numpatches; /* 16 bit raw values */
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
a1logd(p->log,1,"i1pro_read_patches malloc %d bytes failed (11)\n",bsize);
return I1PRO_INT_MALLOC;
}
/* Trigger measure and gather raw readings */
if ((ev = i1pro_read_patches_1(p, numpatches, numpatches, inttime, gainmode,
NULL, buf, bsize)) != I1PRO_OK) {
free(buf);
return ev;
}
/* Process the raw readings without averaging or extraction */
if ((ev = i1pro_read_patches_2a(p, specrd, numpatches, *inttime, gainmode,
buf, bsize)) != I1PRO_OK) {
free(buf);
return ev;
}
free(buf);
return ev;
}
/* Take a trial measurement reading using the current mode. */
/* Used to determine if sensor is saturated, or not optimal */
/* in adaptive emission mode. */
i1pro_code i1pro_trialmeasure(
i1pro *p,
int *saturated, /* Return nz if sensor is saturated */
double *optscale, /* Factor to scale gain/int time by to make optimal (may be NULL) */
int nummeas, /* Number of readings to take */
double *inttime, /* Integration time to use/used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
double targoscale /* Optimal reading scale factor */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
unsigned char *buf; /* Raw USB reading buffer */
unsigned int bsize;
double **multimes; /* Multiple measurement results */
double *absraw; /* Linearsised absolute sensor raw values */
int nmeasuered; /* Number actually measured */
double highest; /* Highest of sensor readings */
double sensavg; /* Overall average of sensor readings */
double satthresh; /* Saturation threshold */
double darkthresh; /* Dark threshold */
double opttarget; /* Optimal sensor target */
int rv;
if (nummeas <= 0)
return I1PRO_INT_ZEROMEASURES;
darkthresh = m->sens_dark + *inttime * 900.0;
if (gainmode)
darkthresh *= m->highgain;
/* Allocate up front to avoid delay between trigger and read */
bsize = m->nsen * 2 * nummeas;
if ((buf = (unsigned char *)malloc(sizeof(unsigned char) * bsize)) == NULL) {
a1logd(p->log,1,"i1pro_trialmeasure malloc %d bytes failed (12)\n",bsize);
return I1PRO_INT_MALLOC;
}
multimes = dmatrix(0, nummeas-1, -1, m->nraw-1);
absraw = dvector(-1, m->nraw-1);
a1logd(p->log,3,"Triggering measurement cycle, nummeas %d, inttime %f, gainmode %d\n",
nummeas, *inttime, gainmode);
if ((ev = i1pro_trigger_one_measure(p, nummeas, inttime, gainmode, i1p_cal)) != I1PRO_OK) {
free_dvector(absraw, -1, m->nraw-1);
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
return ev;
}
a1logd(p->log,4,"Gathering readings\n");
if ((ev = i1pro_readmeasurement(p, nummeas, m->c_measmodeflags & I1PRO_MMF_SCAN,
buf, bsize, &nmeasuered, i1p_cal)) != I1PRO_OK) {
free_dvector(absraw, -1, m->nraw-1);
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
return ev;
}
/* Take a buffer full of raw readings, and convert them to */
/* absolute linearised sensor values. */
if ((ev = i1pro_sens_to_absraw(p, multimes, buf, nmeasuered, *inttime, gainmode, &darkthresh))
!= I1PRO_OK) {
free_dvector(absraw, -1, m->nraw-1);
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
return ev;
}
/* Compute dark subtraction for this trial's parameters */
if ((ev = i1pro_interp_dark(p, s->dark_data,
s->inttime, s->gainmode)) != I1PRO_OK) {
free_dvector(absraw, -1, m->nraw-1);
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free(buf);
a1logd(p->log,2,"i1pro_trialmeasure interplate dark ref failed\n");
return ev;
}
/* Subtract the black level */
i1pro_sub_absraw(p, nummeas, *inttime, gainmode, multimes, s->dark_data);
if (gainmode == 0)
satthresh = m->sens_sat0;
else
satthresh = m->sens_sat1;
satthresh = i1pro_raw_to_absraw(p, satthresh, *inttime, gainmode);
darkthresh = i1pro_raw_to_absraw(p, darkthresh, *inttime, gainmode);
/* Average a set of measurements into one. */
/* Return zero if readings are consistent and not saturated. */
/* Return nz with bit 1 set if the readings are not consistent */
/* Return nz with bit 2 set if the readings are saturated */
/* Return the highest individual element. */
/* Return the overall average. */
rv = i1pro_average_multimeas(p, absraw, multimes, nmeasuered, &highest, &sensavg,
satthresh, darkthresh);
#ifdef PLOT_DEBUG
printf("Average absolute sensor readings, average = %f, satthresh %f:\n",sensavg, satthresh);
plot_raw(absraw);
#endif
if (saturated != NULL) {
*saturated = 0;
if (rv & 2)
*saturated = 1;
}
/* Compute correction factor to make sensor optimal */
opttarget = (double)m->sens_target * targoscale;
opttarget = i1pro_raw_to_absraw(p, opttarget, *inttime, gainmode);
if (optscale != NULL) {
double lhighest = highest;
if (lhighest < 1.0)
lhighest = 1.0;
*optscale = opttarget/lhighest;
}
free_dmatrix(multimes, 0, nummeas-1, -1, m->nraw-1);
free_dvector(absraw, -1, m->nraw-1);
free(buf);
return ev;
}
/* Trigger a single measurement cycle. This could be a dark calibration, */
/* a calibration, or a real measurement. This is used to create the */
/* higher level "calibrate" and "take reading" functions. */
/* The setup for the operation is in the current mode state. */
/* Call i1pro_readmeasurement() to collect the results */
i1pro_code
i1pro_trigger_one_measure(
i1pro *p,
int nummeas, /* Minimum number of measurements to make */
double *inttime, /* Integration time to use/used */
int gainmode, /* Gain mode to use, 0 = normal, 1 = high */
i1p_mmodif mmodif /* Measurement modifier enum */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
unsigned int timssinceoff; /* time in msec since lamp turned off */
double dintclocks;
int intclocks; /* Number of integration clocks */
double dlampclocks;
int lampclocks; /* Number of lamp turn on sub-clocks */
int measmodeflags; /* Measurement mode command flags */
int measmodeflags2; /* Rev E Measurement mode command flags */
/* Sanity check in case bad value was restored, due to switch */
/* from Rev A-D to Rev E mode. */
if (*inttime < m->min_int_time)
*inttime = m->min_int_time;
/* The Rev E measure mode has it's own settings */
if (p->itype == instI1Pro2) {
m->intclkp = m->intclkp2; /* From i1pro2_getmeaschar() ? */
m->subclkdiv = m->subclkdiv2;
m->subtmode = 0;
} else {
/* Set any special hardware up for this sort of read */
if (*inttime != m->c_inttime) { /* integration time is different */
int mcmode, maxmcmode;
int intclkusec;
int subtmodeflags;
/* Setting for fwrev < 301 */
/* (This is what getmcmode() returns for mcmode = 1 on fwrev >= 301) */
m->intclkp = 68.0e-6;
m->subclkdiv = 130;
m->subtmode = 0;
if (m->fwrev >= 301) { /* Special hardware in latter versions of instrument */
#ifdef DEBUG
/* Show all the available clock modes */
for (mcmode = 1;; mcmode++) {
int rmcmode, subclkdiv;
if ((ev = i1pro_setmcmode(p, mcmode)) != I1PRO_OK)
break;
if ((ev = i1pro_getmcmode(p, &maxmcmode, &rmcmode, &subclkdiv,
&intclkusec, &subtmodeflags) ) != I1PRO_OK)
break;
fprintf(stderr,"getcmode %d: maxcmode %d, mcmode %d, subclkdif %d, intclkusec %d, subtmodeflags 0x%x\n",mcmode,maxmcmode,rmcmode,subclkdiv,intclkusec,subtmodeflags);
if (mcmode >= maxmcmode)
break;
}
#endif
/* Configure a clock mode that gives us an optimal integration time ? */
for (mcmode = 1;; mcmode++) {
if ((ev = i1pro_setmcmode(p, mcmode)) != I1PRO_OK)
return ev;
if ((ev = i1pro_getmcmode(p, &maxmcmode, &mcmode, &m->subclkdiv,
&intclkusec, &subtmodeflags) ) != I1PRO_OK)
return ev;
if ((*inttime/(intclkusec * 1e-6)) > 65535.0) {
return I1PRO_INT_INTTOOBIG;
}
if (*inttime >= (intclkusec * m->subclkdiv * 1e-6 * 0.99))
break; /* Setting is optimal */
/* We need to go around again */
if (mcmode >= maxmcmode) {
return I1PRO_INT_INTTOOSMALL;
}
}
m->c_mcmode = mcmode;
m->intclkp = intclkusec * 1e-6;
a1logd(p->log,3,"Switched to perfect mode, subtmode flag = 0x%x, intclk = %f Mhz\n",subtmodeflags & 0x01, 1.0/intclkusec);
if (subtmodeflags & 0x01)
m->subtmode = 1; /* Last reading subtract mode */
}
}
}
a1logd(p->log,3,"Integration clock period = %f ussec\n",m->intclkp * 1e6);
/* Compute integration clocks */
dintclocks = floor(*inttime/m->intclkp + 0.5);
if (p->itype == instI1Pro2) {
if (dintclocks > 4294967296.0) /* This is probably not the actual limit */
return I1PRO_INT_INTTOOBIG;
} else {
if (dintclocks > 65535.0)
return I1PRO_INT_INTTOOBIG;
}
intclocks = (int)dintclocks;
*inttime = (double)intclocks * m->intclkp; /* Quantized integration time */
if (s->reflective && (mmodif & 0x10)) {
dlampclocks = floor(s->lamptime/(m->subclkdiv * m->intclkp) + 0.5);
if (dlampclocks > 256.0) /* Clip - not sure why. Silly value anyway */
dlampclocks = 256.0;
lampclocks = (int)dlampclocks;
s->lamptime = dlampclocks * m->subclkdiv * m->intclkp; /* Quantized lamp time */
} else {
dlampclocks = 0.0;
lampclocks = 0;
}
if (nummeas > 65535)
nummeas = 65535; /* Or should we error ? */
/* Create measurement mode flag values for this operation for both */
/* legacy and Rev E mode. Other code will examine legacy mode flags */
measmodeflags = 0;
if (s->scan && !(mmodif & 0x20)) /* Never scan on a calibration */
measmodeflags |= I1PRO_MMF_SCAN;
if (!s->reflective || !(mmodif & 0x10))
measmodeflags |= I1PRO_MMF_NOLAMP; /* No lamp if not reflective or dark measure */
if (gainmode == 0)
measmodeflags |= I1PRO_MMF_LOWGAIN; /* Normal gain mode */
if (p->itype == instI1Pro2) {
measmodeflags2 = 0;
if (s->scan && !(mmodif & 0x20)) /* Never scan on a calibration */
measmodeflags2 |= I1PRO2_MMF_SCAN;
if (mmodif == i1p2_UV)
measmodeflags2 |= I1PRO2_MMF_UV_LED; /* UV LED illumination measurement */
else if (mmodif == i1p2_wl_cal)
measmodeflags2 |= I1PRO2_MMF_WL_LED; /* Wavelegth illumination cal */
else if (s->reflective && (mmodif & 0x10))
measmodeflags2 |= I1PRO2_MMF_LAMP; /* lamp if reflective and mmodif possible */
if (gainmode != 0)
return I1PRO_INT_NO_HIGH_GAIN;
}
a1logd(p->log,2,"i1pro: Int time %f msec, delay %f msec, no readings %d, expect %f msec\n",
*inttime * 1000.0,
((measmodeflags & I1PRO_MMF_NOLAMP) ? 0.0 : s->lamptime) * 1000.0,
nummeas,
(nummeas * *inttime + ((measmodeflags & I1PRO_MMF_NOLAMP) ? 0.0 : s->lamptime)) * 1000.0);
/* Do a setmeasparams */
#ifdef NEVER
if (intclocks != m->c_intclocks /* If any parameters have changed */
|| lampclocks != m->c_lampclocks
|| nummeas != m->c_nummeas
|| measmodeflags != m->c_measmodeflags
|| measmodeflags2 != m->c_measmodeflags2)
#endif /* NEVER */
{
if (p->itype != instI1Pro2) { /* Rev E sets the params in the measure command */
/* Set the hardware for measurement */
if ((ev = i1pro_setmeasparams(p, intclocks, lampclocks, nummeas, measmodeflags)) != I1PRO_OK)
return ev;
} else {
a1logd(p->log,2,"\ni1pro: SetMeasureParam2 %d, %d, %d, 0x%04x @ %d msec\n",
intclocks, lampclocks, nummeas, measmodeflags2,
msec_time() - m->msec);
}
m->c_intclocks = intclocks;
m->c_lampclocks = lampclocks;
m->c_nummeas = nummeas;
m->c_measmodeflags = measmodeflags;
m->c_measmodeflags2 = measmodeflags2;
m->c_inttime = *inttime; /* Special harware is configured */
m->c_lamptime = s->lamptime;
}
/* If the lamp needs to be off, make sure at least 1.5 seconds */
/* have elapsed since it was last on, to make sure it's dark. */
if ((measmodeflags & I1PRO_MMF_NOLAMP)
&& (timssinceoff = (msec_time() - m->llamponoff)) < LAMP_OFF_TIME) {
a1logd(p->log,3,"Sleep %d msec for lamp cooldown\n",LAMP_OFF_TIME - timssinceoff);
msec_sleep(LAMP_OFF_TIME - timssinceoff); /* Make sure time adds up to 1.5 seconds */
}
/* Trigger a measurement */
usb_reinit_cancel(&m->rd_sync); /* Prepare to sync rd and trigger */
if (p->itype != instI1Pro2) {
if ((ev = i1pro_triggermeasure(p, TRIG_DELAY)) != I1PRO_OK)
return ev;
} else {
if ((ev = i1pro2_triggermeasure(p, TRIG_DELAY)) != I1PRO_OK)
return ev;
}
return ev;
}
/* ============================================================ */
/* Big endian wire format conversion routines */
/* Take an int, and convert it into a byte buffer big endian */
static void int2buf(unsigned char *buf, int inv) {
buf[0] = (inv >> 24) & 0xff;
buf[1] = (inv >> 16) & 0xff;
buf[2] = (inv >> 8) & 0xff;
buf[3] = (inv >> 0) & 0xff;
}
/* Take a short, and convert it into a byte buffer big endian */
static void short2buf(unsigned char *buf, int inv) {
buf[0] = (inv >> 8) & 0xff;
buf[1] = (inv >> 0) & 0xff;
}
/* Take a word sized buffer, and convert it to an int */
static int buf2int(unsigned char *buf) {
int val;
val = buf[0]; /* Hmm. should this be sign extended ?? */
val = ((val << 8) + (0xff & buf[1]));
val = ((val << 8) + (0xff & buf[2]));
val = ((val << 8) + (0xff & buf[3]));
return val;
}
/* Take a short sized buffer, and convert it to an int */
static int buf2short(unsigned char *buf) {
int val;
val = *((signed char *)buf); /* Sign extend */
val = ((val << 8) + (0xff & buf[1]));
return val;
}
/* Take a unsigned short sized buffer, and convert it to an int */
static int buf2ushort(unsigned char *buf) {
int val;
val = (0xff & buf[0]);
val = ((val << 8) + (0xff & buf[1]));
return val;
}
/* ============================================================ */
/* lower level reading processing and computation */
/* Take a buffer full of sensor readings, and convert them to */
/* absolute raw values. Linearise if Rev A..D */
/* If RevE, fill in the [-1] value with the shielded cell values */
/* Note the rev E darkthresh returned has NOT been converted to an absolute raw value */
i1pro_code i1pro_sens_to_absraw(
i1pro *p,
double **absraw, /* Array of [nummeas][-1 nraw] value to return */
unsigned char *buf, /* Raw measurement data must be nsen * nummeas */
int nummeas, /* Return number of readings measured */
double inttime, /* Integration time used */
int gainmode, /* Gain mode, 0 = normal, 1 = high */
double *pdarkthresh /* Return a raw dark threshold value (Rev E) */
) {
i1proimp *m = (i1proimp *)p->m;
int i, j, k;
unsigned char *bp;
unsigned int maxpve = m->maxpve; /* maximum +ve sensor value + 1 */
double avlastv = 0.0;
double darkthresh = 0.0; /* Rev E calculated values */
double ndarkthresh = 0.0;
double gain;
int npoly; /* Number of linearisation coefficients */
double *polys; /* the coeficients */
double scale; /* Absolute scale value */
int sskip = 0; /* Bytes to skip at start */
int eskip = 0; /* Bytes to skip at end */
if (gainmode) {
gain = m->highgain;
npoly = m->nlin1;
polys = m->lin1;
} else {
gain = 1.0;
npoly = m->nlin0;
polys = m->lin0;
}
scale = 1.0/(inttime * gain);
/* Now process the buffer values */
if (m->nsen > m->nraw) { /* It's a Rev E, so we have extra values, */
/* and don't linearize here. */
sskip = 6 * 2; /* 6 dark reading values */
eskip = 0 * 2; /* none to skip at end */
if ((sskip + m->nraw * 2 + eskip) != (m->nsen * 2)) {
a1loge(p->log,1,"i1pro Rev E - sskip %d + nraw %d + eskip %d != nsen %d\n"
,sskip, m->nraw * 2, eskip, m->nsen * 2);
return I1PRO_INT_ASSERT;
}
for (bp = buf, i = 0; i < nummeas; i++, bp += eskip) {
unsigned int rval;
double fval;
/* The first 6 readings (xraw from i1pro2_getmeaschar()) are shielded cells, */
/* and we use them as an estimate of the dark reading consistency, as well as for */
/* compensating the dark level calibration for any temperature changes. */
/* raw average of all measurement shielded cell values */
for (k = 0; k < 6; k++) {
darkthresh += (double)buf2ushort(bp + k * 2);
ndarkthresh++;
}
/* absraw of shielded cells per reading */
absraw[i][-1] = 0.0;
for (k = 0; k < 6; k++) {
rval = buf2ushort(bp + k * 2);
fval = (double)(int)rval;
/* And scale to be an absolute sensor reading */
absraw[i][-1] += fval * scale;
}
absraw[i][-1] /= 6.0;
for (bp += sskip, j = 0; j < m->nraw; j++, bp += 2) {
rval = buf2ushort(bp);
a1logd(p->log,9,"% 3d:rval 0x%x, ",j, rval);
a1logd(p->log,9,"srval 0x%x, ",rval);
fval = (double)(int)rval;
a1logd(p->log,9,"fval %.0f, ",fval);
/* And scale to be an absolute sensor reading */
absraw[i][j] = fval * scale;
a1logd(p->log,9,"absval %.1f\n",fval * scale);
}
}
darkthresh /= ndarkthresh;
if (pdarkthresh != NULL)
*pdarkthresh = darkthresh;
a1logd(p->log,3,"i1pro_sens_to_absraw: Dark threshold = %f\n",darkthresh);
} else {
/* if subtmode is set, compute the average last reading raw value. */
/* Could this be some sort of temperature compensation offset ??? */
/* (Rev A produces a value that is quite different to a sensor value, */
/* ie. 1285 = 0x0505, while RevD and RevE in legacy mode have a value of 0 */
/* I've not seen anything actually use subtmode - maybe this is Rev B only ?) */
/* The 0 band seens to contain values similar to band 1, so it's not clear */
/* why the manufacturers driver appears to be discarding it ? */
/* (Not sure if it's reasonable to extend the sign and then do this */
/* computation, or whether it makes any difference, since I've never */
/* seen this mode triggered. */
if (m->subtmode) {
for (bp = buf + 254, i = 0; i < nummeas; i++, bp += (m->nsen * 2)) {
unsigned int lastv;
lastv = buf2ushort(bp);
if (lastv >= maxpve) {
lastv -= 0x00010000; /* Convert to -ve */
}
avlastv += (double)lastv;
}
avlastv /= (double)nummeas;
a1logd(p->log,3,"subtmode got avlastv = %f\n",avlastv);
}
for (bp = buf, i = 0; i < nummeas; i++) {
absraw[i][-1] = 1.0; /* Not used in RevA-D */
for (j = 0; j < 128; j++, bp += 2) {
unsigned int rval;
double fval, lval;
rval = buf2ushort(bp);
a1logd(p->log,9,"% 3d:rval 0x%x, ",j, rval);
if (rval >= maxpve)
rval -= 0x00010000; /* Convert to -ve */
a1logd(p->log,9,"srval 0x%x, ",rval);
fval = (double)(int)rval;
a1logd(p->log,9,"fval %.0f, ",fval);
fval -= avlastv;
a1logd(p->log,9,"fval-av %.0f, ",fval);
#ifdef ENABLE_NONLINCOR
/* Linearise */
for (lval = polys[npoly-1], k = npoly-2; k >= 0; k--)
lval = lval * fval + polys[k];
#else
lval = fval;
#endif
a1logd(p->log,9,"lval %.1f, ",lval);
/* And scale to be an absolute sensor reading */
absraw[i][j] = lval * scale;
a1logd(p->log,9,"absval %.1f\n",lval * scale);
// a1logd(p->log,3,"Meas %d band %d raw = %f\n",i,j,fval);
}
/* Duplicate last values in buffer to make up to 128 */
absraw[i][0] = absraw[i][1];
absraw[i][127] = absraw[i][126];
}
}
return I1PRO_OK;
}
/* Take a raw value, and convert it into an absolute raw value. */
/* Note that linearisation is ignored, since it is assumed to be insignificant */
/* to the black threshold and saturation values. */
double i1pro_raw_to_absraw(
i1pro *p,
double raw, /* Input value */
double inttime, /* Integration time used */
int gainmode /* Gain mode, 0 = normal, 1 = high */
) {
i1proimp *m = (i1proimp *)p->m;
int i, j, k;
double gain;
double scale; /* Absolute scale value */
double fval;
if (gainmode) {
gain = m->highgain;
} else {
gain = 1.0;
}
scale = 1.0/(inttime * gain);
return raw * scale;
}
/* Invert a polinomial equation. */
/* Since the linearisation is nearly a straight line, */
/* a simple Newton inversion will suffice. */
static double inv_poly(double *polys, int npoly, double inv) {
double outv = inv, lval, del = 100.0;
int i, k;
for (i = 0; i < 200 && fabs(del) > 1e-7; i++) {
for (lval = polys[npoly-1], k = npoly-2; k >= 0; k--) {
lval = lval * outv + polys[k];
}
del = (inv - lval);
outv += 0.99 * del;
}
return outv;
}
/* Take a single set of absolute linearised sensor values and */
/* convert them back into Rev A..D raw reading values. */
/* This is used for saving a calibration to the EEProm */
i1pro_code i1pro_absraw_to_meas(
i1pro *p,
int *meas, /* Return raw measurement data */
double *absraw, /* Array of [-1 nraw] value to process */
double inttime, /* Integration time used */
int gainmode /* Gain mode, 0 = normal, 1 = high */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned int maxpve = m->maxpve; /* maximum +ve sensor value + 1 */
int i, j, k;
double avlastv = 0.0;
double gain;
int npoly; /* Number of linearisation coefficients */
double *polys; /* the coeficients */
double scale; /* Absolute scale value */
if (m->subtmode) {
a1logd(p->log,1,"i1pro_absraw_to_meas subtmode set\n");
return I1PRO_INT_MALLOC;
}
if (gainmode) {
gain = m->highgain;
npoly = m->nlin1;
polys = m->lin1;
} else {
gain = 1.0;
npoly = m->nlin0;
polys = m->lin0;
}
scale = 1.0/(inttime * gain);
for (j = 0; j < 128; j++) {
double fval, lval;
unsigned int rval;
/* Unscale from absolute sensor reading */
lval = absraw[j] / scale;
#ifdef ENABLE_NONLINCOR
/* Un-linearise */
fval = inv_poly(polys, npoly, lval);
#else
fval = lval;
#endif
if (fval < (double)((int)maxpve-65536))
fval = (double)((int)maxpve-65536);
else if (fval > (double)(maxpve-1))
fval = (double)(maxpve-1);
rval = (unsigned int)(int)floor(fval + 0.5);
meas[j] = rval;
}
return I1PRO_OK;
}
/* Average a set of measurements into one. */
/* Return zero if readings are consistent and not saturated. */
/* Return nz with bit 1 set if the readings are not consistent */
/* Return nz with bit 2 set if the readings are saturated */
/* Return the highest individual element. */
/* Return the overall average. */
int i1pro_average_multimeas(
i1pro *p,
double *avg, /* return average [-1 nraw] */
double **multimeas, /* Array of [nummeas][-1 nraw] value to average */
int nummeas, /* number of readings to be averaged */
double *phighest, /* If not NULL, return highest value from all bands and msrmts. */
double *poallavg, /* If not NULL, return overall average of bands and measurements */
double satthresh, /* Sauration threshold, 0 for none */
double darkthresh /* Dark threshold (used for consistency check scaling) */
) {
i1proimp *m = (i1proimp *)p->m;
int i, j;
double highest = -1e6;
double oallavg = 0.0;
double avgoverth = 0.0; /* Average over threshold */
double maxavg = -1e38; /* Track min and max averages of readings */
double minavg = 1e38;
double norm;
int rv = 0;
a1logd(p->log,3,"i1pro_average_multimeas %d readings\n",nummeas);
for (j = -1; j < 128; j++)
avg[j] = 0.0;
/* Now process the buffer values */
for (i = 0; i < nummeas; i++) {
double measavg = 0.0;
int k;
for (j = k = 0; j < m->nraw; j++) {
double val;
val = multimeas[i][j];
avg[j] += val; /* Per value average */
/* Skip 0 and 127 cell values for RevA-D */
if (m->nsen == m->nraw && (j == 0 || j == 127))
continue;
if (val > highest)
highest = val;
if (val > satthresh)
avgoverth++;
measavg += val;
k++;
}
measavg /= (double)k;
oallavg += measavg;
if (measavg < minavg)
minavg = measavg;
if (measavg > maxavg)
maxavg = measavg;
/* and shielded values */
avg[-1] += multimeas[i][-1];
}
for (j = -1; j < 128; j++)
avg[j] /= (double)nummeas;
oallavg /= (double)nummeas;
avgoverth /= (double)nummeas;
if (phighest != NULL)
*phighest = highest;
if (poallavg != NULL)
*poallavg = oallavg;
if (satthresh > 0.0 && avgoverth > 0.0)
rv |= 2;
norm = fabs(0.5 * (maxavg+minavg));
a1logd(p->log,4,"norm = %f, dark thresh = %f\n",norm,darkthresh);
if (norm < (2.0 * darkthresh))
norm = 2.0 * darkthresh;
a1logd(p->log,4,"overall avg = %f, minavg = %f, maxavg = %f, variance %f, shielded avg %f\n",
oallavg,minavg,maxavg,(maxavg - minavg)/norm, avg[-1]);
if ((maxavg - minavg)/norm > PATCH_CONS_THR) {
a1logd(p->log,2,"Reading is inconsistent: (maxavg %f - minavg %f)/norm %f = %f > thresh %f, darkthresh %f\n",maxavg,minavg,norm,(maxavg - minavg)/norm,PATCH_CONS_THR, darkthresh);
rv |= 1;
}
return rv;
}
/* Minimum number of scan samples in a patch */
#define MIN_SAMPLES 3
/* Range of bands to detect transitions */
#define BL 5 /* Start */
#define BH 105 /* End */
#define BW 5 /* Width */
/* Record of possible patch */
typedef struct {
int ss; /* Start sample index */
int no; /* Number of samples */
int use; /* nz if patch is to be used */
} i1pro_patch;
/* Recognise the required number of ref/trans patch locations, */
/* and average the measurements within each patch. */
/* *flags returns zero if readings are consistent and not saturated. */
/* *flags returns nz with bit 1 set if the readings are not consistent */
/* *flags returns nz with bit 2 set if the readings are saturated */
/* *phighest returns the highest individual element. */
/* (Doesn't extract [-1] shielded values, since they have already been used) */
i1pro_code i1pro_extract_patches_multimeas(
i1pro *p,
int *flags, /* return flags */
double **pavg, /* return patch average [naptch][-1 nraw] */
int tnpatch, /* Target number of patches to recognise */
double **multimeas, /* Array of [nummeas][-1 nraw] value to extract from */
int nummeas, /* number of readings made */
double *phighest, /* If not NULL, return highest value from all bands and msrmts. */
double satthresh, /* Sauration threshold, 0 for none */
double inttime /* Integration time (used to adjust consistency threshold) */
) {
i1proimp *m = (i1proimp *)p->m;
int i, j, k, pix;
double **sslope; /* Signed difference between i and i+1 */
double *slope; /* Accumulated absolute difference between i and i+1 */
double *fslope; /* Filtered slope */
i1pro_patch *pat; /* Possible patch information */
int npat, apat = 0;
double *maxval; /* Maximum input value for each wavelength */
double fmaxslope = 0.0;
double maxslope = 0.0;
double minslope = 1e38;
double thresh = 0.4; /* Slope threshold */
int try; /* Thresholding try */
double avglegth; /* Average length of patches */
int *sizepop; /* Size popularity of potential patches */
double median; /* median potential patch width */
double window; /* +/- around median to accept */
double highest = -1e6;
double white_avg; /* Average of (aproximate) white data */
int b_lo = BL; /* Patch detection low band */
int b_hi = BH; /* Patch detection low band */
int rv = 0;
double patch_cons_thr = PATCH_CONS_THR * m->scan_toll_ratio;
#ifdef PATREC_DEBUG
double **plot;
#endif
a1logd(p->log,2,"i1pro_extract_patches_multimeas looking for %d patches out of %d samples\n",tnpatch,nummeas);
/* Adjust bands if UV mode */
/* (This is insufficient for useful patch recognition) */
if (m->uv_en) {
b_lo = 91;
b_hi = 117;
}
maxval = dvectorz(-1, m->nraw-1);
/* Loosen consistency threshold for short integation time, */
/* to allow for extra noise */
if (inttime < 0.012308) /* Smaller than Rev A minimum int. time */
patch_cons_thr *= sqrt(0.012308/inttime);
/* Discover the maximum input value for normalisation */
for (j = 0; j < m->nraw; j ++) {
for (i = 0; i < nummeas; i++) {
if (multimeas[i][j] > maxval[j])
maxval[j] = multimeas[i][j];
}
if (maxval[j] < 1.0)
maxval[j] = 1.0;
}
#ifdef PATREC_DEBUG
/* Plot out 6 lots of 8 values each */
plot = dmatrixz(0, 11, 0, nummeas-1);
// for (j = 45; j <= (m->nraw-8); j += 100) /* Do just one band */
#ifdef PATREC_ALLBANDS
for (j = 0; j <= (m->nraw-8); j += 8) /* Plot all the bands */
#else
for (j = 5; j <= (m->nraw-8); j += 30) /* Do four bands */
#endif
{
for (k = 0; k < 8; k ++) {
for (i = 0; i < nummeas; i++) {
plot[k][i] = multimeas[i][j+k]/maxval[j+k];
}
}
for (i = 0; i < nummeas; i++)
plot[8][i] = (double)i;
printf("Bands %d - %d\n",j,j+7);
do_plot10(plot[8], plot[0], plot[1], plot[2], plot[3], plot[4], plot[5], plot[6], plot[7], NULL, NULL, nummeas, 0);
}
#endif /* PATREC_DEBUG */
sslope = dmatrixz(0, nummeas-1, -1, m->nraw-1);
slope = dvectorz(0, nummeas-1);
fslope = dvectorz(0, nummeas-1);
sizepop = ivectorz(0, nummeas-1);
#ifndef NEVER /* Good with this on */
/* Average bands together */
for (i = 0; i < nummeas; i++) {
for (j = b_lo + BW; j < (b_hi - BW); j++) {
for (k = -b_lo; k <= BW; k++) /* Box averaging filter over bands */
sslope[i][j] += multimeas[i][j + k]/maxval[j];
}
}
#else
/* Don't average bands */
for (i = 0; i < nummeas; i++) {
for (j = 0; j < m->nraw; j++) {
sslope[i][j] = multimeas[i][j]/maxval[j];
}
}
#endif
/* Compute slope result over readings and bands */
/* Compute signed slope result over readings and bands */
#ifdef NEVER /* Works well for non-noisy readings */
/* Median of 5 differences from 6 points */
for (i = 2; i < (nummeas-3); i++) {
for (j = b_lo; j < b_hi; j++) {
double sl, asl[5];
int r, s;
asl[0] = fabs(sslope[i-2][j] - sslope[i-1][j]);
asl[1] = fabs(sslope[i-1][j] - sslope[i-0][j]);
asl[2] = fabs(sslope[i-0][j] - sslope[i+1][j]);
asl[3] = fabs(sslope[i+1][j] - sslope[i+2][j]);
asl[4] = fabs(sslope[i+2][j] - sslope[i+3][j]);
/* Sort them */
for (r = 0; r < (5-1); r++) {
for (s = r+1; s < 5; s++) {
if (asl[s] < asl[r]) {
double tt;
tt = asl[s];
asl[s] = asl[r];
asl[r] = tt;
}
}
}
/* Pick middle one */
sl = asl[2];
if (sl > slope[i])
slope[i] = sl;
}
}
#else /* Works better for noisy readings */
/* Compute sliding window average and deviation that contains */
/* our output point, and chose the average with the minimum deviation. */
#define FW 3 /* Number of delta's to average */
for (i = FW-1; i < (nummeas-FW); i++) { /* Samples */
double basl, bdev; /* Best average slope, Best deviation */
double sl[2 * FW -1];
double asl[FW], dev[FW];
int slopen = 0;
double slopeth = 0.0;
int m, pp;
for (pp = 0; pp < 2; pp++) { /* For each pass */
for (j = b_lo; j < b_hi; j++) { /* Bands */
/* Compute differences for the range of our windows */
for (k = 0; k < (2 * FW -1); k++)
sl[k] = sslope[i+k-FW+1][j] - sslope[i+k+-FW+2][j];
/* For each window offset, compute average and deviation squared */
bdev = 1e38;
for (k = 0; k < FW; k++) {
/* Compute average of this window offset */
asl[k] = 0.0;
for (m = 0; m < FW; m++) /* For slope in window */
asl[k] += sl[k+m];
asl[k] /= (double)FW;
/* Compute deviation squared */
dev[k] = 0.0;
for (m = 0; m < FW; m++) {
double tt;
tt = sl[k+m] - asl[k];
dev[k] += tt * tt;
}
if (dev[k] < bdev)
bdev = dev[k];
}
#ifndef NEVER
/* Weight the deviations with a triangular weighting */
/* to skew slightly towards the center */
for (k = 0; k < FW; k++) {
double wt;
wt = fabs(2.0 * k - (FW -1.0))/(FW-1.0);
dev[k] += wt * bdev;
}
#endif
/* For each window offset, choose the one to use. */
bdev = 1e38;
basl = 0.0;
for (k = 0; k < FW; k++) {
/* Choose window average with smallest deviation squared */
if (dev[k] < bdev) {
bdev = dev[k];
basl = fabs(asl[k]);
}
}
if (pp == 0) { /* First pass, compute average slope over bands */
slope[i] += basl;
} else { /* Second pass, average slopes of bands over threshold */
if (basl > slopeth) {
slope[i] += basl;
slopen++;
}
}
} /* Next band */
if (pp == 0) {
slopeth = 1.0 * slope[i]/j; /* Compute threshold */
slope[i] = 0.0;
} else {
if (slopen > 0)
slope[i] /= slopen; /* Compute average of those over threshold */
}
} /* Next pass */
}
#undef FW
#endif
#ifndef NEVER /* Good with this on */
/* Normalise the slope values */
/* Locate the minumum and maximum values */
maxslope = 0.0;
minslope = 1e38;
for (i = 4; i < (nummeas-4); i++) {
double avs;
if (slope[i] > maxslope)
maxslope = slope[i];
/* Simple moving average for min comp. */
avs = 0.0;
for (j = -2; j <= 2; j++)
avs += slope[i+j];
avs /= 5.0;
if (avs < minslope)
minslope = avs;
}
/* Normalise the slope */
maxslope *= 0.5;
minslope *= 3.0;
for (i = 0; i < nummeas; i++) {
slope[i] = (slope[i] - minslope) / (maxslope - minslope);
if (slope[i] < 0.0)
slope[i] = 0.0;
else if (slope[i] > 1.0)
slope[i] = 1.0;
}
/* "Automatic Gain control" the raw slope information. */
#define LFW 20 /* Half width of triangular filter */
for (i = 0; i < nummeas; i++) {
double sum, twt;
sum = twt = 0.0;
for (j = -LFW; j <= LFW; j++) {
double wt;
if ((i+j) < 0 || (i+j) >= nummeas)
continue;
wt = ((LFW-abs(j))/(double)LFW);
sum += wt * slope[i+j];
twt += wt;
}
fslope[i] = sum/twt;
if (fslope[i] > fmaxslope)
fmaxslope = fslope[i];
}
#undef LFW
#ifdef NEVER /* Better with the off, for very noisy samples */
/* Apply AGC with limited gain */
for (i = 0; i < nummeas; i++) {
if (fslope[i] > fmaxslope/4.0)
slope[i] = slope[i]/fslope[i];
else
slope[i] = slope[i] * 4.0/fmaxslope;
}
#endif
#endif /* NEVER */
/* Locate the minumum and maximum values */
maxslope = 0.0;
minslope = 1e38;
for (i = 4; i < (nummeas-4); i++) {
double avs;
if (slope[i] > maxslope)
maxslope = slope[i];
/* Simple moving average for min comp. */
avs = 0.0;
for (j = -2; j <= 2; j++)
avs += slope[i+j];
avs /= 5.0;
if (avs < minslope)
minslope = avs;
}
#ifndef NEVER /* Good with this on */
/* Normalise the slope again */
maxslope *= 0.3;
minslope *= 3.0;
for (i = 0; i < nummeas; i++) {
slope[i] = (slope[i] - minslope) / (maxslope - minslope);
if (slope[i] < 0.0)
slope[i] = 0.0;
else if (slope[i] > 1.0)
slope[i] = 1.0;
}
#endif
#ifdef PATREC_DEBUG
printf("Slope filter output\n");
for (i = 0; i < nummeas; i++) {
int jj;
for (jj = 0, j = b_lo; jj < 6 && j < b_hi; jj++, j += ((b_hi-b_lo)/6)) {
double sum = 0.0;
for (k = -b_lo; k <= BW; k++) /* Box averaging filter over bands */
sum += multimeas[i][j + k];
plot[jj][i] = sum/((2.0 * b_lo + 1.0) * maxval[j+k]);
}
}
for (i = 0; i < nummeas; i++)
plot[6][i] = (double)i;
do_plot6(plot[6], slope, plot[0], plot[1], plot[2], plot[3], plot[4], nummeas);
#endif /* PATREC_DEBUG */
free_dvector(fslope, 0, nummeas-1);
free_dmatrix(sslope, 0, nummeas-1, -1, m->nraw-1);
/* Now threshold the measurements into possible patches */
apat = 2 * nummeas;
if ((pat = (i1pro_patch *)malloc(sizeof(i1pro_patch) * apat)) == NULL) {
free_ivector(sizepop, 0, nummeas-1);
free_dvector(slope, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
a1logd(p->log, 1, "i1pro: malloc of patch structures failed!\n");
return I1PRO_INT_MALLOC;
}
avglegth = 0.0;
for (npat = i = 0; i < (nummeas-1); i++) {
if (slope[i] > thresh)
continue;
/* Start of a new patch */
if (npat >= apat) {
apat *= 2;
if ((pat = (i1pro_patch *)realloc(pat, sizeof(i1pro_patch) * apat)) == NULL) {
free_ivector(sizepop, 0, nummeas-1);
free_dvector(slope, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
a1logd(p->log, 1, "i1pro: reallloc of patch structures failed!\n");
return I1PRO_INT_MALLOC;
}
}
pat[npat].ss = i;
pat[npat].no = 2;
pat[npat].use = 0;
for (i++; i < (nummeas-1); i++) {
if (slope[i] > thresh)
break;
pat[npat].no++;
}
avglegth += (double) pat[npat].no;
npat++;
}
a1logd(p->log,7,"Number of patches = %d\n",npat);
/* We don't count the first and last patches, as we assume they are white leader */
if (npat < (tnpatch + 2)) {
free_ivector(sizepop, 0, nummeas-1);
free_dvector(slope, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
free(pat);
a1logd(p->log,2,"Patch recog failed - unable to detect enough possible patches\n");
return I1PRO_RD_NOTENOUGHPATCHES;
} else if (npat >= (2 * tnpatch) + 2) {
free_ivector(sizepop, 0, nummeas-1);
free_dvector(slope, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
free(pat);
a1logd(p->log,2,"Patch recog failed - detecting too many possible patches\n");
return I1PRO_RD_TOOMANYPATCHES;
}
avglegth /= (double)npat;
for (i = 0; i < npat; i++) {
a1logd(p->log,7,"Raw patch %d, start %d, length %d\n",i, pat[i].ss, pat[i].no);
}
/* Accumulate popularity ccount of possible patches */
for (i = 1; i < (npat-1); i++)
sizepop[pat[i].no]++;
/* Locate the median potential patch width */
for (j = 0, i = 0; i < nummeas; i++) {
j += sizepop[i];
if (j >= ((npat-2)/2))
break;
}
median = (double)i;
a1logd(p->log,7,"Median patch width %f\n",median);
/* Now decide which patches to use. */
/* Try a widening window around the median. */
for (window = 0.2, try = 0; try < 15; window *= 1.4, try++) {
int bgcount = 0, bgstart = 0;
int gcount, gstart;
double wmin = median/(1.0 + window);
double wmax = median * (1.0 + window);
a1logd(p->log,7,"Window = %f - %f\n",wmin, wmax);
/* Track which is the largest contiguous group that */
/* is within our window */
gcount = gstart = 0;
for (i = 1; i < npat; i++) {
if (i < (npat-1) && pat[i].no <= wmax) { /* Small enough */
if (pat[i].no >= wmin) { /* And big enough */
if (gcount == 0) { /* Start of new group */
gcount++;
gstart = i;
a1logd(p->log,7,"Start group at %d\n",gstart);
} else {
gcount++; /* Continuing new group */
a1logd(p->log,7,"Continue group at %d, count %d\n",gstart,gcount);
}
}
} else { /* Too big or end of patches, end this group */
a1logd(p->log,7,"Terminating group group at %d, count %d\n",gstart,gcount);
if (gcount > bgcount) { /* New biggest group */
bgcount = gcount;
bgstart = gstart;
a1logd(p->log,7,"New biggest\n");
}
gcount = gstart = 0; /* End this group */
}
}
a1logd(p->log,7,"Biggest group is at %d, count %d\n",bgstart,bgcount);
if (bgcount == tnpatch) { /* We're done */
for (i = bgstart, j = 0; i < npat && j < tnpatch; i++) {
if (pat[i].no <= wmax && pat[i].no >= wmin) {
pat[i].use = 1;
j++;
if (pat[i].no < MIN_SAMPLES) {
a1logd(p->log,7,"Too few samples\n");
free_ivector(sizepop, 0, nummeas-1);
free_dvector(slope, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
free(pat);
a1logd(p->log,2,"Patch recog failed - patches sampled too sparsely\n");
return I1PRO_RD_NOTENOUGHSAMPLES;
}
}
}
break;
} else if (bgcount > tnpatch) {
a1logd(p->log,7,"Too many patches\n");
free_ivector(sizepop, 0, nummeas-1);
free_dvector(slope, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
free(pat);
a1logd(p->log,2,"Patch recog failed - detected too many consistent patches\n");
return I1PRO_RD_TOOMANYPATCHES;
}
}
if (try >= 15) {
a1logd(p->log,7,"Not enough patches\n");
free_ivector(sizepop, 0, nummeas-1);
free_dvector(slope, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
free(pat);
a1logd(p->log,2,"Patch recog failed - unable to find enough consistent patches\n");
return I1PRO_RD_NOTENOUGHPATCHES;
}
a1logd(p->log,7,"Got %d patches out of potential %d:\n",tnpatch, npat);
a1logd(p->log,7,"Average patch legth %f\n",avglegth);
for (i = 1; i < (npat-1); i++) {
if (pat[i].use == 0)
continue;
a1logd(p->log,7,"Patch %d, start %d, length %d:\n",i, pat[i].ss, pat[i].no, pat[i].use);
}
#ifdef NEVER /* [Und] - doesn't seem as good for normal patch sizes. */
/* Now trim the patches by expanding the spacers/transitions */
for (k = 1; k < (npat-1); k++) {
int sw, xsw, trim;
if (pat[k].use == 0)
continue;
printf("Patch %d @ %d len %d ->",k,pat[k].ss,pat[k].no);
/* Figure the previous spacer width */
sw = pat[k].ss - (pat[k-1].ss + pat[k-1].no);
xsw = (sw * 170 + 85)/100; /* Expand spacer by 170% */
trim = (xsw - sw + 1)/2; /* Move start of patch half that expansion */
pat[k].ss += trim;
pat[k].no -= trim;
/* Figure the next spacer width */
sw = pat[k+1].ss - (pat[k].ss + pat[k].no);
xsw = (sw * 170 + 85)/100; /* Expand spacer by 170% */
trim = (xsw - sw + 1)/2; /* Move end of patch half that expansion */
pat[k].no -= trim;
if (pat[k].no < 0)
pat[k].no = 0;
printf(" @ %d len %d\n",pat[k].ss,pat[k].no);
}
#else
/* Now trim the patches by shrinking their windows */
for (k = 1; k < (npat-1); k++) {
int nno, trim;
if (pat[k].use == 0)
continue;
// nno = (pat[k].no * 3 + 0)/4; /* Trim to 75% & round down */
nno = (pat[k].no * 2 + 0)/3; /* Trim to 66% & round down [def] */
// nno = (pat[k].no * 2 + 0)/4; /* Trim to 50% & round down */
trim = (pat[k].no - nno + 1)/2;
pat[k].ss += trim;
pat[k].no = nno;
}
#endif
#ifdef PATREC_SAVETRIMMED /* Save debugging file */
{
static int filen = 0; /* Debug file index */
char fname[100];
FILE *fp;
sprintf(fname, "i1pro_raw_trimed_%d.csv",filen++);
if ((fp = fopen(fname, "w")) == NULL)
error("Unable to open debug output file '%'",fname);
/* Create fake "slope" value that marks patches */
for (i = 0; i < nummeas; i++)
slope[i] = 1.0;
for (k = 1; k < (npat-1); k++) {
if (pat[k].use == 0)
continue;
for (i = pat[k].ss; i < (pat[k].ss + pat[k].no); i++)
slope[i] = 0.0;
}
for (i = 0; i < nummeas; i++) {
fprintf(fp, "%f\t",slope[i]);
for (j = 0; j < m->nraw; j++)
fprintf(fp, "%f\t", multimeas[i][j]/maxval[j]);
fprintf(fp, "\n");
}
fclose(fp);
}
#endif
#ifdef PATREC_DEBUG
a1logd(p->log,7,"After trimming got:\n");
for (i = 1; i < (npat-1); i++) {
if (pat[i].use == 0)
continue;
printf("Patch %d, start %d, length %d:\n",i, pat[i].ss, pat[i].no, pat[i].use);
}
/* Create fake "slope" value that marks patches */
for (i = 0; i < nummeas; i++)
slope[i] = 1.0;
for (k = 1; k < (npat-1); k++) {
if (pat[k].use == 0)
continue;
for (i = pat[k].ss; i < (pat[k].ss + pat[k].no); i++)
slope[i] = 0.0;
}
printf("Trimmed output:\n");
#ifdef PATREC_ALLBANDS
for (j = 0; j <= (m->nraw-9); j += 9) { /* Plot all the bands, 9 at a time */
for (i = 0; i < nummeas; i++) {
for (k = 0; k < 9; k++)
plot[k][i] = multimeas[i][j+k]/maxval[j+k];
plot[10][i] = (double)i;
}
printf("Bands %d - %d\n",j,j+9);
do_plot10(plot[10], slope, plot[0], plot[1], plot[2], plot[3], plot[4], plot[5], plot[6], plot[7], plot[8], nummeas, 0);
}
#else
for (i = 0; i < nummeas; i++) {
int jj;
for (jj = 0, j = b_lo; jj < 6 && j < b_hi; jj++, j += ((b_hi-b_lo)/6)) {
double sum = 0.0;
for (k = -b_lo; k <= BW; k++) /* Box averaging filter over bands */
sum += multimeas[i][j + k];
plot[jj][i] = sum/((2.0 * b_lo + 1.0) * maxval[j+k]);
}
}
for (i = 0; i < nummeas; i++)
plot[10][i] = (double)i;
do_plot6(plot[10], slope, plot[0], plot[1], plot[2], plot[3], plot[4], nummeas);
#endif
#endif /* PATREC_DEBUG */
#ifdef PATREC_DEBUG
free_dmatrix(plot, 0, 6, 0, nummeas-1);
#endif /* PATREC_DEBUG */
/* Compute average of (aproximate) white */
white_avg = 0.0;
for (j = 1; j < (m->nraw-1); j++)
white_avg += maxval[j];
white_avg /= (m->nraw - 2.0);
/* Now process the buffer values */
for (i = 0; i < tnpatch; i++) {
for (j = 0; j < m->nraw; j++)
pavg[i][j] = 0.0;
}
for (pix = 0, k = 1; k < (npat-1); k++) {
double maxavg = -1e38; /* Track min and max averages of readings for consistency */
double minavg = 1e38;
double avgoverth = 0.0; /* Average over saturation threshold */
double cons; /* Consistency */
if (pat[k].use == 0)
continue;
if (pat[k].no <= MIN_SAMPLES) {
a1logd(p->log,7,"Too few samples (%d, need %d)\n",pat[k].no,MIN_SAMPLES);
free_dvector(slope, 0, nummeas-1);
free_ivector(sizepop, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
free(pat);
a1logd(p->log,2,"Patch recog failed - patches sampled too sparsely\n");
return I1PRO_RD_NOTENOUGHSAMPLES;
}
/* Measure samples that make up patch value */
for (i = pat[k].ss; i < (pat[k].ss + pat[k].no); i++) {
double measavg = 0.0;
for (j = 1; j < m->nraw-1; j++) {
double val;
val = multimeas[i][j];
if (val > highest)
highest = val;
if (val > satthresh)
avgoverth++;
measavg += val;
pavg[pix][j] += val;
}
measavg /= (m->nraw-2.0);
if (measavg < minavg)
minavg = measavg;
if (measavg > maxavg)
maxavg = measavg;
/* and the duplicated values at the end */
pavg[pix][0] += multimeas[i][0];
pavg[pix][127] += multimeas[i][127];
}
for (j = 0; j < m->nraw; j++)
pavg[pix][j] /= (double)pat[k].no;
avgoverth /= (double)pat[k].no;
if (satthresh > 0.0 && avgoverth >= 10.0)
rv |= 2;
cons = (maxavg - minavg)/white_avg;
a1logd(p->log,7,"Patch %d: consistency = %f%%, thresh = %f%%\n",pix,100.0 * cons, 100.0 * patch_cons_thr);
if (cons > patch_cons_thr) {
a1logd(p->log,2,"Patch recog failed - patch %d is inconsistent (%f%% > %f)\n",pix,cons, patch_cons_thr);
rv |= 1;
}
pix++;
}
if (phighest != NULL)
*phighest = highest;
if (flags != NULL)
*flags = rv;
free_dvector(slope, 0, nummeas-1);
free_ivector(sizepop, 0, nummeas-1);
free_dvector(maxval, -1, m->nraw-1);
free(pat);
if (rv & 2)
a1logd(p->log,2,"Patch recog failed - some patches are saturated\n");
a1logd(p->log,2,"i1pro_extract_patches_multimeas done, sat = %s, inconsist = %s\n",
rv & 2 ? "true" : "false", rv & 1 ? "true" : "false");
return I1PRO_OK;
}
#undef BL
#undef BH
#undef BW
/* Recognise any flashes in the readings, and */
/* and average their values together as well as summing their duration. */
/* Return nz on an error */
/* (Doesn't extract [-1] shielded values, since they have already been used) */
i1pro_code i1pro_extract_patches_flash(
i1pro *p,
int *flags, /* return flags */
double *duration, /* return duration */
double *pavg, /* return patch average [-1 nraw] */
double **multimeas, /* Array of [nummeas][-1 nraw] value to extract from */
int nummeas, /* number of readings made */
double inttime /* Integration time (used to compute duration) */
) {
i1proimp *m = (i1proimp *)p->m;
int i, j, k, pix;
double minval, maxval; /* min and max input value at wavelength of maximum input */
double mean; /* Mean of the max wavelength band */
int maxband; /* Band of maximum value */
double thresh; /* Level threshold */
int fsampl; /* Index of the first sample over the threshold */
int nsampl; /* Number of samples over the threshold */
double *aavg; /* ambient average [-1 nraw] */
double finttime; /* Flash integration time */
int rv = 0;
#ifdef PATREC_DEBUG
double **plot;
#endif
a1logd(p->log,2,"i1pro_extract_patches_flash looking for flashes in %d measurements\n",nummeas);
/* Discover the maximum input value for flash dection */
maxval = -1e6;
maxband = 0;
for (j = 0; j < m->nraw; j ++) {
for (i = 0; i < nummeas; i++) {
if (multimeas[i][j] > maxval) {
maxval = multimeas[i][j];
maxband = j;
}
}
}
if (maxval <= 0.0) {
a1logd(p->log,2,"No flashes found in measurement\n");
return I1PRO_RD_NOFLASHES;
}
minval = 1e6;
mean = 0.0;
for (i = 0; i < nummeas; i++) {
mean += multimeas[i][maxband];
if (multimeas[i][maxband] < minval)
minval = multimeas[i][maxband];
}
mean /= (double)nummeas;
/* Set the threshold at 5% from mean towards max */
thresh = (3.0 * mean + maxval)/4.0;
a1logd(p->log,7,"i1pro_extract_patches_flash band %d minval %f maxval %f, mean = %f, thresh = %f\n",maxband,minval,maxval,mean, thresh);
#ifdef PATREC_DEBUG
/* Plot out 6 lots of 6 values each */
plot = dmatrixz(0, 6, 0, nummeas-1);
for (j = maxband -3; j>= 0 && j < (m->nraw-6); j += 100) /* Do one set around max */
{
for (k = 0; k < 6; k ++) {
for (i = 0; i < nummeas; i++) {
plot[k][i] = multimeas[i][j+k]/maxval;
}
}
for (i = 0; i < nummeas; i++)
plot[6][i] = (double)i;
printf("Bands %d - %d\n",j,j+5);
do_plot6(plot[6], plot[0], plot[1], plot[2], plot[3], plot[4], plot[5], nummeas);
}
free_dmatrix(plot,0,6,0,nummeas-1);
#endif /* PATREC_DEBUG */
#ifdef PATREC_DEBUG
/* Plot just the pulses */
{
int start, end;
plot = dmatrixz(0, 6, 0, nummeas-1);
for(j = 0, start = -1, end = 0;;) {
for (start = -1, i = end; i < nummeas; i++) {
if (multimeas[i][maxband] >= thresh) {
if (start < 0)
start = i;
} else if (start >= 0) {
end = i;
break;
}
}
if (start < 0)
break;
start -= 3;
if (start < 0)
start = 0;
end += 4;
if (end > nummeas)
end = nummeas;
for (i = start; i < end; i++, j++) {
int q;
plot[6][j] = (double)j;
#ifdef NEVER /* Plot +/-3 around maxband */
for (q = 0, k = maxband -3; k < (maxband+3) && k >= 0 && k < m->nraw; k++, q++) {
plot[q][j] = multimeas[i][k]/maxval;
}
#else
/* plot max of bands in 6 segments */
for (q = 0; q < 6; q++) {
int ss, ee;
plot[q][j] = -1e60;
ss = q * (m->nraw/6);
ee = (q+1) * (m->nraw/6);
for (k = ss; k < ee; k++) {
if (multimeas[i][k]/maxval > plot[q][j])
plot[q][j] = multimeas[i][k]/maxval;
}
}
#endif
}
}
do_plot6(plot[6], plot[0], plot[1], plot[2], plot[3], plot[4], plot[5], j);
free_dmatrix(plot,0,6,0,nummeas-1);
}
#endif
/* Locate the first sample over the threshold, and the */
/* total number of samples in the pulses. */
fsampl = -1;
for (nsampl = i = 0; i < nummeas; i++) {
for (j = 0; j < m->nraw-1; j++) {
if (multimeas[i][j] >= thresh)
break;
}
if (j < m->nraw-1) {
if (fsampl < 0)
fsampl = i;
nsampl++;
}
}
a1logd(p->log,7,"Number of flash patches = %d\n",nsampl);
if (nsampl == 0)
return I1PRO_RD_NOFLASHES;
/* See if there are as many samples before the first flash */
if (nsampl < 6)
nsampl = 6;
/* Average nsample samples of ambient */
i = (fsampl-3-nsampl);
if (i < 0)
return I1PRO_RD_NOAMBB4FLASHES;
a1logd(p->log,7,"Ambient samples %d to %d \n",i,fsampl-3);
aavg = dvectorz(-1, m->nraw-1);
for (nsampl = 0; i < (fsampl-3); i++) {
for (j = 0; j < m->nraw-1; j++)
aavg[j] += multimeas[i][j];
nsampl++;
}
/* Integrate all the values over the threshold, */
/* and also one either side of flash */
for (j = 0; j < m->nraw-1; j++)
pavg[j] = 0.0;
for (k = 0, i = 1; i < (nummeas-1); i++) {
int sample = 0;
for (j = 0; j < m->nraw-1; j++) {
if (multimeas[i-1][j] >= thresh) {
sample = 1;
break;
}
if (multimeas[i][j] >= thresh) {
sample = 1;
break;
}
if (multimeas[i+1][j] >= thresh) {
sample = 1;
break;
}
}
if (j < m->nraw-1) {
a1logd(p->log,7,"Integrating flash sample no %d \n",i);
for (j = 0; j < m->nraw-1; j++)
pavg[j] += multimeas[i][j];
k++;
}
}
for (j = 0; j < m->nraw-1; j++)
pavg[j] = pavg[j]/(double)k - aavg[j]/(double)nsampl;
a1logd(p->log,7,"Number of flash patches integrated = %d\n",k);
finttime = inttime * (double)k;
if (duration != NULL)
*duration = finttime;
/* Convert to cd/m^2 seconds */
for (j = 0; j < m->nraw-1; j++)
pavg[j] *= finttime;
if (flags != NULL)
*flags = rv;
free_dvector(aavg, -1, m->nraw-1);
return I1PRO_OK;
}
/* Subtract the black level. */
/* If Rev E, also adjust according to shielded cells, and linearise. */
void i1pro_sub_absraw(
i1pro *p,
int nummeas, /* Return number of readings measured */
double inttime, /* Integration time used */
int gainmode, /* Gain mode, 0 = normal, 1 = high */
double **absraw, /* Source/Desination array [-1 nraw] */
double *sub /* Black value to subtract [-1 nraw] */
) {
i1proimp *m = (i1proimp *)p->m;
double gain;
int npoly; /* Number of linearisation coefficients */
double *polys; /* the coeficients */
double scale; /* Absolute scale value */
double submax = -1e6; /* Subtraction value maximum */
int i, j;
if (gainmode) {
gain = m->highgain;
npoly = m->nlin1;
polys = m->lin1;
} else {
gain = 1.0;
npoly = m->nlin0;
polys = m->lin0;
}
scale = 1.0/(inttime * gain); /* To scale RevE linearity */
/* Adjust black to allow for temperature change by using the */
/* shielded cell values as a reference. */
/* We use a heuristic to compute a zero based scale for adjusting the */
/* black. It's not clear why it works best this way, or how */
/* dependent on the particular instrument the magic numbers are, */
/* but it reduces the black level error from over 10% to about 0.3% */
if (p->itype == instI1Pro2) {
// double xx[NSEN_MAX], in[NSEN_MAX], res[NSEN_MAX];
double asub[NSEN_MAX];
double avgscell, zero;
/* Locate largest of black */
for (j = 0; j < m->nraw; j++) {
if (sub[j] > submax)
submax = sub[j];
}
/* Average the shielded cell value of all the readings */
avgscell = 0.0;
for (i = 0; i < nummeas; i++)
avgscell += absraw[i][-1];
avgscell /= (double)nummeas;
/* Compute scaling zero */
zero = 1.144 * 0.5 * (avgscell + sub[-1]);
/* make sure that the zero point is above any black value */
if (zero < (1.01 * avgscell))
zero = 1.01 * avgscell;
if (zero < (1.01 * sub[-1]))
zero = 1.01 * sub[-1];
if (zero < (1.01 * submax))
zero = 1.01 * submax;
a1logd(p->log,2,"Black shielded value = %f, Reading shielded value = %f\n",sub[-1], avgscell);
/* Compute the adjusted black */
/* [ Unlike the ColorMunki, using the black drift comp. for reflective */
/* seems to be OK and even beneficial. ] */
for (j = 0; j < m->nraw; j++) {
#ifdef ENABLE_BKDRIFTC
# ifdef HEURISTIC_BKDRIFTC
/* heuristic scaled correction */
asub[j] = zero - (zero - sub[j]) * (zero - avgscell)/(zero - sub[-1]);
# else
/* simple additive correction */
# pragma message("######### i1pro2 Simple shielded cell temperature correction! ########")
asub[j] = sub[j] + avgscell - sub[-1];
# endif
#else
# pragma message("######### i1pro2 No shielded cell temperature correction! ########")
asub[j] = sub[j]; /* Just use the calibration dark data */
#endif
}
/* Subtract the black */
for (i = 0; i < nummeas; i++) {
for (j = 0; j < m->nraw; j++) {
// xx[j] = j, in[j] = absraw[i][j];
absraw[i][j] -= asub[j]; /* Subtract adjusted black */
// res[j] = absraw[i][j] + (double)((int)(avgscell/20.0)) * 20.0;
#ifdef ENABLE_NONLINCOR
/* Linearise */
{
int k;
double fval, lval;
fval = absraw[i][j] / scale; /* Scale back to sensor value range */
for (lval = polys[npoly-1], k = npoly-2; k >= 0; k--)
lval = lval * fval + polys[k];
absraw[i][j] = scale * lval; /* Rescale back to absolute range */
}
#endif
}
#ifdef PLOT_BLACK_SUBTRACT /* Plot black adjusted levels */
printf("black = meas, red = black, green = adjuste black, blue = result\n");
do_plot6(xx, in, sub, adjsub, res, NULL, NULL, m->nraw);
#endif
}
/* Rev A-D don't have shielded reference cells */
} else {
/* For each measurement */
for (i = 0; i < nummeas; i++) {
for (j = -1; j < m->nraw; j++) {
absraw[i][j] -= sub[j];
}
}
}
}
/* Convert an absraw array from raw wavelengths to output wavelenths */
/* for a given [std res, high res] and [emis/tras, reflective] mode */
void i1pro_absraw_to_abswav(
i1pro *p,
int highres, /* 0 for std res, 1 for high res */
int refl, /* 0 for emis/trans, 1 for reflective */
int nummeas, /* Return number of readings measured */
double **abswav, /* Desination array [nwav] */
double **absraw /* Source array [-1 nraw] */
) {
i1proimp *m = (i1proimp *)p->m;
int i, j, k, cx, sx;
double *tm; /* Temporary array */
tm = dvector(0, m->nwav[highres]-1);
/* For each measurement */
for (i = 0; i < nummeas; i++) {
/* For each output wavelength */
for (cx = j = 0; j < m->nwav[highres]; j++) {
double oval = 0.0;
/* For each matrix value */
sx = m->mtx[highres][refl].index[j]; /* Starting index */
for (k = 0; k < m->mtx[highres][refl].nocoef[j]; k++, cx++, sx++) {
oval += m->mtx[highres][refl].coef[cx] * absraw[i][sx];
}
abswav[i][j] = tm[j] = oval;
}
if (p->itype == instI1Pro2) {
/* Now apply stray light compensation */
/* For each output wavelength */
for (j = 0; j < m->nwav[highres]; j++) {
double oval = 0.0;
/* For each matrix value */
for (k = 0; k < m->nwav[highres]; k++)
oval += m->straylight[highres][j][k] * tm[k];
abswav[i][j] = oval;
}
#ifdef PLOT_DEBUG
printf("Before & after stray light correction:\n");
plot_wav_2(m, highres, tm, abswav[i]);
#endif /* PLOT_DEBUG */
}
}
free_dvector(tm, 0, m->nwav[highres]-1);
}
/* Convert an abswav array of output wavelengths to scaled output readings. */
void i1pro_scale_specrd(
i1pro *p,
double **outspecrd, /* Destination */
int numpatches, /* Number of readings/patches */
double **inspecrd /* Source */
) {
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
int i, j;
/* For each measurement */
for (i = 0; i < numpatches; i++) {
/* For each output wavelength */
for (j = 0; j < m->nwav[m->highres]; j++) {
outspecrd[i][j] = inspecrd[i][j] * s->cal_factor[m->highres][j];
}
}
}
/* =============================================== */
/* Rev E wavelength calibration */
/*
The Rev E has a wavelength reference LED amd
stores a reference raw spectrum of it in its
calibrated state, together with an polinomial
defining the raw bin no. to wavelength conversion.
By measuring the wavelength LED and finding
the best positional match against the reference
spectrum, a CCD bin offset can be computed
to compensate for any shift in the optical or
physical alignment of spectrum against CCD.
To use the adjustment, the raw to wave subsampling
filters need to be regenerated, and to ensure that
the instrument returns readings very close to the
manufacturers driver, the same underlying filter
creation mathematics needs to be used.
The manufacturers filter weights are the accumulated
third order Lagrange polynomial weights of the
integration of a 20 nm wide triange spectrum
centered at each output wavelength, discretely
integrated between the range of the middle two points
of the Lagrange interpolator. The triangle response
being integrated has an area of exactly 1.0.
*/
/* Invert a raw2wavlength polinomial equation. */
/* Use simple Newton inversion will suffice. */
static double inv_raw2wav(double *polys, int npoly, double inv) {
double outv = 560.0, lval, del = 100.0;
int i, k;
for (i = 0; i < 200 && fabs(del) > 1e-7; i++) {
for (lval = polys[npoly-1], k = npoly-2; k >= 0; k--) {
lval = lval * outv + polys[k];
}
del = (inv - lval);
outv += 0.4 * del;
}
return 128.0 - outv;
}
/* return the uncalibrated wavelength given a raw bin value */
/* (Always uses reflective RevE wav2cal) */
static double i1pro_raw2wav_uncal(i1pro *p, double raw) {
i1proimp *m = (i1proimp *)p->m;
double ov;
int k;
if (p->itype == instI1Pro2) {
raw = 128.0 - raw; /* Quadratic expects +ve correlation */
/* Compute polinomial */
for (ov = m->wlpoly1[4-1], k = 4-2; k >= 0; k--)
ov = ov * raw + m->wlpoly1[k];
} else {
co pp;
if (m->raw2wav == NULL) {
a1loge(p->log,1,"i1pro_raw2wav_uncal called when hi-res not inited\n");
return I1PRO_INT_ASSERT;
}
pp.p[0] = raw;
m->raw2wav->interp(m->raw2wav, &pp);
ov = pp.v[0];
}
return ov;
}
/* return the calibrated wavelength given a raw bin value for the given mode */
static double i1pro_raw2wav(i1pro *p, int refl, double raw) {
i1proimp *m = (i1proimp *)p->m;
double ov;
int k;
if (p->itype == instI1Pro2) {
i1pro_state *s = &m->ms[m->mmode];
/* Correct for CCD offset and scale back to reference */
raw = raw - s->wl_led_off + m->wl_led_ref_off;
raw = 128.0 - raw; /* Quadratic expects +ve correlation */
/* Compute polinomial */
if (refl) {
for (ov = m->wlpoly1[4-1], k = 4-2; k >= 0; k--)
ov = ov * raw + m->wlpoly1[k];
} else {
for (ov = m->wlpoly2[4-1], k = 4-2; k >= 0; k--)
ov = ov * raw + m->wlpoly2[k];
}
} else {
co pp;
/* If not RevE there is no WL calibration */
if (m->raw2wav == NULL) {
a1loge(p->log,1,"i1pro_raw2wav_uncal called when hi-res not inited\n");
return I1PRO_INT_ASSERT;
}
pp.p[0] = raw;
m->raw2wav->interp(m->raw2wav, &pp);
ov = pp.v[0];
}
return ov;
}
/* Powell minimisation contxt for WL calibration */
typedef struct {
double ref_max; /* reference maximum level */
double *wl_ref; /* Wavlength reference samples */
int wl_ref_n; /* Number of wavelength references */
double *wl_meas; /* Wavelength measurement samples */
int wl_meas_n; /* Number of wavelength measurement samples */
int plot; /* Plot each try */
} wlcal_cx;
/* Powell minimisation callback function */
/* Parameters being optimized are magnitude, offset and scale */
static double wlcal_opt1(void *vcx, double tp[]) {
#ifdef PLOT_DEBUG
int pix = 0;
double xx[1024];
double y1[1024]; /* interpolate ref */
double y2[1024]; /* Measurement */
double y3[1024]; /* Error */
#endif
wlcal_cx *cx = (wlcal_cx *)vcx;
double vv, rv = 0.0;
int si, i;
si = (int)tp[1];
/* i = Measurement index */
for (i = si; i < cx->wl_meas_n; i++) {
double xv; /* offset & scaled measurement index */
int ix; /* Lagrange base offset */
double yv;
xv = ((double)i - tp[1]); /* fitted measurement location in reference no scale */
ix = ((int)xv) - 1; /* Reference index of Lagrange for this xv */
if (ix < 0)
continue;
if ((ix + 4) > cx->wl_ref_n)
break;
/* Compute interpolated value of reference using Lagrange: */
yv = cx->wl_ref[ix+0] * (xv-(ix+1)) * (xv-(ix+2)) * (xv-(ix+3))
/((0.0-1.0) * (0.0-2.0) * (0.0-3.0))
+ cx->wl_ref[ix+1] * (xv-(ix+0)) * (xv-(ix+2)) * (xv-(ix+3))
/((1.0-0.0) * (1.0-2.0) * (1.0-3.0))
+ cx->wl_ref[ix+2] * (xv-(ix+0)) * (xv-(ix+1)) * (xv-(ix+3))
/((2.0-0.0) * (2.0-1.0) * (2.0-3.0))
+ cx->wl_ref[ix+3] * (xv-(ix+0)) * (xv-(ix+1)) * (xv-(ix+2))
/((3.0-0.0) * (3.0-1.0) * (3.0-2.0));
vv = yv - tp[0] * cx->wl_meas[i];
/* Weight error linearly with magnitude, to emphasise peak error */
/* rather than what's happening down in the noise */
vv = vv * vv * (yv + 1.0)/(cx->ref_max+1.0);
#ifdef PLOT_DEBUG
if (cx->plot) {
xx[pix] = (double)i;
y1[pix] = yv;
y2[pix] = tp[0] * cx->wl_meas[i];
// y3[pix] = 2000.0 * (0.02 + yv/cx->ref_max); /* Weighting */
y3[pix] = 0.5 * vv; /* Error squared */
pix++;
}
#endif
rv += vv;
}
#ifdef PLOT_DEBUG
if (cx->plot) {
printf("Params %f %f -> err %f\n", tp[0], tp[1], rv);
do_plot(xx, y1, y2, y3, pix);
}
#endif
//printf("~1 %f %f -> %f\n", tp[0], tp[1], rv);
return rv;
}
#ifdef SALONEINSTLIB
/* Do a rudimetrary 2d optimization that uses exaustive */
/* search with hierarchical step sizes */
int wloptimize(double *cparm,
double *ss,
double tol,
double (*funk)(void *fdata, double tp[]),
void *fdata
) {
double range[2][2]; /* [dim][min/max] */
double val[2]; /* Current test values */
double bfit = 1e38; /* Current best fit values */
int dim;
for (dim = 0; dim < 2; dim++) {
range[dim][0] = cparm[dim] - ss[dim];
range[dim][1] = cparm[dim] + ss[dim];
val[dim] = cparm[dim];
}
/* Until we reach the tollerance */
for (;;) {
double mstep = 1e38;
for (dim = 0; dim < 2; dim++) {
double stepsz;
stepsz = (range[dim][1] - range[dim][0])/10.0;
if (stepsz < mstep)
mstep = stepsz;
/* Search in this dimension */
for (val[dim] = range[dim][0]; val[dim] <= range[dim][1]; val[dim] += stepsz) {
double fit;
fit = funk(fdata, val);
if (fit < bfit) {
cparm[dim] = val[dim];
bfit = fit;
}
}
val[dim] = cparm[dim];
range[dim][0] = val[dim] - stepsz;
range[dim][1] = val[dim] + stepsz;
}
if (mstep <= tol)
break;
}
return 0;
}
#endif /* SALONEINSTLIB */
/* Given a raw measurement of the wavelength LED, */
/* Compute the base offset that best fits it to the reference */
i1pro_code i1pro2_match_wl_meas(i1pro *p, double *pled_off, double *wlraw) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
int i;
int rpoff, mpoff; /* Peak offset */
int roff, moff; /* Base index */
double lhalf, rhalf;
double fwhm; /* Measured half width */
double rmax, mmax;
double magscale;
double led_off, off_nm;
/* Do simple match first - locate maximum */
rmax = -1e6;
rpoff = -1;
for (i = 0; i < m->wl_led_count; i++) {
if (m->wl_led_spec[i] > rmax) {
rmax = m->wl_led_spec[i]; /* Max of reference */
rpoff = i;
}
}
mmax = -1e6;
mpoff = -1;
for (i = 0; i < m->nraw; i++) {
if (wlraw[i] > mmax) {
mmax = wlraw[i]; /* Max of measurement */
mpoff = i;
}
}
if (mpoff < 0 || mpoff >= m->nraw) {
a1logd(p->log,1,"Couldn't locate WL measurement peak\n");
return I1PRO_WL_SHAPE;
}
/* Check magnitude is sufficient (not sure this is right, typically 5900 > 882) */
a1logd(p->log,2,"Measured WL level = %f, minimum needed = %f\n",mmax, m->wl_cal_min_level);
if (mmax < m->wl_cal_min_level) {
a1logd(p->log,1,"i1pro2_match_wl_meas peak magnitude too low\n");
return I1PRO_WL_TOOLOW;
}
/* Locate the half peak values */
for (i = 1; i < mpoff; i++) {
if (wlraw[i] > (mmax/2.0)) { /* Use linear interp */
lhalf = (wlraw[i] - mmax/2.0)/(wlraw[i] - wlraw[i-1]);
lhalf = lhalf * (i-1.0) + (1.0 - lhalf) * (double)i;
break;
}
}
if (i >= mpoff) {
a1logd(p->log,1,"Couldn't locate WL left half level\n");
return I1PRO_WL_SHAPE;
}
for (; i < m->nraw; i++) {
if (wlraw[i] < (mmax/2.0)) { /* Use linear interp */
rhalf = (mmax/2.0 - wlraw[i])/(wlraw[i-1] - wlraw[i]);
rhalf = rhalf * (i-1.0) + (1.0 - rhalf) * (double)i;
break;
}
}
if (i >= m->nraw) {
a1logd(p->log,1,"Couldn't locate WL righ half level\n");
return I1PRO_WL_SHAPE;
}
a1logd(p->log,5,"WL half levels at %f (%f nm) and %f (%f nm)\n",lhalf, i1pro_raw2wav_uncal(p, lhalf), rhalf, i1pro_raw2wav_uncal(p, rhalf));
fwhm = i1pro_raw2wav_uncal(p, lhalf) - i1pro_raw2wav_uncal(p, rhalf);
a1logd(p->log,3, "WL spectrum fwhm = %f\n",fwhm);
if (fwhm < (m->wl_cal_fwhm - m->wl_cal_fwhm_tol)
|| fwhm > (m->wl_cal_fwhm + m->wl_cal_fwhm_tol)) {
a1logd(p->log,1,"WL fwhm %f is out of range %f .. %f\n",fwhm,m->wl_cal_fwhm - m->wl_cal_fwhm_tol,m->wl_cal_fwhm + m->wl_cal_fwhm_tol);
return I1PRO_WL_SHAPE;
}
roff = m->wl_led_ref_off; /* reference raw offset */
moff = mpoff - rpoff; /* rough measured raw offset */
a1logd(p->log,3, "Preliminary WL peak match at ref base offset %d into measurement\n", moff);
magscale = rmax/mmax; /* Initial scale to make them match */
#ifdef PLOT_DEBUG
/* Plot the match */
{
double xx[1024];
double y1[1024];
double y2[1024];
for (i = 0; i < m->nraw; i++) {
xx[i] = (double)i;
y1[i] = 0.0;
if (i >= moff && (i - moff) < m->wl_led_count) {
y1[i] = m->wl_led_spec[i- moff];
}
y2[i] = wlraw[i] * magscale;
}
printf("Simple WL match, ref = black, meas = red:\n");
do_plot(xx, y1, y2, NULL, m->nraw);
}
#endif
/* Now do a good match */
/*
Do Lagrange interpolation on the reference curve,
and use a minimizer to find the best fit (minimum weighted y error)
by optimizing the magnitude, offset and scale.
*/
{
wlcal_cx cx;
double cparm[2]; /* fit parameters */
double ss[2]; /* Search range */
cparm[0] = magscale;
ss[0] = 0.2;
cparm[1] = (double)moff;
ss[1] = 4.0; /* == +- 12 nm */
cx.ref_max = rmax;
cx.wl_ref = m->wl_led_spec;
cx.wl_ref_n = m->wl_led_count;
cx.wl_meas = wlraw;
cx.wl_meas_n = m->nraw;
// cx.plot = 1; /* Plot each trial */
/* We could use the scale to adjust the whole CCD range, */
/* but the manufacturers driver doesn't seem to do this, */
/* and it may be making the calibration sensitive to any */
/* changes in the WL LED spectrum shape. Instead we minimize */
/* the error weighted for the peak of the shape. */
#ifdef SALONEINSTLIB
if (wloptimize(cparm, ss, 1e-7, wlcal_opt1, &cx))
a1logw(p->log,"wlcal_opt1 failed\n");
#else
if (powell(NULL, 2, cparm, ss, 1e-6, 1000, wlcal_opt1, &cx, NULL, NULL))
a1logw(p->log,"wlcal_opt1 failed\n");
#endif
a1logd(p->log,3,"WL best fit parameters: %f %f\n", cparm[0], cparm[1]);
led_off = cparm[1];
#ifdef PLOT_DEBUG
/* Plot the final result */
printf("Best WL match, ref = black, meas = red, err = green:\n");
cx.plot = 1;
wlcal_opt1(&cx, cparm);
#endif
/* If we have calibrated on the ambient cap, correct */
/* for the emissive vs. reflective raw2wav scaling factor */
if (mmax < 2500.0) {
double wlraw2 = m->wl_led_ref_off + (double)rpoff;
double raw, wlnm, wlraw1, refnm;
int k;
/* Convert from raw to wavelength using poly2 (emission) */
raw = 128.0 - wlraw2; /* Quadratic expects +ve correlation */
for (wlnm = m->wlpoly2[4-1], k = 4-2; k >= 0; k--)
wlnm = wlnm * raw + m->wlpoly2[k];
/* Convert from wavelength to raw using poly1 (reflectance) */
wlraw1 = inv_raw2wav(m->wlpoly1, 4, wlnm);
//printf("emiss raw %f -> ref raw %f\n",wlraw2, wlraw1);
/* Adjust the raw correction to account for measuring it in emissive mode */
led_off = led_off + wlraw2 - wlraw1;
/* Hmm. This is rather suspect. The difference between the white reference */
/* calibrated wavelength offset and the ambient cap one is about -0.2788 raw. */
/* This is not explained by the poly1 vs. poly2 difference at the WL LED peak */
/* at 550 nm. (see above), which amounts to about +0.026, leaving 0.2528 */
/* unexplained. It appears the CCD wavelength has a dependence on the */
/* angle that the light enters the optics ?? */
led_off += 0.2528; /* Hack to make ambient cap correction == white tile correction */
a1logd(p->log,3,"Adjusted raw correction by %f to account for measurement using ambient cap\n",wlraw2 - wlraw1 + 0.2528);
}
/* Check that the correction is not excessive */
off_nm = i1pro_raw2wav_uncal(p, led_off) - i1pro_raw2wav_uncal(p, m->wl_led_ref_off);
a1logd(p->log,2, "Final WL offset = %f, correction %f nm\n",led_off, off_nm);
if (fabs(off_nm)> m->wl_err_max) {
a1logd(p->log,1,"Final WL correction of %f nm is too big\n",off_nm);
return I1PRO_WL_ERR2BIG;
}
/* Do a verification plot */
/* Plot the measurement against calibrated wavelength, */
/* and reference measurement verses reference wavelength */
#ifdef PLOT_DEBUG
{
double xx[1024];
double y1[1024]; /* interpolate ref */
double y2[1024]; /* Measurement */
int ii;
/* i = index into measurement */
for (ii = 0, i = m->wl_led_ref_off; i < (m->wl_led_ref_off + m->wl_led_count); i++) {
double raw;
double mwl; /* Measurment wavelength */
double rraw; /* Reference raw value */
int ix; /* Lagrange base offset */
int k;
double yv;
raw = (double)i;
raw = raw - led_off + m->wl_led_ref_off;
raw = 128.0 - raw; /* Quadratic expects +ve correlation */
if (mmax < 2500.0) {
for (mwl = m->wlpoly2[4-1], k = 4-2; k >= 0; k--)
mwl = mwl * raw + m->wlpoly2[k];
} else {
for (mwl = m->wlpoly1[4-1], k = 4-2; k >= 0; k--)
mwl = mwl * raw + m->wlpoly1[k];
}
xx[ii] = mwl;
y1[ii] = cparm[0] * wlraw[i];
y2[ii] = 0.0;
/* Compute the reference index corresponding to this wavelength */
rraw = inv_raw2wav(m->wlpoly1, 4, mwl) - (double)m->wl_led_ref_off;
/* Use Lagrange to interpolate the reference level for this wavelength */
ix = ((int)rraw) - 1; /* Reference index of Lagrange for this xv */
if (ix < 0)
continue;
if ((ix + 3) >= m->wl_led_count)
break;
/* Compute interpolated value of reference using Lagrange: */
yv = m->wl_led_spec[ix+0] * (rraw-(ix+1)) * (rraw-(ix+2)) * (rraw-(ix+3))
/((0.0-1.0) * (0.0-2.0) * (0.0-3.0))
+ m->wl_led_spec[ix+1] * (rraw-(ix+0)) * (rraw-(ix+2)) * (rraw-(ix+3))
/((1.0-0.0) * (1.0-2.0) * (1.0-3.0))
+ m->wl_led_spec[ix+2] * (rraw-(ix+0)) * (rraw-(ix+1)) * (rraw-(ix+3))
/((2.0-0.0) * (2.0-1.0) * (2.0-3.0))
+ m->wl_led_spec[ix+3] * (rraw-(ix+0)) * (rraw-(ix+1)) * (rraw-(ix+2))
/((3.0-0.0) * (3.0-1.0) * (3.0-2.0));
y2[ii] = yv;
ii++;
}
printf("Verification fit in nm:\n");
do_plot(xx, y1, y2, NULL, ii);
}
#endif
if (pled_off != NULL)
*pled_off = led_off;
}
return ev;
}
/* Compute standard/high res. downsampling filters for the given mode */
/* given the current wl_led_off, and set them as current, */
/* using triangular filters of the lagrange interpolation of the */
/* CCD values (i.e. the same type of filter used by the OEM driver) */
/* [ Interestingly, the resulting filter shape is a bit like lanczos2, */
/* but not identical. ] */
i1pro_code i1pro_compute_wav_filters(i1pro *p, int hr, int refl) {
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
i1pro_code ev = I1PRO_OK;
double twidth; /* Target filter width */
int six, eix; /* raw starting index and one past end index */
int wlix; /* current wavelenght index */
double *wlcop; /* This wavelength base filter coefficient pointer */
double trh, trx; /* Triangle height and triangle equation x weighting */
int i, j, k;
a1logd(p->log,2,"i1pro_compute_wav_filters called with correction %f raw\n",s->wl_led_off - m->wl_led_ref_off);
twidth = (m->wl_long[hr] - m->wl_short[hr])/(m->nwav[hr] - 1.0); /* Filter width */
trh = 1.0/twidth; /* Triangle height */
trx = trh/twidth; /* Triangle equation x weighting */
/* Allocate separate space for the calibrated versions, so that the */
/* original eeprom values are preserved */
if (m->mtx_c[hr][refl].index == NULL) {
if ((m->mtx_c[hr][refl].index = (int *)calloc(m->nwav[hr], sizeof(int))) == NULL) {
a1logd(p->log,1,"i1pro: malloc ndex1 failed!\n");
return I1PRO_INT_MALLOC;
}
if ((m->mtx_c[hr][refl].nocoef = (int *)calloc(m->nwav[hr], sizeof(int))) == NULL) {
a1logd(p->log,1,"i1pro: malloc nocoef failed!\n");
return I1PRO_INT_MALLOC;
}
if ((m->mtx_c[hr][refl].coef = (double *)calloc(16 * m->nwav[hr], sizeof(double)))
== NULL) {
a1logd(p->log,1,"i1pro: malloc coef failed!\n");
return I1PRO_INT_MALLOC;
}
}
/* For each output wavelength */
wlcop = m->mtx_c[hr][refl].coef;
for (wlix = 0; wlix < m->nwav[hr]; wlix++) {
double owl = wlix/(m->nwav[hr]-1.0) * (m->wl_long[hr] - m->wl_short[hr]) + m->wl_short[hr];
int lip; /* Lagrange interpolation position */
// printf("Generating filter for %.1f nm width %.1f nm\n",owl, twidth);
/* The filter is based on a triangle centered at owl and extending */
/* from owl - twidth to owl + twidth. We therefore need to locate the */
/* raw values that will overlap this range */
/* Do a dumb search from high to low nm */
for (six = 0; six < m->nraw; six++) {
//printf("~1 (raw2wav (six %d) %f <? (owl %f + twidth %f) %f\n",six,i1pro_raw2wav(p, refl, (double)six),owl,twidth,owl + twidth);
if (i1pro_raw2wav(p, refl, (double)six) < (owl + twidth))
break;
}
if (six < 2 || six >= m->nraw) {
a1loge(p->log,1,"i1pro: compute_wav_filters() six %d, exceeds raw range to cover output filter %.1f nm width %.1f nm\n",six, owl, twidth);
return I1PRO_INT_ASSERT;
}
eix = six;
six -= 2; /* Outside */
for (; eix < m->nraw; eix++) {
if (i1pro_raw2wav(p, refl, (double)eix) <= (owl - twidth))
break;
}
if (eix > (m->nraw - 2) ) {
a1loge(p->log,1,"i1pro: compute_wav_filters() eix %d, exceeds raw range to cover output filter %.1f nm width %.1f nm\n",eix, owl, twidth);
return I1PRO_INT_ASSERT;
}
eix += 2; /* Outside */
// for (j = six; j < eix; j++)
// printf("Using raw %d @ %.1f nm\n",j, i1pro_raw2wav(p, refl, (double)j));
/* Set start index for this wavelength */
m->mtx_c[hr][refl].index[wlix] = six;
/* Set number of filter coefficients */
m->mtx_c[hr][refl].nocoef[wlix] = eix - six;
if (m->mtx_c[hr][refl].nocoef[wlix] > 16) {
a1loge(p->log,1,"i1pro: compute_wav_filters() too many filter %d\n",m->mtx_c[hr][refl].nocoef[wlix]);
return I1PRO_INT_ASSERT;
}
/* Start with zero filter weightings */
for (i = 0; i < m->mtx_c[hr][refl].nocoef[wlix]; i++)
wlcop[i] = 0.0;
/* for each Lagrange interpolation position (adjacent CCD locations) */
/* create the Lagrange and then accuumulate the integral of the convolution */
/* of the overlap of the central region, with the triangle of our */
/* underlying re-sampling filter. */
/* (If we were to run out of enough source points for the Lagrange to */
/* encompas the region, then in theory we could use the Lagrange to */
/* extrapolate beyond the end from points within.) */
for (lip = six; (lip + 3) < eix; lip++) {
double rwav[4]; /* Relative wavelength of these Lagrange points */
double den[4]; /* Denominator values for points */
double num[4][4]; /* Numerator polinomial components x^3, x^2, x, 1 */
double ilow, ihigh; /* Integration points */
/* Relative wavelengths to owl of each basis point */
for (i = 0; i < 4; i++)
rwav[i] = i1pro_raw2wav(p, refl, (double)lip + i) - owl;
// printf("\n~1 rwav = %f %f %f %f\n", rwav[0], rwav[1], rwav[2], rwav[3]);
/* Compute each basis points Lagrange denominator values */
den[0] = (rwav[0]-rwav[1]) * (rwav[0]-rwav[2]) * (rwav[0]-rwav[3]);
den[1] = (rwav[1]-rwav[0]) * (rwav[1]-rwav[2]) * (rwav[1]-rwav[3]);
den[2] = (rwav[2]-rwav[0]) * (rwav[2]-rwav[1]) * (rwav[2]-rwav[3]);
den[3] = (rwav[3]-rwav[0]) * (rwav[3]-rwav[1]) * (rwav[3]-rwav[2]);
// printf("~1 denominators = %f %f %f %f\n", den[0], den[1], den[2], den[3]);
/* Compute each basis points Langrange numerator components. */
/* We make the numerator have polinomial form, so that it is easy */
/* to compute the integral equation from it. */
num[0][0] = 1.0;
num[0][1] = -rwav[1] - rwav[2] - rwav[3];
num[0][2] = rwav[1] * rwav[2] + rwav[1] * rwav[3] + rwav[2] * rwav[3];
num[0][3] = -rwav[1] * rwav[2] * rwav[3];
num[1][0] = 1.0;
num[1][1] = -rwav[0] - rwav[2] - rwav[3];
num[1][2] = rwav[0] * rwav[2] + rwav[0] * rwav[3] + rwav[2] * rwav[3];
num[1][3] = -rwav[0] * rwav[2] * rwav[3];
num[2][0] = 1.0;
num[2][1] = -rwav[0] - rwav[1] - rwav[3];
num[2][2] = rwav[0] * rwav[1] + rwav[0] * rwav[3] + rwav[1] * rwav[3];
num[2][3] = -rwav[0] * rwav[1] * rwav[3];
num[3][0] = 1.0;
num[3][1] = -rwav[0] - rwav[1] - rwav[2];
num[3][2] = rwav[0] * rwav[1] + rwav[0] * rwav[2] + rwav[1] * rwav[2];
num[3][3] = -rwav[0] * rwav[1] * rwav[2];
// printf("~1 num %d = %f %f %f %f\n", 0, num[0][0], num[0][1], num[0][2], num[0][3]);
// printf("~1 num %d = %f %f %f %f\n", 1, num[1][0], num[1][1], num[1][2], num[1][3]);
// printf("~1 num %d = %f %f %f %f\n", 2, num[2][0], num[2][1], num[2][2], num[2][3]);
// printf("~1 num %d = %f %f %f %f\n", 3, num[3][0], num[3][1], num[3][2], num[3][3]);
/* Now compute the integral difference between the two middle points */
/* of the Lagrange over the triangle shape, and accumulate the resulting */
/* Lagrange weightings to the filter coefficients. */
/* For high and then low side of the triangle. */
for (k = 0; k < 2; k++) {
ihigh = rwav[1];
ilow = rwav[2];
/* Over just the central portion, if it overlaps the triangle. */
if ((k == 0 && ilow <= twidth && ihigh >= 0.0) /* Portion is +ve side */
|| (k == 1 && ilow <= 0.0 && ihigh >= -twidth)) { /* Portion is -ve side */
if (k == 0) {
if (ilow < 0.0)
ilow = 0.0;
if (ihigh > twidth)
ihigh = twidth;
// printf("~1 doing +ve triangle between %f %f\n",ilow,ihigh);
} else {
if (ilow < -twidth)
ilow = -twidth;
if (ihigh > 0.0)
ihigh = 0.0;
// printf("~1 doing -ve triangle between %f %f\n",ilow,ihigh);
}
/* For each Lagrange point */
for (i = 0; i < 4; i++) {
double xnum[5]; /* Expanded numerator components */
double nvall, nvalh; /* Numerator low and high values */
/* Because the y value is a function of x, we need to */
/* expand the Lagrange 3rd order polinomial into */
/* a 4th order polinomial using the triangle edge equation */
/* y = trh +- trx * x */
for (j = 0; j < 4; j++)
xnum[j] = (k == 0 ? -trx : trx) * num[i][j];
xnum[j] = 0.0;
for (j = 0; j < 4; j++)
xnum[j+1] += trh * num[i][j];
/* The 4th order equation becomes a 5th order one */
/* when we convert it to an integral, ie. x^4 becomes x^5/5 etc. */
for (j = 0; j < 4; j++)
xnum[j] /= (5.0 - (double)j); /* Integral denom. */
/* Compute ihigh integral as 5th order polynomial */
nvalh = xnum[0];
nvalh = nvalh * ihigh + xnum[1];
nvalh = nvalh * ihigh + xnum[2];
nvalh = nvalh * ihigh + xnum[3];
nvalh = nvalh * ihigh + xnum[4];
nvalh = nvalh * ihigh;
/* Compute ilow integral as 5th order polynomial */
nvall = xnum[0];
nvall = nvall * ilow + xnum[1];
nvall = nvall * ilow + xnum[2];
nvall = nvall * ilow + xnum[3];
nvall = nvall * ilow + xnum[4];
nvall = nvall * ilow;
/* Compute ihigh - ilow and add to filter weightings */
wlcop[lip -six + i] += (nvalh - nvall)/den[i];
// printf("~1 k = %d, comp %d weight += %e now %e\n",k,lip-six+i,(nvalh - nvall)/den[i], wlcop[lip-six+i]);
}
}
}
}
// printf("~1 Weightings for for %.1f nm are:\n",owl);
// for (i = 0; i < m->mtx_c[hr][refl].nocoef[wlix]; i++)
// printf("~1 comp %d weight %e\n",i,wlcop[i]);
wlcop += m->mtx_c[hr][refl].nocoef[wlix]; /* Next group of weightings */
}
#ifdef DEBUG
/* Check against orginal filters */
if (!hr) {
int ix1, ix1c;
double aerr = 0.0;
a1logd(p->log,2,"Checking genertated tables against EEProm table\n");
ix1 = ix1c = 0;
for (i = 0; i < m->nwav[0]; i++) {
double err;
int six, eix;
if (m->mtx_o.index[i] < m->mtx_o.index[i])
six = m->mtx_o.index[i];
else
six = m->mtx_o.index[i];
if ((m->mtx_o.index[i] + m->mtx_o.nocoef[i]) > (m->mtx_o.index[i] + m->mtx_o.nocoef[i]))
eix = m->mtx_o.index[i] + m->mtx_o.nocoef[i];
else
eix = m->mtx_o.index[i] + m->mtx_o.nocoef[i];
// printf("~1 filter %d from %d to %d\n",i,six,eix);
err = 0.0;
for (j = six; j < eix; j++) {
double w1, w1c;
if (j < m->mtx_o.index[i] || j >= (m->mtx_o.index[i] + m->mtx_o.nocoef[i]))
w1 = 0.0;
else
w1 = m->mtx_o.coef[ix1 + j - m->mtx_o.index[i]];
if (j < m->mtx_c[0][refl].index[i]
|| j >= (m->mtx_c[0][refl].index[i] + m->mtx_c[0][refl].nocoef[i]))
w1c = 0.0;
else
w1c = m->mtx_c[0][refl].coef[ix1c + j - m->mtx_c[0][refl].index[i]];
err += fabs(w1 - w1c);
// printf("Weight %d, %e should be %e\n", j, w1c, w1);
}
// printf("Filter %d average weighting error = %f\n",i, err/j);
aerr += err/j;
ix1 += m->mtx_o.nocoef[i];
ix1c += m->mtx_c[0][refl].nocoef[i];
}
a1logd(p->log,2,"Overall average filter weighting change = %f\n",aerr/m->nwav[0]);
}
#endif /* DEBUG */
/* Switch normal res. to use wavelength calibrated version */
m->mtx[hr][refl] = m->mtx_c[hr][refl];
return ev;
}
/* =============================================== */
#ifdef HIGH_RES
/*
It turns out that using the sharpest possible resampling filter
may make accuracy worse (particularly on the RevE), because it
enhances bumps in the raw response that mightn't be there
after calibrating for the instrument spectral sensitivity.
A better scheme (which we could sythesise using the hi-res
emissive calibration logic) would be to calibrate the raw CCD
values and then resample with possible sharpening.
Another approach would be to sharpen after filtering with
non-sharpening resampling filters.
The bottom line is that it's best to use a gausian hi-res
filter to avoid sharpening in non calibrated spectral space.
*/
/* High res congiguration */
/* Pick one of these: */
#undef USE_TRI_LAGRANGE /* [und] Use OEM/normal res. filter shape for HiRes */
#undef USE_LANCZOS2 /* [und] Use lanczos2 filter shape */
#undef USE_LANCZOS3 /* [und] Use lanczos3 filter shape */
#undef USE_DECONV /* [und] Use deconvolution curve */
#undef USE_BLACKMAN /* [und] Use Blackman windowed sinc shape */
#define USE_GAUSSIAN /* [def] Use gaussian filter shape*/
#undef USE_CUBIC /* [und] Use cubic spline filter */
#define DO_CCDNORM /* [def] Normalise CCD values to original */
#define DO_CCDNORMAVG /* [und ???] Normalise averages rather than per CCD bin */
/* (We relly on fine cal & white cal to fix it) */
#define BOX_INTEGRATE /* [und] Integrate raw samples as if they were +/-0.5 boxes */
/* (This improves coeficient consistency a bit ?) */
#undef COMPUTE_DISPERSION /* Compute slit & optics dispersion from red laser data */
#ifdef NEVER
/* Plot the matrix coefficients */
static void i1pro_debug_plot_mtx_coef(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
int i, j, k, cx, sx;
double *xx, *ss;
double **yy;
xx = dvectorz(-1, m->nraw-1); /* X index */
yy = dmatrixz(0, 5, -1, m->nraw-1); /* Curves distributed amongst 5 graphs */
for (i = 0; i < m->nraw; i++)
xx[i] = i;
/* For each output wavelength */
for (cx = j = 0; j < m->nwav; j++) {
i = j % 5;
// printf("Out wave = %d\n",j);
/* For each matrix value */
sx = m->mtx_index[j]; /* Starting index */
// printf("start index = %d, nocoef %d\n",sx,m->mtx_nocoef[j]);
for (k = 0; k < m->mtx_nocoef[j]; k++, cx++, sx++) {
// printf("offset %d, coef ix %d val %f from ccd %d\n",k, cx, m->mtx_coef[cx], sx);
yy[5][sx] += 0.5 * m->mtx_coef[cx];
yy[i][sx] = m->mtx_coef[cx];
}
}
do_plot6(xx, yy[0], yy[1], yy[2], yy[3], yy[4], yy[5], m->nraw);
free_dvector(xx, -1, m->nraw-1);
free_dmatrix(yy, 0, 5, -1, m->nraw-1);
}
#endif /* NEVER */
#ifdef COMPUTE_DISPERSION
/* Gausian filter implementation */
/* parameters are amplidude [0], center wavelength [1], std. dev. [2] */
static double gaussf(double tp[], double x) {
double y;
x = (x - tp[1])/(sqrt(2.0) * tp[2]);
y = tp[0] * exp(-(x * x));
return y;
}
/* Gausian integral implementatation */
/* parameters are amplidude [0], center wavelength [1], std. dev. [2] */
/* return an aproximation to the intergral between w1 and w2 */
static double gaussint(double tp[], double w1, double w2) {
int j, nn;
double lw, ll, vv;
/* Intergate in 0.1 nm increments */
nn = (int)(fabs(w2 - w1)/0.1 + 0.5);
lw = w1;
ll = gaussf(tp, lw);
vv = 0.0;
for (j = 0; j < nn; j++) {
double cw, cl;
cw = w1 + (j+1)/(nn +1.0) * (w2 - w1);
cl = gaussf(tp, cw);
vv += 0.5 * (cl + ll) * (lw - cw);
ll = cl;
lw = cw;
}
return fabs(vv);
}
/* Powell minimisation context */
typedef struct {
double nsp; /* Number of samples of dispersion data */
double *llv; /* [nsamp] laser values */
double *lwl; /* [nsamp+1] CCD boundary wavelegths */
} hropt_cx;
/* Powell minimisation callback function */
/* to match dispersion data */
static double hropt_opt1(void *vcx, double tp[]) {
hropt_cx *cx = (hropt_cx *)vcx;
double rv = 0.0;
int i, j;
/* For each CCD sample */
for (i = 0; i < cx->nsp; i++) {
double vv;
/* Actual CCD integrated value */
vv = cx->llv[i] * (cx->lwl[i] - cx->lwl[i+1]);
/* Computed intergral with current curve */
vv -= gaussint(tp, cx->lwl[i], cx->lwl[i+1]);
rv += vv * vv;
}
// printf("~1 params %f %f %f, rv = %f\n", tp[0],tp[1],tp[2],rv);
return rv;
}
#endif /* COMPUTE_DISPERSION */
/* Filter shape point */
typedef struct {
double wl, we;
} i1pro_fs;
/* Filter cooeficient values */
typedef struct {
int ix; /* Raw index */
double we; /* Weighting */
} i1pro_fc;
/* Wavelenth calibration crossover point information */
typedef struct {
double wav; /* Wavelegth of point */
double raw; /* Raw index of point */
double wei; /* Weigting of the point */
} i1pro_xp;
/* Linearly interpolate the filter shape */
static double lin_fshape(i1pro_fs *fsh, int n, double x) {
int i;
double y;
if (x <= fsh[0].wl)
return fsh[0].we;
else if (x >= fsh[n-1].wl)
return fsh[n-1].we;
for (i = 0; i < (n-2); i++)
if (x >= fsh[i].wl && x <= fsh[i+1].wl)
break;
x = (x - fsh[i].wl)/(fsh[i+1].wl - fsh[i].wl);
y = fsh[i].we + (fsh[i+1].we - fsh[i].we) * x;
return y;
}
/* Generate a sample from a lanczos2 filter shape */
/* wi is the width of the filter */
static double lanczos2(double wi, double x) {
double y = 0.0;
#ifdef USE_DECONV
/* For 3.333, created by i1deconv.c */
static i1pro_fs fshape[49] = {
{ -7.200000, 0.0 },
{ -6.900000, 0.013546 },
{ -6.600000, 0.035563 },
{ -6.300000, 0.070500 },
{ -6.000000, 0.106543 },
{ -5.700000, 0.148088 },
{ -5.400000, 0.180888 },
{ -5.100000, 0.186637 },
{ -4.800000, 0.141795 },
{ -4.500000, 0.046101 },
{ -4.200000, -0.089335 },
{ -3.900000, -0.244652 },
{ -3.600000, -0.391910 },
{ -3.300000, -0.510480 },
{ -3.000000, -0.573177 },
{ -2.700000, -0.569256 },
{ -2.400000, -0.489404 },
{ -2.100000, -0.333957 },
{ -1.800000, -0.116832 },
{ -1.500000, 0.142177 },
{ -1.200000, 0.411639 },
{ -0.900000, 0.658382 },
{ -0.600000, 0.851521 },
{ -0.300000, 0.967139 },
{ 0.000000, 1.000000 },
{ 0.300000, 0.967139 },
{ 0.600000, 0.851521 },
{ 0.900000, 0.658382 },
{ 1.200000, 0.411639 },
{ 1.500000, 0.142177 },
{ 1.800000, -0.116832 },
{ 2.100000, -0.333957 },
{ 2.400000, -0.489404 },
{ 2.700000, -0.569256 },
{ 3.000000, -0.573177 },
{ 3.300000, -0.510480 },
{ 3.600000, -0.391910 },
{ 3.900000, -0.244652 },
{ 4.200000, -0.089335 },
{ 4.500000, 0.046101 },
{ 4.800000, 0.141795 },
{ 5.100000, 0.186637 },
{ 5.400000, 0.180888 },
{ 5.700000, 0.148088 },
{ 6.000000, 0.106543 },
{ 6.300000, 0.070500 },
{ 6.600000, 0.035563 },
{ 6.900000, 0.013546 },
{ 7.200000, 0.0 }
};
return lin_fshape(fshape, 49, x);
#endif
#ifdef USE_GAUSSIAN
/* gausian */
wi = wi/(sqrt(2.0 * log(2.0))); /* Convert width at half max to std. dev. */
x = x/wi;
// y = 1.0/(wi * sqrt(2.0 * DBL_PI)) * exp(-(x * x)); /* Unity area */
y = exp(-(x * x)); /* Center at 1.0 */
#endif
#ifdef USE_LANCZOS2
/* lanczos2 */
wi *= 1.05; // Improves smoothness. Why ?
x = fabs(1.0 * x/wi);
if (x >= 2.0)
return 0.0;
if (x < 1e-6)
return 1.0;
y = sin(DBL_PI * x)/(DBL_PI * x) * sin(DBL_PI * x/2.0)/(DBL_PI * x/2.0);
#endif
#ifdef USE_LANCZOS3
/* lanczos3 */
x = fabs(1.0 * x/wi);
if (x >= 3.0)
return 0.0;
if (x < 1e-6)
return 1.0;
y = sin(DBL_PI * x)/(DBL_PI * x) * sin(DBL_PI * x/3.0)/(DBL_PI * x/3.0);
#endif
#ifdef USE_BLACKMAN /* Use Blackman windowed sinc shape */
double xx = x, w;
double a0, a1, a2, a3;
double bb, cc;
xx = fabs(1.0 * x/wi);
if (xx >= 2.0)
return 0.0;
if (xx < 1e-5)
return 1.0;
y = sin(DBL_PI * xx)/(DBL_PI * xx); /* sinc */
/* gausian window */
// wi *= 1.5;
// wi = wi/(2.0 * sqrt(2.0 * log(2.0))); /* Convert width at half max to std. dev. */
// x = x/(sqrt(2.0) * wi);
// w = exp(-(x * x));
xx = (xx/4.0 + 0.5); /* Convert to standard window cos() range */
/* Hamming window */
// a0 = 0.54; a1 = 0.46;
// w = a0 - a1 * cos(2.0 * DBL_PI * xx);
/* Blackman window */
a0 = 7938.0/18608.0; a1 = 9240.0/18608.0; a2 = 1430.0/18608.0;
w = a0 - a1 * cos(2.0 * DBL_PI * xx) + a2 * cos(4.0 * DBL_PI * xx);
/* Nuttall window */
// a0 = 0.355768; a1=0.487396; a2=0.144232; a3=0.012604;
// w = a0 - a1 * cos(2.0 * DBL_PI * xx) + a2 * cos(4.0 * DBL_PI * xx) - a3 * cos(6.0 * DBL_PI * xx);
/* Blackman Harris window */
// a0=0.35875; a1=0.48829; a2=0.14128; a3=0.01168;
// w = a0 - a1 * cos(2.0 * DBL_PI * xx) + a2 * cos(4.0 * DBL_PI * xx) - a3 * cos(6.0 * DBL_PI * xx);
/* Blackman Nuttall window */
// a0=0.3635819; a1=0.4891775; a2=0.1365995; a3=0.0106411;
// w = a0 - a1 * cos(2.0 * DBL_PI * xx) + a2 * cos(4.0 * DBL_PI * xx) - a3 * cos(6.0 * DBL_PI * xx);
y *= w;
#endif
#ifdef USE_CUBIC /* Use cubic sline */
double xx = x;
double bb, cc;
xx = fabs(1.0 * x/wi);
// bb = cc = 1.0/3.0; /* Mitchell */
bb = 0.5;
cc = 0.5;
if (xx < 1.0) {
y = ( 12.0 - 9.0 * bb - 6.0 * cc) * xx * xx * xx
+ (-18.0 + 12.0 * bb + 6.0 * cc) * xx * xx
+ ( 6.0 - 2.0 * bb);
y /= (6.0 - 2.0 * bb);
} else if (xx < 2.0) {
y = ( -1.0 * bb - 6.0 * cc) * xx * xx * xx
+ ( 6.0 * bb + 30.0 * cc) * xx * xx
+ (-12.0 * bb - 48.0 * cc) * xx
+ ( 8.0 * bb + 24.0 * cc);
y /= (6.0 - 2.0 * bb);
} else {
y = 0.0;
}
#endif
return y;
}
#if defined(__APPLE__) && defined(__POWERPC__)
/* Workaround for a ppc gcc 3.3 optimiser bug... */
static int gcc_bug_fix(int i) {
static int nn;
nn += i;
return nn;
}
#endif /* APPLE */
/* Re-create calibration factors for hi-res */
/* Set emisonly to only recompute emissive factors */
i1pro_code i1pro_create_hr_calfactors(i1pro *p, int eonly) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
int i, j;
/* Generate high res. per mode calibration factors. */
if (m->hr_inited) {
for (i = 0; i < i1p_no_modes; i++) {
i1pro_state *s = &m->ms[i];
if (s->cal_factor[1] == NULL)
s->cal_factor[1] = dvectorz(0, m->nwav[1]-1);
switch(i) {
case i1p_refl_spot:
case i1p_refl_scan:
if (eonly)
continue;
if (s->cal_valid) {
/* (Using cal_factor[] as temp. for i1pro_absraw_to_abswav()) */
#ifdef NEVER
printf("~1 regenerating calibration for reflection\n");
printf("~1 raw white data:\n");
plot_raw(s->white_data);
#endif /* NEVER */
i1pro_absraw_to_abswav(p, 0, s->reflective, 1, &s->cal_factor[0], &s->white_data);
#ifdef NEVER
printf("~1 Std res intmd. cal_factor:\n");
plot_wav(m, 0, s->cal_factor[0]);
#endif /* NEVER */
i1pro_absraw_to_abswav(p, 1, s->reflective, 1, &s->cal_factor[1], &s->white_data);
#ifdef NEVER
printf("~1 High intmd. cal_factor:\n");
plot_wav(m, 1, s->cal_factor[1]);
printf("~1 Std res white ref:\n");
plot_wav(m, 0, m->white_ref[0]);
printf("~1 High res white ref:\n");
plot_wav(m, 1, m->white_ref[1]);
#endif /* NEVER */
ev = i1pro_compute_white_cal(p,
s->cal_factor[0], m->white_ref[0], s->cal_factor[0],
s->cal_factor[1], m->white_ref[1], s->cal_factor[1],
i == i1p_refl_spot);
if (ev == I1PRO_RD_TRANSWHITEWARN) /* Shouldn't happen ? */
ev = I1PRO_OK;
if (ev != I1PRO_OK) {
return ev;
}
#ifdef NEVER
printf("~1 Std res final cal_factor:\n");
plot_wav(m, 0, s->cal_factor[0]);
printf("~1 High final cal_factor:\n");
plot_wav(m, 1, s->cal_factor[1]);
#endif /* NEVER */
}
break;
case i1p_emiss_spot_na:
case i1p_emiss_spot:
case i1p_emiss_scan:
for (j = 0; j < m->nwav[1]; j++)
s->cal_factor[1][j] = EMIS_SCALE_FACTOR * m->emis_coef[1][j];
break;
case i1p_amb_spot:
case i1p_amb_flash:
#ifdef FAKE_AMBIENT
for (j = 0; j < m->nwav[1]; j++)
s->cal_factor[1][j] = EMIS_SCALE_FACTOR * m->emis_coef[1][j];
s->cal_valid = 1;
#else
if (m->amb_coef[0] != NULL) {
for (j = 0; j < m->nwav[1]; j++)
s->cal_factor[1][j] = AMB_SCALE_FACTOR * m->emis_coef[1][j] * m->amb_coef[1][j];
s->cal_valid = 1;
}
#endif
break;
case i1p_trans_spot:
case i1p_trans_scan:
if (eonly)
continue;
if (s->cal_valid) {
/* (Using cal_factor[] as temp. for i1pro_absraw_to_abswav()) */
i1pro_absraw_to_abswav(p, 0, s->reflective, 1, &s->cal_factor[0], &s->white_data);
i1pro_absraw_to_abswav(p, 1, s->reflective, 1, &s->cal_factor[1], &s->white_data);
ev = i1pro_compute_white_cal(p, s->cal_factor[0], NULL, s->cal_factor[0],
s->cal_factor[1], NULL, s->cal_factor[1], 0);
if (ev == I1PRO_RD_TRANSWHITEWARN) /* Ignore this ? */
ev = I1PRO_OK;
if (ev != I1PRO_OK) {
return ev;
}
}
break;
}
}
}
return ev;
}
#ifdef SALONEINSTLIB
# define ONEDSTRAYLIGHTUS
#endif
/* Create or re-create high resolution mode references */
i1pro_code i1pro_create_hr(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
int refl;
double twidth = HIGHRES_WIDTH;
int i, j, k, cx, sx;
/* If we don't have any way of converting raw2wav (ie. RevE polinomial equations), */
/* use the orginal filters to figure this out. */
if (m->raw2wav == NULL
#ifndef ANALIZE_EXISTING
&& p->itype != instI1Pro2
#endif
) {
i1pro_fc coeff[100][16]; /* Existing filter cooefficients */
i1pro_xp xp[101]; /* Crossover points each side of filter */
i1pro_fs fshape[100 * 16]; /* Existing filter shape */
int ncp = 0; /* Number of shape points */
/* Convert the native filter cooeficient representation to */
/* a 2D array we can randomly index. */
for (cx = j = 0; j < m->nwav[0]; j++) { /* For each output wavelength */
if (j >= 100) { /* Assert */
a1loge(p->log,1,"i1pro: number of output wavelenths is > 100\n");
return I1PRO_INT_ASSERT;
}
/* For each matrix value */
sx = m->mtx_o.index[j]; /* Starting index */
for (k = 0; k < m->mtx_o.nocoef[j]; k++, cx++, sx++) {
if (k >= 16) { /* Assert */
a1loge(p->log,1,"i1pro: number of filter coeefs is > 16\n");
return I1PRO_INT_ASSERT;
}
coeff[j][k].ix = sx;
coeff[j][k].we = m->mtx_o.coef[cx];
// printf("Output %d, filter %d weight = %e\n",j,k,coeff[j][k].we);
}
}
#ifdef HIGH_RES_PLOT
/* Plot original re-sampling curves */
{
double *xx, *ss;
double **yy;
xx = dvectorz(-1, m->nraw-1); /* X index */
yy = dmatrixz(0, 5, -1, m->nraw-1); /* Curves distributed amongst 5 graphs */
for (i = 0; i < m->nraw; i++)
xx[i] = i;
/* For each output wavelength */
for (j = 0; j < m->nwav[0]; j++) {
i = j % 5;
/* For each matrix value */
for (k = 0; k < m->mtx_o.nocoef[j]; k++) {
yy[5][coeff[j][k].ix] += 0.5 * coeff[j][k].we;
yy[i][coeff[j][k].ix] = coeff[j][k].we;
}
}
printf("Original wavelength sampling curves:\n");
do_plot6(xx, yy[0], yy[1], yy[2], yy[3], yy[4], yy[5], m->nraw);
free_dvector(xx, -1, m->nraw-1);
free_dmatrix(yy, 0, 2, -1, m->nraw-1);
}
#endif /* HIGH_RES_PLOT */
// a1logd(p->log,3,"computing crossover points\n");
/* Compute the crossover points between each filter */
for (i = 0; i < (m->nwav[0]-1); i++) {
double den, y1, y2, y3, y4, yn, xn; /* Location of intersection */
double eps = 1e-6; /* Numerical tollerance */
double besty = -1e6;
/* between filter i and i+1, we want to find the two */
/* raw indexes where the weighting values cross over */
/* Do a brute force search to avoid making assumptions */
/* about the raw order. */
for (j = 0; j < (m->mtx_o.nocoef[i]-1); j++) {
for (k = 0; k < (m->mtx_o.nocoef[i+1]-1); k++) {
if (coeff[i][j].ix == coeff[i+1][k].ix
&& coeff[i][j+1].ix == coeff[i+1][k+1].ix) {
// a1logd(p->log,3,"got it at %d, %d: %d = %d, %d = %d\n",j,k, coeff[i][j].ix, coeff[i+1][k].ix, coeff[i][j+1].ix, coeff[i+1][k+1].ix);
/* Compute the intersection of the two line segments */
y1 = coeff[i][j].we;
y2 = coeff[i][j+1].we;
y3 = coeff[i+1][k].we;
y4 = coeff[i+1][k+1].we;
// a1logd(p->log,3,"y1 %f, y2 %f, y3 %f, y4 %f\n",y1, y2, y3, y4);
den = -y4 + y3 + y2 - y1;
if (fabs(den) < eps)
continue;
yn = (y2 * y3 - y1 * y4)/den;
xn = (y3 - y1)/den;
if (xn < -eps || xn > (1.0 + eps))
continue;
// a1logd(p->log,3,"den = %f, yn = %f, xn = %f\n",den,yn,xn);
if (yn > besty) {
xp[i+1].wav = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], i + 0.5);
xp[i+1].raw = (1.0 - xn) * coeff[i][j].ix + xn * coeff[i][j+1].ix;
xp[i+1].wei = yn;
besty = yn;
// a1logd(p->log,3,"Intersection %d: wav %f, raw %f, wei %f\n",i+1,xp[i+1].wav,xp[i+1].raw,xp[i+1].wei);
// a1logd(p->log,3,"Found new best y %f\n",yn);
}
// a1logd(p->log,3,"\n");
}
}
}
if (besty < 0.0) { /* Assert */
a1logw(p->log,"i1pro: failed to locate crossover between resampling filters\n");
return I1PRO_INT_ASSERT;
}
// a1logd(p->log,3,"\n");
}
/* Add the two points for the end filters */
{
double x5, x6, y5, y6; /* Points on intesecting line */
double den, y1, y2, y3, y4, yn, xn; /* Location of intersection */
x5 = xp[1].raw;
y5 = xp[1].wei;
x6 = xp[2].raw;
y6 = xp[2].wei;
/* Search for possible intersection point with first curve */
/* Create equation for line from next two intersection points */
for (j = 0; j < (m->mtx_o.nocoef[0]-1); j++) {
/* Extrapolate line to this segment */
y3 = y5 + (coeff[0][j].ix - x5)/(x6 - x5) * (y6 - y5);
y4 = y5 + (coeff[0][j+1].ix - x5)/(x6 - x5) * (y6 - y5);
/* This segment of curve */
y1 = coeff[0][j].we;
y2 = coeff[0][j+1].we;
if ( (( y1 >= y3 && y2 <= y4) /* Segments overlap */
|| ( y1 <= y3 && y2 >= y4))
&& (( coeff[0][j].ix < x5 && coeff[0][j].ix < x6
&& coeff[0][j+1].ix < x5 && coeff[0][j+1].ix < x6)
|| ( coeff[0][j+1].ix > x5 && coeff[0][j+1].ix > x6
&& coeff[0][j].ix > x5 && coeff[0][j].ix > x6))) {
break;
}
}
if (j >= m->mtx_o.nocoef[0]) { /* Assert */
a1loge(p->log,1,"i1pro: failed to find end crossover\n");
return I1PRO_INT_ASSERT;
}
den = -y4 + y3 + y2 - y1;
yn = (y2 * y3 - y1 * y4)/den;
xn = (y3 - y1)/den;
// printf("~1 den = %f, yn = %f, xn = %f\n",den,yn,xn);
xp[0].wav = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], -0.5);
xp[0].raw = (1.0 - xn) * coeff[0][j].ix + xn * coeff[0][j+1].ix;
xp[0].wei = yn;
// printf("End 0 intersection %d: wav %f, raw %f, wei %f\n",0,xp[0].wav,xp[0].raw,xp[0].wei);
// printf("\n");
x5 = xp[m->nwav[0]-2].raw;
y5 = xp[m->nwav[0]-2].wei;
x6 = xp[m->nwav[0]-1].raw;
y6 = xp[m->nwav[0]-1].wei;
// printf("~1 x5 %f, y5 %f, x6 %f, y6 %f\n",x5,y5,x6,y6);
/* Search for possible intersection point with first curve */
/* Create equation for line from next two intersection points */
for (j = 0; j < (m->mtx_o.nocoef[0]-1); j++) {
/* Extrapolate line to this segment */
y3 = y5 + (coeff[m->nwav[0]-1][j].ix - x5)/(x6 - x5) * (y6 - y5);
y4 = y5 + (coeff[m->nwav[0]-1][j+1].ix - x5)/(x6 - x5) * (y6 - y5);
/* This segment of curve */
y1 = coeff[m->nwav[0]-1][j].we;
y2 = coeff[m->nwav[0]-1][j+1].we;
if ( (( y1 >= y3 && y2 <= y4) /* Segments overlap */
|| ( y1 <= y3 && y2 >= y4))
&& (( coeff[m->nwav[0]-1][j].ix < x5 && coeff[m->nwav[0]-1][j].ix < x6
&& coeff[m->nwav[0]-1][j+1].ix < x5 && coeff[m->nwav[0]-1][j+1].ix < x6)
|| ( coeff[m->nwav[0]-1][j+1].ix > x5 && coeff[m->nwav[0]-1][j+1].ix > x6
&& coeff[m->nwav[0]-1][j].ix > x5 && coeff[m->nwav[0]-1][j].ix > x6))) {
break;
}
}
if (j >= m->mtx_o.nocoef[m->nwav[0]-1]) { /* Assert */
a1loge(p->log,1,"i1pro: failed to find end crossover\n");
return I1PRO_INT_ASSERT;
}
den = -y4 + y3 + y2 - y1;
yn = (y2 * y3 - y1 * y4)/den;
xn = (y3 - y1)/den;
// printf("~1 den = %f, yn = %f, xn = %f\n",den,yn,xn);
xp[m->nwav[0]].wav = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], m->nwav[0]-0.5);
xp[m->nwav[0]].raw = (1.0 - xn) * coeff[m->nwav[0]-1][j].ix + xn * coeff[m->nwav[0]-1][j+1].ix;
xp[m->nwav[0]].wei = yn;
// printf("End 36 intersection %d: wav %f, raw %f, wei %f\n",m->nwav[0]+1,xp[m->nwav[0]].wav,xp[m->nwav[0]].raw,xp[m->nwav[0]].wei);
// printf("\n");
}
#ifdef HIGH_RES_DEBUG
/* Check to see if the area of each filter curve is the same */
/* (yep, width times 2 * xover height is close to 1.0, and the */
/* sum of the weightings is exactly 1.0) */
for (i = 0; i < m->nwav[0]; i++) {
double area1, area2;
area1 = fabs(xp[i].raw - xp[i+1].raw) * (xp[i].wei + xp[i+1].wei);
area2 = 0.0;
for (j = 0; j < (m->mtx_o.nocoef[i]); j++)
area2 += coeff[i][j].we;
printf("Area of curve %d = %f, %f\n",i,area1, area2);
}
#endif /* HIGH_RES_DEBUG */
/* From our crossover data, create a rspl that maps raw CCD index */
/* value into wavelegth. */
/* (Generating a 4th order polynomial would probably be better, */
/* since this is almost certainly what was used to create the original */
/* filters.) */
{
co sd[101]; /* Scattered data points */
datai glow, ghigh;
datao vlow, vhigh;
int gres[1];
double avgdev[1];
if ((m->raw2wav = new_rspl(RSPL_NOFLAGS, 1, 1)) == NULL) {
a1logd(p->log,1,"i1pro: creating rspl for high res conversion failed\n");
return I1PRO_INT_NEW_RSPL_FAILED;
}
vlow[0] = 1e6;
vhigh[0] = -1e6;
for (i = 0; i < (m->nwav[0]+1); i++) {
sd[i].p[0] = xp[i].raw;
sd[i].v[0] = xp[i].wav;
if (sd[i].v[0] < vlow[0])
vlow[0] = sd[i].v[0];
if (sd[i].v[0] > vhigh[0])
vhigh[0] = sd[i].v[0];
}
glow[0] = 0.0;
ghigh[0] = 127.0;
gres[0] = 128;
avgdev[0] = 0.0;
m->raw2wav->fit_rspl(m->raw2wav, 0, sd, m->nwav[0]+1, glow, ghigh, gres, vlow, vhigh, 0.5, avgdev, NULL);
}
#ifdef HIGH_RES_PLOT
/* Plot raw to wav lookup */
{
double *xx, *yy, *y2;
xx = dvector(0, m->nwav[0]+1); /* X index = raw bin */
yy = dvector(0, m->nwav[0]+1); /* Y = nm */
y2 = dvector(0, m->nwav[0]+1); /* Y = nm */
for (i = 0; i < (m->nwav[0]+1); i++) {
co pp;
double iv, v1, v2;
xx[i] = xp[i].raw;
yy[i] = xp[i].wav;
pp.p[0] = xp[i].raw;
m->raw2wav->interp(m->raw2wav, &pp);
y2[i] = pp.v[0];
}
printf("CCD bin to wavelength mapping of original filters + rspl:\n");
do_plot6(xx, yy, y2, NULL, NULL, NULL, NULL, m->nwav[0]+1);
free_dvector(xx, 0, m->nwav[0]+1);
free_dvector(yy, 0, m->nwav[0]+1);
free_dvector(y2, 0, m->nwav[0]+1);
}
#endif /* HIGH_RES_PLOT */
#ifdef ANALIZE_EXISTING
/* Convert each weighting curves values into normalized values and */
/* accumulate into a single curve. */
if (!m->hr_inited) {
for (i = 0; i < m->nwav[0]; i++) {
double cwl; /* center wavelegth */
double weight = 0.0;
for (j = 0; j < (m->mtx_o.nocoef[i]); j++) {
double w1, w2, cellw;
/* Translate CCD cell boundaries index to wavelength */
w1 = i1pro_raw2wav_uncal(p, (double)coeff[i][j].ix - 0.5);
w2 = i1pro_raw2wav_uncal(p, (double)coeff[i][j].ix + 0.5);
cellw = fabs(w2 - w1);
cwl = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], i);
/* Translate CCD index to wavelength */
fshape[ncp].wl = i1pro_raw2wav_uncal(p, (double)coeff[i][j].ix) - cwl;
fshape[ncp].we = coeff[i][j].we / (0.09 * cellw);
ncp++;
}
}
/* Now sort by wavelength */
#define HEAP_COMPARE(A,B) (A.wl < B.wl)
HEAPSORT(i1pro_fs, fshape, ncp)
#undef HEAP_COMPARE
/* Strip out leading zero's */
for (i = 0; i < ncp; i++) {
if (fshape[i].we != 0.0)
break;
}
if (i > 1 && i < ncp) {
memmove(&fshape[0], &fshape[i-1], sizeof(i1pro_fs) * (ncp - i + 1));
ncp = ncp - i + 1;
for (i = 0; i < ncp; i++) {
if (fshape[i].we != 0.0)
break;
}
}
#ifdef HIGH_RES_PLOT
/* Plot the shape of the accumulated curve */
{
double *x1 = dvectorz(0, ncp-1);
double *y1 = dvectorz(0, ncp-1);
for (i = 0; i < ncp; i++) {
double x;
x1[i] = fshape[i].wl;
y1[i] = fshape[i].we;
}
printf("Original accumulated curve:\n");
do_plot(x1, y1, NULL, NULL, ncp);
free_dvector(x1, 0, ncp-1);
free_dvector(y1, 0, ncp-1);
}
#endif /* HIGH_RES_PLOT */
#ifdef HIGH_RES_DEBUG
/* Check that the orginal filter sums to a constant */
{
double x, sum;
for (x = 0.0; x < 10.0; x += 0.2) {
sum = 0;
sum += lin_fshape(fshape, ncp, x - 30.0);
sum += lin_fshape(fshape, ncp, x - 20.0);
sum += lin_fshape(fshape, ncp, x - 10.0);
sum += lin_fshape(fshape, ncp, x - 0.0);
sum += lin_fshape(fshape, ncp, x + 10.0);
sum += lin_fshape(fshape, ncp, x + 20.0);
printf("Offset %f, sum %f\n",x, sum);
}
}
#endif /* HIGH_RES_DEBUG */
}
#endif /* ANALIZE_EXISTING */
} /* End of compute wavelength cal from existing filters */
#ifdef COMPUTE_DISPERSION
if (!m->hr_inited) {
/* Fit our red laser CCD data to a slit & optics Gaussian dispersion model */
{
double spf[3]; /* Spread function parameters */
/* Measured CCD values of red laser from CCD indexes 29 to 48 inclusive */
/* (It would be nice to have similar data from a monochromic source */
/* at other wavelegths such as green and blue!) */
double llv[20] = {
53.23,
81.3,
116.15,
176.16,
305.87,
613.71,
8500.52,
64052.0,
103134.13,
89154.03,
21742.89,
1158.86,
591.44,
369.75,
241.01,
166.48,
126.79,
97.76,
63.88,
46.46
};
double lwl[21]; /* Wavelegth of boundary between CCD cells */
double ccd;
hropt_cx cx;
double ss[3];
/* Add CCD boundary wavelengths to dispersion data */
for (ccd = 29.0 - 0.5, i = 0; i < 21; i++, ccd += 1.0) {
/* Translate CCD cell boundaries index to wavelength */
lwl[i] = i1pro_raw2wav_uncal(p, ccd);
}
/* Fit a gausian to it */
cx.nsp = 20;
cx.llv = llv;
cx.lwl = lwl;
/* parameters are amplidude [0], center wavelength [1], std. dev. [2] */
spf[0] = 115248.0;
spf[1] = 653.78;
spf[2] = 3.480308;
ss[0] = 500.0;
ss[1] = 0.5;
ss[2] = 0.5;
if (powell(NULL, 3, spf, ss, 1e-5, 2000, hropt_opt1, &cx))
a1logw(p->log,"hropt_opt1 failed\n");
#ifdef HIGH_RES_PLOT
/* Plot dispersion spectra */
{
double xx[200];
double y1[200];
double y2[200];
double w1, w2;
w1 = lwl[0] + 5.0;
w2 = lwl[20] - 5.0;
for (i = 0; i < 200; i++) {
double wl;
wl = w1 + (i/199.0) * (w2-w1);
xx[i] = wl;
for (j = 0; j < 20; j++) {
if (lwl[j] >= wl && wl >= lwl[j+1])
break;
}
if (j < 20)
y1[i] = llv[j];
else
y1[i] = 0.0;
y2[i] = gaussf(spf, wl);
}
printf("Gauss Parameters %f %f %f\n",spf[0],spf[1],spf[2]);
printf("Red laser dispersion data:\n");
do_plot(xx, y1, y2, NULL, 200);
}
#endif /* HIGH_RES_PLOT */
/* Normalize the gausian to have an area of 1 */
spf[0] *= 1.0/(spf[0] * spf[2] * sqrt(2.0 * DBL_PI));
// printf("~1 Normalized intergral = %f\n",gaussint(spf, spf[1] - 30.0, spf[1] + 30.0));
// printf("~1 Half width = %f\n",2.0 * sqrt(2.0 * log(2.0)) * spf[2]);
}
}
#endif /* COMPUTE_DISPERSION */
/* Compute the upsampled calibration references */
if (!m->hr_inited) {
rspl *trspl; /* Upsample rspl */
cow sd[40 * 40]; /* Scattered data points of existing references */
datai glow, ghigh;
datao vlow, vhigh;
int gres[2];
double avgdev[2];
int ix, ii;
co pp;
if ((trspl = new_rspl(RSPL_NOFLAGS, 1, 1)) == NULL) {
a1logd(p->log,1,"i1pro: creating rspl for high res conversion failed\n");
return I1PRO_INT_NEW_RSPL_FAILED;
}
/* For ref, emis, ambient */
for (ii = 0; ii < 3; ii++) {
double **ref2, *ref1;
double smooth = 1.0;
if (ii == 0) {
ref1 = m->white_ref[0];
ref2 = &m->white_ref[1];
// smooth = 0.5;
smooth = 1.5;
} else if (ii == 1) {
/* Don't create high res. from low res., if there is */
/* a better, calibrated cal read from .cal file */
if (m->emis_coef[1] != NULL) {
if (m->emis_hr_cal)
continue;
free(m->emis_coef[1]); /* Regenerate it anyway */
}
ref1 = m->emis_coef[0];
ref2 = &m->emis_coef[1];
m->emis_hr_cal = 0;
smooth = 10.0;
} else {
if (m->amb_coef[0] == NULL)
break;
ref1 = m->amb_coef[0];
ref2 = &m->amb_coef[1];
smooth = 1.0;
}
if (ref1 == NULL)
continue; /* The instI1Monitor doesn't have a reflective cal */
vlow[0] = 1e6;
vhigh[0] = -1e6;
for (ix = i = 0; i < m->nwav[0]; i++) {
sd[ix].p[0] = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], i);
sd[ix].v[0] = ref1[i];
sd[ix].w = 1.0;
if (sd[ix].v[0] < vlow[0])
vlow[0] = sd[ix].v[0];
if (sd[ix].v[0] > vhigh[0])
vhigh[0] = sd[ix].v[0];
ix++;
}
/* Our upsampling is OK for reflective and ambient cal's, */
/* but isn't so good for the emissive cal., especially */
/* on the i1pro2 which has a rather bumpy diffraction */
/* grating/sensor. We'll get an opportunity to fix it */
/* when we do a reflective calibration, by using the */
/* smoothness of the lamp as a reference. */
/* Add inbetween points to restrain dips and peaks in interp. */
for (i = 0; i < (m->nwav[0]-1); i++) {
/* Use linear interp extra points */
double wt = 0.05;
sd[ix].p[0] = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], i + 0.3333);
sd[ix].v[0] = (2.0 * ref1[i] + ref1[i+1])/3.0;
sd[ix].w = wt;
if (sd[ix].v[0] < vlow[0])
vlow[0] = sd[ix].v[0];
if (sd[ix].v[0] > vhigh[0])
vhigh[0] = sd[ix].v[0];
ix++;
sd[ix].p[0] = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], i + 0.66667);
sd[ix].v[0] = (ref1[i] + 2.0 * ref1[i+1])/3.0;
sd[ix].w = wt;
if (sd[ix].v[0] < vlow[0])
vlow[0] = sd[ix].v[0];
if (sd[ix].v[0] > vhigh[0])
vhigh[0] = sd[ix].v[0];
ix++;
}
glow[0] = m->wl_short[1];
ghigh[0] = m->wl_long[1];
gres[0] = 3 * m->nwav[1];
avgdev[0] = 0.0;
trspl->fit_rspl_w(trspl, 0, sd, ix, glow, ghigh, gres, vlow, vhigh, smooth, avgdev, NULL);
if ((*ref2 = (double *)calloc(m->nwav[1], sizeof(double))) == NULL) {
trspl->del(trspl);
a1logw(p->log, "i1pro: malloc ref2 failed!\n");
return I1PRO_INT_MALLOC;
}
for (i = 0; i < m->nwav[1]; i++) {
pp.p[0] = m->wl_short[1]
+ (double)i * (m->wl_long[1] - m->wl_short[1])/(m->nwav[1]-1.0);
trspl->interp(trspl, &pp);
(*ref2)[i] = pp.v[0];
}
#ifdef HIGH_RES_PLOT
/* Plot original and upsampled reference */
{
double *x1 = dvectorz(0, m->nwav[1]-1);
double *y1 = dvectorz(0, m->nwav[1]-1);
double *y2 = dvectorz(0, m->nwav[1]-1);
for (i = 0; i < m->nwav[1]; i++) {
double wl = m->wl_short[1] + (double)i * (m->wl_long[1] - m->wl_short[1])/(m->nwav[1]-1.0);
x1[i] = wl;
y1[i] = wav_lerp_cv(m, 0, ref1, wl, 0.0);
y2[i] = (*ref2)[i];
}
printf("Original and up-sampled ");
if (ii == 0) {
printf("Reflective cal. curve:\n");
} else if (ii == 1) {
printf("Emission cal. curve:\n");
} else {
printf("Ambient cal. curve:\n");
}
do_plot(x1, y1, y2, NULL, m->nwav[1]);
free_dvector(x1, 0, m->nwav[1]-1);
free_dvector(y1, 0, m->nwav[1]-1);
free_dvector(y2, 0, m->nwav[1]-1);
}
#endif /* HIGH_RES_PLOT */
}
trspl->del(trspl);
/* Upsample stray light */
if (p->itype == instI1Pro2) {
#ifdef ONEDSTRAYLIGHTUS
double **slp; /* 2D Array of stray light values */
/* Then the 2D stray light using linear interpolation */
slp = dmatrix(0, m->nwav[0]-1, 0, m->nwav[0]-1);
/* Set scattered points */
for (i = 0; i < m->nwav[0]; i++) { /* Output wavelength */
for (j = 0; j < m->nwav[0]; j++) { /* Input wavelength */
slp[i][j] = m->straylight[0][i][j];
/* Use interpolate/extrapolate for middle points */
if (j == (i-1) || j == i || j == (i+1)) {
int j0, j1;
double w0, w1;
if (j == (i-1)) {
if (j <= 0)
j0 = j+3, j1 = j+4;
else if (j >= (m->nwav[0]-3))
j0 = j-2, j1 = j-1;
else
j0 = j-1, j1 = j+3;
} else if (j == i) {
if (j <= 1)
j0 = j+2, j1 = j+3;
else if (j >= (m->nwav[0]-2))
j0 = j-3, j1 = j-2;
else
j0 = j-2, j1 = j+2;
} else if (j == (i+1)) {
if (j <= 2)
j0 = j+1, j1 = j+2;
else if (j >= (m->nwav[0]-1))
j0 = j-4, j1 = j-3;
else
j0 = j-3, j1 = j+1;
}
w1 = (j - j0)/(j1 - j0);
w0 = 1.0 - w1;
slp[i][j] = w0 * m->straylight[0][i][j0]
+ w1 * m->straylight[0][i][j1];
}
}
}
#else /* !ONEDSTRAYLIGHTUS */
/* Then setup 2D stray light using rspl */
if ((trspl = new_rspl(RSPL_NOFLAGS, 2, 1)) == NULL) {
a1logd(p->log,1,"i1pro: creating rspl for high res conversion failed\n");
return I1PRO_INT_NEW_RSPL_FAILED;
}
/* Set scattered points */
for (i = 0; i < m->nwav[0]; i++) { /* Output wavelength */
for (j = 0; j < m->nwav[0]; j++) { /* Input wavelength */
int ix = i * m->nwav[0] + j;
sd[ix].p[0] = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], i);
sd[ix].p[1] = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], j);
sd[ix].v[0] = m->straylight[0][i][j];
sd[ix].w = 1.0;
if (j == (i-1) || j == i || j == (i+1))
sd[ix].w = 0.0;
}
}
glow[0] = m->wl_short[1];
glow[1] = m->wl_short[1];
ghigh[0] = m->wl_long[1];
ghigh[1] = m->wl_long[1];
gres[0] = m->nwav[1];
gres[1] = m->nwav[1];
avgdev[0] = 0.0;
avgdev[1] = 0.0;
trspl->fit_rspl_w(trspl, 0, sd, m->nwav[0] * m->nwav[0], glow, ghigh, gres, NULL, NULL, 0.5, avgdev, NULL);
#endif /* !ONEDSTRAYLIGHTUS */
m->straylight[1] = dmatrixz(0, m->nwav[1]-1, 0, m->nwav[1]-1);
/* Create upsampled version */
for (i = 0; i < m->nwav[1]; i++) { /* Output wavelength */
for (j = 0; j < m->nwav[1]; j++) { /* Input wavelength */
double p0, p1;
p0 = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], i);
p1 = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], j);
#ifdef ONEDSTRAYLIGHTUS
/* Do linear interp with clipping at ends */
{
int x0, x1, y0, y1;
double xx, yy, w0, w1, v0, v1;
xx = (m->nwav[0]-1.0) * (p0 - m->wl_short[0])/(m->wl_long[0] - m->wl_short[0]);
x0 = (int)floor(xx);
if (x0 <= 0)
x0 = 0;
else if (x0 >= (m->nwav[0]-2))
x0 = m->nwav[0]-2;
x1 = x0 + 1;
w1 = xx - (double)x0;
w0 = 1.0 - w1;
yy = (m->nwav[0]-1.0) * (p1 - m->wl_short[0])/(m->wl_long[0] - m->wl_short[0]);
y0 = (int)floor(yy);
if (y0 <= 0)
y0 = 0;
else if (y0 >= (m->nwav[0]-2))
y0 = m->nwav[0]-2;
y1 = y0 + 1;
v1 = yy - (double)y0;
v0 = 1.0 - v1;
pp.v[0] = w0 * v0 * slp[x0][y0]
+ w0 * v1 * slp[x0][y1]
+ w1 * v0 * slp[x1][y0]
+ w1 * v1 * slp[x1][y1];
}
#else /* !ONEDSTRAYLIGHTUS */
pp.p[0] = p0;
pp.p[1] = p1;
trspl->interp(trspl, &pp);
#endif /* !ONEDSTRAYLIGHTUS */
m->straylight[1][i][j] = pp.v[0] * HIGHRES_WIDTH/10.0;
if (m->straylight[1][i][j] > 0.0)
m->straylight[1][i][j] = 0.0;
}
}
/* Fix primary wavelength weight and neighbors */
for (i = 0; i < m->nwav[1]; i++) { /* Output wavelength */
double sum;
if (i > 0)
m->straylight[1][i][i-1] = 0.0;
m->straylight[1][i][i] = 0.0;
if (i < (m->nwav[1]-1))
m->straylight[1][i][i+1] = 0.0;
for (sum = 0.0, j = 0; j < m->nwav[1]; j++)
sum += m->straylight[1][i][j];
m->straylight[1][i][i] = 1.0 - sum; /* Total sum should be 1.0 */
}
#ifdef HIGH_RES_PLOT_STRAYL
/* Plot original and upsampled reference */
{
double *x1 = dvectorz(0, m->nwav[1]-1);
double *y1 = dvectorz(0, m->nwav[1]-1);
double *y2 = dvectorz(0, m->nwav[1]-1);
for (i = 0; i < m->nwav[1]; i++) { /* Output wavelength */
double wli = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], i);
int i1 = XSPECT_IX(m->wl_short[0], m->wl_long[0], m->nwav[0], wli);
for (j = 0; j < m->nwav[1]; j++) {
double wl = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], j);
x1[j] = wl;
y1[j] = m->straylight[1][i][j];
if (y1[j] == 0.0)
y1[j] = -8.0;
else
y1[j] = log10(fabs(y1[j]));
if (wli < m->wl_short[0] || wli > m->wl_long[0]
|| wl < m->wl_short[0] || wl > m->wl_long[0]) {
y2[j] = -8.0;
} else {
double x, wl1, wl2;
for (k = 0; k < (m->nwav[0]-1); k++) {
wl1 = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], k);
wl2 = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], k+1);
if (wl >= wl1 && wl <= wl2)
break;
}
x = (wl - wl1)/(wl2 - wl1);
y2[j] = m->straylight[0][i1][k] + (m->straylight[0][i1][k+1]
- m->straylight[0][i1][k]) * x;
if (y2[j] == 0.0)
y2[j] = -8.0;
else
y2[j] = log10(fabs(y2[j]));
}
}
do_plot(x1, y1, y2, NULL, m->nwav[1]);
}
free_dvector(x1, 0, m->nwav[1]-1);
free_dvector(y1, 0, m->nwav[1]-1);
free_dvector(y2, 0, m->nwav[1]-1);
}
#endif /* HIGH_RES_PLOT */
#ifdef ONEDSTRAYLIGHTUS
free_dmatrix(slp, 0, m->nwav[0]-1, 0, m->nwav[0]-1);
#else /* !ONEDSTRAYLIGHTUS */
trspl->del(trspl);
#endif /* !ONEDSTRAYLIGHTUS */
}
}
/* Create or re-create the high resolution filters */
for (refl = 0; refl < 2; refl++) { /* for emis/trans and reflective */
#define MXNOWL 200 /* Max hires bands */
#define MXNOFC 32 /* Max hires coeffs */
#ifndef USE_TRI_LAGRANGE /* Use decimation filter */
int super = 0; /* nz if we're super sampling */
double fshmax; /* filter shape max wavelength from center */
i1pro_fc coeff2[MXNOWL][MXNOFC]; /* New filter cooefficients */
/* Construct a set of filters that uses more CCD values */
if (twidth < 3.0)
super = 1;
if (m->nwav[1] > MXNOWL) { /* Assert */
a1loge(p->log,1,"High res filter has too many bands\n");
return I1PRO_INT_ASSERT;
}
if (super) {
fshmax = 5.0;
} else {
/* Use a simple means of determining width */
for (fshmax = 50.0; fshmax >= 0.0; fshmax -= 0.1) {
if (fabs(lanczos2(twidth, fshmax)) > 0.0001) {
fshmax += 0.1;
break;
}
}
if (fshmax <= 0.0) {
a1logw(p->log, "i1pro: fshmax search failed\n");
return I1PRO_INT_ASSERT;
}
}
// printf("~1 fshmax = %f\n",fshmax);
#ifdef HIGH_RES_DEBUG
/* Check that the filter sums to a constant */
{
double x, sum;
for (x = 0.0; x < 5.0; x += 0.1) {
sum = 0;
sum += lin_fshape(fshape, ncp, x - 15.0);
sum += lin_fshape(fshape, ncp, x - 10.0);
sum += lin_fshape(fshape, ncp, x - 5.0);
sum += lin_fshape(fshape, ncp, x - 0.0);
sum += lin_fshape(fshape, ncp, x + 5.0);
sum += lin_fshape(fshape, ncp, x + 10.0);
printf("Offset %f, sum %f\n",x, sum);
}
}
#endif /* HIGH_RES_DEBUG */
/* Create all the filters */
if (m->mtx_c[1][refl].nocoef != NULL)
free(m->mtx_c[1][refl].nocoef);
if ((m->mtx_c[1][refl].nocoef = (int *)calloc(m->nwav[1], sizeof(int))) == NULL) {
a1logw(p->log, "i1pro: malloc nocoef failed!\n");
return I1PRO_INT_MALLOC;
}
if (super) { /* Use linear interpolation */
/* For all the useful CCD bands */
for (i = 1; i < (127-1); i++) {
double wl, wh;
/* Translate CCD centers to calibrated wavelength */
wh = i1pro_raw2wav(p, refl, (double)(i+0));
wl = i1pro_raw2wav(p, refl, (double)(i+1));
/* For each filter */
for (j = 0; j < m->nwav[1]; j++) {
double cwl; /* Center wavelength */
double we; /* Weighting */
double wwwe = 1.0;
cwl = m->wl_short[1] + (double)j * (m->wl_long[1] - m->wl_short[1])
/(m->nwav[1]-1.0);
//printf("~1 wl %f, wh %f, cwl %f\n",wl,wh,cwl);
if (cwl < (wl - 1e-6) || cwl > (wh + 1e-6))
continue; /* Doesn't fall into this filter */
if ((m->mtx_c[1][refl].nocoef[j]+1) >= MXNOFC) {
a1logw(p->log, "i1pro: run out of high res filter space\n");
return I1PRO_INT_ASSERT;
}
we = (cwl - wl)/(wh - wl);
// wwwe = 3.3/(wh - wl);
coeff2[j][m->mtx_c[1][refl].nocoef[j]].ix = i;
coeff2[j][m->mtx_c[1][refl].nocoef[j]++].we = wwwe * we;
//printf("~1 filter %d, cwl %f, ix %d, we %f, nocoefs %d\n",j,cwl,i,we,m->mtx_c[1][refl].nocoef[j]);
coeff2[j][m->mtx_c[1][refl].nocoef[j]].ix = i+1;
coeff2[j][m->mtx_c[1][refl].nocoef[j]++].we = wwwe * (1.0 - we);
//printf("~1 filter %d, cwl %f, ix %d, we %f, nocoefs %d\n",j,cwl,i+1,1.0-we,m->mtx_c[1][refl].nocoef[j]);
}
}
} else {
/* For all the useful CCD bands */
for (i = 1; i < 127; i++) {
double w1, wl, w2;
/* Translate CCD center and boundaries to calibrated wavelength */
wl = i1pro_raw2wav(p, refl, (double)i);
w1 = i1pro_raw2wav(p, refl, (double)i - 0.5);
w2 = i1pro_raw2wav(p, refl, (double)i + 0.5);
// printf("~1 CCD %d, w1 %f, wl %f, w2 %f\n",i,w1,wl,w2);
/* For each filter */
for (j = 0; j < m->nwav[1]; j++) {
double cwl, rwl; /* center, relative wavelegth */
double we;
cwl = m->wl_short[1] + (double)j * (m->wl_long[1] - m->wl_short[1])
/(m->nwav[1]-1.0);
rwl = wl - cwl; /* relative wavelength to filter */
if (fabs(w1 - cwl) > fshmax && fabs(w2 - cwl) > fshmax)
continue; /* Doesn't fall into this filter */
#ifdef BOX_INTEGRATE
/* Integrate in 0.05 nm increments from filter shape */
/* using triangular integration. */
{
int nn;
double lw, ll;
#ifdef FAST_HIGH_RES_SETUP
# define FINC 0.2
#else
# define FINC 0.05
#endif
nn = (int)(fabs(w2 - w1)/FINC + 0.5); /* Number to integrate over */
lw = w1; /* start at lower boundary of CCD cell */
ll = lanczos2(twidth, w1- cwl);
we = 0.0;
for (k = 0; k < nn; k++) {
double cw, cl;
#if defined(__APPLE__) && defined(__POWERPC__)
gcc_bug_fix(k);
#endif
cw = w1 + (k+1.0)/(nn +1.0) * (w2 - w1); /* wl to sample */
cl = lanczos2(twidth, cw- cwl);
we += 0.5 * (cl + ll) * (lw - cw); /* Area under triangle */
ll = cl;
lw = cw;
}
}
#else
we = fabs(w2 - w1) * lanczos2(twidth, rwl);
#endif
if (m->mtx_c[1][refl].nocoef[j] >= MXNOFC) {
a1logw(p->log, "i1pro: run out of high res filter space\n");
return I1PRO_INT_ASSERT;
}
coeff2[j][m->mtx_c[1][refl].nocoef[j]].ix = i;
coeff2[j][m->mtx_c[1][refl].nocoef[j]++].we = we;
// printf("~1 filter %d, cwl %f, rwl %f, ix %d, we %f, nocoefs %d\n",j,cwl,rwl,i,we,m->mtx_c[1][refl].nocoef[j]);
}
}
}
#ifdef HIGH_RES_PLOT
/* Plot resampled curves */
{
double *xx, *ss;
double **yy;
xx = dvectorz(-1, m->nraw-1); /* X index */
yy = dmatrixz(0, 5, -1, m->nraw-1); /* Curves distributed amongst 5 graphs */
for (i = 0; i < m->nraw; i++)
xx[i] = i;
/* For each output wavelength */
for (j = 0; j < m->nwav[1]; j++) {
i = j % 5;
/* For each matrix value */
for (k = 0; k < m->mtx_c[1][refl].nocoef[j]; k++) {
yy[5][coeff2[j][k].ix] += 0.5 * coeff2[j][k].we;
yy[i][coeff2[j][k].ix] = coeff2[j][k].we;
}
}
printf("Hi-Res wavelength sampling curves %s:\n",refl ? "refl" : "emis");
do_plot6(xx, yy[0], yy[1], yy[2], yy[3], yy[4], yy[5], m->nraw);
free_dvector(xx, -1, m->nraw-1);
free_dmatrix(yy, 0, 2, -1, m->nraw-1);
}
#endif /* HIGH_RES_PLOT */
/* Convert hires filters into runtime format */
{
int xcount;
/* Allocate or reallocate high res filter tables */
if (m->mtx_c[1][refl].index != NULL)
free(m->mtx_c[1][refl].index);
if (m->mtx_c[1][refl].coef != NULL)
free(m->mtx_c[1][refl].coef);
if ((m->mtx_c[1][refl].index = (int *)calloc(m->nwav[1], sizeof(int))) == NULL) {
a1logw(p->log, "i1pro: malloc index failed!\n");
return I1PRO_INT_MALLOC;
}
xcount = 0;
for (j = 0; j < m->nwav[1]; j++) {
m->mtx_c[1][refl].index[j] = coeff2[j][0].ix;
xcount += m->mtx_c[1][refl].nocoef[j];
}
if ((m->mtx_c[1][refl].coef = (double *)calloc(xcount, sizeof(double))) == NULL) {
a1logw(p->log, "i1pro: malloc coef failed!\n");
return I1PRO_INT_MALLOC;
}
for (i = j = 0; j < m->nwav[1]; j++)
for (k = 0; k < m->mtx_c[1][refl].nocoef[j]; k++, i++)
m->mtx_c[1][refl].coef[i] = coeff2[j][k].we;
/* Set high res tables to new allocations */
m->mtx[1][refl] = m->mtx_c[1][refl];
}
#else /* USE_TRI_LAGRANGE, OEM/normal res. triangle over lagrange interp */
/* Compute high res. reflective wavelength corrected filters */
if ((ev = i1pro_compute_wav_filters(p, 1, refl)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_compute_wav_filters() failed\n");
return ev;
}
#endif /* USE_TRI_LAGRANGE */
/* Normalise the filters area in CCD space, while maintaining the */
/* total contribution of each CCD at the target too. */
/* Hmm. This will wreck super-sample. We should fix it */
#ifdef DO_CCDNORM /* Normalise CCD values to original */
{
double x[4], y[4];
double avg[2], max[2];
double ccdsum[2][128]; /* Target weight/actual for each CCD */
double dth[2];
avg[0] = avg[1] = 0.0;
max[0] = max[1] = 0.0;
for (j = 0; j < 128; j++) {
ccdsum[0][j] = 0.0;
ccdsum[1][j] = 0.0;
}
/* Compute the weighting of each CCD value in the normal output */
for (cx = j = 0; j < m->nwav[0]; j++) { /* For each wavelength */
/* For each matrix value */
sx = m->mtx_o.index[j]; /* Starting index */
for (k = 0; k < m->mtx_o.nocoef[j]; k++, cx++, sx++) {
ccdsum[0][sx] += m->mtx_o.coef[cx];
//printf("~1 Norm CCD [%d] %f += [%d] %f\n",sx,ccdsum[0][sx],cx, m->mtx_o.coef[cx]);
}
}
/* Compute the weighting of each CCD value in the hires output */
for (cx = j = 0; j < m->nwav[1]; j++) { /* For each wavelength */
/* For each matrix value */
sx = m->mtx_c[1][refl].index[j]; /* Starting index */
for (k = 0; k < m->mtx_c[1][refl].nocoef[j]; k++, cx++, sx++) {
ccdsum[1][sx] += m->mtx_c[1][refl].coef[cx];
//printf("~1 HiRes CCD [%d] %f += [%d] %f\n",sx,ccdsum[1][sx],cx, m->mtx_c[1][refl].coef[cx]);
}
}
/* Figure valid range and extrapolate to edges */
dth[0] = 0.0; /* ref */
// dth[1] = 0.007; /* hires */
dth[1] = 0.004; /* hires */
for (k = 0; k < 2; k++) {
for (i = 0; i < 128; i++) {
if (ccdsum[k][i] > max[k])
max[k] = ccdsum[k][i];
}
//printf("~1 max[%d] = %f\n",k, max[k]);
/* Figure out the valid range */
for (i = 64; i >= 0; i--) {
if (ccdsum[k][i] > (0.8 * max[k])) {
x[0] = (double)i;
} else {
break;
}
}
for (i = 64; i < 128; i++) {
if (ccdsum[k][i] > (0.8 * max[k])) {
x[3] = (double)i;
} else {
break;
}
}
/* Space off the last couple of entries */
x[0] += (3.0 + 3.0);
x[3] -= (3.0 + 3.0);
x[1] = floor((2 * x[0] + x[3])/3.0);
x[2] = floor((x[0] + 2 * x[3])/3.0);
for (i = 0; i < 4; i++) {
y[i] = 0.0;
for (j = -3; j < 4; j++) {
y[i] += ccdsum[k][(int)x[i]+j];
}
y[i] /= 7.0;
}
//printf("~1 extrap nodes %f, %f, %f, %f\n",x[0],x[1],x[2],x[3]);
//printf("~1 extrap value %f, %f, %f, %f\n",y[0],y[1],y[2],y[3]);
for (i = 0; i < 128; i++) {
double xw, yw;
xw = (double)i;
/* Compute interpolated value using Lagrange: */
yw = y[0] * (xw-x[1]) * (xw-x[2]) * (xw-x[3])
/((x[0]-x[1]) * (x[0]-x[2]) * (x[0]-x[3]))
+ y[1] * (xw-x[0]) * (xw-x[2]) * (xw-x[3])
/((x[1]-x[0]) * (x[1]-x[2]) * (x[1]-x[3]))
+ y[2] * (xw-x[0]) * (xw-x[1]) * (xw-x[3])
/((x[2]-x[0]) * (x[2]-x[1]) * (x[2]-x[3]))
+ y[3] * (xw-x[0]) * (xw-x[1]) * (xw-x[2])
/((x[3]-x[0]) * (x[3]-x[1]) * (x[3]-x[2]));
if ((xw < x[0] || xw > x[3])
&& fabs(ccdsum[k][i] - yw)/yw > dth[k]) {
ccdsum[k][i] = yw;
}
avg[k] += ccdsum[k][i];
}
avg[k] /= 128.0;
}
#ifdef HIGH_RES_PLOT
/* Plot target CCD values */
{
double xx[128], y1[128], y2[128];
for (i = 0; i < 128; i++) {
xx[i] = i;
y1[i] = ccdsum[0][i]/avg[0];
y2[i] = ccdsum[1][i]/avg[1];
}
printf("Target and actual CCD weight sums:\n");
do_plot(xx, y1, y2, NULL, 128);
}
#endif
#ifdef DO_CCDNORMAVG /* Just correct by average */
for (cx = j = 0; j < m->nwav[1]; j++) { /* For each wavelength */
/* For each matrix value */
sx = m->mtx_c[1][refl].index[j]; /* Starting index */
for (k = 0; k < m->mtx_c[1][refl].nocoef[j]; k++, cx++, sx++) {
m->mtx_c[1][refl].coef[cx] *= 10.0/twidth * avg[0]/avg[1];
}
}
#else /* Correct by CCD bin */
/* Correct the weighting of each CCD value in the hires output */
for (i = 0; i < 128; i++) {
ccdsum[1][i] = 10.0/twidth * ccdsum[0][i]/ccdsum[1][i]; /* Correction factor */
}
for (cx = j = 0; j < m->nwav[1]; j++) { /* For each wavelength */
/* For each matrix value */
sx = m->mtx_c[1][refl].index[j]; /* Starting index */
for (k = 0; k < m->mtx_c[1][refl].nocoef[j]; k++, cx++, sx++) {
m->mtx_c[1][refl].coef[cx] *= ccdsum[1][sx];
}
}
#endif
}
#endif /* DO_CCDNORM */
#ifdef HIGH_RES_PLOT
{
static i1pro_fc coeff2[MXNOWL][MXNOFC];
double *xx, *ss;
double **yy;
/* Convert the native filter cooeficient representation to */
/* a 2D array we can randomly index. */
for (cx = j = 0; j < m->nwav[1]; j++) { /* For each output wavelength */
if (j >= MXNOWL) { /* Assert */
a1loge(p->log,1,"i1pro: number of hires output wavelenths is > %d\n",MXNOWL);
return I1PRO_INT_ASSERT;
}
/* For each matrix value */
sx = m->mtx[1][refl].index[j]; /* Starting index */
for (k = 0; k < m->mtx[1][refl].nocoef[j]; k++, cx++, sx++) {
if (k >= MXNOFC) { /* Assert */
a1loge(p->log,1,"i1pro: number of hires filter coeefs is > %d\n",MXNOFC);
return I1PRO_INT_ASSERT;
}
coeff2[j][k].ix = sx;
coeff2[j][k].we = m->mtx[1][refl].coef[cx];
// printf("Output %d, filter %d weight = %e\n",j,k,coeff2[j][k].we);
}
}
xx = dvectorz(-1, m->nraw-1); /* X index */
yy = dmatrixz(0, 5, -1, m->nraw-1); /* Curves distributed amongst 5 graphs */
for (i = 0; i < m->nraw; i++)
xx[i] = i;
/* For each output wavelength */
for (j = 0; j < m->nwav[1]; j++) {
i = j % 5;
/* For each matrix value */
for (k = 0; k < m->mtx_c[1][refl].nocoef[j]; k++) {
yy[5][coeff2[j][k].ix] += 0.5 * coeff2[j][k].we;
yy[i][coeff2[j][k].ix] = coeff2[j][k].we;
}
}
printf("Normalized Hi-Res wavelength sampling curves: %s\n",refl ? "refl" : "emis");
do_plot6(xx, yy[0], yy[1], yy[2], yy[3], yy[4], yy[5], m->nraw);
free_dvector(xx, -1, m->nraw-1);
free_dmatrix(yy, 0, 2, -1, m->nraw-1);
}
#endif /* HIGH_RES_PLOT */
#undef MXNOWL
#undef MXNOFC
} /* Do next filter */
/* Hires has been initialised */
m->hr_inited = 1;
/* Generate high res. per mode calibration factors. */
if ((ev = i1pro_create_hr_calfactors(p, 0)) != I1PRO_OK)
return ev;
return ev;
}
#endif /* HIGH_RES */
/* return nz if high res is supported */
int i1pro_imp_highres(i1pro *p) {
#ifdef HIGH_RES
return 1;
#else
return 0;
#endif /* HIGH_RES */
}
/* Set to high resolution mode */
i1pro_code i1pro_set_highres(i1pro *p) {
int i;
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
#ifdef HIGH_RES
if (m->hr_inited == 0) {
if ((ev = i1pro_create_hr(p)) != I1PRO_OK)
return ev;
}
m->highres = 1;
#else
ev = I1PRO_UNSUPPORTED;
#endif /* HIGH_RES */
return ev;
}
/* Set to standard resolution mode */
i1pro_code i1pro_set_stdres(i1pro *p) {
int i;
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
#ifdef HIGH_RES
m->highres = 0;
#else
ev = I1PRO_UNSUPPORTED;
#endif /* HIGH_RES */
return ev;
}
/* =============================================== */
/* Modify the scan consistency tolerance */
i1pro_code i1pro_set_scan_toll(i1pro *p, double toll_ratio) {
i1proimp *m = (i1proimp *)p->m;
i1pro_code ev = I1PRO_OK;
m->scan_toll_ratio = toll_ratio;
return I1PRO_OK;
}
/* Optical adjustment weights */
static double opt_adj_weights[21] = {
1.4944496665144658e-282, 2.0036175483913455e-070, 1.2554893022685038e+232,
2.3898157055642966e+190, 1.5697625128432372e-076, 6.6912978722191457e+281,
1.2369092402930559e+277, 1.4430907501246712e-153, 3.0017439193018232e+238,
1.2978311824382444e+161, 5.5068703318775818e-311, 7.7791723264455314e-260,
6.4560484084110176e+170, 8.9481529920968425e+165, 1.3565405878488529e-153,
2.0835868791190880e-076, 5.4310198502711138e+241, 4.8689849775675438e+275,
9.2709981544886391e+122, 3.7958270103353899e-153, 7.1366083837501666e-154
};
/* Convert from spectral to XYZ, and transfer to the ipatch array. */
/* Apply XRGA conversion if needed */
i1pro_code i1pro_conv2XYZ(
i1pro *p,
ipatch *vals, /* Values to return */
int nvals, /* Number of values */
double **specrd, /* Spectral readings */
instClamping clamp /* Clamp XYZ/Lab to be +ve */
) {
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
xsp2cie *conv; /* Spectral to XYZ conversion object */
int i, j, k;
int six = 0; /* Starting index */
int nwl = m->nwav[m->highres]; /* Number of wavelegths */
double wl_short = m->wl_short[m->highres]; /* Starting wavelegth */
double sms; /* Weighting */
if (s->emiss)
conv = new_xsp2cie(icxIT_none, NULL, icxOT_CIE_1931_2, NULL, icSigXYZData, (icxClamping)clamp);
else
conv = new_xsp2cie(icxIT_D50, NULL, icxOT_CIE_1931_2, NULL, icSigXYZData, (icxClamping)clamp);
if (conv == NULL)
return I1PRO_INT_CIECONVFAIL;
/* Don't report any wavelengths below the minimum for this mode */
if ((s->min_wl-1e-3) > wl_short) {
double wl = 0.0;
for (j = 0; j < m->nwav[m->highres]; j++) {
wl = XSPECT_WL(m->wl_short[m->highres], m->wl_long[m->highres], m->nwav[m->highres], j);
if (wl >= (s->min_wl-1e-3))
break;
}
six = j;
wl_short = wl;
nwl -= six;
}
a1logd(p->log,5,"i1pro_conv2XYZ got wl_short %f, wl_long %f, nwav %d, min_wl %f\n",
m->wl_short[m->highres], m->wl_long[m->highres], m->nwav[m->highres], s->min_wl);
a1logd(p->log,5," after skip got wl_short %f, nwl = %d\n", wl_short, nwl);
for (sms = 0.0, i = 1; i < 21; i++)
sms += opt_adj_weights[i];
sms *= opt_adj_weights[0];
for (i = 0; i < nvals; i++) {
vals[i].loc[0] = '\000';
vals[i].mtype = inst_mrt_none;
vals[i].XYZ_v = 0;
vals[i].sp.spec_n = 0;
vals[i].duration = 0.0;
vals[i].sp.spec_n = nwl;
vals[i].sp.spec_wl_short = wl_short;
vals[i].sp.spec_wl_long = m->wl_long[m->highres];
if (s->emiss) {
/* Leave spectral values as mW/m^2 */
for (j = six, k = 0; j < m->nwav[m->highres]; j++, k++) {
vals[i].sp.spec[k] = specrd[i][j] * sms;
}
vals[i].sp.norm = 1.0;
/* Set the XYZ */
conv->convert(conv, vals[i].XYZ, &vals[i].sp);
vals[i].XYZ_v = 1;
if (s->ambient) {
if (s->flash)
vals[i].mtype = inst_mrt_ambient_flash;
else
vals[i].mtype = inst_mrt_ambient;
} else {
if (s->flash)
vals[i].mtype = inst_mrt_emission_flash;
else
vals[i].mtype = inst_mrt_emission;
}
} else {
/* Scale spectral values to percentage reflectance */
for (j = six, k = 0; j < m->nwav[m->highres]; j++, k++) {
vals[i].sp.spec[k] = 100.0 * specrd[i][j] * sms;
}
vals[i].sp.norm = 100.0;
/* Set the XYZ */
conv->convert(conv, vals[i].XYZ, &vals[i].sp);
vals[i].XYZ_v = 1;
vals[i].XYZ[0] *= 100.0;
vals[i].XYZ[1] *= 100.0;
vals[i].XYZ[2] *= 100.0;
if (s->trans)
vals[i].mtype = inst_mrt_transmissive;
else
vals[i].mtype = inst_mrt_reflective;
}
/* Don't return spectral if not asked for */
if (!m->spec_en) {
vals[i].sp.spec_n = 0;
}
}
conv->del(conv);
/* Apply any XRGA conversion */
ipatch_convert_xrga(vals, nvals, xcalstd_nonpol, m->target_calstd, m->native_calstd, clamp);
return I1PRO_OK;
}
/* Check a reflective white reference measurement to see if */
/* it seems reasonable. Return I1PRO_OK if it is, error if not. */
i1pro_code i1pro_check_white_reference1(
i1pro *p,
double *abswav /* [nwav[0]] Measurement to check */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
double *emiswav, normfac;
double avg01, avg2227;
int j;
emiswav = dvector(-1, m->nraw-1);
/* Convert from absolute wavelength converted sensor reading, */
/* to calibrated emission wavelength spectrum. */
/* For each output wavelength */
for (j = 0; j < m->nwav[0]; j++) {
emiswav[j] = m->emis_coef[0][j] * abswav[j];
}
#ifdef PLOT_DEBUG
printf("White ref read converted to emissive spectrum:\n");
plot_wav(m, 0, emiswav);
#endif
/* Normalise the measurement to the reflectance of the 17 wavelength */
/* of the white reference (550nm), as well as dividing out the */
/* reference white. This should leave us with the iluminant spectrum, */
normfac = m->white_ref[0][17]/emiswav[17];
for (j = 0; j < m->nwav[0]; j++) {
emiswav[j] *= normfac/m->white_ref[0][j];
}
#ifdef PLOT_DEBUG
printf("normalised to reference white read:\n");
plot_wav(m, 0, emiswav);
#endif
/* Compute two sample averages of the illuminant spectrum. */
avg01 = 0.5 * (emiswav[0] + emiswav[1]);
for (avg2227 = 0, j = 22; j < 28; j++) {
avg2227 += emiswav[j];
}
avg2227 /= (double)(28 - 22);
free_dvector(emiswav, -1, m->nraw-1);
/* And check them against tolerance for the illuminant. */
if (m->physfilt == 0x82) { /* UV filter */
a1logd(p->log,2,"Checking white reference (UV): 0.0 < avg01 %f < 0.05, 1.2 < avg2227 %f < 1.76\n",avg01,avg2227);
if (0.0 < avg01 && avg01 < 0.05
&& 1.2 < avg2227 && avg2227 < 1.76) {
return I1PRO_OK;
}
} else { /* No filter */
a1logd(p->log,2,"Checking white reference: 0.11 < avg01 %f < 0.22, 1.35 < avg2227 %f < 1.6\n",avg01,avg2227);
if (0.11 < avg01 && avg01 < 0.22
&& 1.35 < avg2227 && avg2227 < 1.6) {
return I1PRO_OK;
}
}
a1logd(p->log,2,"Checking white reference failed - out of tollerance");
return I1PRO_RD_WHITEREFERROR;
}
/* Compute a mode calibration factor given the reading of the white reference. */
/* We will also calibrate & smooth hi-res emis_coef[1] if they are present. */
/* Return I1PRO_RD_TRANSWHITEWARN if any of the transmission wavelengths are low. */
/* May return some other error (malloc) */
i1pro_code i1pro_compute_white_cal(
i1pro *p,
double *cal_factor0, /* [nwav[0]] Calibration factor to compute */
double *white_ref0, /* [nwav[0]] White reference to aim for, NULL for 1.0 */
double *white_read0, /* [nwav[0]] The white that was read */
double *cal_factor1, /* [nwav[1]] Calibration factor to compute */
double *white_ref1, /* [nwav[1]] White reference to aim for, NULL for 1.0 */
double *white_read1, /* [nwav[1]] The white that was read */
int do_emis_ft /* Do emission hires fine tune with this info. */
) {
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
int j, warn = I1PRO_OK;;
#ifdef HIGH_RES
/* If we need to, fine calibrate the emission */
/* calibration coefficients, using the reflectance cal. */
/* illuminant as an (assumed) smooth light source reference. */
/* (Do this first, befor white_read0/cal_factor0 is overwritten by white cal.) */
if (do_emis_ft && m->hr_inited != 0 && white_ref1 != NULL) {
i1pro_code ev = I1PRO_OK;
int i;
double *lincal;
double *fudge;
xspect illA;
#ifdef HIGH_RES_PLOT
double *targ_smth; /* Hires target in smooth space */
double *old_emis;
double avgl;
if ((targ_smth = (double *)calloc(m->nwav[1], sizeof(double))) == NULL) {
return I1PRO_INT_MALLOC;
}
if ((old_emis = (double *)calloc(m->nwav[1], sizeof(double))) == NULL) {
return I1PRO_INT_MALLOC;
}
for (i = 0; i < m->nwav[1]; i++)
old_emis[i] = m->emis_coef[1][i];
#endif
if ((lincal = (double *)calloc(m->nwav[0], sizeof(double))) == NULL) {
return I1PRO_INT_MALLOC;
}
if ((fudge = (double *)calloc(m->nwav[0], sizeof(double))) == NULL) {
return I1PRO_INT_MALLOC;
}
/* Fill in an xpsect with a standard illuminant spectrum */
if (standardIlluminant(&illA, icxIT_Ptemp, 2990.0)) {
a1loge(p->log,1,"i1pro_compute_white_cal: standardIlluminant() failed");
return I1PRO_INT_ASSERT;
}
for (j = 0; j < m->nwav[0]; j++) {
double wl = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], j);
lincal[j] = white_read0[j] * m->emis_coef[0][j]
/ (white_ref0[j] * value_xspect(&illA, wl));
}
#ifndef NEVER
/* Generate the hires emis_coef by interpolating lincal */
/* using rspl, and reversing computation through hi-res readings */
{
rspl *trspl; /* Upsample rspl */
cow sd[40]; /* Scattered data points of existing references */
datai glow, ghigh;
datao vlow, vhigh;
int gres[1];
double avgdev[1];
int ix;
co pp;
if ((trspl = new_rspl(RSPL_NOFLAGS, 1, 1)) == NULL) {
a1logd(p->log,1,"i1pro: creating rspl for high res conversion failed\n");
return I1PRO_INT_NEW_RSPL_FAILED;
}
vlow[0] = 1e6;
vhigh[0] = -1e6;
for (ix = i = 0; i < m->nwav[0]; i++) {
sd[ix].p[0] = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], i);
sd[ix].v[0] = lincal[i];
sd[ix].w = 1.0;
if (sd[ix].v[0] < vlow[0])
vlow[0] = sd[ix].v[0];
if (sd[ix].v[0] > vhigh[0])
vhigh[0] = sd[ix].v[0];
ix++;
}
glow[0] = m->wl_short[1];
ghigh[0] = m->wl_long[1];
gres[0] = 6 * m->nwav[1];
avgdev[0] = 0.0;
/* The smoothness factor of 0.02 seems critical in tuning the RevE */
/* hires accuracy, as measured on an LCD display */
trspl->fit_rspl_w(trspl, 0, sd, ix, glow, ghigh, gres, vlow, vhigh, 0.05, avgdev, NULL);
/* Create a linear interp fudge factor to place interp at low */
/* res. exactly on lowres linear curve. This compensates */
/* if the rspl moves the target at the lowres points */
for (j = 0; j < m->nwav[0]; j++) {
double wl = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], j);
pp.p[0] = wl;
trspl->interp(trspl, &pp);
fudge[j] = lincal[j] / pp.v[0];
}
/* Compute hires emis_coef */
for (i = 0; i < m->nwav[1]; i++) {
double wl = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], i);
double ff;
pp.p[0] = wl;
trspl->interp(trspl, &pp);
#ifdef HIGH_RES_PLOT
targ_smth[i] = pp.v[0];
#endif
/* Invert lincal at high res */
ff = wav_lerp(m, 0, fudge, wl);
m->emis_coef[1][i] = (ff * pp.v[0] * white_ref1[i] * value_xspect(&illA, wl))
/white_read1[i];
}
trspl->del(trspl);
}
#else
/* Generate the hires emis_coef by interpolating lincal */
/* using lagrange, and reversing computation through hi-res readings */
for (i = 0; i < m->nwav[1]; i++) {
int k;
double x[4], xw;
double y[4], yw;
xw = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], i);
/* Locate lowres index below it */
j = (int)floor(XSPECT_DIX(m->wl_short[0], m->wl_long[0], m->nwav[0], xw)) -1;
if (j < 0)
j = 0;
if (j > (m->nwav[0]-4))
j = (m->nwav[0]-4);
/* Setup the surrounding point values */
for (k = 0; k < 4; k++) {
x[k] = XSPECT_WL(m->wl_short[0], m->wl_long[0], m->nwav[0], j+k);
y[k] = lincal[j+k];
}
/* Compute interpolated value using Lagrange: */
yw = y[0] * (xw-x[1]) * (xw-x[2]) * (xw-x[3])
/((x[0]-x[1]) * (x[0]-x[2]) * (x[0]-x[3]))
+ y[1] * (xw-x[0]) * (xw-x[2]) * (xw-x[3])
/((x[1]-x[0]) * (x[1]-x[2]) * (x[1]-x[3]))
+ y[2] * (xw-x[0]) * (xw-x[1]) * (xw-x[3])
/((x[2]-x[0]) * (x[2]-x[1]) * (x[2]-x[3]))
+ y[3] * (xw-x[0]) * (xw-x[1]) * (xw-x[2])
/((x[3]-x[0]) * (x[3]-x[1]) * (x[3]-x[2]));
targ_smth[i] = yw;
/* Invert lincal at high res */
m->emis_coef[1][i] = (yw * white_ref1[i] * value_xspect(&illA, xw))/white_read1[i];
}
#endif /* NEVER */
#ifdef HIGH_RES_PLOT
/* Plot linear target curve and measured curve */
{
double *xx, *y1, *y2, *y3, *y4;
xx = dvector(0, m->nwav[1]); /* X wl */
y1 = dvector(0, m->nwav[1]);
y2 = dvector(0, m->nwav[1]);
y3 = dvector(0, m->nwav[1]);
y4 = dvector(0, m->nwav[1]);
for (j = 0; j < (m->nwav[1]); j++) {
xx[j] = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], j);
y1[j] = wav_lerp_cv(m, 0, lincal, xx[j], 0.0);
y2[j] = targ_smth[j];
y3[j] = white_read1[j] * wav_lerp(m, 0, m->emis_coef[0], xx[j])
/(white_ref1[j] * value_xspect(&illA, xx[j]));
y4[j] = white_read1[j] * old_emis[j]
/(white_ref1[j] * value_xspect(&illA, xx[j]));
}
printf("stdres interp targ (bk), smoothed targ (rd), measured hires resp. (gn), previous cal resp.(bu):\n");
do_plot6(xx, y1, y2, y3, y4, NULL, NULL, m->nwav[1]);
free_dvector(xx, 0, m->nwav[1]);
free_dvector(y1, 0, m->nwav[1]);
free_dvector(y2, 0, m->nwav[1]);
free_dvector(y4, 0, m->nwav[1]);
}
/* Plot target and achieved smooth space responses */
{
double *xx, *y2;
xx = dvector(0, m->nwav[1]);
y2 = dvector(0, m->nwav[1]);
for (j = 0; j < (m->nwav[1]); j++) {
xx[j] = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], j);
y2[j] = white_read1[j] * m->emis_coef[1][j]
/(white_ref1[j] * value_xspect(&illA, xx[j]));
}
printf("target smooth curve, achived smooth curve:\n");
do_plot6(xx, targ_smth, y2, NULL, NULL, NULL, NULL, m->nwav[1]);
free_dvector(xx, 0, m->nwav[1]);
free_dvector(y2, 0, m->nwav[1]);
}
/* Plot lowres and hires lamp response */
{
double *xx, *y1, *y2;
xx = dvector(0, m->nwav[1]);
y1 = dvector(0, m->nwav[1]);
y2 = dvector(0, m->nwav[1]);
for (j = 0; j < (m->nwav[1]); j++) {
xx[j] = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], j);
y1[j] = wav_lerp(m, 0, white_read0, xx[j]) * wav_lerp(m, 0, m->emis_coef[0], xx[j])
/wav_lerp(m, 0, white_ref0, xx[j]);
y2[j] = white_read1[j] * m->emis_coef[1][j]
/white_ref1[j];
}
printf("lowres, high res lamp response:\n");
do_plot6(xx, y1, y2, NULL, NULL, NULL, NULL, m->nwav[1]);
free_dvector(xx, 0, m->nwav[1]);
free_dvector(y1, 0, m->nwav[1]);
free_dvector(y2, 0, m->nwav[1]);
}
/* Plot hires emis calibration */
{
double *xx;
xx = dvector(0, m->nwav[1]); /* X wl */
for (j = 0; j < (m->nwav[1]); j++) {
xx[j] = XSPECT_WL(m->wl_short[1], m->wl_long[1], m->nwav[1], j);
}
printf("orig upsampled + smoothed hires emis_coef:\n");
do_plot6(xx, old_emis, m->emis_coef[1], NULL, NULL, NULL, NULL, m->nwav[1]);
free_dvector(xx, 0, m->nwav[1]);
}
free(old_emis);
free(targ_smth);
#endif /* HIGH_RES_PLOT */
free(fudge);
free(lincal);
m->emis_hr_cal = 1; /* We don't have to do a reflective calibration */
/* Make sure these are updated */
if ((ev = i1pro_create_hr_calfactors(p, 1)) != I1PRO_OK)
return ev;
}
#endif /* HIGH_RES */
if (white_ref0 == NULL) { /* transmission white reference */
double avgwh = 0.0;
/* Compute average white reference reading */
for (j = 0; j < m->nwav[0]; j++)
avgwh += white_read0[j];
avgwh /= (double)m->nwav[0];
/* For each wavelength */
for (j = 0; j < m->nwav[0]; j++) {
/* If reference is < 0.4% of average */
if (white_read0[j]/avgwh < 0.004) {
cal_factor0[j] = 1.0/(0.004 * avgwh);
warn = I1PRO_RD_TRANSWHITEWARN;
} else {
cal_factor0[j] = 1.0/white_read0[j];
}
}
} else { /* Reflection white reference */
/* For each wavelength */
for (j = 0; j < m->nwav[0]; j++) {
if (white_read0[j] < 1000.0)
cal_factor0[j] = white_ref0[j]/1000.0;
else
cal_factor0[j] = white_ref0[j]/white_read0[j];
}
}
#ifdef HIGH_RES
if (m->hr_inited == 0)
return warn;
if (white_ref1 == NULL) { /* transmission white reference */
double avgwh = 0.0;
/* Compute average white reference reading */
for (j = 0; j < m->nwav[1]; j++)
avgwh += white_read1[j];
avgwh /= (double)m->nwav[1];
/* For each wavelength */
for (j = 0; j < m->nwav[1]; j++) {
/* If reference is < 0.4% of average */
if (white_read1[j]/avgwh < 0.004) {
cal_factor1[j] = 1.0/(0.004 * avgwh);
warn = I1PRO_RD_TRANSWHITEWARN;
} else {
cal_factor1[j] = 1.0/white_read1[j];
}
}
} else { /* Reflection white reference */
/* For each wavelength */
for (j = 0; j < m->nwav[1]; j++) {
if (white_read1[j] < 1000.0)
cal_factor1[j] = white_ref1[j]/1000.0;
else
cal_factor1[j] = white_ref1[j]/white_read1[j];
}
#endif /* HIGH_RES */
}
return warn;
}
/* For adaptive mode, compute a new integration time and gain mode */
/* in order to optimise the sensor values. Note that the Rev E doesn't have */
/* a high gain mode. */
i1pro_code i1pro_optimise_sensor(
i1pro *p,
double *pnew_int_time,
int *pnew_gain_mode,
double cur_int_time,
int cur_gain_mode,
int permithg, /* nz to permit switching to high gain mode */
int permitclip, /* nz to permit clipping out of range int_time, else error */
double targoscale, /* Optimising target scale ( <= 1.0) */
double scale /* scale needed of current int time to reach optimum */
) {
i1pro_code ev = I1PRO_OK;
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
double new_int_time;
int new_gain_mode;
a1logd(p->log,3,"i1pro_optimise_sensor called, inttime %f, gain mode %d, targ scale %f, scale %f\n",cur_int_time,cur_gain_mode, targoscale, scale);
/* Compute new normal gain integration time */
if (cur_gain_mode) /* If high gain */
new_int_time = cur_int_time * scale * m->highgain;
else
new_int_time = cur_int_time * scale;
new_gain_mode = 0;
a1logd(p->log,3,"target inttime %f, gain mode %d\n",new_int_time,new_gain_mode);
/* Adjust to low light situation by increasing the integration time. */
if (new_int_time > s->targmaxitime) { /* Exceeding target integration time */
if (s->targmaxitime/new_int_time > s->targoscale2) { /* But within range */
/* Compromise sensor target value to maintain targmaxitime */
new_int_time = s->targmaxitime;
a1logd(p->log,3,"Using targmaxitime with compromise sensor target\n");
} else {
/* Target reduced sensor value to give improved measurement time and continuity */
new_int_time *= s->targoscale2;
a1logd(p->log,3,"Using compromse sensor target\n");
}
#ifdef USE_HIGH_GAIN_MODE
/* !! Should change this so that it doesn't affect int. time, */
/* but that we simply switch to high gain mode when the */
/* expected level is < target_level/gain */
/* Hmm. It may not be a good idea to use high gain mode if it compromises */
/* the longer integration time which reduces noise. */
if (p->itype != instI1Pro2 && new_int_time > m->max_int_time && permithg) {
new_int_time /= m->highgain;
new_gain_mode = 1;
a1logd(p->log,3,"Switching to high gain mode\n");
}
#endif
}
a1logd(p->log,3,"after low light adjust, inttime %f, gain mode %d\n",new_int_time,new_gain_mode);
/* Deal with still low light */
if (new_int_time > m->max_int_time) {
if (permitclip)
new_int_time = m->max_int_time;
else
return I1PRO_RD_LIGHTTOOLOW;
}
a1logd(p->log,3,"after low light clip, inttime %f, gain mode %d\n",new_int_time,new_gain_mode);
/* Adjust to high light situation */
if (new_int_time < m->min_int_time && targoscale < 1.0) {
new_int_time /= targoscale; /* Aim for non-scaled sensor optimum */
if (new_int_time > m->min_int_time) /* But scale as much as possible */
new_int_time = m->min_int_time;
}
a1logd(p->log,3,"after high light adjust, inttime %f, gain mode %d\n",new_int_time,new_gain_mode);
/* Deal with still high light */
if (new_int_time < m->min_int_time) {
if (permitclip)
new_int_time = m->min_int_time;
else
return I1PRO_RD_LIGHTTOOHIGH;
}
a1logd(p->log,3,"after high light clip, returning inttime %f, gain mode %d\n",new_int_time,new_gain_mode);
if (pnew_int_time != NULL)
*pnew_int_time = new_int_time;
if (pnew_gain_mode != NULL)
*pnew_gain_mode = new_gain_mode;
return I1PRO_OK;
}
/* Compute the number of measurements needed, given the target */
/* measurement time and integration time. Will return 0 if target time is 0 */
int i1pro_comp_nummeas(
i1pro *p,
double meas_time,
double int_time
) {
int nmeas;
if (meas_time <= 0.0)
return 0;
nmeas = (int)floor(meas_time/int_time + 0.5);
if (nmeas < 1)
nmeas = 1;
return nmeas;
}
/* Convert the dark interpolation data to a useful state */
/* (also allow for interpolating the shielded cell values) */
void
i1pro_prepare_idark(
i1pro *p
) {
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
int i, j;
/* For normal and high gain */
for (i = 0; i < 4; i+= 2) {
for (j = -1; j < m->nraw; j++) {
double d01, d1;
d01 = s->idark_data[i+0][j] * s->idark_int_time[i+0];
d1 = s->idark_data[i+1][j] * s->idark_int_time[i+1];
/* Compute increment */
s->idark_data[i+1][j] = (d1 - d01)/(s->idark_int_time[i+1] - s->idark_int_time[i+0]);
/* Compute base */
s->idark_data[i+0][j] = d01 - s->idark_data[i+1][j] * s->idark_int_time[i+0];
}
if (p->itype == instI1Pro2) /* Rev E doesn't have high gain mode */
break;
}
}
/* Create the dark reference for the given integration time and gain */
/* by interpolating from the 4 readings taken earlier. */
i1pro_code
i1pro_interp_dark(
i1pro *p,
double *result, /* Put result of interpolation here */
double inttime,
int gainmode
) {
i1proimp *m = (i1proimp *)p->m;
i1pro_state *s = &m->ms[m->mmode];
int i, j;
if (!s->idark_valid)
return I1PRO_INT_NOTCALIBRATED;
i = 0;
#ifdef USE_HIGH_GAIN_MODE
if (gainmode)
i = 2;
#endif
for (j = -1; j < m->nraw; j++) {
double tt;
tt = s->idark_data[i+0][j] + inttime * s->idark_data[i+1][j];
tt /= inttime;
result[j] = tt;
}
return I1PRO_OK;
}
/* Set the noinitcalib mode */
void i1pro_set_noinitcalib(i1pro *p, int v, int losecs) {
i1proimp *m = (i1proimp *)p->m;
/* Ignore disabling init calib if more than losecs since instrument was open */
if (v && losecs != 0 && m->lo_secs >= losecs) {
a1logd(p->log,3,"initcalib disable ignored because %d >= %d secs\n",m->lo_secs,losecs);
return;
}
m->noinitcalib = v;
}
/* Set the trigger config */
void i1pro_set_trig(i1pro *p, inst_opt_type trig) {
i1proimp *m = (i1proimp *)p->m;
m->trig = trig;
}
/* Return the trigger config */
inst_opt_type i1pro_get_trig(i1pro *p) {
i1proimp *m = (i1proimp *)p->m;
return m->trig;
}
/* Switch thread handler */
int i1pro_switch_thread(void *pp) {
int nfailed = 0;
i1pro *p = (i1pro *)pp;
i1proimp *m = (i1proimp *)p->m;
i1pro_code rv = I1PRO_OK;
a1logd(p->log,3,"Switch thread started\n");
// for (nfailed = 0;nfailed < 5;)
/* Try indefinitely, in case instrument is put to sleep */
for (;;) {
rv = i1pro_waitfor_switch_th(p, SW_THREAD_TIMEOUT);
a1logd(p->log,8,"Switch handler triggered with rv %d, th_term %d\n",rv,m->th_term);
if (m->th_term) {
m->th_termed = 1;
break;
}
if (rv == I1PRO_INT_BUTTONTIMEOUT) {
nfailed = 0;
continue;
}
if (rv != I1PRO_OK) {
nfailed++;
a1logd(p->log,3,"Switch thread failed with 0x%x\n",rv);
continue;
}
m->switch_count++;
if (!m->hide_switch && p->eventcallback != NULL) {
p->eventcallback(p->event_cntx, inst_event_switch);
}
}
a1logd(p->log,3,"Switch thread returning\n");
return rv;
}
/* ============================================================ */
/* Low level i1pro commands */
/* USB Instrument commands */
/* Reset the instrument */
i1pro_code
i1pro_reset(
i1pro *p,
int mask /* reset mask ?. Known values ar 0x1f, 0x07, 0x01 */
/* 0x1f = normal resent */
/* 0x01 = establish high power mode */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[2]; /* 1 or 2 bytes to write */
int len = 1; /* Message length */
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_reset: reset with mask 0x%02x @ %d msec\n",
mask,(stime = msec_time()) - m->msec);
pbuf[0] = mask;
if (p->itype == instI1Pro2) {
pbuf[1] = 0; /* Not known what i1pro2 second byte is for */
len = 2;
}
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xCA, 0, 0, pbuf, len, 2.0);
rv = icoms2i1pro_err(se);
a1logd(p->log,2,"i1pro_reset: complete, ICOM err 0x%x (%d msec)\n",se,msec_time()-stime);
/* Allow time for hardware to stabalize */
msec_sleep(100);
/* Make sure that we re-initialize the measurement mode */
m->c_intclocks = 0;
m->c_lampclocks = 0;
m->c_nummeas = 0;
m->c_measmodeflags = 0;
return rv;
}
/* Read from the EEProm */
i1pro_code
i1pro_readEEProm(
i1pro *p,
unsigned char *buf, /* Where to read it to */
int addr, /* Address in EEprom to read from */
int size /* Number of bytes to read (max 65535) */
) {
i1proimp *m = (i1proimp *)p->m;
int rwbytes; /* Data bytes read or written */
unsigned char pbuf[8]; /* Write EEprom parameters */
int len = 8; /* Message length */
int se, rv = I1PRO_OK;
int stime;
if (size >= 0x10000)
return I1PRO_INT_EETOOBIG;
a1logd(p->log,2,"i1pro_readEEProm: address 0x%x size 0x%x @ %d msec\n",
addr, size, (stime = msec_time()) - m->msec);
int2buf(&pbuf[0], addr);
short2buf(&pbuf[4], size);
pbuf[6] = pbuf[7] = 0; /* Ignored */
if (p->itype == instI1Pro2)
len = 6;
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xC4, 0, 0, pbuf, len, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_readEEProm: read failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
/* Now read the bytes */
se = p->icom->usb_read(p->icom, NULL, 0x82, buf, size, &rwbytes, 5.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_readEEProm: read failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
if (rwbytes != size) {
a1logd(p->log,1,"i1pro_readEEProm: 0x%x bytes, short read error\n",rwbytes);
return I1PRO_HW_EE_SHORTREAD;
}
if (p->log->debug >= 7) {
int i;
char oline[100], *bp = oline;
for (i = 0; i < size; i++) {
if ((i % 16) == 0)
bp += sprintf(bp," %04x:",i);
bp += sprintf(bp," %02x",buf[i]);
if ((i+1) >= size || ((i+1) % 16) == 0) {
bp += sprintf(bp,"\n");
a1logd(p->log,7,oline);
bp = oline;
}
}
}
a1logd(p->log,2,"i1pro_readEEProm: 0x%x bytes, ICOM err 0x%x (%d msec)\n",
rwbytes, se, msec_time()-stime);
return rv;
}
/* Write to the EEProm */
i1pro_code
i1pro_writeEEProm(
i1pro *p,
unsigned char *buf, /* Where to write from */
int addr, /* Address in EEprom to write to */
int size /* Number of bytes to write (max 65535) */
) {
i1proimp *m = (i1proimp *)p->m;
int rwbytes; /* Data bytes read or written */
unsigned char pbuf[8]; /* Write EEprom parameters */
int len = 8; /* Message length */
int se = 0, rv = I1PRO_OK;
int i;
int stime;
/* Don't write over fixed values, as the instrument could become unusable.. */
if (addr < 0 || addr > 0x1000 || (addr + size) >= 0x1000)
return I1PRO_INT_EETOOBIG;
a1logd(p->log,2,"i1pro_writeEEProm: address 0x%x size 0x%x @ %d msec\n",
addr,size, (stime = msec_time()) - m->msec);
if (p->log->debug >= 6) {
int i;
char oline[100], *bp = oline;
for (i = 0; i < size; i++) {
if ((i % 16) == 0)
bp += sprintf(bp," %04x:",i);
bp += sprintf(bp," %02x",buf[i]);
if ((i+1) >= size || ((i+1) % 16) == 0) {
bp += sprintf(bp,"\n");
a1logd(p->log,6,oline);
bp = oline;
}
}
}
#ifdef ENABLE_WRITE
int2buf(&pbuf[0], addr);
short2buf(&pbuf[4], size);
short2buf(&pbuf[6], 0x100); /* Might be accidental, left over from getmisc.. */
if (p->itype == instI1Pro2)
len = 6;
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xC3, 0, 0, pbuf, len, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_writeEEProm: write failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
/* Now write the bytes */
se = p->icom->usb_write(p->icom, NULL, 0x03, buf, size, &rwbytes, 5.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_writeEEProm: failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
if (rwbytes != size) {
a1logd(p->log,1,"i1pro_writeEEProm: 0x%x bytes, short write error\n",rwbytes);
return I1PRO_HW_EE_SHORTWRITE;
}
/* Now we write two separate bytes of 0 - confirm write ?? */
for (i = 0; i < 2; i++) {
pbuf[0] = 0;
/* Now write the bytes */
se = p->icom->usb_write(p->icom, NULL, 0x03, pbuf, 1, &rwbytes, 5.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_writeEEProm: write failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
if (rwbytes != 1) {
a1logd(p->log,1,"i1pro_writeEEProm: 0x%x bytes, short write error\n",rwbytes);
return I1PRO_HW_EE_SHORTWRITE;
}
}
a1logd(p->log,2,"i1pro_writeEEProm: 0x%x bytes, ICOM err 0x%x (%d msec)\n",
size, se, msec_time()-stime);
/* The instrument needs some recovery time after a write */
msec_sleep(50);
#else /* ENABLE_WRITE */
a1logd(p->log,2,"i1pro_writeEEProm: (NOT) 0x%x bytes, ICOM err 0x%x\n",size, se);
#endif /* ENABLE_WRITE */
return rv;
}
/* Get the miscellaneous status */
/* return pointers may be NULL if not needed. */
i1pro_code
i1pro_getmisc(
i1pro *p,
int *fwrev, /* Return the hardware version number */
int *unkn1, /* Unknown status, set after doing a measurement */
int *maxpve, /* Maximum positive value in sensor readings */
int *unkn3, /* Unknown status, usually 1 */
int *powmode /* 0 = high power mode, 8 = low power mode */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[8]; /* status bytes read */
int _fwrev;
int _unkn1;
int _maxpve;
int _unkn3;
int _powmode;
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_getmisc: @ %d msec\n",(stime = msec_time()) - m->msec);
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_IN | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xC9, 0, 0, pbuf, 8, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_getmisc: failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
_fwrev = buf2ushort(&pbuf[0]);
_unkn1 = buf2ushort(&pbuf[2]); /* Value set after each read. Average ?? */
_maxpve = buf2ushort(&pbuf[4]);
_unkn3 = pbuf[6]; /* Flag values are tested, but don't seem to be used ? */
_powmode = pbuf[7];
a1logd(p->log,2,"i1pro_getmisc: returning %d, 0x%04x, 0x%04x, 0x%02x, 0x%02x ICOM err 0x%x (%d msec)\n",
_fwrev, _unkn1, _maxpve, _unkn3, _powmode, se, msec_time()-stime);
if (fwrev != NULL) *fwrev = _fwrev;
if (unkn1 != NULL) *unkn1 = _unkn1;
if (maxpve != NULL) *maxpve = _maxpve;
if (unkn3 != NULL) *unkn3 = _unkn3;
if (powmode != NULL) *powmode = _powmode;
return rv;
}
/* Get the current measurement parameters */
/* Return pointers may be NULL if not needed. */
i1pro_code
i1pro_getmeasparams(
i1pro *p,
int *intclocks, /* Number of integration clocks */
int *lampclocks, /* Number of lamp turn on sub-clocks */
int *nummeas, /* Number of measurements */
int *measmodeflags /* Measurement mode flags */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[8]; /* status bytes read */
int _intclocks;
int _lampclocks;
int _nummeas;
int _measmodeflags;
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_getmeasparams: @ %d msec\n", (stime = msec_time()) - m->msec);
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_IN | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xC2, 0, 0, pbuf, 8, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_getmeasparams: failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
_intclocks = buf2ushort(&pbuf[0]);
_lampclocks = buf2ushort(&pbuf[2]);
_nummeas = buf2ushort(&pbuf[4]);
_measmodeflags = pbuf[6];
a1logd(p->log,2,"i1pro_getmeasparams: returning %d, %d, %d, 0x%02x ICOM err 0x%x (%d msec)\n",
_intclocks, _lampclocks, _nummeas, _measmodeflags, se, msec_time()-stime);
if (intclocks != NULL) *intclocks = _intclocks;
if (lampclocks != NULL) *lampclocks = _lampclocks;
if (nummeas != NULL) *nummeas = _nummeas;
if (measmodeflags != NULL) *measmodeflags = _measmodeflags;
return rv;
}
/* Set the current measurement parameters */
/* Return pointers may be NULL if not needed. */
/* Quirks:
Rev. A upgrade:
Rev. B:
Appears to have a bug where the measurement time
is the sum of the previous measurement plus the current measurement.
It doesn't seem to alter the integration time though.
There is no obvious way of fixing this (ie. reseting the instrument
doesn't work).
Rev. D:
It appears that setting intclocks to 0, toggles to/from
a half clock speed mode. (?)
*/
i1pro_code
i1pro_setmeasparams(
i1pro *p,
int intclocks, /* Number of integration clocks */
int lampclocks, /* Number of lamp turn on sub-clocks */
int nummeas, /* Number of measurements */
int measmodeflags /* Measurement mode flags */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[8]; /* command bytes written */
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_setmeasparams: %d, %d, %d, 0x%02x @ %d msec\n",
intclocks, lampclocks, nummeas, measmodeflags,
(stime = msec_time()) - m->msec);
short2buf(&pbuf[0], intclocks);
short2buf(&pbuf[2], lampclocks);
short2buf(&pbuf[4], nummeas);
pbuf[6] = measmodeflags;
pbuf[7] = 0;
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xC1, 0, 0, pbuf, 8, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_setmeasparams: failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
a1logd(p->log,2,"i1pro_setmeasparams: returning ICOM err 0x%x (%d msec)\n",
se,msec_time()-stime);
return rv;
}
/* Delayed trigger implementation, called from thread */
static int
i1pro_delayed_trigger(void *pp) {
i1pro *p = (i1pro *)pp;
i1proimp *m = (i1proimp *)p->m;
int se, rv = I1PRO_OK;
int stime = 0;
if ((m->c_measmodeflags & I1PRO_MMF_NOLAMP) == 0) { /* Lamp will be on for measurement */
m->llampoffon = msec_time(); /* Record when it turned on */
// printf("~1 got lamp off -> on at %d (%f)\n",m->llampoffon, (m->llampoffon - m->llamponoff)/1000.0);
}
a1logd(p->log,2,"i1pro_delayed_trigger: start sleep @ %d msec\n", msec_time() - m->msec);
#ifdef USE_RD_SYNC
p->icom->usb_wait_io(p->icom, &m->rd_sync); /* Wait for read to start */
#else
/* Delay the trigger */
msec_sleep(m->trig_delay);
#endif
m->tr_t1 = msec_time(); /* Diagnostic */
a1logd(p->log,2,"i1pro_delayed_trigger: trigger @ %d msec\n",(stime = msec_time()) - m->msec);
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xC0, 0, 0, NULL, 0, 2.0);
m->trigstamp = usec_time();
m->tr_t2 = msec_time(); /* Diagnostic */
m->trig_se = se;
m->trig_rv = icoms2i1pro_err(se);
a1logd(p->log,2,"i1pro_delayed_trigger: returning ICOM err 0x%x (%d msec)\n",
se,msec_time()-stime);
return 0;
}
/* Trigger a measurement after the nominated delay */
/* The actual return code will be in m->trig_rv after the delay. */
/* This allows us to start the measurement read before the trigger, */
/* ensuring that process scheduling latency can't cause the read to fail. */
i1pro_code
i1pro_triggermeasure(i1pro *p, int delay) {
i1proimp *m = (i1proimp *)p->m;
int rv = I1PRO_OK;
a1logd(p->log,2,"i1pro_triggermeasure: trigger after %dmsec delay @ %d msec\n",
delay, msec_time() - m->msec);
/* NOTE := would be better here to create thread once, and then trigger it */
/* using a condition variable. */
if (m->trig_thread != NULL) {
m->trig_thread->del(m->trig_thread);
m->trig_thread = NULL;
}
m->tr_t1 = m->tr_t2 = m->tr_t3 = m->tr_t4 = m->tr_t5 = m->tr_t6 = m->tr_t7 = 0;
m->trig_delay = delay;
if ((m->trig_thread = new_athread(i1pro_delayed_trigger, (void *)p)) == NULL) {
a1logd(p->log,1,"i1pro_triggermeasure: creating delayed trigger thread failed\n");
return I1PRO_INT_THREADFAILED;
}
#ifdef WAIT_FOR_DELAY_TRIGGER /* hack to diagnose threading problems */
while (m->tr_t2 == 0) {
Sleep(1);
}
#endif
a1logd(p->log,2,"i1pro_triggermeasure: scheduled triggering OK\n");
return rv;
}
/* Read a measurements results. */
/* A buffer full of bytes is returned. */
/* (This will fail on a Rev. A if there is more than about a 40 msec delay */
/* between triggering the measurement and starting this read. */
/* It appears that the read can be pending before triggering though. */
/* Scan reads will also terminate if there is too great a delay beteween each read.) */
static i1pro_code
i1pro_readmeasurement(
i1pro *p,
int inummeas, /* Initial number of measurements to expect */
int scanflag, /* NZ if in scan mode to continue reading */
unsigned char *buf, /* Where to read it to */
int bsize, /* Bytes available in buffer */
int *nummeas, /* Return number of readings measured */
i1p_mmodif mmodif /* Measurement modifier enum */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char *ibuf = buf; /* Incoming buffer */
int nmeas; /* Number of measurements for this read */
double top, extra; /* Time out period */
int rwbytes; /* Data bytes read or written */
int se, rv = I1PRO_OK;
int treadings = 0;
int stime = 0;
// int gotshort = 0; /* nz when got a previous short reading */
if ((bsize % (m->nsen * 2)) != 0) {
return I1PRO_INT_ODDREADBUF;
}
a1logd(p->log,2,"i1pro_readmeasurement: inummeas %d, scanflag %d, address %p bsize 0x%x "
"@ %d msec\n",inummeas, scanflag, buf, bsize, (stime = msec_time()) - m->msec);
extra = 2.0; /* Extra timeout margin */
/* Deal with Rev A+ & Rev B quirk: */
if ((m->fwrev >= 200 && m->fwrev < 300)
|| (m->fwrev >= 300 && m->fwrev < 400))
extra += m->l_inttime;
m->l_inttime = m->c_inttime;
#ifdef SINGLE_READ
if (scanflag == 0)
nmeas = inummeas;
else
nmeas = bsize / (m->nsen * 2); /* Use a single large read */
#else
nmeas = inummeas; /* Smaller initial number of measurements */
#endif
top = extra + m->c_inttime * nmeas;
if ((m->c_measmodeflags & I1PRO_MMF_NOLAMP) == 0) /* Lamp is on */
top += m->c_lamptime;
/* NOTE :- for a scan on Rev. A, if we don't read fast enough the Eye-One will */
/* assume it should stop sending, even though the user has the switch pressed. */
/* For the rev A, this is quite a small margin (aprox. 1 msec ?) */
/* The Rev D has a lot more buffering, and is quite robust. */
/* By using the delayed trigger and a single read, this problem is usually */
/* eliminated. */
/* An unexpected short read seems to lock the instrument up. Not currently */
/* sure what sequence would recover it for a retry of the read. */
for (;;) {
int size; /* number of bytes to read */
size = m->nsen * 2 * nmeas;
if (size > bsize) { /* oops, no room for read */
a1logd(p->log,1,"i1pro_readmeasurement: buffer was too short for scan\n");
return I1PRO_INT_MEASBUFFTOOSMALL;
}
m->tr_t6 = msec_time(); /* Diagnostic, start of subsequent reads */
if (m->tr_t3 == 0) m->tr_t3 = m->tr_t6; /* Diagnostic, start of first read */
se = p->icom->usb_read(p->icom, &m->rd_sync, 0x82, buf, size, &rwbytes, top);
m->tr_t5 = m->tr_t7;
m->tr_t7 = msec_time(); /* Diagnostic, end of subsequent reads */
if (m->tr_t4 == 0) {
m->tr_t5 = m->tr_t2;
m->tr_t4 = m->tr_t7; /* Diagnostic, end of first read */
}
#ifdef NEVER /* Use short + timeout to terminate scan */
if (gotshort != 0 && se == ICOM_TO) { /* We got a timeout after a short read. */
a1logd(p->log,2,"i1pro_readmeasurement: timed out in %f secs after getting short read\n",top);
a1logd(p->log,2,"i1pro_readmeasurement: trig & rd times %d %d %d %d)\n",
m->tr_t2-m->tr_t1, m->tr_t3-m->tr_t2, m->tr_t4-m->tr_t3, m->tr_t6-m->tr_t5);
break; /* We're done */
} else
#endif
if (se == ICOM_SHORT) { /* Expect this to terminate scan reading */
a1logd(p->log,2,"i1pro_readmeasurement: short read, read %d bytes, asked for %d\n",
rwbytes,size);
a1logd(p->log,2,"i1pro_readmeasurement: trig & rd times %d %d %d %d)\n",
m->tr_t2-m->tr_t1, m->tr_t3-m->tr_t2, m->tr_t4-m->tr_t3, m->tr_t6-m->tr_t5);
} else if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
if (m->trig_rv != I1PRO_OK) {
a1logd(p->log,1,"i1pro_readmeasurement: trigger failed, ICOM err 0x%x\n",
m->trig_se);
return m->trig_rv;
}
if (se & ICOM_TO)
a1logd(p->log,1,"i1pro_readmeasurement: timed out with top = %f\n",top);
a1logd(p->log,1,"i1pro_readmeasurement: failed, bytes read 0x%x, ICOM err 0x%x\n",
rwbytes, se);
return rv;
}
/* If we didn't read a multiple of m->nsen * 2, we've got problems */
if ((rwbytes % (m->nsen * 2)) != 0) {
a1logd(p->log,1,"i1pro_readmeasurement: read 0x%x bytes, odd read error\n",rwbytes);
return I1PRO_HW_ME_ODDREAD;
}
/* Track where we're up to */
bsize -= rwbytes;
buf += rwbytes;
treadings += rwbytes/(m->nsen * 2);
if (scanflag == 0) { /* Not scanning */
/* Expect to read exactly what we asked for */
if (rwbytes != size) {
a1logd(p->log,1,"i1pro_readmeasurement: unexpected short read, got %d expected %d\n"
,rwbytes,size);
return I1PRO_HW_ME_SHORTREAD;
}
break; /* And we're done */
}
#ifdef NEVER /* Use short + timeout to terminate scan */
/* We expect to get a short read at the end of a scan, */
/* or we might have the USB transfer truncated by somethinge else. */
/* Note the short read, and keep reading until we get a time out */
if (rwbytes != size) {
gotshort = 1;
} else {
gotshort = 0;
}
#else /* Use short to terminate scan */
/* We're scanning and expect to get a short read at the end of the scan. */
if (rwbytes != size) {
break;
}
#endif
if (bsize == 0) { /* oops, no room for more scanning read */
unsigned char tbuf[NSEN_MAX * 2];
/* We need to clean up, so soak up all the data and throw it away */
while ((se = p->icom->usb_read(p->icom, NULL, 0x82, tbuf, m->nsen * 2, &rwbytes, top)) == ICOM_OK)
;
a1logd(p->log,1,"i1pro_readmeasurement: buffer was too short for scan\n");
return I1PRO_INT_MEASBUFFTOOSMALL;
}
/* Read a bunch more readings until the read is short or times out */
nmeas = bsize / (m->nsen * 2);
if (nmeas > 64)
nmeas = 64;
top = extra + m->c_inttime * nmeas;
}
if ((m->c_measmodeflags & I1PRO_MMF_NOLAMP) == 0) { /* Lamp was on for measurement */
m->slamponoff = m->llamponoff; /* remember second last */
m->llamponoff = msec_time(); /* Record when it turned off */
// printf("~1 got lamp on -> off at %d (%f)\n",m->llamponoff, (m->llamponoff - m->llampoffon)/1000.0);
m->lampage += (m->llamponoff - m->llampoffon)/1000.0; /* Time lamp was on */
}
/* Update log values */
if (mmodif != i1p_dark_cal)
m->meascount++;
/* Must have timed out in initial readings */
if (treadings < inummeas) {
a1logd(p->log,1,"i1pro_readmeasurement: read failed, bytes read 0x%x, ICOM err 0x%x\n",
rwbytes, se);
return I1PRO_RD_SHORTMEAS;
}
if (p->log->debug >= 6) {
int i, size = treadings * m->nsen * 2;
char oline[100], *bp = oline;
for (i = 0; i < size; i++) {
if ((i % 16) == 0)
bp += sprintf(bp," %04x:",i);
bp += sprintf(bp," %02x",ibuf[i]);
if ((i+1) >= size || ((i+1) % 16) == 0) {
bp += sprintf(bp,"\n");
a1logd(p->log,6,oline);
bp = oline;
}
}
}
a1logd(p->log,2,"i1pro_readmeasurement: read %d readings, ICOM err 0x%x (%d msec)\n",
treadings, se, msec_time()-stime);
a1logd(p->log,2,"i1pro_readmeasurement: (trig & rd times %d %d %d %d)\n",
m->tr_t2-m->tr_t1, m->tr_t3-m->tr_t2, m->tr_t4-m->tr_t3, m->tr_t6-m->tr_t5);
if (nummeas != NULL) *nummeas = treadings;
return rv;
}
/* Set the measurement clock mode */
/* Firmware Version >= 301 only */
i1pro_code
i1pro_setmcmode(
i1pro *p,
int mcmode /* Measurement clock mode, 1..mxmcmode */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[1]; /* 1 bytes to write */
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_setmcmode: mode %d @ %d msec\n",
mcmode, (stime = msec_time()) - m->msec);
pbuf[0] = mcmode;
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xCF, 0, 0, pbuf, 1, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_setmcmode: failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
/* Hmm. Give the instrument a little time to reconfigure itself. */
/* (Probably needs about 1msec, but err on the safe side) */
msec_sleep(10);
a1logd(p->log,2,"i1pro_setmcmode: done, ICOM err 0x%x (%d msec)\n",
se, msec_time()-stime);
return rv;
}
/* Get the current measurement clock mode */
/* Return pointers may be NULL if not needed. */
/* Firmware Version >= 301 only */
i1pro_code
i1pro_getmcmode(
i1pro *p,
int *maxmcmode, /* mcmode must be <= maxmcmode */
int *mcmode, /* readback current mcmode */
int *subclkdiv, /* Sub clock divider ratio */
int *intclkusec, /* Integration clock in usec */
int *subtmode /* Subtract mode on read using average of value 127 */
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[8]; /* status bytes read */
int _maxmcmode; /* mcmode must be < maxmcmode */
int _mcmode; /* readback current mcmode */
int _unknown; /* Unknown */
int _subclkdiv; /* Sub clock divider ratio */
int _intclkusec; /* Integration clock in usec */
int _subtmode; /* Subtract mode on read using average of value 127 */
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_getmcmode: called @ %d msec\n",
(stime = msec_time()) - m->msec);
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_IN | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD1, 0, 0, pbuf, 6, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_getmcmode: failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
_maxmcmode = pbuf[0];
_mcmode = pbuf[1];
_unknown = pbuf[2];
_subclkdiv = pbuf[3];
_intclkusec = pbuf[4];
_subtmode = pbuf[5];
a1logd(p->log,2,"i1pro_getmcmode: returns %d, %d, (%d), %d, %d 0x%x ICOM err 0x%x (%d msec)\n",
_maxmcmode, _mcmode, _unknown, _subclkdiv, _intclkusec, _subtmode, se, msec_time()-stime);
if (maxmcmode != NULL) *maxmcmode = _maxmcmode;
if (mcmode != NULL) *mcmode = _mcmode;
if (subclkdiv != NULL) *subclkdiv = _subclkdiv;
if (intclkusec != NULL) *intclkusec = _intclkusec;
if (subtmode != NULL) *subtmode = _subtmode;
return rv;
}
/* Wait for a reply triggered by an instrument switch press */
i1pro_code i1pro_waitfor_switch(i1pro *p, double top) {
i1proimp *m = (i1proimp *)p->m;
int rwbytes; /* Data bytes read */
unsigned char buf[8]; /* Result */
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_waitfor_switch: read 1 byte from switch hit port @ %d msec\n",
(stime = msec_time()) - m->msec);
/* Now read 1 byte */
se = p->icom->usb_read(p->icom, NULL, 0x84, buf, 1, &rwbytes, top);
if (se & ICOM_TO) {
a1logd(p->log,2,"i1pro_waitfor_switch: read 0x%x bytes, timed out (%d msec)\n",
rwbytes,msec_time()-stime);
return I1PRO_INT_BUTTONTIMEOUT;
}
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro_waitfor_switch: failed with ICOM err 0x%x (%d msec)\n",se, msec_time()-stime);
return rv;
}
if (rwbytes != 1) {
a1logd(p->log,1,"i1pro_waitfor_switch: read 0x%x bytes, short read error (%d msec)\n",
rwbytes,msec_time()-stime);
return I1PRO_HW_SW_SHORTREAD;
}
a1logd(p->log,2,"i1pro_waitfor_switch: read 0x%x bytes value 0x%x ICOM err 0x%x (%d msec)\n",
rwbytes, buf[0], se, msec_time()-stime);
return rv;
}
/* Wait for a reply triggered by a key press (thread version) */
/* Returns I1PRO_OK if the switch has been pressed, */
/* or I1PRO_INT_BUTTONTIMEOUT if */
/* no switch was pressed befor the time expired, */
/* or some other error. */
i1pro_code i1pro_waitfor_switch_th(i1pro *p, double top) {
i1proimp *m = (i1proimp *)p->m;
int rwbytes; /* Data bytes read */
unsigned char buf[8]; /* Result */
int se, rv = I1PRO_OK;
int stime = 0;
a1logd(p->log,2,"i1pro_waitfor_switch_th: read 1 byte from switch hit port @ %d msec\n",
(stime = msec_time()) - m->msec);
/* Now read 1 byte */
se = p->icom->usb_read(p->icom, &m->sw_cancel, 0x84, buf, 1, &rwbytes, top);
if (se & ICOM_TO) {
a1logd(p->log,2,"i1pro_waitfor_switch_th: read 0x%x bytes, timed out (%d msec)\n",
rwbytes,msec_time()-stime);
return I1PRO_INT_BUTTONTIMEOUT;
}
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_waitfor_switch_th: failed with ICOM err 0x%x (%d msec)\n",
se,msec_time()-stime);
return rv;
}
if (rwbytes != 1) {
a1logd(p->log,2,"i1pro_waitfor_switch_th: read 0x%x bytes, short read error (%d msec)\n",
rwbytes,msec_time()-stime);
return I1PRO_HW_SW_SHORTREAD;
}
a1logd(p->log,2,"i1pro_waitfor_switch_th: read 0x%x bytes value 0x%x ICOM err 0x%x (%d msec)\n",
rwbytes, buf[0], se,msec_time()-stime);
return rv;
}
/* Terminate switch handling */
/* This seems to always return an error ? */
i1pro_code
i1pro_terminate_switch(
i1pro *p
) {
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[8]; /* 8 bytes to write */
int se, rv = I1PRO_OK;
a1logd(p->log,2,"i1pro_terminate_switch: called\n");
/* These values may not be significant */
pbuf[0] = pbuf[1] = pbuf[2] = pbuf[3] = 0xff;
pbuf[4] = 0xfc;
pbuf[5] = 0xee;
pbuf[6] = 0x12;
pbuf[7] = 0x00;
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD0, 3, 0, pbuf, 8, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,2,"i1pro_terminate_switch: Warning: Terminate Switch Handling failed with ICOM err 0x%x\n",se);
} else {
a1logd(p->log,2,"i1pro_terminate_switch: done, ICOM err 0x%x\n",se);
}
/* In case the above didn't work, cancel the I/O */
msec_sleep(50);
if (m->th_termed == 0) {
a1logd(p->log,3,"i1pro terminate switch thread failed, canceling I/O\n");
p->icom->usb_cancel_io(p->icom, &m->sw_cancel);
}
return rv;
}
/* ============================================================ */
/* Low level i1pro2 (Rev E) commands */
/* Get the EEProm size */
i1pro_code
i1pro2_geteesize(
i1pro *p,
int *eesize
) {
int se, rv = I1PRO_OK;
unsigned char buf[4]; /* Result */
int _eesize = 0;
a1logd(p->log,2,"i1pro2_geteesize: called\n");
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_IN | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD9, 0, 0, buf, 4, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro2_geteesize: failed with ICOM err 0x%x\n",se);
return rv;
}
_eesize = buf2int(buf);
a1logd(p->log,2,"i1pro2_geteesize: returning %d ICOM err 0x%x\n", _eesize, se);
if (eesize != NULL)
*eesize = _eesize;
return rv;
}
/* Get the Chip ID */
/* This does actually work with the Rev D. */
/* (It returns all zero's unless you've read the EEProm first !) */
i1pro_code
i1pro2_getchipid(
i1pro *p,
unsigned char chipid[8]
) {
int se, rv = I1PRO_OK;
a1logd(p->log,2,"i1pro2_getchipid: called\n");
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_IN | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD2, 0, 0, chipid, 8, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro2_getchipid: failed with ICOM err 0x%x\n",se);
return rv;
}
a1logd(p->log,2,"i1pro2_getchipid: returning %02X-%02X%02X%02X%02X%02X%02X%02X ICOM err 0x%x\n",
chipid[0], chipid[1], chipid[2], chipid[3],
chipid[4], chipid[5], chipid[6], chipid[7], se);
return rv;
}
/* Get Rev E measure characteristics. */
i1pro_code
i1pro2_getmeaschar(
i1pro *p,
int *clkusec, /* Return integration clock length in usec ? (ie. 36) */
int *xraw, /* Return number of extra non-reading (dark) raw bands ? (ie. 6) */
int *nraw, /* Return number of reading raw bands ? (ie. 128) */
int *subdiv /* Sub divider and minium integration clocks ? (ie. 136) */
) {
int se, rv = I1PRO_OK;
unsigned char buf[16]; /* Result */
int _clkusec;
int _xraw;
int _nraw;
int _subdiv;
a1logd(p->log,2,"i1pro2_getmeaschar: called\n");
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_IN | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD5, 0, 0, buf, 16, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro2_getmeaschar: failed with ICOM err 0x%x\n",se);
return rv;
}
_clkusec = buf2int(buf + 0);
_xraw = buf2int(buf + 4);
_nraw = buf2int(buf + 8);
_subdiv = buf2int(buf + 12);
a1logd(p->log,2,"i1pro2_getmeaschar: returning clkusec %d, xraw %d, nraw %d, subdiv %d ICOM err 0x%x\n", _clkusec, _xraw, _nraw, _subdiv, se);
if (clkusec != NULL)
*clkusec = _clkusec;
if (xraw != NULL)
*xraw = _xraw;
if (nraw != NULL)
*nraw = _nraw;
if (subdiv != NULL)
*subdiv = _subdiv;
return rv;
}
/* Delayed trigger implementation, called from thread */
/* We assume that the Rev E measurement parameters have been set in */
/* the i1proimp structure c_* values */
static int
i1pro2_delayed_trigger(void *pp) {
i1pro *p = (i1pro *)pp;
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[14]; /* 14 bytes to write */
int se, rv = I1PRO_OK;
int stime = 0;
int2buf(pbuf + 0, m->c_intclocks);
int2buf(pbuf + 4, m->c_lampclocks);
int2buf(pbuf + 8, m->c_nummeas);
short2buf(pbuf + 12, m->c_measmodeflags2);
if ((m->c_measmodeflags & I1PRO_MMF_NOLAMP) == 0) { /* Lamp will be on for measurement */
m->llampoffon = msec_time(); /* Record when it turned on */
}
a1logd(p->log,2,"i1pro2_delayed_trigger: Rev E start sleep @ %d msec\n",
msec_time() - m->msec);
#ifdef USE_RD_SYNC
p->icom->usb_wait_io(p->icom, &m->rd_sync); /* Wait for read to start */
#else
/* Delay the trigger */
msec_sleep(m->trig_delay);
#endif
m->tr_t1 = msec_time(); /* Diagnostic */
a1logd(p->log,2,"i1pro2_delayed_trigger: trigger Rev E @ %d msec\n",
(stime = msec_time()) - m->msec);
m->trigstamp = usec_time();
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD4, 0, 0, pbuf, 14, 2.0);
m->tr_t2 = msec_time(); /* Diagnostic */
m->trig_se = se;
m->trig_rv = icoms2i1pro_err(se);
a1logd(p->log,2,"i1pro2_delayed_trigger: done ICOM err 0x%x (%d msec)\n",
se,msec_time()-stime);
return 0;
}
/* Trigger a measurement after the nominated delay */
/* The actual return code will be in m->trig_rv after the delay. */
/* This allows us to start the measurement read before the trigger, */
/* ensuring that process scheduling latency can't cause the read to fail. */
i1pro_code
i1pro2_triggermeasure(i1pro *p, int delay) {
i1proimp *m = (i1proimp *)p->m;
int rv = I1PRO_OK;
a1logd(p->log,2,"i1pro2_triggermeasure: triggering Rev E measurement after %dmsec "
"delay @ %d msec\n", delay, msec_time() - m->msec);
/* NOTE := would be better here to create thread once, and then trigger it */
/* using a condition variable. */
if (m->trig_thread != NULL)
m->trig_thread->del(m->trig_thread);
m->tr_t1 = m->tr_t2 = m->tr_t3 = m->tr_t4 = m->tr_t5 = m->tr_t6 = m->tr_t7 = 0;
m->trig_delay = delay;
if ((m->trig_thread = new_athread(i1pro2_delayed_trigger, (void *)p)) == NULL) {
a1logd(p->log,1,"i1pro2_triggermeasure: creating delayed trigger Rev E thread failed\n");
return I1PRO_INT_THREADFAILED;
}
#ifdef WAIT_FOR_DELAY_TRIGGER /* hack to diagnose threading problems */
while (m->tr_t2 == 0) {
Sleep(1);
}
#endif
a1logd(p->log,2,"i1pro2_triggermeasure: scheduled triggering Rev E OK\n");
return rv;
}
/* Get the UV before and after measurement voltage drop */
i1pro_code
i1pro2_getUVvolts(
i1pro *p,
int *before,
int *after
) {
int se, rv = I1PRO_OK;
unsigned char buf[4]; /* Result */
int _before = 0;
int _after = 0;
a1logd(p->log,2,"i1pro2_getUVvolts: called\n");
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_IN | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD8, 0, 0, buf, 4, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro2_getUVvolts: failed with ICOM err 0x%x\n",se);
return rv;
}
_before = buf2ushort(buf);
_after = buf2ushort(buf+2);
a1logd(p->log,2,"i1pro2_getUVvolts: returning %d, %d ICOM err 0x%x\n", _before, _after, se);
if (before != NULL)
*before = _before;
if (after != NULL)
*after = _after;
return rv;
}
/* Terminate Ruler tracking (???) */
/* The parameter seems to be always 0 ? */
static int
i1pro2_stop_ruler(void *pp, int parm) {
i1pro *p = (i1pro *)pp;
i1proimp *m = (i1proimp *)p->m;
unsigned char pbuf[2]; /* 2 bytes to write */
int se, rv = I1PRO_OK;
short2buf(pbuf, parm);
a1logd(p->log,2,"i1pro2_stop_ruler: called with 0x%x\n", parm);
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD7, 0, 0, pbuf, 2, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro2_stop_ruler: failed with ICOM err 0x%x\n",rv);
return rv;
}
a1logd(p->log,2,"i1pro2_stop_ruler: returning ICOM err 0x%x\n",rv);
return rv;
}
/* Send a raw indicator LED sequence. */
/*
The byte sequence has the following format:
(all values are big endian)
XXXX Number of following blocks, BE.
Blocks are:
YYYY Number of bytes in the block
RRRR Number of repeats of the block, FFFFFFFF = infinite
A sequence of codes:
LL TTTT
L = Led mask:
01 = Red Right
02 = Green Right
04 = Blue Right
08 = Red Left
10 = Green Left
20 = Blue Left
TTT = clock count for this mask (ie. aprox. 73 usec clock period)
PWM typically alternates between on & off state with a period total of
0x50 clocks = 170 Hz. 255 clocks would be 54 Hz.
*/
static int
i1pro2_indLEDseq(void *pp, unsigned char *buf, int size) {
i1pro *p = (i1pro *)pp;
i1proimp *m = (i1proimp *)p->m;
int rwbytes; /* Data bytes written */
unsigned char pbuf[4]; /* Number of bytes being send */
int se, rv = I1PRO_OK;
int2buf(pbuf, size);
a1logd(p->log,2,"i1pro2_indLEDseq: length %d bytes\n", size);
se = p->icom->usb_control(p->icom,
IUSB_ENDPOINT_OUT | IUSB_REQ_TYPE_VENDOR | IUSB_REQ_RECIP_DEVICE,
0xD6, 0, 0, pbuf, 4, 2.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro2_indLEDseq: failed with ICOM err 0x%x\n",rv);
return rv;
}
a1logd(p->log,2,"i1pro2_geteesize: command got ICOM err 0x%x\n", se);
/* Now write the bytes */
se = p->icom->usb_write(p->icom, NULL, 0x03, buf, size, &rwbytes, 5.0);
if ((rv = icoms2i1pro_err(se)) != I1PRO_OK) {
a1logd(p->log,1,"i1pro2_indLEDseq: data write failed with ICOM err 0x%x\n",se);
return rv;
}
if (rwbytes != size) {
a1logd(p->log,1,"i1pro2_indLEDseq: wrote 0x%x bytes, short write error\n",rwbytes);
return I1PRO_HW_LED_SHORTWRITE;
}
a1logd(p->log,2,"i1pro2_indLEDseq: wrote 0x%x bytes LED sequence, ICOM err 0x%x\n", size, rv);
return rv;
}
/* Turn indicator LEDs off */
static int
i1pro2_indLEDoff(void *pp) {
i1pro *p = (i1pro *)pp;
int rv = I1PRO_OK;
unsigned char seq[] = {
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x07,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x10
};
a1logd(p->log,2,"i1pro2_indLEDoff: called\n");
rv = i1pro2_indLEDseq(p, seq, sizeof(seq));
a1logd(p->log,2,"i1pro2_indLEDoff: returning ICOM err 0x%x\n",rv);
return rv;
}
#ifdef NEVER
// ~~99 play with LED settings
if (p->itype == instI1Pro2) {
// LED is capable of white and red
/* Turns it off */
unsigned char b1[] = {
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x07,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01
};
/* Makes it white */
unsigned char b2[] = {
0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x0a,
0x00, 0x00, 0x00, 0x01,
0x00, 0x36, 0x00,
0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x0a,
0xff, 0xff, 0xff, 0xff,
0x3f, 0x36, 0x40,
0x00, 0x00, 0x01
};
/* Makes it pulsing white */
unsigned char b3[] = {
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x36, 0x40, 0x00,
0x00, 0x01, 0x00, 0x00, 0x08, 0xec, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x03, 0x00, 0x00, 0x50, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x50, 0x3f, 0x00, 0x03, 0x00,
0x00, 0x4d, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x45, 0x3f, 0x00,
0x03, 0x00, 0x00, 0x42, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x42, 0x3f, 0x00, 0x04, 0x00, 0x00, 0x4f,
0x3f, 0x00, 0x04, 0x00, 0x00, 0x4d, 0x3f, 0x00, 0x04, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x04, 0x00,
0x00, 0x46, 0x3f, 0x00, 0x04, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x04, 0x00, 0x00, 0x41, 0x3f, 0x00,
0x05, 0x00, 0x00, 0x4d, 0x3f, 0x00, 0x05, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x05, 0x00, 0x00, 0x46,
0x3f, 0x00, 0x05, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x06, 0x00, 0x00, 0x4d, 0x3f, 0x00, 0x06, 0x00,
0x00, 0x4a, 0x3f, 0x00, 0x06, 0x00, 0x00, 0x47, 0x3f, 0x00, 0x06, 0x00, 0x00, 0x44, 0x3f, 0x00,
0x06, 0x00, 0x00, 0x41, 0x3f, 0x00, 0x07, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x07, 0x00, 0x00, 0x46,
0x3f, 0x00, 0x07, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x08, 0x00, 0x00, 0x4a, 0x3f, 0x00, 0x07, 0x00,
0x00, 0x3e, 0x3f, 0x00, 0x08, 0x00, 0x00, 0x44, 0x3f, 0x00, 0x09, 0x00, 0x00, 0x4a, 0x3f, 0x00,
0x09, 0x00, 0x00, 0x47, 0x3f, 0x00, 0x09, 0x00, 0x00, 0x44, 0x3f, 0x00, 0x0a, 0x00, 0x00, 0x49,
0x3f, 0x00, 0x09, 0x00, 0x00, 0x3f, 0x3f, 0x00, 0x09, 0x00, 0x00, 0x3d, 0x3f, 0x00, 0x0b, 0x00,
0x00, 0x48, 0x3f, 0x00, 0x0b, 0x00, 0x00, 0x45, 0x3f, 0x00, 0x0a, 0x00, 0x00, 0x3c, 0x3f, 0x00,
0x0c, 0x00, 0x00, 0x46, 0x3f, 0x00, 0x0c, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x0d, 0x00, 0x00, 0x46,
0x3f, 0x00, 0x0c, 0x00, 0x00, 0x3e, 0x3f, 0x00, 0x0c, 0x00, 0x00, 0x3c, 0x3f, 0x00, 0x0d, 0x00,
0x00, 0x3f, 0x3f, 0x00, 0x0d, 0x00, 0x00, 0x3d, 0x3f, 0x00, 0x0e, 0x00, 0x00, 0x3f, 0x3f, 0x00,
0x0e, 0x00, 0x00, 0x3d, 0x3f, 0x00, 0x0e, 0x00, 0x00, 0x3b, 0x3f, 0x00, 0x0f, 0x00, 0x00, 0x3d,
0x3f, 0x00, 0x0e, 0x00, 0x00, 0x37, 0x3f, 0x00, 0x0f, 0x00, 0x00, 0x39, 0x3f, 0x00, 0x10, 0x00,
0x00, 0x3b, 0x3f, 0x00, 0x12, 0x00, 0x00, 0x40, 0x3f, 0x00, 0x10, 0x00, 0x00, 0x37, 0x3f, 0x00,
0x13, 0x00, 0x00, 0x3f, 0x3f, 0x00, 0x13, 0x00, 0x00, 0x3d, 0x3f, 0x00, 0x11, 0x00, 0x00, 0x34,
0x3f, 0x00, 0x12, 0x00, 0x00, 0x36, 0x3f, 0x00, 0x12, 0x00, 0x00, 0x34, 0x3f, 0x00, 0x14, 0x00,
0x00, 0x38, 0x3f, 0x00, 0x14, 0x00, 0x00, 0x36, 0x3f, 0x00, 0x17, 0x00, 0x00, 0x3c, 0x3f, 0x00,
0x17, 0x00, 0x00, 0x3a, 0x3f, 0x00, 0x18, 0x00, 0x00, 0x3a, 0x3f, 0x00, 0x15, 0x00, 0x00, 0x31,
0x3f, 0x00, 0x17, 0x00, 0x00, 0x34, 0x3f, 0x00, 0x16, 0x00, 0x00, 0x30, 0x3f, 0x00, 0x1a, 0x00,
0x00, 0x37, 0x3f, 0x00, 0x1b, 0x00, 0x00, 0x37, 0x3f, 0x00, 0x18, 0x00, 0x00, 0x2f, 0x3f, 0x00,
0x1c, 0x00, 0x00, 0x35, 0x3f, 0x00, 0x1c, 0x00, 0x00, 0x33, 0x3f, 0x00, 0x1c, 0x00, 0x00, 0x31,
0x3f, 0x00, 0x1d, 0x00, 0x00, 0x31, 0x3f, 0x00, 0x1b, 0x00, 0x00, 0x2c, 0x3f, 0x00, 0x1c, 0x00,
0x00, 0x2c, 0x3f, 0x00, 0x1d, 0x00, 0x00, 0x2c, 0x3f, 0x00, 0x1e, 0x00, 0x00, 0x2c, 0x3f, 0x00,
0x1d, 0x00, 0x00, 0x29, 0x3f, 0x00, 0x1e, 0x00, 0x00, 0x29, 0x3f, 0x00, 0x23, 0x00, 0x00, 0x2e,
0x3f, 0x00, 0x22, 0x00, 0x00, 0x2b, 0x3f, 0x00, 0x25, 0x00, 0x00, 0x2d, 0x3f, 0x00, 0x24, 0x00,
0x00, 0x2a, 0x3f, 0x00, 0x22, 0x00, 0x00, 0x26, 0x3f, 0x00, 0x27, 0x00, 0x00, 0x2a, 0x3f, 0x00,
0x22, 0x00, 0x00, 0x23, 0x3f, 0x00, 0x23, 0x00, 0x00, 0x23, 0x3f, 0x00, 0x2a, 0x00, 0x00, 0x28,
0x3f, 0x00, 0x24, 0x00, 0x00, 0x21, 0x3f, 0x00, 0x29, 0x00, 0x00, 0x24, 0x3f, 0x00, 0x2c, 0x00,
0x00, 0x25, 0x3f, 0x00, 0x28, 0x00, 0x00, 0x20, 0x3f, 0x00, 0x2b, 0x00, 0x00, 0x21, 0x3f, 0x00,
0x2d, 0x00, 0x00, 0x21, 0x3f, 0x00, 0x2b, 0x00, 0x00, 0x1e, 0x3f, 0x00, 0x2a, 0x00, 0x00, 0x1c,
0x3f, 0x00, 0x2f, 0x00, 0x00, 0x1e, 0x3f, 0x00, 0x2b, 0x00, 0x00, 0x1a, 0x3f, 0x00, 0x2d, 0x00,
0x00, 0x1a, 0x3f, 0x00, 0x31, 0x00, 0x00, 0x1b, 0x3f, 0x00, 0x2e, 0x00, 0x00, 0x18, 0x3f, 0x00,
0x37, 0x00, 0x00, 0x1b, 0x3f, 0x00, 0x38, 0x00, 0x00, 0x1a, 0x3f, 0x00, 0x37, 0x00, 0x00, 0x18,
0x3f, 0x00, 0x31, 0x00, 0x00, 0x14, 0x3f, 0x00, 0x39, 0x00, 0x00, 0x16, 0x3f, 0x00, 0x3d, 0x00,
0x00, 0x16, 0x3f, 0x00, 0x36, 0x00, 0x00, 0x12, 0x3f, 0x00, 0x3a, 0x00, 0x00, 0x12, 0x3f, 0x00,
0x3b, 0x00, 0x00, 0x11, 0x3f, 0x00, 0x40, 0x00, 0x00, 0x11, 0x3f, 0x00, 0x3a, 0x00, 0x00, 0x0e,
0x3f, 0x00, 0x3b, 0x00, 0x00, 0x0d, 0x3f, 0x00, 0x3c, 0x00, 0x00, 0x0c, 0x3f, 0x00, 0x3d, 0x00,
0x00, 0x0b, 0x3f, 0x00, 0x3e, 0x00, 0x00, 0x0a, 0x3f, 0x00, 0x3f, 0x00, 0x00, 0x09, 0x3f, 0x00,
0x40, 0x00, 0x00, 0x08, 0x3f, 0x00, 0x42, 0x00, 0x00, 0x07, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x06,
0x3f, 0x00, 0x47, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x4b, 0x00, 0x00, 0x04, 0x3f, 0x00, 0x50, 0x00,
0x00, 0x03, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x45, 0x3f, 0x00, 0x45, 0x3f, 0x00,
0x45, 0x3f, 0x00, 0x45, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x50, 0x00, 0x00, 0x03,
0x3f, 0x00, 0x4b, 0x00, 0x00, 0x04, 0x3f, 0x00, 0x47, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x44, 0x00,
0x00, 0x06, 0x3f, 0x00, 0x42, 0x00, 0x00, 0x07, 0x3f, 0x00, 0x40, 0x00, 0x00, 0x08, 0x3f, 0x00,
0x3f, 0x00, 0x00, 0x09, 0x3f, 0x00, 0x3e, 0x00, 0x00, 0x0a, 0x3f, 0x00, 0x3d, 0x00, 0x00, 0x0b,
0x3f, 0x00, 0x3c, 0x00, 0x00, 0x0c, 0x3f, 0x00, 0x3b, 0x00, 0x00, 0x0d, 0x3f, 0x00, 0x3a, 0x00,
0x00, 0x0e, 0x3f, 0x00, 0x40, 0x00, 0x00, 0x11, 0x3f, 0x00, 0x3b, 0x00, 0x00, 0x11, 0x3f, 0x00,
0x3a, 0x00, 0x00, 0x12, 0x3f, 0x00, 0x36, 0x00, 0x00, 0x12, 0x3f, 0x00, 0x3d, 0x00, 0x00, 0x16,
0x3f, 0x00, 0x39, 0x00, 0x00, 0x16, 0x3f, 0x00, 0x31, 0x00, 0x00, 0x14, 0x3f, 0x00, 0x37, 0x00,
0x00, 0x18, 0x3f, 0x00, 0x38, 0x00, 0x00, 0x1a, 0x3f, 0x00, 0x37, 0x00, 0x00, 0x1b, 0x3f, 0x00,
0x2e, 0x00, 0x00, 0x18, 0x3f, 0x00, 0x31, 0x00, 0x00, 0x1b, 0x3f, 0x00, 0x2d, 0x00, 0x00, 0x1a,
0x3f, 0x00, 0x2b, 0x00, 0x00, 0x1a, 0x3f, 0x00, 0x2f, 0x00, 0x00, 0x1e, 0x3f, 0x00, 0x2a, 0x00,
0x00, 0x1c, 0x3f, 0x00, 0x2b, 0x00, 0x00, 0x1e, 0x3f, 0x00, 0x2d, 0x00, 0x00, 0x21, 0x3f, 0x00,
0x2b, 0x00, 0x00, 0x21, 0x3f, 0x00, 0x28, 0x00, 0x00, 0x20, 0x3f, 0x00, 0x2c, 0x00, 0x00, 0x25,
0x3f, 0x00, 0x29, 0x00, 0x00, 0x24, 0x3f, 0x00, 0x24, 0x00, 0x00, 0x21, 0x3f, 0x00, 0x2a, 0x00,
0x00, 0x28, 0x3f, 0x00, 0x23, 0x00, 0x00, 0x23, 0x3f, 0x00, 0x22, 0x00, 0x00, 0x23, 0x3f, 0x00,
0x27, 0x00, 0x00, 0x2a, 0x3f, 0x00, 0x22, 0x00, 0x00, 0x26, 0x3f, 0x00, 0x24, 0x00, 0x00, 0x2a,
0x3f, 0x00, 0x25, 0x00, 0x00, 0x2d, 0x3f, 0x00, 0x22, 0x00, 0x00, 0x2b, 0x3f, 0x00, 0x23, 0x00,
0x00, 0x2e, 0x3f, 0x00, 0x1e, 0x00, 0x00, 0x29, 0x3f, 0x00, 0x1d, 0x00, 0x00, 0x29, 0x3f, 0x00,
0x1e, 0x00, 0x00, 0x2c, 0x3f, 0x00, 0x1d, 0x00, 0x00, 0x2c, 0x3f, 0x00, 0x1c, 0x00, 0x00, 0x2c,
0x3f, 0x00, 0x1b, 0x00, 0x00, 0x2c, 0x3f, 0x00, 0x1d, 0x00, 0x00, 0x31, 0x3f, 0x00, 0x1c, 0x00,
0x00, 0x31, 0x3f, 0x00, 0x1c, 0x00, 0x00, 0x33, 0x3f, 0x00, 0x1c, 0x00, 0x00, 0x35, 0x3f, 0x00,
0x18, 0x00, 0x00, 0x2f, 0x3f, 0x00, 0x1b, 0x00, 0x00, 0x37, 0x3f, 0x00, 0x1a, 0x00, 0x00, 0x37,
0x3f, 0x00, 0x16, 0x00, 0x00, 0x30, 0x3f, 0x00, 0x17, 0x00, 0x00, 0x34, 0x3f, 0x00, 0x15, 0x00,
0x00, 0x31, 0x3f, 0x00, 0x18, 0x00, 0x00, 0x3a, 0x3f, 0x00, 0x17, 0x00, 0x00, 0x3a, 0x3f, 0x00,
0x17, 0x00, 0x00, 0x3c, 0x3f, 0x00, 0x14, 0x00, 0x00, 0x36, 0x3f, 0x00, 0x14, 0x00, 0x00, 0x38,
0x3f, 0x00, 0x12, 0x00, 0x00, 0x34, 0x3f, 0x00, 0x12, 0x00, 0x00, 0x36, 0x3f, 0x00, 0x11, 0x00,
0x00, 0x34, 0x3f, 0x00, 0x13, 0x00, 0x00, 0x3d, 0x3f, 0x00, 0x13, 0x00, 0x00, 0x3f, 0x3f, 0x00,
0x10, 0x00, 0x00, 0x37, 0x3f, 0x00, 0x12, 0x00, 0x00, 0x40, 0x3f, 0x00, 0x10, 0x00, 0x00, 0x3b,
0x3f, 0x00, 0x0f, 0x00, 0x00, 0x39, 0x3f, 0x00, 0x0e, 0x00, 0x00, 0x37, 0x3f, 0x00, 0x0f, 0x00,
0x00, 0x3d, 0x3f, 0x00, 0x0e, 0x00, 0x00, 0x3b, 0x3f, 0x00, 0x0e, 0x00, 0x00, 0x3d, 0x3f, 0x00,
0x0e, 0x00, 0x00, 0x3f, 0x3f, 0x00, 0x0d, 0x00, 0x00, 0x3d, 0x3f, 0x00, 0x0d, 0x00, 0x00, 0x3f,
0x3f, 0x00, 0x0c, 0x00, 0x00, 0x3c, 0x3f, 0x00, 0x0c, 0x00, 0x00, 0x3e, 0x3f, 0x00, 0x0d, 0x00,
0x00, 0x46, 0x3f, 0x00, 0x0c, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x0c, 0x00, 0x00, 0x46, 0x3f, 0x00,
0x0a, 0x00, 0x00, 0x3c, 0x3f, 0x00, 0x0b, 0x00, 0x00, 0x45, 0x3f, 0x00, 0x0b, 0x00, 0x00, 0x48,
0x3f, 0x00, 0x09, 0x00, 0x00, 0x3d, 0x3f, 0x00, 0x09, 0x00, 0x00, 0x3f, 0x3f, 0x00, 0x0a, 0x00,
0x00, 0x49, 0x3f, 0x00, 0x09, 0x00, 0x00, 0x44, 0x3f, 0x00, 0x09, 0x00, 0x00, 0x47, 0x3f, 0x00,
0x09, 0x00, 0x00, 0x4a, 0x3f, 0x00, 0x08, 0x00, 0x00, 0x44, 0x3f, 0x00, 0x07, 0x00, 0x00, 0x3e,
0x3f, 0x00, 0x08, 0x00, 0x00, 0x4a, 0x3f, 0x00, 0x07, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x07, 0x00,
0x00, 0x46, 0x3f, 0x00, 0x07, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x06, 0x00, 0x00, 0x41, 0x3f, 0x00,
0x06, 0x00, 0x00, 0x44, 0x3f, 0x00, 0x06, 0x00, 0x00, 0x47, 0x3f, 0x00, 0x06, 0x00, 0x00, 0x4a,
0x3f, 0x00, 0x06, 0x00, 0x00, 0x4d, 0x3f, 0x00, 0x05, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x05, 0x00,
0x00, 0x46, 0x3f, 0x00, 0x05, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x05, 0x00, 0x00, 0x4d, 0x3f, 0x00,
0x04, 0x00, 0x00, 0x41, 0x3f, 0x00, 0x04, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x04, 0x00, 0x00, 0x46,
0x3f, 0x00, 0x04, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x04, 0x00, 0x00, 0x4d, 0x3f, 0x00, 0x04, 0x00,
0x00, 0x4f, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x42, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x42, 0x3f, 0x00,
0x03, 0x00, 0x00, 0x45, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x49, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x4d,
0x3f, 0x00, 0x03, 0x00, 0x00, 0x50, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x50, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00,
0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43,
0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x43, 0x3f, 0x00, 0x02, 0x00,
0x00, 0x43
};
unsigned char b4[] = {
0x00, 0x00, 0x00, 0x01, // blocks
0x00, 0x00, 0x00, 0x0a, // bytes
0x00, 0x00, 0x00, 0x04, // repeat
// 0xff, 0xff, 0xff, 0xff, // repeat
// 0x3f, 0x00, 0x04, // Level ????
// 0x00, 0x00, 0x3c // msec ????
0x3f, 0x20, 0x00, // "
0x00, 0x20, 0x00 // LED mask + clocks
};
printf("~1 send led sequence length %d\n",sizeof(b4));
if ((ev = i1pro2_indLEDseq(p, b4, sizeof(b4))) != I1PRO_OK)
return ev;
}
#endif /* NEVER */
/* ============================================================ */
/* key/value dictionary support for EEProm contents */
/* Search the linked list for the given key */
/* Return NULL if not found */
static i1keyv *i1data_find_key(i1data *d, i1key key) {
i1keyv *k;
for (k = d->head; k != NULL; k = k->next) {
if (k->key == key)
return k;
}
return NULL;
}
/* Search the linked list for the given key and */
/* return it, or add it to the list if it doesn't exist. */
/* Return NULL on error */
static i1keyv *i1data_make_key(i1data *d, i1key key) {
i1keyv *k;
for (k = d->head; k != NULL; k = k->next)
if (k->key == key)
return k;
if ((k = (i1keyv *)calloc(1, sizeof(i1keyv))) == NULL) {
a1logw(d->log, "i1data: malloc failed!\n");
return NULL;
}
k->key = key;
k->next = NULL;
if (d->last == NULL) {
d->head = d->last = k;
} else {
d->last->next = k;
d->last = k;
}
return k;
}
/* Return type of data associated with key. Return i1_dtype_unknown if not found */
static i1_dtype i1data_get_type(i1data *d, i1key key) {
i1keyv *k;
if ((k = d->find_key(d, key)) != NULL)
return k->type;
return i1_dtype_unknown;
}
/* Return the number of data items in a keyv. Return 0 if not found */
static unsigned int i1data_get_count(i1data *d, i1key key) {
i1keyv *k;
if ((k = d->find_key(d, key)) != NULL)
return k->count;
return 0;
}
/* Return a pointer to the short data for the key. */
/* Return NULL if not found or wrong type */
static int *i1data_get_shorts(i1data *d, unsigned int *count, i1key key) {
i1keyv *k;
if ((k = d->find_key(d, key)) == NULL)
return NULL;
if (k->type != i1_dtype_short)
return NULL;
if (count != NULL)
*count = k->count;
return (int *)k->data;
}
/* Return a pointer to the int data for the key. */
/* Return NULL if not found or wrong type */
static int *i1data_get_ints(i1data *d, unsigned int *count, i1key key) {
i1keyv *k;
if ((k = d->find_key(d, key)) == NULL)
return NULL;
if (k->type != i1_dtype_int)
return NULL;
if (count != NULL)
*count = k->count;
return (int *)k->data;
}
/* Return a pointer to the double data for the key. */
/* Return NULL if not found or wrong type */
static double *i1data_get_doubles(i1data *d, unsigned int *count, i1key key) {
i1keyv *k;
if ((k = d->find_key(d, key)) == NULL)
return NULL;
if (k->type != i1_dtype_double)
return NULL;
if (count != NULL)
*count = k->count;
return (double *)k->data;
}
/* Return pointer to one of the int data for the key. */
/* Return NULL if not found or wrong type or out of range index. */
static int *i1data_get_int(i1data *d, i1key key, unsigned int index) {
i1keyv *k;
if ((k = d->find_key(d, key)) == NULL)
return NULL;
if (k->type != i1_dtype_int)
return NULL;
if (index >= k->count)
return NULL;
return ((int *)k->data) + index;
}
/* Return pointer to one of the double data for the key. */
/* Return NULL if not found or wrong type or out of range index. */
static double *i1data_get_double(i1data *d, i1key key, double *data, unsigned int index) {
i1keyv *k;
if ((k = d->find_key(d, key)) == NULL)
return NULL;
if (k->type != i1_dtype_double)
return NULL;
if (index >= k->count)
return NULL;
return ((double *)k->data) + index;
}
/* Un-serialize a char buffer into an i1key keyv */
static i1pro_code i1data_unser_shorts(
i1data *d,
i1key key,
int addr,
unsigned char *buf,
unsigned int size
) {
i1keyv *k;
int i, count;
count = size/2;
if (count == 0)
return I1PRO_DATA_COUNT;
if ((k = d->make_key(d, key)) == NULL)
return I1PRO_DATA_MAKE_KEY;
if (k->data != NULL)
free(k->data);
if ((k->data = (void *)malloc(sizeof(int) * count)) == NULL)
return I1PRO_DATA_MEMORY;
for (i = 0; i < count; i++, buf += 2) {
((int *)k->data)[i] = buf2short(buf);
}
k->count = count;
k->size = size;
k->type = i1_dtype_short;
if (addr != -1)
k->addr = addr;
return I1PRO_OK;
}
/* Un-serialize a char buffer into an i1key keyv */
static i1pro_code i1data_unser_ints(
i1data *d,
i1key key,
int addr,
unsigned char *buf,
unsigned int size
) {
i1keyv *k;
int i, count;
count = size/4;
if (count == 0)
return I1PRO_DATA_COUNT;
if ((k = d->make_key(d, key)) == NULL)
return I1PRO_DATA_MAKE_KEY;
if (k->data != NULL)
free(k->data);
if ((k->data = (void *)malloc(sizeof(int) * count)) == NULL)
return I1PRO_DATA_MEMORY;
for (i = 0; i < count; i++, buf += 4) {
((int *)k->data)[i] = buf2int(buf);
}
k->count = count;
k->size = size;
k->type = i1_dtype_int;
if (addr != -1)
k->addr = addr;
return I1PRO_OK;
}
/* Create an entry for an end of section marker */
static i1pro_code i1data_add_eosmarker(
i1data *d,
i1key key, /* section number */
int addr
) {
i1keyv *k;
if ((k = d->make_key(d, key)) == NULL)
return I1PRO_DATA_MAKE_KEY;
if (k->data != NULL) {
free(k->data);
k->data = NULL;
}
k->count = 0;
k->size = 0;
k->type = i1_dtype_section;
if (addr != -1)
k->addr = addr;
return I1PRO_OK;
}
/* Un-serialize a char buffer of floats into a double keyv */
static i1pro_code i1data_unser_doubles(
i1data *d,
i1key key,
int addr,
unsigned char *buf,
unsigned int size
) {
i1keyv *k;
int i, count;
count = size/4;
if (count == 0)
return I1PRO_DATA_COUNT;
if ((k = d->make_key(d, key)) == NULL)
return I1PRO_DATA_MAKE_KEY;
if (k->data != NULL)
free(k->data);
if ((k->data = (void *)malloc(sizeof(double) * count)) == NULL)
return I1PRO_DATA_MEMORY;
for (i = 0; i < count; i++, buf += 4) {
int val;
val = buf2int(buf);
((double *)k->data)[i] = IEEE754todouble((unsigned int)val);
}
k->count = count;
k->size = size;
k->type = i1_dtype_double;
if (addr != -1)
k->addr = addr;
return I1PRO_OK;
}
/* Serialize an i1key keyv into a char buffer. Error if it is outside the buffer */
static i1pro_code i1data_ser_ints(
i1data *d,
i1keyv *k,
unsigned char *buf,
unsigned int size
) {
i1pro *p = d->p;
int i, len;
if (k->type != i1_dtype_int)
return I1PRO_DATA_WRONGTYPE;
len = k->count * 4;
if (len > k->size)
return I1PRO_DATA_BUFSIZE;
if (k->addr < 0 || k->addr >= size || (k->addr + k->size) > size)
return I1PRO_DATA_BUFSIZE;
buf += k->addr;
for (i = 0; i < k->count; i++, buf += 4) {
int2buf(buf, ((int *)k->data)[i]);
}
return I1PRO_OK;
}
/* Serialize a double keyv as floats into a char buffer. Error if the buf is not big enough */
static i1pro_code i1data_ser_doubles(
i1data *d,
i1keyv *k,
unsigned char *buf,
unsigned int size
) {
i1pro *p = d->p;
int i, len;
if (k->type != i1_dtype_double)
return I1PRO_DATA_WRONGTYPE;
len = k->count * 4;
if (len > k->size)
return I1PRO_DATA_BUFSIZE;
if (k->addr < 0 || k->addr >= size || (k->addr + k->size) > size)
return I1PRO_DATA_BUFSIZE;
buf += k->addr;
for (i = 0; i < k->count; i++, buf += 4) {
int2buf(buf, doubletoIEEE754(((double *)k->data)[i]));
}
return I1PRO_OK;
}
/* Copy an array full of ints to the key */
/* Note the count must be the same as the existing key value, */
/* since we are not prepared to re-allocate key/values within */
/* the EEProm, or re-write the directory. */
static i1pro_code i1data_add_ints(i1data *d, i1key key, int *data, unsigned int count) {
i1keyv *k;
int i;
if ((k = d->make_key(d, key)) == NULL)
return I1PRO_DATA_MAKE_KEY;
if (count != k->count)
return I1PRO_DATA_COUNT;
if (k->data != NULL)
free(k->data);
if ((k->data = (void *)malloc(sizeof(int) * count)) == NULL)
return I1PRO_DATA_MEMORY;
for (i = 0; i < count; i++) {
((int *)k->data)[i] = data[i];
}
k->count = count;
k->type = i1_dtype_int;
return I1PRO_OK;
}
/* Copy an array full of doubles to the key */
/* Note the count must be the same as the existing key value, */
/* since we are not prepared to re-allocate key/values within */
/* the EEProm, or re-write the directory. */
static i1pro_code i1data_add_doubles(i1data *d, i1key key, double *data, unsigned int count) {
i1keyv *k;
int i;
if ((k = d->make_key(d, key)) == NULL)
return I1PRO_DATA_MAKE_KEY;
if (count != k->count)
return I1PRO_DATA_COUNT;
if (k->data != NULL)
free(k->data);
if ((k->data = (void *)malloc(sizeof(double) * count)) == NULL)
return I1PRO_DATA_MEMORY;
for (i = 0; i < count; i++) {
((double *)k->data)[i] = data[i];
}
k->count = count;
k->type = i1_dtype_double;
return I1PRO_OK;
}
/* Initialise the data from the EEProm contents */
static i1pro_code i1data_parse_eeprom(i1data *d, unsigned char *buf, unsigned int len, int extra) {
i1pro *p = d->p;
int rv = I1PRO_OK;
int dir = 0x1000; /* Location of key directory */
int minkeys = 300; /* Expected minumum number of bytes for keys */
int maxkeys = 512; /* Expected maxumum number of bytes for keys */
int block_id; /* Block id */
int nokeys;
i1key key, off, nkey = 0, noff = 0;
int size; /* size of key in bytes */
unsigned char *bp;
int i;
if (extra) {
dir = 0x2000; /* Directory is at half way in i1pro2 2nd table */
minkeys = 200; /* Hmm. Had a report that the i1Pro2 failed to parse */
}
a1logd(p->log,3,"i1pro_parse_eeprom called with %d bytes, table %d\n",len,extra);
/* Room for minimum number of keys ? */
if ((dir + minkeys) > len)
return I1PRO_DATA_KEY_COUNT_SMALL;
block_id = buf2ushort(buf + dir);
if ((extra == 0 && block_id != 1) /* Must be 1 for base data */
|| (extra == 1 && block_id != 2)) /* Must be 2 for i1pro2 extra data*/
return I1PRO_DATA_KEY_CORRUPT;
nokeys = buf2ushort(buf + dir + 2); /* Bytes in key table */
a1logd(p->log,3,"%d bytes for keys in EEProm table %d\n",nokeys, extra);
if (nokeys < minkeys)
return I1PRO_DATA_KEY_COUNT_SMALL;
if (nokeys > maxkeys)
return I1PRO_DATA_KEY_COUNT_LARGE;
nokeys = (nokeys - 4)/6; /* Number of 6 byte entries */
a1logd(p->log,3,"%d keys & values in EEProm table %d\n",nokeys, extra);
/* We need current and next value to figure data size out */
bp = buf + dir + 4;
key = buf2ushort(bp);
off = buf2int(bp+2);
bp += 6;
for (i = 0; i < nokeys; i++, bp += 6, key = nkey, off = noff) {
i1_dtype type;
if (i < (nokeys-1)) {
nkey = buf2ushort(bp);
noff = buf2int(bp+2);
}
size = noff - off;
if (size < 0)
size = 0;
type = d->det_type(d, key);
a1logd(p->log,3,"Table entry %d is Key 0x%04x, type %d addr 0x%x, size %d\n",
i,key,type,off,size);
/* Check data is within range */
if (off >= len || noff < off || noff > len) {
a1logd(p->log,3,"Key 0x%04x offset %d and length %d out of range\n",key,off,noff);
return I1PRO_DATA_KEY_MEMRANGE;
}
if (type == i1_dtype_unknown) {
if (d->log->debug >= 7) {
int i;
char oline[100], *bp = oline;
bp = oline;
a1logd(d->log,7,"Key 0x%04x is unknown type\n",key);
for (i = 0; i < size; i++) {
if ((i % 16) == 0)
bp += sprintf(bp," %04x:",i);
bp += sprintf(bp," %02x",buf[off + i]);
if ((i+1) >= size || ((i+1) % 16) == 0) {
bp += sprintf(bp,"\n");
a1logd(p->log,7,oline);
bp = oline;
}
}
}
if (type == i1_dtype_unknown)
continue; /* Ignore it */
}
if (type == i1_dtype_section) {
if ((rv = i1data_add_eosmarker(d, key, off)) != I1PRO_OK) {
a1logd(p->log,3,"Key 0x%04x section marker failed with 0x%x\n",key,rv);
return rv;
}
continue;
}
if (i >= nokeys) {
a1logd(p->log,3,"Last key wasn't a section marker!\n");
return I1PRO_DATA_KEY_ENDMARK;
}
if (type == i1_dtype_short) {
if ((rv = i1data_unser_shorts(d, key, off, buf + off, size)) != I1PRO_OK) {
a1logd(p->log,3,"Key 0x%04x short unserialise failed with 0x%x\n",key,rv);
return rv;
}
} else if (type == i1_dtype_int) {
if ((rv = i1data_unser_ints(d, key, off, buf + off, size)) != I1PRO_OK) {
a1logd(p->log,3,"Key 0x%04x int unserialise failed with 0x%x\n",key,rv);
return rv;
}
} else if (type == i1_dtype_double) {
if ((rv = i1data_unser_doubles(d, key, off, buf + off, size)) != I1PRO_OK) {
a1logd(p->log,3,"Key 0x%04x double unserialise failed with 0x%x\n",key,rv);
return rv;
}
} else {
a1logd(p->log,3,"Key 0x%04x has type we can't handle!\n",key);
}
}
return I1PRO_OK;
}
/* Compute and set the checksum, then serialise all the keys up */
/* to the first marker into a buffer, ready for writing back to */
/* the EEProm. It is an error if this buffer is not located at */
/* zero in the EEProm */
static i1pro_code i1data_prep_section1(
i1data *d,
unsigned char **buf, /* return allocated buffer */
unsigned int *len
) {
i1pro *p = d->p;
i1proimp *m = d->m;
int chsum1, *chsum2;
i1keyv *k, *sk, *j;
i1pro_code ev = I1PRO_OK;
a1logd(p->log,5,"i1data_prep_section1 called\n");
/* Compute the checksum for the first copy of the log data */
chsum1 = m->data->checksum(m->data, 0);
/* Locate and then set the checksum */
if ((chsum2 = m->data->get_int(m->data, key_checksum, 0)) == NULL) {
a1logd(p->log,2,"i1data_prep_section1 failed to locate checksum\n");
return I1PRO_INT_PREP_LOG_DATA;
}
*chsum2 = chsum1;
/* Locate the first section marker */
for (sk = d->head; sk != NULL; sk = sk->next) {
if (sk->type == i1_dtype_section)
break;
}
if (sk == NULL) {
a1logd(p->log,2,"i1data_prep_section1 failed to find section marker\n");
return I1PRO_INT_PREP_LOG_DATA;
}
/* for each key up to the first section marker */
/* check it resides within that section, and doesn't */
/* overlap any other key. */
for (k = d->head; k != NULL; k = k->next) {
if (k->type == i1_dtype_section)
break;
if (k->addr < 0 || k->addr >= sk->addr || (k->addr + k->size) > sk->addr) {
a1logd(p->log,2,"i1data_prep_section1 found key outside section\n");
return I1PRO_INT_PREP_LOG_DATA;
}
for (j = k->next; j != NULL; j = j->next) {
if (j->type == i1_dtype_section)
break;
if ((j->addr >= k->addr && j->addr < (k->addr + k->size))
|| ((j->addr + j->size) > k->addr && (j->addr + j->size) <= (k->addr + k->size))) {
a1logd(p->log,2,"i1data_prep_section1 found key overlap section, 0x%x %d and 0x%x %d\n",
k->addr, k->size, j->addr, j->size);
return I1PRO_INT_PREP_LOG_DATA;
}
}
}
/* Allocate the buffer for the data */
*len = sk->addr;
if ((*buf = (unsigned char *)calloc(sk->addr, sizeof(unsigned char))) == NULL) {
a1logw(p->log, "i1data: malloc failed!\n");
return I1PRO_INT_MALLOC;
}
/* Serialise it into the buffer */
for (k = d->head; k != NULL; k = k->next) {
if (k->type == i1_dtype_section)
break;
else if (k->type == i1_dtype_int) {
if ((ev = m->data->ser_ints(m->data, k, *buf, *len)) != I1PRO_OK) {
a1logd(p->log,2,"i1data_prep_section1 serializing ints failed\n");
return ev;
}
} else if (k->type == i1_dtype_double) {
if ((ev = m->data->ser_doubles(m->data, k, *buf, *len)) != I1PRO_OK) {
a1logd(p->log,2,"i1data_prep_section1 serializing doubles failed\n");
return ev;
}
} else {
a1logd(p->log,2,"i1data_prep_section1 tried to serialise unknown type\n");
return I1PRO_INT_PREP_LOG_DATA;
}
}
a1logd(p->log,5,"a_prep_section1 done\n");
return ev;
}
/* Return the data type for the given key identifier */
static i1_dtype i1data_det_type(i1data *d, i1key key) {
if (key < 0x100)
return i1_dtype_section;
switch(key) {
/* Log keys */
case key_meascount:
case key_meascount + 1000:
return i1_dtype_int;
case key_darkreading:
case key_darkreading + 1000:
return i1_dtype_int;
case key_whitereading:
case key_whitereading + 1000:
return i1_dtype_int;
case key_gainmode:
case key_gainmode + 1000:
return i1_dtype_int;
case key_inttime:
case key_inttime + 1000:
return i1_dtype_double;
case key_caldate:
case key_caldate + 1000:
return i1_dtype_int;
case key_calcount:
case key_calcount + 1000:
return i1_dtype_int;
case key_checksum:
case key_checksum + 1000:
return i1_dtype_int;
case key_rpinttime:
case key_rpinttime + 1000:
return i1_dtype_double;
case key_rpcount:
case key_rpcount + 1000:
return i1_dtype_int;
case key_acount:
case key_acount + 1000:
return i1_dtype_int;
case key_lampage:
case key_lampage + 1000:
return i1_dtype_double;
/* Intstrument calibration keys */
case key_ng_lin:
return i1_dtype_double;
case key_hg_lin:
return i1_dtype_double;
case key_min_int_time:
return i1_dtype_double;
case key_max_int_time:
return i1_dtype_double;
case key_mtx_index:
return i1_dtype_int;
case key_mtx_nocoef:
return i1_dtype_int;
case key_mtx_coef:
return i1_dtype_double;
case key_0bb9:
return i1_dtype_int;
case key_0bba:
return i1_dtype_int;
case key_white_ref:
return i1_dtype_double;
case key_emis_coef:
return i1_dtype_double;
case key_amb_coef:
return i1_dtype_double;
case key_0fa0:
return i1_dtype_int;
case key_0bbf:
return i1_dtype_int;
case key_cpldrev:
return i1_dtype_int;
case key_0bc1:
return i1_dtype_int;
case key_capabilities:
return i1_dtype_int;
case key_0bc3:
return i1_dtype_int;
case key_physfilt:
return i1_dtype_int;
case key_0bc5:
return i1_dtype_int;
case key_0bc6:
return i1_dtype_double;
case key_sens_target:
return i1_dtype_int;
case key_sens_dark:
return i1_dtype_int;
case key_ng_sens_sat:
return i1_dtype_int;
case key_hg_sens_sat:
return i1_dtype_int;
case key_serno:
return i1_dtype_int;
case key_dom:
return i1_dtype_int;
case key_hg_factor:
return i1_dtype_double;
default:
return i1_dtype_unknown;
/* i1pro2 keys */
case 0x2ee0:
return i1_dtype_unknown; // ~~
case 0x2ee1:
return i1_dtype_char;
case 0x2ee2:
return i1_dtype_int;
case 0x2ee3:
return i1_dtype_int;
case 0x2ee4:
return i1_dtype_unknown; // ~~
case 0x2eea:
return i1_dtype_int;
case 0x2eeb:
return i1_dtype_int;
case 0x2eec:
return i1_dtype_int;
case 0x2ef4:
return i1_dtype_double;
case 0x2ef5:
return i1_dtype_double;
case 0x2ef6:
return i1_dtype_double;
case 0x2ef9:
return i1_dtype_double;
case 0x2efa:
return i1_dtype_double;
case 0x2efe:
return i1_dtype_int;
case 0x2eff:
return i1_dtype_int;
case 0x2f08:
return i1_dtype_double;
case 0x2f09:
return i1_dtype_double;
case 0x2f12:
return i1_dtype_double;
case 0x2f13:
return i1_dtype_double;
case 0x2f14:
return i1_dtype_double;
case 0x2f15:
return i1_dtype_double;
case 0x2f44: /* Wavelength LED reference shape ? */
return i1_dtype_double;
case 0x2f45:
return i1_dtype_int;
case 0x2f46:
return i1_dtype_double;
case 0x2f4e:
return i1_dtype_double;
case 0x2f4f:
return i1_dtype_double;
case 0x2f50:
return i1_dtype_double;
case 0x2f58:
return i1_dtype_short; /* Stray light compensation table */
case 0x2f59:
return i1_dtype_double; /* Stray light scale factor ? */
case 0x2f62:
return i1_dtype_double;
case 0x2f63:
return i1_dtype_double;
case 0x2f6c:
return i1_dtype_double;
case 0x2f6d:
return i1_dtype_double;
case 0x2f6e:
return i1_dtype_double;
case 0x2f76:
return i1_dtype_double;
case 0x2f77:
return i1_dtype_double;
case 0x32c8:
return i1_dtype_int; // Date
case 0x32c9:
return i1_dtype_int; // Date
case 0x32ca:
return i1_dtype_unknown; // ~~
case 0x36b0:
return i1_dtype_int; // Date
case 0x36b1:
return i1_dtype_int; // Date
case 0x36b2:
return i1_dtype_unknown; // ~~
case 0x3a99:
return i1_dtype_unknown; // ~~
case 0x3a9a:
return i1_dtype_unknown; // ~~
case 0x3a9b:
return i1_dtype_unknown; // ~~
case 0x3a9c:
return i1_dtype_unknown; // ~~
case 0x3a9d:
return i1_dtype_unknown; // ~~
case 0x3e81:
return i1_dtype_char; // "X-Rite"
case 0x3e82:
return i1_dtype_unknown; // ~~
case 0x3e8a:
return i1_dtype_unknown; // ~~
case 0x3e94:
return i1_dtype_unknown; // ~~
}
return i1_dtype_unknown;
}
/* Given an index starting at 0, return the matching key code */
/* for keys that get checksummed. Return 0 if outside range. */
static i1key i1data_chsum_keys(
i1data *d,
int index
) {
switch(index) {
case 0:
return key_meascount;
case 1:
return key_darkreading;
case 2:
return key_whitereading;
case 3:
return key_gainmode;
case 4:
return key_inttime;
case 5:
return key_caldate;
case 6:
return key_calcount;
case 7:
return key_rpinttime;
case 8:
return key_rpcount;
case 9:
return key_acount;
case 10:
return key_lampage;
}
return 0;
}
/* Compute a checksum. */
static int i1data_checksum(
i1data *d,
i1key keyoffset /* Offset to apply to keys */
) {
int i, n, j;
int chsum = 0;
for (i = 0; ; i++) {
i1key key;
i1keyv *k;
if ((key = d->chsum_keys(d, i)) == 0)
break; /* we're done */
key += keyoffset;
if ((k = d->find_key(d, key)) == NULL)
continue; /* Hmm */
if (k->type == i1_dtype_int) {
for (j = 0; j < k->count; j++)
chsum += ((int *)k->data)[j];
} else if (k->type == i1_dtype_double) {
for (j = 0; j < k->count; j++)
chsum += doubletoIEEE754(((double *)k->data)[j]);
}
}
return chsum;
}
/* Destroy ourselves */
static void i1data_del(i1data *d) {
i1keyv *k, *nk;
del_a1log(d->log); /* Unref it */
/* Free all the keys and their data */
for (k = d->head; k != NULL; k = nk) {
nk = k->next;
if (k->data != NULL)
free(k->data);
free(k);
}
free(d);
}
/* Constructor for i1data */
i1data *new_i1data(i1proimp *m) {
i1data *d;
if ((d = (i1data *)calloc(1, sizeof(i1data))) == NULL) {
a1loge(m->p->log, 1, "new_i1data: malloc failed!\n");
return NULL;
}
d->p = m->p;
d->m = m;
d->log = new_a1log_d(m->p->log); /* Take reference */
d->find_key = i1data_find_key;
d->make_key = i1data_make_key;
d->get_type = i1data_get_type;
d->get_count = i1data_get_count;
d->get_shorts = i1data_get_shorts;
d->get_ints = i1data_get_ints;
d->get_doubles = i1data_get_doubles;
d->get_int = i1data_get_int;
d->get_double = i1data_get_double;
d->unser_ints = i1data_unser_ints;
d->unser_doubles = i1data_unser_doubles;
d->ser_ints = i1data_ser_ints;
d->ser_doubles = i1data_ser_doubles;
d->parse_eeprom = i1data_parse_eeprom;
d->prep_section1 = i1data_prep_section1;
d->add_ints = i1data_add_ints;
d->add_doubles = i1data_add_doubles;
d->del = i1data_del;
d->det_type = i1data_det_type;
d->chsum_keys = i1data_chsum_keys;
d->checksum = i1data_checksum;
return d;
}
/* ----------------------------------------------------------------- */
|
94ae73c59c51810ad4c3aa856357d1128de3520e
|
9a68dcf8668b52b2594f1d021fe2cad3d80ca722
|
/UVa-10267.c
|
1fae1b5e5a0bddce29600f8349b742bccc2cbea0
|
[] |
no_license
|
shaojason999/Competitive_Programming
|
8c50a1a4b1f4c2bd8b53627c35c20efcd1c706e6
|
4cb9d33e2738f9bf4601f4bc4dc0ff64a7129720
|
refs/heads/master
| 2022-10-14T00:22:52.974340 | 2020-06-10T14:39:10 | 2020-06-10T14:39:10 | 262,034,853 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,144 |
c
|
UVa-10267.c
|
/* UVa 10137 - The Trip
# Problem Verdict Language Run Time Submission Date
24765101 10267 Graphical Editor Accepted ANSI C 0.000 2020-03-26 06:13:46
# 注意輸入的 x,y 不是照大小輸入
# 其中 F 指令的意思是把"相鄰"同顏色區塊都轉換成顏色 C (相鄰的定義為上下左右,不包括斜角線)
# 無須檢查邊界,因為我把邊界外多加一層,顏色設成 '@'。F 指令時可以直接檢查邊界外顏色,而且不會跟任何顏色相同
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* #define SWAP(x,y) {typeof(x) t=x, x=y, y=t;} // UVa compilation may fail
or #define SWAP(x,y) {typeof(x) t; t=x, x=y, y=t;} */
#define SWAP(x,y) {x^=y, y^=x, x^=y;}
/* or #define SWAP(x,y) {x=x+y; y=x-y; x=x-y;} */
char table[260][260];
char RC,C;
struct direction{
int x,y;
} dir[4] = {{0,-1},{1,0},{0,1},{-1,0}};
void find_4_dirs(int X, int Y)
{
int new_X,new_Y,i;
for (i=0;i<4;++i){
new_X = X + dir[i].x;
new_Y = Y + dir[i].y;
if(table[new_Y][new_X] == RC){
table[new_Y][new_X] = C;
find_4_dirs(new_X,new_Y);
}
}
}
int main()
{
char F;
int M,N;
int i,j;
int X1,Y1,X2,Y2;
char name[1000];
while(scanf("%c",&F)){
if (F == 'X') {
break;
}else if (F == 'I' || F == 'C'){
if (F == 'I')
scanf("%d %d",&M,&N);
/* clear all */
memset(table,'O',sizeof(table));
/* boundary set */
for(j=0;j<M+2;++j)
table[0][j] = '@';
for(j=0;j<M+2;++j)
table[N+1][j] = '@';
for(i=0;i<N+2;++i)
table[i][0] = '@';
for(i=0;i<N+2;++i)
table[i][M+1] = '@';
}else if (F == 'L'){
scanf("%d %d %c",&X1,&Y1,&C);
table[Y1][X1] = C;
}else if (F == 'V'){
scanf("%d %d %d %c",&X1,&Y1,&Y2,&C);
if(Y1>Y2) SWAP(Y1,Y2);
for(i=Y1;i<=Y2;++i)
table[i][X1] = C;
}else if (F == 'H'){
scanf("%d %d %d %c",&X1,&X2,&Y1,&C);
if(X1>X2) SWAP(X1,X2);
for(j=X1;j<=X2;++j)
table[Y1][j] = C;
}else if (F == 'K'){
scanf("%d %d %d %d %c",&X1,&Y1,&X2,&Y2,&C);
if(X1>X2) SWAP(X1,X2);
if(Y1>Y2) SWAP(Y1,Y2);
for(i=Y1;i<=Y2;++i)
for(j=X1;j<=X2;++j)
table[i][j] = C;
}else if (F == 'F'){
scanf("%d %d %c",&X1,&Y1,&C);
RC = table[Y1][X1];
if( RC != C){
table[Y1][X1] = C;
find_4_dirs(X1,Y1);
}
}else if (F == 'S'){
scanf("%s",name);
printf("%s\n",name);
for (i=1;i<=N;++i){
for (j=1;j<=M;++j)
printf("%c",table[i][j]);
printf("\n");
}
}
}
return 0;
}
|
7f782629dbfd6ee825d48851b284a0cc9608518f
|
7210ffabbba6ec656a9cab0b35be0afd03480d1d
|
/Fontes/.hbmk/win/mingw/rel_clie.c
|
cea910bbf47664f885c1141cf5d50e7796fae37e
|
[] |
no_license
|
Airam1968/XSan
|
6b39e933dd146357477e5ae2fedc5065e920a74a
|
1387c7de9b1512395098f44af2a1fe442378f575
|
refs/heads/main
| 2023-01-05T18:32:46.148202 | 2020-11-06T20:30:49 | 2020-11-06T20:30:49 | 305,840,534 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 23,171 |
c
|
rel_clie.c
|
/*
* Harbour 2.0.0 (Rev. 13372)
* MinGW GNU C 4.4.1 (32-bit)
* Generated C source from "C:/sis/SAN/xhb/rel_clie.prg"
*/
#include "hbvmpub.h"
#include "hbinit.h"
HB_FUNC( REL_CLIE );
HB_FUNC_EXTERN( PPERG );
HB_FUNC_EXTERN( PTIT );
HB_FUNC_EXTERN( PLQUA );
HB_FUNC_EXTERN( SPACE );
HB_FUNC_EXTERN( DEVPOS );
HB_FUNC_EXTERN( DEVOUT );
HB_FUNC_EXTERN( SETPOS );
HB_FUNC_EXTERN( ROW );
HB_FUNC_EXTERN( COL );
HB_FUNC_EXTERN( AADD );
HB_FUNC_EXTERN( __GET );
HB_FUNC_EXTERN( ATAIL );
HB_FUNC_EXTERN( READMODAL );
HB_FUNC_EXTERN( ALLTRIM );
HB_FUNC_EXTERN( PIMPR );
HB_FUNC_EXTERN( DBSELECTAREA );
HB_FUNC_EXTERN( DBUSEAREA );
HB_FUNC_EXTERN( DBSETINDEX );
HB_FUNC_EXTERN( DBSETFILTER );
HB_FUNC_EXTERN( DBGOTOP );
HB_FUNC_EXTERN( DBSKIP );
HB_FUNC_EXTERN( PMENSAG );
HB_FUNC_EXTERN( DBCREATEINDEX );
HB_FUNC_EXTERN( STR );
HB_FUNC_EXTERN( EOF );
HB_FUNC_EXTERN( PMSGR );
HB_FUNC_EXTERN( PPARA );
HB_FUNC_EXTERN( SET );
HB_FUNC_EXTERN( DTOC );
HB_FUNC_EXTERN( DATE );
HB_FUNC_EXTERN( REPLICATE );
HB_FUNC_EXTERN( ORDSETFOCUS );
HB_FUNC_EXTERN( DBSEEK );
HB_FUNC_EXTERN( FOUND );
HB_FUNC_EXTERN( DEVOUTPICT );
HB_FUNC_EXTERN( SUBSTR );
HB_FUNC_EXTERN( PTECLA );
HB_FUNC_EXTERN( DBCLOSEALL );
HB_FUNC_EXTERN( __SETFORMAT );
HB_INIT_SYMBOLS_BEGIN( hb_vm_SymbolInit_REL_CLIE )
{ "REL_CLIE", {HB_FS_PUBLIC | HB_FS_FIRST | HB_FS_LOCAL}, {HB_FUNCNAME( REL_CLIE )}, NULL },
{ "PPERG", {HB_FS_PUBLIC}, {HB_FUNCNAME( PPERG )}, NULL },
{ "SISRESP", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "PTIT", {HB_FS_PUBLIC}, {HB_FUNCNAME( PTIT )}, NULL },
{ "PLQUA", {HB_FS_PUBLIC}, {HB_FUNCNAME( PLQUA )}, NULL },
{ "SPACE", {HB_FS_PUBLIC}, {HB_FUNCNAME( SPACE )}, NULL },
{ "ETIPO", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "DEVPOS", {HB_FS_PUBLIC}, {HB_FUNCNAME( DEVPOS )}, NULL },
{ "DEVOUT", {HB_FS_PUBLIC}, {HB_FUNCNAME( DEVOUT )}, NULL },
{ "SETPOS", {HB_FS_PUBLIC}, {HB_FUNCNAME( SETPOS )}, NULL },
{ "ROW", {HB_FS_PUBLIC}, {HB_FUNCNAME( ROW )}, NULL },
{ "COL", {HB_FS_PUBLIC}, {HB_FUNCNAME( COL )}, NULL },
{ "AADD", {HB_FS_PUBLIC}, {HB_FUNCNAME( AADD )}, NULL },
{ "GETLIST", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "__GET", {HB_FS_PUBLIC}, {HB_FUNCNAME( __GET )}, NULL },
{ "DISPLAY", {HB_FS_PUBLIC | HB_FS_MESSAGE}, {NULL}, NULL },
{ "ATAIL", {HB_FS_PUBLIC}, {HB_FUNCNAME( ATAIL )}, NULL },
{ "READMODAL", {HB_FS_PUBLIC}, {HB_FUNCNAME( READMODAL )}, NULL },
{ "EEMPREEND", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "EARQUIVO", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ALLTRIM", {HB_FS_PUBLIC}, {HB_FUNCNAME( ALLTRIM )}, NULL },
{ "SISDRIVE_REL", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "SISPASTA_REL", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ESAIDA", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "PIMPR", {HB_FS_PUBLIC}, {HB_FUNCNAME( PIMPR )}, NULL },
{ "DBSELECTAREA", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBSELECTAREA )}, NULL },
{ "DBUSEAREA", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBUSEAREA )}, NULL },
{ "DBSETINDEX", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBSETINDEX )}, NULL },
{ "DBSETFILTER", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBSETFILTER )}, NULL },
{ "NUM_CLIE", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "DBGOTOP", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBGOTOP )}, NULL },
{ "DBSKIP", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBSKIP )}, NULL },
{ "PMENSAG", {HB_FS_PUBLIC}, {HB_FUNCNAME( PMENSAG )}, NULL },
{ "DBCREATEINDEX", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBCREATEINDEX )}, NULL },
{ "PROPRIET_1", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "PROPRIET_2", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "CLASSE", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "STR", {HB_FS_PUBLIC}, {HB_FUNCNAME( STR )}, NULL },
{ "EOF", {HB_FS_PUBLIC}, {HB_FUNCNAME( EOF )}, NULL },
{ "PMSGR", {HB_FS_PUBLIC}, {HB_FUNCNAME( PMSGR )}, NULL },
{ "PPARA", {HB_FS_PUBLIC}, {HB_FUNCNAME( PPARA )}, NULL },
{ "SET", {HB_FS_PUBLIC}, {HB_FUNCNAME( SET )}, NULL },
{ "SISLETRAC", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "SISTIT1", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "DTOC", {HB_FS_PUBLIC}, {HB_FUNCNAME( DTOC )}, NULL },
{ "DATE", {HB_FS_PUBLIC}, {HB_FUNCNAME( DATE )}, NULL },
{ "SISTIT2", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "SISLETRAE", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "REPLICATE", {HB_FS_PUBLIC}, {HB_FUNCNAME( REPLICATE )}, NULL },
{ "LIN", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ENUM_CLIE", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ORDSETFOCUS", {HB_FS_PUBLIC}, {HB_FUNCNAME( ORDSETFOCUS )}, NULL },
{ "DBSEEK", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBSEEK )}, NULL },
{ "FOUND", {HB_FS_PUBLIC}, {HB_FUNCNAME( FOUND )}, NULL },
{ "DEVOUTPICT", {HB_FS_PUBLIC}, {HB_FUNCNAME( DEVOUTPICT )}, NULL },
{ "CLIENTE", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "OPCAO", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "TEL_R_1", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ETEL1", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "TEL_R_2", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ETEL2", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "TEL_C_1", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "TEL_C_2", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "QUADRA", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "NUM_IMOVEL", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "STATUS", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "END_R", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "BAIRRO_R", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "CIDADE_R", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ESTADO_R", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "SUBSTR", {HB_FS_PUBLIC}, {HB_FUNCNAME( SUBSTR )}, NULL },
{ "CEP_R", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "END_C", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "BAIRRO_C", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "CIDADE_C", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "ESTADO_C", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "CEP_C", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "MAIL_PROP", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "PTECLA", {HB_FS_PUBLIC}, {HB_FUNCNAME( PTECLA )}, NULL },
{ "SISINTERR", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "DBCLOSEALL", {HB_FS_PUBLIC}, {HB_FUNCNAME( DBCLOSEALL )}, NULL },
{ "__SETFORMAT", {HB_FS_PUBLIC}, {HB_FUNCNAME( __SETFORMAT )}, NULL },
{ "SISTIT3", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL },
{ "SISLETRAN", {HB_FS_PUBLIC | HB_FS_MEMVAR}, {NULL}, NULL }
HB_INIT_SYMBOLS_EX_END( hb_vm_SymbolInit_REL_CLIE, "C:/sis/SAN/xhb/rel_clie.prg", 0x0, 0x0002 )
#if defined( HB_PRAGMA_STARTUP )
#pragma startup hb_vm_SymbolInit_REL_CLIE
#elif defined( HB_DATASEG_STARTUP )
#define HB_DATASEG_BODY HB_DATASEG_FUNC( hb_vm_SymbolInit_REL_CLIE )
#include "hbiniseg.h"
#endif
HB_FUNC( REL_CLIE )
{
static const HB_BYTE pcode[] =
{
36,14,0,176,1,0,106,17,67,111,110,102,105,114,
109,97,32,40,83,47,78,41,32,63,0,20,1,36,
15,0,109,2,0,106,2,83,0,5,29,180,19,36,
16,0,176,3,0,106,43,82,69,76,65,84,79,82,
73,79,32,67,65,68,65,83,84,82,79,32,68,69,
32,67,76,73,69,78,84,69,83,32,80,79,82,32,
80,82,79,68,85,84,79,0,20,1,36,17,0,176,
4,0,106,3,48,49,0,20,1,36,18,0,176,5,
0,122,12,1,83,6,0,36,19,0,176,7,0,92,
23,92,2,20,2,176,8,0,106,39,79,114,100,101,
109,32,65,108,102,97,98,130,116,105,99,97,32,111,
117,32,78,117,109,130,114,105,99,97,32,40,65,47,
78,41,32,32,58,32,0,20,1,176,9,0,176,10,
0,12,0,176,11,0,12,0,122,72,20,2,176,12,
0,109,13,0,176,14,0,100,106,6,101,84,73,80,
79,0,106,2,88,0,90,12,109,6,0,106,3,65,
78,0,24,6,100,12,5,20,2,48,15,0,176,16,
0,109,13,0,12,1,112,0,73,36,20,0,176,17,
0,109,13,0,100,100,100,100,100,100,20,7,4,0,
0,83,13,0,109,13,0,73,36,21,0,121,83,18,
0,36,22,0,176,7,0,92,23,92,2,20,2,176,
8,0,106,56,73,110,102,111,114,109,101,32,111,32,
78,163,109,101,114,111,32,100,111,32,69,109,112,114,
101,101,110,100,105,109,101,110,116,111,32,111,117,32,
40,48,41,32,112,97,114,97,32,116,111,100,111,115,
32,58,32,0,20,1,176,9,0,176,10,0,12,0,
176,11,0,12,0,122,72,20,2,176,12,0,109,13,
0,176,14,0,100,106,10,101,69,77,80,82,69,69,
78,68,0,106,8,64,82,32,57,57,57,57,0,100,
100,12,5,20,2,48,15,0,176,16,0,109,13,0,
12,1,112,0,73,36,23,0,176,17,0,109,13,0,
100,100,100,100,100,100,20,7,4,0,0,83,13,0,
109,13,0,73,36,24,0,176,5,0,92,60,12,1,
83,19,0,36,25,0,176,20,0,109,21,0,12,1,
176,5,0,122,12,1,69,28,18,36,26,0,109,21,
0,106,2,58,0,72,83,19,0,25,13,36,28,0,
106,3,67,58,0,83,19,0,36,30,0,109,22,0,
176,5,0,92,30,12,1,69,28,45,36,31,0,176,
20,0,109,19,0,12,1,109,22,0,72,106,12,69,
88,84,82,65,84,79,46,84,88,84,0,72,176,5,
0,92,10,12,1,72,83,19,0,25,39,36,33,0,
176,20,0,109,19,0,12,1,106,12,69,88,84,82,
65,84,79,46,84,88,84,0,72,176,5,0,92,10,
12,1,72,83,19,0,36,36,0,176,5,0,92,10,
12,1,83,23,0,36,38,0,176,4,0,106,3,48,
49,0,20,1,36,39,0,176,1,0,106,55,68,101,
115,101,106,97,32,101,120,116,114,97,116,111,32,101,
109,32,97,114,113,117,105,118,111,32,116,101,120,116,
111,32,110,111,32,68,114,105,118,101,32,40,88,58,
41,32,40,83,47,78,41,32,63,32,0,20,1,36,
40,0,109,2,0,106,2,83,0,5,29,178,0,36,
41,0,176,4,0,106,3,48,49,0,20,1,36,42,
0,176,7,0,92,23,121,20,2,176,8,0,106,23,
67,79,78,70,73,82,77,69,32,79,32,68,69,83,
84,73,78,79,32,32,58,32,0,20,1,176,9,0,
176,10,0,12,0,176,11,0,12,0,122,72,20,2,
176,12,0,109,13,0,176,14,0,100,106,9,101,65,
82,81,85,73,86,79,0,100,100,100,12,5,20,2,
48,15,0,176,16,0,109,13,0,12,1,112,0,73,
36,43,0,176,17,0,109,13,0,100,100,100,100,100,
100,20,7,4,0,0,83,13,0,109,13,0,73,36,
44,0,176,20,0,109,19,0,12,1,83,19,0,36,
45,0,106,8,65,82,81,85,73,86,79,0,83,23,
0,36,46,0,25,29,36,48,0,176,24,0,20,0,
36,49,0,106,11,73,77,80,82,69,83,83,79,82,
65,0,83,23,0,36,53,0,109,6,0,106,2,65,
0,5,28,119,36,54,0,176,25,0,106,2,49,0,
20,1,36,55,0,176,26,0,9,100,106,8,67,79,
78,84,65,84,79,0,100,100,9,20,6,176,27,0,
106,8,67,79,78,84,65,84,79,0,20,1,176,27,
0,106,9,78,85,77,95,67,76,73,69,0,20,1,
36,56,0,176,28,0,90,8,109,29,0,122,69,6,
106,14,78,85,77,95,67,76,73,69,32,60,62,32,
49,0,20,2,36,57,0,176,30,0,20,0,36,58,
0,176,31,0,122,20,1,25,117,36,60,0,176,25,
0,106,2,49,0,20,1,36,61,0,176,26,0,9,
100,106,8,67,79,78,84,65,84,79,0,100,100,9,
20,6,176,27,0,106,9,78,85,77,95,67,76,73,
69,0,20,1,176,27,0,106,8,67,79,78,84,65,
84,79,0,20,1,36,62,0,176,28,0,90,8,109,
29,0,122,69,6,106,14,78,85,77,95,67,76,73,
69,32,60,62,32,49,0,20,2,36,63,0,176,30,
0,20,0,36,64,0,176,31,0,122,20,1,36,66,
0,176,4,0,106,3,48,49,0,20,1,36,67,0,
176,32,0,106,19,73,110,100,101,120,97,110,100,111,
32,86,101,110,100,97,115,32,33,0,20,1,36,68,
0,176,25,0,106,2,50,0,20,1,36,69,0,176,
26,0,9,100,106,9,85,78,73,95,73,77,79,66,
0,100,100,9,20,6,36,70,0,176,30,0,20,0,
36,71,0,176,33,0,106,9,85,78,73,95,73,77,
79,49,0,106,11,80,82,79,80,82,73,69,84,95,
49,0,90,6,109,34,0,6,100,20,4,36,72,0,
176,30,0,20,0,36,73,0,176,33,0,106,9,85,
78,73,95,73,77,79,50,0,106,11,80,82,79,80,
82,73,69,84,95,50,0,90,6,109,35,0,6,100,
20,4,36,74,0,176,30,0,20,0,36,75,0,176,
26,0,9,100,106,9,85,78,73,95,73,77,79,66,
0,100,100,9,20,6,176,27,0,106,9,85,78,73,
95,73,77,79,49,0,20,1,176,27,0,106,9,85,
78,73,95,73,77,79,50,0,20,1,36,76,0,176,
30,0,20,0,36,77,0,109,18,0,121,69,28,63,
36,78,0,176,28,0,90,17,109,36,0,176,37,0,
109,18,0,92,5,12,2,5,6,106,26,67,76,65,
83,83,69,32,61,32,83,84,82,40,101,69,77,80,
82,69,69,78,68,44,53,41,0,20,2,36,79,0,
176,30,0,20,0,36,81,0,176,25,0,106,2,50,
0,20,1,36,82,0,176,30,0,20,0,36,83,0,
176,38,0,12,0,28,91,36,84,0,176,4,0,106,
3,48,49,0,20,1,36,85,0,176,39,0,106,10,
65,116,101,110,135,198,111,32,33,0,92,3,20,2,
36,86,0,176,32,0,106,33,78,198,111,32,72,160,
32,82,101,108,97,116,162,114,105,111,32,68,101,115,
116,101,32,80,101,114,161,111,100,111,32,33,0,20,
1,36,87,0,176,40,0,20,0,26,172,0,36,89,
0,109,23,0,106,8,65,82,81,85,73,86,79,0,
5,28,53,36,90,0,176,41,0,92,23,106,3,79,
78,0,20,2,36,91,0,176,41,0,92,20,106,8,
80,82,73,78,84,69,82,0,20,2,36,92,0,176,
41,0,92,24,109,19,0,9,20,3,25,98,36,94,
0,176,32,0,106,50,80,111,115,105,99,105,111,110,
101,32,111,32,70,111,114,109,117,108,97,114,105,111,
32,56,48,32,67,111,108,117,110,97,115,32,101,32,
84,101,99,108,101,32,91,69,78,84,69,82,93,0,
20,1,36,95,0,176,40,0,20,0,36,96,0,176,
24,0,20,0,36,97,0,176,41,0,92,20,106,8,
80,82,73,78,84,69,82,0,20,2,36,100,0,176,
38,0,12,0,32,242,12,36,101,0,176,7,0,122,
121,20,2,176,8,0,109,42,0,106,11,69,109,112,
114,101,115,97,32,58,32,0,72,109,43,0,72,20,
1,36,102,0,176,7,0,122,92,115,20,2,176,8,
0,106,8,68,97,116,97,32,58,32,0,176,44,0,
176,45,0,12,0,12,1,72,20,1,36,103,0,176,
7,0,92,2,121,20,2,176,8,0,106,11,83,105,
115,116,101,109,97,32,58,32,0,109,46,0,72,20,
1,36,104,0,176,7,0,92,2,92,115,20,2,176,
8,0,106,14,82,101,108,97,116,58,32,83,65,78,
48,48,49,0,20,1,36,105,0,176,7,0,92,3,
92,40,20,2,176,8,0,109,47,0,106,21,67,65,
68,65,83,84,82,79,32,68,69,32,67,76,73,69,
78,84,69,83,0,72,109,42,0,72,20,1,36,106,
0,176,7,0,92,4,121,20,2,176,8,0,176,48,
0,106,2,61,0,93,135,0,12,2,20,1,36,107,
0,176,7,0,92,5,121,20,2,176,8,0,106,2,
124,0,20,1,36,108,0,176,7,0,92,5,92,2,
20,2,176,8,0,106,7,67,111,100,105,103,111,0,
20,1,36,109,0,176,7,0,92,5,92,10,20,2,
176,8,0,106,5,78,111,109,101,0,20,1,36,110,
0,176,7,0,92,5,92,50,20,2,176,8,0,106,
8,80,114,111,100,117,116,111,0,20,1,36,111,0,
176,7,0,92,5,92,60,20,2,176,8,0,106,6,
71,114,117,112,111,0,20,1,36,112,0,176,7,0,
92,5,92,70,20,2,176,8,0,106,6,85,110,105,
100,46,0,20,1,36,113,0,176,7,0,92,5,92,
80,20,2,176,8,0,106,6,80,97,114,116,101,0,
20,1,36,114,0,176,7,0,92,5,92,90,20,2,
176,8,0,106,9,84,101,108,101,102,111,110,101,0,
20,1,36,115,0,176,7,0,92,5,93,134,0,20,
2,176,8,0,106,2,124,0,20,1,36,116,0,176,
7,0,92,6,121,20,2,176,8,0,176,48,0,106,
2,61,0,93,135,0,12,2,20,1,36,117,0,92,
7,83,49,0,36,118,0,176,38,0,12,0,32,196,
10,109,49,0,92,54,34,29,187,10,36,120,0,176,
25,0,106,2,49,0,20,1,36,121,0,109,29,0,
83,50,0,36,122,0,176,25,0,106,2,50,0,20,
1,36,123,0,176,51,0,122,20,1,36,124,0,176,
30,0,20,0,36,125,0,176,52,0,109,50,0,100,
100,20,3,36,126,0,176,53,0,12,0,31,94,36,
127,0,176,25,0,106,2,50,0,20,1,36,128,0,
176,51,0,92,2,20,1,36,129,0,176,30,0,20,
0,36,130,0,176,52,0,109,50,0,100,100,20,3,
36,131,0,176,53,0,12,0,31,29,36,132,0,176,
25,0,106,2,49,0,20,1,36,133,0,176,31,0,
122,20,1,36,134,0,26,106,255,36,136,0,176,25,
0,106,2,49,0,20,1,36,144,0,176,25,0,106,
2,50,0,20,1,36,145,0,109,34,0,109,50,0,
5,29,124,3,36,146,0,176,25,0,106,2,49,0,
20,1,36,147,0,176,7,0,109,49,0,121,20,2,
176,8,0,106,2,124,0,20,1,36,148,0,176,7,
0,109,49,0,122,20,2,176,54,0,109,29,0,106,
12,64,82,32,57,57,57,57,57,57,57,57,0,20,
2,36,149,0,176,7,0,109,49,0,92,10,20,2,
176,54,0,176,20,0,109,55,0,12,1,106,5,64,
83,51,57,0,20,2,36,150,0,109,56,0,106,2,
82,0,5,28,22,36,151,0,109,57,0,83,58,0,
36,152,0,109,59,0,83,60,0,25,20,36,154,0,
109,61,0,83,58,0,36,155,0,109,62,0,83,60,
0,36,157,0,176,25,0,106,2,50,0,20,1,36,
158,0,176,7,0,109,49,0,92,50,20,2,176,54,
0,109,36,0,106,9,64,82,32,57,57,57,57,57,
0,20,2,36,159,0,176,7,0,109,49,0,92,60,
20,2,176,54,0,109,63,0,106,9,64,82,32,57,
57,57,57,57,0,20,2,36,160,0,176,7,0,109,
49,0,92,70,20,2,176,54,0,109,64,0,106,9,
64,82,32,57,57,57,57,57,0,20,2,36,161,0,
176,7,0,109,49,0,92,80,20,2,176,54,0,109,
65,0,121,5,28,5,121,25,3,122,106,5,64,82,
32,57,0,20,2,36,162,0,176,7,0,109,49,0,
92,85,20,2,176,54,0,109,58,0,106,20,64,82,
32,40,88,88,41,32,88,88,88,88,88,45,88,88,
88,88,88,0,20,2,36,163,0,176,7,0,109,49,
0,92,105,20,2,176,54,0,109,60,0,106,20,64,
82,32,40,88,88,41,32,88,88,88,88,88,45,88,
88,88,88,88,0,20,2,36,164,0,176,7,0,109,
49,0,93,134,0,20,2,176,8,0,106,2,124,0,
20,1,36,165,0,109,49,0,122,72,83,49,0,36,
166,0,176,7,0,109,49,0,121,20,2,176,8,0,
106,2,124,0,20,1,36,167,0,176,25,0,106,2,
49,0,20,1,36,168,0,109,56,0,106,2,82,0,
5,29,134,0,36,170,0,176,7,0,109,49,0,92,
15,20,2,176,8,0,106,14,82,69,83,73,68,69,
78,67,73,65,76,58,32,0,176,20,0,109,66,0,
12,1,72,106,4,32,45,32,0,72,176,20,0,109,
67,0,12,1,72,106,4,32,45,32,0,72,176,20,
0,109,68,0,12,1,72,106,4,32,45,32,0,72,
176,20,0,109,69,0,12,1,72,106,4,32,45,32,
0,72,176,70,0,109,71,0,122,92,5,12,3,72,
106,2,45,0,72,176,70,0,109,71,0,92,6,92,
3,12,3,72,20,1,26,131,0,36,173,0,176,7,
0,109,49,0,92,15,20,2,176,8,0,106,14,67,
79,77,69,82,67,73,65,76,32,32,58,32,0,176,
20,0,109,72,0,12,1,72,106,4,32,45,32,0,
72,176,20,0,109,73,0,12,1,72,106,4,32,45,
32,0,72,176,20,0,109,74,0,12,1,72,106,4,
32,45,32,0,72,176,20,0,109,75,0,12,1,72,
106,4,32,45,32,0,72,176,70,0,109,76,0,122,
92,5,12,3,72,106,2,45,0,72,176,70,0,109,
76,0,92,6,92,3,12,3,72,20,1,36,175,0,
176,7,0,109,49,0,93,134,0,20,2,176,8,0,
106,2,124,0,20,1,36,176,0,109,49,0,122,72,
83,49,0,36,177,0,176,7,0,109,49,0,121,20,
2,176,8,0,106,2,124,0,20,1,36,178,0,176,
25,0,106,2,49,0,20,1,36,179,0,176,7,0,
109,49,0,92,15,20,2,176,8,0,106,14,69,45,
77,65,73,76,32,80,82,79,80,58,32,0,176,20,
0,109,77,0,12,1,72,20,1,36,180,0,176,7,
0,109,49,0,93,134,0,20,2,176,8,0,106,2,
124,0,20,1,36,181,0,176,25,0,106,2,50,0,
20,1,36,182,0,176,31,0,122,20,1,36,183,0,
109,49,0,122,72,83,49,0,26,185,3,36,185,0,
109,35,0,109,50,0,5,29,169,3,36,186,0,176,
25,0,106,2,49,0,20,1,36,187,0,176,7,0,
109,49,0,121,20,2,176,8,0,106,2,124,0,20,
1,36,188,0,176,7,0,109,49,0,122,20,2,176,
54,0,109,29,0,106,12,64,82,32,57,57,57,57,
57,57,57,57,0,20,2,36,189,0,176,7,0,109,
49,0,92,10,20,2,176,54,0,176,20,0,109,55,
0,12,1,106,5,64,83,51,57,0,20,2,36,190,
0,109,56,0,106,2,82,0,5,28,22,36,191,0,
109,57,0,83,58,0,36,192,0,109,59,0,83,60,
0,25,20,36,194,0,109,61,0,83,58,0,36,195,
0,109,62,0,83,60,0,36,197,0,176,25,0,106,
2,50,0,20,1,36,198,0,176,7,0,109,49,0,
92,50,20,2,176,54,0,109,36,0,106,9,64,82,
32,57,57,57,57,57,0,20,2,36,199,0,176,7,
0,109,49,0,92,60,20,2,176,54,0,109,63,0,
106,9,64,82,32,57,57,57,57,57,0,20,2,36,
200,0,176,7,0,109,49,0,92,70,20,2,176,54,
0,109,64,0,106,9,64,82,32,57,57,57,57,57,
0,20,2,36,201,0,176,7,0,109,49,0,92,80,
20,2,176,8,0,106,2,50,0,20,1,36,202,0,
176,7,0,109,49,0,92,85,20,2,176,54,0,109,
58,0,106,20,64,82,32,40,88,88,41,32,88,88,
88,88,88,45,88,88,88,88,88,0,20,2,36,203,
0,176,7,0,109,49,0,92,105,20,2,176,54,0,
109,60,0,106,20,64,82,32,40,88,88,41,32,88,
88,88,88,88,45,88,88,88,88,88,0,20,2,36,
204,0,176,7,0,109,49,0,93,134,0,20,2,176,
8,0,106,2,124,0,20,1,36,205,0,109,49,0,
122,72,83,49,0,36,206,0,176,7,0,109,49,0,
121,20,2,176,8,0,106,2,124,0,20,1,36,207,
0,176,25,0,106,2,49,0,20,1,36,208,0,109,
56,0,106,2,82,0,5,29,134,0,36,210,0,176,
7,0,109,49,0,92,15,20,2,176,8,0,106,14,
82,69,83,73,68,69,78,67,73,65,76,58,32,0,
176,20,0,109,66,0,12,1,72,106,4,32,45,32,
0,72,176,20,0,109,67,0,12,1,72,106,4,32,
45,32,0,72,176,20,0,109,68,0,12,1,72,106,
4,32,45,32,0,72,176,20,0,109,69,0,12,1,
72,106,4,32,45,32,0,72,176,70,0,109,71,0,
122,92,5,12,3,72,106,2,45,0,72,176,70,0,
109,71,0,92,6,92,3,12,3,72,20,1,26,131,
0,36,213,0,176,7,0,109,49,0,92,15,20,2,
176,8,0,106,14,67,79,77,69,82,67,73,65,76,
32,32,58,32,0,176,20,0,109,72,0,12,1,72,
106,4,32,45,32,0,72,176,20,0,109,73,0,12,
1,72,106,4,32,45,32,0,72,176,20,0,109,74,
0,12,1,72,106,4,32,45,32,0,72,176,20,0,
109,75,0,12,1,72,106,4,32,45,32,0,72,176,
70,0,109,76,0,122,92,5,12,3,72,106,2,45,
0,72,176,70,0,109,76,0,92,6,92,3,12,3,
72,20,1,36,215,0,176,7,0,109,49,0,93,134,
0,20,2,176,8,0,106,2,124,0,20,1,36,216,
0,109,49,0,122,72,83,49,0,36,217,0,176,7,
0,109,49,0,121,20,2,176,8,0,106,2,124,0,
20,1,36,218,0,176,25,0,106,2,49,0,20,1,
36,219,0,176,7,0,109,49,0,92,15,20,2,176,
8,0,106,14,69,45,77,65,73,76,32,80,82,79,
80,58,32,0,176,20,0,109,77,0,12,1,72,20,
1,36,220,0,176,7,0,109,49,0,93,134,0,20,
2,176,8,0,106,2,124,0,20,1,36,221,0,176,
25,0,106,2,50,0,20,1,36,222,0,176,31,0,
122,20,1,36,223,0,109,49,0,122,72,83,49,0,
36,224,0,176,78,0,20,0,36,225,0,109,79,0,
28,48,36,226,0,176,41,0,92,20,106,7,83,67,
82,69,69,78,0,20,2,36,227,0,176,80,0,20,
0,176,25,0,106,2,49,0,20,1,176,81,0,100,
20,1,36,228,0,7,36,232,0,176,25,0,106,2,
50,0,20,1,36,233,0,109,34,0,109,50,0,69,
28,11,109,35,0,109,50,0,69,31,10,176,38,0,
12,0,29,145,0,36,234,0,176,25,0,106,2,49,
0,20,1,36,235,0,176,31,0,122,20,1,36,236,
0,176,78,0,20,0,36,237,0,109,79,0,29,182,
247,36,238,0,109,23,0,106,8,65,82,81,85,73,
86,79,0,5,28,39,36,239,0,176,41,0,92,23,
106,4,79,70,70,0,20,2,36,240,0,176,41,0,
92,20,106,7,83,67,82,69,69,78,0,20,2,25,
21,36,242,0,176,41,0,92,20,106,7,83,67,82,
69,69,78,0,20,2,36,244,0,176,80,0,20,0,
176,25,0,106,2,49,0,20,1,176,81,0,100,20,
1,36,245,0,100,110,7,36,249,0,109,49,0,92,
54,16,29,251,247,36,250,0,176,7,0,92,58,121,
20,2,176,8,0,176,48,0,106,2,61,0,93,135,
0,12,2,20,1,36,251,0,176,7,0,92,59,92,
104,20,2,176,8,0,109,82,0,20,1,36,252,0,
176,7,0,122,121,20,2,176,8,0,106,2,32,0,
109,83,0,72,20,1,36,253,0,176,7,0,122,121,
20,2,176,8,0,109,42,0,106,11,69,109,112,114,
101,115,97,32,58,32,0,72,109,43,0,72,20,1,
36,254,0,176,7,0,122,92,115,20,2,176,8,0,
106,8,68,97,116,97,32,58,32,0,176,44,0,176,
45,0,12,0,12,1,72,20,1,36,255,0,176,7,
0,92,2,121,20,2,176,8,0,106,11,83,105,115,
116,101,109,97,32,58,32,0,109,46,0,72,20,1,
36,0,1,176,7,0,92,2,92,115,20,2,176,8,
0,106,14,82,101,108,97,116,58,32,83,65,78,48,
48,49,0,20,1,36,1,1,176,7,0,92,3,92,
40,20,2,176,8,0,109,47,0,106,21,67,65,68,
65,83,84,82,79,32,68,69,32,67,76,73,69,78,
84,69,83,0,72,109,42,0,72,20,1,36,2,1,
176,7,0,92,4,121,20,2,176,8,0,176,48,0,
106,2,61,0,93,135,0,12,2,20,1,36,3,1,
176,7,0,92,5,121,20,2,176,8,0,106,2,124,
0,20,1,36,4,1,176,7,0,92,5,92,2,20,
2,176,8,0,106,7,67,111,100,105,103,111,0,20,
1,36,5,1,176,7,0,92,5,92,10,20,2,176,
8,0,106,5,78,111,109,101,0,20,1,36,6,1,
176,7,0,92,5,92,50,20,2,176,8,0,106,9,
80,114,111,100,117,116,111,46,0,20,1,36,7,1,
176,7,0,92,5,92,60,20,2,176,8,0,106,6,
71,114,117,112,111,0,20,1,36,8,1,176,7,0,
92,5,92,70,20,2,176,8,0,106,6,85,110,105,
100,46,0,20,1,36,9,1,176,7,0,92,5,92,
80,20,2,176,8,0,106,6,80,97,114,116,101,0,
20,1,36,10,1,176,7,0,92,5,93,134,0,20,
2,176,8,0,106,2,124,0,20,1,36,11,1,176,
7,0,92,6,121,20,2,176,8,0,176,48,0,106,
2,61,0,93,135,0,12,2,20,1,36,12,1,92,
7,83,49,0,36,13,1,26,240,245,36,16,1,176,
7,0,92,56,121,20,2,176,8,0,176,48,0,106,
2,61,0,93,135,0,12,2,20,1,36,17,1,176,
7,0,92,57,92,104,20,2,176,8,0,109,82,0,
20,1,36,18,1,176,7,0,122,121,20,2,176,8,
0,106,2,32,0,109,83,0,72,20,1,26,12,243,
36,21,1,109,23,0,106,8,65,82,81,85,73,86,
79,0,5,28,52,36,22,1,176,41,0,92,24,106,
1,0,20,2,36,23,1,176,41,0,92,23,106,4,
79,70,70,0,20,2,36,24,1,176,41,0,92,20,
106,7,83,67,82,69,69,78,0,20,2,25,34,36,
26,1,176,41,0,92,24,106,1,0,20,2,36,27,
1,176,41,0,92,20,106,7,83,67,82,69,69,78,
0,20,2,36,29,1,176,80,0,20,0,36,30,1,
176,80,0,20,0,176,25,0,106,2,49,0,20,1,
176,81,0,100,20,1,36,31,1,100,110,7
};
hb_vmExecute( pcode, symbols );
}
|
f69b5cf4f4c6256b6d4375146c99baaedd24bcb6
|
4df965fa9d1effd61a651f61676d8ae6f3511769
|
/build_in/fn_unset.c
|
06cd2f237cb66c38419edec0a48f1cd1bcc16416
|
[] |
no_license
|
AliyaZa/minishell
|
aa8b2f36fe6c0064ce8d6d58b05c10e629ca2957
|
2bdd2d1394a326f5879f72a8d9173ece516660ba
|
refs/heads/main
| 2023-05-26T21:00:26.145928 | 2021-06-13T14:14:14 | 2021-06-13T14:14:14 | 348,753,498 | 0 | 0 | null | 2021-04-20T13:26:53 | 2021-03-17T15:09:44 |
C
|
UTF-8
|
C
| false | false | 1,630 |
c
|
fn_unset.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fn_unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nhill <nhill@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/23 16:38:20 by nhill #+# #+# */
/* Updated: 2021/04/12 16:26:07 by nhill ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
static void fn_del_el(t_env **root)
{
if ((*root)->key)
{
free((*root)->key);
(*root)->key = NULL;
}
if ((*root)->value)
{
free((*root)->value);
(*root)->value = NULL;
}
}
void fn_unset(t_parsed_data *parsed_data, t_command *command)
{
t_env *prev;
t_env *root;
root = parsed_data->env_data;
if (fn_search(parsed_data->env_data->key, command->argument))
parsed_data->env_data = parsed_data->env_data->next;
else
{
while (root->next)
{
prev = root;
root = root->next;
if (fn_search(root->key, command->argument))
{
prev->next = root->next;
fn_del_el(&root);
if (root)
free(root);
root = NULL;
break ;
}
}
}
root = parsed_data->env_data;
}
|
6357e36535e5503eb60f133351a7005aa51f1495
|
384cbec7a47d32526079dbe7c1e5e0727ccdc9a0
|
/firmware/Src/embd_sys_esp8266.c
|
572813d25d9e1d52ab644b6e047b19284cd90deb
|
[] |
no_license
|
Contrix/VUT_FIT_BP
|
58edbb71cb5fc17b4a5db314d6d3c5e05a6aeafe
|
a2b6b6b40ae01ad9935a2402ec03d219b9d9791d
|
refs/heads/master
| 2020-08-27T12:58:54.862239 | 2019-10-24T19:50:18 | 2019-10-24T19:50:18 | 217,377,463 | 0 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 6,942 |
c
|
embd_sys_esp8266.c
|
/**
* Water level monitoring
* ESP8266 module
* @Author HanakJiri, xhanak33
* @file embd_sys_esp8266.c
*/
#include "../Inc/embd_sys_esp8266.h"
uint8_t ESP_init(char *msg, char *ssid, char *password) {
ESP_restart();
if (ESP_test() ||
ESP_set_feedback(false_e) ||
//ESP_set_autoconnect(false_e) ||
ESP_set_mode(ESP_CWMODE_AP) ||
ESP_set_multiple_connections(false_e)) {
sprintf(msg, "ESP init failed.\r\n");
return EMBD_FAILURE;
}
if (ESP_connect_to_wifi(ssid, password)) {
sprintf(msg, "Connect to wifi failed.\r\n");
return EMBD_FAILURE;
}
if (ESP_get_IP(esp_buffer)) {
sprintf(msg, "Can not get IP.\r\n");
return EMBD_FAILURE;
}
return EMBD_SUCCESS;
}
void ESP_restart() {
sprintf(esp_cmd_buffer, "AT+RST");
ESP_send_command();
uint16_t limit = 0;
do {
UART_read_line(UART_ESP8266, esp_buffer, ESP_BUFFER_SIZE, ESP_TIMEOUT);
} while (strcmp(esp_buffer, "ready\r\n") != 0 && limit++ < ESP_LINES_LIMIT);
}
void ESP_send_command() {
uint16_t len = (uint16_t) strlen(esp_cmd_buffer);
esp_cmd_buffer[len++] = '\r';
esp_cmd_buffer[len++] = '\n';
UART_flush_Rx(UART_ESP8266);
UART_send_message(UART_ESP8266, esp_cmd_buffer, len);
bzero(esp_cmd_buffer, ESP_CMD_BUFFER_SIZE);
}
void ESP_send_data(char* data, uint16_t size) {
UART_send_message(UART_ESP8266, data, size);
}
uint8_t ESP_check_response() {
uint16_t limit = 0;
do {
UART_read_line(UART_ESP8266, esp_buffer, ESP_BUFFER_SIZE, 500);
if (strcmp(esp_buffer, "FAIL\r\n") == 0 ||
strcmp(esp_buffer, "ERROR\r\n") == 0) {
return EMBD_FAILURE;
}
if (strcmp(esp_buffer, "SEND OK\r\n") == 0 ||
strcmp(esp_buffer, "CLOSED\r\n") == 0) {
return EMBD_SUCCESS;
}
} while (strcmp(esp_buffer, "OK\r\n") != 0 && limit++ < ESP_LINES_LIMIT);
return EMBD_SUCCESS;
}
uint8_t ESP_test() {
sprintf(esp_cmd_buffer, "AT");
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_sleep(uint32_t time) {
sprintf(esp_cmd_buffer, "AT+GSLP=%"PRIu32, time);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_ping(char* ip_addres) {
sprintf(esp_cmd_buffer, "AT+PING=\"%s\"", ip_addres);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_set_mode(uint8_t mode) {
if (mode < 1 || mode > 3) {
return EMBD_FAILURE;
}
sprintf(esp_cmd_buffer, "AT+CWMODE=%u", mode);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_set_feedback(uint8_t mode) {
if (mode > 1) {
return EMBD_FAILURE;
}
sprintf(esp_cmd_buffer, "ATE%u", mode);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_set_autoconnect(uint8_t mode) {
if (mode > 1) {
return EMBD_FAILURE;
}
sprintf(esp_cmd_buffer, "AT+CWAUTOCONN=%u", mode);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_set_multiple_connections(uint8_t mode) {
if (mode > 1) {
return EMBD_FAILURE;
}
sprintf(esp_cmd_buffer, "AT+CIPMUX=%u", mode);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_connect_to_wifi(char *ssid, char *password) {
sprintf(esp_cmd_buffer, "AT+CWJAP=\"%s\",\"%s\"", ssid, password);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_get_IP(char *msg) {
char ip[32];
sprintf(esp_cmd_buffer, "AT+CIFSR");
ESP_send_command();
//UART_read_line(UART_ESP8266, esp_buffer, ESP_BUFFER_SIZE, ESP_TIMEOUT);
//UART_read_line(UART_ESP8266, esp_buffer, ESP_BUFFER_SIZE, ESP_TIMEOUT);
//UART_read_line(UART_ESP8266, esp_buffer, ESP_BUFFER_SIZE, ESP_TIMEOUT);
sscanf(esp_buffer, "+CIFSR:STAIP,\"%s\"", ip); // STAIP
if (strcmp(ip, "0.0.0.0") == 0) {
sprintf(msg, "Unable to get IP address.\r\n");
return EMBD_FAILURE;
}
UART_read_line(UART_ESP8266, esp_buffer, ESP_BUFFER_SIZE, ESP_TIMEOUT);
return ESP_check_response();
}
uint8_t ESP_open_TCP_connection(char *ip, uint16_t port) {
sprintf(esp_cmd_buffer, "AT+CIPSTART=\"TCP\",\"%s\",%u", ip, port);
ESP_send_command();
return ESP_check_response();
}
uint8_t ESP_send_TCP_data(char* data, uint16_t len) {
sprintf(esp_cmd_buffer, "AT+CIPSEND=%u", len);
ESP_send_command();
if (ESP_check_response() == EMBD_SUCCESS) {
ESP_send_data(data, len);
} else {
return EMBD_FAILURE;
}
return ESP_check_response();
}
uint8_t ESP_get_response(Vector_t *response, char *msg) {
uint16_t msg_len;
uint16_t limit = 0;
char number[STR_TO_UINT16_BUFFER_SIZE];
Vector_t *buffer = init_vector();
skip_blank_lines(UART_ESP8266);
while (UART_compare_char(UART_ESP8266, '+', ESP_TIMEOUT) == true_e && limit++ < ESP_LINES_LIMIT) {
UART_read_message_until_char(UART_ESP8266, buffer, ':');
if (get_char(buffer) == '+' &&
get_char(buffer) == 'I' &&
get_char(buffer) == 'P' &&
get_char(buffer) == 'D' &&
get_char(buffer) == ',') {
msg_len = 0;
bzero(number, STR_TO_UINT16_BUFFER_SIZE);
for (uint8_t i = 0; i < STR_TO_UINT16_BUFFER_SIZE && buffer->message_len; ++i) {
number[i] = get_char(buffer);
if (i > 5) {
sprintf(msg, "Wrong response format - number length\r\n");
deinit_vector_(buffer);
return EMBD_FAILURE;
}
}
if (!str_to_uint16(number, &msg_len)) {
sprintf(msg, "Wrong response format - number\r\n");
deinit_vector_(buffer);
return EMBD_FAILURE;
}
UART_read_message(UART_ESP8266, response, msg_len, 5000);
} else {
sprintf(msg, "Wrong response format - start character\r\n");
deinit_vector_(buffer);
return EMBD_FAILURE;
}
skip_blank_lines(UART_ESP8266);
}
deinit_vector_(buffer);
return ESP_check_response();
}
uint8_t ESP_TCP_GET(char *ip, uint16_t port, char* data, uint16_t len, char* msg, Vector_t *vector) {
uint8_t open = false_e;
for (uint8_t i = 0; i < 5; ++i) {
if (ESP_open_TCP_connection(ip, port) == EMBD_SUCCESS) {
open = true_e;
break;
}
}
if (!open) {
sprintf(msg, "Unable to connect to server.\r\n");
return EMBD_FAILURE;
}
if (ESP_send_TCP_data(data, len) == EMBD_FAILURE) {
sprintf(msg, "Data transfer failed.\r\n");
return EMBD_FAILURE;
}
if (ESP_get_response(vector, msg) == EMBD_FAILURE) {
return EMBD_FAILURE;
}
return EMBD_SUCCESS;
}
|
5491058e5c10f996954bc827d229f8ed295f8021
|
52a72b44f5449264ffbf2478d7ff4337cb06d467
|
/set2-6.c
|
6e13aee2ef54a7f12a4af5e81d06738508ccfc2e
|
[] |
no_license
|
Buttu1/c-programming
|
3b5b113e5517fc2e5cf1be61836319d366274e94
|
00c6e5c7c519a922c696bc6a2b0f3f9bfb8d9ec1
|
refs/heads/master
| 2020-04-13T04:19:32.377348 | 2019-02-19T11:06:44 | 2019-02-19T11:06:44 | 162,958,001 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 219 |
c
|
set2-6.c
|
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,i.j,c[20],k=0;
scanf("%d %d",&a,&b);
for(i=a;i<=b;i++)
{
for(j=2;j<=b/2;j++)
{
if(i%j!=0)
{
c[k]=i;
k++;
}
}
for(k=0;k<=b;k++)
{
printf("%d",c[k]);
}
getch();
}
|
e1c31cba28e313f3c6cecc50c6586e464e0a9313
|
e732bd7e451dea33190f256d5fd9d2eccf33dd30
|
/BaiTapTinHoc/Bai3.c
|
dfc875d7eac8d291214f4a89d375f08f72302b14
|
[] |
no_license
|
samreachyan/BKCodes
|
4f9486ceb8a27db29cc3d8ac584cc233a17918bd
|
fa91a55d9ef7e48aeb3be3589040c7bd9be128b2
|
refs/heads/master
| 2023-02-17T22:46:07.287094 | 2021-01-12T04:59:45 | 2021-01-12T04:59:45 | 192,798,916 | 5 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 262 |
c
|
Bai3.c
|
#include<stdio.h>
#include<math.h>
int main(int argc, char const *argv[])
{
float x, fx=0;
printf("Nhap vao so x : ");
scanf("%f", &x);
if ( x >= 0 ) {
fx = pow(3,2*x) + 5 ;
} else {
fx = ((log(-x)/log(3))+1)/3;
}
printf("%0.4f\n", fx);
return 0;
}
|
530bc58cfbf508ff5850b2d0892fed9fc2ed35ca
|
0c605e1a5ae4139b44246c82e8332fd0447ac191
|
/serial_code/old versions/klarasimplementation/assign_3d.c
|
c6ce38f7d8f3441e8fa0cfcbbe2db5abb096a45c
|
[] |
no_license
|
HPC-01-21/Project-2-Poisson
|
8b0abc56e3cb0325cbe944a85e043bb277552c78
|
e47f7595b4f1b7055dee78cc51977da332ca5a1e
|
refs/heads/main
| 2023-02-16T05:50:32.202892 | 2021-01-15T17:57:07 | 2021-01-15T17:57:07 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 606 |
c
|
assign_3d.c
|
#include <stdio.h>
#include <stdlib.h>
#include "alloc3d.h"
#include "print.h"
void reset_matrix(int n, int k, double **C){
for (int i=0; i<n; i++){
for (int j=0; j<k; j++){
C[i][j]=0;
}
}
}
void assign(double*** arr, int m, int n, int k)
{
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
for (int h=0; h<k; h++)
arr[i][j][h]=f(i,j,h);
}
}
}
int main(int argc, char *argv[]){
int m =10;
int n=10;
int k=10;
char fname='f';
double ***A = d_malloc_3d(m,n,k);
assign(A,m,n,k);
print_vtk(&fname, 100, A);
return 0;
}
|
60d0b81f860d0efc2cce0dcf6b322472909d15c5
|
1271490fcdd0ff8342780d62298bb2475d9fe895
|
/offer.test3/offer.test2/TwoDimensionalArrayFind.h
|
0aaf9cceda2f7d5f544f65870ab22f546880b6c1
|
[] |
no_license
|
comedly/liu153
|
a6299d59fa49ccf927ccbcc6aa6f3505b75ff872
|
5e075da878721a6895902ff47c6a26a07284a00c
|
refs/heads/master
| 2021-01-17T02:55:56.667658 | 2016-10-27T15:47:46 | 2016-10-27T15:47:46 | 59,343,526 | 0 | 0 | null | null | null | null |
GB18030
|
C
| false | false | 1,089 |
h
|
TwoDimensionalArrayFind.h
|
#pragma once
//二维数组的查找
//每一行从左向右递增,每一列从上向下递增
//1 2 8 9
//2 4 9 12
//4 7 10 13
//6 8 11 15
//若在数组中查找7,则返回true,若在数组中查找5,返回false
bool Find(int* Array,int rows,int columns,int number)
{
bool found = false;//记录返回值
if(Array != NULL && rows > 0 && columns > 0)
{
//从右上角的元素开始,等于要查找的元素返回true,数组的元素无论是行还是列都是递增的,最后一列的第一个元素是该列中最小的,大于要查找的元素时,剔除掉该列,column--,再从右上角开始,如果右上角的元素小于要查找的元素时,因为每一行的最后一个元素是最大的,所以row++;以此类推,直到找到为止。
int row = 0;
int column = columns - 1;
while (row < rows && column >= 0)
{
if(Array[row*columns + column] == number)
{
found = true;
break;
}
else if(Array[row*columns + column] > number)
{
--column;
}
else
{
++row;
}
}
}
return found;
}
|
88b6d036ecdf402f74ddd017615b8d43e4f986c6
|
9d364070c646239b2efad7abbab58f4ad602ef7b
|
/platform/external/ebtables/kernel/linux/include/linux/netfilter_bridge/ebt_limit.h
|
9ae04b497f5e1ab909ffd0929663b95812b5e9e9
|
[] |
no_license
|
denix123/a32_ul
|
4ffe304b13c1266b6c7409d790979eb8e3b0379c
|
b2fd25640704f37d5248da9cc147ed267d4771c2
|
refs/heads/master
| 2021-01-17T20:21:17.196296 | 2016-08-16T04:30:53 | 2016-08-16T04:30:53 | 65,786,970 | 0 | 2 | null | 2020-03-06T22:00:52 | 2016-08-16T04:15:54 | null |
UTF-8
|
C
| false | false | 283 |
h
|
ebt_limit.h
|
#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
#define __LINUX_BRIDGE_EBT_LIMIT_H
#define EBT_LIMIT_MATCH "limit"
#define EBT_LIMIT_SCALE 10000
struct ebt_limit_info
{
u_int32_t avg;
u_int32_t burst;
unsigned long prev;
u_int32_t credit;
u_int32_t credit_cap, cost;
};
#endif
|
ceb6f2fdd624f36715d93cb867a74df659ca3425
|
8b219af66fbf3b751191f2f696bdd683e1d136d1
|
/src/io/ft_putstr.c
|
b9b6373c7c93582fa8d08076ae3472a95e2b47c0
|
[] |
no_license
|
akarasso/Libft_v3
|
07557469a140458c34c041a522edeeb8f9524453
|
1192517e763a3d0d7b2ad07c0394f8fd47aa784a
|
refs/heads/master
| 2020-04-26T03:50:25.308675 | 2019-06-03T15:32:28 | 2019-06-03T15:32:28 | 173,281,003 | 3 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 977 |
c
|
ft_putstr.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akarasso <akarasso@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/03 17:51:53 by akarasso #+# #+# */
/* Updated: 2019/03/24 19:30:37 by akarasso ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_libft.h"
void ft_putstr(char const *s)
{
write(1, s, ft_strlen(s));
}
|
2440d1a7ec43cf5bce8e162ba99f5cd0bca2f945
|
100ecfb2892454d6dd4d5e15817ae428e2262401
|
/prj/fbl/CBD1500748_D04_Rh850/BSW/WrapNv/_WrapNv_inc.h
|
1eb878be7ef5b762706b586dd9585026e8f443c5
|
[
"BSD-2-Clause"
] |
permissive
|
SuperLu/rh850_osek
|
1e46889b6929c511b12bd0940a96d009a486310c
|
1371efd161383472da4d4589eed52cd0d99b3021
|
refs/heads/master
| 2017-12-05T08:30:00.875782 | 2017-05-17T23:33:40 | 2017-05-17T23:33:40 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,225 |
h
|
_WrapNv_inc.h
|
/***********************************************************************************************************************
* FILE DESCRIPTION
* ------------------------------------------------------------------------------------------------------------------*/
/** \file
* \brief Compacts the include files for the NV-Wrapper
*
* --------------------------------------------------------------------------------------------------------------------
* COPYRIGHT
* --------------------------------------------------------------------------------------------------------------------
* \par Copyright
* \verbatim
* Copyright (c) 2012 by Vector Informatik GmbH. All rights reserved.
*
* This software is copyright protected and proprietary to Vector Informatik GmbH.
* Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
* All other rights remain with Vector Informatik GmbH.
* \endverbatim
*/
/**********************************************************************************************************************/
/***********************************************************************************************************************
* AUTHOR IDENTITY
* --------------------------------------------------------------------------------------------------------------------
* Name Initials Company
* --------------------------------------------------------------------------------------------------------------------
* Christian Baeuerle CB Vector Informatik GmbH
* Achim Strobelt Ach Vector Informatik GmbH
* --------------------------------------------------------------------------------------------------------------------
* REVISION HISTORY
* --------------------------------------------------------------------------------------------------------------------
* Version Date Author Change Id Description
* --------------------------------------------------------------------------------------------------------------------
* 01.00.00 2009-07-08 CB Initial implementation
* 01.01.00 2012-01-26 Ach No changes
* 01.02.00 2012-11-29 Ach ESCAN00062931 Adapted comments to use Doxygen
**********************************************************************************************************************/
#ifndef __WRAPPERNV_INC_H__
#define __WRAPPERNV_INC_H__
/* Include Vector standard includes first */
#include "v_cfg.h"
#include "v_def.h"
#include "fbl_inc.h"
#if defined( FBL_ENABLE_EEPMGR )
# include "iotypes.h"
# include "fbl_flio_Xd.h"
# include "EepMgr_inc.h"
#else
# include "iotypes.h"
# include "eepinc.h"
# include "eepio.h"
#endif
#include "WrapNv.h"
#endif /* __WRAPPERNV_INC_H__ */
/***********************************************************************************************************************
* END OF FILE: _WRAPNV_INC.H
**********************************************************************************************************************/
|
2c7c929e94b88487aa70a49aa4945f6ff0913e51
|
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
|
/source/linux/drivers/video/fbdev/extr_da8xx-fb.c_cfb_blank.c
|
45ab216ff3a27619c042b2a319af5a137dc13924
|
[] |
no_license
|
isabella232/AnghaBench
|
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
|
9a5f60cdc907a0475090eef45e5be43392c25132
|
refs/heads/master
| 2023-04-20T09:05:33.024569 | 2021-05-07T18:36:26 | 2021-05-07T18:36:26 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,608 |
c
|
extr_da8xx-fb.c_cfb_blank.c
|
#define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
/* Type definitions */
struct fb_info {struct da8xx_fb_par* par; } ;
struct da8xx_fb_par {int blank; int /*<<< orphan*/ lcd_supply; } ;
/* Variables and functions */
int /*<<< orphan*/ DA8XX_FRAME_WAIT ;
int EINVAL ;
#define FB_BLANK_HSYNC_SUSPEND 132
#define FB_BLANK_NORMAL 131
#define FB_BLANK_POWERDOWN 130
#define FB_BLANK_UNBLANK 129
#define FB_BLANK_VSYNC_SUSPEND 128
int /*<<< orphan*/ lcd_disable_raster (int /*<<< orphan*/ ) ;
int /*<<< orphan*/ lcd_enable_raster () ;
int regulator_disable (int /*<<< orphan*/ ) ;
int regulator_enable (int /*<<< orphan*/ ) ;
__attribute__((used)) static int cfb_blank(int blank, struct fb_info *info)
{
struct da8xx_fb_par *par = info->par;
int ret = 0;
if (par->blank == blank)
return 0;
par->blank = blank;
switch (blank) {
case FB_BLANK_UNBLANK:
lcd_enable_raster();
if (par->lcd_supply) {
ret = regulator_enable(par->lcd_supply);
if (ret)
return ret;
}
break;
case FB_BLANK_NORMAL:
case FB_BLANK_VSYNC_SUSPEND:
case FB_BLANK_HSYNC_SUSPEND:
case FB_BLANK_POWERDOWN:
if (par->lcd_supply) {
ret = regulator_disable(par->lcd_supply);
if (ret)
return ret;
}
lcd_disable_raster(DA8XX_FRAME_WAIT);
break;
default:
ret = -EINVAL;
}
return ret;
}
|
94311ca255d468610e2536cc4878ff2863f2b6cf
|
b759314eed7edf6e27ca8d2381ac73835e54cb3d
|
/assembler/src/symtable.c
|
4bf9b5a8962866eee6977090a2184b746e54ea70
|
[
"BSD-2-Clause-Views"
] |
permissive
|
theepot/esc64
|
a352c026b8549b182dab58b48e615072a8241a42
|
1d4110318fe4631002971666e707a669a4e926e3
|
refs/heads/master
| 2016-09-06T00:48:07.743363 | 2014-08-25T14:24:17 | 2014-08-25T14:24:17 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 2,416 |
c
|
symtable.c
|
#include <esc64asm/symtable.h>
#include <assert.h>
#include <string.h>
static int CompareEntry(const void* a, const void* b);
static Hash_t HashEntry(const void* entry);
static void DumpEntry(FILE* stream, const void* entry_);
static const char* PutString(SymTable* table, const char* str, size_t strSize);
void SymTableInit(SymTable* table, void* setMem, size_t setMemSize, void* strMem, size_t strMemSize)
{
HashSetInit(&table->set, setMem, setMemSize, sizeof(SymTableEntry), HashEntry, CompareEntry);
table->strPool.mem = strMem;
table->strPool.size = strMemSize;
table->strPool.i = 0;
}
int SymTableInsert(SymTable* table, const char* sym, size_t symSize, uword_t addr)
{
const char* sym_ = PutString(table, sym, symSize);
SymTableEntry entry = { symSize, sym_, addr };
int r = HashSetInsert(&table->set, &entry);
if(r)
{
table->strPool.i -= symSize;
}
return r;
}
int SymTableFind(SymTable* table, const char* sym, size_t symSize, uword_t* address)
{
SymTableEntry entry = { symSize, sym, 0 };
SymTableEntry* out = NULL;
int r = HashSetFind(&table->set, &entry, (void**)&out);
if(!r)
{
*address = out->addr;
}
return r;
}
void SymTableDump(SymTable* table, FILE* stream)
{
HashSetDump(stream, &table->set, DumpEntry);
}
static int CompareEntry(const void* a_, const void* b_)
{
SymTableEntry* a = (SymTableEntry*)a_;
SymTableEntry* b = (SymTableEntry*)b_;
return a->symSize == b->symSize && !strncmp(a->sym, b->sym, a->symSize);
}
static Hash_t HashEntry(const void* entry_)
{
SymTableEntry* entry = (SymTableEntry*)entry_;
Hash_t hash = 0;
size_t i;
for(i = 0; i < entry->symSize; ++i)
{
Hash_t c = entry->sym[i];
hash += c;
hash += hash << 10;
hash ^= hash >> 6;
}
hash += hash << 3;
hash ^= hash >> 11;
hash += hash << 15;
return hash;
}
static const char* PutString(SymTable* table, const char* str, size_t strSize)
{
size_t iNew = table->strPool.i + strSize;
assert(iNew <= table->strPool.size);
char* r = &table->strPool.mem[table->strPool.i];
memcpy(r, str, strSize);
table->strPool.i = iNew;
return r;
}
static void DumpEntry(FILE* stream, const void* entry_)
{
const SymTableEntry* entry = (const SymTableEntry*)entry_;
fprintf(stream, "symSize=%u; sym=`", entry->symSize);
size_t i;
for(i = 0; i < entry->symSize; ++i)
{
putc(entry->sym[i], stream);
}
fprintf(stream, "'; addr=0x%X(%u);", entry->addr, entry->addr);
}
|
4a0fd1e1dd6c773961da460bef41b876ab530644
|
d1c9d7a27fc19e4e3f8bb3f68365cdfd8d5c52aa
|
/server/data/user.c
|
0929f65c8d243b79f18c2576bf8635110413fb0e
|
[] |
no_license
|
SanzenSekai4/ChatBerry
|
c2733649bfb21c9b3d40556f22c208c4052372c2
|
2d465118a021434b0ec1706140a163627d1d61c5
|
refs/heads/master
| 2021-01-01T18:53:23.925542 | 2017-07-26T21:50:37 | 2017-07-26T21:50:37 | 98,461,040 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 417 |
c
|
user.c
|
#include <stdlib.h>
#include "user.h"
user_t * init_user(uint32_t ip, char * name, char * pass, uint8_t red, uint8_t green, uint8_t blue) {
user_t * user = malloc(sizeof(struct user_s));
user->(ip.entier) = ip;
user->name = name;
user->pass = pass;
(user->rgb)[0] = red;
(user->rgb)[0] = green;
(user->rgb)[0] = blue;
return user;
}
void delete_user(user_t * user) {
free(user);
user = NULL;
}
|
e676997cb569f36cc1382df71abacb5a9a712221
|
29368fb88fc557b8481087000c62872999cb521d
|
/aix-4.1.3/bos/usr/ccs/lib/libc/setrgid.c
|
5d7b3d4970e620695ed2fd7cc1b630a6cf228de5
|
[] |
no_license
|
legacy-codedigger/aix-4.1.3
|
07101a0795fe56fe97e8fe06d469142bb65371d5
|
2f37969bee9c0fb7c0a2490e5a82533acac03d39
|
refs/heads/master
| 2022-05-17T01:18:52.520939 | 2020-04-25T00:38:20 | 2020-04-25T00:38:20 | 258,655,180 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 798 |
c
|
setrgid.c
|
static char sccsid[] = "@(#)38 1.5 src/bos/usr/ccs/lib/libc/setrgid.c, libcs, bos411, 9428A410j 11/17/93 15:13:44";
/*
* COMPONENT_NAME: (LIBCS) Standard C Library System Security Functions
*
* FUNCTIONS: setrgid
*
* ORIGINS: 27
*
* IBM CONFIDENTIAL -- (IBM Confidential Restricted when
* combined with the aggregated modules for this product)
* SOURCE MATERIALS
* (C) COPYRIGHT International Business Machines Corp. 1988, 1989
* All Rights Reserved
*
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
#include <sys/types.h>
#include <sys/errno.h>
/* this function is in violation to the security policy of AIX */
int
setrgid(gid)
gid_t gid;
{
errno = EPERM;
return(-1);
}
|
763d9b67ab706305a0cc06f22d3a8d6fe43cbd45
|
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
|
/source/linux/arch/sparc/kernel/extr_irq_64.c_sysino_set_bucket.c
|
a0a950e15ec510b611924bce64c11aa36d582875
|
[] |
no_license
|
isabella232/AnghaBench
|
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
|
9a5f60cdc907a0475090eef45e5be43392c25132
|
refs/heads/master
| 2023-04-20T09:05:33.024569 | 2021-05-07T18:36:26 | 2021-05-07T18:36:26 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,234 |
c
|
extr_irq_64.c_sysino_set_bucket.c
|
#define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
/* Type definitions */
struct irq_handler_data {int /*<<< orphan*/ dev_ino; int /*<<< orphan*/ dev_handle; } ;
struct ino_bucket {int dummy; } ;
/* Variables and functions */
int /*<<< orphan*/ BUG_ON (int) ;
int /*<<< orphan*/ __pa (struct ino_bucket*) ;
int /*<<< orphan*/ bucket_set_irq (int /*<<< orphan*/ ,unsigned int) ;
struct irq_handler_data* irq_get_handler_data (unsigned int) ;
struct ino_bucket* ivector_table ;
unsigned long nr_ivec ;
unsigned long sun4v_devino_to_sysino (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
__attribute__((used)) static void sysino_set_bucket(unsigned int irq)
{
struct irq_handler_data *ihd = irq_get_handler_data(irq);
struct ino_bucket *bucket;
unsigned long sysino;
sysino = sun4v_devino_to_sysino(ihd->dev_handle, ihd->dev_ino);
BUG_ON(sysino >= nr_ivec);
bucket = &ivector_table[sysino];
bucket_set_irq(__pa(bucket), irq);
}
|
9254cf76f6fa1348363aab8939ef388e35a91719
|
931bad2ace518f23323caa15488ddb434fa2c767
|
/options/Z/i/func.h
|
ee00d3cde71e155a3672bf85b4388d20243ad6fe
|
[] |
no_license
|
ReneNyffenegger/about-cl
|
c05ddab204ab3e8a5d39f545602195831fe3488c
|
4db04c9912f9ef8501c014a2070a96ed16e7340c
|
refs/heads/master
| 2021-06-18T06:36:17.086946 | 2021-02-14T09:34:28 | 2021-02-14T09:34:28 | 166,049,908 | 3 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 36 |
h
|
func.h
|
int func(int arg_one, int arg_two);
|
b5251ce4461a9a0007f99f268b720ba12c395ce1
|
486560a70f178e322ca2f2b521d2185e4677058f
|
/src/app_main.c
|
0324aa02188f1b42054678408d6784fa07e6aed0
|
[
"MIT"
] |
permissive
|
twiggotronix/a9g-pudding-sms
|
1286b779782db3e1212ca88479c808ae48f6065f
|
b87af2f520a43c9079063d3456a85d02ac5a38b7
|
refs/heads/master
| 2020-05-09T17:28:28.911483 | 2019-04-16T08:06:58 | 2019-04-16T08:06:58 | 181,311,047 | 1 | 1 | null | null | null | null |
UTF-8
|
C
| false | false | 6,745 |
c
|
app_main.c
|
/*
* @File app_main.c
* @Brief An example of SDK's mini system
*
* @Author: Neucrack
* @Date: 2017-11-11 16:45:17
* @Last Modified by: Neucrack
* @Last Modified time: 2017-11-11 18:24:56
*/
#include "stdint.h"
#include "stdbool.h"
#include "api_os.h"
#include "api_event.h"
#include "api_debug.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "api_sms.h"
#include "api_hal_uart.h"
#include "include/app_main.h"
#define AppMain_TASK_STACK_SIZE (1024 * 2)
#define AppMain_TASK_PRIORITY 1
HANDLE mainTaskHandle = NULL;
HANDLE otherTaskHandle = NULL;
static uint8_t flag = 0;
void SMSInit()
{
if(!SMS_SetFormat(SMS_FORMAT_TEXT,SIM0))
{
Trace(1,"sms set format error");
return;
}
SMS_Parameter_t smsParam = {
.fo = 17 ,
.vp = 167,
.pid= 0 ,
.dcs= 8 ,//0:English 7bit, 4:English 8 bit, 8:Unicode 2 Bytes
};
if(!SMS_SetParameter(&smsParam,SIM0))
{
Trace(1,"sms set parameter error");
return;
}
if(!SMS_SetNewMessageStorage(SMS_STORAGE_SIM_CARD))
{
Trace(1,"sms set message storage fail");
return;
}
}
void UartInit()
{
UART_Config_t config = {
.baudRate = UART_BAUD_RATE_115200,
.dataBits = UART_DATA_BITS_8,
.stopBits = UART_STOP_BITS_1,
.parity = UART_PARITY_NONE,
.rxCallback = NULL,
};
UART_Init(UART1,config);
}
void Init()
{
UartInit();
SMSInit();
}
void SendSMS(uint8_t message[])
{
uint8_t* unicode = NULL;
uint32_t unicodeLen;
Trace(1,"sms start send UTF-8 message");
if(!SMS_LocalLanguage2Unicode(message,strlen(message),CHARSET_UTF_8,&unicode,&unicodeLen))
{
Trace(1,"local to unicode fail!");
return;
}
if(!SMS_SendMessage(PHONE_NUMBER,unicode,unicodeLen,SIM0))
{
Trace(1,"sms send message fail");
}
OS_Free(unicode);
}
void messageRecieved(uint8_t* content)
{
char buffer[200];
snprintf(buffer, sizeof(buffer), "Message received : %s", content);
Trace(1, buffer);
SendSMS(buffer);
}
void ServerCenterTest()
{
uint8_t addr[32];
uint8_t temp;
SMS_Server_Center_Info_t sca;
sca.addr = addr;
SMS_GetServerCenterInfo(&sca);
Trace(1,"server center address:%s,type:%d",sca.addr,sca.addrType);
temp = sca.addr[strlen(sca.addr)-1];
sca.addr[strlen(sca.addr)-1] = '0';
if(!SMS_SetServerCenterInfo(&sca))
Trace(1,"SMS_SetServerCenterInfo fail");
else
Trace(1,"SMS_SetServerCenterInfo success");
SMS_GetServerCenterInfo(&sca);
Trace(1,"server center address:%s,type:%d",sca.addr,sca.addrType);
sca.addr[strlen(sca.addr)-1] = temp;
if(!SMS_SetServerCenterInfo(&sca))
Trace(1,"SMS_SetServerCenterInfo fail");
else
Trace(1,"SMS_SetServerCenterInfo success");
}
void EventDispatch(API_Event_t* pEvent)
{
switch(pEvent->id)
{
case API_EVENT_ID_NO_SIMCARD:
Trace(10,"!!NO SIM CARD%d!!!!",pEvent->param1);
break;
case API_EVENT_ID_SYSTEM_READY:
Trace(1,"system initialize complete");
flag |= 1;
break;
case API_EVENT_ID_NETWORK_REGISTERED_HOME:
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
Trace(2,"network register success");
flag |= 2;
break;
case API_EVENT_ID_SMS_SENT:
Trace(2,"Send Message Success");
break;
case API_EVENT_ID_SMS_RECEIVED:
Trace(2,"received message");
//SMS_Encode_Type_t encodeType = pEvent->param1;
uint32_t contentLength = pEvent->param2;
uint8_t* header = pEvent->pParam1;
uint8_t* content = pEvent->pParam2;
Trace(2,"message header:%s",header);
Trace(2,"message content length:%d",contentLength);
messageRecieved(content);
break;
case API_EVENT_ID_SMS_LIST_MESSAGE:
{
SMS_Message_Info_t* messageInfo = (SMS_Message_Info_t*)pEvent->pParam1;
Trace(1,"message header index:%d,status:%d,number type:%d,number:%s,time:\"%u/%02u/%02u,%02u:%02u:%02u+%02d\"", messageInfo->index, messageInfo->status,
messageInfo->phoneNumberType, messageInfo->phoneNumber,
messageInfo->time.year, messageInfo->time.month, messageInfo->time.day,
messageInfo->time.hour, messageInfo->time.minute, messageInfo->time.second,
messageInfo->time.timeZone);
Trace(1,"message content len:%d,data:%s",messageInfo->dataLen,messageInfo->data);
UART_Write(UART1, messageInfo->data, messageInfo->dataLen);//use serial tool that support GBK decode if have Chinese, eg: https://github.com/Neutree/COMTool
UART_Write(UART1,"\r\n\r\n",4);
//need to free data here
OS_Free(messageInfo->data);
break;
}
case API_EVENT_ID_SMS_ERROR:
Trace(10,"SMS error occured! cause:%d",pEvent->param1);
default:
break;
}
//system initialize complete and network register complete, now can send message
if(flag == 3)
{
SMS_Storage_Info_t storageInfo;
SendSMS("Ready and able!");
ServerCenterTest();
SMS_GetStorageInfo(&storageInfo,SMS_STORAGE_SIM_CARD);
Trace(1,"sms storage sim card info, used:%d,total:%d",storageInfo.used,storageInfo.total);
SMS_GetStorageInfo(&storageInfo,SMS_STORAGE_FLASH);
Trace(1,"sms storage flash info, used:%d,total:%d",storageInfo.used,storageInfo.total);
if(!SMS_DeleteMessage(5,SMS_STATUS_ALL,SMS_STORAGE_SIM_CARD))
Trace(1,"delete sms fail");
else
Trace(1,"delete sms success");
SMS_ListMessageRequst(SMS_STATUS_ALL,SMS_STORAGE_SIM_CARD);
flag = 0;
}
}
void AppMainTask(void *pData)
{
API_Event_t* event=NULL;
Init();
while(1)
{
if(OS_WaitEvent(mainTaskHandle, &event, OS_TIME_OUT_WAIT_FOREVER))
{
EventDispatch(event);
OS_Free(event->pParam1);
OS_Free(event->pParam2);
OS_Free(event);
}
}
}
void app_Main(void)
{
mainTaskHandle = OS_CreateTask(AppMainTask ,
NULL, NULL, AppMain_TASK_STACK_SIZE, AppMain_TASK_PRIORITY, 0, 0, "init Task");
OS_SetUserMainHandle(&mainTaskHandle);
}
|
2b3b93b3c86e17d12a0b6a4b164028bf52c9766f
|
8e4286d114cd09483018e61caab702ff6a10988b
|
/core/embed/trezorhal/touch_1.h
|
2f66c7bf5267f13e7d39761e96c6b7293b0500f6
|
[
"GPL-3.0-only"
] |
permissive
|
keepkey/trezor-crypto
|
954ca02b8be49d80e031369103ba0667a0a1b3c3
|
6556616681a4e2d7e18817e8692d4f6e041dee01
|
refs/heads/keepkey
| 2020-03-29T10:18:06.918347 | 2019-04-16T22:55:45 | 2019-04-16T22:55:45 | 149,797,972 | 0 | 2 |
MIT
| 2019-04-16T22:55:46 | 2018-09-21T17:45:21 |
C
|
UTF-8
|
C
| false | false | 1,540 |
h
|
touch_1.h
|
#define BTN_PIN_LEFT GPIO_PIN_5
#define BTN_PIN_RIGHT GPIO_PIN_2
#define DISPLAY_RESX 128
#define DISPLAY_RESY 64
#define BTN_LEFT_COORDS touch_pack_xy(0, DISPLAY_RESY - 1)
#define BTN_RIGHT_COORDS touch_pack_xy(DISPLAY_RESX - 1, DISPLAY_RESY - 1)
void touch_init(void) {
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;
// PC4 capacitive touch panel module (CTPM) interrupt (INT) input
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Pin = BTN_PIN_LEFT | BTN_PIN_RIGHT;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void touch_power_on(void) {}
void touch_power_off(void) {}
void touch_sensitivity(uint8_t value) { (void)value; }
uint32_t touch_read(void) {
static char last_left = 0, last_right = 0;
char left = (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, BTN_PIN_LEFT));
char right = (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, BTN_PIN_RIGHT));
if (last_left != left) {
last_left = left;
if (left) {
return TOUCH_START | BTN_LEFT_COORDS;
} else {
return TOUCH_END | BTN_LEFT_COORDS;
}
}
if (last_right != right) {
last_right = right;
if (right) {
return TOUCH_START | BTN_RIGHT_COORDS;
} else {
return TOUCH_END | BTN_RIGHT_COORDS;
}
}
return 0;
}
uint32_t touch_is_detected(void) {
return (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, BTN_PIN_LEFT)) ||
(GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, BTN_PIN_RIGHT));
}
|
6e2a9f9ef6fa025da19012138818b3864f5b2906
|
303352ded41d63a4205990c15b90cfb465412bd9
|
/utils/ringbuf/ringbuf.c
|
0a1ebe9aab58a8ff017a5413b71fe90d9454158d
|
[] |
no_license
|
hnutank163/algor
|
39fda7927c9c4d87810f2ca6ff071cd1be0ae935
|
f48c3de6c372ce9cfaaf37acf7e12a989ddd571e
|
refs/heads/master
| 2023-03-07T16:51:11.682724 | 2021-03-07T13:59:45 | 2021-03-07T13:59:45 | 52,439,815 | 1 | 0 | null | 2023-02-25T02:27:43 | 2016-02-24T12:15:31 |
C++
|
UTF-8
|
C
| false | false | 3,062 |
c
|
ringbuf.c
|
#include "ringbuf.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#define MIN(a, b) (a) < (b) ? (a) : (b)
struct ringbuf_st
{
size_t capacity;
char * head;
char * tail;
char * write_ptr;
char * read_ptr;
char * buf;
};
ringbuf * ringbuf_new(unsigned int size)
{
ringbuf *rb = (ringbuf *)malloc(sizeof(ringbuf));
if (rb == NULL)
return NULL;
rb->capacity = size + 1; //avoid readptr == writeptr
rb->buf = (char *)malloc(rb->capacity);
if (rb->buf == NULL)
{
free(rb);
return NULL;
}
rb->head = rb->write_ptr = rb->read_ptr = rb->buf;
rb->tail = rb->head + rb->capacity;
return rb;
}
void ringbuf_free(ringbuf *rb)
{
if (rb)
{
if (rb->buf)
free(rb->buf);
free(rb);
}
}
unsigned int ringbuf_put(ringbuf *rb, const void *data, unsigned int size)
{
assert(rb && data);
const char *rptr = rb->read_ptr; //avoid another thread is read
if (rptr <= rb->write_ptr)
{
//###################
//h r w t
if (size > rb->capacity - (rb->write_ptr - rptr) - 1)
{
size = rb->capacity - (rb->write_ptr - rptr) - 1;
}
size_t back_size = MIN(size, rb->tail - rb->write_ptr);
size_t front_size = size - back_size;
if (front_size)
{
memcpy(rb->write_ptr, data, back_size);
memcpy(rb->head, (unsigned char *)data+back_size, front_size);
rb->write_ptr = rb->head +front_size;
}
else
{
memcpy(rb->write_ptr, data, back_size);
rb->write_ptr += back_size;
}
}
else
{
//###################
// h w r t
if (size > (size_t)(rptr - rb->write_ptr-1))
{
size = rptr - rb->write_ptr - 1;
}
memcpy(rb->write_ptr, data, size);
rb->write_ptr += size;
}
return size;
}
unsigned int ringbuf_get(ringbuf *rb, void *data, unsigned int size)
{
const char *wptr = rb->write_ptr; //avoid another thread is write
if (wptr >= rb->read_ptr)
{
// #################
// h r w t
if (size > (size_t)(wptr - rb->read_ptr))
size = wptr - rb->read_ptr;
memcpy(data, rb->read_ptr, size);
rb->read_ptr += size;
}
else
{
// ################
// h w r t
if (size > rb->capacity - (rb->read_ptr - wptr))
size = rb->capacity - (rb->read_ptr - wptr);
size_t back_size = MIN(size, rb->tail - rb->read_ptr);
size_t front_size = size - back_size;
if (front_size)
{
memcpy(data, rb->read_ptr, back_size);
memcpy((unsigned char *)data + back_size, rb->head, front_size);
rb->read_ptr = rb->head + front_size;
}
else
{
memcpy(data, rb->read_ptr, size);
rb->read_ptr += size;
}
}
return size;
}
|
21d248335f1a510c96cb3e68932a3c84127f7a7f
|
bc8849e18ce1e6032ac89cb03a9910aa06ee2635
|
/examples/libopencm3-usb-cdcacm/src/usb_to_serial_cdcacm.c
|
b07d27cf53bebcb86d066ab29ce013b0da8eb80c
|
[
"Apache-2.0"
] |
permissive
|
platformio/platform-titiva
|
c6a7dc6a6a31900d9a1b856f56949c302e7ece13
|
c9aed53f74280d4dbc7907f837dc65823be57592
|
refs/heads/develop
| 2023-04-07T01:55:31.137334 | 2023-03-21T00:48:51 | 2023-03-21T00:48:51 | 59,846,800 | 14 | 13 |
Apache-2.0
| 2022-07-25T10:18:23 | 2016-05-27T16:02:35 |
Python
|
UTF-8
|
C
| false | false | 4,725 |
c
|
usb_to_serial_cdcacm.c
|
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \addtogroup Examples
*
* Flashes the Red, Green and Blue diodes on the board, in order.
*
* RED controlled by PF1
* Green controlled by PF3
* Blue controlled by PF2
*/
#include "usb_to_serial_cdcacm.h"
#include <libopencm3/lm4f/systemcontrol.h>
#include <libopencm3/lm4f/rcc.h>
#include <libopencm3/lm4f/gpio.h>
#include <libopencm3/lm4f/uart.h>
#include <libopencm3/lm4f/nvic.h>
#include <libopencm3/cm3/scb.h>
#define PLL_DIV_80MHZ 5
/* This is how the RGB LED is connected on the stellaris launchpad */
#define RGB_PORT GPIOF
enum {
LED_R = GPIO1,
LED_G = GPIO3,
LED_B = GPIO2,
};
/*
* Clock setup:
* Take the main crystal oscillator at 16MHz, run it through the PLL, and divide
* the 400MHz PLL clock to get a system clock of 80MHz.
*/
static void clock_setup(void)
{
rcc_sysclk_config(OSCSRC_MOSC, XTAL_16M, PLL_DIV_80MHZ);
}
/*
* GPIO setup:
* Enable the pins driving the RGB LED as outputs.
*/
static void gpio_setup(void)
{
/*
* Configure GPIOF
* This port is used to control the RGB LED
*/
periph_clock_enable(RCC_GPIOF);
const uint32_t opins = (LED_R | LED_G | LED_B);
gpio_mode_setup(RGB_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, opins);
gpio_set_output_config(RGB_PORT, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, opins);
}
static void cm4f_enable_fpu(void)
{
/* Enable FPU */
SCB_CPACR |= SCB_CPACR_FULL * (SCB_CPACR_CP10 | SCB_CPACR_CP11);
/* Wait for store to complete */
__asm__("DSB");
/* Reset pipeline. Now the FPU is enabled */
__asm__("ISB");
}
void glue_data_received_cb(uint8_t * buf, uint16_t len)
{
/* Blue LED indicates data coming in */
gpio_set(RGB_PORT, LED_B);
cdcacm_send_data(buf, len);
gpio_clear(RGB_PORT, LED_B);
}
void glue_set_line_state_cb(uint8_t dtr, uint8_t rts)
{
/* Green LED indicated one of the control lines are active */
if (dtr || rts)
gpio_set(RGB_PORT, LED_G);
else
gpio_clear(RGB_PORT, LED_G);
uart_set_ctl_line_state(dtr, rts);
}
int glue_set_line_coding_cb(uint32_t baud, uint8_t databits,
enum usb_cdc_line_coding_bParityType cdc_parity,
enum usb_cdc_line_coding_bCharFormat cdc_stopbits)
{
enum uart_parity parity;
uint8_t uart_stopbits;
if (databits < 5 || databits > 8)
return 0;
switch (cdc_parity) {
case USB_CDC_NO_PARITY:
parity = UART_PARITY_NONE;
break;
case USB_CDC_ODD_PARITY:
parity = UART_PARITY_ODD;
break;
case USB_CDC_EVEN_PARITY:
parity = UART_PARITY_EVEN;
break;
default:
return 0;
}
switch (cdc_stopbits) {
case USB_CDC_1_STOP_BITS:
uart_stopbits = 1;
break;
case USB_CDC_2_STOP_BITS:
uart_stopbits = 2;
break;
default:
return 0;
}
/* Disable the UART while we mess with its settings */
uart_disable(UART1);
/* Set communication parameters */
uart_set_baudrate(UART1, baud);
uart_set_databits(UART1, databits);
uart_set_parity(UART1, parity);
uart_set_stopbits(UART1, uart_stopbits);
/* Back to work. */
uart_enable(UART1);
return 1;
}
void glue_send_data_cb(uint8_t * buf, uint16_t len)
{
int i;
/* Red LED indicates data going out */
gpio_set(RGB_PORT, LED_R);
for (i = 0; i < len; i++) {
uart_send_blocking(UART1, buf[i]);
}
gpio_clear(RGB_PORT, LED_R);
}
static void mainloop(void)
{
uint8_t linestate, cdcacmstate;
static uint8_t oldlinestate = 0;
/* See if the state of control lines has changed */
linestate = uart_get_ctl_line_state();
if (oldlinestate != linestate) {
/* Inform host of state change */
cdcacmstate = 0;
if (linestate & PIN_RI)
cdcacmstate |= CDCACM_RI;
if (linestate & PIN_DSR)
cdcacmstate |= CDCACM_DSR;
if (linestate & PIN_DCD)
cdcacmstate |= CDCACM_DCD;
cdcacm_line_state_changed_cb(cdcacmstate);
}
oldlinestate = linestate;
}
int main(void)
{
gpio_enable_ahb_aperture();
clock_setup();
gpio_setup();
cdcacm_init();
uart_init();
cm4f_enable_fpu();
while (1)
mainloop();
return 0;
}
|
c2adfca48ed9697b523294e5ba180bd01bba4f6a
|
da9b3111dc4bd4ed9e965a06c3514485400a183c
|
/libbzip2/libbzip2/bzlib_private.h
|
bbed587d436737429d7a7bb67bbe1a46e6fd52fe
|
[] |
no_license
|
build2-packaging/bzip2
|
beb1d8dd0f7e87eced95b300ecd5a05a1d9f19cc
|
e4ff6111f45ad64bcf1210a227ca42348418ef9e
|
refs/heads/master
| 2023-01-24T19:03:59.985300 | 2020-11-17T14:48:38 | 2020-11-17T14:48:38 | 311,434,785 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 30 |
h
|
bzlib_private.h
|
../../upstream/bzlib_private.h
|
c506d0e05aa4b481f68f07b7234c6a5d432f4d85
|
b893ae7df306e4efe1917a23cec5c1133412cd5e
|
/Exemplo-Acelerometro-2/includes.h
|
070a238b49d9d4585f484bdf56b718ee6ab24713
|
[] |
no_license
|
ErickCReis/TwinoBoard
|
ea2d631b2d672d82895093869acce319aece874e
|
27b2000e03fd724aa77099cfe6fce120b79c7cad
|
refs/heads/master
| 2020-07-10T17:12:58.128799 | 2019-09-19T14:14:27 | 2019-09-19T14:14:27 | 204,318,947 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 241 |
h
|
includes.h
|
/*
* includes.h
*
* Created on: 12/09/2019
* Author: erickreis
*/
#ifndef INCLUDES_H_
#define INCLUDES_H_
#include <msp430fr5729.h>
#include "accel.h"
#include "clock.h"
#include "TI_USCI_I2C_master.h"
#endif /* INCLUDES_H_ */
|
a64b1b0d4f82776d4d9a258ec62c04825ea9c406
|
ed71ea65658456ab3b2d5e9db3dbf12404b06eab
|
/src/example/max.c
|
6535e3e367ff62ba7870ae0f33504756b5de056b
|
[] |
no_license
|
matt-welch/wave-equation-solver-2d
|
11be49bc6c25b71a1aa14523a1f84383d3857bfd
|
70d0a1f012d77d3d2089be4297b0e3ede53341f8
|
refs/heads/master
| 2016-09-12T10:20:02.182883 | 2013-03-21T00:31:25 | 2013-03-21T00:31:25 | 58,680,759 | 1 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,690 |
c
|
max.c
|
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[] ) {
int numprocs, rank, chunk_size, i;
int max, mymax,rem;
int array[800];
MPI_Status status;
MPI_Init( &argc,&argv);
MPI_Comm_rank( MPI_COMM_WORLD, &rank);
MPI_Comm_size( MPI_COMM_WORLD, &numprocs);
printf("Hello from process %d of %d \n",rank,numprocs);
chunk_size = 800/numprocs;
rem = 800%numprocs;
if (rank == 0) {
/* Initialize Array */
printf("REM %d \n",rem);
for(i=0;i<800;i++) {
array[i] = i;
}
/* Distribute Array */
for(i=1;i<numprocs;i++) {
if(i<rem ) {
MPI_Send(&array[i*chunk_size],chunk_size+1, MPI_INT, i, 1, MPI_COMM_WORLD);
} else {
MPI_Send(&array[i*chunk_size],chunk_size, MPI_INT, i, 1, MPI_COMM_WORLD);
}
}
}
else {
MPI_Recv(array, chunk_size, MPI_INT, 0,1,MPI_COMM_WORLD,&status);
}
/*Each processor has a chunk, now find local max */
mymax = array[0];
for(i=1;i<chunk_size;i++) {
if(mymax<array[i]) {
mymax = array[i];
}
}
printf("Array els 1-5 for rank %d: %d %d %d %d %d\n",rank,array[0],array[1],array[2],array[3],array[4]);
printf("Last 5 Array els for rank %d: %d %d %d %d %d\n",rank,array[chunk_size-5],array[chunk_size-4],array[chunk_size-3],array[chunk_size-2],array[chunk_size-1]);
printf("The Max for rank %d is: %d\n",rank,mymax);
/*Send local_max back to master */
if (rank == 0) {
max = mymax; //Store rank 0 local maximum
for(i=1;i<numprocs;i++) {
MPI_Recv(&mymax,1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD,&status);
if(max<mymax) max = mymax;
}
printf("The Max is: %d",max);
}
else {
MPI_Send(&mymax, 1, MPI_INT, 0,1,MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}
|
4ef71403684073fb5f41a85b2bcefaa0fd219e41
|
db9ceefdb67f34e5fcaa89db227097abba2ceacb
|
/build/rational.h
|
6bcbcd6d3c5d724bbb69ade91912242403857744
|
[] |
no_license
|
Komdosh/DM43
|
dbc4e550865f206b7676f4ca86b10321eba32317
|
db572be428e6ee4c2d87bab1ccd673ec1132a8cc
|
refs/heads/master
| 2021-01-15T12:26:52.681885 | 2015-12-29T11:43:25 | 2015-12-29T11:43:25 | 48,112,625 | 1 | 0 | null | 2015-12-29T11:43:26 | 2015-12-16T13:43:01 |
C
|
UTF-8
|
C
| false | false | 626 |
h
|
rational.h
|
#ifndef RATIONAL_H
#define RATIONAL_H
#include "../build/main.h"
int menuItemRational();
int menuRational(struct RATIONAL* rats, struct INTEGER* ints);
struct RATIONAL ADD_QQ_Q(struct RATIONAL A, struct RATIONAL B);
struct RATIONAL DIV_QQ_Q(struct RATIONAL A, struct RATIONAL B);
int INT_Q_Z(struct RATIONAL A);
struct RATIONAL MUL_QQ_Q(struct RATIONAL A, struct RATIONAL B);
int output_Q(struct RATIONAL A);
struct RATIONAL RED_Q_Q(struct RATIONAL A);
struct RATIONAL SUB_QQ_Q(struct RATIONAL A, struct RATIONAL B);
struct INTEGER TRAN_Q_Z(struct RATIONAL B);
struct RATIONAL TRAN_Z_Q(struct INTEGER A);
#endif // RATIONAL_H
|
8e2742478d5dc427bb949d574506deda8da53825
|
4f1ff8839971502ee988c5d94eea42a3639141ba
|
/lab4/lab4/common.h
|
d65274647b9272ca8c36e1c5476ba0f2576ce1be
|
[] |
no_license
|
nguyentriencf/CTDL2
|
0ed33c061ec7df551ce8026ecf63a48078251ac9
|
2b954b882b7cb8cc7035de808ba0eb4e4db522f2
|
refs/heads/main
| 2023-01-30T12:56:18.315675 | 2020-12-03T14:31:17 | 2020-12-03T14:31:17 | 314,762,530 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 1,127 |
h
|
common.h
|
#pragma once
// định nghĩa hằng số
#define UPPER 100 // số phần tử tối đa
#define ZERO 0 // gIÁ TRỊ 0
#define MAX 20 // số đỉnh tối đa
#define INF 1000 // vô cùng
#define YES 1 // đã xét
#define NO 0 // chưa xét
#define NULLDATA -1 // giá trị rỗng
// dùng cho kiểu dữ liệu đò thi
// dùng định nghĩa các kiểu dữ liệu
typedef char LabelType;
typedef int CostType;
typedef CostType MaTrix[MAX][MAX]; // ma trận
struct Vertex
{
LabelType Label; // Nhãn của đinh
int Visited; // trạng thái
};
// định nghĩa cạnh
struct Edge
{
int Source; ///đỉnh đầu
int target; // đỉnh cuối
CostType Weight; // trọng số
int Marked; // trạng thái
};
// định nghĩa cấu trúc đường đi
struct Path
{
CostType Length; //Độ dài đường đi
int Parent; // đỉnh trước
};
// đinh nghĩa đỉnh
struct Graph
{
bool Directed; // đt có hướng?
int NumVertices; // số đỉnh
int NumEdges; // số cạnh
MaTrix Cost; //Ma trận kề
Vertex Vertices[MAX]; //DS đỉnh
};
|
b30b67d46473f5b18f9fa4ab26f39cc5c2468ed0
|
6c996ca5146bd307a062f38819acec16d710656f
|
/workspace/iw8/code_source/libs/demonwareclient/bdcore/bdcrypto/bdcypher3des.h
|
98c047f4c68ff3517d63ab63e0a73ab8488cdb1b
|
[] |
no_license
|
Omn1z/OpenIW8
|
d46f095d4d743d1d8657f7e396e6d3cf944aa562
|
6c01a9548e4d5f7e1185369a62846f2c6f8304ba
|
refs/heads/main
| 2023-08-15T22:43:01.627895 | 2021-10-10T20:44:57 | 2021-10-10T20:44:57 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 627 |
h
|
bdcypher3des.h
|
/*
==============
bdCypher3Des::operator delete
==============
*/
void __fastcall bdCypher3Des::operator delete(void *__formal, void *a2)
{
??3bdCypher3Des@@SAXPEAX0@Z(__formal, a2);
}
/*
==============
bdCypher3Des::operator delete
==============
*/
void __fastcall bdCypher3Des::operator delete(void *p)
{
??3bdCypher3Des@@SAXPEAX@Z(p);
}
/*
==============
bdCypher3Des::operator delete
==============
*/
void bdCypher3Des::operator delete(void *__formal, void *a2)
{
;
}
/*
==============
bdCypher3Des::operator delete
==============
*/
void bdCypher3Des::operator delete(void *p)
{
bdMemory::deallocate(p);
}
|
aea376f32583a619ecd0843815d3d846ff7367a4
|
552c39141dab7cbc0c34245000291a46cdb41495
|
/lte_enb/src/x2ap/cz_ex_ms.c
|
2fe762b1333e4c97dbdba9eb6d1ea7e585636523
|
[] |
no_license
|
cmjeong/rashmi_oai_epc
|
a0d6c19d12b292e4da5d34b409c63e3dec28bd20
|
6ec1784eb786ab6faa4f7c4f1c76cc23438c5b90
|
refs/heads/master
| 2021-04-06T01:48:10.060300 | 2017-08-10T02:04:34 | 2017-08-10T02:04:34 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 11,137 |
c
|
cz_ex_ms.c
|
/********************************************************************20**
Name: X2AP Layer
Type: C source file
Desc: C Source code
File: cz_ex_ms.c
Sid: tr_ex_ms.c@@/main/2 - Tue Aug 30 18:36:11 2011
Prg: sy
*********************************************************************21*/
/* Header include files (.h) */
#include "envopt.h" /* environment options */
#include "envdep.h" /* environment dependent */
#include "envind.h" /* environment independent */
#include "gen.h" /* General */
#include "ssi.h" /* System Services */
#include "cm_tkns.h" /* common tokens */
#include "cm_hash.h" /* common structs 1 */
#include "cm_mblk.h" /* common memory */
#include "cm_llist.h" /* cm link list */
#include "cm5.h" /* common structs 3 */
#include "cm_inet.h" /* common tokens */
#include "cm_tkns.h" /* common tokens */
#include "cm_tpt.h" /* common transport */
#include "cm_pasn.h" /* Common Asn.1 library */
#include "sct.h" /* SCTP Layer */
#include "czt.h" /* X2AP Upper Interface */
#include "lcz.h" /* X2AP LM Interface */
#include "cz.h" /* X2AP Layer */
#include "cz_err.h" /* X2AP Error */
#include "czt_asn.h" /* X2AP ASN */
/* Header include files (.x) */
#include "gen.x" /* General */
#include "ssi.x" /* System Services */
#include "cm_tkns.x" /* common tokens */
#include "cm_hash.x" /* common structs 1 */
#include "cm_lib.x" /* common library */
#include "cm_mblk.x" /* common memory */
#include "cm_llist.x" /* cm link list */
#include "cm5.x" /* common structs 3 */
#include "cm_inet.x" /* common transport */
#include "cm_tpt.x" /* common transport */
#include "cm_pasn.x" /* Common Asn.1 library */
#include "sct.x" /* SCTP Layer */
#include "czt.x" /* X2AP Upper Interface */
#include "lcz.x" /* X2AP LM Interface */
#include "cz.x" /* X2AP Layer */
#include "czt_asn.x" /* X2AP ASN */
/* functions in other modules */
/* public variable declarations */
/* control variables for testing */
/* private variable declarations */
/*
* support functions
*/
/* cz001.101 : CR fixes */
/*
*
* Fun : activate task
*
* Desc : All loosely coupled messages that are received by RANAP
* arrive at this point. This includes loosely coupled layer
* management requests and loosely coupled messages arriving
* from the service user and service provider(s).
*
* Ret : ROK - ok
*
* Notes: None
*
* File : cz_ex_ms.c
*
*/
#ifdef ANSI
PUBLIC S16 czActvTsk
(
Pst *pst, /* post structure */
Buffer *mBuf /* message buffer */
)
#else
PUBLIC S16 czActvTsk(pst, mBuf)
Pst *pst; /* post structure */
Buffer *mBuf; /* message buffer */
#endif
{
Mem sMem;
CZ_TRC3(czActvTsk);
#ifdef SS_MULTIPLE_PROCS
if(((SGetXxCb(pst->dstProcId,pst->dstEnt,pst->dstInst,(Void **)&czCbPtr))
!=ROK)||( czCbPtr == NULLP))
{
#if (ERRCLASS & ERRCLS_INT_PAR)
SLOGERROR(pst->dstEnt, pst->dstInst, pst->dstProcId, (S8*)__FILE__, __LINE__,\
ERRCLS_INT_PAR,1,0, (S8*)"czActvTsk() failed, cannot derive czCb");
#endif /* ERRCLASS & ERRCLS_INT_PAR */
SPutMsg(mBuf);
/* cz001.301: Klockwork warning fix*/
RETVALUE(FALSE);
}
#endif /*SS_MULTIPLE_PROCS */
sMem.region = czCb.init.region;
sMem.pool = czCb.init.pool;
switch(pst->srcEnt)
{
/* The originator of this message is the stack manager,
* unpack and go to the respective primitive processing function */
#ifdef LCLCZ
case ENTSM:
{
switch(pst->event)
{
case EVTLCZCFGREQ:
/* Process a config. request */
cmUnpkLczCfgReq(CzMiLczCfgReq, pst, mBuf);
break;
case EVTLCZCNTRLREQ:
/* Process a control request */
cmUnpkLczCntrlReq(CzMiLczCntrlReq, pst, mBuf);
break;
case EVTLCZSTAREQ:
/* Process a status request */
cmUnpkLczStaReq(CzMiLczStaReq, pst, mBuf);
break;
case EVTLCZSTSREQ:
/* Process a statistics request */
cmUnpkLczStsReq(CzMiLczStsReq, pst, mBuf);
break;
default:
CZ_DBG_ERROR((CZ_PRNT_BUF,
"Invalid event from Layer Manager: czActvTsk Failed"));
SPutMsg(mBuf);
break;
}
break;
}
#endif /* LCLCZ */
#ifdef LCSCT
case ENTSB:
case ENTHI:
{
S16 ret = RFAILED;
switch(pst->event)
{
/* Bind confirm */
case SCT_EVTBNDCFM:
ret = cmUnpkSctBndCfm(CzLiSctBndCfm, pst, mBuf);
break;
/* Assoc. Establishment indication */
case SCT_EVTASSOCIND:
ret = cmUnpkSctAssocInd(CzLiSctAssocInd, pst, mBuf);
break;
/* Assoc. Establishment confirmation */
case SCT_EVTASSOCCFM:
ret = cmUnpkSctAssocCfm(CzLiSctAssocCfm, pst, mBuf);
break;
/* Association Termination indication */
case SCT_EVTTERMIND:
ret = cmUnpkSctTermInd(CzLiSctTermInd, pst, mBuf);
break;
/* Assoc. Termination confirmation */
case SCT_EVTTERMCFM:
ret = cmUnpkSctTermCfm(CzLiSctTermCfm, pst, mBuf);
break;
/* Set Primary confirmation */
case SCT_EVTSETPRICFM:
ret = cmUnpkSctSetPriCfm(CzLiSctSetPriCfm, pst, mBuf);
break;
/*Set heartbeat confirmation */
case SCT_EVTHBEATCFM:
ret = cmUnpkSctHBeatCfm(CzLiSctHBeatCfm, pst, mBuf);
break;
/* Status confirm */
case SCT_EVTSTACFM:
ret = cmUnpkSctStaCfm(CzLiSctStaCfm, pst, mBuf);
break;
/* Data Indication */
case SCT_EVTDATIND:
ret = cmUnpkSctDatInd(CzLiSctDatInd, pst, mBuf);
break;
/* Status Indication */
case SCT_EVTSTAIND:
ret = cmUnpkSctStaInd(CzLiSctStaInd, pst, mBuf);
break;
/* Flow control indication */
case SCT_EVTFLCIND:
ret = cmUnpkSctFlcInd(CzLiSctFlcInd, pst, mBuf);
break;
/* Endpoint open confirmation */
case SCT_EVTENDPOPENCFM:
ret = cmUnpkSctEndpOpenCfm(CzLiSctEndpOpenCfm, pst, mBuf);
break;
/* Endpoint close confirmation */
case SCT_EVTENDPCLOSECFM:
ret = cmUnpkSctEndpCloseCfm(CzLiSctEndpCloseCfm, pst, mBuf);
break;
default:
{
#if (ERRCLASS & ERRCLS_DEBUG)
if (pst->event == ENTSB)
{
CZ_DBG_ERROR((CZ_PRNT_BUF,
"czActvTsk: Invalid event specified for srcEnt (ENTSB)."));
}
if (pst->event == ENTHI)
{
CZ_DBG_ERROR((CZ_PRNT_BUF,
"czActvTsk: Invalid event specified for srcEnt (ENTHI)."));
}
#endif /* (ERRCLASS & ERRCLS_DEBUG) */
SPutMsg(mBuf);
break;
}
}
break;
}
#endif /* LCSCT */
#if (defined(LCCZT) || defined(LWLCCZT))
case ENTRS:
{
switch (pst->event)
{
case EVTCZTBNDREQ:
cmUnpkCztBndReq(CzUiCztBndReq, pst, mBuf);
break;
case EVTCZTUBNDREQ:
cmUnpkCztUbndReq(CzUiCztUbndReq, pst, mBuf);
break;
case EVTCZTGPREQ:
cmUnpkCztGpReq(CzUiCztGpReq, pst, mBuf);
break;
case EVTCZTGPRSP:
cmUnpkCztGpRsp(CzUiCztGpRsp, pst, mBuf);
break;
case EVTCZTGPRETXREQ:
cmUnpkCztGpRetxReq(CzUiCztGpRetxReq, pst, mBuf);
break;
case EVTCZTBMPREQ:
cmUnpkCztBmpReq(CzUiCztBmpReq, pst, mBuf);
break;
case EVTCZTBMPRSP:
cmUnpkCztBmpRsp(CzUiCztBmpRsp, pst, mBuf);
break;
case EVTCZTGPERRREQ:
cmUnpkCztGpErrReq(CzUiCztGpErrReq, pst, mBuf);
break;
case EVTCZTPEERASSOCRSP:
cmUnpkCztDynamPeerAssocRsp(CzUiCztDynamPeerAssocRsp, pst, mBuf);
break;
case EVTCZTLOCALRELREQ:
cmUnpkCztRelReq(CzUiCztRelReq, pst, mBuf);
break;
case EVTCZTAUDREQ:
cmUnpkCztAudReq(CzUiCztAudReq, pst, mBuf);
break;
default:
#if (ERRCLASS & ERRCLS_DEBUG)
CZ_DBG_ERROR((CZ_PRNT_BUF,
"Invalid event from Upper Interface: czActvTsk Failed"));
#endif /* ERRCLASS & ERRCLS_DEBUG */
SPutMsg(mBuf);
break;
}
break;
}
#endif
default:
#if (ERRCLASS & ERRCLS_DEBUG)
CZ_DBG_ERROR((CZ_PRNT_BUF,
"Event Received from Invalid Entity : czActvTsk Failed"));
#endif /* ERRCLASS & ERRCLS_DEBUG */
SPutMsg(mBuf);
break;
} /* end switch */
SExitTsk();
CZ_RETVALUE(ROK);
} /* end of czActvTsk */
/********************************************************************30**
End of file: tr_ex_ms.c@@/main/2 - Tue Aug 30 18:36:11 2011
*********************************************************************31*/
/********************************************************************40**
Notes:
*********************************************************************41*/
/********************************************************************50**
*********************************************************************51*/
/********************************************************************60**
Revision history:
*********************************************************************61*/
/********************************************************************90**
ver pat init description
------------ -------- ---- ----------------------------------------------
/main/1 --- sy 1. LTE-X2AP Initial Release.
cz001.101 mm 1. CR Fixes, Memory Leak fixes.
/main/2 --- pt 1. LTE-X2AP 3.1 release.
/main/3 cz001.301 akaranth 1. Klockwork Warning fix
*********************************************************************91*/
|
964dbdd6613451a680f13d91666d7b3b20adbe0a
|
5137017e6af9405474d478129831bf297978cc7f
|
/IndustrialPrototype/c+4memorytest+misra/flashtest.c
|
c044f0c47a93cb8ede8fe93bbb3a3d2675bc90fa
|
[] |
no_license
|
pedromarinho94/light-intensity-regulator
|
26de11c968bd2812cc453eec34a4076e758a8495
|
c4b57a8d2e3347d19f96fb2c17e4b8e601511843
|
refs/heads/master
| 2020-06-25T16:35:27.877765 | 2019-07-29T03:43:35 | 2019-07-29T03:43:35 | null | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 688 |
c
|
flashtest.c
|
#include "flashtest.h"
#include <avr/pgmspace.h>
#include <twi2c.h>
#define N_BYTES_FLASH (1956U)
uint16_t flash_test_calculate_xor(void);
void flash_test(void) {
static uint8_t rwrong;
uint16_t hash = flash_test_calculate_xor();
uint16_t true_hash = eeprom_read_word ((const uint16_t*)0x45);
eeprom_write_word((uint16_t*)0x50, hash);
if (hash==true_hash)
{
rwrong = 0x87U;
}
else
{
rwrong = 0x00U;
}
montagem(rwrong);
}
uint16_t flash_test_calculate_xor(void) {
uint16_t hash = 0;
for (uint16_t k = 0; k < N_BYTES_FLASH - 1; k += 2) {
uint16_t value = pgm_read_word_near(k);
hash ^= value;
}
return hash;
}
|
9d4570e407f3eb3f2103eb83b8c15a98d23d6543
|
4a85bbe44d3df9c03b02d8776ec28456bb722dcf
|
/functions.c
|
b21f642518abf6174bdf2956c1e80c415945a1ef
|
[] |
no_license
|
sabaoempo/random4c
|
ae854634861a2a2556d86a9f7832c4ae0529a25d
|
cd8a4afe3b75ed7d79d966b06185703aa440f49f
|
refs/heads/master
| 2020-03-11T10:08:34.291073 | 2018-08-10T13:12:47 | 2018-08-10T13:12:47 | 129,930,857 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 474 |
c
|
functions.c
|
#include <stdio.h>
#include <stdlib.h>
int soma_mult(int x, int y, int *soma, int *mult)
{
*soma=x+y;
*mult=x*y;
}
int main()
{
int n1, n2, s, m;
printf("Programa para somar e multiplicar dois números a partir de uma função.\nDigite o primeiro número: ");
scanf("%d", &n1);
printf("\nDigite o segundo número: ");
scanf("%d", &n2);
soma_mult(n1, n2, &s, &m);
printf("Soma = %d, multiplicação = %d\n", s, m);
system("pause");
}
|
f0f9bcb68bcce1b56f1e042110004a12024645f6
|
566c2568455b675a70f2159786cd4487cafe8692
|
/步兵五号(3)/Task/shoot_task.c
|
3791343c07bf9b00e8b91853810c513db8a74c22
|
[] |
no_license
|
linghuix/robomaster
|
9ee4d636a21276628251d49b29d5e43e1cd86221
|
03748a6bbe7d7173f84fe17efe5c9a2f78508275
|
refs/heads/master
| 2021-01-02T20:34:10.075476 | 2020-02-25T15:47:50 | 2020-02-25T15:47:50 | 239,789,542 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 7,870 |
c
|
shoot_task.c
|
/**************************************************
* @file shoot_task.c
* @author wwy
* @version version 1.0
* @date 2019.2.10
* @brief 射击任务,本工程还未与裁判系统适配,枪口
热量变量用shootHeat表示,机器人等级用
robotlevel表示
***************************************************
* @attention
For hero robot. Since hero robot has only two shoot
mode, so it's quite simpler than infantry robot.
Infantry need additional codes.
***************************************************
*/
/* Include ---------------------------------------*/
#include "shoot_task.h"
/* Global Variable -------------------------------*/
Trigger_Mode_t Trigger_Mode; //拨弹模式
const int16_t heat_buff[4] = {0, 240, 360, 480}; //热量上限
const int8_t heat_cd[4] = {0, 20, 40, 60}; //每秒冷却值
int16_t fric_current[3]; //发个三个摩擦轮的电流值
int16_t feed_current; //发给拨弹电机的电流值
int8_t shoot_allowed_num, shooted_num; //当前热量下允许射击的总数和热量未更新状态下已发射的弹丸数
uint32_t tick_last,tick_sub; //当前射击和上一次射击的时间差,若大于100则默认热量数据已更新
uint8_t Shoot_Signal_Old; //上一次的射击请求信号
uint8_t shoot_one; //打出一发
uint32_t continuous_shoot_tick; //连发计时
extern short temp3; //从nuc那里获得的深度
//发射一个子弹的热量
const int SHOOT_SPEED25 = 9;
const int SHOOT_SPEED20 = 12;
const int SHOOT_SPEED15 = 18;
const int BULL_SPEED15 = 3500;
const int BULL_SPEED20 = 3500;
const int BULL_SPEED25 = 5500;
/**
* @brief 总射击处理函数,根据模式进行散转
* @param none
* @retval none
* @note
**/
void shoot_task(void)
{
if(Mode.Shoot_Signal == 0) //没有射击请求信号
{
shoot_one = 0;
continuous_shoot_tick = 0;
}
shoot_signal_process(); //有射击请求信号,处理射击请求信号
switch(Mode.Shoot)
{
case Shoot_Normal_Mode: _shoot_normal_handle();break;
case Shoot_Auto_Mode: _shoot_auto_handle();break;
default: _shoot_normal_handle();break;
}
Shoot_Signal_Old = Mode.Shoot_Signal;
fric_wheel_ctrl();
Set_Shoot_Current(&hcan1, feed_current, fric_current);
}
/**
* @brief 处理设计信号,判断是单发还是连发
* @param none
* @retval none
* @note 发送shoot_one信号量,连发间隔100ms,单发不设间隔看手速
**/
void shoot_signal_process(void)
{
if(Mode.Shoot_Signal == 0)
return;
if(Mode.Shoot == Shoot_Normal_Mode) //普通射击模式下判断是否是连发
{
if(Shoot_Signal_Old == 0)
{
Trigger_Mode = Single_Shoot; //发射模式单发
}
else
{
Trigger_Mode = Continuous_Shoot; //发射模式连发
}
switch(Trigger_Mode)
{
case Single_Shoot:
shoot_one = 1;
break;
case Continuous_Shoot:
continuous_shoot_tick++;
if(continuous_shoot_tick >= 300) //按住鼠标300ms触发连发
{
if(continuous_shoot_tick % 100 == 0)//连发射频10Hz
{
shoot_one = 1;
}
else
{
shoot_one = 0;
}
}
else
{
shoot_one = 0;
}
break;
}
}
}
/**
* @brief 普通射击处理函数
* @param none
* @retval none
* @note 获取shoot_one信号量
**/
static void _shoot_normal_handle(void)
{
//发射间隔要大于100时,更新已发射数量
tick_sub = HAL_GetTick() - tick_last;
if(tick_sub>=100)
shooted_num = 0;
if(shoot_one == 1)
{
//允许继续发射的子弹数
shoot_allowed_num = (int8_t)((heat_buff[robotlevel]-shooterheat0)/SHOOT_SPEED20);
shoot_allowed_num = 50;
if(shooted_num>=shoot_allowed_num)
ShootFeedPID.Position.ref = SHOOTEncoder[FEED].real_angle;
else
{
tick_last = HAL_GetTick();//记录发射时间
ShootFeedPID.Position.ref = SHOOTEncoder[FEED].real_angle + ONE_SHOOT_ANGLE;
shooted_num++;
}
}
ShootFeedPID.Position.fdb = SHOOTEncoder[FEED].real_angle;
PID_Calc(&ShootFeedPID.Position);
ShootFeedPID.Speed.fdb = SHOOTEncoder[FEED].rotate_speed;
ShootFeedPID.Speed.ref = ShootFeedPID.Position.output;
PID_Calc(&ShootFeedPID.Speed);
feed_current = ShootFeedPID.Speed.output;
}
/**
* @brief 自瞄处理函数
* @param none
* @retval none
* @note 自瞄子弹速度设置,云台角度校准设置
**/
int shoot_speed; //子弹射速
uint8_t schmidtFlag=0;
static void _shoot_auto_handle(void)
{
// if (temp3 < 2000)
// {
// shoot_speed = SHOOT_SPEED15;
// }
// else
// {
// shoot_speed = SHOOT_SPEED25;
// }
if(schmidtFlag==0 && temp3<1200)
schmidtFlag=1;
else if(schmidtFlag==1 && temp3>1500)
schmidtFlag=0;
if(schmidtFlag==0)
shoot_speed=SHOOT_SPEED25;
else
shoot_speed=SHOOT_SPEED15;
//shoot_speed = 9;
tick_sub = HAL_GetTick() - tick_last;
if(tick_sub>=100)
shooted_num = 0;
if(isNUC == 1)
{
shoot_allowed_num = (int8_t)((heat_buff[robotlevel]-shooterheat0)/shoot_speed);//-1;
if(shooted_num>=shoot_allowed_num)
ShootFeedPID.Position.ref = SHOOTEncoder[FEED].real_angle;
else
{
tick_last = HAL_GetTick();
ShootFeedPID.Position.ref = SHOOTEncoder[FEED].real_angle + ONE_SHOOT_ANGLE;
shooted_num++;
}
}
ShootFeedPID.Position.fdb = SHOOTEncoder[FEED].real_angle;
PID_Calc(&ShootFeedPID.Position);
ShootFeedPID.Speed.fdb = SHOOTEncoder[FEED].rotate_speed;
ShootFeedPID.Speed.ref = ShootFeedPID.Position.output;
PID_Calc(&ShootFeedPID.Speed);
feed_current = ShootFeedPID.Speed.output;
isNUC = 0;
}
/**
* @brief 摩擦轮速度控制
* @param none
* @retval none
* @note 根据 isHighSpeed 设置子弹速度
**/
int bull_speed;
uint8_t isHighSpeed = 0;
extern float PITCH_AUTO_OFFSET;
extern float YAW_AUTO_OFFSET;
static void fric_wheel_ctrl(void)
{
if(Mode.Shoot == Shoot_Normal_Mode)
{
if(isHighSpeed==1)
{
bull_speed = 6500;
}
else
{
bull_speed = 5500;
}
PITCH_AUTO_OFFSET = 0.0;
YAW_AUTO_OFFSET = 0.0;
}
else if(Mode.Shoot == Shoot_Auto_Mode)
{
if (shoot_speed == SHOOT_SPEED15)
{
bull_speed = BULL_SPEED15;
PITCH_AUTO_OFFSET = 4.0; //自瞄云台校准
YAW_AUTO_OFFSET = -0.5;
}
else if (shoot_speed == SHOOT_SPEED25)
{
bull_speed = BULL_SPEED25;
PITCH_AUTO_OFFSET = 2.0;
YAW_AUTO_OFFSET = -0.4;
}
else
{
bull_speed = BULL_SPEED15;
PITCH_AUTO_OFFSET =0.0;//2.0;//陀螺自瞄//自瞄哨兵0.0//自瞄地面 2.0;
YAW_AUTO_OFFSET =-0.4;//1.0;//陀螺自瞄// -0.4;自瞄地面
}
}
else
{
bull_speed = 5500;
PITCH_AUTO_OFFSET = 0.0;
YAW_AUTO_OFFSET = 0.0;
}
//bull_speed = 5500;
//PITCH_AUTO_OFFSET = 2.0;
ShootFric1PID.ref = -1*bull_speed;
ShootFric2PID.ref = -1*ShootFric1PID.ref;
ShootFric3PID.ref = 1*bull_speed;
ShootFric1PID.fdb = SHOOTEncoder[FRIC1].rotate_speed;
ShootFric2PID.fdb = SHOOTEncoder[FRIC2].rotate_speed;
ShootFric3PID.fdb = SHOOTEncoder[FRIC3].rotate_speed;
PID_Calc(&ShootFric1PID);
PID_Calc(&ShootFric2PID);
PID_Calc(&ShootFric3PID);
fric_current[0] = (int16_t)ShootFric1PID.output;
fric_current[1] = (int16_t)ShootFric2PID.output;
fric_current[2] = (int16_t)ShootFric3PID.output;
}
/**
* @brief 摩擦轮、拨弹电机停转
* @param none
* @retval none
* @note
**/
void shoot_stop() {
uint8_t TxMessage[8];
TxMessage[0] = 0;
TxMessage[1] = 0;
TxMessage[2] = 0;
TxMessage[3] = 0;
TxMessage[4] = 0;
TxMessage[5] = 0;
TxMessage[6] = 0;
TxMessage[7] = 0;
CAN_Send_Msg(&hcan1, TxMessage, 0x200 , 8);
}
|
34dc4724b98991f23982772f112098293ecca287
|
ac50b09a3bcc621f08f49f4652c59bfcb9349f8f
|
/main.c
|
e1ffd1ef0ef721223ecc6b95ee6583f1f2abd6e6
|
[] |
no_license
|
AhmadAbdElHakim/DoorLock
|
dc58a63a6bf93ed4bd477309c9c37ee852ae6973
|
1fcb3fead6b2ac4a182a0605827b9cf437d8014f
|
refs/heads/master
| 2022-11-08T23:17:30.885775 | 2020-06-22T11:16:05 | 2020-06-22T11:16:05 | 267,445,501 | 0 | 0 | null | null | null | null |
UTF-8
|
C
| false | false | 3,461 |
c
|
main.c
|
#include "KeyPad.h"
#include "uart.h"
int8_t validatepassword(uint8_t *input , uint8_t *rightpass);
void initportf()
{
SYSCTL_RCGC2_R |= 0x20;
GPIO_PORTF_LOCK_R = 0x4C4F434B;
GPIO_PORTF_CR_R = 0XFF;
GPIO_PORTF_AFSEL_R = 0;
GPIO_PORTF_PCTL_R = 0;
GPIO_PORTF_AMSEL_R = 0;
GPIO_PORTF_DIR_R |= 0X02;
GPIO_PORTF_DIR_R &= ~0X01;
GPIO_PORTF_DEN_R |= 0X03;
GPIO_PORTF_PUR_R |= 0X01;
GPIO_PORTF_DATA_R &= ~0x02; // Solenoid Locked
}
int main(void)
{
uint8_t noOfRooms = 0;
uint8_t key;
uint8_t counter = 0;
uint8_t status[10];
uint8_t roomsNo[10];
uint8_t roomNo;
uint8_t found = 0;
uint8_t in[4];
uint8_t savedpassarr[10][4];
uint8_t setup = 0;
uint8_t first = 0;
uint8_t i = 0;
uint8_t j = 0;
uint8_t k = 0;
volatile uint8_t check;
volatile uint8_t roomNumber;
initportf();
UART_init();
KeyPad_init();
for(;;)
{
if(setup == 0)
{
while(1)
{
roomNo = UART0_read();
for(k = 0; k <= noOfRooms && noOfRooms != 0; k++)
{
if(roomsNo[k] == roomNo)
{
// Setup finished, same room number
roomNumber = roomNo;
found = 1;
}
}
if(found == 0)
{
roomsNo[noOfRooms] = roomNo;
noOfRooms++;
}
else
{
break;
}
}
setup = 1;
}
if(setup == 1)
{
if(first == 1)
{
roomNumber = UART0_read();
}
first = 1;
status[roomNumber] = UART0_read();
if(status[roomNumber] == 1)
{
for(j = 0; j < 4; j++)
{
savedpassarr[roomNumber][j] = UART0_read();
}
if(counter < 4)
{
key = KeyPad_getPressedKey();
if(key == '#' || key == '*'){continue;}
in[i] = key;
i++;
counter++;
}
if(counter >= 4)
{
key = KeyPad_getPressedKey();
if(key == '#')
{
check = validatepassword(in,savedpassarr[roomNumber]);
// Correct password
if(check == 1)
{
GPIO_PORTF_DATA_R |= 0x02; //Solenoid open
}
i = 0;
counter = 0;
}
}
}
else if(status[roomNumber] == 2)
{
GPIO_PORTF_DATA_R |= 0x02;
}
else if(status[roomNumber] == 0)
{
GPIO_PORTF_DATA_R &= ~0x02;
}
}
}
}
int8_t validatepassword(uint8_t *input , uint8_t *rightpass)
{
uint8_t z;
for(z = 0; z < 4; z++)
{
if (input[z] != rightpass[z])
return 0;
}
return 1;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.