41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "spiport" 53 ,_rxCount(RXCOUNT_INVALID)
54 ,_txCount(TXCOUNT_INVALID)
55 ,_errCount(ERRCOUNT_INVALID)
56 ,_rxMsgCount(RXMSGCOUNT_INVALID)
57 ,_txMsgCount(TXMSGCOUNT_INVALID)
58 ,_lastMsg(LASTMSG_INVALID)
59 ,_currentJob(CURRENTJOB_INVALID)
60 ,_startupJob(STARTUPJOB_INVALID)
61 ,_command(COMMAND_INVALID)
62 ,_voltageLevel(VOLTAGELEVEL_INVALID)
63 ,_protocol(PROTOCOL_INVALID)
64 ,_spiMode(SPIMODE_INVALID)
65 ,_ssPolarity(SSPOLARITY_INVALID)
66 ,_shitftSampling(SHITFTSAMPLING_INVALID)
67 ,_valueCallbackSpiPort(NULL)
91 if(json_val->
has(
"rxCount")) {
94 if(json_val->
has(
"txCount")) {
97 if(json_val->
has(
"errCount")) {
100 if(json_val->
has(
"rxMsgCount")) {
103 if(json_val->
has(
"txMsgCount")) {
106 if(json_val->
has(
"lastMsg")) {
109 if(json_val->
has(
"currentJob")) {
112 if(json_val->
has(
"startupJob")) {
115 if(json_val->
has(
"command")) {
118 if(json_val->
has(
"voltageLevel")) {
121 if(json_val->
has(
"protocol")) {
124 if(json_val->
has(
"spiMode")) {
127 if(json_val->
has(
"ssPolarity")) {
130 if(json_val->
has(
"shitftSampling")) {
158 }
catch (std::exception) {
187 }
catch (std::exception) {
216 }
catch (std::exception) {
245 }
catch (std::exception) {
274 }
catch (std::exception) {
303 }
catch (std::exception) {
332 }
catch (std::exception) {
358 res =
_setAttr(
"currentJob", rest_val);
359 }
catch (std::exception) {
388 }
catch (std::exception) {
414 res =
_setAttr(
"startupJob", rest_val);
415 }
catch (std::exception) {
437 }
catch (std::exception) {
452 res =
_setAttr(
"command", rest_val);
453 }
catch (std::exception) {
484 }
catch (std::exception) {
513 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
514 res =
_setAttr(
"voltageLevel", rest_val);
515 }
catch (std::exception) {
548 }
catch (std::exception) {
578 res =
_setAttr(
"protocol", rest_val);
579 }
catch (std::exception) {
611 }
catch (std::exception) {
638 res =
_setAttr(
"spiMode", rest_val);
639 }
catch (std::exception) {
668 }
catch (std::exception) {
691 rest_val = (newval>0 ?
"1" :
"0");
692 res =
_setAttr(
"ssPolarity", rest_val);
693 }
catch (std::exception) {
723 }
catch (std::exception) {
748 rest_val = (newval>0 ?
"1" :
"0");
749 res =
_setAttr(
"shitftSampling", rest_val);
750 }
catch (std::exception) {
798 }
catch (std::exception) {
820 if (callback != NULL) {
827 if (callback != NULL && this->
isOnline()) {
897 bufflen = (int)(buff).size();
902 while ((idx < bufflen) && (ch != 0)) {
903 ch = ((u8)buff[idx]);
904 if ((ch >= 0x20) && (ch < 0x7f)) {
910 if (idx >= bufflen) {
915 return this->
_upload(
"txdata", buff);
929 return this->
_upload(
"txdata", buff);
948 bufflen = (int)byteList.size();
949 buff = string(bufflen, (
char)0);
951 while (idx < bufflen) {
952 hexb = byteList[idx];
953 buff[idx] = (char)(hexb);
957 res = this->
_upload(
"txdata", buff);
977 bufflen = (int)(hexString).length();
981 bufflen = ((bufflen) >> (1));
982 buff = string(bufflen, (
char)0);
984 while (idx < bufflen) {
985 hexb = (int)strtoul((hexString).substr( 2 * idx, 2).c_str(), NULL, 16);
986 buff[idx] = (char)(hexb);
990 res = this->
_upload(
"txdata", buff);
1010 bufflen = (int)(buff).size()-2;
1011 if (bufflen < 100) {
1015 while ((idx < bufflen) && (ch != 0)) {
1016 ch = ((u8)buff[idx]);
1017 if ((ch >= 0x20) && (ch < 0x7f)) {
1023 if (idx >= bufflen) {
1028 return this->
_upload(
"txdata", buff);
1050 bufflen = (int)(
_rxbuff).size();
1060 bufflen = (int)(buff).size();
1061 if (
_rxptr == currpos+bufflen) {
1062 res = ((u8)buff[0]);
1072 bufflen = (int)(buff).size();
1073 if (
_rxptr == currpos+bufflen) {
1074 res = ((u8)buff[0]);
1084 bufflen = (int)(buff).size() - 1;
1087 while ((bufflen > 0) && (((u8)buff[bufflen]) != 64)) {
1088 endpos = endpos + mult * (((u8)buff[bufflen]) - 48);
1090 bufflen = bufflen - 1;
1096 res = ((u8)buff[0]);
1118 if (nChars > 65535) {
1123 bufflen = (int)(buff).size() - 1;
1126 while ((bufflen > 0) && (((u8)buff[bufflen]) != 64)) {
1127 endpos = endpos + mult * (((u8)buff[bufflen]) - 48);
1129 bufflen = bufflen - 1;
1132 res = (buff).substr( 0, bufflen);
1155 if (nChars > 65535) {
1160 bufflen = (int)(buff).size() - 1;
1163 while ((bufflen > 0) && (((u8)buff[bufflen]) != 64)) {
1164 endpos = endpos + mult * (((u8)buff[bufflen]) - 48);
1166 bufflen = bufflen - 1;
1169 res = string(bufflen, (
char)0);
1171 while (idx < bufflen) {
1172 res[idx] = (char)(((u8)buff[idx]));
1198 if (nChars > 65535) {
1203 bufflen = (int)(buff).size() - 1;
1206 while ((bufflen > 0) && (((u8)buff[bufflen]) != 64)) {
1207 endpos = endpos + mult * (((u8)buff[bufflen]) - 48);
1209 bufflen = bufflen - 1;
1214 while (idx < bufflen) {
1215 b = ((u8)buff[idx]);
1241 if (nBytes > 65535) {
1246 bufflen = (int)(buff).size() - 1;
1249 while ((bufflen > 0) && (((u8)buff[bufflen]) != 64)) {
1250 endpos = endpos + mult * (((u8)buff[bufflen]) - 48);
1252 bufflen = bufflen - 1;
1257 while (ofs + 3 < bufflen) {
1258 res =
YapiWrapper::ysprintf(
"%s%02x%02x%02x%02x", res.c_str(), ((u8)buff[ofs]), ((u8)buff[ofs + 1]), ((u8)buff[ofs + 2]),((u8)buff[ofs + 3]));
1261 while (ofs < bufflen) {
1285 vector<string> msgarr;
1292 msglen = (int)msgarr.size();
1297 msglen = msglen - 1;
1298 _rxptr = atoi((msgarr[msglen]).c_str());
1331 vector<string> msgarr;
1339 msglen = (int)msgarr.size();
1344 msglen = msglen - 1;
1345 _rxptr = atoi((msgarr[msglen]).c_str());
1347 while (idx < msglen) {
1392 bufflen = (int)(buff).size() - 1;
1393 while ((bufflen > 0) && (((u8)buff[bufflen]) != 64)) {
1394 bufflen = bufflen - 1;
1396 res = atoi(((buff).substr( 0, bufflen)).c_str());
1416 vector<string> msgarr;
1423 msglen = (int)msgarr.size();
1428 msglen = msglen - 1;
1429 _rxptr = atoi((msgarr[msglen]).c_str());
1450 this->
_upload(jobfile, jsonDef);
1497 vector<YFUN_DESCR> v_fundescr;
1499 string serial, funcId, funcName, funcVal, errmsg;
1502 v_fundescr.size() == 0 ||
int set_command(const string &newval)
Y_SHITFTSAMPLING_enum get_shitftSampling(void)
Y_VOLTAGELEVEL_enum get_voltageLevel(void)
yCRITICAL_SECTION _this_cs
Y_SHITFTSAMPLING_enum _shitftSampling
virtual int sendCommand(string text)
YSpiPort(const string &func)
string _json_get_string(const string &json)
YRETCODE _load_unsafe(int msValidity)
virtual int read_seek(int absPos)
virtual string readHex(int nBytes)
int set_ssPolarity(Y_SSPOLARITY_enum newval)
virtual int _invokeValueCallback(string value)
virtual int read_tell(void)
virtual int uploadJob(string jobfile, string jsonDef)
int set_shitftSampling(Y_SHITFTSAMPLING_enum newval)
virtual string readStr(int nChars)
static const Y_SHITFTSAMPLING_enum SHITFTSAMPLING_INVALID
YSpiPortValueCallback _valueCallbackSpiPort
virtual string readLine(void)
YRETCODE _upload(const string &path, const string &content)
static int DefaultCacheValidity
void(* YSpiPortValueCallback)(YSpiPort *func, const string &functionValue)
string getString(const string &key)
static const string LASTMSG_INVALID
static const int RXMSGCOUNT_INVALID
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
static const int TXCOUNT_INVALID
static const string CURRENTJOB_INVALID
YSpiPort * nextSpiPort(void)
string _download(const string &url)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
static const string SPIMODE_INVALID
virtual int writeByte(int code)
static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_INVALID
static YSpiPort * FindSpiPort(string func)
int set_voltageLevel(Y_VOLTAGELEVEL_enum newval)
virtual int writeArray(vector< int > byteList)
static const int RXCOUNT_INVALID
#define YAPI_INVALID_STRING
static const int ERRCOUNT_INVALID
virtual int _parseAttr(YJSONObject *json_val)
virtual int registerValueCallback(YSpiPortValueCallback callback)
virtual int selectJob(string jobfile)
int getInt(const string &key)
string get_currentJob(void)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
Y_SSPOLARITY_enum _ssPolarity
virtual int _parseAttr(YJSONObject *json_val)
virtual int read_avail(void)
static YFunction * _FindFromCache(const string &classname, const string &func)
vector< string > _json_get_array(const string &json)
virtual string readBin(int nChars)
static string ysprintf(const char *fmt,...)
int set_currentJob(const string &newval)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
static YSpiPort * FirstSpiPort(void)
int set_protocol(const string &newval)
virtual int writeLine(string text)
static const Y_SSPOLARITY_enum SSPOLARITY_INVALID
virtual vector< int > readArray(int nChars)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
Y_VOLTAGELEVEL_enum _voltageLevel
int set_spiMode(const string &newval)
virtual int set_SS(int val)
virtual int writeBin(string buff)
virtual string queryLine(string query, int maxWait)
static const string PROTOCOL_INVALID
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
static void _UpdateValueCallbackList(YFunction *func, bool add)
virtual int readByte(void)
Y_SSPOLARITY_enum get_ssPolarity(void)
static const string STARTUPJOB_INVALID
static const string COMMAND_INVALID
static const int TXMSGCOUNT_INVALID
bool has(const string &key)
string get_startupJob(void)
YRETCODE _setAttr(string attrname, string newvalue)
virtual int writeHex(string hexString)
virtual int writeStr(string text)
int set_startupJob(const string &newval)
virtual vector< string > readMessages(string pattern, int maxWait)
virtual int _invokeValueCallback(string value)
string get_protocol(void)